@lushly-dev/afd-server 0.1.0

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 (43) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +381 -0
  3. package/dist/bootstrap/afd-docs.d.ts +27 -0
  4. package/dist/bootstrap/afd-docs.d.ts.map +1 -0
  5. package/dist/bootstrap/afd-docs.js +93 -0
  6. package/dist/bootstrap/afd-docs.js.map +1 -0
  7. package/dist/bootstrap/afd-help.d.ts +39 -0
  8. package/dist/bootstrap/afd-help.d.ts.map +1 -0
  9. package/dist/bootstrap/afd-help.js +77 -0
  10. package/dist/bootstrap/afd-help.js.map +1 -0
  11. package/dist/bootstrap/afd-schema.d.ts +34 -0
  12. package/dist/bootstrap/afd-schema.d.ts.map +1 -0
  13. package/dist/bootstrap/afd-schema.js +78 -0
  14. package/dist/bootstrap/afd-schema.js.map +1 -0
  15. package/dist/bootstrap/index.d.ts +11 -0
  16. package/dist/bootstrap/index.d.ts.map +1 -0
  17. package/dist/bootstrap/index.js +11 -0
  18. package/dist/bootstrap/index.js.map +1 -0
  19. package/dist/bootstrap/registry.d.ts +17 -0
  20. package/dist/bootstrap/registry.d.ts.map +1 -0
  21. package/dist/bootstrap/registry.js +23 -0
  22. package/dist/bootstrap/registry.js.map +1 -0
  23. package/dist/index.d.ts +54 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +60 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/middleware.d.ts +125 -0
  28. package/dist/middleware.d.ts.map +1 -0
  29. package/dist/middleware.js +182 -0
  30. package/dist/middleware.js.map +1 -0
  31. package/dist/schema.d.ts +105 -0
  32. package/dist/schema.d.ts.map +1 -0
  33. package/dist/schema.js +132 -0
  34. package/dist/schema.js.map +1 -0
  35. package/dist/server.d.ts +141 -0
  36. package/dist/server.d.ts.map +1 -0
  37. package/dist/server.js +846 -0
  38. package/dist/server.js.map +1 -0
  39. package/dist/validation.d.ts +137 -0
  40. package/dist/validation.d.ts.map +1 -0
  41. package/dist/validation.js +182 -0
  42. package/dist/validation.js.map +1 -0
  43. package/package.json +48 -0
