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.
- package/dist/cli.js +12 -65
- package/dist/commands/index.d.ts +0 -1
- package/dist/commands/index.js +0 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -5
- package/dist/modules/index.d.ts +0 -2
- package/dist/modules/index.js +0 -2
- package/dist/modules/loader.d.ts +2 -22
- package/dist/modules/loader.js +4 -167
- package/dist/modules/runner.d.ts +34 -348
- package/dist/modules/runner.js +708 -1263
- package/dist/modules/subagent.js +0 -2
- package/dist/providers/base.d.ts +45 -1
- package/dist/providers/base.js +67 -0
- package/dist/providers/openai.d.ts +27 -3
- package/dist/providers/openai.js +175 -3
- package/dist/types.d.ts +316 -93
- package/dist/types.js +120 -1
- package/package.json +1 -2
- package/src/cli.ts +12 -73
- package/src/commands/index.ts +0 -1
- package/src/index.ts +0 -35
- package/src/modules/index.ts +0 -2
- package/src/modules/loader.ts +6 -196
- package/src/modules/runner.ts +996 -1690
- package/src/modules/subagent.ts +0 -2
- package/src/providers/base.ts +86 -1
- package/src/providers/openai.ts +226 -4
- package/src/types.ts +462 -113
- package/tsconfig.json +1 -1
- package/dist/commands/compose.d.ts +0 -31
- package/dist/commands/compose.js +0 -148
- package/dist/modules/composition.d.ts +0 -251
- package/dist/modules/composition.js +0 -1265
- package/dist/modules/composition.test.d.ts +0 -11
- package/dist/modules/composition.test.js +0 -450
- package/dist/modules/policy.test.d.ts +0 -10
- package/dist/modules/policy.test.js +0 -369
- package/dist/modules/validator.d.ts +0 -28
- package/dist/modules/validator.js +0 -629
- package/src/commands/compose.ts +0 -185
- package/src/modules/composition.test.ts +0 -558
- package/src/modules/composition.ts +0 -1674
- package/src/modules/policy.test.ts +0 -455
- package/src/modules/validator.ts +0 -700
package/src/commands/compose.ts
DELETED
|
@@ -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
|
-
}
|