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.
- package/README.md +165 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.js +335 -0
- package/dist/commands/add.d.ts +34 -0
- package/dist/commands/add.js +229 -0
- package/dist/commands/index.d.ts +11 -0
- package/dist/commands/index.js +11 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.js +78 -0
- package/dist/commands/list.d.ts +5 -0
- package/dist/commands/list.js +28 -0
- package/dist/commands/pipe.d.ts +9 -0
- package/dist/commands/pipe.js +59 -0
- package/dist/commands/remove.d.ts +10 -0
- package/dist/commands/remove.js +47 -0
- package/dist/commands/run.d.ts +12 -0
- package/dist/commands/run.js +65 -0
- package/dist/commands/update.d.ts +14 -0
- package/dist/commands/update.js +105 -0
- package/dist/commands/versions.d.ts +13 -0
- package/dist/commands/versions.js +60 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +11 -0
- package/dist/modules/index.d.ts +5 -0
- package/dist/modules/index.js +5 -0
- package/dist/modules/loader.d.ts +12 -0
- package/dist/modules/loader.js +197 -0
- package/dist/modules/runner.d.ts +12 -0
- package/dist/modules/runner.js +229 -0
- package/dist/providers/anthropic.d.ts +14 -0
- package/dist/providers/anthropic.js +70 -0
- package/dist/providers/base.d.ts +11 -0
- package/dist/providers/base.js +19 -0
- package/dist/providers/deepseek.d.ts +14 -0
- package/dist/providers/deepseek.js +66 -0
- package/dist/providers/gemini.d.ts +19 -0
- package/dist/providers/gemini.js +94 -0
- package/dist/providers/index.d.ts +19 -0
- package/dist/providers/index.js +74 -0
- package/dist/providers/minimax.d.ts +14 -0
- package/dist/providers/minimax.js +64 -0
- package/dist/providers/moonshot.d.ts +14 -0
- package/dist/providers/moonshot.js +65 -0
- package/dist/providers/ollama.d.ts +13 -0
- package/dist/providers/ollama.js +64 -0
- package/dist/providers/openai.d.ts +14 -0
- package/dist/providers/openai.js +67 -0
- package/dist/providers/qwen.d.ts +14 -0
- package/dist/providers/qwen.js +65 -0
- package/dist/types.d.ts +136 -0
- package/dist/types.js +5 -0
- package/package.json +48 -0
- package/src/cli.ts +375 -0
- package/src/commands/add.ts +315 -0
- package/src/commands/index.ts +12 -0
- package/src/commands/init.ts +94 -0
- package/src/commands/list.ts +33 -0
- package/src/commands/pipe.ts +76 -0
- package/src/commands/remove.ts +57 -0
- package/src/commands/run.ts +80 -0
- package/src/commands/update.ts +130 -0
- package/src/commands/versions.ts +79 -0
- package/src/index.ts +44 -0
- package/src/modules/index.ts +6 -0
- package/src/modules/loader.ts +219 -0
- package/src/modules/runner.ts +278 -0
- package/src/providers/anthropic.ts +89 -0
- package/src/providers/base.ts +29 -0
- package/src/providers/deepseek.ts +83 -0
- package/src/providers/gemini.ts +117 -0
- package/src/providers/index.ts +78 -0
- package/src/providers/minimax.ts +81 -0
- package/src/providers/moonshot.ts +82 -0
- package/src/providers/ollama.ts +83 -0
- package/src/providers/openai.ts +84 -0
- package/src/providers/qwen.ts +82 -0
- package/src/types.ts +184 -0
- package/tsconfig.json +17 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cognitive Runtime - Core Types
|
|
3
|
+
* Version 2.1 - With envelope format, tools policy, failure contract
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Provider interface - all LLM providers implement this
|
|
7
|
+
export interface Provider {
|
|
8
|
+
name: string;
|
|
9
|
+
invoke(params: InvokeParams): Promise<InvokeResult>;
|
|
10
|
+
isConfigured(): boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface InvokeParams {
|
|
14
|
+
messages: Message[];
|
|
15
|
+
jsonSchema?: object;
|
|
16
|
+
temperature?: number;
|
|
17
|
+
maxTokens?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Message {
|
|
21
|
+
role: 'system' | 'user' | 'assistant';
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface InvokeResult {
|
|
26
|
+
content: string;
|
|
27
|
+
usage?: {
|
|
28
|
+
promptTokens: number;
|
|
29
|
+
completionTokens: number;
|
|
30
|
+
totalTokens: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Module types (v2.1)
|
|
35
|
+
export interface CognitiveModule {
|
|
36
|
+
// Core identity
|
|
37
|
+
name: string;
|
|
38
|
+
version: string;
|
|
39
|
+
responsibility: string;
|
|
40
|
+
|
|
41
|
+
// Constraints
|
|
42
|
+
excludes: string[];
|
|
43
|
+
constraints?: ModuleConstraints;
|
|
44
|
+
|
|
45
|
+
// Unified policies (v2.1)
|
|
46
|
+
policies?: ModulePolicies;
|
|
47
|
+
|
|
48
|
+
// Tools policy
|
|
49
|
+
tools?: ToolsPolicy;
|
|
50
|
+
|
|
51
|
+
// Output contract
|
|
52
|
+
output?: OutputContract;
|
|
53
|
+
|
|
54
|
+
// Failure contract
|
|
55
|
+
failure?: FailureContract;
|
|
56
|
+
|
|
57
|
+
// Runtime requirements
|
|
58
|
+
runtimeRequirements?: RuntimeRequirements;
|
|
59
|
+
|
|
60
|
+
// Execution context
|
|
61
|
+
context?: 'fork' | 'main';
|
|
62
|
+
|
|
63
|
+
// Prompt (from prompt.md or MODULE.md body)
|
|
64
|
+
prompt: string;
|
|
65
|
+
|
|
66
|
+
// Schemas
|
|
67
|
+
inputSchema?: object;
|
|
68
|
+
outputSchema?: object;
|
|
69
|
+
errorSchema?: object;
|
|
70
|
+
|
|
71
|
+
// Metadata
|
|
72
|
+
location: string;
|
|
73
|
+
format: 'v1' | 'v2'; // v1 = MODULE.md, v2 = module.yaml + prompt.md
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface ModuleConstraints {
|
|
77
|
+
no_network?: boolean;
|
|
78
|
+
no_side_effects?: boolean;
|
|
79
|
+
no_file_write?: boolean;
|
|
80
|
+
no_inventing_data?: boolean;
|
|
81
|
+
behavior_equivalence_false_max_confidence?: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface ModulePolicies {
|
|
85
|
+
network?: 'allow' | 'deny';
|
|
86
|
+
filesystem_write?: 'allow' | 'deny';
|
|
87
|
+
side_effects?: 'allow' | 'deny';
|
|
88
|
+
code_execution?: 'allow' | 'deny';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ToolsPolicy {
|
|
92
|
+
policy?: 'allow_by_default' | 'deny_by_default';
|
|
93
|
+
allowed: string[];
|
|
94
|
+
denied?: string[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface OutputContract {
|
|
98
|
+
format?: 'json_strict' | 'json_lenient' | 'text';
|
|
99
|
+
envelope?: boolean; // v2.1: Use {ok, data/error} wrapper
|
|
100
|
+
require?: string[];
|
|
101
|
+
require_confidence?: boolean;
|
|
102
|
+
require_rationale?: boolean;
|
|
103
|
+
require_behavior_equivalence?: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface FailureContract {
|
|
107
|
+
contract?: 'error_union' | 'throw';
|
|
108
|
+
partial_allowed?: boolean;
|
|
109
|
+
must_return_error_schema?: boolean;
|
|
110
|
+
schema?: object;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface RuntimeRequirements {
|
|
114
|
+
structured_output?: boolean;
|
|
115
|
+
max_input_tokens?: number;
|
|
116
|
+
preferred_capabilities?: string[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Envelope response format (v2.1)
|
|
120
|
+
export interface EnvelopeSuccess<T = unknown> {
|
|
121
|
+
ok: true;
|
|
122
|
+
data: T;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface EnvelopeError {
|
|
126
|
+
ok: false;
|
|
127
|
+
error: {
|
|
128
|
+
code: string;
|
|
129
|
+
message: string;
|
|
130
|
+
};
|
|
131
|
+
partial_data?: unknown;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type EnvelopeResponse<T = unknown> = EnvelopeSuccess<T> | EnvelopeError;
|
|
135
|
+
|
|
136
|
+
// Module result types
|
|
137
|
+
export interface ModuleResultData {
|
|
138
|
+
[key: string]: unknown;
|
|
139
|
+
confidence: number;
|
|
140
|
+
rationale: string;
|
|
141
|
+
behavior_equivalence?: boolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface ModuleResult {
|
|
145
|
+
ok: boolean;
|
|
146
|
+
data?: ModuleResultData;
|
|
147
|
+
error?: {
|
|
148
|
+
code: string;
|
|
149
|
+
message: string;
|
|
150
|
+
};
|
|
151
|
+
partial_data?: unknown;
|
|
152
|
+
raw?: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Legacy result format (for backward compatibility)
|
|
156
|
+
export interface LegacyModuleResult {
|
|
157
|
+
output: unknown;
|
|
158
|
+
confidence: number;
|
|
159
|
+
rationale: string;
|
|
160
|
+
behaviorEquivalence?: boolean;
|
|
161
|
+
raw?: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Command types
|
|
165
|
+
export interface CommandContext {
|
|
166
|
+
cwd: string;
|
|
167
|
+
provider: Provider;
|
|
168
|
+
verbose?: boolean;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface CommandResult {
|
|
172
|
+
success: boolean;
|
|
173
|
+
data?: unknown;
|
|
174
|
+
error?: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Module input (clean, no CLI pollution)
|
|
178
|
+
export interface ModuleInput {
|
|
179
|
+
code?: string;
|
|
180
|
+
query?: string;
|
|
181
|
+
language?: string;
|
|
182
|
+
options?: Record<string, unknown>;
|
|
183
|
+
[key: string]: unknown;
|
|
184
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"lib": ["ES2023"],
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"resolveJsonModule": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*"],
|
|
16
|
+
"exclude": ["node_modules", "dist"]
|
|
17
|
+
}
|