cognitive-modules-cli 2.2.0 → 2.2.5

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 (94) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +35 -29
  4. package/dist/cli.js +572 -28
  5. package/dist/commands/add.d.ts +33 -14
  6. package/dist/commands/add.js +222 -13
  7. package/dist/commands/compose.d.ts +31 -0
  8. package/dist/commands/compose.js +185 -0
  9. package/dist/commands/index.d.ts +5 -0
  10. package/dist/commands/index.js +5 -0
  11. package/dist/commands/init.js +23 -1
  12. package/dist/commands/migrate.d.ts +30 -0
  13. package/dist/commands/migrate.js +650 -0
  14. package/dist/commands/pipe.d.ts +1 -0
  15. package/dist/commands/pipe.js +31 -11
  16. package/dist/commands/remove.js +33 -2
  17. package/dist/commands/run.d.ts +1 -0
  18. package/dist/commands/run.js +37 -27
  19. package/dist/commands/search.d.ts +28 -0
  20. package/dist/commands/search.js +143 -0
  21. package/dist/commands/test.d.ts +65 -0
  22. package/dist/commands/test.js +454 -0
  23. package/dist/commands/update.d.ts +1 -0
  24. package/dist/commands/update.js +106 -14
  25. package/dist/commands/validate.d.ts +36 -0
  26. package/dist/commands/validate.js +97 -0
  27. package/dist/errors/index.d.ts +218 -0
  28. package/dist/errors/index.js +412 -0
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.js +5 -1
  31. package/dist/mcp/server.js +84 -79
  32. package/dist/modules/composition.d.ts +251 -0
  33. package/dist/modules/composition.js +1330 -0
  34. package/dist/modules/index.d.ts +2 -0
  35. package/dist/modules/index.js +2 -0
  36. package/dist/modules/loader.d.ts +22 -2
  37. package/dist/modules/loader.js +171 -6
  38. package/dist/modules/runner.d.ts +422 -1
  39. package/dist/modules/runner.js +1472 -71
  40. package/dist/modules/subagent.d.ts +6 -1
  41. package/dist/modules/subagent.js +20 -13
  42. package/dist/modules/validator.d.ts +28 -0
  43. package/dist/modules/validator.js +637 -0
  44. package/dist/providers/anthropic.d.ts +15 -0
  45. package/dist/providers/anthropic.js +147 -5
  46. package/dist/providers/base.d.ts +11 -0
  47. package/dist/providers/base.js +18 -0
  48. package/dist/providers/gemini.d.ts +15 -0
  49. package/dist/providers/gemini.js +122 -5
  50. package/dist/providers/ollama.d.ts +15 -0
  51. package/dist/providers/ollama.js +111 -3
  52. package/dist/providers/openai.d.ts +11 -0
  53. package/dist/providers/openai.js +133 -0
  54. package/dist/registry/client.d.ts +204 -0
  55. package/dist/registry/client.js +356 -0
  56. package/dist/registry/index.d.ts +4 -0
  57. package/dist/registry/index.js +4 -0
  58. package/dist/server/http.js +173 -42
  59. package/dist/types.d.ts +123 -8
  60. package/dist/types.js +4 -1
  61. package/dist/version.d.ts +1 -0
  62. package/dist/version.js +4 -0
  63. package/package.json +32 -7
  64. package/src/cli.ts +0 -410
  65. package/src/commands/add.ts +0 -315
  66. package/src/commands/index.ts +0 -12
  67. package/src/commands/init.ts +0 -94
  68. package/src/commands/list.ts +0 -33
  69. package/src/commands/pipe.ts +0 -76
  70. package/src/commands/remove.ts +0 -57
  71. package/src/commands/run.ts +0 -80
  72. package/src/commands/update.ts +0 -130
  73. package/src/commands/versions.ts +0 -79
  74. package/src/index.ts +0 -55
  75. package/src/mcp/index.ts +0 -5
  76. package/src/mcp/server.ts +0 -403
  77. package/src/modules/index.ts +0 -7
  78. package/src/modules/loader.ts +0 -318
  79. package/src/modules/runner.ts +0 -495
  80. package/src/modules/subagent.ts +0 -275
  81. package/src/providers/anthropic.ts +0 -89
  82. package/src/providers/base.ts +0 -29
  83. package/src/providers/deepseek.ts +0 -83
  84. package/src/providers/gemini.ts +0 -117
  85. package/src/providers/index.ts +0 -78
  86. package/src/providers/minimax.ts +0 -81
  87. package/src/providers/moonshot.ts +0 -82
  88. package/src/providers/ollama.ts +0 -83
  89. package/src/providers/openai.ts +0 -84
  90. package/src/providers/qwen.ts +0 -82
  91. package/src/server/http.ts +0 -316
  92. package/src/server/index.ts +0 -6
  93. package/src/types.ts +0 -495
  94. package/tsconfig.json +0 -17
