cognitive-modules-cli 2.2.1 → 2.2.7

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 (101) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +35 -29
  4. package/dist/cli.js +519 -23
  5. package/dist/commands/add.d.ts +33 -14
  6. package/dist/commands/add.js +383 -16
  7. package/dist/commands/compose.js +60 -23
  8. package/dist/commands/index.d.ts +4 -0
  9. package/dist/commands/index.js +4 -0
  10. package/dist/commands/init.js +23 -1
  11. package/dist/commands/migrate.d.ts +30 -0
  12. package/dist/commands/migrate.js +650 -0
  13. package/dist/commands/pipe.d.ts +1 -0
  14. package/dist/commands/pipe.js +31 -11
  15. package/dist/commands/remove.js +33 -2
  16. package/dist/commands/run.d.ts +2 -0
  17. package/dist/commands/run.js +61 -28
  18. package/dist/commands/search.d.ts +28 -0
  19. package/dist/commands/search.js +143 -0
  20. package/dist/commands/test.d.ts +65 -0
  21. package/dist/commands/test.js +454 -0
  22. package/dist/commands/update.d.ts +1 -0
  23. package/dist/commands/update.js +106 -14
  24. package/dist/commands/validate.d.ts +36 -0
  25. package/dist/commands/validate.js +97 -0
  26. package/dist/errors/index.d.ts +225 -0
  27. package/dist/errors/index.js +420 -0
  28. package/dist/mcp/server.js +84 -79
  29. package/dist/modules/composition.js +97 -32
  30. package/dist/modules/loader.js +4 -2
  31. package/dist/modules/runner.d.ts +72 -5
  32. package/dist/modules/runner.js +306 -59
  33. package/dist/modules/subagent.d.ts +6 -1
  34. package/dist/modules/subagent.js +18 -13
  35. package/dist/modules/validator.js +14 -6
  36. package/dist/providers/anthropic.d.ts +15 -0
  37. package/dist/providers/anthropic.js +147 -5
  38. package/dist/providers/base.d.ts +11 -0
  39. package/dist/providers/base.js +18 -0
  40. package/dist/providers/gemini.d.ts +15 -0
  41. package/dist/providers/gemini.js +122 -5
  42. package/dist/providers/ollama.d.ts +15 -0
  43. package/dist/providers/ollama.js +111 -3
  44. package/dist/providers/openai.d.ts +11 -0
  45. package/dist/providers/openai.js +133 -0
  46. package/dist/registry/client.d.ts +212 -0
  47. package/dist/registry/client.js +359 -0
  48. package/dist/registry/index.d.ts +4 -0
  49. package/dist/registry/index.js +4 -0
  50. package/dist/registry/tar.d.ts +8 -0
  51. package/dist/registry/tar.js +353 -0
  52. package/dist/server/http.js +301 -45
  53. package/dist/server/index.d.ts +2 -0
  54. package/dist/server/index.js +1 -0
  55. package/dist/server/sse.d.ts +13 -0
  56. package/dist/server/sse.js +22 -0
  57. package/dist/types.d.ts +32 -1
  58. package/dist/types.js +4 -1
  59. package/dist/version.d.ts +1 -0
  60. package/dist/version.js +4 -0
  61. package/package.json +31 -7
  62. package/dist/modules/composition.test.d.ts +0 -11
  63. package/dist/modules/composition.test.js +0 -450
  64. package/dist/modules/policy.test.d.ts +0 -10
  65. package/dist/modules/policy.test.js +0 -369
  66. package/src/cli.ts +0 -471
  67. package/src/commands/add.ts +0 -315
  68. package/src/commands/compose.ts +0 -185
  69. package/src/commands/index.ts +0 -13
  70. package/src/commands/init.ts +0 -94
  71. package/src/commands/list.ts +0 -33
  72. package/src/commands/pipe.ts +0 -76
  73. package/src/commands/remove.ts +0 -57
  74. package/src/commands/run.ts +0 -80
  75. package/src/commands/update.ts +0 -130
  76. package/src/commands/versions.ts +0 -79
  77. package/src/index.ts +0 -90
  78. package/src/mcp/index.ts +0 -5
  79. package/src/mcp/server.ts +0 -403
  80. package/src/modules/composition.test.ts +0 -558
  81. package/src/modules/composition.ts +0 -1674
  82. package/src/modules/index.ts +0 -9
  83. package/src/modules/loader.ts +0 -508
  84. package/src/modules/policy.test.ts +0 -455
  85. package/src/modules/runner.ts +0 -1983
  86. package/src/modules/subagent.ts +0 -277
  87. package/src/modules/validator.ts +0 -700
  88. package/src/providers/anthropic.ts +0 -89
  89. package/src/providers/base.ts +0 -29
  90. package/src/providers/deepseek.ts +0 -83
  91. package/src/providers/gemini.ts +0 -117
  92. package/src/providers/index.ts +0 -78
  93. package/src/providers/minimax.ts +0 -81
  94. package/src/providers/moonshot.ts +0 -82
  95. package/src/providers/ollama.ts +0 -83
  96. package/src/providers/openai.ts +0 -84
  97. package/src/providers/qwen.ts +0 -82
  98. package/src/server/http.ts +0 -316
  99. package/src/server/index.ts +0 -6
  100. package/src/types.ts +0 -599
  101. package/tsconfig.json +0 -17
