@zaganjade/pi-multi-skill 1.0.0 → 1.3.1

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/src/index.ts CHANGED
@@ -1,395 +1,332 @@
1
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { dirname, join } from "node:path";
4
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
1
+ import type {
2
+ ExtensionAPI,
3
+ ExtensionCommandContext,
4
+ } from "@earendil-works/pi-coding-agent";
5
5
  import type { AutocompleteItem } from "@earendil-works/pi-tui";
6
+ import {
7
+ bundleOrderHint,
8
+ DEFAULT_BUNDLES,
9
+ expandSkillNames,
10
+ loadBundles,
11
+ } from "./bundles.ts";
12
+ import {
13
+ assessAllBundles,
14
+ formatBundleFailureGuide,
15
+ formatBundleHelpLine,
16
+ formatMissingSkillHints,
17
+ formatSetupReport,
18
+ } from "./bundle-status.ts";
19
+ import { bmadAutoHint, resolveBmadAutoSkills } from "./bmad-auto.ts";
20
+ import { buildBmadStatusBlock, shouldInjectBmadStatus } from "./bmad-status.ts";
21
+ import { buildCombinedMessage, resolveAndReadLegacySkill } from "./build.ts";
22
+ import { getSkillsArgumentCompletions } from "./completions.ts";
23
+ import { resolveSkillConflicts } from "./conflicts.ts";
24
+ import { discoverAllSkills, resolveSkillByName } from "./discover.ts";
25
+ import { enrichSkill, sortSkills } from "./metadata.ts";
26
+ import { parseSkillsArgs } from "./parse-args.ts";
27
+ import { rebuildSkillIndex } from "./registry.ts";
28
+ import { formatStatsReport, recordActivation, replayLastArgs, formatLastActivationHint } from "./stats.ts";
29
+ import { formatSuggestionHint, suggestSkillBundle } from "./suggestions.ts";
30
+ import { hasSubagentTool } from "./subagents.ts";
31
+ import type { EnrichedSkillInfo, LoadMode, SkillBundle, SkillInfo, SkillOrder } from "./types.ts";
6
32
 
7
33
  /**
8
34
  * Multi-Skill Loader Extension for Pi
9
- *
10
- * Enables loading multiple skills at once via the /skills command.
11
- * Appears in the slash autocomplete menu alongside built-in commands,
12
- * with full skill descriptions shown just like /skill: commands.
13
- *
14
- * Uses pi.getCommands() to discover ALL skills from every source:
15
- * user-level, project-level, npm packages, git packages, etc.
16
- *
17
- * Usage:
18
- * /skills frontend-design,motion-design Create an animated landing page
19
- * /skills → shows help + available skills
20
- *
21
- * Also handles legacy formats via the input event:
22
- * /skills:frontend-design,motion-design [args] (colon-separated)
23
- * /skill:frontend-design+motion-design [args] (plus-separated)
24
35
  */
25
36
 
