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
@@ -1,185 +0,0 @@
1
- /**
2
- * cog compose - Execute a Composed Cognitive Module Workflow
3
- *
4
- * Supports all composition patterns:
5
- * - Sequential: A → B → C
6
- * - Parallel: A → [B, C, D] → Aggregate
7
- * - Conditional: A → (condition) → B or C
8
- * - Iterative: A → (check) → A → ... → Done
9
- */
10
-
11
- import type { CommandContext, CommandResult } from '../types.js';
12
- import { findModule, getDefaultSearchPaths, executeComposition } from '../modules/index.js';
13
-
14
- export interface ComposeOptions {
15
- /** Direct text input */
16
- args?: string;
17
- /** JSON input data */
18
- input?: string;
19
- /** Maximum composition depth */
20
- maxDepth?: number;
21
- /** Timeout in milliseconds */
22
- timeout?: number;
23
- /** Include execution trace */
24
- trace?: boolean;
25
- /** Pretty print output */
26
- pretty?: boolean;
27
- /** Verbose mode */
28
- verbose?: boolean;
29
- }
30
-
31
- export async function compose(
32
- moduleName: string,
33
- ctx: CommandContext,
34
- options: ComposeOptions = {}
35
- ): Promise<CommandResult> {
36
- const searchPaths = getDefaultSearchPaths(ctx.cwd);
37
-
38
- // Find module
39
- const module = await findModule(moduleName, searchPaths);
40
- if (!module) {
41
- return {
42
- success: false,
43
- error: `Module not found: ${moduleName}\nSearch paths: ${searchPaths.join(', ')}`,
44
- };
45
- }
46
-
47
- try {
48
- // Parse input if provided as JSON
49
- let inputData: Record<string, unknown> = {};
50
- if (options.input) {
51
- try {
52
- inputData = JSON.parse(options.input);
53
- } catch {
54
- return {
55
- success: false,
56
- error: `Invalid JSON input: ${options.input}`,
57
- };
58
- }
59
- }
60
-
61
- // Handle --args as text input
62
- if (options.args) {
63
- inputData.query = options.args;
64
- inputData.code = options.args;
65
- }
66
-
67
- // Execute composition
68
- const result = await executeComposition(
69
- moduleName,
70
- inputData,
71
- ctx.provider,
72
- {
73
- cwd: ctx.cwd,
74
- maxDepth: options.maxDepth,
75
- timeoutMs: options.timeout
76
- }
77
- );
78
-
79
- if (options.verbose) {
80
- console.error('--- Composition Trace ---');
81
- for (const entry of result.trace) {
82
- const status = entry.success
83
- ? (entry.skipped ? '⏭️ SKIPPED' : '✅ OK')
84
- : '❌ FAILED';
85
- console.error(`${status} ${entry.module} (${entry.durationMs}ms)`);
86
- if (entry.reason) {
87
- console.error(` Reason: ${entry.reason}`);
88
- }
89
- }
90
- console.error(`--- Total: ${result.totalTimeMs}ms ---`);
91
- }
92
-
93
- // Return result
94
- if (options.trace) {
95
- // Include full result with trace
96
- return {
97
- success: result.ok,
98
- data: {
99
- ok: result.ok,
100
- result: result.result,
101
- moduleResults: result.moduleResults,
102
- trace: result.trace,
103
- totalTimeMs: result.totalTimeMs,
104
- error: result.error
105
- }
106
- };
107
- } else if (options.pretty) {
108
- return {
109
- success: result.ok,
110
- data: result.result,
111
- };
112
- } else {
113
- // For non-pretty mode, return data (success) or error (failure)
114
- if (result.ok && result.result) {
115
- return {
116
- success: true,
117
- data: (result.result as { data?: unknown }).data,
118
- };
119
- } else {
120
- return {
121
- success: false,
122
- error: result.error
123
- ? `${result.error.code}: ${result.error.message}`
124
- : 'Composition failed',
125
- data: result.moduleResults,
126
- };
127
- }
128
- }
129
- } catch (e) {
130
- return {
131
- success: false,
132
- error: e instanceof Error ? e.message : String(e),
133
- };
134
- }
135
- }
136
-
137
- /**
138
- * Show composition info for a module
139
- */
140
- export async function composeInfo(
141
- moduleName: string,
142
- ctx: CommandContext
143
- ): Promise<CommandResult> {
144
- const searchPaths = getDefaultSearchPaths(ctx.cwd);
145
-
146
- const module = await findModule(moduleName, searchPaths);
147
- if (!module) {
148
- return {
149
- success: false,
150
- error: `Module not found: ${moduleName}`,
151
- };
152
- }
153
-
154
- const composition = module.composition;
155
- if (!composition) {
156
- return {
157
- success: true,
158
- data: {
159
- name: module.name,
160
- hasComposition: false,
161
- message: 'Module does not have composition configuration'
162
- }
163
- };
164
- }
165
-
166
- return {
167
- success: true,
168
- data: {
169
- name: module.name,
170
- hasComposition: true,
171
- pattern: composition.pattern,
172
- requires: composition.requires?.map(d => ({
173
- name: d.name,
174
- version: d.version,
175
- optional: d.optional,
176
- fallback: d.fallback
177
- })),
178
- dataflowSteps: composition.dataflow?.length ?? 0,
179
- routingRules: composition.routing?.length ?? 0,
180
- maxDepth: composition.max_depth,
181
- timeoutMs: composition.timeout_ms,
182
- iteration: composition.iteration
183
- }
184
- };
185
- }