outlet-orm 6.5.0 → 9.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 (58) hide show
  1. package/README.md +130 -2
  2. package/bin/init.js +122 -0
  3. package/bin/mcp.js +78 -0
  4. package/bin/migrate.js +25 -0
  5. package/docs/skills/outlet-orm/ADVANCED.md +575 -0
  6. package/docs/skills/outlet-orm/AI.md +220 -0
  7. package/docs/skills/outlet-orm/API.md +522 -0
  8. package/docs/skills/outlet-orm/BACKUP.md +150 -0
  9. package/docs/skills/outlet-orm/MIGRATIONS.md +605 -0
  10. package/docs/skills/outlet-orm/MODELS.md +427 -0
  11. package/docs/skills/outlet-orm/QUERIES.md +345 -0
  12. package/docs/skills/outlet-orm/RELATIONS.md +555 -0
  13. package/docs/skills/outlet-orm/SECURITY.md +386 -0
  14. package/docs/skills/outlet-orm/SEEDS.md +98 -0
  15. package/docs/skills/outlet-orm/SKILL.md +205 -0
  16. package/docs/skills/outlet-orm/TYPESCRIPT.md +480 -0
  17. package/package.json +7 -3
  18. package/src/AI/AIPromptEnhancer.js +170 -0
  19. package/src/AI/AIQueryBuilder.js +234 -0
  20. package/src/AI/AIQueryOptimizer.js +185 -0
  21. package/src/AI/AISafetyGuardrails.js +146 -0
  22. package/src/AI/AISeeder.js +181 -0
  23. package/src/AI/AiBridgeManager.js +287 -0
  24. package/src/AI/Builders/TextBuilder.js +170 -0
  25. package/src/AI/Contracts/AudioProviderContract.js +29 -0
  26. package/src/AI/Contracts/ChatProviderContract.js +38 -0
  27. package/src/AI/Contracts/EmbeddingsProviderContract.js +19 -0
  28. package/src/AI/Contracts/ImageProviderContract.js +19 -0
  29. package/src/AI/Contracts/ModelsProviderContract.js +26 -0
  30. package/src/AI/Contracts/ToolContract.js +25 -0
  31. package/src/AI/Facades/AiBridge.js +79 -0
  32. package/src/AI/MCPServer.js +798 -0
  33. package/src/AI/PromptGenerator.js +318 -0
  34. package/src/AI/Providers/ClaudeProvider.js +64 -0
  35. package/src/AI/Providers/CustomOpenAIProvider.js +238 -0
  36. package/src/AI/Providers/GeminiProvider.js +68 -0
  37. package/src/AI/Providers/GrokProvider.js +46 -0
  38. package/src/AI/Providers/MistralProvider.js +21 -0
  39. package/src/AI/Providers/OllamaProvider.js +249 -0
  40. package/src/AI/Providers/OllamaTurboProvider.js +32 -0
  41. package/src/AI/Providers/OnnProvider.js +46 -0
  42. package/src/AI/Providers/OpenAIProvider.js +471 -0
  43. package/src/AI/Support/AudioNormalizer.js +37 -0
  44. package/src/AI/Support/ChatNormalizer.js +42 -0
  45. package/src/AI/Support/Document.js +77 -0
  46. package/src/AI/Support/DocumentAttachmentMapper.js +101 -0
  47. package/src/AI/Support/EmbeddingsNormalizer.js +30 -0
  48. package/src/AI/Support/Exceptions/ProviderError.js +22 -0
  49. package/src/AI/Support/FileSecurity.js +56 -0
  50. package/src/AI/Support/ImageNormalizer.js +62 -0
  51. package/src/AI/Support/JsonSchemaValidator.js +73 -0
  52. package/src/AI/Support/Message.js +40 -0
  53. package/src/AI/Support/StreamChunk.js +45 -0
  54. package/src/AI/Support/ToolChatRunner.js +160 -0
  55. package/src/AI/Support/ToolRegistry.js +62 -0
  56. package/src/AI/Tools/SystemInfoTool.js +25 -0
  57. package/src/index.js +77 -1
  58. package/types/index.d.ts +432 -0
