cognitive-modules-cli 2.2.1 → 2.5.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/cli.js +12 -65
  2. package/dist/commands/index.d.ts +0 -1
  3. package/dist/commands/index.js +0 -1
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.js +1 -5
  6. package/dist/modules/index.d.ts +0 -2
  7. package/dist/modules/index.js +0 -2
  8. package/dist/modules/loader.d.ts +2 -22
  9. package/dist/modules/loader.js +4 -167
  10. package/dist/modules/runner.d.ts +34 -348
  11. package/dist/modules/runner.js +708 -1263
  12. package/dist/modules/subagent.js +0 -2
  13. package/dist/providers/base.d.ts +45 -1
  14. package/dist/providers/base.js +67 -0
  15. package/dist/providers/openai.d.ts +27 -3
  16. package/dist/providers/openai.js +175 -3
  17. package/dist/types.d.ts +316 -93
  18. package/dist/types.js +120 -1
  19. package/package.json +1 -2
  20. package/src/cli.ts +12 -73
  21. package/src/commands/index.ts +0 -1
  22. package/src/index.ts +0 -35
  23. package/src/modules/index.ts +0 -2
  24. package/src/modules/loader.ts +6 -196
  25. package/src/modules/runner.ts +996 -1690
  26. package/src/modules/subagent.ts +0 -2
  27. package/src/providers/base.ts +86 -1
  28. package/src/providers/openai.ts +226 -4
  29. package/src/types.ts +462 -113
  30. package/tsconfig.json +1 -1
  31. package/dist/commands/compose.d.ts +0 -31
  32. package/dist/commands/compose.js +0 -148
  33. package/dist/modules/composition.d.ts +0 -251
  34. package/dist/modules/composition.js +0 -1265
  35. package/dist/modules/composition.test.d.ts +0 -11
  36. package/dist/modules/composition.test.js +0 -450
  37. package/dist/modules/policy.test.d.ts +0 -10
  38. package/dist/modules/policy.test.js +0 -369
  39. package/dist/modules/validator.d.ts +0 -28
  40. package/dist/modules/validator.js +0 -629
  41. package/src/commands/compose.ts +0 -185
  42. package/src/modules/composition.test.ts +0 -558
  43. package/src/modules/composition.ts +0 -1674
  44. package/src/modules/policy.test.ts +0 -455
  45. package/src/modules/validator.ts +0 -700
package/dist/cli.js CHANGED
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { parseArgs } from 'node:util';
17
17
  import { getProvider, listProviders } from './providers/index.js';
18
- import { run, list, pipe, init, add, update, remove, versions, compose, composeInfo } from './commands/index.js';
18
+ import { run, list, pipe, init, add, update, remove, versions } from './commands/index.js';
19
19
  const VERSION = '1.3.0';
20
20
  async function main() {
21
21
  const args = process.argv.slice(2);
@@ -48,10 +48,6 @@ async function main() {
48
48
  // Server options
49
49
  host: { type: 'string', short: 'H' },
50
50
  port: { type: 'string', short: 'P' },
51
- // Compose options
52
- 'max-depth': { type: 'string', short: 'd' },
53
- timeout: { type: 'string', short: 'T' },
54
- trace: { type: 'boolean', default: false },
55
51
  },
56
52
  allowPositionals: true,
57
53
  });
@@ -256,45 +252,6 @@ async function main() {
256
252
  }
257
253
  break;
258
254
  }
