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.
Files changed (94) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +35 -29
  4. package/dist/cli.js +572 -28
  5. package/dist/commands/add.d.ts +33 -14
  6. package/dist/commands/add.js +222 -13
  7. package/dist/commands/compose.d.ts +31 -0
  8. package/dist/commands/compose.js +185 -0
  9. package/dist/commands/index.d.ts +5 -0
  10. package/dist/commands/index.js +5 -0
  11. package/dist/commands/init.js +23 -1
  12. package/dist/commands/migrate.d.ts +30 -0
  13. package/dist/commands/migrate.js +650 -0
  14. package/dist/commands/pipe.d.ts +1 -0
  15. package/dist/commands/pipe.js +31 -11
  16. package/dist/commands/remove.js +33 -2
  17. package/dist/commands/run.d.ts +1 -0
  18. package/dist/commands/run.js +37 -27
  19. package/dist/commands/search.d.ts +28 -0
  20. package/dist/commands/search.js +143 -0
  21. package/dist/commands/test.d.ts +65 -0
  22. package/dist/commands/test.js +454 -0
  23. package/dist/commands/update.d.ts +1 -0
  24. package/dist/commands/update.js +106 -14
  25. package/dist/commands/validate.d.ts +36 -0
  26. package/dist/commands/validate.js +97 -0
  27. package/dist/errors/index.d.ts +218 -0
  28. package/dist/errors/index.js +412 -0
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.js +5 -1
  31. package/dist/mcp/server.js +84 -79
  32. package/dist/modules/composition.d.ts +251 -0
  33. package/dist/modules/composition.js +1330 -0
  34. package/dist/modules/index.d.ts +2 -0
  35. package/dist/modules/index.js +2 -0
  36. package/dist/modules/loader.d.ts +22 -2
  37. package/dist/modules/loader.js +171 -6
  38. package/dist/modules/runner.d.ts +422 -1
  39. package/dist/modules/runner.js +1472 -71
  40. package/dist/modules/subagent.d.ts +6 -1
  41. package/dist/modules/subagent.js +20 -13
  42. package/dist/modules/validator.d.ts +28 -0
  43. package/dist/modules/validator.js +637 -0
  44. package/dist/providers/anthropic.d.ts +15 -0
  45. package/dist/providers/anthropic.js +147 -5
  46. package/dist/providers/base.d.ts +11 -0
  47. package/dist/providers/base.js +18 -0
  48. package/dist/providers/gemini.d.ts +15 -0
  49. package/dist/providers/gemini.js +122 -5
  50. package/dist/providers/ollama.d.ts +15 -0
  51. package/dist/providers/ollama.js +111 -3
  52. package/dist/providers/openai.d.ts +11 -0
  53. package/dist/providers/openai.js +133 -0
  54. package/dist/registry/client.d.ts +204 -0
  55. package/dist/registry/client.js +356 -0
  56. package/dist/registry/index.d.ts +4 -0
  57. package/dist/registry/index.js +4 -0
  58. package/dist/server/http.js +173 -42
  59. package/dist/types.d.ts +123 -8
  60. package/dist/types.js +4 -1
  61. package/dist/version.d.ts +1 -0
  62. package/dist/version.js +4 -0
  63. package/package.json +32 -7
  64. package/src/cli.ts +0 -410
  65. package/src/commands/add.ts +0 -315
  66. package/src/commands/index.ts +0 -12
  67. package/src/commands/init.ts +0 -94
  68. package/src/commands/list.ts +0 -33
  69. package/src/commands/pipe.ts +0 -76
  70. package/src/commands/remove.ts +0 -57
  71. package/src/commands/run.ts +0 -80
  72. package/src/commands/update.ts +0 -130
  73. package/src/commands/versions.ts +0 -79
  74. package/src/index.ts +0 -55
  75. package/src/mcp/index.ts +0 -5
  76. package/src/mcp/server.ts +0 -403
  77. package/src/modules/index.ts +0 -7
  78. package/src/modules/loader.ts +0 -318
  79. package/src/modules/runner.ts +0 -495
  80. package/src/modules/subagent.ts +0 -275
  81. package/src/providers/anthropic.ts +0 -89
  82. package/src/providers/base.ts +0 -29
  83. package/src/providers/deepseek.ts +0 -83
  84. package/src/providers/gemini.ts +0 -117
  85. package/src/providers/index.ts +0 -78
  86. package/src/providers/minimax.ts +0 -81
  87. package/src/providers/moonshot.ts +0 -82
  88. package/src/providers/ollama.ts +0 -83
  89. package/src/providers/openai.ts +0 -84
  90. package/src/providers/qwen.ts +0 -82
  91. package/src/server/http.ts +0 -316
  92. package/src/server/index.ts +0 -6
  93. package/src/types.ts +0 -495
  94. 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: Record<string, unknown>): string;
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;
@@ -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 [callStr, callResult] of Object.entries(callResults)) {
79
- const resultStr = typeof callResult === 'object'
80
- ? JSON.stringify(callResult, null, 2)
81
- : String(callResult);
82
- result = result.replace(callStr, `[Result from ${callStr}]:\n${resultStr}`);
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 childInput = childArgs
132
- ? { query: childArgs, code: childArgs }
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[call.match] = childResult.data;
150
+ callResults.push({ match: call.match, module: call.module, result: childResult.data });
147
151
  }
148
152
  else if ('error' in childResult) {
149
- callResults[call.match] = { error: childResult.error };
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 (Object.keys(callResults).length > 0) {
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
+ };