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
package/dist/modules/index.d.ts
CHANGED
package/dist/modules/index.js
CHANGED
package/dist/modules/loader.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Module Loader - Load and parse Cognitive Modules
|
|
3
|
-
* Supports
|
|
3
|
+
* Supports v0 (6-file), v1 (MODULE.md) and v2 (module.yaml + prompt.md) formats
|
|
4
4
|
*/
|
|
5
|
-
import type { CognitiveModule } from '../types.js';
|
|
5
|
+
import type { CognitiveModule, ModuleTier, SchemaStrictness } from '../types.js';
|
|
6
6
|
/**
|
|
7
7
|
* Load a Cognitive Module (auto-detects format)
|
|
8
8
|
*/
|
|
@@ -10,3 +10,23 @@ 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;
|
package/dist/modules/loader.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Module Loader - Load and parse Cognitive Modules
|
|
3
|
-
* Supports
|
|
3
|
+
* Supports v0 (6-file), 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';
|
|
7
|
+
import { homedir } from 'node:os';
|
|
7
8
|
import yaml from 'js-yaml';
|
|
8
9
|
const FRONTMATTER_REGEX = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?/;
|
|
9
10
|
/**
|
|
@@ -11,12 +12,26 @@ const FRONTMATTER_REGEX = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?/;
|
|
|
11
12
|
*/
|
|
12
13
|
async function detectFormat(modulePath) {
|
|
13
14
|
const v2Manifest = path.join(modulePath, 'module.yaml');
|
|
15
|
+
const v1Module = path.join(modulePath, 'MODULE.md');
|
|
16
|
+
const v0Module = path.join(modulePath, 'module.md');
|
|
14
17
|
try {
|
|
15
18
|
await fs.access(v2Manifest);
|
|
16
19
|
return 'v2';
|
|
17
20
|
}
|
|
18
21
|
catch {
|
|
19
|
-
|
|
22
|
+
try {
|
|
23
|
+
await fs.access(v1Module);
|
|
24
|
+
return 'v1';
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
try {
|
|
28
|
+
await fs.access(v0Module);
|
|
29
|
+
return 'v0';
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
throw new Error(`No module.yaml, MODULE.md, or module.md found in ${modulePath}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
20
35
|
}
|
|
21
36
|
}
|
|
22
37
|
/**
|
|
@@ -40,7 +55,8 @@ async function loadModuleV2(modulePath) {
|
|
|
40
55
|
const schemaFile = path.join(modulePath, 'schema.json');
|
|
41
56
|
// Read module.yaml
|
|
42
57
|
const manifestContent = await fs.readFile(manifestFile, 'utf-8');
|
|
43
|
-
const
|
|
58
|
+
const loaded = yaml.load(manifestContent);
|
|
59
|
+
const manifest = loaded && typeof loaded === 'object' ? loaded : {};
|
|
44
60
|
// Detect v2.x version
|
|
45
61
|
const formatVersion = detectV2Version(manifest);
|
|
46
62
|
// Read prompt.md
|
|
@@ -114,6 +130,54 @@ async function loadModuleV2(modulePath) {
|
|
|
114
130
|
required: metaRaw.required,
|
|
115
131
|
risk_rule: validatedRiskRule,
|
|
116
132
|
};
|
|
133
|
+
// Parse composition config (v2.2)
|
|
134
|
+
const compositionRaw = manifest.composition;
|
|
135
|
+
let composition;
|
|
136
|
+
if (compositionRaw) {
|
|
137
|
+
// Parse pattern
|
|
138
|
+
const pattern = compositionRaw.pattern ?? 'sequential';
|
|
139
|
+
// Parse requires (dependencies)
|
|
140
|
+
const requiresRaw = compositionRaw.requires;
|
|
141
|
+
const requires = requiresRaw?.map(dep => ({
|
|
142
|
+
name: dep.name,
|
|
143
|
+
version: dep.version,
|
|
144
|
+
optional: dep.optional,
|
|
145
|
+
fallback: dep.fallback,
|
|
146
|
+
timeout_ms: dep.timeout_ms
|
|
147
|
+
}));
|
|
148
|
+
// Parse dataflow
|
|
149
|
+
const dataflowRaw = compositionRaw.dataflow;
|
|
150
|
+
const dataflow = dataflowRaw?.map(step => ({
|
|
151
|
+
from: step.from,
|
|
152
|
+
to: step.to,
|
|
153
|
+
mapping: step.mapping,
|
|
154
|
+
condition: step.condition,
|
|
155
|
+
aggregate: step.aggregate,
|
|
156
|
+
aggregator: step.aggregator
|
|
157
|
+
}));
|
|
158
|
+
// Parse routing rules
|
|
159
|
+
const routingRaw = compositionRaw.routing;
|
|
160
|
+
const routing = routingRaw?.map(rule => ({
|
|
161
|
+
condition: rule.condition,
|
|
162
|
+
next: rule.next
|
|
163
|
+
}));
|
|
164
|
+
// Parse iteration config
|
|
165
|
+
const iterationRaw = compositionRaw.iteration;
|
|
166
|
+
const iteration = iterationRaw ? {
|
|
167
|
+
max_iterations: iterationRaw.max_iterations,
|
|
168
|
+
continue_condition: iterationRaw.continue_condition,
|
|
169
|
+
stop_condition: iterationRaw.stop_condition
|
|
170
|
+
} : undefined;
|
|
171
|
+
composition = {
|
|
172
|
+
pattern,
|
|
173
|
+
requires,
|
|
174
|
+
dataflow,
|
|
175
|
+
routing,
|
|
176
|
+
max_depth: compositionRaw.max_depth,
|
|
177
|
+
timeout_ms: compositionRaw.timeout_ms,
|
|
178
|
+
iteration
|
|
179
|
+
};
|
|
180
|
+
}
|
|
117
181
|
return {
|
|
118
182
|
name: manifest.name || path.basename(modulePath),
|
|
119
183
|
version: manifest.version || '1.0.0',
|
|
@@ -132,6 +196,7 @@ async function loadModuleV2(modulePath) {
|
|
|
132
196
|
enums,
|
|
133
197
|
compat,
|
|
134
198
|
metaConfig,
|
|
199
|
+
composition,
|
|
135
200
|
// Context and prompt
|
|
136
201
|
context: manifest.context,
|
|
137
202
|
prompt,
|
|
@@ -196,6 +261,63 @@ async function loadModuleV1(modulePath) {
|
|
|
196
261
|
format: 'v1',
|
|
197
262
|
};
|
|
198
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Load v0 format module (6-file format - deprecated)
|
|
266
|
+
*/
|
|
267
|
+
async function loadModuleV0(modulePath) {
|
|
268
|
+
// Read module.md
|
|
269
|
+
const moduleFile = path.join(modulePath, 'module.md');
|
|
270
|
+
const moduleContent = await fs.readFile(moduleFile, 'utf-8');
|
|
271
|
+
// Parse frontmatter
|
|
272
|
+
const match = moduleContent.match(FRONTMATTER_REGEX);
|
|
273
|
+
if (!match) {
|
|
274
|
+
throw new Error(`Invalid module.md: missing YAML frontmatter in ${moduleFile}`);
|
|
275
|
+
}
|
|
276
|
+
const metadata = yaml.load(match[1]);
|
|
277
|
+
// Read schemas
|
|
278
|
+
const inputSchemaFile = path.join(modulePath, 'input.schema.json');
|
|
279
|
+
const outputSchemaFile = path.join(modulePath, 'output.schema.json');
|
|
280
|
+
const constraintsFile = path.join(modulePath, 'constraints.yaml');
|
|
281
|
+
const promptFile = path.join(modulePath, 'prompt.txt');
|
|
282
|
+
const inputSchemaContent = await fs.readFile(inputSchemaFile, 'utf-8');
|
|
283
|
+
const inputSchema = JSON.parse(inputSchemaContent);
|
|
284
|
+
const outputSchemaContent = await fs.readFile(outputSchemaFile, 'utf-8');
|
|
285
|
+
const outputSchema = JSON.parse(outputSchemaContent);
|
|
286
|
+
// Load constraints
|
|
287
|
+
const constraintsContent = await fs.readFile(constraintsFile, 'utf-8');
|
|
288
|
+
const constraintsRaw = yaml.load(constraintsContent);
|
|
289
|
+
// Load prompt
|
|
290
|
+
const prompt = await fs.readFile(promptFile, 'utf-8');
|
|
291
|
+
// Extract constraints
|
|
292
|
+
const constraints = {};
|
|
293
|
+
if (constraintsRaw) {
|
|
294
|
+
const operational = constraintsRaw.operational ?? {};
|
|
295
|
+
constraints.no_network = operational.no_external_network;
|
|
296
|
+
constraints.no_side_effects = operational.no_side_effects;
|
|
297
|
+
constraints.no_file_write = operational.no_file_write;
|
|
298
|
+
constraints.no_inventing_data = operational.no_inventing_data;
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
name: metadata.name || path.basename(modulePath),
|
|
302
|
+
version: metadata.version || '1.0.0',
|
|
303
|
+
responsibility: metadata.responsibility || '',
|
|
304
|
+
excludes: metadata.excludes || [],
|
|
305
|
+
constraints: Object.keys(constraints).length > 0 ? constraints : undefined,
|
|
306
|
+
prompt,
|
|
307
|
+
inputSchema,
|
|
308
|
+
outputSchema,
|
|
309
|
+
dataSchema: outputSchema, // Alias for v2.2 compat
|
|
310
|
+
// v2.2 defaults for v0 modules
|
|
311
|
+
schemaStrictness: 'medium',
|
|
312
|
+
overflow: { enabled: false },
|
|
313
|
+
enums: { strategy: 'strict' },
|
|
314
|
+
compat: { accepts_v21_payload: true, runtime_auto_wrap: true },
|
|
315
|
+
// Metadata
|
|
316
|
+
location: modulePath,
|
|
317
|
+
format: 'v0',
|
|
318
|
+
formatVersion: 'v0.0',
|
|
319
|
+
};
|
|
320
|
+
}
|
|
199
321
|
/**
|
|
200
322
|
* Load a Cognitive Module (auto-detects format)
|
|
201
323
|
*/
|
|
@@ -204,9 +326,12 @@ export async function loadModule(modulePath) {
|
|
|
204
326
|
if (format === 'v2') {
|
|
205
327
|
return loadModuleV2(modulePath);
|
|
206
328
|
}
|
|
207
|
-
else {
|
|
329
|
+
else if (format === 'v1') {
|
|
208
330
|
return loadModuleV1(modulePath);
|
|
209
331
|
}
|
|
332
|
+
else {
|
|
333
|
+
return loadModuleV0(modulePath);
|
|
334
|
+
}
|
|
210
335
|
}
|
|
211
336
|
/**
|
|
212
337
|
* Check if a directory contains a valid module
|
|
@@ -214,6 +339,7 @@ export async function loadModule(modulePath) {
|
|
|
214
339
|
async function isValidModule(modulePath) {
|
|
215
340
|
const v2Manifest = path.join(modulePath, 'module.yaml');
|
|
216
341
|
const v1Module = path.join(modulePath, 'MODULE.md');
|
|
342
|
+
const v0Module = path.join(modulePath, 'module.md');
|
|
217
343
|
try {
|
|
218
344
|
await fs.access(v2Manifest);
|
|
219
345
|
return true;
|
|
@@ -224,7 +350,13 @@ async function isValidModule(modulePath) {
|
|
|
224
350
|
return true;
|
|
225
351
|
}
|
|
226
352
|
catch {
|
|
227
|
-
|
|
353
|
+
try {
|
|
354
|
+
await fs.access(v0Module);
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
228
360
|
}
|
|
229
361
|
}
|
|
230
362
|
}
|
|
@@ -264,10 +396,43 @@ export async function listModules(searchPaths) {
|
|
|
264
396
|
return modules;
|
|
265
397
|
}
|
|
266
398
|
export function getDefaultSearchPaths(cwd) {
|
|
267
|
-
const home =
|
|
399
|
+
const home = homedir();
|
|
268
400
|
return [
|
|
269
401
|
path.join(cwd, 'cognitive', 'modules'),
|
|
270
402
|
path.join(cwd, '.cognitive', 'modules'),
|
|
271
403
|
path.join(home, '.cognitive', 'modules'),
|
|
272
404
|
];
|
|
273
405
|
}
|
|
406
|
+
// =============================================================================
|
|
407
|
+
// Utility Functions
|
|
408
|
+
// =============================================================================
|
|
409
|
+
/**
|
|
410
|
+
* Get module tier (exec, decision, exploration).
|
|
411
|
+
*/
|
|
412
|
+
export function getModuleTier(module) {
|
|
413
|
+
return module.tier;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Get schema strictness level.
|
|
417
|
+
*/
|
|
418
|
+
export function getSchemaStrictness(module) {
|
|
419
|
+
return module.schemaStrictness ?? 'medium';
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Check if overflow (extensions.insights) is enabled.
|
|
423
|
+
*/
|
|
424
|
+
export function isOverflowEnabled(module) {
|
|
425
|
+
return module.overflow?.enabled ?? false;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Get enum extension strategy.
|
|
429
|
+
*/
|
|
430
|
+
export function getEnumStrategy(module) {
|
|
431
|
+
return module.enums?.strategy ?? 'strict';
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Check if runtime should auto-wrap v2.1 to v2.2.
|
|
435
|
+
*/
|
|
436
|
+
export function shouldAutoWrap(module) {
|
|
437
|
+
return module.compat?.runtime_auto_wrap ?? true;
|
|
438
|
+
}
|