@@ -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
- }
@@ -1,130 +0,0 @@
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
-
8
- import { existsSync, rmSync } from 'node:fs';
9
- import { readFile } from 'node:fs/promises';
10
- import { join } from 'node:path';
11
- import { homedir } from 'node:os';
12
- import type { CommandContext, CommandResult } from '../types.js';
13
- import { add, getInstallInfo } from './add.js';
14
-
15
- const USER_MODULES_DIR = join(homedir(), '.cognitive', 'modules');
16
-
17
- export interface UpdateOptions {
18
- tag?: string;
19
- }
20
-
21
- /**
22
- * Get module version from installed module
23
- */
24
- async function getInstalledVersion(moduleName: string): Promise<string | undefined> {
25
- const modulePath = join(USER_MODULES_DIR, moduleName);
26
-
27
- if (!existsSync(modulePath)) {
28
- return undefined;
29
- }
30
-
31
- const yaml = await import('js-yaml');
32
-
33
- // Try v2 format
34
- const yamlPath = join(modulePath, 'module.yaml');
35
- if (existsSync(yamlPath)) {
36
- const content = await readFile(yamlPath, 'utf-8');
37
- const data = yaml.load(content) as { version?: string };
38
- return data?.version;
39
- }
40
-
41
- // Try v1 format
42
- const mdPath = existsSync(join(modulePath, 'MODULE.md'))
43
- ? join(modulePath, 'MODULE.md')
44
- : join(modulePath, 'module.md');
45
-
46
- if (existsSync(mdPath)) {
47
- const content = await readFile(mdPath, 'utf-8');
48
- if (content.startsWith('---')) {
49
- const parts = content.split('---');
50
- if (parts.length >= 3) {
51
- const meta = yaml.load(parts[1]) as { version?: string };
52
- return meta?.version;
53
- }
54
- }
55
- }
56
-
57
- return undefined;
58
- }
59
-
60
- /**
61
- * Update an installed module
62
- */
63
- export async function update(
64
- moduleName: string,
65
- ctx: CommandContext,
66
- options: UpdateOptions = {}
67
- ): Promise<CommandResult> {
68
- // Get installation info
69
- const info = await getInstallInfo(moduleName);
70
-
71
- if (!info) {
72
- return {
73
- success: false,
74
- error: `Module not found or not installed from GitHub: ${moduleName}. Only modules installed with 'cog add' can be updated.`,
75
- };
76
- }
77
-
78
- if (!info.githubUrl) {
79
- return {
80
- success: false,
81
- error: `Module was not installed from GitHub: ${moduleName}`,
82
- };
83
- }
84
-
85
- // Get current version
86
- const oldVersion = await getInstalledVersion(moduleName);
87
-
88
- // Determine what ref to use
89
- const tag = options.tag || info.tag;
90
- const branch = info.branch || 'main';
91
-
92
- // Re-install from source
93
- const result = await add(info.githubUrl, ctx, {
94
- module: info.modulePath,
95
- name: moduleName,
96
- tag,
97
- branch: tag ? undefined : branch,
98
- });
99
-
100
- if (!result.success) {
101
- return result;
102
- }
103
-
104
- const data = result.data as { version?: string };
105
- const newVersion = data.version;
106
-
107
- // Determine message
108
- let message: string;
109
- if (oldVersion && newVersion) {
110
- if (oldVersion === newVersion) {
111
- message = `Already up to date: ${moduleName} v${newVersion}`;
112
- } else {
113
- message = `Updated: ${moduleName} v${oldVersion} → v${newVersion}`;
114
- }
115
- } else if (newVersion) {
116
- message = `Updated: ${moduleName} to v${newVersion}`;
117
- } else {
118
- message = `Updated: ${moduleName}`;
119
- }
120
-
121
- return {
122
- success: true,
123
- data: {
124
- message,
125
- name: moduleName,
126
- oldVersion,
127
- newVersion,
128
- },
129
- };
130
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * Versions command - List available versions from GitHub
3
- *
4
- * cog versions ziel-io/cognitive-modules
5
- */
6
-
7
- import type { CommandContext, CommandResult } from '../types.js';
8
-
9
- export interface VersionsOptions {
10
- limit?: number;
11
- }
12
-
13
- /**
14
- * Parse GitHub URL or shorthand
15
- */
16
- function parseGitHubUrl(url: string): { org: string; repo: string } {
17
- if (!url.startsWith('http')) {
18
- url = `https://github.com/${url}`;
19
- }
20
-
21
- const match = url.match(/https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/?/);
22
- if (!match) {
23
- throw new Error(`Invalid GitHub URL: ${url}`);
24
- }
25
-
26
- return {
27
- org: match[1],
28
- repo: match[2].replace(/\.git$/, ''),
29
- };
30
- }
31
-
32
- /**
33
- * List available versions (tags) from GitHub
34
- */
35
- export async function versions(
36
- url: string,
37
- ctx: CommandContext,
38
- options: VersionsOptions = {}
39
- ): Promise<CommandResult> {
40
- const { limit = 10 } = options;
41
-
42
- try {
43
- const { org, repo } = parseGitHubUrl(url);
44
-
45
- // Fetch tags from GitHub API
46
- const apiUrl = `https://api.github.com/repos/${org}/${repo}/tags?per_page=${limit}`;
47
-
48
- const response = await fetch(apiUrl, {
49
- headers: {
50
- 'User-Agent': 'cognitive-runtime/1.0',
51
- 'Accept': 'application/vnd.github.v3+json',
52
- },
53
- });
54
-
55
- if (!response.ok) {
56
- if (response.status === 404) {
57
- throw new Error(`Repository not found: ${org}/${repo}`);
58
- }
59
- throw new Error(`GitHub API error: ${response.status}`);
60
- }
61
-
62
- const data = await response.json() as Array<{ name: string }>;
63
- const tags = data.map(t => t.name);
64
-
65
- return {
66
- success: true,
67
- data: {
68
- repository: `${org}/${repo}`,
69
- tags,
70
- count: tags.length,
71
- },
72
- };
73
- } catch (error) {
74
- return {
75
- success: false,
76
- error: error instanceof Error ? error.message : String(error),
77
- };
78
- }
79
- }
package/src/index.ts DELETED
@@ -1,90 +0,0 @@
1
- /**
2
- * Cognitive Runtime - Main Entry Point
3
- *
4
- * Exports all public APIs for programmatic use.
5
- */
6
-
7
- // Types
8
- export type {
9
- Provider,
10
- InvokeParams,
11
- InvokeResult,
12
- Message,
13
- CognitiveModule,
14
- ModuleResult,
15
- ModuleInput,
16
- ModuleConstraints,
17
- ToolsPolicy,
18
- OutputContract,
19
- FailureContract,
20
- CommandContext,
21
- CommandResult,
22
- // v2.2 Composition Types
23
- CompositionConfig,
24
- CompositionPattern,
25
- DependencyDeclaration,
26
- DataflowStep,
27
- DataflowMapping,
28
- RoutingRule,
29
- AggregationStrategy,
30
- IterationConfig,
31
- } from './types.js';
32
-
33
- // Providers
34
- export {
35
- getProvider,
36
- listProviders,
37
- GeminiProvider,
38
- OpenAIProvider,
39
- AnthropicProvider,
40
- BaseProvider,
41
- } from './providers/index.js';
42
-
43
- // Modules
44
- export {
45
- loadModule,
46
- findModule,
47
- listModules,
48
- getDefaultSearchPaths,
49
- runModule,
50
- // Subagent
51
- SubagentOrchestrator,
52
- runWithSubagents,
53
- parseCalls,
54
- createContext,
55
- // Composition
56
- CompositionOrchestrator,
57
- executeComposition,
58
- validateCompositionConfig,
59
- evaluateJsonPath,
60
- evaluateCondition,
61
- applyMapping,
62
- aggregateResults,
63
- versionMatches,
64
- resolveDependency,
65
- COMPOSITION_ERRORS,
66
- // Policy Enforcement
67
- checkToolPolicy,
68
- checkPolicy,
69
- checkToolAllowed,
70
- validateToolsAllowed,
71
- getDeniedActions,
72
- getDeniedTools,
73
- getAllowedTools,
74
- ToolCallInterceptor,
75
- createPolicyAwareExecutor,
76
- type PolicyAction,
77
- type PolicyCheckResult,
78
- type ToolCallRequest,
79
- type ToolCallResult,
80
- type ToolExecutor,
81
- } from './modules/index.js';
82
-
83
- // Server
84
- export { serve as serveHttp, createServer } from './server/index.js';
85
-
86
- // MCP
87
- export { serve as serveMcp } from './mcp/index.js';
88
-
89
- // Commands
90
- export { run, list, pipe } from './commands/index.js';
package/src/mcp/index.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * MCP Server - Re-export all MCP functionality
3
- */
4
-
5
- export { serve } from './server.js';