@@ -0,0 +1,220 @@
1
+ ---
2
+ name: outlet-orm-ai-integration
3
+ description: Guide for AI agents to use Outlet ORM's MCP Server, AI Safety Guardrails, and prompt-based project initialization. Use this skill when an AI agent needs to interact with Outlet ORM databases, run migrations, create projects, or execute queries safely.
4
+ license: MIT
5
+ metadata:
6
+ author: omgbwa-yasse
7
+ version: "7.0.0"
8
+ source: https://github.com/omgbwa-yasse/outlet-orm
9
+ npm: https://www.npmjs.com/package/outlet-orm
10
+ ---
11
+
12
+ # Outlet ORM — AI Integration Guide
13
+
14
+ This skill covers Outlet ORM's AI-oriented features introduced in v7.0.0:
15
+
16
+ - **MCP Server** — Model Context Protocol server for AI agents
17
+ - **AI Safety Guardrails** — Protection against destructive operations
18
+ - **Prompt-based Init** — Generate projects from natural language descriptions
19
+
20
+ ---
21
+
22
+ ## MCP Server
23
+
24
+ The MCP server exposes Outlet ORM's full capabilities to AI agents via JSON-RPC 2.0 over stdio.
25
+
26
+ ### Configuration
27
+
28
+ Add to your AI editor's MCP config (e.g. `.cursor/mcp.json`, `.vscode/mcp.json`, `claude_desktop_config.json`):
29
+
30
+ ```json
31
+ {
32
+ "mcpServers": {
33
+ "outlet-orm": {
34
+ "command": "npx",
35
+ "args": ["outlet-mcp"],
36
+ "env": {
37
+ "DB_DRIVER": "sqlite",
38
+ "DB_DATABASE": "./database.sqlite"
39
+ }
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ ### Available Tools
46
+
47
+ | Tool | Description | Destructive |
48
+ |------|-------------|:-----------:|
49
+ | `migrate_status` | Show pending and executed migrations | No |
50
+ | `migrate_run` | Run all pending migrations | No |
51
+ | `migrate_rollback` | Rollback last batch (supports `steps` param) | No |
52
+ | `migrate_reset` | Rollback ALL migrations | **Yes** |
53
+ | `migrate_make` | Create a new migration file | No |
54
+ | `seed_run` | Run database seeders | No |
55
+ | `schema_introspect` | Introspect database schema (all tables or specific) | No |
56
+ | `query_execute` | Execute raw SQL (write queries need consent) | Conditional |
57
+ | `model_list` | List all model files in the project | No |
58
+ | `backup_create` | Create a database backup (full/partial/journal) | No |
59
+ | `backup_restore` | Restore from a backup file | **Yes** |
60
+
61
+ ### Tool Usage Examples
62
+
63
+ **Introspect the schema:**
64
+ ```json
65
+ { "method": "tools/call", "params": { "name": "schema_introspect", "arguments": {} } }
66
+ ```
67
+
68
+ **Run a SELECT query:**
69
+ ```json
70
+ { "method": "tools/call", "params": { "name": "query_execute", "arguments": { "sql": "SELECT * FROM users LIMIT 10" } } }
71
+ ```
72
+
73
+ **Create a migration:**
74
+ ```json
75
+ { "method": "tools/call", "params": { "name": "migrate_make", "arguments": { "name": "create_products_table" } } }
76
+ ```
77
+
78
+ **Destructive operation (requires consent):**
79
+ ```json
80
+ { "method": "tools/call", "params": { "name": "migrate_reset", "arguments": { "consent": "User confirmed: reset all migrations in dev environment" } } }
81
+ ```
82
+
83
+ ### Programmatic Usage
84
+
85
+ ```javascript
86
+ const { MCPServer } = require('outlet-orm');
87
+
88
+ const server = new MCPServer({
89
+ projectDir: process.cwd(),
90
+ safetyGuardrails: true
91
+ });
92
+
93
+ // Programmatic handler (for testing or embedding)
94
+ const handler = server.handler();
95
+ const response = await handler({
96
+ jsonrpc: '2.0',
97
+ id: 1,
98
+ method: 'tools/call',
99
+ params: { name: 'schema_introspect', arguments: {} }
100
+ });
101
+ ```
102
+
103
+ ---
104
+
105
+ ## AI Safety Guardrails
106
+
107
+ Outlet ORM automatically detects AI agent invocations and blocks destructive operations without explicit user consent.
108
+
109
+ ### Detected Agents
110
+
111
+ - **Cursor** (CURSOR_TRACE_ID, CURSOR_SESSION_ID)
112
+ - **Claude Code** (CLAUDE_CODE)
113
+ - **GitHub Copilot** (COPILOT_AGENT_MODE)
114
+ - **Windsurf** (WINDSURF_SESSION_ID, CODEIUM_SESSION)
115
+ - **Gemini CLI** (GEMINI_API_KEY + process title)
116
+ - **Aider** (AIDER_SESSION)
117
+ - **Replit** (REPLIT_DB_URL, REPLIT_AI_ENABLED)
118
+ - **Qwen Code** (QWEN_SESSION)
119
+ - **MCP Clients** (MCP_SERVER_NAME, MCP_SESSION_ID)
120
+
121
+ ### Destructive Commands
122
+
123
+ These commands are blocked when an AI agent is detected without consent:
124
+ `reset`, `fresh`, `migrate:reset`, `migrate:fresh`, `drop`, `truncate`, `restore`
125
+
126
+ ### Consent Mechanism
127
+
128
+ To allow a destructive operation, the AI agent must either:
129
+
130
+ 1. **Set the environment variable:**
131
+ ```bash
132
+ OUTLET_USER_CONSENT_FOR_DANGEROUS_AI_ACTION="User confirmed: reset dev database"
133
+ ```
134
+
135
+ 2. **Pass the `consent` flag** in MCP tool arguments:
136
+ ```json
137
+ { "consent": "User explicitly approved resetting the development database" }
138
+ ```
139
+
140
+ ### Programmatic Usage
141
+
142
+ ```javascript
143
+ const { AISafetyGuardrails } = require('outlet-orm');
144
+
145
+ // Detect if running under an AI agent
146
+ const { detected, agentName } = AISafetyGuardrails.detectAgent();
147
+ console.log(detected, agentName); // true, 'GitHub Copilot'
148
+
149
+ // Validate a destructive action
150
+ const result = AISafetyGuardrails.validateDestructiveAction('reset', { consent: 'User approved' });
151
+ console.log(result.allowed); // true
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Prompt-based Initialization
157
+
158
+ Generate an entire project from a natural language description.
159
+
160
+ ### CLI Usage
161
+
162
+ ```bash
163
+ outlet-init --prompt "Create a blog application with posts, comments, and tags"
164
+ outlet-init --prompt "E-commerce store with products, orders, and payments" --driver sqlite
165
+ ```
166
+
167
+ ### Supported Domains
168
+
169
+ | Domain | Keywords | Generated Tables |
170
+ |--------|----------|-----------------|
171
+ | **E-commerce** | shop, store, product, cart, order, payment | users, products, categories, orders, order_items, payments |
172
+ | **Blog/CMS** | blog, article, post, cms, comment, tag | users, posts, categories, tags, post_tag, comments |
173
+ | **Task/Project** | task, project, todo, kanban, sprint | users, projects, tasks, labels, task_label |
174
+ | **Social Network** | social, friend, follow, like, feed, message | users, posts, comments, likes, follows, messages |
175
+ | **SaaS** | saas, tenant, subscription, plan, billing | organizations, users, plans, subscriptions, invoices |
176
+ | **Habit Tracker** | habit, tracker, health, fitness, goal | users, habits, logs, goals |
177
+ | **API/Auth** | api, auth, rest, user | users, tokens, password_resets |
178
+
179
+ ### Programmatic Usage
180
+
181
+ ```javascript
182
+ const { PromptGenerator } = require('outlet-orm');
183
+
184
+ // Parse a prompt
185
+ const blueprint = PromptGenerator.parse('Create a blog with comments and tags');
186
+ console.log(blueprint.domain); // 'blog'
187
+ console.log(blueprint.tables); // { users: {...}, posts: {...}, ... }
188
+
189
+ // Generate models
190
+ const modelFiles = PromptGenerator.generateModels(blueprint, './models');
191
+
192
+ // Generate migrations
193
+ const migrationFiles = PromptGenerator.generateMigrations(blueprint, './database/migrations');
194
+
195
+ // Generate seeder
196
+ const seederFile = PromptGenerator.generateSeeder(blueprint, './database/seeds');
197
+ ```
198
+
199
+ ---
200
+
201
+ ## Best Practices for AI Agents
202
+
203
+ 1. **Always introspect first** — Use `schema_introspect` before modifying the database.
204
+ 2. **Never bypass safety guardrails** — Always obtain explicit user consent for destructive operations.
205
+ 3. **Use migrations, not raw DDL** — Prefer `migrate_make` + `migrate_run` over raw `CREATE TABLE` queries.
206
+ 4. **Check migration status** — Use `migrate_status` before running migrations.
207
+ 5. **Explain write queries** — When using `query_execute` for writes, explain what the query does to the user.
208
+ 6. **Prefer backups before destructive operations** — Use `backup_create` before `migrate_reset`.
209
+
210
+ ---
211
+
212
+ ## Quick Reference
213
+
214
+ ```javascript
215
+ const {
216
+ MCPServer, // MCP server for AI agents
217
+ AISafetyGuardrails, // AI agent detection & safety
218
+ PromptGenerator // Natural language project generation
219
+ } = require('outlet-orm');
220
+ ```