cognitive-modules-cli 2.2.1 → 2.2.7

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 (101) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +35 -29
  4. package/dist/cli.js +519 -23
  5. package/dist/commands/add.d.ts +33 -14
  6. package/dist/commands/add.js +383 -16
  7. package/dist/commands/compose.js +60 -23
  8. package/dist/commands/index.d.ts +4 -0
  9. package/dist/commands/index.js +4 -0
  10. package/dist/commands/init.js +23 -1
  11. package/dist/commands/migrate.d.ts +30 -0
  12. package/dist/commands/migrate.js +650 -0
  13. package/dist/commands/pipe.d.ts +1 -0
  14. package/dist/commands/pipe.js +31 -11
  15. package/dist/commands/remove.js +33 -2
  16. package/dist/commands/run.d.ts +2 -0
  17. package/dist/commands/run.js +61 -28
  18. package/dist/commands/search.d.ts +28 -0
  19. package/dist/commands/search.js +143 -0
  20. package/dist/commands/test.d.ts +65 -0
  21. package/dist/commands/test.js +454 -0
  22. package/dist/commands/update.d.ts +1 -0
  23. package/dist/commands/update.js +106 -14
  24. package/dist/commands/validate.d.ts +36 -0
  25. package/dist/commands/validate.js +97 -0
  26. package/dist/errors/index.d.ts +225 -0
  27. package/dist/errors/index.js +420 -0
  28. package/dist/mcp/server.js +84 -79
  29. package/dist/modules/composition.js +97 -32
  30. package/dist/modules/loader.js +4 -2
  31. package/dist/modules/runner.d.ts +72 -5
  32. package/dist/modules/runner.js +306 -59
  33. package/dist/modules/subagent.d.ts +6 -1
  34. package/dist/modules/subagent.js +18 -13
  35. package/dist/modules/validator.js +14 -6
  36. package/dist/providers/anthropic.d.ts +15 -0
  37. package/dist/providers/anthropic.js +147 -5
  38. package/dist/providers/base.d.ts +11 -0
  39. package/dist/providers/base.js +18 -0
  40. package/dist/providers/gemini.d.ts +15 -0
  41. package/dist/providers/gemini.js +122 -5
  42. package/dist/providers/ollama.d.ts +15 -0
  43. package/dist/providers/ollama.js +111 -3
  44. package/dist/providers/openai.d.ts +11 -0
  45. package/dist/providers/openai.js +133 -0
  46. package/dist/registry/client.d.ts +212 -0
  47. package/dist/registry/client.js +359 -0
  48. package/dist/registry/index.d.ts +4 -0
  49. package/dist/registry/index.js +4 -0
  50. package/dist/registry/tar.d.ts +8 -0
  51. package/dist/registry/tar.js +353 -0
  52. package/dist/server/http.js +301 -45
  53. package/dist/server/index.d.ts +2 -0
  54. package/dist/server/index.js +1 -0
  55. package/dist/server/sse.d.ts +13 -0
  56. package/dist/server/sse.js +22 -0
  57. package/dist/types.d.ts +32 -1
  58. package/dist/types.js +4 -1
  59. package/dist/version.d.ts +1 -0
  60. package/dist/version.js +4 -0
  61. package/package.json +31 -7
  62. package/dist/modules/composition.test.d.ts +0 -11
  63. package/dist/modules/composition.test.js +0 -450
  64. package/dist/modules/policy.test.d.ts +0 -10
  65. package/dist/modules/policy.test.js +0 -369
  66. package/src/cli.ts +0 -471
  67. package/src/commands/add.ts +0 -315
  68. package/src/commands/compose.ts +0 -185
  69. package/src/commands/index.ts +0 -13
  70. package/src/commands/init.ts +0 -94
  71. package/src/commands/list.ts +0 -33
  72. package/src/commands/pipe.ts +0 -76
  73. package/src/commands/remove.ts +0 -57
  74. package/src/commands/run.ts +0 -80
  75. package/src/commands/update.ts +0 -130
  76. package/src/commands/versions.ts +0 -79
  77. package/src/index.ts +0 -90
  78. package/src/mcp/index.ts +0 -5
  79. package/src/mcp/server.ts +0 -403
  80. package/src/modules/composition.test.ts +0 -558
  81. package/src/modules/composition.ts +0 -1674
  82. package/src/modules/index.ts +0 -9
  83. package/src/modules/loader.ts +0 -508
  84. package/src/modules/policy.test.ts +0 -455
  85. package/src/modules/runner.ts +0 -1983
  86. package/src/modules/subagent.ts +0 -277
  87. package/src/modules/validator.ts +0 -700
  88. package/src/providers/anthropic.ts +0 -89
  89. package/src/providers/base.ts +0 -29
  90. package/src/providers/deepseek.ts +0 -83
  91. package/src/providers/gemini.ts +0 -117
  92. package/src/providers/index.ts +0 -78
  93. package/src/providers/minimax.ts +0 -81
  94. package/src/providers/moonshot.ts +0 -82
  95. package/src/providers/ollama.ts +0 -83
  96. package/src/providers/openai.ts +0 -84
  97. package/src/providers/qwen.ts +0 -82
  98. package/src/server/http.ts +0 -316
  99. package/src/server/index.ts +0 -6
  100. package/src/types.ts +0 -599
  101. package/tsconfig.json +0 -17
