@dcyfr/ai 1.0.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +21 -0
  3. package/README.md +210 -0
  4. package/bin/cli.js +249 -0
  5. package/bin/dcyfr-ai.js +376 -0
  6. package/config/default.json +123 -0
  7. package/config/default.yaml +161 -0
  8. package/config/minimal.yaml +16 -0
  9. package/dist/ai/config/loader.d.ts +91 -0
  10. package/dist/ai/config/loader.d.ts.map +1 -0
  11. package/dist/ai/config/loader.js +259 -0
  12. package/dist/ai/config/loader.js.map +1 -0
  13. package/dist/ai/config/schema.d.ts +854 -0
  14. package/dist/ai/config/schema.d.ts.map +1 -0
  15. package/dist/ai/config/schema.js +260 -0
  16. package/dist/ai/config/schema.js.map +1 -0
  17. package/dist/ai/core/provider-registry.d.ts +115 -0
  18. package/dist/ai/core/provider-registry.d.ts.map +1 -0
  19. package/dist/ai/core/provider-registry.js +360 -0
  20. package/dist/ai/core/provider-registry.js.map +1 -0
  21. package/dist/ai/core/telemetry-engine.d.ts +114 -0
  22. package/dist/ai/core/telemetry-engine.d.ts.map +1 -0
  23. package/dist/ai/core/telemetry-engine.js +390 -0
  24. package/dist/ai/core/telemetry-engine.js.map +1 -0
  25. package/dist/ai/index.d.ts +17 -0
  26. package/dist/ai/index.d.ts.map +1 -0
  27. package/dist/ai/index.js +21 -0
  28. package/dist/ai/index.js.map +1 -0
  29. package/dist/ai/plugins/plugin-loader.d.ts +132 -0
  30. package/dist/ai/plugins/plugin-loader.d.ts.map +1 -0
  31. package/dist/ai/plugins/plugin-loader.js +316 -0
  32. package/dist/ai/plugins/plugin-loader.js.map +1 -0
  33. package/dist/ai/types/index.d.ts +179 -0
  34. package/dist/ai/types/index.d.ts.map +1 -0
  35. package/dist/ai/types/index.js +11 -0
  36. package/dist/ai/types/index.js.map +1 -0
  37. package/dist/ai/types/telemetry.d.ts +117 -0
  38. package/dist/ai/types/telemetry.d.ts.map +1 -0
  39. package/dist/ai/types/telemetry.js +6 -0
  40. package/dist/ai/types/telemetry.js.map +1 -0
  41. package/dist/ai/utils/storage.d.ts +37 -0
  42. package/dist/ai/utils/storage.d.ts.map +1 -0
  43. package/dist/ai/utils/storage.js +129 -0
  44. package/dist/ai/utils/storage.js.map +1 -0
  45. package/dist/ai/validation/validation-framework.d.ts +112 -0
  46. package/dist/ai/validation/validation-framework.d.ts.map +1 -0
  47. package/dist/ai/validation/validation-framework.js +221 -0
  48. package/dist/ai/validation/validation-framework.js.map +1 -0
  49. package/package.json +67 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,91 @@
