gsd-pi 2.29.0-dev.49d972f → 2.29.0-dev.6a38b5d

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.
Files changed (98) hide show
  1. package/README.md +24 -17
  2. package/dist/resources/extensions/bg-shell/process-manager.ts +13 -0
  3. package/dist/resources/extensions/gsd/auto-dashboard.ts +186 -65
  4. package/dist/resources/extensions/gsd/auto-post-unit.ts +5 -2
  5. package/dist/resources/extensions/gsd/commands-prefs-wizard.ts +44 -14
  6. package/dist/resources/extensions/gsd/commands-workflow-templates.ts +544 -0
  7. package/dist/resources/extensions/gsd/commands.ts +53 -1
  8. package/dist/resources/extensions/gsd/prompts/workflow-start.md +28 -0
  9. package/dist/resources/extensions/gsd/tests/extension-selector-separator.test.ts +60 -38
  10. package/dist/resources/extensions/gsd/tests/workflow-templates.test.ts +173 -0
  11. package/dist/resources/extensions/gsd/workflow-templates/bugfix.md +87 -0
  12. package/dist/resources/extensions/gsd/workflow-templates/dep-upgrade.md +74 -0
  13. package/dist/resources/extensions/gsd/workflow-templates/full-project.md +41 -0
  14. package/dist/resources/extensions/gsd/workflow-templates/hotfix.md +45 -0
  15. package/dist/resources/extensions/gsd/workflow-templates/refactor.md +83 -0
  16. package/dist/resources/extensions/gsd/workflow-templates/registry.json +85 -0
  17. package/dist/resources/extensions/gsd/workflow-templates/security-audit.md +73 -0
  18. package/dist/resources/extensions/gsd/workflow-templates/small-feature.md +81 -0
  19. package/dist/resources/extensions/gsd/workflow-templates/spike.md +69 -0
  20. package/dist/resources/extensions/gsd/workflow-templates.ts +241 -0
  21. package/dist/resources/extensions/mcp-client/index.ts +459 -0
  22. package/dist/resources/skills/create-skill/SKILL.md +184 -0
  23. package/dist/resources/skills/create-skill/references/api-security.md +226 -0
  24. package/dist/resources/skills/create-skill/references/be-clear-and-direct.md +531 -0
  25. package/dist/resources/skills/create-skill/references/common-patterns.md +595 -0
  26. package/dist/resources/skills/create-skill/references/core-principles.md +437 -0
  27. package/dist/resources/skills/create-skill/references/executable-code.md +175 -0
  28. package/dist/resources/skills/create-skill/references/gsd-skill-ecosystem.md +68 -0
  29. package/dist/resources/skills/create-skill/references/iteration-and-testing.md +474 -0
  30. package/dist/resources/skills/create-skill/references/recommended-structure.md +168 -0
  31. package/dist/resources/skills/create-skill/references/skill-structure.md +372 -0
  32. package/dist/resources/skills/create-skill/references/use-xml-tags.md +466 -0
  33. package/dist/resources/skills/create-skill/references/using-scripts.md +113 -0
  34. package/dist/resources/skills/create-skill/references/using-templates.md +112 -0
  35. package/dist/resources/skills/create-skill/references/workflows-and-validation.md +510 -0
  36. package/dist/resources/skills/create-skill/templates/router-skill.md +73 -0
  37. package/dist/resources/skills/create-skill/templates/simple-skill.md +33 -0
  38. package/dist/resources/skills/create-skill/workflows/add-reference.md +96 -0
  39. package/dist/resources/skills/create-skill/workflows/add-script.md +93 -0
  40. package/dist/resources/skills/create-skill/workflows/add-template.md +74 -0
  41. package/dist/resources/skills/create-skill/workflows/add-workflow.md +120 -0
  42. package/dist/resources/skills/create-skill/workflows/audit-skill.md +148 -0
  43. package/dist/resources/skills/create-skill/workflows/create-new-skill.md +196 -0
  44. package/dist/resources/skills/create-skill/workflows/get-guidance.md +121 -0
  45. package/dist/resources/skills/create-skill/workflows/upgrade-to-router.md +161 -0
  46. package/dist/resources/skills/create-skill/workflows/verify-skill.md +204 -0
  47. package/package.json +1 -1
  48. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  49. package/packages/pi-coding-agent/dist/core/extensions/loader.js +13 -0
  50. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  51. package/packages/pi-coding-agent/src/core/extensions/loader.ts +13 -0
  52. package/src/resources/extensions/bg-shell/process-manager.ts +13 -0
  53. package/src/resources/extensions/gsd/auto-dashboard.ts +186 -65
  54. package/src/resources/extensions/gsd/auto-post-unit.ts +5 -2
  55. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +44 -14
  56. package/src/resources/extensions/gsd/commands-workflow-templates.ts +544 -0
  57. package/src/resources/extensions/gsd/commands.ts +53 -1
  58. package/src/resources/extensions/gsd/prompts/workflow-start.md +28 -0
  59. package/src/resources/extensions/gsd/tests/extension-selector-separator.test.ts +60 -38
  60. package/src/resources/extensions/gsd/tests/workflow-templates.test.ts +173 -0
  61. package/src/resources/extensions/gsd/workflow-templates/bugfix.md +87 -0
  62. package/src/resources/extensions/gsd/workflow-templates/dep-upgrade.md +74 -0
  63. package/src/resources/extensions/gsd/workflow-templates/full-project.md +41 -0
  64. package/src/resources/extensions/gsd/workflow-templates/hotfix.md +45 -0
  65. package/src/resources/extensions/gsd/workflow-templates/refactor.md +83 -0
  66. package/src/resources/extensions/gsd/workflow-templates/registry.json +85 -0
  67. package/src/resources/extensions/gsd/workflow-templates/security-audit.md +73 -0
  68. package/src/resources/extensions/gsd/workflow-templates/small-feature.md +81 -0
  69. package/src/resources/extensions/gsd/workflow-templates/spike.md +69 -0
  70. package/src/resources/extensions/gsd/workflow-templates.ts +241 -0
  71. package/src/resources/extensions/mcp-client/index.ts +459 -0
  72. package/src/resources/skills/create-skill/SKILL.md +184 -0
  73. package/src/resources/skills/create-skill/references/api-security.md +226 -0
  74. package/src/resources/skills/create-skill/references/be-clear-and-direct.md +531 -0
  75. package/src/resources/skills/create-skill/references/common-patterns.md +595 -0
  76. package/src/resources/skills/create-skill/references/core-principles.md +437 -0
  77. package/src/resources/skills/create-skill/references/executable-code.md +175 -0
  78. package/src/resources/skills/create-skill/references/gsd-skill-ecosystem.md +68 -0
  79. package/src/resources/skills/create-skill/references/iteration-and-testing.md +474 -0
  80. package/src/resources/skills/create-skill/references/recommended-structure.md +168 -0
  81. package/src/resources/skills/create-skill/references/skill-structure.md +372 -0
  82. package/src/resources/skills/create-skill/references/use-xml-tags.md +466 -0
  83. package/src/resources/skills/create-skill/references/using-scripts.md +113 -0
  84. package/src/resources/skills/create-skill/references/using-templates.md +112 -0
  85. package/src/resources/skills/create-skill/references/workflows-and-validation.md +510 -0
  86. package/src/resources/skills/create-skill/templates/router-skill.md +73 -0
  87. package/src/resources/skills/create-skill/templates/simple-skill.md +33 -0
  88. package/src/resources/skills/create-skill/workflows/add-reference.md +96 -0
  89. package/src/resources/skills/create-skill/workflows/add-script.md +93 -0
  90. package/src/resources/skills/create-skill/workflows/add-template.md +74 -0
  91. package/src/resources/skills/create-skill/workflows/add-workflow.md +120 -0
  92. package/src/resources/skills/create-skill/workflows/audit-skill.md +148 -0
  93. package/src/resources/skills/create-skill/workflows/create-new-skill.md +196 -0
  94. package/src/resources/skills/create-skill/workflows/get-guidance.md +121 -0
  95. package/src/resources/skills/create-skill/workflows/upgrade-to-router.md +161 -0
  96. package/src/resources/skills/create-skill/workflows/verify-skill.md +204 -0
  97. package/dist/resources/extensions/mcporter/index.ts +0 -525
  98. package/src/resources/extensions/mcporter/index.ts +0 -525