26
- // ─── Types ──────────────────────────────────────────────────────────────────
27
-
28
- interface SkillInfo {
29
- name: string;
30
- description: string;
31
- filePath: string;
32
- baseDir: string;
33
- }
34
-
35
- // ─── Helpers ────────────────────────────────────────────────────────────────
36
-
37
- /** Normalize CRLF → LF then strip YAML frontmatter, return body. */
38
- function stripFrontmatter(content: string): string {
39
- const normalized = content.replace(/\r\n/g, "\n");
40
- const match = normalized.match(/^---\n([\s\S]*?\n)?---\n?/);
41
- return match ? normalized.slice(match[0].length) : normalized;
42
- }
43
-
44
- /** Truncate a description to a single readable line for autocomplete display. */
45
- function truncateDescription(desc: string, maxLen = 120): string {
46
- if (!desc) return "";
47
-
48
- // Take first non-empty line
49
- const lines = desc
50
- .split("\n")
51
- .map((l) => l.replace(/^>\s*/, "").trim())
52
- .filter((l) => l.length > 0);
53
-
54
- if (lines.length === 0) return "";
55
-
56
- let text = lines[0];
57
- if (lines.length > 1 && text.length < 40) {
58
- text = `${text} ${lines[1]}`;
59
- }
60
-
61
- if (text.length > maxLen) {
62
- text = `${text.slice(0, maxLen - 1)}…`;
37
+ function resolveSelectedSkills(
38
+ names: string[],
39
+ available: SkillInfo[],
40
+ order: SkillOrder = "process-first",
41
+ ): EnrichedSkillInfo[] {
42
+ const nameToSkill = new Map(available.map((s) => [s.name, s]));
43
+ const selected: SkillInfo[] = [];
44
+
45
+ for (const name of names) {
46
+ const skill =
47
+ nameToSkill.get(name) ?? resolveSkillByName(name, nameToSkill);
48
+ if (skill) {
49
+ nameToSkill.set(skill.name, skill);
50
+ selected.push(skill);
51
+ }
63
52
  }
64
53
 
65
- return text;
54
+ return sortSkills(selected.map(enrichSkill), order);
66
55
  }
67
56
 
68
- function getAgentDir(): string {
69
- return join(homedir(), ".pi", "agent");
57
+ function resolveSelectedSkillsWithConflicts(
58
+ names: string[],
59
+ available: SkillInfo[],
60
+ order: SkillOrder = "process-first",
61
+ ): { skills: EnrichedSkillInfo[]; warnings: string[] } {
62
+ const sorted = resolveSelectedSkills(names, available, order);
63
+ const resolved = resolveSkillConflicts(sorted);
64
+ return { skills: resolved.skills, warnings: resolved.warnings };
70
65
  }
71
66
 
72
- /**
73
- * Discover ALL available skills via pi.getCommands().
74
- * This covers user-level, project-level, and package-installed skills.
75
- */
76
- function discoverSkillsFromPi(pi: ExtensionAPI): SkillInfo[] {
77
- const commands = pi.getCommands();
78
- const skills: SkillInfo[] = [];
79
-
80
- for (const cmd of commands) {
81
- if (cmd.source !== "skill") continue;
82
-
83
- // Command name is like "skill:name" → extract the skill name
84
- const skillName = cmd.name.startsWith("skill:")
85
- ? cmd.name.slice(6)
86
- : cmd.name;
87
-
88
- const filePath = cmd.sourceInfo.path;
89
- const baseDir = cmd.sourceInfo.baseDir || dirname(filePath);
90
-
91
- skills.push({
92
- name: skillName,
93
- description: truncateDescription(cmd.description || ""),
94
- filePath,
95
- baseDir,
96
- });
97
- }
98
-
99
- return skills.sort((a, b) => a.name.localeCompare(b.name));
67
+ function formatHelp(available: SkillInfo[], bundles: Map<string, SkillBundle>): string {
68
+ const skillLines = available
69
+ .map((s) =>
70
+ s.description ? ` • ${s.name} — ${s.description}` : ` • ${s.name}`,
71
+ )
72
+ .join("\n");
73
+
74
+ const bundleStatuses = assessAllBundles(bundles, available);
75
+ const bundleLines = bundleStatuses.map(formatBundleHelpLine).join("\n");
76
+ const readyCount = bundleStatuses.filter((s) => s.ready).length;
77
+
78
+ return (
79
+ `Usage:\n` +
80
+ ` /skills skill1,skill2 [instructions]\n` +
81
+ ` /skills @bundle [--meta|--lazy|--full] [instructions]\n` +
82
+ ` /skills bmad-master /workflow-status\n` +
83
+ ` /skills @bmad-planning --auto\n` +
84
+ ` /skills @cc-feature --parallel Task A | Task B | Task C\n\n` +
85
+ `Flags: --meta · --lazy · --full · --auto · --parallel\n` +
86
+ `Setup: /skills-setup · Stats: /skills-stats · Repeat: /skills-last\n\n` +
87
+ `Bundles (${readyCount}/${bundles.size} usable on this machine):\n${bundleLines}\n\n` +
88
+ `Skills (${available.length}):\n${skillLines}\n\n` +
89
+ `No BMAD/Superpowers? Use /skills-setup or create ~/.pi/agent/skill-bundles.json`
90
+ );
100
91
  }
101
92
 
102
- /**
103
- * Fallback: scan filesystem for skills not yet discovered via pi.getCommands().
104
- * Used to catch any edge cases.
105
- */
106
- function discoverSkillsFromFilesystem(
107
- cwd: string,
108
- knownNames: Set<string>,
109
- ): SkillInfo[] {
110
- const skills: SkillInfo[] = [];
111
- const dirs = [
112
- join(getAgentDir(), "skills"),
113
- join(cwd, ".pi", "skills"),
114
- ].filter((d) => existsSync(d));
115
-
116
- for (const dir of dirs) {
117
- try {
118
- const entries = readdirSync(dir, { withFileTypes: true });
119
- for (const entry of entries) {
120
- if (entry.isDirectory()) {
121
- const skillFile = join(dir, entry.name, "SKILL.md");
122
- if (existsSync(skillFile) && !knownNames.has(entry.name)) {
123
- skills.push({
124
- name: entry.name,
125
- description: "",
126
- filePath: skillFile,
127
- baseDir: join(dir, entry.name),
128
- });
129
- knownNames.add(entry.name);
130
- }
131
- } else if (entry.isFile() && entry.name.endsWith(".md")) {
132
- const name = entry.name.replace(/\.md$/, "");
133
- if (!knownNames.has(name)) {
134
- const skillFile = join(dir, entry.name);
135
- skills.push({
136
- name,
137
- description: "",
138
- filePath: skillFile,
139
- baseDir: dir,
140
- });
141
- knownNames.add(name);
142
- }
143
- }
144
- }
145
- } catch {
146
- // Skip unreadable directories
147
- }
93
+ function processAndSend(
94
+ pi: ExtensionAPI,
95
+ ctx: ExtensionCommandContext,
96
+ rawArgs: string,
97
+ getSkills: (cwd: string) => SkillInfo[],
98
+ ): void {
99
+ const bundles = loadBundles(ctx.cwd);
100
+ const parsed = parseSkillsArgs(rawArgs);
101
+ let skillNames = [...parsed.skillNames];
102
+ let mode: LoadMode = parsed.mode;
103
+
104
+ if (parsed.auto) {
105
+ skillNames = resolveBmadAutoSkills(ctx.cwd);
106
+ const hint = bmadAutoHint(ctx.cwd);
107
+ if (hint) ctx.ui.notify(hint, "info");
108
+ } else {
109
+ const expanded = expandSkillNames(skillNames, bundles);
110
+ skillNames = expanded.skills;
111
+ if (mode === "full" && expanded.modeHint) mode = expanded.modeHint;
148
112
  }
149
113
 
150
- return skills;
151
- }
152
-
153
- function resolveAndReadSkill(skillName: string, cwd: string): string | null {
154
- // Try all possible skill locations
155
- const dirs = [join(getAgentDir(), "skills"), join(cwd, ".pi", "skills")];
156
-
157
- for (const dir of dirs) {
158
- // Directory-based: <dir>/<name>/SKILL.md
159
- const skillFile = join(dir, skillName, "SKILL.md");
160
- try {
161
- const content = readFileSync(skillFile, "utf-8");
162
- const body = stripFrontmatter(content).trim();
163
- return `<skill name="${skillName}" location="${skillFile}">\nReferences are relative to ${dirname(skillFile)}.\n\n${body}\n</skill>`;
164
- } catch {
165
- // not found
166
- }
114
+ if (skillNames.length === 0) {
115
+ ctx.ui.notify("No skill names provided.", "error");
116
+ return;
117
+ }
167
118
 
168
- // File-based: <dir>/<name>.md
169
- const mdFile = join(dir, `${skillName}.md`);
170
- try {
171
- const content = readFileSync(mdFile, "utf-8");
172
- const body = stripFrontmatter(content).trim();
173
- return `<skill name="${skillName}" location="${mdFile}">\nReferences are relative to ${dirname(mdFile)}.\n\n${body}\n</skill>`;
174
- } catch {
175
- // not found
119
+ const bundleNames = parsed.skillNames
120
+ .filter((n) => n.startsWith("@"))
121
+ .map((n) => n.slice(1));
122
+
123
+ const allSkills = getSkills(ctx.cwd);
124
+ const order =
125
+ bundleOrderHint(parsed.skillNames, bundles) ?? "process-first";
126
+ const { skills: selected, warnings: conflictWarnings } =
127
+ resolveSelectedSkillsWithConflicts(skillNames, allSkills, order);
128
+
129
+ if (selected.length === 0) {
130
+ if (bundleNames.length > 0) {
131
+ ctx.ui.notify(
132
+ formatBundleFailureGuide(bundleNames, bundles, allSkills),
133
+ "error",
134
+ );
135
+ } else {
136
+ ctx.ui.notify(
137
+ `No skills found for: ${skillNames.join(", ")}\n` +
138
+ `Install skills under ~/.pi/agent/skills, ~/.claude/skills, or pi settings "skills" paths.\n` +
139
+ `Run /skills-setup for bundle install guide.`,
140
+ "error",
141
+ );
176
142
  }
143
+ return;
177
144
  }
178
145
 
179
- return null;
180
- }
181
-
182
- /**
183
- * Read a skill file by its absolute path (for package-installed skills
184
- * that live outside ~/.pi/agent/skills/).
185
- */
186
- function resolveAndReadSkillByPath(
187
- skillName: string,
188
- filePath: string,
189
- ): string | null {
190
- try {
191
- const content = readFileSync(filePath, "utf-8");
192
- const body = stripFrontmatter(content).trim();
193
- const baseDir = dirname(filePath);
194
- return `<skill name="${skillName}" location="${filePath}">\nReferences are relative to ${baseDir}.\n\n${body}\n</skill>`;
195
- } catch {
196
- return null;
146
+ const missing = skillNames.filter(
147
+ (name) => !selected.some((s) => s.name === name),
148
+ );
149
+ if (missing.length > 0) {
150
+ const hint =
151
+ bundleNames.length > 0
152
+ ? `Skills not found (partial bundle load):\n${formatMissingSkillHints(missing)}\nRun /skills-setup for install guide.`
153
+ : `Skills not found: ${missing.join(", ")}`;
154
+ ctx.ui.notify(hint, "info");
155
+ }
156
+ if (conflictWarnings.length > 0) {
157
+ ctx.ui.notify(conflictWarnings.join("\n"), "info");
197
158
  }
198
- }
199
159
 
200
- /** Build the combined skill block text from a list of skill infos. */
201
- function buildCombinedSkills(
202
- selectedSkills: SkillInfo[],
203
- cwd: string,
204
- instructions?: string,
205
- ): string {
206
- const expandedBlocks: string[] = [];
207
- const notFound: string[] = [];
208
-
209
- for (const skill of selectedSkills) {
210
- // Try reading by the known filePath first (works for package skills)
211
- let content = resolveAndReadSkillByPath(skill.name, skill.filePath);
212
-
213
- // Fallback to filesystem scan for user/project skills
214
- if (!content) {
215
- content = resolveAndReadSkill(skill.name, cwd);
216
- }
160
+ if (parsed.embeddedCommand) {
161
+ ctx.ui.notify(
162
+ `Loading ${selected.map((s) => s.name).join(", ")} → ${parsed.embeddedCommand}`,
163
+ "info",
164
+ );
165
+ }
217
166
 
218
- if (content) expandedBlocks.push(content);
219
- else notFound.push(skill.name);
167
+ const subagentAvailable = hasSubagentTool(pi);
168
+ if (parsed.parallel && !subagentAvailable) {
169
+ ctx.ui.notify(
170
+ "Parallel mode: pi-subagents not detected — tasks will run sequentially. Install: pi install npm:pi-subagents",
171
+ "info",
172
+ );
220
173
  }
221
174
 
222
- let combined = expandedBlocks.join("\n\n");
175
+ const bmadStatusBlock = shouldInjectBmadStatus({
176
+ embeddedCommand: parsed.embeddedCommand,
177
+ auto: parsed.auto,
178
+ })
179
+ ? buildBmadStatusBlock(ctx.cwd)
180
+ : null;
181
+
182
+ const { message } = buildCombinedMessage(selected, ctx.cwd, {
183
+ mode,
184
+ bundles: bundleNames,
185
+ bmadStatusBlock: bmadStatusBlock ?? undefined,
186
+ parallel: parsed.parallel,
187
+ parallelTasks: parsed.parallelTasks,
188
+ subagentAvailable,
189
+ embeddedCommand: parsed.embeddedCommand,
190
+ instructions: parsed.instructions || undefined,
191
+ conflictWarnings,
192
+ });
223
193
 
224
- if (notFound.length > 0) {
225
- combined += `\n\n> ⚠️ Skills not found: ${notFound.join(", ")}`;
194
+ if (!message.includes("<skill ")) {
195
+ ctx.ui.notify(`Could not read skill files for: ${skillNames.join(", ")}`, "error");
196
+ return;
226
197
  }
227
198
 
228
- if (instructions) {
229
- combined += `\n\n${instructions}`;
230
- }
199
+ recordActivation({
200
+ mode,
201
+ skillNames: selected.map((s) => s.name),
202
+ bundles: bundleNames,
203
+ parallel: parsed.parallel,
204
+ skillCount: selected.length,
205
+ rawArgs,
206
+ });
231
207
 
232
- return combined;
208
+ pi.sendUserMessage(message);
233
209
  }
234
210
 
235
- // ─── Extension ──────────────────────────────────────────────────────────────
236
-
237
211
  export default function (pi: ExtensionAPI) {
238
- // Cache skills list for the session (refreshed on reload)
239
212
  let cachedSkills: SkillInfo[] | null = null;
240
213
 
241
- function getSkills(cwd?: string): SkillInfo[] {
214
+ function getSkills(cwd: string): SkillInfo[] {
242
215
  if (!cachedSkills) {
243
- // Primary: use pi.getCommands() which covers ALL sources
244
- const piSkills = discoverSkillsFromPi(pi);
245
- const knownNames = new Set(piSkills.map((s) => s.name));
246
-
247
- // Secondary: filesystem fallback for anything missed
248
- const fsSkills = cwd ? discoverSkillsFromFilesystem(cwd, knownNames) : [];
249
-
250
- cachedSkills = [...piSkills, ...fsSkills].sort((a, b) =>
251
- a.name.localeCompare(b.name),
252
- );
216
+ cachedSkills = discoverAllSkills(pi, cwd);
253
217
  }
254
218
  return cachedSkills;
255
219
  }
256
220
 
257
- // Clear cache on session start (skills might have changed)
258
- pi.on("session_start", async () => {
259
- cachedSkills = null;
221
+ pi.on("session_start", async (_event, ctx) => {
222
+ try {
223
+ cachedSkills = null;
224
+ const cwd = ctx?.cwd ?? process.cwd();
225
+ rebuildSkillIndex(getSkills(cwd));
226
+ } catch (err) {
227
+ console.error("[pi-multi-skill] session_start:", err);
228
+ }
260
229
  });
261
230
 
262
- // ========================================================================
263
- // /skills command — registered as an extension command so it appears in
264
- // the slash autocomplete menu when the user types "/".
265
- // ========================================================================
266
- pi.registerCommand("skills", {
267
- description:
268
- "Load multiple skills at once. Usage: /skills skill1,skill2 [instructions]",
269
- getArgumentCompletions: (prefix: string): AutocompleteItem[] | null => {
270
- const allSkills = getSkills();
271
- if (allSkills.length === 0) return null;
272
-
273
- // Parse comma-separated skills already typed
274
- // e.g. prefix = "frontend-design,mot" → already = ["frontend-design"], current = "mot"
275
- const parts = prefix.split(",");
276
- const currentPart = parts[parts.length - 1].trim();
277
- const alreadySelected = parts
278
- .slice(0, -1)
279
- .map((s) => s.trim())
280
- .filter((s) => s.length > 0);
281
-
282
- // Filter out already selected skills
283
- const remaining = allSkills.filter(
284
- (s) => !alreadySelected.includes(s.name),
285
- );
286
-
287
- let candidates = remaining;
288
- if (currentPart) {
289
- candidates = remaining.filter((s) => s.name.startsWith(currentPart));
231
+ pi.on("turn_end", async (_event, ctx) => {
232
+ try {
233
+ const sm = ctx?.sessionManager;
234
+ if (!sm) return;
235
+
236
+ for (const entry of [...sm.getBranch()].reverse()) {
237
+ if (entry.type !== "message") continue;
238
+ if (entry.message.role !== "user") continue;
239
+ const content = entry.message.content;
240
+ const text = typeof content === "string" ? content : "";
241
+ if (
242
+ text.includes("<manually_attached_skills") ||
243
+ text.includes("<skill ")
244
+ ) {
245
+ return;
246
+ }
247
+ const suggestion = suggestSkillBundle(
248
+ text,
249
+ loadBundles(ctx.cwd),
250
+ getSkills(ctx.cwd),
251
+ );
252
+ if (suggestion) {
253
+ ctx.ui.notify(
254
+ formatSuggestionHint(suggestion.bundle, suggestion.reason),
255
+ "info",
256
+ );
257
+ }
258
+ return;
290
259
  }
260
+ } catch (err) {
261
+ console.error("[pi-multi-skill] turn_end:", err);
262
+ }
263
+ });
291
264
 
292
- if (candidates.length === 0) return null;
293
-
294
- // If user has already typed some skills, show completion with comma prefix
295
- // so selecting appends properly
296
- const needsComma = alreadySelected.length > 0;
297
- return candidates.map((s) => ({
298
- value: needsComma
299
- ? `${parts.slice(0, -1).join(",")},${s.name}`
300
- : s.name,
301
- label: alreadySelected.length > 0 ? ` ${s.name}` : s.name,
302
- description: s.description || undefined,
303
- }));
304
- },
265
+ pi.registerCommand("skills", {
266
+ description:
267
+ "Load multiple skills /skills @bundle,skill1,skill2 [--meta|--lazy] [instructions]",
268
+ getArgumentCompletions: (prefix: string): AutocompleteItem[] | null =>
269
+ getSkillsArgumentCompletions(
270
+ prefix,
271
+ getSkills(process.cwd()),
272
+ loadBundles(process.cwd()),
273
+ pi,
274
+ ),
305
275
  handler: async (args, ctx) => {
306
276
  const available = getSkills(ctx.cwd);
277
+ const bundles = loadBundles(ctx.cwd);
307
278
 
308
279
  if (!args || args.trim().length === 0) {
309
- // No args → show help with available skills list + descriptions
310
- const skillLines = available
311
- .map((s) =>
312
- s.description
313
- ? ` • ${s.name} — ${s.description}`
314
- : ` • ${s.name}`,
315
- )
316
- .join("\n");
317
-
318
- ctx.ui.notify(
319
- `Usage: /skills skill1,skill2,... [additional instructions]\n` +
320
- `Example: /skills frontend-design,motion-design Create an animated page\n\n` +
321
- `Available skills (${available.length}):\n${skillLines}`,
322
- "info",
323
- );
324
- return;
325
- }
326
-
327
- // Parse: first token is comma-separated skill names, rest is instructions
328
- const tokens = args.trim().match(/^(\S+)(?:\s+([\s\S]*))?$/);
329
- if (!tokens) {
330
- ctx.ui.notify(
331
- "Invalid format. Usage: /skills skill1,skill2 [instructions]",
332
- "error",
333
- );
280
+ ctx.ui.notify(formatHelp(available, bundles), "info");
334
281
  return;
335
282
  }
336
283
 
337
- const skillNames = tokens[1]
338
- .split(",")
339
- .map((s) => s.trim())
340
- .filter((s) => s.length > 0);
341
- const instructions = tokens[2]?.trim() || "";
342
-
343
- if (skillNames.length === 0) {
344
- ctx.ui.notify("No skill names provided.", "error");
345
- return;
346
- }
284
+ processAndSend(pi, ctx, args, getSkills);
285
+ },
286
+ });
347
287
 
348
- // Resolve skill infos from names
349
- const nameToSkill = new Map(available.map((s) => [s.name, s]));
350
- const selectedSkills = skillNames
351
- .map((name) => nameToSkill.get(name))
352
- .filter((s): s is SkillInfo => s !== undefined);
288
+ pi.registerCommand("skills-stats", {
289
+ description: "Show multi-skill activation statistics",
290
+ handler: async (_args, ctx) => {
291
+ ctx.ui.notify(formatStatsReport(), "info");
292
+ },
293
+ });
353
294
 
354
- const combined = buildCombinedSkills(
355
- selectedSkills.length > 0 ? selectedSkills : [],
356
- ctx.cwd,
357
- instructions || undefined,
358
- );
295
+ pi.registerCommand("skills-setup", {
296
+ description: "Bundle prerequisites and install guide (BMAD, Superpowers, custom bundles)",
297
+ handler: async (_args, ctx) => {
298
+ const available = getSkills(ctx.cwd);
299
+ const bundles = loadBundles(ctx.cwd);
300
+ ctx.ui.notify(formatSetupReport(bundles, available), "info");
301
+ },
302
+ });
359
303
 
360
- // Check if any skills were actually loaded
361
- if (!combined.includes("<skill ")) {
362
- ctx.ui.notify(`No skills found for: ${skillNames.join(", ")}`, "error");
304
+ pi.registerCommand("skills-last", {
305
+ description: "Repeat the last /skills activation (optional: --meta|--lazy|--full|--parallel)",
306
+ handler: async (args, ctx) => {
307
+ const replay = replayLastArgs(args?.trim() ?? "");
308
+ if (!replay) {
309
+ ctx.ui.notify(
310
+ "No recent /skills activation to replay.\nRun /skills first, then /skills-last.",
311
+ "error",
312
+ );
363
313
  return;
364
314
  }
365
-
366
- // Send the combined skill content as a user message to trigger agent processing
367
- pi.sendUserMessage(combined);
315
+ const hint = formatLastActivationHint();
316
+ if (hint) ctx.ui.notify(`Repeating: ${hint}`, "info");
317
+ processAndSend(pi, ctx, replay, getSkills);
368
318
  },
369
319
  });
370
320
 
371
- // ========================================================================
372
- // Input event — handles legacy formats that use colons/plus signs.
373
- // These formats bypass the command system, so we intercept via input.
374
- //
375
- // Supported:
376
- // /skills:name1,name2,... [args] (colon + comma)
377
- // /skill:name1+name2+... [args] (colon + plus)
378
- // ========================================================================
379
- pi.on("input", async (event, _ctx) => {
321
+ pi.on("input", async (event, ctx) => {
380
322
  const text = event.text.trim();
381
-
382
- // Only handle /skills:... or /skill:...+... formats
383
- // /skills ... (space) is handled by the registered command above
384
- if (!text.startsWith("/skills:") && !text.startsWith("/skill:"))
323
+ if (!text.startsWith("/skills:") && !text.startsWith("/skill:")) {
385
324
  return { action: "continue" };
386
-
387
- // For /skill:... with no plus sign, let pi's built-in handler deal with it
325
+ }
388
326
  if (text.startsWith("/skill:") && !text.slice(7).includes("+")) {
389
327
  return { action: "continue" };
390
328
  }
391
329
 
392
- // Parse the skill list
393
330
  const colonIndex = text.indexOf(":");
394
331
  const spaceIndex = text.indexOf(" ", colonIndex);
395
332
  const skillListRaw =
@@ -397,8 +334,6 @@ export default function (pi: ExtensionAPI) {
397
334
  ? text.slice(colonIndex + 1)
398
335
  : text.slice(colonIndex + 1, spaceIndex);
399
336
  const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1).trim();
400
-
401
- // Determine separator: comma for /skills:, plus for /skill:
402
337
  const separator = text.startsWith("/skills:") ? "," : "+";
403
338
  const skillNames = skillListRaw
404
339
  .split(separator)
@@ -407,21 +342,28 @@ export default function (pi: ExtensionAPI) {
407
342
 
408
343
  if (skillNames.length === 0) return { action: "continue" };
409
344
 
410
- // Resolve skills from the full skill list
411
- const available = getSkills(_ctx.cwd);
412
- const nameToSkill = new Map(available.map((s) => [s.name, s]));
413
- const selectedSkills = skillNames
414
- .map((name) => nameToSkill.get(name))
415
- .filter((s): s is SkillInfo => s !== undefined);
416
-
417
- const combined = buildCombinedSkills(
418
- selectedSkills.length > 0 ? selectedSkills : [],
419
- _ctx.cwd,
420
- args || undefined,
345
+ const available = getSkills(ctx.cwd);
346
+ const { skills: selected } = resolveSelectedSkillsWithConflicts(
347
+ skillNames,
348
+ available,
421
349
  );
422
-
423
- if (!combined.includes("<skill ")) return { action: "continue" };
424
-
425
- return { action: "transform", text: combined };
350
+ const blocks = selected
351
+ .map((s) => resolveAndReadLegacySkill(s.name, s.filePath, ctx.cwd))
352
+ .filter((b): b is string => b !== null);
353
+
354
+ if (blocks.length === 0) return { action: "continue" };
355
+
356
+ const wrapped = [
357
+ `<manually_attached_skills count="${blocks.length}">`,
358
+ ...blocks,
359
+ args ? `\n<user_query>\n${args}\n</user_query>` : "",
360
+ "</manually_attached_skills>",
361
+ ]
362
+ .filter(Boolean)
363
+ .join("\n\n");
364
+
365
+ return { action: "transform", text: wrapped };
426
366
  });
427
367
  }
368
+
369
+ export { DEFAULT_BUNDLES };