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
@@ -1,315 +0,0 @@
1
- /**
2
- * Add command - Install modules from GitHub
3
- *
4
- * cog add ziel-io/cognitive-modules -m code-simplifier
5
- * cog add https://github.com/org/repo --module name --tag v1.0.0
6
- */
7
-
8
- import { createWriteStream, existsSync, mkdirSync, rmSync, readdirSync, statSync, copyFileSync } from 'node:fs';
9
- import { writeFile, readFile, mkdir, rm } from 'node:fs/promises';
10
- import { pipeline } from 'node:stream/promises';
11
- import { Readable } from 'node:stream';
12
- import { join, basename } from 'node:path';
13
- import { homedir, tmpdir } from 'node:os';
14
- import { createGunzip } from 'node:zlib';
15
- import type { CommandContext, CommandResult } from '../types.js';
16
-
17
- // Module storage paths
18
- const USER_MODULES_DIR = join(homedir(), '.cognitive', 'modules');
19
- const INSTALLED_MANIFEST = join(homedir(), '.cognitive', 'installed.json');
20
-
21
- export interface AddOptions {
22
- module?: string;
23
- name?: string;
24
- branch?: string;
25
- tag?: string;
26
- }
27
-
28
- interface InstallManifest {
29
- [moduleName: string]: {
30
- source: string;
31
- githubUrl: string;
32
- modulePath?: string;
33
- tag?: string;
34
- branch?: string;
35
- version?: string;
36
- installedAt: string;
37
- installedTime: string;
38
- };
39
- }
40
-
41
- /**
42
- * Parse GitHub URL or shorthand
43
- */
44
- function parseGitHubUrl(url: string): { org: string; repo: string; fullUrl: string } {
45
- // Handle shorthand: org/repo
46
- if (!url.startsWith('http')) {
47
- url = `https://github.com/${url}`;
48
- }
49
-
50
- const match = url.match(/https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/?/);
51
- if (!match) {
52
- throw new Error(`Invalid GitHub URL: ${url}`);
53
- }
54
-
55
- const org = match[1];
56
- const repo = match[2].replace(/\.git$/, '');
57
-
58
- return {
59
- org,
60
- repo,
61
- fullUrl: `https://github.com/${org}/${repo}`,
62
- };
63
- }
64
-
65
- /**
66
- * Download and extract ZIP from GitHub
67
- */
68
- async function downloadAndExtract(
69
- org: string,
70
- repo: string,
71
- ref: string,
72
- isTag: boolean
73
- ): Promise<string> {
74
- const zipUrl = isTag
75
- ? `https://github.com/${org}/${repo}/archive/refs/tags/${ref}.zip`
76
- : `https://github.com/${org}/${repo}/archive/refs/heads/${ref}.zip`;
77
-
78
- // Create temp directory
79
- const tempDir = join(tmpdir(), `cog-${Date.now()}`);
80
- mkdirSync(tempDir, { recursive: true });
81
-
82
- const zipPath = join(tempDir, 'repo.zip');
83
-
84
- // Download ZIP
85
- const response = await fetch(zipUrl, {
86
- headers: { 'User-Agent': 'cognitive-runtime/1.0' },
87
- });
88
-
89
- if (!response.ok) {
90
- throw new Error(`Failed to download: ${response.status} ${response.statusText}`);
91
- }
92
-
93
- // Save to file
94
- const fileStream = createWriteStream(zipPath);
95
- await pipeline(Readable.fromWeb(response.body as any), fileStream);
96
-
97
- // Extract using built-in unzip (available on most systems)
98
- const { execSync } = await import('node:child_process');
99
- execSync(`unzip -q "${zipPath}" -d "${tempDir}"`, { stdio: 'pipe' });
100
-
101
- // Find extracted directory
102
- const entries = readdirSync(tempDir).filter(
103
- e => e !== 'repo.zip' && statSync(join(tempDir, e)).isDirectory()
104
- );
105
-
106
- if (entries.length === 0) {
107
- throw new Error('ZIP file was empty');
108
- }
109
-
110
- return join(tempDir, entries[0]);
111
- }
112
-
113
- /**
114
- * Check if a directory is a valid module
115
- */
116
- function isValidModule(path: string): boolean {
117
- return (
118
- existsSync(join(path, 'module.yaml')) ||
119
- existsSync(join(path, 'MODULE.md')) ||
120
- existsSync(join(path, 'module.md'))
121
- );
122
- }
123
-
124
- /**
125
- * Find module within repository
126
- */
127
- function findModuleInRepo(repoRoot: string, modulePath: string): string {
128
- const possiblePaths = [
129
- join(repoRoot, modulePath),
130
- join(repoRoot, 'cognitive', 'modules', modulePath),
131
- join(repoRoot, 'modules', modulePath),
132
- ];
133
-
134
- for (const p of possiblePaths) {
135
- if (existsSync(p) && isValidModule(p)) {
136
- return p;
137
- }
138
- }
139
-
140
- throw new Error(
141
- `Module not found at: ${modulePath}\n` +
142
- `Searched in: ${possiblePaths.map(p => p.replace(repoRoot, '.')).join(', ')}`
143
- );
144
- }
145
-
146
- /**
147
- * Copy directory recursively
148
- */
149
- function copyDir(src: string, dest: string): void {
150
- mkdirSync(dest, { recursive: true });
151
-
152
- for (const entry of readdirSync(src)) {
153
- const srcPath = join(src, entry);
154
- const destPath = join(dest, entry);
155
-
156
- if (statSync(srcPath).isDirectory()) {
157
- copyDir(srcPath, destPath);
158
- } else {
159
- copyFileSync(srcPath, destPath);
160
- }
161
- }
162
- }
163
-
164
- /**
165
- * Get module version from module.yaml or MODULE.md
166
- */
167
- async function getModuleVersion(modulePath: string): Promise<string | undefined> {
168
- const yaml = await import('js-yaml');
169
-
170
- // Try v2 format
171
- const yamlPath = join(modulePath, 'module.yaml');
172
- if (existsSync(yamlPath)) {
173
- const content = await readFile(yamlPath, 'utf-8');
174
- const data = yaml.load(content) as { version?: string };
175
- return data?.version;
176
- }
177
-
178
- // Try v1 format
179
- const mdPath = existsSync(join(modulePath, 'MODULE.md'))
180
- ? join(modulePath, 'MODULE.md')
181
- : join(modulePath, 'module.md');
182
-
183
- if (existsSync(mdPath)) {
184
- const content = await readFile(mdPath, 'utf-8');
185
- if (content.startsWith('---')) {
186
- const parts = content.split('---');
187
- if (parts.length >= 3) {
188
- const meta = yaml.load(parts[1]) as { version?: string };
189
- return meta?.version;
190
- }
191
- }
192
- }
193
-
194
- return undefined;
195
- }
196
-
197
- /**
198
- * Record installation info
199
- */
200
- async function recordInstall(
201
- moduleName: string,
202
- info: InstallManifest[string]
203
- ): Promise<void> {
204
- let manifest: InstallManifest = {};
205
-
206
- if (existsSync(INSTALLED_MANIFEST)) {
207
- const content = await readFile(INSTALLED_MANIFEST, 'utf-8');
208
- manifest = JSON.parse(content);
209
- }
210
-
211
- manifest[moduleName] = info;
212
-
213
- await mkdir(join(homedir(), '.cognitive'), { recursive: true });
214
- await writeFile(INSTALLED_MANIFEST, JSON.stringify(manifest, null, 2));
215
- }
216
-
217
- /**
218
- * Get installation info for a module
219
- */
220
- export async function getInstallInfo(moduleName: string): Promise<InstallManifest[string] | null> {
221
- if (!existsSync(INSTALLED_MANIFEST)) {
222
- return null;
223
- }
224
-
225
- const content = await readFile(INSTALLED_MANIFEST, 'utf-8');
226
- const manifest: InstallManifest = JSON.parse(content);
227
- return manifest[moduleName] || null;
228
- }
229
-
230
- /**
231
- * Add a module from GitHub
232
- */
233
- export async function add(
234
- url: string,
235
- ctx: CommandContext,
236
- options: AddOptions = {}
237
- ): Promise<CommandResult> {
238
- const { org, repo, fullUrl } = parseGitHubUrl(url);
239
- const { module: modulePath, name, branch = 'main', tag } = options;
240
-
241
- // Determine ref (tag takes priority)
242
- const ref = tag || branch;
243
- const isTag = !!tag;
244
-
245
- let repoRoot: string;
246
- let sourcePath: string;
247
- let moduleName: string;
248
-
249
- try {
250
- // Download repository
251
- repoRoot = await downloadAndExtract(org, repo, ref, isTag);
252
-
253
- // Find module
254
- if (modulePath) {
255
- sourcePath = findModuleInRepo(repoRoot, modulePath);
256
- } else {
257
- // Use repo root as module
258
- if (!isValidModule(repoRoot)) {
259
- throw new Error(
260
- 'Repository root is not a valid module. Use --module to specify the module path.'
261
- );
262
- }
263
- sourcePath = repoRoot;
264
- }
265
-
266
- // Determine module name
267
- moduleName = name || basename(sourcePath);
268
-
269
- // Get version
270
- const version = await getModuleVersion(sourcePath);
271
-
272
- // Install to user modules dir
273
- const targetPath = join(USER_MODULES_DIR, moduleName);
274
-
275
- // Remove existing
276
- if (existsSync(targetPath)) {
277
- rmSync(targetPath, { recursive: true, force: true });
278
- }
279
-
280
- // Copy module
281
- await mkdir(USER_MODULES_DIR, { recursive: true });
282
- copyDir(sourcePath, targetPath);
283
-
284
- // Record installation info
285
- await recordInstall(moduleName, {
286
- source: sourcePath,
287
- githubUrl: fullUrl,
288
- modulePath,
289
- tag,
290
- branch,
291
- version,
292
- installedAt: targetPath,
293
- installedTime: new Date().toISOString(),
294
- });
295
-
296
- // Cleanup temp directory
297
- const tempDir = repoRoot.split('/').slice(0, -1).join('/');
298
- rmSync(tempDir, { recursive: true, force: true });
299
-
300
- return {
301
- success: true,
302
- data: {
303
- message: `Added: ${moduleName}${version ? ` v${version}` : ''}`,
304
- name: moduleName,
305
- version,
306
- location: targetPath,
307
- },
308
- };
309
- } catch (error) {
310
- return {
311
- success: false,
312
- error: error instanceof Error ? error.message : String(error),
313
- };
314
- }
315
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Commands - Re-export all commands
3
- */
4
-
5
- export * from './run.js';
6
- export * from './list.js';
7
- export * from './pipe.js';
8
- export * from './init.js';
9
- export * from './add.js';
10
- export * from './update.js';
11
- export * from './remove.js';
12
- export * from './versions.js';
@@ -1,94 +0,0 @@
1
- /**
2
- * cog init - Initialize a new Cognitive project
3
- */
4
-
5
- import * as fs from 'node:fs/promises';
6
- import * as path from 'node:path';
7
- import type { CommandContext, CommandResult } from '../types.js';
8
-
9
- const EXAMPLE_MODULE_MD = `---
10
- name: my-module
11
- version: 1.0.0
12
- responsibility: Describe what this module does
13
- excludes:
14
- - Do not do X
15
- - Do not do Y
16
- ---
17
-
18
- Analyze the following input and provide a structured response:
19
-
20
- $ARGUMENTS
21
-
22
- Return a JSON object with your analysis.
23
- `;
24
-
25
- const EXAMPLE_SCHEMA_JSON = `{
26
- "type": "object",
27
- "properties": {
28
- "result": {
29
- "type": "string",
30
- "description": "The main result of the analysis"
31
- },
32
- "confidence": {
33
- "type": "number",
34
- "minimum": 0,
35
- "maximum": 1,
36
- "description": "Confidence score"
37
- },
38
- "rationale": {
39
- "type": "string",
40
- "description": "Explanation of the reasoning"
41
- }
42
- },
43
- "required": ["result", "confidence", "rationale"]
44
- }
45
- `;
46
-
47
- export async function init(ctx: CommandContext, moduleName?: string): Promise<CommandResult> {
48
- const cognitiveDir = path.join(ctx.cwd, 'cognitive', 'modules');
49
-
50
- try {
51
- // Create directory structure
52
- await fs.mkdir(cognitiveDir, { recursive: true });
53
-
54
- // If module name provided, create a new module
55
- if (moduleName) {
56
- const moduleDir = path.join(cognitiveDir, moduleName);
57
- await fs.mkdir(moduleDir, { recursive: true });
58
-
59
- await fs.writeFile(
60
- path.join(moduleDir, 'MODULE.md'),
61
- EXAMPLE_MODULE_MD.replace('my-module', moduleName)
62
- );
63
-
64
- await fs.writeFile(
65
- path.join(moduleDir, 'schema.json'),
66
- EXAMPLE_SCHEMA_JSON
67
- );
68
-
69
- return {
70
- success: true,
71
- data: {
72
- message: `Created module: ${moduleName}`,
73
- location: moduleDir,
74
- files: ['MODULE.md', 'schema.json'],
75
- },
76
- };
77
- }
78
-
79
- // Just initialize the directory
80
- return {
81
- success: true,
82
- data: {
83
- message: 'Cognitive project initialized',
84
- location: cognitiveDir,
85
- hint: 'Run "cog init <module-name>" to create a new module',
86
- },
87
- };
88
- } catch (e) {
89
- return {
90
- success: false,
91
- error: e instanceof Error ? e.message : String(e),
92
- };
93
- }
94
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * cog list - List available Cognitive Modules
3
- */
4
-
5
- import type { CommandContext, CommandResult } from '../types.js';
6
- import { listModules, getDefaultSearchPaths } from '../modules/index.js';
7
-
8
- export async function list(ctx: CommandContext): Promise<CommandResult> {
9
- const searchPaths = getDefaultSearchPaths(ctx.cwd);
10
- const modules = await listModules(searchPaths);
11
-
12
- if (modules.length === 0) {
13
- return {
14
- success: true,
15
- data: {
16
- modules: [],
17
- message: `No modules found in: ${searchPaths.join(', ')}`,
18
- },
19
- };
20
- }
21
-
22
- return {
23
- success: true,
24
- data: {
25
- modules: modules.map(m => ({
26
- name: m.name,
27
- version: m.version,
28
- responsibility: m.responsibility,
29
- location: m.location,
30
- })),
31
- },
32
- };
33
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * cog pipe - Pipe mode for stdin/stdout integration
3
- */
4
-
5
- import * as readline from 'node:readline';
6
- import type { CommandContext, CommandResult } from '../types.js';
7
- import { findModule, getDefaultSearchPaths, runModule } from '../modules/index.js';
8
-
9
- export interface PipeOptions {
10
- module: string;
11
- noValidate?: boolean;
12
- }
13
-
14
- export async function pipe(
15
- ctx: CommandContext,
16
- options: PipeOptions
17
- ): Promise<CommandResult> {
18
- const searchPaths = getDefaultSearchPaths(ctx.cwd);
19
-
20
- // Find module
21
- const module = await findModule(options.module, searchPaths);
22
- if (!module) {
23
- return {
24
- success: false,
25
- error: `Module not found: ${options.module}`,
26
- };
27
- }
28
-
29
- // Read from stdin
30
- const rl = readline.createInterface({
31
- input: process.stdin,
32
- output: process.stdout,
33
- terminal: false,
34
- });
35
-
36
- const lines: string[] = [];
37
- for await (const line of rl) {
38
- lines.push(line);
39
- }
40
-
41
- const input = lines.join('\n');
42
-
43
- try {
44
- // Check if input is JSON
45
- let inputData: Record<string, unknown> | undefined;
46
- try {
47
- inputData = JSON.parse(input);
48
- } catch {
49
- // Not JSON, use as args
50
- }
51
-
52
- const result = await runModule(module, ctx.provider, {
53
- args: inputData ? undefined : input,
54
- input: inputData,
55
- });
56
-
57
- // Output envelope format to stdout
58
- console.log(JSON.stringify(result));
59
-
60
- return {
61
- success: result.ok,
62
- data: result,
63
- };
64
- } catch (e) {
65
- const error = e instanceof Error ? e.message : String(e);
66
- // Output error in envelope format
67
- console.log(JSON.stringify({
68
- ok: false,
69
- error: { code: 'RUNTIME_ERROR', message: error }
70
- }));
71
- return {
72
- success: false,
73
- error,
74
- };
75
- }
76
- }
@@ -1,57 +0,0 @@
1
- /**
2
- * Remove command - Remove installed modules
3
- *
4
- * cog remove code-simplifier
5
- */
6
-
7
- import { existsSync, rmSync } from 'node:fs';
8
- import { readFile, writeFile } from 'node:fs/promises';
9
- import { join } from 'node:path';
10
- import { homedir } from 'node:os';
11
- import type { CommandContext, CommandResult } from '../types.js';
12
-
13
- const USER_MODULES_DIR = join(homedir(), '.cognitive', 'modules');
14
- const INSTALLED_MANIFEST = join(homedir(), '.cognitive', 'installed.json');
15
-
16
- /**
17
- * Remove an installed module
18
- */
19
- export async function remove(
20
- moduleName: string,
21
- ctx: CommandContext
22
- ): Promise<CommandResult> {
23
- const modulePath = join(USER_MODULES_DIR, moduleName);
24
-
25
- if (!existsSync(modulePath)) {
26
- return {
27
- success: false,
28
- error: `Module not found in global location: ${moduleName}. Only modules in ~/.cognitive/modules can be removed.`,
29
- };
30
- }
31
-
32
- try {
33
- // Remove module directory
34
- rmSync(modulePath, { recursive: true, force: true });
35
-
36
- // Remove from manifest
37
- if (existsSync(INSTALLED_MANIFEST)) {
38
- const content = await readFile(INSTALLED_MANIFEST, 'utf-8');
39
- const manifest = JSON.parse(content);
40
- delete manifest[moduleName];
41
- await writeFile(INSTALLED_MANIFEST, JSON.stringify(manifest, null, 2));
42
- }
43
-
44
- return {
45
- success: true,
46
- data: {
47
- message: `Removed: ${moduleName}`,
48
- name: moduleName,
49
- },
50
- };
51
- } catch (error) {
52
- return {
53
- success: false,
54
- error: error instanceof Error ? error.message : String(error),
55
- };
56
- }
57
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * cog run - Run a Cognitive Module
3
- */
4
-
5
- import type { CommandContext, CommandResult } from '../types.js';
6
- import { findModule, getDefaultSearchPaths, runModule } from '../modules/index.js';
7
-
8
- export interface RunOptions {
9
- args?: string;
10
- input?: string;
11
- noValidate?: boolean;
12
- pretty?: boolean;
13
- verbose?: boolean;
14
- }
15
-
16
- export async function run(
17
- moduleName: string,
18
- ctx: CommandContext,
19
- options: RunOptions = {}
20
- ): Promise<CommandResult> {
21
- const searchPaths = getDefaultSearchPaths(ctx.cwd);
22
-
23
- // Find module
24
- const module = await findModule(moduleName, searchPaths);
25
- if (!module) {
26
- return {
27
- success: false,
28
- error: `Module not found: ${moduleName}\nSearch paths: ${searchPaths.join(', ')}`,
29
- };
30
- }
31
-
32
- try {
33
- // Parse input if provided as JSON
34
- let inputData: Record<string, unknown> | undefined;
35
- if (options.input) {
36
- try {
37
- inputData = JSON.parse(options.input);
38
- } catch {
39
- return {
40
- success: false,
41
- error: `Invalid JSON input: ${options.input}`,
42
- };
43
- }
44
- }
45
-
46
- // Run module
47
- const result = await runModule(module, ctx.provider, {
48
- args: options.args,
49
- input: inputData,
50
- verbose: options.verbose || ctx.verbose,
51
- });
52
-
53
- // Return envelope format or extracted data
54
- if (options.pretty) {
55
- return {
56
- success: result.ok,
57
- data: result,
58
- };
59
- } else {
60
- // For non-pretty mode, return data (success) or error (failure)
61
- if (result.ok) {
62
- return {
63
- success: true,
64
- data: result.data,
65
- };
66
- } else {
67
- return {
68
- success: false,
69
- error: `${result.error?.code}: ${result.error?.message}`,
70
- data: result.partial_data,
71
- };
72
- }
73
- }
74
- } catch (e) {
75
- return {
76
- success: false,
77
- error: e instanceof Error ? e.message : String(e),
78
- };
79
- }
80
- }