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
@@ -10,3 +10,7 @@ export * from './update.js';
10
10
  export * from './remove.js';
11
11
  export * from './versions.js';
12
12
  export * from './compose.js';
13
+ export * from './validate.js';
14
+ export * from './migrate.js';
15
+ export * from './test.js';
16
+ export * from './search.js';
@@ -10,3 +10,7 @@ export * from './update.js';
10
10
  export * from './remove.js';
11
11
  export * from './versions.js';
12
12
  export * from './compose.js';
13
+ export * from './validate.js';
14
+ export * from './migrate.js';
15
+ export * from './test.js';
16
+ export * from './search.js';
@@ -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 = path.join(cognitiveDir, moduleName);
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>;