@@ -0,0 +1,459 @@
1
+ /**
2
+ * MCP Client Extension — Native MCP server integration for pi
3
+ *
4
+ * Provides on-demand access to MCP servers configured in project files
5
+ * (.mcp.json, .gsd/mcp.json) using the @modelcontextprotocol/sdk Client
6
+ * directly — no external CLI dependency required.
7
+ *
8
+ * Three tools:
9
+ * mcp_servers — List available MCP servers from config files
10
+ * mcp_discover — Get tool signatures for a specific server (lazy connect)
11
+ * mcp_call — Call a tool on an MCP server (lazy connect)
12
+ */
13
+
14
+ import type { ExtensionAPI } from "@gsd/pi-coding-agent";
15
+ import {
16
+ truncateHead,
17
+ DEFAULT_MAX_BYTES,
18
+ DEFAULT_MAX_LINES,
19
+ formatSize,
20
+ } from "@gsd/pi-coding-agent";
21
+ import { Text } from "@gsd/pi-tui";
22
+ import { Type } from "@sinclair/typebox";
23
+ import { Client } from "@modelcontextprotocol/sdk/client";
24
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
25
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
26
+ import { readFileSync, existsSync } from "node:fs";
27
+ import { join } from "node:path";
28
+
29
+ // ─── Types ────────────────────────────────────────────────────────────────────
30
+
31
+ interface McpServerConfig {
32
+ name: string;
33
+ transport: "stdio" | "http" | "unknown";
34
+ command?: string;
35
+ args?: string[];
36
+ env?: Record<string, string>;
37
+ url?: string;
38
+ cwd?: string;
39
+ }
40
+
41
+ interface McpToolSchema {
42
+ name: string;
43
+ description: string;
44
+ inputSchema?: Record<string, unknown>;
45
+ }
46
+
47
+ interface ManagedConnection {
48
+ client: Client;
49
+ transport: StdioClientTransport | StreamableHTTPClientTransport;
50
+ }
51
+
52
+ // ─── Connection Manager ───────────────────────────────────────────────────────
53
+
54
+ const connections = new Map<string, ManagedConnection>();
55
+ let configCache: McpServerConfig[] | null = null;
56
+ const toolCache = new Map<string, McpToolSchema[]>();
57
+
58
+ function readConfigs(): McpServerConfig[] {
59
+ if (configCache) return configCache;
60
+
61
+ const servers: McpServerConfig[] = [];
62
+ const seen = new Set<string>();
63
+ const configPaths = [
64
+ join(process.cwd(), ".mcp.json"),
65
+ join(process.cwd(), ".gsd", "mcp.json"),
66
+ ];
67
+
68
+ for (const configPath of configPaths) {
69
+ try {
70
+ if (!existsSync(configPath)) continue;
71
+ const raw = readFileSync(configPath, "utf-8");
72
+ const data = JSON.parse(raw) as Record<string, unknown>;
73
+ const mcpServers = (data.mcpServers ?? data.servers) as
74
+ | Record<string, Record<string, unknown>>
75
+ | undefined;
76
+ if (!mcpServers || typeof mcpServers !== "object") continue;
77
+
78
+ for (const [name, config] of Object.entries(mcpServers)) {
79
+ if (seen.has(name)) continue;
80
+ seen.add(name);
81
+
82
+ const hasCommand = typeof config.command === "string";
83
+ const hasUrl = typeof config.url === "string";
84
+ const transport: McpServerConfig["transport"] = hasCommand
85
+ ? "stdio"
86
+ : hasUrl
87
+ ? "http"
88
+ : "unknown";
89
+
90
+ servers.push({
91
+ name,
92
+ transport,
93
+ ...(hasCommand && {
94
+ command: config.command as string,
95
+ args: Array.isArray(config.args) ? (config.args as string[]) : undefined,
96
+ env: config.env && typeof config.env === "object"
97
+ ? (config.env as Record<string, string>)
98
+ : undefined,
99
+ cwd: typeof config.cwd === "string" ? config.cwd : undefined,
100
+ }),
101
+ ...(hasUrl && { url: config.url as string }),
102
+ });
103
+ }
104
+ } catch {
105
+ // Non-fatal — config file may not exist or be malformed
106
+ }
107
+ }
108
+
109
+ configCache = servers;
110
+ return servers;
111
+ }
112
+
113
+ function getServerConfig(name: string): McpServerConfig | undefined {
114
+ return readConfigs().find((s) => s.name === name);
115
+ }
116
+
117
+ async function getOrConnect(name: string, signal?: AbortSignal): Promise<Client> {
118
+ const existing = connections.get(name);
119
+ if (existing) return existing.client;
120
+
121
+ const config = getServerConfig(name);
122
+ if (!config) throw new Error(`Unknown MCP server: "${name}". Use mcp_servers to list available servers.`);
123
+
124
+ const client = new Client({ name: "gsd", version: "1.0.0" });
125
+ let transport: StdioClientTransport | StreamableHTTPClientTransport;
126
+
127
+ if (config.transport === "stdio" && config.command) {
128
+ transport = new StdioClientTransport({
129
+ command: config.command,
130
+ args: config.args,
131
+ env: config.env ? { ...process.env, ...config.env } as Record<string, string> : undefined,
132
+ cwd: config.cwd,
133
+ stderr: "pipe",
134
+ });
135
+ } else if (config.transport === "http" && config.url) {
136
+ transport = new StreamableHTTPClientTransport(new URL(config.url));
137
+ } else {
138
+ throw new Error(`Server "${name}" has unsupported transport: ${config.transport}`);
139
+ }
140
+
141
+ await client.connect(transport, { signal, timeout: 30000 });
142
+ connections.set(name, { client, transport });
143
+ return client;
144
+ }
145
+
146
+ async function closeAll(): Promise<void> {
147
+ const closing = Array.from(connections.entries()).map(async ([name, conn]) => {
148
+ try {
149
+ await conn.client.close();
150
+ } catch {
151
+ // Best-effort cleanup
152
+ }
153
+ connections.delete(name);
154
+ });
155
+ await Promise.allSettled(closing);
156
+ toolCache.clear();
157
+ }
158
+
159
+ // ─── Formatters ───────────────────────────────────────────────────────────────
160
+
161
+ function formatServerList(servers: McpServerConfig[]): string {
162
+ if (servers.length === 0) return "No MCP servers configured. Add servers to .mcp.json or .gsd/mcp.json.";
163
+
164
+ const lines: string[] = [`${servers.length} MCP servers configured:\n`];
165
+
166
+ for (const s of servers) {
167
+ const connected = connections.has(s.name) ? "✓" : "○";
168
+ const cached = toolCache.get(s.name);
169
+ const toolCount = cached ? ` — ${cached.length} tools` : "";
170
+ lines.push(`${connected} ${s.name} (${s.transport})${toolCount}`);
171
+ }
172
+
173
+ lines.push("\nUse mcp_discover to see full tool schemas for a specific server.");
174
+ lines.push("Use mcp_call to invoke a tool: mcp_call(server, tool, args).");
175
+ return lines.join("\n");
176
+ }
177
+
178
+ function formatToolList(serverName: string, tools: McpToolSchema[]): string {
179
+ const lines: string[] = [`${serverName} — ${tools.length} tools:\n`];
180
+
181
+ for (const tool of tools) {
182
+ lines.push(`## ${tool.name}`);
183
+ if (tool.description) lines.push(tool.description);
184
+ if (tool.inputSchema) {
185
+ lines.push("```json");
186
+ lines.push(JSON.stringify(tool.inputSchema, null, 2));
187
+ lines.push("```");
188
+ }
189
+ lines.push("");
190
+ }
191
+
192
+ lines.push(`Call with: mcp_call(server="${serverName}", tool="<tool_name>", args={...})`);
193
+ return lines.join("\n");
194
+ }
195
+
196
+ // ─── Extension ────────────────────────────────────────────────────────────────
197
+
198
+ export default function (pi: ExtensionAPI) {
199
+ // ── mcp_servers ──────────────────────────────────────────────────────────
200
+
201
+ pi.registerTool({
202
+ name: "mcp_servers",
203
+ label: "MCP Servers",
204
+ description:
205
+ "List all available MCP servers configured in project files (.mcp.json, .gsd/mcp.json). " +
206
+ "Shows server names, transport type, and connection status. Use mcp_discover to get full tool schemas for a server.",
207
+ promptSnippet:
208
+ "List available MCP servers from project configuration",
209
+ promptGuidelines: [
210
+ "Call mcp_servers to see what MCP servers are available before trying to use one.",
211
+ "MCP servers provide external integrations (Twitter, Linear, Railway, etc.) via the Model Context Protocol.",
212
+ "After listing, use mcp_discover(server) to get tool schemas, then mcp_call(server, tool, args) to invoke.",
213
+ ],
214
+ parameters: Type.Object({
215
+ refresh: Type.Optional(
216
+ Type.Boolean({ description: "Force refresh the server list (default: use cache)" }),
217
+ ),
218
+ }),
219
+
220
+ async execute(_id, params) {
221
+ if (params.refresh) configCache = null;
222
+
223
+ const servers = readConfigs();
224
+ return {
225
+ content: [{ type: "text", text: formatServerList(servers) }],
226
+ details: {
227
+ serverCount: servers.length,
228
+ cached: !params.refresh && configCache !== null,
229
+ },
230
+ };
231
+ },
232
+
233
+ renderCall(args, theme) {
234
+ let text = theme.fg("toolTitle", theme.bold("mcp_servers"));
235
+ if (args.refresh) text += theme.fg("warning", " (refresh)");
236
+ return new Text(text, 0, 0);
237
+ },
238
+
239
+ renderResult(result, { isPartial }, theme) {
240
+ if (isPartial) return new Text(theme.fg("warning", "Reading MCP config..."), 0, 0);
241
+ const d = result.details as { serverCount: number } | undefined;
242
+ return new Text(
243
+ theme.fg("success", `${d?.serverCount ?? 0} servers configured`),
244
+ 0,
245
+ 0,
246
+ );
247
+ },
248
+ });
249
+
250
+ // ── mcp_discover ─────────────────────────────────────────────────────────
251
+
252
+ pi.registerTool({
253
+ name: "mcp_discover",
254
+ label: "MCP Discover",
255
+ description:
256
+ "Get detailed tool signatures and JSON schemas for a specific MCP server. " +
257
+ "Connects to the server on first call (lazy connection). " +
258
+ "Use this to understand what tools a server provides and what arguments they accept " +
259
+ "before calling them with mcp_call.",
260
+ promptSnippet:
261
+ "Get tool schemas for a specific MCP server before calling its tools",
262
+ promptGuidelines: [
263
+ "Call mcp_discover with a server name to see the full tool signatures before calling mcp_call.",
264
+ "The schemas show required and optional parameters with types and descriptions.",
265
+ ],
266
+ parameters: Type.Object({
267
+ server: Type.String({
268
+ description:
269
+ "MCP server name (from mcp_servers output), e.g. 'railway', 'twitter-mcp', 'linear'",
270
+ }),
271
+ }),
272
+
273
+ async execute(_id, params, signal) {
274
+ try {
275
+ // Return cached tools if available
276
+ const cached = toolCache.get(params.server);
277
+ if (cached) {
278
+ const text = formatToolList(params.server, cached);
279
+ const truncation = truncateHead(text, { maxLines: DEFAULT_MAX_LINES, maxBytes: DEFAULT_MAX_BYTES });
280
+ let finalText = truncation.content;
281
+ if (truncation.truncated) {
282
+ finalText += `\n\n[Truncated: ${truncation.outputLines}/${truncation.totalLines} lines (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)})]`;
283
+ }
284
+ return {
285
+ content: [{ type: "text", text: finalText }],
286
+ details: { server: params.server, toolCount: cached.length, cached: true },
287
+ };
288
+ }
289
+
290
+ const client = await getOrConnect(params.server, signal);
291
+ const result = await client.listTools(undefined, { signal, timeout: 30000 });
292
+ const tools: McpToolSchema[] = (result.tools ?? []).map((t) => ({
293
+ name: t.name,
294
+ description: t.description ?? "",
295
+ inputSchema: t.inputSchema as Record<string, unknown> | undefined,
296
+ }));
297
+ toolCache.set(params.server, tools);
298
+
299
+ const text = formatToolList(params.server, tools);
300
+ const truncation = truncateHead(text, { maxLines: DEFAULT_MAX_LINES, maxBytes: DEFAULT_MAX_BYTES });
301
+ let finalText = truncation.content;
302
+ if (truncation.truncated) {
303
+ finalText += `\n\n[Truncated: ${truncation.outputLines}/${truncation.totalLines} lines (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)})]`;
304
+ }
305
+
306
+ return {
307
+ content: [{ type: "text", text: finalText }],
308
+ details: { server: params.server, toolCount: tools.length, cached: false },
309
+ };
310
+ } catch (err: unknown) {
311
+ const msg = err instanceof Error ? err.message : String(err);
312
+ throw new Error(`Failed to discover tools for "${params.server}": ${msg}`);
313
+ }
314
+ },
315
+
316
+ renderCall(args, theme) {
317
+ let text = theme.fg("toolTitle", theme.bold("mcp_discover "));
318
+ text += theme.fg("accent", args.server);
319
+ return new Text(text, 0, 0);
320
+ },
321
+
322
+ renderResult(result, { isPartial }, theme) {
323
+ if (isPartial)
324
+ return new Text(theme.fg("warning", "Discovering tools..."), 0, 0);
325
+ const d = result.details as { server: string; toolCount: number } | undefined;
326
+ return new Text(
327
+ theme.fg("success", `${d?.toolCount ?? 0} tools`) +
328
+ theme.fg("dim", ` · ${d?.server}`),
329
+ 0,
330
+ 0,
331
+ );
332
+ },
333
+ });
334
+
335
+ // ── mcp_call ─────────────────────────────────────────────────────────────
336
+
337
+ pi.registerTool({
338
+ name: "mcp_call",
339
+ label: "MCP Call",
340
+ description:
341
+ "Call a tool on an MCP server. Provide the server name, tool name, and arguments. " +
342
+ "Connects to the server on first call (lazy connection). " +
343
+ "Use mcp_discover first to see available tools and their required arguments.",
344
+ promptSnippet: "Call a tool on an MCP server",
345
+ promptGuidelines: [
346
+ "Always use mcp_discover first to understand the tool's parameters before calling mcp_call.",
347
+ "Arguments are passed as a JSON object matching the tool's input schema.",
348
+ ],
349
+ parameters: Type.Object({
350
+ server: Type.String({
351
+ description: "MCP server name, e.g. 'railway', 'twitter-mcp'",
352
+ }),
353
+ tool: Type.String({
354
+ description: "Tool name on that server, e.g. 'railway_list_projects'",
355
+ }),
356
+ args: Type.Optional(
357
+ Type.Record(Type.String(), Type.Unknown(), {
358
+ description:
359
+ "Tool arguments as key-value pairs matching the tool's input schema",
360
+ }),
361
+ ),
362
+ }),
363
+
364
+ async execute(_id, params, signal) {
365
+ try {
366
+ const client = await getOrConnect(params.server, signal);
367
+ const result = await client.callTool(
368
+ { name: params.tool, arguments: params.args ?? {} },
369
+ undefined,
370
+ { signal, timeout: 60000 },
371
+ );
372
+
373
+ // Serialize result content to text
374
+ const contentItems = result.content as Array<{ type: string; text?: string }>;
375
+ const raw = contentItems
376
+ .map((c) => (c.type === "text" ? c.text ?? "" : JSON.stringify(c)))
377
+ .join("\n");
378
+
379
+ const truncation = truncateHead(raw, { maxLines: DEFAULT_MAX_LINES, maxBytes: DEFAULT_MAX_BYTES });
380
+ let finalText = truncation.content;
381
+ if (truncation.truncated) {
382
+ finalText += `\n\n[Output truncated: ${truncation.outputLines}/${truncation.totalLines} lines (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)})]`;
383
+ }
384
+
385
+ return {
386
+ content: [{ type: "text", text: finalText }],
387
+ details: {
388
+ server: params.server,
389
+ tool: params.tool,
390
+ charCount: finalText.length,
391
+ truncated: truncation.truncated,
392
+ },
393
+ };
394
+ } catch (err: unknown) {
395
+ const msg = err instanceof Error ? err.message : String(err);
396
+ throw new Error(`MCP call failed: ${params.server}.${params.tool}\n${msg}`);
397
+ }
398
+ },
399
+
400
+ renderCall(args, theme) {
401
+ let text = theme.fg("toolTitle", theme.bold("mcp_call "));
402
+ text += theme.fg("accent", `${args.server}.${args.tool}`);
403
+ if (args.args && Object.keys(args.args).length > 0) {
404
+ const preview = Object.entries(args.args)
405
+ .slice(0, 3)
406
+ .map(([k, v]) => {
407
+ const val = typeof v === "string" ? v : JSON.stringify(v);
408
+ return `${k}:${val.length > 30 ? val.slice(0, 30) + "…" : val}`;
409
+ })
410
+ .join(" ");
411
+ text += " " + theme.fg("muted", preview);
412
+ }
413
+ return new Text(text, 0, 0);
414
+ },
415
+
416
+ renderResult(result, { isPartial, expanded }, theme) {
417
+ if (isPartial) return new Text(theme.fg("warning", "Calling MCP tool..."), 0, 0);
418
+
419
+ const d = result.details as {
420
+ server: string;
421
+ tool: string;
422
+ charCount: number;
423
+ truncated: boolean;
424
+ } | undefined;
425
+
426
+ let text = theme.fg("success", `✓ ${d?.server}.${d?.tool}`);
427
+ text += theme.fg("dim", ` · ${(d?.charCount ?? 0).toLocaleString()} chars`);
428
+ if (d?.truncated) text += theme.fg("warning", " · truncated");
429
+
430
+ if (expanded) {
431
+ const content = result.content[0];
432
+ if (content?.type === "text") {
433
+ const preview = content.text.split("\n").slice(0, 15).join("\n");
434
+ text += "\n\n" + theme.fg("dim", preview);
435
+ }
436
+ }
437
+
438
+ return new Text(text, 0, 0);
439
+ },
440
+ });
441
+
442
+ // ── Lifecycle ─────────────────────────────────────────────────────────────
443
+
444
+ pi.on("session_start", async (_event, ctx) => {
445
+ const servers = readConfigs();
446
+ if (servers.length > 0) {
447
+ ctx.ui.notify(`MCP client ready — ${servers.length} server(s) configured`, "info");
448
+ }
449
+ });
450
+
451
+ pi.on("session_shutdown", async () => {
452
+ await closeAll();
453
+ });
454
+
455
+ pi.on("session_switch", async () => {
456
+ await closeAll();
457
+ configCache = null;
458
+ });
459
+ }
@@ -0,0 +1,184 @@
1
+ ---
2
+ name: create-skill
3
+ description: Expert guidance for creating, writing, building, and refining GSD skills. Use when working with SKILL.md files, authoring new skills, improving existing skills, or understanding skill structure and best practices.
4
+ ---
5
+
6
+ <essential_principles>
7
+ ## How Skills Work
8
+
9
+ Skills are modular, filesystem-based capabilities that provide domain expertise on demand. This skill teaches how to create effective skills.
10
+
11
+ ### 1. Skills Are Prompts
12
+
13
+ All prompting best practices apply. Be clear, be direct, use XML structure. Assume Claude is smart - only add context Claude doesn't have.
14
+
15
+ ### 2. SKILL.md Is Always Loaded
16
+
17
+ When a skill is invoked, Claude reads SKILL.md. Use this guarantee:
18
+ - Essential principles go in SKILL.md (can't be skipped)
19
+ - Workflow-specific content goes in workflows/
20
+ - Reusable knowledge goes in references/
21
+
22
+ ### 3. Router Pattern for Complex Skills
23
+
24
+ ```
25
+ skill-name/
26
+ ├── SKILL.md # Router + principles
27
+ ├── workflows/ # Step-by-step procedures (FOLLOW)
28
+ ├── references/ # Domain knowledge (READ)
29
+ ├── templates/ # Output structures (COPY + FILL)
30
+ └── scripts/ # Reusable code (EXECUTE)
31
+ ```
32
+
33
+ SKILL.md asks "what do you want to do?" → routes to workflow → workflow specifies which references to read.
34
+
35
+ **When to use each folder:**
36
+ - **workflows/** - Multi-step procedures Claude follows
37
+ - **references/** - Domain knowledge Claude reads for context
38
+ - **templates/** - Consistent output structures Claude copies and fills (plans, specs, configs)
39
+ - **scripts/** - Executable code Claude runs as-is (deploy, setup, API calls)
40
+
41
+ ### 4. Pure XML Structure
42
+
43
+ No markdown headings (#, ##, ###) in skill body. Use semantic XML tags:
44
+ ```xml
45
+ <objective>...</objective>
46
+ <process>...</process>
47
+ <success_criteria>...</success_criteria>
48
+ ```
49
+
50
+ Keep markdown formatting within content (bold, lists, code blocks).
51
+
52
+ ### 5. Progressive Disclosure
53
+
54
+ SKILL.md under 500 lines. Split detailed content into reference files. Load only what's needed for the current workflow.
55
+ </essential_principles>
56
+
57
+ <routing>
58
+ ## Understanding User Intent
59
+
60
+ Based on the user's message, route directly to the appropriate workflow:
61
+
62
+ **Creating new skills:**
63
+ - Domain expertise (exhaustive knowledge base) → **Use `create-domain-expertise` skill instead** (separate skill with batched subagent orchestration)
64
+ - Task-execution skill (does specific things) → workflows/create-new-skill.md
65
+
66
+ **Working with existing skills:**
67
+ - Audit, review, check → workflows/audit-skill.md
68
+ - Verify content is current → workflows/verify-skill.md
69
+ - Add workflow → workflows/add-workflow.md
70
+ - Add reference → workflows/add-reference.md
71
+ - Add template → workflows/add-template.md
72
+ - Add script → workflows/add-script.md
73
+ - Upgrade to router pattern → workflows/upgrade-to-router.md
74
+
75
+ **Need help deciding:**
76
+ - General guidance → workflows/get-guidance.md
77
+
78
+ **If user intent is unclear, ask minimal clarifying questions:**
79
+ - "Create a MIDI skill" → "Task-execution skill (does MIDI tasks) or domain expertise (complete MIDI knowledge base)?"
80
+ - "Work on my skill" → "Which skill? What do you want to do with it?"
81
+
82
+ Then proceed directly to the workflow.
83
+ </routing>
84
+
85
+ <quick_reference>
86
+ ## Skill Structure Quick Reference
87
+
88
+ **Skill directories:**
89
+ - Global: `~/.gsd/agent/skills/{skill-name}/`
90
+ - Project-local: `.pi/agent/skills/{skill-name}/`
91
+
92
+ **Simple skill (single file):**
93
+ ```yaml
94
+ ---
95
+ name: skill-name
96
+ description: What it does and when to use it.
97
+ ---
98
+
99
+ <objective>What this skill does</objective>
100
+ <quick_start>Immediate actionable guidance</quick_start>
101
+ <process>Step-by-step procedure</process>
102
+ <success_criteria>How to know it worked</success_criteria>
103
+ ```
104
+
105
+ **Complex skill (router pattern):**
106
+ ```
107
+ SKILL.md:
108
+ <essential_principles> - Always applies
109
+ <intake> - Question to ask
110
+ <routing> - Maps answers to workflows
111
+
112
+ workflows/:
113
+ <required_reading> - Which refs to load
114
+ <process> - Steps
115
+ <success_criteria> - Done when...
116
+
117
+ references/:
118
+ Domain knowledge, patterns, examples
119
+
120
+ templates/:
121
+ Output structures Claude copies and fills
122
+ (plans, specs, configs, documents)
123
+
124
+ scripts/:
125
+ Executable code Claude runs as-is
126
+ (deploy, setup, API calls, data processing)
127
+ ```
128
+ </quick_reference>
129
+
130
+ <reference_index>
131
+ ## Domain Knowledge
132
+
133
+ All in `references/`:
134
+
135
+ **Structure:** recommended-structure.md, skill-structure.md
136
+ **Principles:** core-principles.md, be-clear-and-direct.md, use-xml-tags.md
137
+ **Patterns:** common-patterns.md, workflows-and-validation.md
138
+ **Assets:** using-templates.md, using-scripts.md
139
+ **Advanced:** executable-code.md, api-security.md, iteration-and-testing.md
140
+ **GSD-specific:** gsd-skill-ecosystem.md
141
+ </reference_index>
142
+
143
+ <workflows_index>
144
+ ## Workflows
145
+
146
+ All in `workflows/`:
147
+
148
+ | Workflow | Purpose |
149
+ |----------|---------|
150
+ | create-new-skill.md | Build a task-execution skill from scratch |
151
+ | audit-skill.md | Analyze skill against best practices |
152
+ | verify-skill.md | Check if content is still accurate |
153
+ | add-workflow.md | Add a workflow to existing skill |
154
+ | add-reference.md | Add a reference to existing skill |
155
+ | add-template.md | Add a template to existing skill |
156
+ | add-script.md | Add a script to existing skill |
157
+ | upgrade-to-router.md | Convert simple skill to router pattern |
158
+ | get-guidance.md | Help decide what kind of skill to build |
159
+ </workflows_index>
160
+
161
+ <yaml_requirements>
162
+ ## YAML Frontmatter
163
+
164
+ Required fields:
165
+ ```yaml
166
+ ---
167
+ name: skill-name # lowercase-with-hyphens, matches directory
168
+ description: ... # What it does AND when to use it (third person)
169
+ ---
170
+ ```
171
+
172
+ Name conventions: `create-*`, `manage-*`, `setup-*`, `generate-*`, `build-*`
173
+ </yaml_requirements>
174
+
175
+ <success_criteria>
176
+ A well-structured skill:
177
+ - Has valid YAML frontmatter
178
+ - Uses pure XML structure (no markdown headings in body)
179
+ - Has essential principles inline in SKILL.md
180
+ - Routes directly to appropriate workflows based on user intent
181
+ - Keeps SKILL.md under 500 lines
182
+ - Asks minimal clarifying questions only when truly needed
183
+ - Has been tested with real usage
184
+ </success_criteria>