package/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lushly
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ NOTE: This license applies to the compiled npm packages (dist/).
26
+ Source code repository access is separate and not included.
package/README.md ADDED
@@ -0,0 +1,381 @@
1
+ # @afd/server
2
+
3
+ Server-side utilities for building AFD-compliant MCP servers with Zod validation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @afd/server
9
+ # or
10
+ pnpm add @afd/server
11
+ ```
12
+
13
+ ## Features
14
+
15
+ - **Zod-based Command Definition** - Define commands with Zod schemas for type-safe validation
16
+ - **Auto JSON Schema Generation** - Automatic conversion to JSON Schema for MCP tool definitions
17
+ - **Multiple Transport Support** - stdio for IDE/agent integration, HTTP/SSE for browser clients
18
+ - **Auto Transport Detection** - Automatically selects the right transport based on environment
19
+ - **Built-in Validation** - Automatic input validation before handler execution
20
+ - **Middleware System** - Logging, tracing, rate limiting, and custom middleware
21
+ - **Full TypeScript Support** - Complete type inference from Zod schemas
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import { z } from 'zod';
27
+ import { defineCommand, createMcpServer, success, failure } from '@afd/server';
28
+
29
+ // Define a command with Zod schema
30
+ const greet = defineCommand({
31
+ name: 'greet',
32
+ description: 'Greet a user by name',
33
+ category: 'demo',
34
+ input: z.object({
35
+ name: z.string().min(1, 'Name is required'),
36
+ formal: z.boolean().default(false),
37
+ }),
38
+
39
+ async handler(input) {
40
+ const greeting = input.formal
41
+ ? `Good day, ${input.name}.`
42
+ : `Hello, ${input.name}!`;
43
+
44
+ return success({ greeting }, {
45
+ reasoning: `Generated ${input.formal ? 'formal' : 'casual'} greeting`,
46
+ confidence: 1.0,
47
+ });
48
+ },
49
+ });
50
+
51
+ // Create and start the server (auto-detects transport)
52
+ const server = createMcpServer({
53
+ name: 'my-server',
54
+ version: '1.0.0',
55
+ commands: [greet],
56
+ port: 3100,
57
+ });
58
+
59
+ await server.start();
60
+ console.log(`Server running at ${server.getUrl()}`);
61
+ ```
62
+
63
+ ## Transport Protocols
64
+
65
+ The server supports multiple transport protocols for different use cases:
66
+
67
+ ### Auto-Detection (Default)
68
+
69
+ By default, the server auto-detects the best transport based on the environment:
70
+
71
+ ```typescript
72
+ const server = createMcpServer({
73
+ name: 'my-server',
74
+ version: '1.0.0',
75
+ commands: [greet],
76
+ // transport: 'auto' is the default
77
+ });
78
+
79
+ // When stdin is piped (IDE/agent context): uses stdio
80
+ // When stdin is a TTY (interactive context): uses HTTP
81
+ ```
82
+
83
+ ### stdio Transport (IDE/Agent Integration)
84
+
85
+ Use stdio for integration with IDE MCP clients like Cursor, Claude Code, or Antigravity:
86
+
87
+ ```typescript
88
+ const server = createMcpServer({
89
+ name: 'my-server',
90
+ version: '1.0.0',
91
+ commands: [greet],
92
+ transport: 'stdio', // Explicit stdio mode
93
+ });
94
+
95
+ await server.start();
96
+ // Server reads JSON-RPC from stdin, writes to stdout
97
+ ```
98
+
99
+ In your IDE's MCP configuration (adjust the path to match your project):
100
+ ```json
101
+ {
102
+ "mcpServers": {
103
+ "my-server": {
104
+ "command": "node",
105
+ "args": ["path/to/your/server.js"]
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ ### HTTP Transport (Browser/Web UI)
112
+
113
+ Use HTTP for browser-based clients and web UIs:
114
+
115
+ ```typescript
116
+ const server = createMcpServer({
117
+ name: 'my-server',
118
+ version: '1.0.0',
119
+ commands: [greet],
120
+ transport: 'http', // Explicit HTTP mode
121
+ port: 3100,
122
+ });
123
+
124
+ await server.start();
125
+ console.log(`Server running at ${server.getUrl()}`);
126
+ // Exposes /sse, /message, /health endpoints
127
+ ```
128
+
129
+ ## Defining Commands
130
+
131
+ ### Basic Command
132
+
133
+ ```typescript
134
+ import { z } from 'zod';
135
+ import { defineCommand, success, failure } from '@afd/server';
136
+
137
+ const createUser = defineCommand({
138
+ name: 'user.create',
139
+ description: 'Create a new user',
140
+ category: 'users',
141
+ mutation: true,
142
+
143
+ input: z.object({
144
+ email: z.string().email(),
145
+ name: z.string().min(1).max(100),
146
+ role: z.enum(['admin', 'user', 'guest']).default('user'),
147
+ }),
148
+
149
+ async handler(input) {
150
+ // Your implementation
151
+ const user = await db.users.create(input);
152
+
153
+ return success(user, {
154
+ reasoning: `Created user ${user.email} with role ${user.role}`,
155
+ });
156
+ },
157
+ });
158
+ ```
159
+
160
+ ### Command with Error Handling
161
+
162
+ ```typescript
163
+ const getUser = defineCommand({
164
+ name: 'user.get',
165
+ description: 'Get a user by ID',
166
+ category: 'users',
167
+ errors: ['NOT_FOUND'],
168
+
169
+ input: z.object({
170
+ id: z.string().uuid(),
171
+ }),
172
+
173
+ async handler(input) {
174
+ const user = await db.users.find(input.id);
175
+
176
+ if (!user) {
177
+ return failure({
178
+ code: 'NOT_FOUND',
179
+ message: `User with ID "${input.id}" not found`,
180
+ suggestion: 'Check the ID or use user.list to find available users',
181
+ });
182
+ }
183
+
184
+ return success(user);
185
+ },
186
+ });
187
+ ```
188
+
189
+ ## Server Configuration
190
+
191
+ ```typescript
192
+ const server = createMcpServer({
193
+ // Required
194
+ name: 'my-server',
195
+ version: '1.0.0',
196
+ commands: [cmd1, cmd2, cmd3],
197
+
198
+ // Optional
199
+ port: 3100, // Default: 3100
200
+ host: 'localhost', // Default: localhost
201
+ cors: true, // Enable CORS (default: true)
202
+
203
+ // Middleware
204
+ middleware: [
205
+ createLoggingMiddleware(),
206
+ createTimingMiddleware({ slowThreshold: 1000 }),
207
+ ],
208
+
209
+ // Callbacks
210
+ onCommand(command, input, result) {
211
+ console.log(`Executed ${command}:`, result.success);
212
+ },
213
+ onError(error) {
214
+ console.error('Server error:', error);
215
+ },
216
+ });
217
+ ```
218
+
219
+ ## Middleware
220
+
221
+ ### Logging
222
+
223
+ ```typescript
224
+ import { createLoggingMiddleware } from '@afd/server';
225
+
226
+ const middleware = createLoggingMiddleware({
227
+ log: console.log, // Custom log function
228
+ logInput: false, // Don't log input (may contain sensitive data)
229
+ logResult: false, // Don't log full results
230
+ });
231
+ ```
232
+
233
+ ### Timing
234
+
235
+ ```typescript
236
+ import { createTimingMiddleware } from '@afd/server';
237
+
238
+ const middleware = createTimingMiddleware({
239
+ slowThreshold: 1000, // Warn if command takes > 1s
240
+ onSlow(command, durationMs) {
241
+ console.warn(`Slow command: ${command} took ${durationMs}ms`);
242
+ },
243
+ });
244
+ ```
245
+
246
+ ### OpenTelemetry Tracing
247
+
248
+ ```typescript
249
+ import { trace } from '@opentelemetry/api';
250
+ import { createTracingMiddleware } from '@afd/server';
251
+
252
+ const tracer = trace.getTracer('my-app');
253
+
254
+ const middleware = createTracingMiddleware({
255
+ tracer,
256
+ spanPrefix: 'command', // Span names: command.user.create, etc.
257
+ });
258
+ ```
259
+
260
+ ### Rate Limiting
261
+
262
+ ```typescript
263
+ import { createRateLimitMiddleware } from '@afd/server';
264
+
265
+ const middleware = createRateLimitMiddleware({
266
+ maxRequests: 100,
267
+ windowMs: 60000, // 100 requests per minute
268
+ keyFn: (context) => context.userId ?? 'anonymous',
269
+ });
270
+ ```
271
+
272
+ ### Custom Middleware
273
+
274
+ ```typescript
275
+ import type { CommandMiddleware } from '@afd/server';
276
+
277
+ const myMiddleware: CommandMiddleware = async (commandName, input, context, next) => {
278
+ console.log(`Before: ${commandName}`);
279
+ const result = await next();
280
+ console.log(`After: ${commandName}, success: ${result.success}`);
281
+ return result;
282
+ };
283
+ ```
284
+
285
+ ## Validation Utilities
286
+
287
+ ```typescript
288
+ import { validateInput, validateOrThrow, isValid, patterns } from '@afd/server';
289
+
290
+ // Validate and get result
291
+ const result = validateInput(schema, data);
292
+ if (!result.success) {
293
+ console.log(result.errors);
294
+ }
295
+
296
+ // Validate or throw
297
+ try {
298
+ const data = validateOrThrow(schema, input);
299
+ } catch (e) {
300
+ if (e instanceof ValidationException) {
301
+ console.log(e.errors);
302
+ }
303
+ }
304
+
305
+ // Check validity
306
+ if (isValid(schema, data)) {
307
+ // data is typed
308
+ }
309
+
310
+ // Common patterns
311
+ const schema = z.object({
312
+ id: patterns.uuid,
313
+ email: patterns.email,
314
+ count: patterns.positiveInt,
315
+ ...patterns.pagination,
316
+ });
317
+ ```
318
+
319
+ ## API Reference
320
+
321
+ ### defineCommand(options)
322
+
323
+ Create a command definition with Zod schema.
324
+
325
+ | Option | Type | Required | Description |
326
+ |--------|------|----------|-------------|
327
+ | `name` | string | Yes | Unique command name (e.g., `user.create`) |
328
+ | `description` | string | Yes | Human-readable description |
329
+ | `input` | ZodType | Yes | Zod schema for input validation |
330
+ | `handler` | function | Yes | Command implementation |
331
+ | `category` | string | No | Category for grouping |
332
+ | `mutation` | boolean | No | Whether command has side effects |
333
+ | `version` | string | No | Command version |
334
+ | `tags` | string[] | No | Additional tags |
335
+ | `errors` | string[] | No | Possible error codes |
336
+
337
+ ### createMcpServer(options)
338
+
339
+ Create an MCP server from commands.
340
+
341
+ | Option | Type | Required | Description |
342
+ |--------|------|----------|-------------|
343
+ | `name` | string | Yes | Server name |
344
+ | `version` | string | Yes | Server version |
345
+ | `commands` | array | Yes | Command definitions |
346
+ | `transport` | `'stdio' \| 'http' \| 'auto'` | No | Transport protocol (default: `'auto'`) |
347
+ | `port` | number | No | Port for HTTP transport (default: 3100) |
348
+ | `host` | string | No | Host for HTTP transport (default: localhost) |
349
+ | `devMode` | boolean | No | Enable development mode (default: false) |
350
+ | `cors` | boolean | No | Enable CORS for HTTP transport (default: follows devMode) |
351
+ | `middleware` | array | No | Middleware functions |
352
+ | `onCommand` | function | No | Command execution callback |
353
+ | `onError` | function | No | Error callback |
354
+
355
+ ### Server Methods
356
+
357
+ | Method | Description |
358
+ |--------|-------------|
359
+ | `start()` | Start the server |
360
+ | `stop()` | Stop the server |
361
+ | `getUrl()` | Get server URL (`"stdio://"` for stdio transport) |
362
+ | `getTransport()` | Get the resolved transport mode (`"stdio"` or `"http"`) |
363
+ | `getCommands()` | Get registered commands |
364
+ | `execute(name, input, context)` | Execute command directly |
365
+
366
+ ## Endpoints
367
+
368
+ The server exposes these endpoints:
369
+
370
+ | Endpoint | Method | Description |
371
+ |----------|--------|-------------|
372
+ | `/sse` | GET | SSE connection for MCP clients |
373
+ | `/message` | POST | JSON-RPC message endpoint |
374
+ | `/health` | GET | Health check |
375
+
376
+ ## Related
377
+
378
+ - [@afd/core](../core) - Core types and helpers
379
+ - [@afd/client](../client) - MCP client library
380
+ - [@afd/cli](../cli) - Command-line interface
381
+ - [Example: Todo App](../examples/todo-app) - Complete working example
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @fileoverview afd-docs bootstrap command
3
+ *
4
+ * Generate markdown documentation for commands.
5
+ */
6
+ import { z } from 'zod';
7
+ import type { CommandDefinition } from '@lushly-dev/afd-core';
8
+ declare const inputSchema: z.ZodObject<{
9
+ command: z.ZodOptional<z.ZodString>;
10
+ }, "strip", z.ZodTypeAny, {
11
+ command?: string | undefined;
12
+ }, {
13
+ command?: string | undefined;
14
+ }>;
15
+ type InputType = z.infer<typeof inputSchema>;
16
+ interface DocsOutput {
17
+ markdown: string;
18
+ commandCount: number;
19
+ }
20
+ /**
21
+ * Create the afd-docs bootstrap command.
22
+ *
23
+ * @param getCommands - Function to get all registered commands
24
+ */
25
+ export declare function createAfdDocsCommand(getCommands: () => CommandDefinition[]): CommandDefinition<InputType, DocsOutput>;
26
+ export {};
27
+ //# sourceMappingURL=afd-docs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"afd-docs.d.ts","sourceRoot":"","sources":["../../src/bootstrap/afd-docs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,QAAA,MAAM,WAAW;;;;;;EAEf,CAAC;AAEH,KAAK,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAE7C,UAAU,UAAU;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CACnC,WAAW,EAAE,MAAM,iBAAiB,EAAE,GACpC,iBAAiB,CAAC,SAAS,EAAE,UAAU,CAAC,CA+F1C"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @fileoverview afd-docs bootstrap command
3
+ *
4
+ * Generate markdown documentation for commands.
5
+ */
6
+ import { z } from 'zod';
7
+ import { success } from '@lushly-dev/afd-core';
8
+ const inputSchema = z.object({
9
+ command: z.string().optional().describe('Specific command name, or omit for all'),
10
+ });
11
+ /**
12
+ * Create the afd-docs bootstrap command.
13
+ *
14
+ * @param getCommands - Function to get all registered commands
15
+ */
16
+ export function createAfdDocsCommand(getCommands) {
17
+ return {
18
+ name: 'afd-docs',
19
+ description: 'Get detailed documentation for commands',
20
+ category: 'bootstrap',
21
+ tags: ['bootstrap', 'read', 'safe'],
22
+ mutation: false,
23
+ version: '1.0.0',
24
+ parameters: [
25
+ { name: 'command', type: 'string', required: false, description: 'Specific command name' },
26
+ ],
27
+ async handler(input) {
28
+ const allCommands = getCommands();
29
+ // Filter to specific command if provided
30
+ const commands = input.command
31
+ ? allCommands.filter(cmd => cmd.name === input.command)
32
+ : allCommands;
33
+ if (input.command && commands.length === 0) {
34
+ return success({ markdown: '', commandCount: 0 }, { reasoning: `Command "${input.command}" not found`, confidence: 1.0 });
35
+ }
36
+ // Generate markdown
37
+ const lines = [];
38
+ lines.push('# Command Documentation');
39
+ lines.push('');
40
+ // Group by category
41
+ const byCategory = {};
42
+ for (const cmd of commands) {
43
+ const category = cmd.category || 'General';
44
+ if (!byCategory[category]) {
45
+ byCategory[category] = [];
46
+ }
47
+ byCategory[category].push(cmd);
48
+ }
49
+ for (const [category, cmds] of Object.entries(byCategory).sort()) {
50
+ lines.push(`## ${category}`);
51
+ lines.push('');
52
+ for (const cmd of cmds.sort((a, b) => a.name.localeCompare(b.name))) {
53
+ lines.push(`### \`${cmd.name}\``);
54
+ lines.push('');
55
+ lines.push(cmd.description);
56
+ lines.push('');
57
+ // Tags
58
+ if (cmd.tags && cmd.tags.length > 0) {
59
+ lines.push(`**Tags:** ${cmd.tags.map(t => `\`${t}\``).join(', ')}`);
60
+ lines.push('');
61
+ }
62
+ // Mutation info
63
+ if (cmd.mutation !== undefined) {
64
+ lines.push(`**Mutation:** ${cmd.mutation ? 'Yes' : 'No (read-only)'}`);
65
+ lines.push('');
66
+ }
67
+ // Parameters
68
+ if (cmd.parameters && cmd.parameters.length > 0) {
69
+ lines.push('**Parameters:**');
70
+ lines.push('');
71
+ lines.push('| Name | Type | Required | Description |');
72
+ lines.push('|------|------|----------|-------------|');
73
+ for (const param of cmd.parameters) {
74
+ const required = param.required ? 'Yes' : 'No';
75
+ lines.push(`| ${param.name} | ${param.type} | ${required} | ${param.description || ''} |`);
76
+ }
77
+ lines.push('');
78
+ }
79
+ lines.push('---');
80
+ lines.push('');
81
+ }
82
+ }
83
+ const markdown = lines.join('\n');
84
+ return success({ markdown, commandCount: commands.length }, {
85
+ reasoning: input.command
86
+ ? `Generated documentation for "${input.command}"`
87
+ : `Generated documentation for ${commands.length} commands`,
88
+ confidence: 1.0,
89
+ });
90
+ },
91
+ };
92
+ }
93
+ //# sourceMappingURL=afd-docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"afd-docs.js","sourceRoot":"","sources":["../../src/bootstrap/afd-docs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wCAAwC,CAAC;CACjF,CAAC,CAAC;AASH;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CACnC,WAAsC;IAEtC,OAAO;QACN,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,yCAAyC;QACtD,QAAQ,EAAE,WAAW;QACrB,IAAI,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC;QACnC,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,OAAO;QAChB,UAAU,EAAE;YACX,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE;SAC1F;QAED,KAAK,CAAC,OAAO,CAAC,KAAgB;YAC7B,MAAM,WAAW,GAAG,WAAW,EAAE,CAAC;YAElC,yCAAyC;YACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO;gBAC7B,CA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CAAC;wBACvD,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;4BACpC,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;4BAC/C,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,IAAI,MAAM,QAAQ,MAAM,KAAK,CAAC,WAAW,IAAI,EAAE,IAAI,CAAC,CAAC;wBAC5F,CAAC;wBACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBAChB,CAAC;oBAED,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBAClB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAChB,CAAC;YACF,CAAC;YAED,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAElC,OAAO,OAAO,CACb,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC,MAAM,EAAE,EAC3C;gBACC,SAAS,EAAE,KAAK,CAAC,OAAO;oBACvB,CAAC,CAAC,gCAAgC,KAAK,CAAC,OAAO,GAAG;oBAClD,CAAC,CAAC,+BAA+B,QAAQ,CAAC,MAAM,WAAW;gBAC5D,UAAU,EAAE,GAAG;aACf,CACD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @fileoverview afd-help bootstrap command
3
+ *
4
+ * List all available commands with tags and grouping.
5
+ */
6
+ import { z } from 'zod';
7
+ import type { CommandDefinition } from '@lushly-dev/afd-core';
8
+ declare const inputSchema: z.ZodObject<{
9
+ filter: z.ZodOptional<z.ZodString>;
10
+ format: z.ZodDefault<z.ZodEnum<["brief", "full"]>>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ format: "brief" | "full";
13
+ filter?: string | undefined;
14
+ }, {
15
+ filter?: string | undefined;
16
+ format?: "brief" | "full" | undefined;
17
+ }>;
18
+ type InputType = z.infer<typeof inputSchema>;
19
+ interface CommandInfo {
20
+ name: string;
21
+ description: string;
22
+ category?: string;
23
+ tags?: string[];
24
+ mutation?: boolean;
25
+ }
26
+ interface HelpOutput {
27
+ commands: CommandInfo[];
28
+ total: number;
29
+ filtered: boolean;
30
+ groupedByCategory: Record<string, CommandInfo[]>;
31
+ }
32
+ /**
33
+ * Create the afd-help bootstrap command.
34
+ *
35
+ * @param getCommands - Function to get all registered commands
36
+ */
37
+ export declare function createAfdHelpCommand(getCommands: () => CommandDefinition[]): CommandDefinition<InputType, HelpOutput>;
38
+ export {};
39
+ //# sourceMappingURL=afd-help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"afd-help.d.ts","sourceRoot":"","sources":["../../src/bootstrap/afd-help.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,QAAA,MAAM,WAAW;;;;;;;;;EAGf,CAAC;AAEH,KAAK,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAE7C,UAAU,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,UAAU;IACnB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;CACjD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CACnC,WAAW,EAAE,MAAM,iBAAiB,EAAE,GACpC,iBAAiB,CAAC,SAAS,EAAE,UAAU,CAAC,CAsE1C"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @fileoverview afd-help bootstrap command
3
+ *
4
+ * List all available commands with tags and grouping.
5
+ */
6
+ import { z } from 'zod';
7
+ import { success } from '@lushly-dev/afd-core';
8
+ const inputSchema = z.object({
9
+ filter: z.string().optional().describe('Tag filter: e.g., "todo" or "read"'),
10
+ format: z.enum(['brief', 'full']).default('brief').describe('Output format'),
11
+ });
12
+ /**
13
+ * Create the afd-help bootstrap command.
14
+ *
15
+ * @param getCommands - Function to get all registered commands
16
+ */
17
+ export function createAfdHelpCommand(getCommands) {
18
+ return {
19
+ name: 'afd-help',
20
+ description: 'List all available commands with tags and grouping',
21
+ category: 'bootstrap',
22
+ tags: ['bootstrap', 'read', 'safe'],
23
+ mutation: false,
24
+ version: '1.0.0',
25
+ parameters: [
26
+ { name: 'filter', type: 'string', required: false, description: 'Tag filter' },
27
+ { name: 'format', type: 'string', required: false, description: 'Output format' },
28
+ ],
29
+ async handler(input) {
30
+ const allCommands = getCommands();
31
+ // Filter by tag if provided
32
+ let commands = allCommands;
33
+ const filtered = !!input.filter;
34
+ if (input.filter) {
35
+ const filterTag = input.filter.toLowerCase();
36
+ commands = allCommands.filter(cmd => cmd.tags?.some(tag => tag.toLowerCase().includes(filterTag)) ||
37
+ cmd.category?.toLowerCase().includes(filterTag) ||
38
+ cmd.name.toLowerCase().includes(filterTag));
39
+ }
40
+ // Map to output format
41
+ const commandInfos = commands.map(cmd => {
42
+ const info = {
43
+ name: cmd.name,
44
+ description: cmd.description,
45
+ };
46
+ if (input.format === 'full') {
47
+ info.category = cmd.category;
48
+ info.tags = cmd.tags;
49
+ info.mutation = cmd.mutation;
50
+ }
51
+ return info;
52
+ });
53
+ // Group by category
54
+ const groupedByCategory = {};
55
+ for (const cmd of commandInfos) {
56
+ const category = cmd.category || 'uncategorized';
57
+ if (!groupedByCategory[category]) {
58
+ groupedByCategory[category] = [];
59
+ }
60
+ groupedByCategory[category].push(cmd);
61
+ }
62
+ const output = {
63
+ commands: commandInfos,
64
+ total: commandInfos.length,
65
+ filtered,
66
+ groupedByCategory,
67
+ };
68
+ return success(output, {
69
+ reasoning: filtered
70
+ ? `Found ${commandInfos.length} commands matching "${input.filter}"`
71
+ : `Listing all ${commandInfos.length} available commands`,
72
+ confidence: 1.0,
73
+ });
74
+ },
75
+ };
76
+ }
77
+ //# sourceMappingURL=afd-help.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"afd-help.js","sourceRoot":"","sources":["../../src/bootstrap/afd-help.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;IAC5E,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC;CAC5E,CAAC,CAAC;AAmBH;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CACnC,WAAsC;IAEtC,OAAO;QACN,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,oDAAoD;QACjE,QAAQ,EAAE,WAAW;QACrB,IAAI,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC;QACnC,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,OAAO;QAChB,UAAU,EAAE;YACX,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE;YAC9E,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI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