@@ -1,130 +0,0 @@
1
- /**
2
- * Update command - Update installed modules to latest version
3
- *
4
- * cog update code-simplifier
5
- * cog update code-simplifier --tag v2.0.0
6
- */
7
-
8
- import { existsSync, rmSync } from 'node:fs';
9
- import { readFile } from 'node:fs/promises';
10
- import { join } from 'node:path';
11
- import { homedir } from 'node:os';
12
- import type { CommandContext, CommandResult } from '../types.js';
13
- import { add, getInstallInfo } from './add.js';
14
-
15
- const USER_MODULES_DIR = join(homedir(), '.cognitive', 'modules');
16
-
17
- export interface UpdateOptions {
18
- tag?: string;
19
- }
20
-
21
- /**
22
- * Get module version from installed module
23
- */
24
- async function getInstalledVersion(moduleName: string): Promise<string | undefined> {
25
- const modulePath = join(USER_MODULES_DIR, moduleName);
26
-
27
- if (!existsSync(modulePath)) {
28
- return undefined;
29
- }
30
-
31
- const yaml = await import('js-yaml');
32
-
33
- // Try v2 format
34
- const yamlPath = join(modulePath, 'module.yaml');
35
- if (existsSync(yamlPath)) {
36
- const content = await readFile(yamlPath, 'utf-8');
37
- const data = yaml.load(content) as { version?: string };
38
- return data?.version;
39
- }
40
-
41
- // Try v1 format
42
- const mdPath = existsSync(join(modulePath, 'MODULE.md'))
43
- ? join(modulePath, 'MODULE.md')
44
- : join(modulePath, 'module.md');
45
-
46
- if (existsSync(mdPath)) {
47
- const content = await readFile(mdPath, 'utf-8');
48
- if (content.startsWith('---')) {
49
- const parts = content.split('---');
50
- if (parts.length >= 3) {
51
- const meta = yaml.load(parts[1]) as { version?: string };
52
- return meta?.version;
53
- }
54
- }
55
- }
56
-
57
- return undefined;
58
- }
59
-
60
- /**
61
- * Update an installed module
62
- */
63
- export async function update(
64
- moduleName: string,
65
- ctx: CommandContext,
66
- options: UpdateOptions = {}
67
- ): Promise<CommandResult> {
68
- // Get installation info
69
- const info = await getInstallInfo(moduleName);
70
-
71
- if (!info) {
72
- return {
73
- success: false,
74
- error: `Module not found or not installed from GitHub: ${moduleName}. Only modules installed with 'cog add' can be updated.`,
75
- };
76
- }
77
-
78
- if (!info.githubUrl) {
79
- return {
80
- success: false,
81
- error: `Module was not installed from GitHub: ${moduleName}`,
82
- };
83
- }
84
-
85
- // Get current version
86
- const oldVersion = await getInstalledVersion(moduleName);
87
-
88
- // Determine what ref to use
89
- const tag = options.tag || info.tag;
90
- const branch = info.branch || 'main';
91
-
92
- // Re-install from source
93
- const result = await add(info.githubUrl, ctx, {
94
- module: info.modulePath,
95
- name: moduleName,
96
- tag,
97
- branch: tag ? undefined : branch,
98
- });
99
-
100
- if (!result.success) {
101
- return result;
102
- }
103
-
104
- const data = result.data as { version?: string };
105
- const newVersion = data.version;
106
-
107
- // Determine message
108
- let message: string;
109
- if (oldVersion && newVersion) {
110
- if (oldVersion === newVersion) {
111
- message = `Already up to date: ${moduleName} v${newVersion}`;
112
- } else {
113
- message = `Updated: ${moduleName} v${oldVersion} → v${newVersion}`;
114
- }
115
- } else if (newVersion) {
116
- message = `Updated: ${moduleName} to v${newVersion}`;
117
- } else {
118
- message = `Updated: ${moduleName}`;
119
- }
120
-
121
- return {
122
- success: true,
123
- data: {
124
- message,
125
- name: moduleName,
126
- oldVersion,
127
- newVersion,
128
- },
129
- };
130
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * Versions command - List available versions from GitHub
3
- *
4
- * cog versions ziel-io/cognitive-modules
5
- */
6
-
7
- import type { CommandContext, CommandResult } from '../types.js';
8
-
9
- export interface VersionsOptions {
10
- limit?: number;
11
- }
12
-
13
- /**
14
- * Parse GitHub URL or shorthand
15
- */
16
- function parseGitHubUrl(url: string): { org: string; repo: string } {
17
- if (!url.startsWith('http')) {
18
- url = `https://github.com/${url}`;
19
- }
20
-
21
- const match = url.match(/https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/?/);
22
- if (!match) {
23
- throw new Error(`Invalid GitHub URL: ${url}`);
24
- }
25
-
26
- return {
27
- org: match[1],
28
- repo: match[2].replace(/\.git$/, ''),
29
- };
30
- }
31
-
32
- /**
33
- * List available versions (tags) from GitHub
34
- */
35
- export async function versions(
36
- url: string,
37
- ctx: CommandContext,
38
- options: VersionsOptions = {}
39
- ): Promise<CommandResult> {
40
- const { limit = 10 } = options;
41
-
42
- try {
43
- const { org, repo } = parseGitHubUrl(url);
44
-
45
- // Fetch tags from GitHub API
46
- const apiUrl = `https://api.github.com/repos/${org}/${repo}/tags?per_page=${limit}`;
47
-
48
- const response = await fetch(apiUrl, {
49
- headers: {
50
- 'User-Agent': 'cognitive-runtime/1.0',
51
- 'Accept': 'application/vnd.github.v3+json',
52
- },
53
- });
54
-
55
- if (!response.ok) {
56
- if (response.status === 404) {
57
- throw new Error(`Repository not found: ${org}/${repo}`);
58
- }
59
- throw new Error(`GitHub API error: ${response.status}`);
60
- }
61
-
62
- const data = await response.json() as Array<{ name: string }>;
63
- const tags = data.map(t => t.name);
64
-
65
- return {
66
- success: true,
67
- data: {
68
- repository: `${org}/${repo}`,
69
- tags,
70
- count: tags.length,
71
- },
72
- };
73
- } catch (error) {
74
- return {
75
- success: false,
76
- error: error instanceof Error ? error.message : String(error),
77
- };
78
- }
79
- }
package/src/index.ts DELETED
@@ -1,55 +0,0 @@
1
- /**
2
- * Cognitive Runtime - Main Entry Point
3
- *
4
- * Exports all public APIs for programmatic use.
5
- */
6
-
7
- // Types
8
- export type {
9
- Provider,
10
- InvokeParams,
11
- InvokeResult,
12
- Message,
13
- CognitiveModule,
14
- ModuleResult,
15
- ModuleInput,
16
- ModuleConstraints,
17
- ToolsPolicy,
18
- OutputContract,
19
- FailureContract,
20
- CommandContext,
21
- CommandResult,
22
- } from './types.js';
23
-
24
- // Providers
25
- export {
26
- getProvider,
27
- listProviders,
28
- GeminiProvider,
29
- OpenAIProvider,
30
- AnthropicProvider,
31
- BaseProvider,
32
- } from './providers/index.js';
33
-
34
- // Modules
35
- export {
36
- loadModule,
37
- findModule,
38
- listModules,
39
- getDefaultSearchPaths,
40
- runModule,
41
- // Subagent
42
- SubagentOrchestrator,
43
- runWithSubagents,
44
- parseCalls,
45
- createContext,
46
- } from './modules/index.js';
47
-
48
- // Server
49
- export { serve as serveHttp, createServer } from './server/index.js';
50
-
51
- // MCP
52
- export { serve as serveMcp } from './mcp/index.js';
53
-
54
- // Commands
55
- export { run, list, pipe } from './commands/index.js';
package/src/mcp/index.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * MCP Server - Re-export all MCP functionality
3
- */
4
-
5
- export { serve } from './server.js';
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
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Modules - Re-export all module functionality
3
- */
4
-
5
- export * from './loader.js';
6
- export * from './runner.js';
7
- export * from './subagent.js';