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.
- package/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +35 -29
- package/dist/cli.js +519 -23
- package/dist/commands/add.d.ts +33 -14
- package/dist/commands/add.js +383 -16
- package/dist/commands/compose.js +60 -23
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.js +4 -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 +2 -0
- package/dist/commands/run.js +61 -28
- 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 +225 -0
- package/dist/errors/index.js +420 -0
- package/dist/mcp/server.js +84 -79
- package/dist/modules/composition.js +97 -32
- package/dist/modules/loader.js +4 -2
- package/dist/modules/runner.d.ts +72 -5
- package/dist/modules/runner.js +306 -59
- package/dist/modules/subagent.d.ts +6 -1
- package/dist/modules/subagent.js +18 -13
- package/dist/modules/validator.js +14 -6
- 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 +212 -0
- package/dist/registry/client.js +359 -0
- package/dist/registry/index.d.ts +4 -0
- package/dist/registry/index.js +4 -0
- package/dist/registry/tar.d.ts +8 -0
- package/dist/registry/tar.js +353 -0
- package/dist/server/http.js +301 -45
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +1 -0
- package/dist/server/sse.d.ts +13 -0
- package/dist/server/sse.js +22 -0
- package/dist/types.d.ts +32 -1
- package/dist/types.js +4 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/package.json +31 -7
- package/dist/modules/composition.test.d.ts +0 -11
- package/dist/modules/composition.test.js +0 -450
- package/dist/modules/policy.test.d.ts +0 -10
- package/dist/modules/policy.test.js +0 -369
- package/src/cli.ts +0 -471
- package/src/commands/add.ts +0 -315
- package/src/commands/compose.ts +0 -185
- package/src/commands/index.ts +0 -13
- 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 -90
- package/src/mcp/index.ts +0 -5
- package/src/mcp/server.ts +0 -403
- package/src/modules/composition.test.ts +0 -558
- package/src/modules/composition.ts +0 -1674
- package/src/modules/index.ts +0 -9
- package/src/modules/loader.ts +0 -508
- package/src/modules/policy.test.ts +0 -455
- package/src/modules/runner.ts +0 -1983
- package/src/modules/subagent.ts +0 -277
- package/src/modules/validator.ts +0 -700
- 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 -599
- package/tsconfig.json +0 -17
package/dist/commands/index.d.ts
CHANGED
package/dist/commands/index.js
CHANGED
package/dist/commands/init.js
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as fs from 'node:fs/promises';
|
|
5
5
|
import * as path from 'node:path';
|
|
6
|
+
function assertSafeModuleName(name) {
|
|
7
|
+
const trimmed = name.trim();
|
|
8
|
+
if (!trimmed) {
|
|
9
|
+
throw new Error('Invalid module name: empty');
|
|
10
|
+
}
|
|
11
|
+
if (trimmed.includes('..') || trimmed.includes('/') || trimmed.includes('\\')) {
|
|
12
|
+
throw new Error(`Invalid module name: ${name}`);
|
|
13
|
+
}
|
|
14
|
+
if (path.isAbsolute(trimmed)) {
|
|
15
|
+
throw new Error(`Invalid module name (absolute path not allowed): ${name}`);
|
|
16
|
+
}
|
|
17
|
+
return trimmed;
|
|
18
|
+
}
|
|
19
|
+
function resolveModuleDir(rootDir, moduleName) {
|
|
20
|
+
const safeName = assertSafeModuleName(moduleName);
|
|
21
|
+
const targetPath = path.resolve(rootDir, safeName);
|
|
22
|
+
const root = path.resolve(rootDir) + path.sep;
|
|
23
|
+
if (!targetPath.startsWith(root)) {
|
|
24
|
+
throw new Error(`Invalid module name (path traversal): ${moduleName}`);
|
|
25
|
+
}
|
|
26
|
+
return targetPath;
|
|
27
|
+
}
|
|
6
28
|
const EXAMPLE_MODULE_MD = `---
|
|
7
29
|
name: my-module
|
|
8
30
|
version: 1.0.0
|
|
@@ -46,7 +68,7 @@ export async function init(ctx, moduleName) {
|
|
|
46
68
|
await fs.mkdir(cognitiveDir, { recursive: true });
|
|
47
69
|
// If module name provided, create a new module
|
|
48
70
|
if (moduleName) {
|
|
49
|
-
const moduleDir =
|
|
71
|
+
const moduleDir = resolveModuleDir(cognitiveDir, moduleName);
|
|
50
72
|
await fs.mkdir(moduleDir, { recursive: true });
|
|
51
73
|
await fs.writeFile(path.join(moduleDir, 'MODULE.md'), EXAMPLE_MODULE_MD.replace('my-module', moduleName));
|
|
52
74
|
await fs.writeFile(path.join(moduleDir, 'schema.json'), EXAMPLE_SCHEMA_JSON);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cog migrate - Migrate modules to v2.2 format
|
|
3
|
+
*
|
|
4
|
+
* Aligns with Python CLI's `cog migrate` command.
|
|
5
|
+
* Performs migration from v0/v1/v2.1 to v2.2 format.
|
|
6
|
+
*/
|
|
7
|
+
import type { CommandContext, CommandResult } from '../types.js';
|
|
8
|
+
export interface MigrateOptions {
|
|
9
|
+
/** Dry run - only show what would be done */
|
|
10
|
+
dryRun?: boolean;
|
|
11
|
+
/** Create backup before migration */
|
|
12
|
+
backup?: boolean;
|
|
13
|
+
/** Migrate all modules */
|
|
14
|
+
all?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface MigrateResult {
|
|
17
|
+
moduleName: string;
|
|
18
|
+
modulePath: string;
|
|
19
|
+
success: boolean;
|
|
20
|
+
changes: string[];
|
|
21
|
+
warnings: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Migrate a single module to v2.2 format.
|
|
25
|
+
*/
|
|
26
|
+
export declare function migrate(nameOrPath: string, ctx: CommandContext, options?: MigrateOptions): Promise<CommandResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Migrate all modules to v2.2 format.
|
|
29
|
+
*/
|
|
30
|
+
export declare function migrateAll(ctx: CommandContext, options?: MigrateOptions): Promise<CommandResult>;
|