259
- case 'compose': {
260
- const moduleName = args[1];
261
- if (!moduleName || moduleName.startsWith('-')) {
262
- console.error('Usage: cog compose <module> [--args "..."] [--timeout <ms>] [--max-depth <n>]');
263
- process.exit(1);
264
- }
265
- const result = await compose(moduleName, ctx, {
266
- args: values.args,
267
- input: values.input,
268
- maxDepth: values['max-depth'] ? parseInt(values['max-depth'], 10) : undefined,
269
- timeout: values.timeout ? parseInt(values.timeout, 10) : undefined,
270
- trace: values.trace,
271
- pretty: values.pretty,
272
- verbose: values.verbose,
273
- });
274
- if (!result.success) {
275
- console.error(`Error: ${result.error}`);
276
- if (result.data) {
277
- console.error('Partial results:', JSON.stringify(result.data, null, 2));
278
- }
279
- process.exit(1);
280
- }
281
- console.log(JSON.stringify(result.data, null, values.pretty ? 2 : 0));
282
- break;
283
- }
284
- case 'compose-info': {
285
- const moduleName = args[1];
286
- if (!moduleName || moduleName.startsWith('-')) {
287
- console.error('Usage: cog compose-info <module>');
288
- process.exit(1);
289
- }
290
- const result = await composeInfo(moduleName, ctx);
291
- if (!result.success) {
292
- console.error(`Error: ${result.error}`);
293
- process.exit(1);
294
- }
295
- console.log(JSON.stringify(result.data, null, 2));
296
- break;
297
- }
298
255
  case 'serve': {
299
256
  const { serve } = await import('./server/http.js');
300
257
  const port = values.port ? parseInt(values.port, 10) : 8000;
@@ -341,19 +298,17 @@ USAGE:
341
298
  cog <command> [options]
342
299
 
343
300
  COMMANDS:
344
- run <module> Run a Cognitive Module
345
- compose <module> Execute a composed module workflow
346
- compose-info <mod> Show composition configuration
347
- list List available modules
348
- add <url> Add module from GitHub
349
- update <module> Update module to latest version
350
- remove <module> Remove installed module
351
- versions <url> List available versions
352
- pipe Pipe mode (stdin/stdout)
353
- init [name] Initialize project or create module
354
- serve Start HTTP API server
355
- mcp Start MCP server (for Claude Code, Cursor)
356
- doctor Check configuration
301
+ run <module> Run a Cognitive Module
302
+ list List available modules
303
+ add <url> Add module from GitHub
304
+ update <module> Update module to latest version
305
+ remove <module> Remove installed module
306
+ versions <url> List available versions
307
+ pipe Pipe mode (stdin/stdout)
308
+ init [name] Initialize project or create module
309
+ serve Start HTTP API server
310
+ mcp Start MCP server (for Claude Code, Cursor)
311
+ doctor Check configuration
357
312
 
358
313
  OPTIONS:
359
314
  -a, --args <str> Arguments to pass to module
@@ -369,9 +324,6 @@ OPTIONS:
369
324
  --no-validate Skip schema validation
370
325
  -H, --host <host> Server host (default: 0.0.0.0)
371
326
  -P, --port <port> Server port (default: 8000)
372
- -d, --max-depth <n> Max composition depth (default: 5)
373
- -T, --timeout <ms> Composition timeout in milliseconds
374
- --trace Include execution trace (for compose)
375
327
  -v, --version Show version
376
328
  -h, --help Show this help
377
329
 
@@ -390,11 +342,6 @@ EXAMPLES:
390
342
  cog run code-reviewer --provider openai --model gpt-4o --args "..."
391
343
  cog list
392
344
 
393
- # Compose modules (multi-step workflows)
394
- cog compose code-review-pipeline --args "code to review"
395
- cog compose smart-processor --args "input" --timeout 60000 --verbose
396
- cog compose-info code-review-pipeline
397
-
398
345
  # Servers
399
346
  cog serve --port 8080
400
347
  cog mcp
@@ -9,4 +9,3 @@ export * from './add.js';
9
9
  export * from './update.js';
10
10
  export * from './remove.js';
11
11
  export * from './versions.js';
12
- export * from './compose.js';
@@ -9,4 +9,3 @@ export * from './add.js';
9
9
  export * from './update.js';
10
10
  export * from './remove.js';
11
11
  export * from './versions.js';
12
- export * from './compose.js';
package/dist/index.d.ts CHANGED
@@ -3,9 +3,9 @@
3
3
  *
4
4
  * Exports all public APIs for programmatic use.
5
5
  */
6
- export type { Provider, InvokeParams, InvokeResult, Message, CognitiveModule, ModuleResult, ModuleInput, ModuleConstraints, ToolsPolicy, OutputContract, FailureContract, CommandContext, CommandResult, CompositionConfig, CompositionPattern, DependencyDeclaration, DataflowStep, DataflowMapping, RoutingRule, AggregationStrategy, IterationConfig, } from './types.js';
6
+ export type { Provider, InvokeParams, InvokeResult, Message, CognitiveModule, ModuleResult, ModuleInput, ModuleConstraints, ToolsPolicy, OutputContract, FailureContract, CommandContext, CommandResult, } from './types.js';
7
7
  export { getProvider, listProviders, GeminiProvider, OpenAIProvider, AnthropicProvider, BaseProvider, } from './providers/index.js';
8
- export { loadModule, findModule, listModules, getDefaultSearchPaths, runModule, SubagentOrchestrator, runWithSubagents, parseCalls, createContext, CompositionOrchestrator, executeComposition, validateCompositionConfig, evaluateJsonPath, evaluateCondition, applyMapping, aggregateResults, versionMatches, resolveDependency, COMPOSITION_ERRORS, checkToolPolicy, checkPolicy, checkToolAllowed, validateToolsAllowed, getDeniedActions, getDeniedTools, getAllowedTools, ToolCallInterceptor, createPolicyAwareExecutor, type PolicyAction, type PolicyCheckResult, type ToolCallRequest, type ToolCallResult, type ToolExecutor, } from './modules/index.js';
8
+ export { loadModule, findModule, listModules, getDefaultSearchPaths, runModule, SubagentOrchestrator, runWithSubagents, parseCalls, createContext, } from './modules/index.js';
9
9
  export { serve as serveHttp, createServer } from './server/index.js';
10
10
  export { serve as serveMcp } from './mcp/index.js';
11
11
  export { run, list, pipe } from './commands/index.js';
package/dist/index.js CHANGED
@@ -8,11 +8,7 @@ export { getProvider, listProviders, GeminiProvider, OpenAIProvider, AnthropicPr
8
8
  // Modules
9
9
  export { loadModule, findModule, listModules, getDefaultSearchPaths, runModule,
10
10
  // Subagent
11
- SubagentOrchestrator, runWithSubagents, parseCalls, createContext,
12
- // Composition
13
- CompositionOrchestrator, executeComposition, validateCompositionConfig, evaluateJsonPath, evaluateCondition, applyMapping, aggregateResults, versionMatches, resolveDependency, COMPOSITION_ERRORS,
14
- // Policy Enforcement
15
- checkToolPolicy, checkPolicy, checkToolAllowed, validateToolsAllowed, getDeniedActions, getDeniedTools, getAllowedTools, ToolCallInterceptor, createPolicyAwareExecutor, } from './modules/index.js';
11
+ SubagentOrchestrator, runWithSubagents, parseCalls, createContext, } from './modules/index.js';
16
12
  // Server
17
13
  export { serve as serveHttp, createServer } from './server/index.js';
18
14
  // MCP
@@ -4,5 +4,3 @@
4
4
  export * from './loader.js';
5
5
  export * from './runner.js';
6
6
  export * from './subagent.js';
7
- export * from './validator.js';
8
- export * from './composition.js';
@@ -4,5 +4,3 @@
4
4
  export * from './loader.js';
5
5
  export * from './runner.js';
6
6
  export * from './subagent.js';
7
- export * from './validator.js';
8
- export * from './composition.js';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Module Loader - Load and parse Cognitive Modules
3
- * Supports v0 (6-file), v1 (MODULE.md) and v2 (module.yaml + prompt.md) formats
3
+ * Supports both v1 (MODULE.md) and v2 (module.yaml + prompt.md) formats
4
4
  */
5
- import type { CognitiveModule, ModuleTier, SchemaStrictness } from '../types.js';
5
+ import type { CognitiveModule } from '../types.js';
6
6
  /**
7
7
  * Load a Cognitive Module (auto-detects format)
8
8
  */
@@ -10,23 +10,3 @@ export declare function loadModule(modulePath: string): Promise<CognitiveModule>
10
10
  export declare function findModule(name: string, searchPaths: string[]): Promise<CognitiveModule | null>;
11
11
  export declare function listModules(searchPaths: string[]): Promise<CognitiveModule[]>;
12
12
  export declare function getDefaultSearchPaths(cwd: string): string[];
13
- /**
14
- * Get module tier (exec, decision, exploration).
15
- */
16
- export declare function getModuleTier(module: CognitiveModule): ModuleTier | undefined;
17
- /**
18
- * Get schema strictness level.
19
- */
20
- export declare function getSchemaStrictness(module: CognitiveModule): SchemaStrictness;
21
- /**
22
- * Check if overflow (extensions.insights) is enabled.
23
- */
24
- export declare function isOverflowEnabled(module: CognitiveModule): boolean;
25
- /**
26
- * Get enum extension strategy.
27
- */
28
- export declare function getEnumStrategy(module: CognitiveModule): 'strict' | 'extensible';
29
- /**
30
- * Check if runtime should auto-wrap v2.1 to v2.2.
31
- */
32
- export declare function shouldAutoWrap(module: CognitiveModule): boolean;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Module Loader - Load and parse Cognitive Modules
3
- * Supports v0 (6-file), v1 (MODULE.md) and v2 (module.yaml + prompt.md) formats
3
+ * Supports both v1 (MODULE.md) and v2 (module.yaml + prompt.md) formats
4
4
  */
5
5
  import * as fs from 'node:fs/promises';
6
6
  import * as path from 'node:path';
@@ -11,26 +11,12 @@ const FRONTMATTER_REGEX = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?/;
11
11
  */
12
12
  async function detectFormat(modulePath) {
13
13
  const v2Manifest = path.join(modulePath, 'module.yaml');
14
- const v1Module = path.join(modulePath, 'MODULE.md');
15
- const v0Module = path.join(modulePath, 'module.md');
16
14
  try {
17
15
  await fs.access(v2Manifest);
18
16
  return 'v2';
19
17
  }
20
18
  catch {
21
- try {
22
- await fs.access(v1Module);
23
- return 'v1';
24
- }
25
- catch {
26
- try {
27
- await fs.access(v0Module);
28
- return 'v0';
29
- }
30
- catch {
31
- throw new Error(`No module.yaml, MODULE.md, or module.md found in ${modulePath}`);
32
- }
33
- }
19
+ return 'v1';
34
20
  }
35
21
  }
36
22
  /**
@@ -128,54 +114,6 @@ async function loadModuleV2(modulePath) {
128
114
  required: metaRaw.required,
129
115
  risk_rule: validatedRiskRule,
130
116
  };
131
- // Parse composition config (v2.2)
132
- const compositionRaw = manifest.composition;
133
- let composition;
134
- if (compositionRaw) {
135
- // Parse pattern
136
- const pattern = compositionRaw.pattern ?? 'sequential';
137
- // Parse requires (dependencies)
138
- const requiresRaw = compositionRaw.requires;
139
- const requires = requiresRaw?.map(dep => ({
140
- name: dep.name,
141
- version: dep.version,
142
- optional: dep.optional,
143
- fallback: dep.fallback,
144
- timeout_ms: dep.timeout_ms
145
- }));
146
- // Parse dataflow
147
- const dataflowRaw = compositionRaw.dataflow;
148
- const dataflow = dataflowRaw?.map(step => ({
149
- from: step.from,
150
- to: step.to,
151
- mapping: step.mapping,
152
- condition: step.condition,
153
- aggregate: step.aggregate,
154
- aggregator: step.aggregator
155
- }));
156
- // Parse routing rules
157
- const routingRaw = compositionRaw.routing;
158
- const routing = routingRaw?.map(rule => ({
159
- condition: rule.condition,
160
- next: rule.next
161
- }));
162
- // Parse iteration config
163
- const iterationRaw = compositionRaw.iteration;
164
- const iteration = iterationRaw ? {
165
- max_iterations: iterationRaw.max_iterations,
166
- continue_condition: iterationRaw.continue_condition,
167
- stop_condition: iterationRaw.stop_condition
168
- } : undefined;
169
- composition = {
170
- pattern,
171
- requires,
172
- dataflow,
173
- routing,
174
- max_depth: compositionRaw.max_depth,
175
- timeout_ms: compositionRaw.timeout_ms,
176
- iteration
177
- };
178
- }
179
117
  return {
180
118
  name: manifest.name || path.basename(modulePath),
181
119
  version: manifest.version || '1.0.0',
@@ -194,7 +132,6 @@ async function loadModuleV2(modulePath) {
194
132
  enums,
195
133
  compat,
196
134
  metaConfig,
197
- composition,
198
135
  // Context and prompt
199
136
  context: manifest.context,
200
137
  prompt,
@@ -259,63 +196,6 @@ async function loadModuleV1(modulePath) {
259
196
  format: 'v1',
260
197
  };
261
198
  }
262
- /**
263
- * Load v0 format module (6-file format - deprecated)
264
- */
265
- async function loadModuleV0(modulePath) {
266
- // Read module.md
267
- const moduleFile = path.join(modulePath, 'module.md');
268
- const moduleContent = await fs.readFile(moduleFile, 'utf-8');
269
- // Parse frontmatter
270
- const match = moduleContent.match(FRONTMATTER_REGEX);
271
- if (!match) {
272
- throw new Error(`Invalid module.md: missing YAML frontmatter in ${moduleFile}`);
273
- }
274
- const metadata = yaml.load(match[1]);
275
- // Read schemas
276
- const inputSchemaFile = path.join(modulePath, 'input.schema.json');
277
- const outputSchemaFile = path.join(modulePath, 'output.schema.json');
278
- const constraintsFile = path.join(modulePath, 'constraints.yaml');
279
- const promptFile = path.join(modulePath, 'prompt.txt');
280
- const inputSchemaContent = await fs.readFile(inputSchemaFile, 'utf-8');
281
- const inputSchema = JSON.parse(inputSchemaContent);
282
- const outputSchemaContent = await fs.readFile(outputSchemaFile, 'utf-8');
283
- const outputSchema = JSON.parse(outputSchemaContent);
284
- // Load constraints
285
- const constraintsContent = await fs.readFile(constraintsFile, 'utf-8');
286
- const constraintsRaw = yaml.load(constraintsContent);
287
- // Load prompt
288
- const prompt = await fs.readFile(promptFile, 'utf-8');
289
- // Extract constraints
290
- const constraints = {};
291
- if (constraintsRaw) {
292
- const operational = constraintsRaw.operational ?? {};
293
- constraints.no_network = operational.no_external_network;
294
- constraints.no_side_effects = operational.no_side_effects;
295
- constraints.no_file_write = operational.no_file_write;
296
- constraints.no_inventing_data = operational.no_inventing_data;
297
- }
298
- return {
299
- name: metadata.name || path.basename(modulePath),
300
- version: metadata.version || '1.0.0',
301
- responsibility: metadata.responsibility || '',
302
- excludes: metadata.excludes || [],
303
- constraints: Object.keys(constraints).length > 0 ? constraints : undefined,
304
- prompt,
305
- inputSchema,
306
- outputSchema,
307
- dataSchema: outputSchema, // Alias for v2.2 compat
308
- // v2.2 defaults for v0 modules
309
- schemaStrictness: 'medium',
310
- overflow: { enabled: false },
311
- enums: { strategy: 'strict' },
312
- compat: { accepts_v21_payload: true, runtime_auto_wrap: true },
313
- // Metadata
314
- location: modulePath,
315
- format: 'v0',
316
- formatVersion: 'v0.0',
317
- };
318
- }
319
199
  /**
320
200
  * Load a Cognitive Module (auto-detects format)
321
201
  */
@@ -324,11 +204,8 @@ export async function loadModule(modulePath) {
324
204
  if (format === 'v2') {
325
205
  return loadModuleV2(modulePath);
326
206
  }
327
- else if (format === 'v1') {
328
- return loadModuleV1(modulePath);
329
- }
330
207
  else {
331
- return loadModuleV0(modulePath);
208
+ return loadModuleV1(modulePath);
332
209
  }
333
210
  }
334
211
  /**
@@ -337,7 +214,6 @@ export async function loadModule(modulePath) {
337
214
  async function isValidModule(modulePath) {
338
215
  const v2Manifest = path.join(modulePath, 'module.yaml');
339
216
  const v1Module = path.join(modulePath, 'MODULE.md');
340
- const v0Module = path.join(modulePath, 'module.md');
341
217
  try {
342
218
  await fs.access(v2Manifest);
343
219
  return true;
@@ -348,13 +224,7 @@ async function isValidModule(modulePath) {
348
224
  return true;
349
225
  }
350
226
  catch {
351
- try {
352
- await fs.access(v0Module);
353
- return true;
354
- }
355
- catch {
356
- return false;
357
- }
227
+ return false;
358
228
  }
359
229
  }
360
230
  }
@@ -401,36 +271,3 @@ export function getDefaultSearchPaths(cwd) {
401
271
  path.join(home, '.cognitive', 'modules'),
402
272
  ];
403
273
  }
404
- // =============================================================================
405
- // Utility Functions
406
- // =============================================================================
407
- /**
408
- * Get module tier (exec, decision, exploration).
409
- */
410
- export function getModuleTier(module) {
411
- return module.tier;
412
- }
413
- /**
414
- * Get schema strictness level.
415
- */
416
- export function getSchemaStrictness(module) {
417
- return module.schemaStrictness ?? 'medium';
418
- }
419
- /**
420
- * Check if overflow (extensions.insights) is enabled.
421
- */
422
- export function isOverflowEnabled(module) {
423
- return module.overflow?.enabled ?? false;
424
- }
425
- /**
426
- * Get enum extension strategy.
427
- */
428
- export function getEnumStrategy(module) {
429
- return module.enums?.strategy ?? 'strict';
430
- }
431
- /**
432
- * Check if runtime should auto-wrap v2.1 to v2.2.
433
- */
434
- export function shouldAutoWrap(module) {
435
- return module.compat?.runtime_auto_wrap ?? true;
436
- }