@claude-flow/plugin-cognitive-kernel 3.0.0-alpha.1

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 ADDED
@@ -0,0 +1,315 @@
1
+ # @claude-flow/plugin-cognitive-kernel
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@claude-flow/plugin-cognitive-kernel.svg)](https://www.npmjs.com/package/@claude-flow/plugin-cognitive-kernel)
4
+ [![license](https://img.shields.io/npm/l/@claude-flow/plugin-cognitive-kernel.svg)](https://github.com/ruvnet/claude-flow/blob/main/LICENSE)
5
+ [![downloads](https://img.shields.io/npm/dm/@claude-flow/plugin-cognitive-kernel.svg)](https://www.npmjs.com/package/@claude-flow/plugin-cognitive-kernel)
6
+
7
+ A cutting-edge cognitive augmentation plugin combining the Cognitum Gate Kernel with SONA self-optimizing architecture to provide LLMs with enhanced cognitive capabilities. The plugin enables dynamic working memory, attention control mechanisms, meta-cognitive self-monitoring, and cognitive scaffolding while maintaining low latency through WASM acceleration.
8
+
9
+ ## Installation
10
+
11
+ ### npm
12
+
13
+ ```bash
14
+ npm install @claude-flow/plugin-cognitive-kernel
15
+ ```
16
+
17
+ ### CLI
18
+
19
+ ```bash
20
+ npx claude-flow plugins install --name @claude-flow/plugin-cognitive-kernel
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import { CognitiveKernelPlugin } from '@claude-flow/plugin-cognitive-kernel';
27
+
28
+ // Initialize the plugin
29
+ const plugin = new CognitiveKernelPlugin();
30
+ await plugin.initialize();
31
+
32
+ // Allocate working memory for a complex reasoning task
33
+ const memorySlot = await plugin.workingMemory({
34
+ action: 'allocate',
35
+ slot: {
36
+ id: 'current-problem',
37
+ content: { problem: 'Design authentication system', context: {...} },
38
+ priority: 0.9,
39
+ decay: 0.05
40
+ },
41
+ capacity: 7 // Miller's number
42
+ });
43
+
44
+ // Control attention for focused analysis
45
+ await plugin.attentionControl({
46
+ mode: 'focus',
47
+ targets: [
48
+ { entity: 'security-requirements', weight: 0.8, duration: 300 },
49
+ { entity: 'user-experience', weight: 0.6, duration: 300 }
50
+ ],
51
+ filters: {
52
+ includePatterns: ['auth*', 'security*', 'token*'],
53
+ noveltyBias: 0.3
54
+ }
55
+ });
56
+
57
+ console.log('Cognitive context established');
58
+ ```
59
+
60
+ ## Available MCP Tools
61
+
62
+ ### 1. `cognition/working-memory`
63
+
64
+ Manage dynamic working memory slots for complex reasoning tasks.
65
+
66
+ ```typescript
67
+ const result = await mcp.call('cognition/working-memory', {
68
+ action: 'allocate',
69
+ slot: {
70
+ id: 'task-context',
71
+ content: {
72
+ goal: 'Refactor authentication module',
73
+ constraints: ['maintain backward compatibility', 'improve security'],
74
+ progress: []
75
+ },
76
+ priority: 0.8,
77
+ decay: 0.1
78
+ },
79
+ capacity: 7,
80
+ consolidationTarget: 'episodic'
81
+ });
82
+ ```
83
+
84
+ **Actions:** `allocate`, `update`, `retrieve`, `clear`, `consolidate`
85
+
86
+ **Returns:** Memory slot state with current contents and decay status.
87
+
88
+ ### 2. `cognition/attention-control`
89
+
90
+ Control cognitive attention and information filtering.
91
+
92
+ ```typescript
93
+ const result = await mcp.call('cognition/attention-control', {
94
+ mode: 'selective',
95
+ targets: [
96
+ { entity: 'error-handling', weight: 0.9, duration: 600 },
97
+ { entity: 'input-validation', weight: 0.7, duration: 600 }
98
+ ],
99
+ filters: {
100
+ includePatterns: ['error*', 'exception*', 'validation*'],
101
+ excludePatterns: ['deprecated*', 'legacy*'],
102
+ noveltyBias: 0.5
103
+ }
104
+ });
105
+ ```
106
+
107
+ **Modes:** `focus`, `diffuse`, `selective`, `divided`, `sustained`
108
+
109
+ **Returns:** Attention state with active targets and filter configuration.
110
+
111
+ ### 3. `cognition/meta-monitor`
112
+
113
+ Meta-cognitive monitoring of reasoning quality and self-reflection.
114
+
115
+ ```typescript
116
+ const result = await mcp.call('cognition/meta-monitor', {
117
+ monitoring: [
118
+ 'confidence_calibration',
119
+ 'reasoning_coherence',
120
+ 'goal_tracking',
121
+ 'error_detection'
122
+ ],
123
+ reflection: {
124
+ trigger: 'on_uncertainty',
125
+ depth: 'medium'
126
+ },
127
+ interventions: true
128
+ });
129
+ ```
130
+
131
+ **Returns:** Meta-cognitive assessment with confidence scores, detected issues, and suggested interventions.
132
+
133
+ ### 4. `cognition/scaffold`
134
+
135
+ Provide cognitive scaffolding for complex reasoning tasks.
136
+
137
+ ```typescript
138
+ const result = await mcp.call('cognition/scaffold', {
139
+ task: {
140
+ description: 'Design a distributed caching system',
141
+ complexity: 'complex',
142
+ domain: 'distributed-systems'
143
+ },
144
+ scaffoldType: 'decomposition',
145
+ adaptivity: {
146
+ fading: true,
147
+ monitoring: true
148
+ }
149
+ });
150
+ ```
151
+
152
+ **Scaffold Types:** `decomposition`, `analogy`, `worked_example`, `socratic`, `metacognitive_prompting`, `chain_of_thought`
153
+
154
+ **Returns:** Structured scaffolding with step-by-step guidance adapted to task complexity.
155
+
156
+ ### 5. `cognition/cognitive-load`
157
+
158
+ Monitor and balance cognitive load during reasoning.
159
+
160
+ ```typescript
161
+ const result = await mcp.call('cognition/cognitive-load', {
162
+ assessment: {
163
+ intrinsic: 0.7, // Task complexity
164
+ extraneous: 0.3, // Presentation complexity
165
+ germane: 0.5 // Learning investment
166
+ },
167
+ optimization: 'reduce_extraneous',
168
+ threshold: 0.8
169
+ });
170
+ ```
171
+
172
+ **Optimizations:** `reduce_extraneous`, `chunk_intrinsic`, `maximize_germane`, `balanced`
173
+
174
+ **Returns:** Load assessment with optimization recommendations and intervention triggers.
175
+
176
+ ## Configuration Options
177
+
178
+ ```typescript
179
+ interface CognitiveKernelConfig {
180
+ // Maximum working memory slots (default: 7, Miller's number)
181
+ maxWorkingMemorySlots: number;
182
+
183
+ // Memory limit in MB (default: 256)
184
+ memoryLimit: number;
185
+
186
+ // CPU time limit per operation in seconds (default: 10)
187
+ cpuTimeLimit: number;
188
+
189
+ // Enable session isolation (default: true)
190
+ sessionIsolation: boolean;
191
+
192
+ // Scaffold fading configuration
193
+ scaffolding: {
194
+ enableFading: boolean;
195
+ fadingRate: number;
196
+ };
197
+
198
+ // Meta-cognitive intervention thresholds
199
+ metaCognition: {
200
+ confidenceThreshold: number;
201
+ coherenceThreshold: number;
202
+ autoIntervene: boolean;
203
+ };
204
+ }
205
+ ```
206
+
207
+ ## Performance Targets
208
+
209
+ | Metric | Target | Notes |
210
+ |--------|--------|-------|
211
+ | Working memory operations | <1ms per slot | 10x faster than naive cache |
212
+ | Attention steering | <5ms for reallocation | 10x faster than context rebuild |
213
+ | Meta-cognitive check | <10ms per assessment | Novel capability |
214
+ | Memory consolidation | <100ms batch | 10x faster than full reindex |
215
+ | Scaffold generation | <50ms per step | Novel capability |
216
+
217
+ ## Cognitive Theories Implemented
218
+
219
+ | Theory | Implementation |
220
+ |--------|----------------|
221
+ | Baddeley's Working Memory | Multi-component memory system with phonological loop, visuospatial sketchpad, and episodic buffer |
222
+ | Cognitive Load Theory | Intrinsic/extraneous/germane load management |
223
+ | Metacognition | Self-monitoring, error detection, and regulation |
224
+ | Zone of Proximal Development | Adaptive scaffolding with gradual fading |
225
+ | Dual Process Theory | Fast/slow thinking modes |
226
+
227
+ ## Security Considerations
228
+
229
+ - **Session Isolation**: Each cognitive session has isolated working memory with session-specific encryption keys (AES-256-GCM)
230
+ - **Secure Clearing**: Working memory is securely cleared and overwritten (zero-fill) at session end
231
+ - **Prompt Injection Prevention**: Scaffold content is sanitized to remove potential prompt injection patterns (special tokens, control sequences)
232
+ - **Input Validation**: All inputs validated with Zod schemas with strict limits
233
+ - **Rate Limiting**: Prevents abuse of cognitive resources
234
+ - **Content Filtering**: Memory content scanned for sensitive data patterns before storage
235
+
236
+ ### WASM Security Constraints
237
+
238
+ | Constraint | Value | Rationale |
239
+ |------------|-------|-----------|
240
+ | Memory Limit | 256MB | Sufficient for cognitive operations |
241
+ | CPU Time per Operation | 10 seconds | Prevent runaway processing |
242
+ | No Network Access | Enforced | Prevent data exfiltration |
243
+ | Session Isolation | Enforced | Per-session WASM instances |
244
+ | Secure Memory Clear | Zero-fill on exit | Prevent memory forensics |
245
+
246
+ ### Input Limits
247
+
248
+ | Constraint | Limit |
249
+ |------------|-------|
250
+ | Working memory slots | 20 max |
251
+ | Memory limit | 256MB |
252
+ | CPU time per operation | 10 seconds |
253
+ | Attention targets | 50 max |
254
+ | Scaffold description | 5,000 characters |
255
+
256
+ ### Rate Limits
257
+
258
+ | Tool | Requests/Minute | Max Concurrent |
259
+ |------|-----------------|----------------|
260
+ | `working-memory` | 120 | 10 |
261
+ | `attention-control` | 60 | 5 |
262
+ | `meta-monitor` | 60 | 5 |
263
+ | `scaffold` | 30 | 3 |
264
+ | `cognitive-load` | 60 | 5 |
265
+
266
+ ## Dependencies
267
+
268
+ - `cognitum-gate-kernel` - Core cognitive kernel for memory gating and attention control
269
+ - `sona` - Self-Optimizing Neural Architecture for adaptive cognition
270
+ - `ruvector-attention-wasm` - Multi-head attention for cognitive focus
271
+ - `ruvector-nervous-system-wasm` - Coordination between cognitive subsystems
272
+ - `micro-hnsw-wasm` - Fast retrieval for episodic memory
273
+
274
+ ## Use Cases
275
+
276
+ 1. **Complex Reasoning**: Support multi-step reasoning with working memory persistence
277
+ 2. **Research Synthesis**: Maintain focus across long document analysis sessions
278
+ 3. **Learning Enhancement**: Adaptive scaffolding for skill acquisition
279
+ 4. **Error Prevention**: Meta-cognitive monitoring catches reasoning errors before output
280
+ 5. **Context Management**: Intelligent attention control for managing long contexts
281
+
282
+ ## Related Plugins
283
+
284
+ | Plugin | Description | Synergy |
285
+ |--------|-------------|---------|
286
+ | [@claude-flow/plugin-neural-coordination](https://www.npmjs.com/package/@claude-flow/plugin-neural-coordination) | Multi-agent coordination | Cognitive kernel provides enhanced reasoning for coordinated agents |
287
+ | [@claude-flow/plugin-hyperbolic-reasoning](https://www.npmjs.com/package/@claude-flow/plugin-hyperbolic-reasoning) | Hierarchical reasoning | Combines hierarchical structure with cognitive scaffolding |
288
+ | [@claude-flow/plugin-quantum-optimizer](https://www.npmjs.com/package/@claude-flow/plugin-quantum-optimizer) | Quantum-inspired optimization | Optimizes cognitive resource allocation and attention scheduling |
289
+
290
+ ## Architecture
291
+
292
+ ```
293
+ +------------------+ +----------------------+ +------------------+
294
+ | LLM Input |---->| Cognitive Kernel |---->| Enhanced Output |
295
+ | (Prompts) | | (WASM Accelerated) | | (Augmented) |
296
+ +------------------+ +----------------------+ +------------------+
297
+ |
298
+ +--------------------+--------------------+
299
+ | | |
300
+ +------+------+ +-------+-------+ +------+------+
301
+ | Cognitum | | SONA | | Attention |
302
+ | Gate Kernel | | Self-Optimize | | Control |
303
+ +-------------+ +---------------+ +-------------+
304
+ | | |
305
+ +--------------------+--------------------+
306
+ |
307
+ +-------+-------+
308
+ | Working Memory |
309
+ | (HNSW Index) |
310
+ +---------------+
311
+ ```
312
+
313
+ ## License
314
+
315
+ MIT
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Cognitive Bridge
3
+ *
4
+ * Bridge to cognitum-gate-kernel for cognitive computation including
5
+ * working memory, attention control, meta-cognition, and scaffolding.
6
+ */
7
+ import type { CognitiveItem, MetaCognitiveAssessment } from '../types.js';
8
+ /**
9
+ * WASM module status
10
+ */
11
+ export type WasmModuleStatus = 'unloaded' | 'loading' | 'ready' | 'error';
12
+ /**
13
+ * Cognitive configuration
14
+ */
15
+ export interface CognitiveConfig {
16
+ /** Working memory capacity (Miller's 7 +/- 2) */
17
+ workingMemorySize: number;
18
+ /** Attention span in seconds */
19
+ attentionSpan: number;
20
+ /** Enable meta-cognitive monitoring */
21
+ metaCognitionEnabled: boolean;
22
+ /** Scaffolding level */
23
+ scaffoldingLevel: 'none' | 'light' | 'moderate' | 'heavy';
24
+ /** Decay rate for memory items */
25
+ decayRate: number;
26
+ }
27
+ /**
28
+ * Attention state
29
+ */
30
+ export interface AttentionState {
31
+ focus: string[];
32
+ breadth: number;
33
+ intensity: number;
34
+ distractors: string[];
35
+ }
36
+ /**
37
+ * WASM cognitive module interface
38
+ */
39
+ interface CognitiveModule {
40
+ store(item: CognitiveItem): boolean;
41
+ retrieve(id: string): CognitiveItem | null;
42
+ search(query: Float32Array, k: number): CognitiveItem[];
43
+ decay(deltaTime: number): void;
44
+ consolidate(): void;
45
+ focus(ids: string[]): AttentionState;
46
+ broaden(): AttentionState;
47
+ narrow(): AttentionState;
48
+ getAttentionState(): AttentionState;
49
+ assess(): MetaCognitiveAssessment;
50
+ monitor(task: string): number;
51
+ regulate(strategy: string): void;
52
+ scaffold(task: string, difficulty: number): string[];
53
+ adapt(performance: number): void;
54
+ }
55
+ /**
56
+ * Cognitive Bridge implementation
57
+ */
58
+ export declare class CognitiveBridge {
59
+ readonly name = "cognitum-gate-kernel";
60
+ readonly version = "0.1.0";
61
+ private _status;
62
+ private _module;
63
+ private config;
64
+ constructor(config?: Partial<CognitiveConfig>);
65
+ get status(): WasmModuleStatus;
66
+ get initialized(): boolean;
67
+ init(): Promise<void>;
68
+ destroy(): Promise<void>;
69
+ isReady(): boolean;
70
+ getModule(): CognitiveModule | null;
71
+ /**
72
+ * Store item in working memory
73
+ */
74
+ store(item: CognitiveItem): boolean;
75
+ /**
76
+ * Retrieve item from working memory
77
+ */
78
+ retrieve(id: string): CognitiveItem | null;
79
+ /**
80
+ * Search working memory
81
+ */
82
+ search(query: Float32Array, k: number): CognitiveItem[];
83
+ /**
84
+ * Apply memory decay
85
+ */
86
+ decay(deltaTime: number): void;
87
+ /**
88
+ * Consolidate working memory to long-term
89
+ */
90
+ consolidate(): void;
91
+ /**
92
+ * Focus attention on specific items
93
+ */
94
+ focus(ids: string[]): AttentionState;
95
+ /**
96
+ * Broaden attention
97
+ */
98
+ broaden(): AttentionState;
99
+ /**
100
+ * Narrow attention
101
+ */
102
+ narrow(): AttentionState;
103
+ /**
104
+ * Get current attention state
105
+ */
106
+ getAttentionState(): AttentionState;
107
+ /**
108
+ * Perform meta-cognitive assessment
109
+ */
110
+ assess(): MetaCognitiveAssessment;
111
+ /**
112
+ * Monitor task performance
113
+ */
114
+ monitor(task: string): number;
115
+ /**
116
+ * Apply cognitive regulation strategy
117
+ */
118
+ regulate(strategy: string): void;
119
+ /**
120
+ * Get scaffolding for task
121
+ */
122
+ scaffold(task: string, difficulty: number): string[];
123
+ /**
124
+ * Adapt scaffolding based on performance
125
+ */
126
+ adapt(performance: number): void;
127
+ /**
128
+ * Create mock module for development
129
+ */
130
+ private createMockModule;
131
+ }
132
+ /**
133
+ * Create a new cognitive bridge
134
+ */
135
+ export declare function createCognitiveBridge(config?: Partial<CognitiveConfig>): CognitiveBridge;
136
+ export default CognitiveBridge;
137
+ //# sourceMappingURL=cognitive-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cognitive-bridge.d.ts","sourceRoot":"","sources":["../../src/bridges/cognitive-bridge.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gCAAgC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,wBAAwB;IACxB,gBAAgB,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;IAC1D,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;CACnB;AAaD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,UAAU,eAAe;IAEvB,KAAK,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