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.
- package/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +35 -29
- package/dist/cli.js +572 -28
- package/dist/commands/add.d.ts +33 -14
- package/dist/commands/add.js +222 -13
- package/dist/commands/compose.d.ts +31 -0
- package/dist/commands/compose.js +185 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.js +5 -0
- package/dist/commands/init.js +23 -1
- package/dist/commands/migrate.d.ts +30 -0
- package/dist/commands/migrate.js +650 -0
- package/dist/commands/pipe.d.ts +1 -0
- package/dist/commands/pipe.js +31 -11
- package/dist/commands/remove.js +33 -2
- package/dist/commands/run.d.ts +1 -0
- package/dist/commands/run.js +37 -27
- package/dist/commands/search.d.ts +28 -0
- package/dist/commands/search.js +143 -0
- package/dist/commands/test.d.ts +65 -0
- package/dist/commands/test.js +454 -0
- package/dist/commands/update.d.ts +1 -0
- package/dist/commands/update.js +106 -14
- package/dist/commands/validate.d.ts +36 -0
- package/dist/commands/validate.js +97 -0
- package/dist/errors/index.d.ts +218 -0
- package/dist/errors/index.js +412 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -1
- package/dist/mcp/server.js +84 -79
- package/dist/modules/composition.d.ts +251 -0
- package/dist/modules/composition.js +1330 -0
- package/dist/modules/index.d.ts +2 -0
- package/dist/modules/index.js +2 -0
- package/dist/modules/loader.d.ts +22 -2
- package/dist/modules/loader.js +171 -6
- package/dist/modules/runner.d.ts +422 -1
- package/dist/modules/runner.js +1472 -71
- package/dist/modules/subagent.d.ts +6 -1
- package/dist/modules/subagent.js +20 -13
- package/dist/modules/validator.d.ts +28 -0
- package/dist/modules/validator.js +637 -0
- package/dist/providers/anthropic.d.ts +15 -0
- package/dist/providers/anthropic.js +147 -5
- package/dist/providers/base.d.ts +11 -0
- package/dist/providers/base.js +18 -0
- package/dist/providers/gemini.d.ts +15 -0
- package/dist/providers/gemini.js +122 -5
- package/dist/providers/ollama.d.ts +15 -0
- package/dist/providers/ollama.js +111 -3
- package/dist/providers/openai.d.ts +11 -0
- package/dist/providers/openai.js +133 -0
- package/dist/registry/client.d.ts +204 -0
- package/dist/registry/client.js +356 -0
- package/dist/registry/index.d.ts +4 -0
- package/dist/registry/index.js +4 -0
- package/dist/server/http.js +173 -42
- package/dist/types.d.ts +123 -8
- package/dist/types.js +4 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/package.json +32 -7
- package/src/cli.ts +0 -410
- package/src/commands/add.ts +0 -315
- package/src/commands/index.ts +0 -12
- package/src/commands/init.ts +0 -94
- package/src/commands/list.ts +0 -33
- package/src/commands/pipe.ts +0 -76
- package/src/commands/remove.ts +0 -57
- package/src/commands/run.ts +0 -80
- package/src/commands/update.ts +0 -130
- package/src/commands/versions.ts +0 -79
- package/src/index.ts +0 -55
- package/src/mcp/index.ts +0 -5
- package/src/mcp/server.ts +0 -403
- package/src/modules/index.ts +0 -7
- package/src/modules/loader.ts +0 -318
- package/src/modules/runner.ts +0 -495
- package/src/modules/subagent.ts +0 -275
- package/src/providers/anthropic.ts +0 -89
- package/src/providers/base.ts +0 -29
- package/src/providers/deepseek.ts +0 -83
- package/src/providers/gemini.ts +0 -117
- package/src/providers/index.ts +0 -78
- package/src/providers/minimax.ts +0 -81
- package/src/providers/moonshot.ts +0 -82
- package/src/providers/ollama.ts +0 -83
- package/src/providers/openai.ts +0 -84
- package/src/providers/qwen.ts +0 -82
- package/src/server/http.ts +0 -316
- package/src/server/index.ts +0 -6
- package/src/types.ts +0 -495
- package/tsconfig.json +0 -17
|
@@ -22,6 +22,7 @@ export interface CallDirective {
|
|
|
22
22
|
}
|
|
23
23
|
export interface SubagentRunOptions {
|
|
24
24
|
input?: ModuleInput;
|
|
25
|
+
args?: string;
|
|
25
26
|
validateInput?: boolean;
|
|
26
27
|
validateOutput?: boolean;
|
|
27
28
|
maxDepth?: number;
|
|
@@ -45,7 +46,11 @@ export declare function parseCalls(text: string): CallDirective[];
|
|
|
45
46
|
/**
|
|
46
47
|
* Replace @call directives with their results
|
|
47
48
|
*/
|
|
48
|
-
export declare function substituteCallResults(text: string, callResults:
|
|
49
|
+
export declare function substituteCallResults(text: string, callResults: Array<{
|
|
50
|
+
match: string;
|
|
51
|
+
module: string;
|
|
52
|
+
result: unknown;
|
|
53
|
+
}>): string;
|
|
49
54
|
export declare class SubagentOrchestrator {
|
|
50
55
|
private provider;
|
|
51
56
|
private running;
|
package/dist/modules/subagent.js
CHANGED
|
@@ -75,11 +75,15 @@ export function parseCalls(text) {
|
|
|
75
75
|
*/
|
|
76
76
|
export function substituteCallResults(text, callResults) {
|
|
77
77
|
let result = text;
|
|
78
|
-
for (const
|
|
79
|
-
const resultStr = typeof
|
|
80
|
-
? JSON.stringify(
|
|
81
|
-
: String(
|
|
82
|
-
|
|
78
|
+
for (const entry of callResults) {
|
|
79
|
+
const resultStr = typeof entry.result === 'object'
|
|
80
|
+
? JSON.stringify(entry.result, null, 2)
|
|
81
|
+
: String(entry.result);
|
|
82
|
+
const replacement = `[Result from ${entry.module}]:\n${resultStr}`;
|
|
83
|
+
const idx = result.indexOf(entry.match);
|
|
84
|
+
if (idx !== -1) {
|
|
85
|
+
result = result.slice(0, idx) + replacement + result.slice(idx + entry.match.length);
|
|
86
|
+
}
|
|
83
87
|
}
|
|
84
88
|
return result;
|
|
85
89
|
}
|
|
@@ -99,7 +103,7 @@ export class SubagentOrchestrator {
|
|
|
99
103
|
* Recursively resolves @call directives before final execution.
|
|
100
104
|
*/
|
|
101
105
|
async run(moduleName, options = {}, context) {
|
|
102
|
-
const { input = {}, validateInput = true, validateOutput = true, maxDepth = 5 } = options;
|
|
106
|
+
const { input = {}, args, validateInput = true, validateOutput = true, maxDepth = 5 } = options;
|
|
103
107
|
// Initialize context
|
|
104
108
|
const ctx = context ?? createContext(maxDepth);
|
|
105
109
|
// Check depth limit
|
|
@@ -122,15 +126,14 @@ export class SubagentOrchestrator {
|
|
|
122
126
|
const moduleContextMode = module.context ?? 'main';
|
|
123
127
|
// Parse @call directives from prompt
|
|
124
128
|
const calls = parseCalls(module.prompt);
|
|
125
|
-
const callResults =
|
|
129
|
+
const callResults = [];
|
|
126
130
|
// Resolve each @call directive
|
|
127
131
|
for (const call of calls) {
|
|
128
132
|
const childModule = call.module;
|
|
129
133
|
const childArgs = call.args;
|
|
130
134
|
// Prepare child input
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
: { ...input };
|
|
135
|
+
const hasChildArgs = childArgs.length > 0;
|
|
136
|
+
const childInput = hasChildArgs ? {} : { ...input };
|
|
134
137
|
// Determine child context
|
|
135
138
|
const childContext = moduleContextMode === 'fork'
|
|
136
139
|
? forkContext(ctx, moduleName)
|
|
@@ -138,20 +141,21 @@ export class SubagentOrchestrator {
|
|
|
138
141
|
// Recursively run child module
|
|
139
142
|
const childResult = await this.run(childModule, {
|
|
140
143
|
input: childInput,
|
|
144
|
+
args: hasChildArgs ? childArgs : undefined,
|
|
141
145
|
validateInput: false, // Skip validation for @call args
|
|
142
146
|
validateOutput
|
|
143
147
|
}, childContext);
|
|
144
148
|
// Store result
|
|
145
149
|
if (childResult.ok && 'data' in childResult) {
|
|
146
|
-
callResults
|
|
150
|
+
callResults.push({ match: call.match, module: call.module, result: childResult.data });
|
|
147
151
|
}
|
|
148
152
|
else if ('error' in childResult) {
|
|
149
|
-
callResults
|
|
153
|
+
callResults.push({ match: call.match, module: call.module, result: { error: childResult.error } });
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
// Substitute call results into prompt
|
|
153
157
|
let modifiedModule = module;
|
|
154
|
-
if (
|
|
158
|
+
if (callResults.length > 0) {
|
|
155
159
|
const modifiedPrompt = substituteCallResults(module.prompt, callResults);
|
|
156
160
|
modifiedModule = {
|
|
157
161
|
...module,
|
|
@@ -161,6 +165,9 @@ export class SubagentOrchestrator {
|
|
|
161
165
|
// Run the module
|
|
162
166
|
const result = await runModule(modifiedModule, this.provider, {
|
|
163
167
|
input,
|
|
168
|
+
args,
|
|
169
|
+
validateInput,
|
|
170
|
+
validateOutput,
|
|
164
171
|
verbose: false,
|
|
165
172
|
useV22: true
|
|
166
173
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Validator - Validate cognitive module structure and examples.
|
|
3
|
+
* Supports v0, v1, v2.1, and v2.2 module formats.
|
|
4
|
+
*/
|
|
5
|
+
export interface ValidationResult {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
errors: string[];
|
|
8
|
+
warnings: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validate a cognitive module's structure and examples.
|
|
12
|
+
* Supports all formats.
|
|
13
|
+
*
|
|
14
|
+
* @param nameOrPath Module name or path
|
|
15
|
+
* @param v22 If true, validate v2.2 specific requirements
|
|
16
|
+
* @returns Validation result with errors and warnings
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateModule(modulePath: string, v22?: boolean): Promise<ValidationResult>;
|
|
19
|
+
/**
|
|
20
|
+
* Validate a response against v2.2 envelope format.
|
|
21
|
+
*
|
|
22
|
+
* @param response The response dict to validate
|
|
23
|
+
* @returns Validation result
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateV22Envelope(response: Record<string, unknown>): {
|
|
26
|
+
valid: boolean;
|
|
27
|
+
errors: string[];
|
|
28
|
+
};
|