@dcyfr/ai 3.0.1 → 3.0.2

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 (64) hide show
  1. package/LICENSE +11 -30
  2. package/README.md +211 -138
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/ai/core/provider-registry.d.ts +8 -0
  5. package/dist/ai/core/provider-registry.d.ts.map +1 -1
  6. package/dist/ai/core/provider-registry.js +17 -2
  7. package/dist/ai/core/provider-registry.js.map +1 -1
  8. package/dist/ai/metacognition/config.d.ts +41 -0
  9. package/dist/ai/metacognition/config.d.ts.map +1 -0
  10. package/dist/ai/metacognition/config.js +51 -0
  11. package/dist/ai/metacognition/config.js.map +1 -0
  12. package/dist/ai/metacognition/governance.d.ts +68 -0
  13. package/dist/ai/metacognition/governance.d.ts.map +1 -0
  14. package/dist/ai/metacognition/governance.js +118 -0
  15. package/dist/ai/metacognition/governance.js.map +1 -0
  16. package/dist/ai/metacognition/index.d.ts +24 -0
  17. package/dist/ai/metacognition/index.d.ts.map +1 -0
  18. package/dist/ai/metacognition/index.js +18 -0
  19. package/dist/ai/metacognition/index.js.map +1 -0
  20. package/dist/ai/metacognition/ledger.d.ts +121 -0
  21. package/dist/ai/metacognition/ledger.d.ts.map +1 -0
  22. package/dist/ai/metacognition/ledger.js +268 -0
  23. package/dist/ai/metacognition/ledger.js.map +1 -0
  24. package/dist/ai/metacognition/runtime.d.ts +205 -0
  25. package/dist/ai/metacognition/runtime.d.ts.map +1 -0
  26. package/dist/ai/metacognition/runtime.js +391 -0
  27. package/dist/ai/metacognition/runtime.js.map +1 -0
  28. package/dist/ai/metacognition/telemetry.d.ts +144 -0
  29. package/dist/ai/metacognition/telemetry.d.ts.map +1 -0
  30. package/dist/ai/metacognition/telemetry.js +149 -0
  31. package/dist/ai/metacognition/telemetry.js.map +1 -0
  32. package/dist/ai/metacognition/transfer.d.ts +153 -0
  33. package/dist/ai/metacognition/transfer.d.ts.map +1 -0
  34. package/dist/ai/metacognition/transfer.js +182 -0
  35. package/dist/ai/metacognition/transfer.js.map +1 -0
  36. package/dist/ai/metacognition/types.d.ts +302 -0
  37. package/dist/ai/metacognition/types.d.ts.map +1 -0
  38. package/dist/ai/metacognition/types.js +79 -0
  39. package/dist/ai/metacognition/types.js.map +1 -0
  40. package/dist/ai/runtime/agent-runtime.d.ts.map +1 -1
  41. package/dist/ai/runtime/agent-runtime.js.map +1 -1
  42. package/dist/ai/src/integrations/linear/index.d.ts +19 -0
  43. package/dist/ai/src/integrations/linear/index.d.ts.map +1 -0
  44. package/dist/ai/src/integrations/linear/index.js +20 -0
  45. package/dist/ai/src/integrations/linear/index.js.map +1 -0
  46. package/dist/ai/src/integrations/linear/issue-mapper.d.ts +93 -0
  47. package/dist/ai/src/integrations/linear/issue-mapper.d.ts.map +1 -0
  48. package/dist/ai/src/integrations/linear/issue-mapper.js +186 -0
  49. package/dist/ai/src/integrations/linear/issue-mapper.js.map +1 -0
  50. package/dist/ai/src/integrations/linear/linear-client.d.ts +199 -0
  51. package/dist/ai/src/integrations/linear/linear-client.d.ts.map +1 -0
  52. package/dist/ai/src/integrations/linear/linear-client.js +300 -0
  53. package/dist/ai/src/integrations/linear/linear-client.js.map +1 -0
  54. package/dist/ai/src/runtime/agent-runtime.js +1 -1
  55. package/dist/ai/src/runtime/agent-runtime.js.map +1 -1
  56. package/dist/ai/src/security/prompt-scan-worker.d.ts +63 -0
  57. package/dist/ai/src/security/prompt-scan-worker.d.ts.map +1 -0
  58. package/dist/ai/src/security/prompt-scan-worker.js +174 -0
  59. package/dist/ai/src/security/prompt-scan-worker.js.map +1 -0
  60. package/dist/ai/src/telemetry/delegation-telemetry.d.ts +10 -0
  61. package/dist/ai/src/telemetry/delegation-telemetry.d.ts.map +1 -1
  62. package/dist/ai/src/telemetry/delegation-telemetry.js +23 -0
  63. package/dist/ai/src/telemetry/delegation-telemetry.js.map +1 -1
  64. package/package.json +25 -15
package/README.md CHANGED
@@ -1,42 +1,59 @@
1
1
  # @dcyfr/ai
2
2
 
3
+ <!-- README-META
4
+ tlp_clearance: GREEN
5
+ status: active
6
+ name: dcyfr-ai
7
+ description: Portable AI agent harness with plugin architecture
8
+ last_validated: 2026-03-29
9
+ -->
10
+
3
11
  [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/dcyfr/dcyfr-ai)
4
12
 
5
13
  > Portable AI agent harness with plugin architecture for multi-provider integration, telemetry tracking, and quality validation.
6
14
 