package/src/mcp/server.ts DELETED
@@ -1,403 +0,0 @@
1
- /**
2
- * Cognitive Modules MCP Server
3
- *
4
- * Provides MCP (Model Context Protocol) interface for Claude Code, Cursor, etc.
5
- *
6
- * Start with:
7
- * cog mcp
8
- */
9
-
10
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
11
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
12
- import {
13
- CallToolRequestSchema,
14
- ListToolsRequestSchema,
15
- ListResourcesRequestSchema,
16
- ReadResourceRequestSchema,
17
- ListPromptsRequestSchema,
18
- GetPromptRequestSchema,
19
- } from '@modelcontextprotocol/sdk/types.js';
20
-
21
- import { loadModule, findModule, listModules, getDefaultSearchPaths } from '../modules/loader.js';
22
- import { runModule } from '../modules/runner.js';
23
- import { getProvider } from '../providers/index.js';
24
- import type { CognitiveModule, ModuleResult } from '../types.js';
25
-
26
- // =============================================================================
27
- // Server Setup
28
- // =============================================================================
29
-
30
- const server = new Server(
31
- {
32
- name: 'cognitive-modules',
33
- version: '1.3.0',
34
- },
35
- {
36
- capabilities: {
37
- tools: {},
38
- resources: {},
39
- prompts: {},
40
- },
41
- }
42
- );
43
-
44
- const cwd = process.cwd();
45
- const searchPaths = getDefaultSearchPaths(cwd);
46
-
47
- // =============================================================================
48
- // Tools
49
- // =============================================================================
50
-
51
- server.setRequestHandler(ListToolsRequestSchema, async () => {
52
- return {
53
- tools: [
54
- {
55
- name: 'cognitive_run',
56
- description: 'Run a Cognitive Module to get structured AI analysis results',
57
- inputSchema: {
58
- type: 'object',
59
- properties: {
60
- module: {
61
- type: 'string',
62
- description: 'Module name, e.g. "code-reviewer", "task-prioritizer"',
63
- },
64
- args: {
65
- type: 'string',
66
- description: 'Input arguments, e.g. code snippet or task list',
67
- },
68
- provider: {
69
- type: 'string',
70
- description: 'LLM provider (optional), e.g. "openai", "anthropic"',
71
- },
72
- model: {
73
- type: 'string',
74
- description: 'Model name (optional), e.g. "gpt-4o", "claude-3-5-sonnet"',
75
- },
76
- },
77
- required: ['module', 'args'],
78
- },
79
- },
80
- {
81
- name: 'cognitive_list',
82
- description: 'List all installed Cognitive Modules',
83
- inputSchema: {
84
- type: 'object',
85
- properties: {},
86
- },
87
- },
88
- {
89
- name: 'cognitive_info',
90
- description: 'Get detailed information about a Cognitive Module',
91
- inputSchema: {
92
- type: 'object',
93
- properties: {
94
- module: {
95
- type: 'string',
96
- description: 'Module name',
97
- },
98
- },
99
- required: ['module'],
100
- },
101
- },
102
- ],
103
- };
104
- });
105
-
106
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
107
- const { name, arguments: args } = request.params;
108
-
109
- try {
110
- switch (name) {
111
- case 'cognitive_run': {
112
- const { module: moduleName, args: inputArgs, provider: providerName, model } = args as {
113
- module: string;
114
- args: string;
115
- provider?: string;
116
- model?: string;
117
- };
118
-
119
- // Find module
120
- const moduleData = await findModule(moduleName, searchPaths);
121
- if (!moduleData) {
122
- return {
123
- content: [
124
- {
125
- type: 'text',
126
- text: JSON.stringify({ ok: false, error: `Module '${moduleName}' not found` }),
127
- },
128
- ],
129
- };
130
- }
131
-
132
- // Create provider
133
- const provider = getProvider(providerName, model);
134
-
135
- // Run module
136
- const result = await runModule(moduleData, provider, {
137
- input: { query: inputArgs, code: inputArgs },
138
- useV22: true,
139
- });
140
-
141
- return {
142
- content: [
143
- {
144
- type: 'text',
145
- text: JSON.stringify(result, null, 2),
146
- },
147
- ],
148
- };
149
- }
150
-
151
- case 'cognitive_list': {
152
- const modules = await listModules(searchPaths);
153
- return {
154
- content: [
155
- {
156
- type: 'text',
157
- text: JSON.stringify(
158
- {
159
- modules: modules.map((m) => ({
160
- name: m.name,
161
- location: m.location,
162
- format: m.format,
163
- tier: m.tier,
164
- })),
165
- count: modules.length,
166
- },
167
- null,
168
- 2
169
- ),
170
- },
171
- ],
172
- };
173
- }
174
-
175
- case 'cognitive_info': {
176
- const { module: moduleName } = args as { module: string };
177
-
178
- const moduleData = await findModule(moduleName, searchPaths);
179
- if (!moduleData) {
180
- return {
181
- content: [
182
- {
183
- type: 'text',
184
- text: JSON.stringify({ ok: false, error: `Module '${moduleName}' not found` }),
185
- },
186
- ],
187
- };
188
- }
189
-
190
- return {
191
- content: [
192
- {
193
- type: 'text',
194
- text: JSON.stringify(
195
- {
196
- ok: true,
197
- name: moduleData.name,
198
- version: moduleData.version,
199
- responsibility: moduleData.responsibility,
200
- tier: moduleData.tier,
201
- format: moduleData.format,
202
- inputSchema: moduleData.inputSchema,
203
- outputSchema: moduleData.outputSchema,
204
- },
205
- null,
206
- 2
207
- ),
208
- },
209
- ],
210
- };
211
- }
212
-
213
- default:
214
- return {
215
- content: [
216
- {
217
- type: 'text',
218
- text: JSON.stringify({ ok: false, error: `Unknown tool: ${name}` }),
219
- },
220
- ],
221
- };
222
- }
223
- } catch (error) {
224
- return {
225
- content: [
226
- {
227
- type: 'text',
228
- text: JSON.stringify({
229
- ok: false,
230
- error: error instanceof Error ? error.message : String(error),
231
- }),
232
- },
233
- ],
234
- };
235
- }
236
- });
237
-
238
- // =============================================================================
239
- // Resources
240
- // =============================================================================
241
-
242
- server.setRequestHandler(ListResourcesRequestSchema, async () => {
243
- const modules = await listModules(searchPaths);
244
-
245
- return {
246
- resources: [
247
- {
248
- uri: 'cognitive://modules',
249
- name: 'All Modules',
250
- description: 'List of all installed Cognitive Modules',
251
- mimeType: 'application/json',
252
- },
253
- ...modules.map((m) => ({
254
- uri: `cognitive://module/${m.name}`,
255
- name: m.name,
256
- description: m.responsibility || `Cognitive Module: ${m.name}`,
257
- mimeType: 'text/markdown',
258
- })),
259
- ],
260
- };
261
- });
262
-
263
- server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
264
- const { uri } = request.params;
265
-
266
- if (uri === 'cognitive://modules') {
267
- const modules = await listModules(searchPaths);
268
- return {
269
- contents: [
270
- {
271
- uri,
272
- mimeType: 'application/json',
273
- text: JSON.stringify(modules.map((m) => m.name), null, 2),
274
- },
275
- ],
276
- };
277
- }
278
-
279
- const match = uri.match(/^cognitive:\/\/module\/(.+)$/);
280
- if (match) {
281
- const moduleName = match[1];
282
- const moduleData = await findModule(moduleName, searchPaths);
283
-
284
- if (!moduleData) {
285
- return {
286
- contents: [
287
- {
288
- uri,
289
- mimeType: 'text/plain',
290
- text: `Module '${moduleName}' not found`,
291
- },
292
- ],
293
- };
294
- }
295
-
296
- return {
297
- contents: [
298
- {
299
- uri,
300
- mimeType: 'text/markdown',
301
- text: moduleData.prompt,
302
- },
303
- ],
304
- };
305
- }
306
-
307
- return {
308
- contents: [
309
- {
310
- uri,
311
- mimeType: 'text/plain',
312
- text: `Unknown resource: ${uri}`,
313
- },
314
- ],
315
- };
316
- });
317
-
318
- // =============================================================================
319
- // Prompts
320
- // =============================================================================
321
-
322
- server.setRequestHandler(ListPromptsRequestSchema, async () => {
323
- return {
324
- prompts: [
325
- {
326
- name: 'code_review',
327
- description: 'Generate a code review prompt',
328
- arguments: [
329
- {
330
- name: 'code',
331
- description: 'The code to review',
332
- required: true,
333
- },
334
- ],
335
- },
336
- {
337
- name: 'task_prioritize',
338
- description: 'Generate a task prioritization prompt',
339
- arguments: [
340
- {
341
- name: 'tasks',
342
- description: 'The tasks to prioritize',
343
- required: true,
344
- },
345
- ],
346
- },
347
- ],
348
- };
349
- });
350
-
351
- server.setRequestHandler(GetPromptRequestSchema, async (request) => {
352
- const { name, arguments: args } = request.params;
353
-
354
- switch (name) {
355
- case 'code_review': {
356
- const code = args?.code ?? '';
357
- return {
358
- messages: [
359
- {
360
- role: 'user',
361
- content: {
362
- type: 'text',
363
- text: `Please use the cognitive_run tool to review the following code:\n\n\`\`\`\n${code}\n\`\`\`\n\nCall: cognitive_run("code-reviewer", "${code.slice(0, 100)}...")`,
364
- },
365
- },
366
- ],
367
- };
368
- }
369
-
370
- case 'task_prioritize': {
371
- const tasks = args?.tasks ?? '';
372
- return {
373
- messages: [
374
- {
375
- role: 'user',
376
- content: {
377
- type: 'text',
378
- text: `Please use the cognitive_run tool to prioritize the following tasks:\n\n${tasks}\n\nCall: cognitive_run("task-prioritizer", "${tasks}")`,
379
- },
380
- },
381
- ],
382
- };
383
- }
384
-
385
- default:
386
- throw new Error(`Unknown prompt: ${name}`);
387
- }
388
- });
389
-
390
- // =============================================================================
391
- // Server Start
392
- // =============================================================================
393
-
394
- export async function serve(): Promise<void> {
395
- const transport = new StdioServerTransport();
396
- await server.connect(transport);
397
- console.error('Cognitive Modules MCP Server started');
398
- }
399
-
400
- // Allow running directly
401
- if (import.meta.url === `file://${process.argv[1]}`) {
402
- serve().catch(console.error);
403
- }