cognitive-modules 0.6.0

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