7
- [![npm](https://img.shields.io/npm/v/@dcyfr/ai?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@dcyfr/ai)
8
- [![Downloads](https://img.shields.io/npm/dm/@dcyfr/ai?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@dcyfr/ai)
15
+ [![npm](https://img.shields.io/npm/v/@dcyfr/ai?logo=npm&logoColor=white)](https://www.npmjs.com/package/@dcyfr/ai)
16
+ [![Downloads](https://img.shields.io/npm/dm/@dcyfr/ai?logo=npm&logoColor=white)](https://www.npmjs.com/package/@dcyfr/ai)
9
17
  [![License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](https://opensource.org/licenses/MIT)
10
- [![TypeScript](https://img.shields.io/badge/TypeScript-Strict-3178C6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
11
- [![Bundle Size](https://img.shields.io/badge/Bundle%20Size-~200KB%20gzipped-28a745?style=flat-square&logo=webpack)](https://bundlephobia.com/package/@dcyfr/ai)
18
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Strict-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
19
+ [![Bundle Size](https://img.shields.io/bundlephobia/minzip/@dcyfr/ai?label=Bundle%20Size&logo=webpack)](https://bundlephobia.com/package/@dcyfr/ai)
12
20
 
13
21
  Portable AI agent harness with plugin architecture for managing multiple AI providers, tracking telemetry, and ensuring quality compliance.
14
22
 
23
+ ## About DCYFR
24
+
25
+ `@dcyfr/ai` is maintained by **DCYFR Labs** as part of the DCYFR AI tooling portfolio.
26
+
27
+ - **DCYFR** is a registered trademark of DCYFR Labs.
28
+ - Primary domain: [www.dcyfr.ai](https://www.dcyfr.ai)
29
+ - Trademark guidance: [../TRADEMARK.md](../TRADEMARK.md)
30
+ - Licensing details: [LICENSE](./LICENSE)
31
+
15
32
  ## 🔍 @dcyfr/ai vs. Alternatives
16
33
 
17
- | Feature | @dcyfr/ai | LangChain | Vercel AI SDK | AutoGPT |
18
- | ------------------ | ------------------- | ------------ | ------------- | ------------ |
19
- | Multi-Provider | ✅ | ✅ | ✅ | ❌ |
20
- | Plugin System | ✅ Custom | ✅ Complex | ❌ | ❌ |
21
- | Telemetry | ✅ Built-in | ❌ | ❌ | ❌ |
22
- | Zero Config | ✅ | ❌ | ✅ | ❌ |
23
- | Bundle Size | ~200KB gzipped | ~2.3MB | ~450KB | N/A |
24
- | TypeScript | ✅ Strict | Partial | ✅ | ❌ |
25
- | Quality Gates | ✅ | ❌ | ❌ | ❌ |
26
- | Config System | YAML/JSON/package | Code-only | Code-only | JSON |
27
- | Learning Curve | Low | High | Low | High |
34
+ | Feature | @dcyfr/ai | LangChain | Vercel AI SDK | AutoGPT |
35
+ | -------------- | ------------------------------ | ---------- | ------------- | ------- |
36
+ | Multi-Provider | ✅ | ✅ | ✅ | ❌ |
37
+ | Plugin System | ✅ Custom | ✅ Complex | ❌ | ❌ |
38
+ | Telemetry | ✅ Built-in | ❌ | ❌ | ❌ |
39
+ | Zero Config | ✅ | ❌ | ✅ | ❌ |
40
+ | Bundle Size | Live Bundlephobia minzip badge | ~2.3MB | ~450KB | N/A |
41
+ | TypeScript | ✅ Strict | Partial | ✅ | ❌ |
42
+ | Quality Gates | ✅ | ❌ | ❌ | ❌ |
43
+ | Config System | YAML/JSON/package | Code-only | Code-only | JSON |
44
+ | Learning Curve | Low | High | Low | High |
28
45
 
29
46
  ---
30
47
 
31
48
  ## 📊 npm Statistics
32
49
 
33
- [![npm](https://img.shields.io/npm/v/@dcyfr/ai?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@dcyfr/ai)
34
- [![Downloads](https://img.shields.io/npm/dm/@dcyfr/ai?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@dcyfr/ai)
35
- [![Bundle Size](https://img.shields.io/bundlephobia/minzip/@dcyfr/ai?style=flat-square&logo=webpack)](https://bundlephobia.com/package/@dcyfr/ai)
50
+ [![npm](https://img.shields.io/npm/v/@dcyfr/ai?logo=npm&logoColor=white)](https://www.npmjs.com/package/@dcyfr/ai)
51
+ [![Downloads](https://img.shields.io/npm/dm/@dcyfr/ai?logo=npm&logoColor=white)](https://www.npmjs.com/package/@dcyfr/ai)
52
+ [![Bundle Size](https://img.shields.io/bundlephobia/minzip/@dcyfr/ai?logo=webpack)](https://bundlephobia.com/package/@dcyfr/ai)
36
53
 
37
54
  - **Weekly Downloads:** Check [npm stats](https://www.npmjs.com/package/@dcyfr/ai)
38
- - **Dependencies:** 12 production dependencies (zero bloat)
39
- - **Bundle Size:** ~200KB gzipped with tree shaking
55
+ - **Dependencies:** 28 production dependencies
56
+ - **Bundle Size:** Live Bundlephobia minzip badge (see above)
40
57
  - **TypeScript:** Full type definitions included
41
58
  - **ESM Support:** ✅ Full ESM modules with tree shaking
42
59
 
@@ -85,7 +102,7 @@ Portable AI agent harness with plugin architecture for managing multiple AI prov
85
102
  - ✅ **Validation Harness** - Quality gates with parallel/serial execution
86
103
  - 💾 **Pluggable Storage** - Memory, file-based, or custom adapters
87
104
  - ⚡ **Type-Safe** - Full TypeScript support with Zod validation
88
- - 📦 **Lightweight** - ~200KB gzipped bundle size
105
+ - 📦 **Bundle Profile** - Live Bundlephobia minzip badge
89
106
  - 🛠️ **CLI Tools** - Config validation and initialization
90
107
 
91
108
  ## Installation
@@ -105,7 +122,7 @@ npx @dcyfr/ai config:init
105
122
  This creates a `.dcyfr.yaml` configuration file:
106
123
 
107
124
  ```yaml
108
- version: '1.0.0'
125
+ version: "1.0.0"
109
126
  projectName: my-app
110
127
 
111
128
  agents:
@@ -124,7 +141,7 @@ agents:
124
141
  ### 2. Load and Use Configuration
125
142
 
126
143
  ```typescript
127
- import { loadConfig, ValidationFramework } from '@dcyfr/ai';
144
+ import { loadConfig, ValidationFramework } from "@dcyfr/ai";
128
145
 
129
146
  // Load configuration (auto-detects .dcyfr.yaml, .dcyfr.json, package.json)
130
147
  const config = await loadConfig();
@@ -142,7 +159,7 @@ const report = await framework.validate({
142
159
  config: config.agents,
143
160
  });
144
161
 
145
- console.log(`Validation: ${report.valid ? 'PASS' : 'FAIL'}`);
162
+ console.log(`Validation: ${report.valid ? "PASS" : "FAIL"}`);
146
163
  ```
147
164
 
148
165
  ### 3. Validate Configuration
@@ -161,7 +178,7 @@ npx @dcyfr/ai config:validate --verbose
161
178
 
162
179
  ### Migrating from LangChain
163
180
 
164
- **Why migrate:** 10x smaller bundle (~200KB vs 2.3MB), built-in telemetry, simpler API
181
+ **Why migrate:** Smaller bundle footprint than LangChain (see live Bundlephobia badge), built-in telemetry, simpler API
165
182
 
166
183
  ```typescript
167
184
  // LangChain (before)
@@ -172,21 +189,24 @@ const model = new ChatOpenAI({ temperature: 0.9 });
172
189
  const response = await model.call([new HumanMessage("Hello")]);
173
190
 
174
191
  // @dcyfr/ai (after)
175
- import { AgentRuntime } from '@dcyfr/ai';
192
+ import { AgentRuntime } from "@dcyfr/ai";
176
193
 
177
194
  const runtime = new AgentRuntime({
178
- provider: 'openai',
179
- model: 'gpt-4',
180
- temperature: 0.9
195
+ provider: "openai",
196
+ model: "gpt-4",
197
+ temperature: 0.9,
181
198
  });
182
199
 
183
- const response = await runtime.chat({ messages: [{ role: 'user', content: 'Hello' }] });
200
+ const response = await runtime.chat({
201
+ messages: [{ role: "user", content: "Hello" }],
202
+ });
184
203
  ```
185
204
 
186
205
  **Key Differences:**
206
+
187
207
  - Simpler configuration (YAML/JSON vs code-only)
188
208
  - Built-in telemetry tracking (no additional setup)
189
- - Smaller bundle size (200KB vs 2.3MB)
209
+ - Smaller bundle size than LangChain (see live Bundlephobia badge)
190
210
  - Type-safe validation with Zod
191
211
  - Quality gates included out of the box
192
212
 
@@ -196,32 +216,35 @@ const response = await runtime.chat({ messages: [{ role: 'user', content: 'Hello
196
216
 
197
217
  ```typescript
198
218
  // Vercel AI SDK (before)
199
- import { openai } from '@ai-sdk/openai';
200
- import { generateText } from 'ai';
219
+ import { openai } from "@ai-sdk/openai";
220
+ import { generateText } from "ai";
201
221
 
202
222
  const { text } = await generateText({
203
- model: openai('gpt-4-turbo'),
204
- prompt: 'Hello'
223
+ model: openai("gpt-4-turbo"),
224
+ prompt: "Hello",
205
225
  });
206
226
 
207
227
  // @dcyfr/ai (after)
208
- import { AgentRuntime, ValidationFramework } from '@dcyfr/ai';
228
+ import { AgentRuntime, ValidationFramework } from "@dcyfr/ai";
209
229
 
210
230
  const runtime = new AgentRuntime({
211
- provider: 'openai',
212
- model: 'gpt-4-turbo'
231
+ provider: "openai",
232
+ model: "gpt-4-turbo",
213
233
  });
214
234
 
215
235
  const response = await runtime.chat({
216
- messages: [{ role: 'user', content: 'Hello' }]
236
+ messages: [{ role: "user", content: "Hello" }],
217
237
  });
218
238
 
219
239
  // Bonus: Built-in validation
220
240
  const validator = new ValidationFramework();
221
- const report = await validator.validate({ /* config */ });
241
+ const report = await validator.validate({
242
+ /* config */
243
+ });
222
244
  ```
223
245
 
224
246
  **Key Differences:**
247
+
225
248
  - Configuration system (YAML/JSON files)
226
249
  - Validation harness with quality gates
227
250
  - Comprehensive telemetry tracking
@@ -251,23 +274,23 @@ export ANTHROPIC_API_KEY=your_anthropic_key
251
274
  ### 1. Basic AgentRuntime Setup
252
275
 
253
276
  ```typescript
254
- import {
255
- AgentRuntime,
256
- ProviderRegistry,
257
- TelemetryEngine,
258
- DCYFRMemory
259
- } from '@dcyfr/ai';
277
+ import {
278
+ AgentRuntime,
279
+ ProviderRegistry,
280
+ TelemetryEngine,
281
+ DCYFRMemory,
282
+ } from "@dcyfr/ai";
260
283
 
261
284
  // Initialize components
262
285
  const providerRegistry = new ProviderRegistry();
263
- const telemetryEngine = new TelemetryEngine({ storage: 'sqlite' });
264
- const memory = new DCYFRMemory({ storage: 'memory' });
286
+ const telemetryEngine = new TelemetryEngine({ storage: "sqlite" });
287
+ const memory = new DCYFRMemory({ storage: "memory" });
265
288
 
266
289
  // Create runtime
267
290
  const runtime = new AgentRuntime({
268
291
  providerRegistry,
269
292
  memory,
270
- telemetry: telemetryEngine
293
+ telemetry: telemetryEngine,
271
294
  });
272
295
 
273
296
  // Verify setup
@@ -278,13 +301,13 @@ console.log(`Runtime ready: ${runtime.isReady()}`);
278
301
 
279
302
  ```typescript
280
303
  // Simple task execution
281
- const result = await runtime.executeTask('Explain quantum computing briefly');
304
+ const result = await runtime.executeTask("Explain quantum computing briefly");
282
305
 
283
306
  if (result.success) {
284
- console.log('Output:', result.output);
285
- console.log('Memory used:', result.memoryRetrievalUsed);
307
+ console.log("Output:", result.output);
308
+ console.log("Memory used:", result.memoryRetrievalUsed);
286
309
  } else {
287
- console.error('Error:', result.error);
310
+ console.error("Error:", result.error);
288
311
  }
289
312
  ```
290
313
 
@@ -292,16 +315,19 @@ if (result.success) {
292
315
 
293
316
  ```typescript
294
317
  // Task with memory context
295
- const result = await runtime.executeTask('Continue the quantum computing explanation', {
296
- timeout: 30000,
297
- memoryConfig: {
298
- maxResults: 10, // Maximum context entries
299
- minScore: 0.7 // Relevance threshold (0.0-1.0)
300
- }
301
- });
318
+ const result = await runtime.executeTask(
319
+ "Continue the quantum computing explanation",
320
+ {
321
+ timeout: 30000,
322
+ memoryConfig: {
323
+ maxResults: 10, // Maximum context entries
324
+ minScore: 0.7, // Relevance threshold (0.0-1.0)
325
+ },
326
+ },
327
+ );
302
328
 
303
329
  // Memory is automatically retrieved, injected, and persisted
304
- console.log('Previous context used:', result.memoryRetrievalUsed);
330
+ console.log("Previous context used:", result.memoryRetrievalUsed);
305
331
  ```
306
332
 
307
333
  ### 4. Working Memory for Multi-Step Tasks
@@ -311,45 +337,45 @@ console.log('Previous context used:', result.memoryRetrievalUsed);
311
337
  const workingMemory = runtime.getWorkingMemory();
312
338
 
313
339
  // Step 1: Research overview
314
- workingMemory.set('research-topic', 'AI ethics');
340
+ workingMemory.set("research-topic", "AI ethics");
315
341
  const overviewResult = await runtime.executeTask(
316
- 'Provide overview of AI ethics and key considerations'
342
+ "Provide overview of AI ethics and key considerations",
317
343
  );
318
344
 
319
- // Step 2: Deep dive (with context from step 1)
320
- workingMemory.set('overview-complete', overviewResult.output);
345
+ // Step 2: Deep dive (with context from step 1)
346
+ workingMemory.set("overview-complete", overviewResult.output);
321
347
  const deepDiveResult = await runtime.executeTask(
322
- 'Analyze specific ethical challenges in AI deployment'
348
+ "Analyze specific ethical challenges in AI deployment",
323
349
  );
324
350
 
325
- console.log('Working memory keys:', Array.from(workingMemory.keys()));
351
+ console.log("Working memory keys:", Array.from(workingMemory.keys()));
326
352
  ```
327
353
 
328
354
  ### 5. Hook System for Extensions
329
355
 
330
356
  ```typescript
331
357
  // Add before-execution hook
332
- runtime.addHook('beforeExecute', async (task: string) => {
358
+ runtime.addHook("beforeExecute", async (task: string) => {
333
359
  console.log(`🚀 Starting task: ${task}`);
334
-
360
+
335
361
  // Custom validation
336
- if (task.includes('sensitive')) {
337
- return { approved: false, reason: 'Sensitive content detected' };
362
+ if (task.includes("sensitive")) {
363
+ return { approved: false, reason: "Sensitive content detected" };
338
364
  }
339
-
365
+
340
366
  return { approved: true };
341
367
  });
342
368
 
343
369
  // Add after-execution hook
344
- runtime.addHook('afterExecute', async (task, result, success) => {
345
- console.log(`✅ Task completed: ${success ? 'SUCCESS' : 'FAILED'}`);
346
-
370
+ runtime.addHook("afterExecute", async (task, result, success) => {
371
+ console.log(`✅ Task completed: ${success ? "SUCCESS" : "FAILED"}`);
372
+
347
373
  // Custom telemetry
348
374
  if (success) {
349
375
  await customAnalytics.track({
350
376
  task: task.substring(0, 50),
351
377
  duration: result.duration,
352
- memoryUsed: result.memoryRetrievalUsed
378
+ memoryUsed: result.memoryRetrievalUsed,
353
379
  });
354
380
  }
355
381
  });
@@ -362,16 +388,16 @@ runtime.addHook('afterExecute', async (task, result, success) => {
362
388
  const runtime = new AgentRuntime({
363
389
  providerRegistry: new ProviderRegistry(),
364
390
  memory,
365
- telemetry
391
+ telemetry,
366
392
  });
367
393
 
368
394
  // Providers automatically fallback: OpenAI → Anthropic → Ollama
369
- const result = await runtime.executeTask('Analyze market trends');
395
+ const result = await runtime.executeTask("Analyze market trends");
370
396
 
371
397
  // Check which provider was used
372
398
  const events = await telemetryEngine.getEvents();
373
- const lastExecution = events.filter(e => e.type === 'start').pop();
374
- console.log('Provider used:', lastExecution?.provider);
399
+ const lastExecution = events.filter((e) => e.type === "start").pop();
400
+ console.log("Provider used:", lastExecution?.provider);
375
401
  ```
376
402
 
377
403
  ### 7. Telemetry Monitoring & Analysis
@@ -385,10 +411,12 @@ const events = await telemetry.getEvents();
385
411
  console.log(`Total events: ${events.length}`);
386
412
 
387
413
  // Filter memory events
388
- const memoryEvents = events.filter(e => e.type === 'memory_retrieval');
389
- const hitRate = memoryEvents.length > 0
390
- ? memoryEvents.filter(e => e.memoriesRelevant > 0).length / memoryEvents.length
391
- : 0;
414
+ const memoryEvents = events.filter((e) => e.type === "memory_retrieval");
415
+ const hitRate =
416
+ memoryEvents.length > 0
417
+ ? memoryEvents.filter((e) => e.memoriesRelevant > 0).length /
418
+ memoryEvents.length
419
+ : 0;
392
420
  console.log(`Memory hit rate: ${(hitRate * 100).toFixed(1)}%`);
393
421
  ```
394
422
 
@@ -417,18 +445,21 @@ npx @dcyfr/ai telemetry --export usage_data.csv
417
445
  ### 9. Provider Setup
418
446
 
419
447
  **OpenAI:**
448
+
420
449
  ```bash
421
450
  export OPENAI_API_KEY=sk-your-key-here
422
451
  # Supports: gpt-4, gpt-4o, gpt-3.5-turbo
423
452
  ```
424
453
 
425
454
  **Anthropic:**
455
+
426
456
  ```bash
427
- export ANTHROPIC_API_KEY=sk-ant-your-key-here
457
+ export ANTHROPIC_API_KEY=sk-ant-your-key-here
428
458
  # Supports: claude-3-5-sonnet, claude-3-haiku, claude-3-opus
429
459
  ```
430
460
 
431
461
  **Ollama (Local):**
462
+
432
463
  ```bash
433
464
  # Install Ollama
434
465
  curl -fsSL https://ollama.ai/install.sh | sh
@@ -444,31 +475,33 @@ export OLLAMA_HOST=localhost:11434
444
475
  ### 10. Configuration Examples
445
476
 
446
477
  **Development:**
478
+
447
479
  ```typescript
448
480
  const devConfig = {
449
481
  providerRegistry: new ProviderRegistry(),
450
- memory: new DCYFRMemory({
451
- storage: 'memory',
452
- maxEntries: 100
482
+ memory: new DCYFRMemory({
483
+ storage: "memory",
484
+ maxEntries: 100,
485
+ }),
486
+ telemetry: new TelemetryEngine({
487
+ storage: "memory", // No persistence for dev
453
488
  }),
454
- telemetry: new TelemetryEngine({
455
- storage: 'memory' // No persistence for dev
456
- })
457
489
  };
458
490
  ```
459
491
 
460
492
  **Production:**
461
- ```typescript
493
+
494
+ ```typescript
462
495
  const prodConfig = {
463
496
  providerRegistry: new ProviderRegistry(),
464
- memory: new DCYFRMemory({
465
- storage: 'file',
466
- filePath: './data/memory.json'
497
+ memory: new DCYFRMemory({
498
+ storage: "file",
499
+ filePath: "./data/memory.json",
500
+ }),
501
+ telemetry: new TelemetryEngine({
502
+ storage: "sqlite",
503
+ dbPath: "./data/telemetry.db",
467
504
  }),
468
- telemetry: new TelemetryEngine({
469
- storage: 'sqlite',
470
- dbPath: './data/telemetry.db'
471
- })
472
505
  };
473
506
  ```
474
507
 
@@ -482,10 +515,11 @@ npm run demo -- --topic "quantum computing applications"
482
515
  ```
483
516
 
484
517
  This example demonstrates:
518
+
485
519
  - 5-step autonomous research pipeline
486
520
  - Memory context integration
487
521
  - Working memory coordination
488
- - Hook system extensions
522
+ - Hook system extensions
489
523
  - Telemetry monitoring
490
524
  - Provider fallback handling
491
525
  - Configuration management
@@ -499,41 +533,45 @@ Build agents that operate independently with persistent memory, scheduled execut
499
533
  ### Subpath Imports
500
534
 
501
535
  ```typescript
502
- import { FileMemoryAdapter, SQLiteIndex, flushWorkingMemory } from '@dcyfr/ai/memory';
503
- import { ContextCompactor, MemoryCompaction } from '@dcyfr/ai/compaction';
504
- import { SkillRegistry } from '@dcyfr/ai/skills';
505
- import { MCPToolBridge } from '@dcyfr/ai/mcp';
506
- import { SessionManager } from '@dcyfr/ai/session';
507
- import { AgentScheduler } from '@dcyfr/ai/scheduler';
508
- import { MessageGateway, TelegramAdapter, CLIAdapter } from '@dcyfr/ai/gateway';
536
+ import {
537
+ FileMemoryAdapter,
538
+ SQLiteIndex,
539
+ flushWorkingMemory,
540
+ } from "@dcyfr/ai/memory";
541
+ import { ContextCompactor, MemoryCompaction } from "@dcyfr/ai/compaction";
542
+ import { SkillRegistry } from "@dcyfr/ai/skills";
543
+ import { MCPToolBridge } from "@dcyfr/ai/mcp";
544
+ import { SessionManager } from "@dcyfr/ai/session";
545
+ import { AgentScheduler } from "@dcyfr/ai/scheduler";
546
+ import { MessageGateway, TelegramAdapter, CLIAdapter } from "@dcyfr/ai/gateway";
509
547
  ```
510
548
 
511
549
  ### Key Capabilities
512
550
 
513
- | Module | Description |
514
- |--------|-------------|
515
- | **File Memory** | Markdown-based persistent memory with SHA-256 dedup and optional SQLite FTS5 hybrid search |
516
- | **Context Compaction** | LLM-powered pre-flush summarization to prevent context overflow |
517
- | **Skill Injection** | BM25-powered matching of `.md` skill files to inject relevant knowledge |
518
- | **MCP Tool Bridge** | Bridges MCP server tool discovery → AgentRuntime tools |
519
- | **Session Management** | Trust-level tool policies (full/sandboxed/readonly), session lifecycle |
520
- | **Agent Scheduler** | Built-in cron parser, webhooks, event subscriptions, quiet hours |
521
- | **Messaging Gateway** | Telegram/CLI/HTTP adapters, input sanitization, rate limiting |
522
- | **Memory Compaction** | Cross-backend dedup, monthly conversation summarization, stale fact archival |
523
- | **Working Memory** | Persist `Map<string, unknown>` as human-readable Markdown |
551
+ | Module | Description |
552
+ | ---------------------- | ------------------------------------------------------------------------------------------ |
553
+ | **File Memory** | Markdown-based persistent memory with SHA-256 dedup and optional SQLite FTS5 hybrid search |
554
+ | **Context Compaction** | LLM-powered pre-flush summarization to prevent context overflow |
555
+ | **Skill Injection** | BM25-powered matching of `.md` skill files to inject relevant knowledge |
556
+ | **MCP Tool Bridge** | Bridges MCP server tool discovery → AgentRuntime tools |
557
+ | **Session Management** | Trust-level tool policies (full/sandboxed/readonly), session lifecycle |
558
+ | **Agent Scheduler** | Built-in cron parser, webhooks, event subscriptions, quiet hours |
559
+ | **Messaging Gateway** | Telegram/CLI/HTTP adapters, input sanitization, rate limiting |
560
+ | **Memory Compaction** | Cross-backend dedup, monthly conversation summarization, stale fact archival |
561
+ | **Working Memory** | Persist `Map<string, unknown>` as human-readable Markdown |
524
562
 
525
563
  ### Quick Example
526
564
 
527
565
  ```typescript
528
- import { MessageGateway, TelegramAdapter } from '@dcyfr/ai/gateway';
529
- import { SessionManager } from '@dcyfr/ai/session';
530
- import { AgentScheduler } from '@dcyfr/ai/scheduler';
566
+ import { MessageGateway, TelegramAdapter } from "@dcyfr/ai/gateway";
567
+ import { SessionManager } from "@dcyfr/ai/session";
568
+ import { AgentScheduler } from "@dcyfr/ai/scheduler";
531
569
 
532
570
  // Create a messaging gateway with platform adapters
533
571
  const gateway = new MessageGateway({
534
572
  adapters: [new TelegramAdapter({ sendFn: telegramBot.sendMessage })],
535
573
  trustRules: [
536
- { name: 'admin', userIds: ['admin-id'], trustLevel: 'full', priority: 10 },
574
+ { name: "admin", userIds: ["admin-id"], trustLevel: "full", priority: 10 },
537
575
  ],
538
576
  });
539
577
 
@@ -541,7 +579,7 @@ const gateway = new MessageGateway({
541
579
  const scheduler = new AgentScheduler({
542
580
  executor: async (task) => runAgent(task),
543
581
  });
544
- scheduler.schedule('0 9 * * *', { name: 'morning-report' });
582
+ scheduler.schedule("0 9 * * *", { name: "morning-report" });
545
583
  scheduler.start();
546
584
  ```
547
585
 
@@ -591,6 +629,7 @@ graph TB
591
629
  ### File Formats
592
630
 
593
631
  Supports multiple configuration formats (auto-detected):
632
+
594
633
  - `.dcyfr.yaml` / `.dcyfr.yml` - YAML format (recommended)
595
634
  - `.dcyfr.json` / `dcyfr.config.json` - JSON format
596
635
  - `package.json` - Under `dcyfr` key
@@ -622,7 +661,7 @@ DCYFR comes with specialized validation agents:
622
661
 
623
662
  - **Design Token Validator** - Enforces design system compliance
624
663
  - **Barrel Export Checker** - Ensures import conventions
625
- - **PageLayout Enforcer** - Validates layout usage patterns
664
+ - **PageLayout Enforcer** - Validates layout usage patterns
626
665
  - **Test Data Guardian** - Prevents production data in tests
627
666
 
628
667
  See `@dcyfr/agents` for specialized DCYFR agents.
@@ -630,13 +669,13 @@ See `@dcyfr/agents` for specialized DCYFR agents.
630
669
  ### Custom Plugins
631
670
 
632
671
  ```typescript
633
- import { PluginLoader } from '@dcyfr/ai';
672
+ import { PluginLoader } from "@dcyfr/ai";
634
673
 
635
674
  const customPlugin = {
636
675
  manifest: {
637
- name: 'my-validator',
638
- version: '1.0.0',
639
- description: 'Custom validation logic',
676
+ name: "my-validator",
677
+ version: "1.0.0",
678
+ description: "Custom validation logic",
640
679
  },
641
680
  async onValidate(context) {
642
681
  // Your validation logic
@@ -683,6 +722,9 @@ npx @dcyfr/ai help
683
722
  ## Examples
684
723
 
685
724
  See [examples/](./examples/) directory:
725
+
726
+ - [Examples index](./examples/README.md) - prerequisites and run commands
727
+
686
728
  - `basic-usage.ts` - Getting started
687
729
  - `plugin-system.ts` - Plugin development
688
730
  - `configuration.ts` - Configuration usage
@@ -699,6 +741,7 @@ See [examples/](./examples/) directory:
699
741
  - [Quick Release Guide](./docs/RELEASE_QUICK_START.md) - TL;DR for releases
700
742
 
701
743
  ### Plugin Marketplace Security
744
+
702
745
  - [GVISOR_SETUP.md](./docs/guides/GVISOR_SETUP.md) - gVisor runtime sandboxing for untrusted plugins
703
746
  - [BEHAVIORAL_ANOMALY_DETECTION.md](./docs/guides/BEHAVIORAL_ANOMALY_DETECTION.md) - Behavioral anomaly detection system
704
747
  - [CERTIFICATION_PROGRAM.md](./docs/guides/CERTIFICATION_PROGRAM.md) - Plugin Certification Program (Bronze/Silver/Gold tiers)
@@ -714,6 +757,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.
714
757
  We use [Changesets](https://github.com/changesets/changesets) for automated versioning and publishing.
715
758
 
716
759
  **For contributors:**
760
+
717
761
  ```bash
718
762
  # Add a changeset describing your changes
719
763
  npm run changeset
@@ -724,6 +768,7 @@ git commit -m "feat: your feature"
724
768
  ```
725
769
 
726
770
  **For maintainers:**
771
+
727
772
  - Changesets automatically creates Release PRs
728
773
  - Merging a Release PR publishes to npm
729
774
  - See [Release Management](./docs/RELEASE_MANAGEMENT.md) for full details
@@ -737,11 +782,13 @@ git commit -m "feat: your feature"
737
782
  ### Installation Issues
738
783
 
739
784
  **Issue: `npm install @dcyfr/ai` fails with 404**
785
+
740
786
  - **Cause:** Package may not be published yet or npm registry issue
741
787
  - **Solution:** Verify package exists: `npm view @dcyfr/ai`, or install from GitHub: `npm install git+https://github.com/dcyfr/dcyfr-ai.git`
742
788
  - **Check:** Visit https://www.npmjs.com/package/@dcyfr/ai to confirm publication status
743
789
 
744
790
  **Issue: "Cannot find module '@dcyfr/ai'"**
791
+
745
792
  - **Cause:** Package not in `node_modules` or incorrect import path
746
793
  - **Solution:** Run `npm install`, verify import: `import { loadConfig } from '@dcyfr/ai'`
747
794
  - **TypeScript:** Ensure `moduleResolution: "bundler"` or `"node16"` in tsconfig.json
@@ -749,6 +796,7 @@ git commit -m "feat: your feature"
749
796
  ### Configuration Issues
750
797
 
751
798
  **Issue: `.dcyfr.yaml` not detected**
799
+
752
800
  - **Cause:** File in wrong location or invalid YAML syntax
753
801
  - **Solution:**
754
802
  1. Place `.dcyfr.yaml` in project root (same directory as package.json)
@@ -757,18 +805,21 @@ git commit -m "feat: your feature"
757
805
  - **Alternative:** Use `.dcyfr.json` or add `dcyfr` key to `package.json`
758
806
 
759
807
  **Issue: "Invalid configuration schema"**
808
+
760
809
  - **Cause:** Missing required fields or incorrect types
761
810
  - **Solution:**
762
811
  1. Run `npx @dcyfr/ai config:schema` to see full schema
763
812
  2. Ensure required fields present: `version`, `projectName`
764
813
  3. Check types match (strings in quotes, booleans without quotes, arrays with brackets)
765
814
  - **Example:** Valid config minimum:
815
+
766
816
  ```yaml
767
- version: '1.0.0'
817
+ version: "1.0.0"
768
818
  projectName: my-app
769
819
  ```
770
820
 
771
821
  **Issue: Environment variables not overriding config**
822
+
772
823
  - **Cause:** Incorrect env var naming or precedence
773
824
  - **Solution:** Use `DCYFR_` prefix with nested path: `DCYFR_AGENTS_DESIGNTOKENS_COMPLIANCE=0.95`
774
825
  - **Format:** `DCYFR_<SECTION>_<SUBSECTION>_<KEY>=<value>` (uppercase, underscores)
@@ -777,6 +828,7 @@ projectName: my-app
777
828
  ### Plugin Issues
778
829
 
779
830
  **Issue: Custom plugin not loading**
831
+
780
832
  - **Cause:** Plugin doesn't implement required interface or missing manifest
781
833
  - **Solution:** Ensure plugin exports:
782
834
  1. `manifest` object with `name`, `version`, `description`
@@ -785,10 +837,12 @@ projectName: my-app
785
837
  - **Example:** See [examples/plugin-system.ts](./examples/plugin-system.ts)
786
838
 
787
839
  **Issue: Validation fails with "No plugins loaded"**
840
+
788
841
  - **Cause:** Plugins not registered with PluginLoader before validation
789
842
  - **Solution:**
843
+
790
844
  ```typescript
791
- import { PluginLoader } from '@dcyfr/ai';
845
+ import { PluginLoader } from "@dcyfr/ai";
792
846
  const loader = new PluginLoader();
793
847
  await loader.loadPlugin(myPlugin);
794
848
  await loader.runValidation();
@@ -797,6 +851,7 @@ await loader.runValidation();
797
851
  ### CLI Issues
798
852
 
799
853
  **Issue: `npx @dcyfr/ai` command not found**
854
+
800
855
  - **Cause:** Package not installed or PATH issue
801
856
  - **Solution:**
802
857
  - Local: Add to devDependencies: `npm install --save-dev @dcyfr/ai`
@@ -804,6 +859,7 @@ await loader.runValidation();
804
859
  - npx: Use full package name: `npx @dcyfr/ai@latest`
805
860
 
806
861
  **Issue: CLI commands hang or timeout**
862
+
807
863
  - **Cause:** Large project or slow file system operations
808
864
  - **Solution:**
809
865
  1. Use `--files` flag to target specific files: `npx @dcyfr/ai validate --files "src/**/*.ts"`
@@ -827,19 +883,21 @@ A: Yes, but TypeScript is strongly recommended for better type safety and IDE su
827
883
  **Q: How do I create a custom validation plugin?**
828
884
 
829
885
  A: Implement the `Plugin` interface with `manifest` and `onValidate` method:
886
+
830
887
  ```typescript
831
888
  export const myPlugin = {
832
889
  manifest: {
833
- name: 'my-plugin',
834
- version: '1.0.0',
835
- description: 'My custom validation'
890
+ name: "my-plugin",
891
+ version: "1.0.0",
892
+ description: "My custom validation",
836
893
  },
837
894
  async onValidate(context) {
838
895
  // Your validation logic here
839
896
  return { passed: true, issues: [] };
840
- }
897
+ },
841
898
  };
842
899
  ```
900
+
843
901
  See [docs/plugins.md](./docs/plugins.md) and [examples/plugin-system.ts](./examples/plugin-system.ts) for complete guide.
844
902
 
845
903
  **Q: What's the difference between @dcyfr/ai and @dcyfr/agents?**
@@ -849,6 +907,7 @@ A: `@dcyfr/ai` is the **public harness** (plugin architecture, config management
849
907
  **Q: Can I use this with other AI providers (non-Claude)?**
850
908
 
851
909
  A: Yes! The harness supports multi-provider integration including Claude, GitHub Copilot, Groq, Ollama, OpenAI, Anthropic. Configure providers in `.dcyfr.yaml`:
910
+
852
911
  ```yaml
853
912
  providers:
854
913
  - name: openai
@@ -860,12 +919,14 @@ providers:
860
919
  **Q: How do I track telemetry and costs?**
861
920
 
862
921
  A: Use the `TelemetryEngine` with storage adapters:
922
+
863
923
  ```typescript
864
- import { TelemetryEngine, FileStorageAdapter } from '@dcyfr/ai';
924
+ import { TelemetryEngine, FileStorageAdapter } from "@dcyfr/ai";
865
925
  const telemetry = new TelemetryEngine({
866
- storage: new FileStorageAdapter('./telemetry')
926
+ storage: new FileStorageAdapter("./telemetry"),
867
927
  });
868
928
  ```
929
+
869
930
  Telemetry tracks: API calls, token usage, costs, latency, quality scores.
870
931
 
871
932
  **Q: Is this harness production-ready?**
@@ -879,21 +940,24 @@ A: Yes! @dcyfr/ai is used in production at dcyfr-labs and other projects. It has
879
940
  ## 📊 Performance Benchmarks
880
941
 
881
942
  ### Framework Performance
943
+
882
944
  - **Config Loading:** ~10ms (cached), ~50ms (first load with file I/O)
883
945
  - **Validation Framework:** Parallel execution 2-5x faster than serial (depends on plugin count)
884
946
  - **Plugin System:** Minimal overhead ~5ms per plugin registration
885
- - **Bundle Size:** ~200KB gzipped (includes Zod validation library)
947
+ - **Bundle Size:** Live Bundlephobia minzip badge
886
948
 
887
949
  ### Recommended Usage Patterns
950
+
888
951
  - **Use parallel validation** for independent checks (faster): `mode: 'parallel'`
889
952
  - **Cache config loading** (use singleton pattern): Load once, reuse across app
890
953
  - **Batch telemetry writes** (reduce I/O overhead): Buffer writes, flush periodically
891
954
  - **Lazy load plugins** (faster startup): Only load plugins you need for current validation
892
955
 
893
956
  ### Comparison with Alternatives
957
+
894
958
  - **vs. Custom Scripts:** 10-20x faster due to optimized plugin execution
895
959
  - **vs. Serial Validation:** 2-5x faster with parallel execution mode
896
- - **vs. LangChain:** ~10x smaller bundle size (~200KB vs 2MB+)
960
+ - **vs. LangChain:** Smaller bundle footprint (live Bundlephobia tracking)
897
961
 
898
962
  [⬆️ Back to top](#dcyfr-ai)
899
963
 
@@ -902,11 +966,14 @@ A: Yes! @dcyfr/ai is used in production at dcyfr-labs and other projects. It has
902
966
  ## 🔒 Security
903
967
 
904
968
  ### Reporting Vulnerabilities
969
+
905
970
  Found a security issue? Report it privately:
971
+
906
972
  - **GitHub Security Advisories:** [dcyfr-ai/security](https://github.com/dcyfr/dcyfr-ai/security/advisories/new)
907
973
  - **Expected Response:** Within 48 hours
908
974
 
909
975
  ### Security Considerations
976
+
910
977
  - **No API keys stored:** Use environment variables for sensitive data (Zod validates but doesn't store)
911
978
  - **Zod validation:** All inputs validated with schemas before processing
912
979
  - **No remote code execution:** Plugins run in local environment only (no sandboxing yet - see limitations)
@@ -914,6 +981,7 @@ Found a security issue? Report it privately:
914
981
  - **Dependencies:** Regular Dependabot updates, npm audit on CI
915
982
 
916
983
  ### Best Practices
984
+
917
985
  - Never commit `.env` files (use `.env.example`)
918
986
  - Use environment variables for API keys: `${OPENAI_API_KEY}`
919
987
  - Review plugin code before loading (plugins have full access to filesystem)
@@ -927,6 +995,7 @@ Found a security issue? Report it privately:
927
995
  ## ⚙️ Known Limitations
928
996
 
929
997
  ### Current Constraints
998
+
930
999
  - **Plugin isolation:** Plugins run in same process (no sandboxing yet) - trust plugin code before loading
931
1000
  - **File-based telemetry only:** No database storage adapter yet (planned for v2.0)
932
1001
  - **Config caching:** Requires manual cache invalidation on config changes (no hot-reload yet)
@@ -934,11 +1003,13 @@ Found a security issue? Report it privately:
934
1003
  - **TypeScript required for development:** JavaScript works at runtime but TypeScript recommended for development
935
1004
 
936
1005
  ### Platform-Specific Issues
1006
+
937
1007
  - **Windows:** Path separators handled automatically but some plugins may have issues
938
1008
  - **Node.js version:** Requires ≥24.13.0 (uses native fetch, modern APIs)
939
1009
  - **ESM-only:** Package is ESM (ECMAScript Modules) - CommonJS require() not supported
940
1010
 
941
1011
  ### Planned Improvements
1012
+
942
1013
  - [ ] Database storage adapter for telemetry (PostgreSQL, SQLite)
943
1014
  - [ ] Plugin sandboxing for security (worker threads or VM isolation)
944
1015
  - [ ] Hot-reload config watching (auto-reload on file changes)
@@ -959,10 +1030,12 @@ See [GitHub Issues](https://github.com/dcyfr/dcyfr-ai/issues) for tracked featur
959
1030
  ### Commercial Use
960
1031
 
961
1032
  This package is dual-licensed:
1033
+
962
1034
  - **MIT License** for personal, educational, and non-commercial use (free)
963
1035
  - **Commercial License** for business and revenue-generating use (paid)
964
1036
 
965
1037
  **Commercial use includes:**
1038
+
966
1039
  - Using @dcyfr/ai in SaaS products or revenue-generating services
967
1040
  - Deploying in companies with >5 employees
968
1041
  - Providing paid consulting/services using @dcyfr/ai