1
+ # Changelog
2
+
3
+ All notable changes to @dcyfr/ai will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2026-01-26
9
+
10
+ ### Added
11
+
12
+ #### Core Framework
13
+ - Configuration system with three-layer merge (defaults → project → env)
14
+ - Support for YAML, JSON, and package.json configuration formats
15
+ - Environment variable overrides for all configuration options
16
+ - Zod-based runtime validation for type safety
17
+ - Telemetry engine for tracking AI usage and quality metrics
18
+ - Provider registry with automatic fallback between AI providers
19
+ - Plugin loader with dynamic loading and validation
20
+ - Validation framework with parallel/serial execution modes
21
+
22
+ #### Plugin System
23
+ - Plugin manifest validation
24
+ - Lifecycle hooks (onLoad, onValidate, onComplete, onUnload)
25
+ - Error isolation and recovery
26
+ - Configurable failure modes (error, warn, skip)
27
+ - Plugin timeout support
28
+
29
+ #### Telemetry
30
+ - Session management with context tracking
31
+ - Metric recording (compliance, test pass rate, costs)
32
+ - Agent statistics aggregation
33
+ - Time-based analytics (7d, 30d, 90d)
34
+ - File-based storage with JSON serialization
35
+ - Memory storage adapter for testing
36
+
37
+ #### Provider Support
38
+ - Claude (Anthropic)
39
+ - Groq
40
+ - Ollama
41
+ - GitHub Copilot
42
+ - OpenAI
43
+ - Generic provider interface
44
+
45
+ #### CLI Tools
46
+ - `init` - Initialize new project
47
+ - `config:init` - Create configuration file
48
+ - `config:validate` - Validate configuration
49
+ - `config:schema` - Show configuration schema
50
+ - `plugin:create` - Generate plugin template
51
+
52
+ #### Documentation
53
+ - Comprehensive getting started guide
54
+ - Complete API reference
55
+ - Plugin development guide
56
+ - Standalone Next.js example project
57
+ - Migration documentation
58
+
59
+ #### Configuration Templates
60
+ - Default YAML configuration
61
+ - Default JSON configuration
62
+ - Minimal configuration templates
63
+
64
+ ### Quality
65
+
66
+ - 49 passing tests (100% pass rate)
67
+ - Full TypeScript strict mode
68
+ - ~200KB bundle size
69
+ - <2s build time
70
+ - Zero breaking changes in API surface
71
+
72
+ ### Developer Experience
73
+ - Type-safe configuration with Zod
74
+ - ESM modules with .d.ts declarations
75
+ - Comprehensive error messages
76
+ - CLI with helpful output and examples
77
+ - Hot module replacement support
78
+
79
+ ## [Unreleased]
80
+
81
+ ### Planned
82
+ - Redis storage adapter for telemetry
83
+ - Database storage adapter
84
+ - Additional validation gates
85
+ - Performance profiling tools
86
+ - Cloud-hosted validation service
87
+ - Multi-language bindings
88
+
89
+ ---
90
+
91
+ [1.0.0]: https://github.com/dcyfr/dcyfr-ai/releases/tag/v1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Drew
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,210 @@
1
+ # @dcyfr/ai
2
+
3
+ Portable AI agent framework with plugin architecture for managing multiple AI providers, tracking telemetry, and ensuring quality compliance.
4
+
5
+ ## Features
6
+
7
+ - šŸ”Œ **Plugin Architecture** - Extensible validation system with custom agents
8
+ - šŸ”„ **Multi-Provider Support** - Claude, Copilot, Groq, Ollama, OpenAI, Anthropic
9
+ - āš™ļø **Configuration System** - YAML/JSON config with three-layer merge
10
+ - šŸ“Š **Comprehensive Telemetry** - Track usage, costs, quality metrics, performance
11
+ - āœ… **Validation Framework** - Quality gates with parallel/serial execution
12
+ - šŸ’¾ **Pluggable Storage** - Memory, file-based, or custom adapters
13
+ - ⚔ **Type-Safe** - Full TypeScript support with Zod validation
14
+ - šŸ“¦ **Lightweight** - ~200KB gzipped bundle size
15
+ - šŸ› ļø **CLI Tools** - Config validation and initialization
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @dcyfr/ai
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ### 1. Initialize Configuration
26
+
27
+ ```bash
28
+ npx @dcyfr/ai config:init
29
+ ```
30
+
31
+ This creates a `.dcyfr.yaml` configuration file:
32
+
33
+ ```yaml
34
+ version: '1.0.0'
35
+ projectName: my-app
36
+
37
+ agents:
38
+ designTokens:
39
+ enabled: true
40
+ compliance: 0.90
41
+ barrelExports:
42
+ enabled: true
43
+ pageLayout:
44
+ enabled: true
45
+ targetUsage: 0.90
46
+ testData:
47
+ enabled: true
48
+ ```
49
+
50
+ ### 2. Load and Use Configuration
51
+
52
+ ```typescript
53
+ import { loadConfig, ValidationFramework } from '@dcyfr/ai';
54
+
55
+ // Load configuration (auto-detects .dcyfr.yaml, .dcyfr.json, package.json)
56
+ const config = await loadConfig();
57
+
58
+ // Create validation framework
59
+ const framework = new ValidationFramework({
60
+ gates: config.validation.gates,
61
+ parallel: config.validation.parallel,
62
+ });
63
+
64
+ // Run validation
65
+ const report = await framework.validate({
66
+ projectRoot: config.project.root,
67
+ files: config.project.include,
68
+ config: config.agents,
69
+ });
70
+
71
+ console.log(`Validation: ${report.valid ? 'PASS' : 'FAIL'}`);
72
+ ```
73
+
74
+ ### 3. Validate Configuration
75
+
76
+ ```bash
77
+ # Validate current project config
78
+ npx @dcyfr/ai config:validate
79
+
80
+ # Show full configuration
81
+ npx @dcyfr/ai config:validate --verbose
82
+ ```
83
+
84
+ ## Configuration
85
+
86
+ ### File Formats
87
+
88
+ Supports multiple configuration formats (auto-detected):
89
+ - `.dcyfr.yaml` / `.dcyfr.yml` - YAML format (recommended)
90
+ - `.dcyfr.json` / `dcyfr.config.json` - JSON format
91
+ - `package.json` - Under `dcyfr` key
92
+
93
+ ### Three-Layer Merge
94
+
95
+ Configuration is merged from three sources:
96
+
97
+ ```
98
+ Framework Defaults → Project Config → Environment Variables
99
+ (built-in) (.dcyfr.yaml) (DCYFR_* vars)
100
+ ```
101
+
102
+ ### Environment Overrides
103
+
104
+ Override any config value with environment variables:
105
+
106
+ ```bash
107
+ DCYFR_TELEMETRY_ENABLED=false
108
+ DCYFR_PROVIDERS_PRIMARY=groq
109
+ DCYFR_AGENTS_DESIGNTOKENS_COMPLIANCE=0.95
110
+ ```
111
+
112
+ ## Plugin System
113
+
114
+ ### Built-in Agents
115
+
116
+ DCYFR comes with specialized validation agents:
117
+
118
+ - **Design Token Validator** - Enforces design system compliance
119
+ - **Barrel Export Checker** - Ensures import conventions
120
+ - **PageLayout Enforcer** - Validates layout usage patterns
121
+ - **Test Data Guardian** - Prevents production data in tests
122
+
123
+ See `@dcyfr/agents` for specialized DCYFR agents.
124
+
125
+ ### Custom Plugins
126
+
127
+ ```typescript
128
+ import { PluginLoader } from '@dcyfr/ai';
129
+
130
+ const customPlugin = {
131
+ manifest: {
132
+ name: 'my-validator',
133
+ version: '1.0.0',
134
+ description: 'Custom validation logic',
135
+ },
136
+ async onValidate(context) {
137
+ // Your validation logic
138
+ return {
139
+ valid: true,
140
+ violations: [],
141
+ warnings: [],
142
+ };
143
+ },
144
+ };
145
+
146
+ const loader = new PluginLoader();
147
+ await loader.loadPlugin(customPlugin);
148
+ ```
149
+
150
+ ## CLI Commands
151
+
152
+ ```bash
153
+ # Initialize configuration
154
+ npx @dcyfr/ai config:init
155
+ npx @dcyfr/ai config:init --format json
156
+ npx @dcyfr/ai config:init --minimal
157
+
158
+ # Validate configuration
159
+ npx @dcyfr/ai config:validate
160
+ npx @dcyfr/ai config:validate --verbose
161
+ npx @dcyfr/ai config:validate --config custom.yaml
162
+
163
+ # Show schema
164
+ npx @dcyfr/ai config:schema
165
+
166
+ # Help
167
+ npx @dcyfr/ai help
168
+ ```
169
+
170
+ ## Examples
171
+
172
+ See [examples/](./examples/) directory:
173
+ - `basic-usage.ts` - Getting started
174
+ - `plugin-system.ts` - Plugin development
175
+ - `configuration.ts` - Configuration usage
176
+
177
+ ## Documentation
178
+
179
+ - [Getting Started](./docs/getting-started.md)
180
+ - [Configuration Guide](./docs/configuration.md)
181
+ - [Plugin Development](./docs/plugins.md)
182
+ - [API Reference](./docs/api.md)
183
+
184
+ ## Architecture
185
+
186
+ ```
187
+ @dcyfr/ai (Public Framework)
188
+ ā”œā”€ā”€ Core
189
+ │ ā”œā”€ā”€ TelemetryEngine - Usage tracking
190
+ │ └── ProviderRegistry - Multi-provider AI
191
+ ā”œā”€ā”€ Plugins
192
+ │ ā”œā”€ā”€ PluginLoader - Dynamic loading
193
+ │ └── ValidationFramework - Quality gates
194
+ ā”œā”€ā”€ Config
195
+ │ ā”œā”€ā”€ Schema (Zod) - Validation
196
+ │ └── Loader - Three-layer merge
197
+ └── CLI
198
+ └── Config tools
199
+
200
+ @dcyfr/agents (Private Agents)
201
+ └── Specialized validators for DCYFR projects
202
+ ```
203
+
204
+ ## License
205
+
206
+ MIT Ā© DCYFR Labs
207
+
208
+ ## Contributing
209
+
210
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.
package/bin/cli.js ADDED
@@ -0,0 +1,249 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * DCYFR AI Framework CLI
5
+ * Configuration validation and management tool
6
+ */
7
+
8
+ import { ConfigLoader } from '../dist/ai/config/loader.js';
9
+ import { FrameworkConfigSchema } from '../dist/ai/config/schema.js';
10
+ import { existsSync } from 'fs';
11
+ import { join, dirname } from 'path';
12
+ import { fileURLToPath } from 'url';
13
+
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = dirname(__filename);
16
+
17
+ /**
18
+ * Parse command line arguments
19
+ */
20
+ function parseArgs() {
21
+ const args = process.argv.slice(2);
22
+ const command = args[0] || 'help';
23
+ const flags = {};
24
+ const positional = [];
25
+
26
+ for (let i = 1; i < args.length; i++) {
27
+ const arg = args[i];
28
+
29
+ if (arg.startsWith('--')) {
30
+ const [key, value] = arg.substring(2).split('=');
31
+ flags[key] = value || true;
32
+ } else if (arg.startsWith('-')) {
33
+ flags[arg.substring(1)] = true;
34
+ } else {
35
+ positional.push(arg);
36
+ }
37
+ }
38
+
39
+ return { command, args: positional, flags };
40
+ }
41
+
42
+ /**
43
+ * Validate configuration
44
+ */
45
+ async function validateConfig(options) {
46
+ console.log('šŸ” Validating DCYFR configuration...\n');
47
+
48
+ const projectRoot = options.flags.root || process.cwd();
49
+ const configFile = options.flags.config;
50
+
51
+ try {
52
+ // Load configuration
53
+ const loader = new ConfigLoader({
54
+ projectRoot,
55
+ configFile,
56
+ validate: true,
57
+ });
58
+
59
+ const config = await loader.load();
60
+ const configPath = await loader.getConfigFilePath();
61
+
62
+ // Display results
63
+ console.log('āœ… Configuration is valid!\n');
64
+ console.log(`šŸ“‚ Project root: ${projectRoot}`);
65
+
66
+ if (configPath) {
67
+ console.log(`šŸ“„ Config file: ${configPath}`);
68
+ } else {
69
+ console.log('šŸ“„ Config file: None (using defaults)');
70
+ }
71
+
72
+ console.log(`šŸŽÆ Project: ${config.projectName || '(unnamed)'}`);
73
+ console.log(`šŸ“Š Version: ${config.version}`);
74
+
75
+ // Feature summary
76
+ console.log('\nšŸ”Œ Features:');
77
+ console.log(` Telemetry: ${config.telemetry.enabled ? 'āœ…' : 'āŒ'}`);
78
+ console.log(` Validation: ${config.validation.enabled ? 'āœ…' : 'āŒ'}`);
79
+ console.log(` Plugins: ${config.plugins.length} configured`);
80
+ console.log(` Gates: ${config.validation.gates.length} configured`);
81
+
82
+ // Agent summary
83
+ console.log('\nšŸ¤– Agents:');
84
+ Object.entries(config.agents).forEach(([name, agentConfig]) => {
85
+ const enabled = 'enabled' in agentConfig ? agentConfig.enabled : true;
86
+ console.log(` ${name}: ${enabled ? 'āœ…' : 'āŒ'}`);
87
+ });
88
+
89
+ // Verbose mode
90
+ if (options.flags.verbose || options.flags.v) {
91
+ console.log('\nšŸ“‹ Full Configuration:');
92
+ console.log(JSON.stringify(config, null, 2));
93
+ }
94
+
95
+ process.exit(0);
96
+ } catch (error) {
97
+ console.error('āŒ Configuration validation failed!\n');
98
+ console.error(error instanceof Error ? error.message : String(error));
99
+
100
+ if (options.flags.verbose || options.flags.v) {
101
+ console.error('\nšŸ“š Stack trace:');
102
+ console.error(error);
103
+ }
104
+
105
+ process.exit(1);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Show configuration schema
111
+ */
112
+ async function showSchema() {
113
+ console.log('šŸ“‹ DCYFR Configuration Schema\n');
114
+ console.log('The configuration supports the following structure:\n');
115
+ console.log(FrameworkConfigSchema.description || 'Framework configuration schema');
116
+ console.log('\nFor detailed documentation, visit:');
117
+ console.log('https://github.com/dcyfr/dcyfr-ai/blob/main/docs/configuration.md');
118
+ process.exit(0);
119
+ }
120
+
121
+ /**
122
+ * Initialize configuration file
123
+ */
124
+ async function initConfig(options) {
125
+ const projectRoot = options.flags.root || process.cwd();
126
+ const format = options.flags.format || 'yaml';
127
+ const minimal = options.flags.minimal || false;
128
+
129
+ const configFile = format === 'json' ? '.dcyfr.json' : '.dcyfr.yaml';
130
+ const configPath = join(projectRoot, configFile);
131
+
132
+ if (existsSync(configPath)) {
133
+ console.error(`āŒ Config file already exists: ${configPath}`);
134
+ console.error('Use --force to overwrite');
135
+
136
+ if (!options.flags.force) {
137
+ process.exit(1);
138
+ }
139
+ }
140
+
141
+ console.log(`šŸ“ Creating ${configFile}...\n`);
142
+
143
+ // Read template
144
+ const templateName = minimal ? 'minimal.yaml' : `default.${format}`;
145
+ const templatePath = join(__dirname, '../config', templateName);
146
+
147
+ if (!existsSync(templatePath)) {
148
+ console.error(`āŒ Template not found: ${templateName}`);
149
+ process.exit(1);
150
+ }
151
+
152
+ // Copy template
153
+ const { copyFile } = await import('fs/promises');
154
+ await copyFile(templatePath, configPath);
155
+
156
+ console.log(`āœ… Created ${configPath}`);
157
+ console.log('\nNext steps:');
158
+ console.log(' 1. Edit the configuration file to match your project');
159
+ console.log(' 2. Run `npx @dcyfr/ai config:validate` to verify');
160
+ console.log(' 3. Start using DCYFR AI Framework in your project\n');
161
+
162
+ process.exit(0);
163
+ }
164
+
165
+ /**
166
+ * Show help
167
+ */
168
+ function showHelp() {
169
+ console.log(`
170
+ DCYFR AI Framework CLI
171
+
172
+ Usage:
173
+ npx @dcyfr/ai <command> [options]
174
+
175
+ Commands:
176
+ config:validate Validate configuration file
177
+ config:init Initialize new configuration file
178
+ config:schema Show configuration schema
179
+ help Show this help message
180
+
181
+ Options:
182
+ --root <path> Project root directory (default: current directory)
183
+ --config <file> Custom config file path
184
+ --format <json|yaml> Config file format for init (default: yaml)
185
+ --minimal Create minimal config (init only)
186
+ --force Overwrite existing config (init only)
187
+ --verbose, -v Show detailed output
188
+
189
+ Examples:
190
+ # Validate current project configuration
191
+ npx @dcyfr/ai config:validate
192
+
193
+ # Validate with custom config file
194
+ npx @dcyfr/ai config:validate --config custom.yaml
195
+
196
+ # Initialize new YAML configuration
197
+ npx @dcyfr/ai config:init
198
+
199
+ # Initialize minimal JSON configuration
200
+ npx @dcyfr/ai config:init --format json --minimal
201
+
202
+ # Show full configuration with validation
203
+ npx @dcyfr/ai config:validate --verbose
204
+
205
+ Documentation:
206
+ https://github.com/dcyfr/dcyfr-ai
207
+ `);
208
+ process.exit(0);
209
+ }
210
+
211
+ /**
212
+ * Main CLI entry point
213
+ */
214
+ async function main() {
215
+ const options = parseArgs();
216
+
217
+ switch (options.command) {
218
+ case 'config:validate':
219
+ case 'validate':
220
+ await validateConfig(options);
221
+ break;
222
+
223
+ case 'config:init':
224
+ case 'init':
225
+ await initConfig(options);
226
+ break;
227
+
228
+ case 'config:schema':
229
+ case 'schema':
230
+ await showSchema();
231
+ break;
232
+
233
+ case 'help':
234
+ case '--help':
235
+ case '-h':
236
+ showHelp();
237
+ break;
238
+
239
+ default:
240
+ console.error(`āŒ Unknown command: ${options.command}\n`);
241
+ showHelp();
242
+ }
243
+ }
244
+
245
+ // Run CLI
246
+ main().catch((error) => {
247
+ console.error('āŒ Unexpected error:', error);
248
+ process.exit(1);
249
+ });