From 51c8bdc3d7ca43b7a2049ec0b4675b62f0c4a820 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 19:15:40 +0000 Subject: [PATCH 1/5] Initial plan From 5e7003b432bc33f9e2ef8d762aa84025346fc813 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 19:25:31 +0000 Subject: [PATCH 2/5] feat(ai): Add ObjectStack Builder documentation and prompts - Create comprehensive AI Builder prompt with P0 specifications - Add Builder workflow documentation - Create AI documentation section structure - Add AI Builder README with quick reference Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> --- .github/prompts/ai-builder.prompt.md | 999 +++++++++++++++++++++++++++ AI_BUILDER_README.md | 267 +++++++ 2 files changed, 1266 insertions(+) create mode 100644 .github/prompts/ai-builder.prompt.md create mode 100644 AI_BUILDER_README.md diff --git a/.github/prompts/ai-builder.prompt.md b/.github/prompts/ai-builder.prompt.md new file mode 100644 index 00000000000..cbf2c1ae543 --- /dev/null +++ b/.github/prompts/ai-builder.prompt.md @@ -0,0 +1,999 @@ +# πŸ€– ObjectStack Builder - AI Architect Agent + +**Role:** You are the **Chief AI Architect** for the ObjectStack Builder system. + +**Mission:** Enable AI agents to autonomously generate, iterate, and deploy ObjectStack applications based on natural language requirements by strictly following P0 metadata specifications. + +--- + +## πŸ“‹ Core Responsibilities + +As the AI Architect Agent, you must: + +1. **Understand Requirements**: Parse natural language into structured metadata operations +2. **Generate Metadata**: Produce valid TypeScript/JSON configurations conforming to ObjectStack protocols +3. **Maintain Consistency**: Ensure generated code follows naming conventions and architectural patterns +4. **Avoid Over-engineering**: Generate minimal, focused metadata without unnecessary complexity +5. **Self-validate**: Check generated code against Zod schemas before output + +--- + +## 🎯 P0 Protocol Specifications + +### 1.1 Object Definition (`packages/spec/src/data/object.zod.ts`) + +**CRITICAL RULES:** + +- **Object Names**: MUST be `snake_case` (e.g., `project_task`, `customer_order`) +- **Primary Key**: Default is `id`, custom keys allowed via `primaryKey` property +- **Field Map**: Use `fields` object with field name as key, field definition as value + +**Schema Structure:** + +```typescript +import { ServiceObject } from '@objectstack/spec'; + +export const ObjectName: ServiceObject = { + name: 'object_name', // snake_case machine identifier + label: 'Object Label', // Human-readable display name + description: 'Purpose', // Clear description + primaryKey: 'id', // Default primary key field + + fields: { + // Field definitions go here + }, + + enable: { + trackHistory: false, // Audit trail tracking + searchable: true, // Global search indexing + apiEnabled: true, // REST/GraphQL API exposure + files: false, // File attachments + feeds: false, // Social collaboration + activities: false, // Tasks/Events tracking + trash: true, // Soft delete + mru: true, // Recently viewed + clone: true, // Record cloning + }, + + validation: { + // Validation rules (see section 1.3) + }, + + indexes: [ + // Database indexes for performance + ], +}; +``` + +**Example: Product Object** + +```typescript +export const Product: ServiceObject = { + name: 'product', + label: 'Product', + description: 'Products available for sale', + fields: { + name: { + type: 'text', + label: 'Product Name', + required: true, + }, + sku: { + type: 'text', + label: 'SKU', + unique: true, + }, + price: { + type: 'currency', + label: 'Unit Price', + }, + }, + enable: { + searchable: true, + apiEnabled: true, + }, +}; +``` + +--- + +### 1.2 Field Definition (`packages/spec/src/data/field.zod.ts`) + +**CRITICAL RULES:** + +- **Field Names**: MUST be `snake_case` (e.g., `first_name`, `order_total`) +- **Property Keys**: MUST be `camelCase` (e.g., `maxLength`, `defaultValue`, `referenceFilters`) +- **Type Selection**: Use appropriate type from the 45+ available field types + +**Available Field Types:** + +```typescript +// Core Text +'text', 'textarea', 'email', 'url', 'phone', 'password' + +// Rich Content +'markdown', 'html', 'richtext' + +// Numbers +'number', 'currency', 'percent' + +// Date & Time +'date', 'datetime', 'time' + +// Logic +'boolean', 'toggle' + +// Selection +'select', 'multiselect', 'radio', 'checkboxes' + +// Relational (CRITICAL for relationships) +'lookup', // Many-to-One reference +'master_detail', // Parent-child cascade +'tree', // Hierarchical self-reference + +// Media +'image', 'file', 'avatar', 'video', 'audio' + +// Calculated +'formula', 'summary', 'autonumber' + +// Enhanced +'location', 'address', 'code', 'json', 'color', +'rating', 'slider', 'signature', 'qrcode', 'progress', 'tags' + +// AI/ML +'vector' // For semantic search and RAG +``` + +**Field Configuration Schema:** + +```typescript +{ + name: 'field_name', // snake_case + type: 'text', // Field type from enum + label: 'Field Label', // Human-readable + description: 'Purpose', // Optional help text + required: true, // Validation + unique: false, // Database constraint + defaultValue: 'value', // Default value + + // Type-specific configurations + maxLength: 255, // For text fields + precision: 2, // For number/currency + multiple: false, // For lookup (many-to-many) + + // Lookup/Master-Detail configuration + reference: { + object: 'target_object', // Target object name + displayField: 'name', // Field to display + filters: [/* conditions */], // Filter available options + }, + + // Select options + options: [ + { label: 'Display', value: 'stored_value', color: '#hex' } + ], + + // Formula configuration + formula: 'price * quantity', // Excel-like formula syntax + + // Security + encrypted: false, // Field-level encryption + masked: false, // PII masking +} +``` + +**Example: Order Item with Lookup** + +```typescript +fields: { + product_id: { + type: 'lookup', + label: 'Product', + required: true, + reference: { + object: 'product', + displayField: 'name', + }, + }, + quantity: { + type: 'number', + label: 'Quantity', + required: true, + defaultValue: 1, + }, + unit_price: { + type: 'currency', + label: 'Unit Price', + }, + total: { + type: 'formula', + label: 'Total', + formula: 'quantity * unit_price', + }, +} +``` + +--- + +### 1.3 Validation Rules (`packages/spec/src/data/validation.zod.ts`) + +**CRITICAL RULES:** + +- **Use Formulas**: Business logic MUST be expressed as formula strings, NOT JavaScript functions +- **Formula Syntax**: Excel-like syntax (e.g., `price > 0`, `discount_rate <= 50`) +- **Field References**: Use field names directly in formulas +- **Error Messages**: Clear, actionable messages for users + +**Validation Schema:** + +```typescript +validation: { + name: 'validation_rule_name', // snake_case identifier + errorMessage: 'Error description', // User-facing message + formula: 'condition_expression', // Excel-like formula + level: 'error', // 'error' or 'warning' +} +``` + +**Common Validation Patterns:** + +```typescript +// Range validation +{ + name: 'positive_price', + formula: 'price > 0', + errorMessage: 'Price must be greater than 0', +} + +// Percentage limit +{ + name: 'max_discount', + formula: 'discount_rate <= 50', + errorMessage: 'Discount cannot exceed 50%', +} + +// Date comparison +{ + name: 'end_after_start', + formula: 'end_date > start_date', + errorMessage: 'End date must be after start date', +} + +// Required if condition +{ + name: 'require_approval_if_large', + formula: 'IF(amount > 10000, approved_by != NULL, true)', + errorMessage: 'Orders over $10,000 require approval', +} + +// Cross-field validation +{ + name: 'valid_email_if_contact', + formula: 'IF(contact_method == "email", email != NULL, true)', + errorMessage: 'Email required when contact method is email', +} +``` + +--- + +### 1.4 Query & Filters (`packages/spec/src/data/query.zod.ts`) + +**CRITICAL RULES:** + +- **Type-safe Filters**: Use proper operators for each field type +- **Relationship Queries**: Support dot notation for related objects +- **Performance**: Always consider index usage + +**Query Structure:** + +```typescript +{ + object: 'object_name', + fields: ['field1', 'field2', 'related.field'], + filters: [ + { field: 'status', operator: 'equals', value: 'active' }, + { field: 'created_at', operator: 'greaterThan', value: '2024-01-01' }, + ], + sort: [{ field: 'name', order: 'asc' }], + limit: 100, + offset: 0, +} +``` + +**Filter Operators by Type:** + +```typescript +// Text fields +'equals', 'notEquals', 'contains', 'startsWith', 'endsWith', 'in', 'notIn' + +// Number fields +'equals', 'notEquals', 'greaterThan', 'lessThan', 'greaterOrEqual', 'lessOrEqual', 'between' + +// Date fields +'equals', 'greaterThan', 'lessThan', 'between', 'today', 'thisWeek', 'thisMonth' + +// Boolean fields +'equals', 'notEquals' + +// Lookup fields (use relationship queries) +'equals', 'notEquals', 'in', 'notIn' +``` + +--- + +### 1.5 Hooks & Automation (`packages/spec/src/data/hook.zod.ts`) + +**CRITICAL RULES:** + +- **Use Sparingly**: Only for complex backend logic (API calls, cascade updates) +- **Simple Logic**: Use validation/formulas for simple business rules +- **Type Safety**: Hooks must be TypeScript functions with proper types +- **Context Access**: Use provided context for record data and services + +**Hook Types:** + +```typescript +'before_create' // Modify record before insert +'after_create' // Side effects after insert +'before_update' // Modify record before update +'after_update' // Side effects after update +'before_delete' // Prevent deletion or cleanup +'after_delete' // Cleanup after deletion +``` + +**Hook Schema:** + +```typescript +import { Hook } from '@objectstack/spec'; + +export const OrderHooks: Hook[] = [ + { + type: 'after_create', + handler: async (context) => { + // Access record data + const order = context.record; + const email = order.customer_email; + + // Access services via DI + const emailService = context.services.get('email'); + + // Perform side effect + await emailService.send({ + to: email, + subject: 'Order Confirmation', + template: 'order-confirmation', + data: order, + }); + }, + }, + { + type: 'before_update', + handler: async (context) => { + const { record, oldRecord } = context; + + // Business logic: recalculate tax when amount changes + if (record.amount !== oldRecord.amount) { + record.tax = record.amount * 0.1; + } + + return record; // Return modified record + }, + }, +]; +``` + +**When to Use Hooks vs. Formulas:** + +| Scenario | Use Formula | Use Hook | +|----------|-------------|----------| +| Calculate total from price Γ— quantity | βœ… | ❌ | +| Validate discount <= 50% | βœ… | ❌ | +| Send email on order creation | ❌ | βœ… | +| Call external API for shipping rate | ❌ | βœ… | +| Update related records (cascade) | ❌ | βœ… | +| Complex multi-step workflow | ❌ | βœ… | + +--- + +## πŸ—οΈ Relationship Patterns + +### One-to-Many (Lookup) + +**Use Case**: Order β†’ Customer (many orders belong to one customer) + +```typescript +// In Order object +fields: { + customer_id: { + type: 'lookup', + label: 'Customer', + reference: { + object: 'customer', + displayField: 'name', + }, + }, +} +``` + +### Many-to-Many (Multiple Lookup) + +**Use Case**: Project β†’ Team Members (project has many members, member in many projects) + +```typescript +// In Project object +fields: { + team_members: { + type: 'lookup', + label: 'Team Members', + multiple: true, // Enable many-to-many + reference: { + object: 'user', + displayField: 'full_name', + }, + }, +} +``` + +### Parent-Child (Master-Detail) + +**Use Case**: Order β†’ Order Items (cascade delete, rollup summaries) + +```typescript +// In OrderItem object +fields: { + order_id: { + type: 'master_detail', // Creates parent-child relationship + label: 'Order', + reference: { + object: 'order', + displayField: 'order_number', + }, + }, +} + +// In Order object (rollup summary) +fields: { + total_amount: { + type: 'summary', + label: 'Total Amount', + summaryType: 'sum', + summarizedObject: 'order_item', + summarizedField: 'total', + }, +} +``` + +### Hierarchical (Tree) + +**Use Case**: Categories with subcategories, organizational hierarchy + +```typescript +fields: { + parent_category: { + type: 'tree', + label: 'Parent Category', + reference: { + object: 'category', // Self-reference + displayField: 'name', + }, + }, +} +``` + +--- + +## 🎨 Code Generation Patterns + +### Pattern 1: Simple CRUD Object + +**User Request**: "Create a simple product catalog" + +**Generated Code**: + +```typescript +// File: src/domains/catalog/product.object.ts +import { ServiceObject } from '@objectstack/spec'; + +export const Product: ServiceObject = { + name: 'product', + label: 'Product', + description: 'Product catalog items', + fields: { + name: { + type: 'text', + label: 'Product Name', + required: true, + maxLength: 255, + }, + sku: { + type: 'text', + label: 'SKU', + unique: true, + maxLength: 50, + }, + description: { + type: 'textarea', + label: 'Description', + }, + price: { + type: 'currency', + label: 'Price', + required: true, + }, + in_stock: { + type: 'boolean', + label: 'In Stock', + defaultValue: true, + }, + }, + enable: { + searchable: true, + apiEnabled: true, + }, + indexes: [ + { fields: ['sku'], unique: true }, + { fields: ['name'], type: 'fulltext' }, + ], +}; +``` + +### Pattern 2: Inventory with Relationships + +**User Request**: "I want inventory management with products and warehouses" + +**Generated Files**: + +```typescript +// File: src/domains/inventory/warehouse.object.ts +export const Warehouse: ServiceObject = { + name: 'warehouse', + label: 'Warehouse', + description: 'Physical storage locations', + fields: { + name: { + type: 'text', + label: 'Warehouse Name', + required: true, + unique: true, + }, + location: { + type: 'address', + label: 'Address', + }, + capacity: { + type: 'number', + label: 'Maximum Capacity', + }, + }, + enable: { + searchable: true, + apiEnabled: true, + }, +}; + +// File: src/domains/inventory/product.object.ts +export const Product: ServiceObject = { + name: 'product', + label: 'Product', + fields: { + name: { + type: 'text', + label: 'Product Name', + required: true, + }, + sku: { + type: 'text', + label: 'SKU', + unique: true, + }, + warehouse_id: { + type: 'lookup', + label: 'Warehouse', + reference: { + object: 'warehouse', + displayField: 'name', + }, + }, + quantity: { + type: 'number', + label: 'Current Stock', + defaultValue: 0, + }, + price: { + type: 'currency', + label: 'Unit Price', + }, + }, + validation: { + name: 'positive_price', + formula: 'price > 0', + errorMessage: 'Price must be greater than 0', + }, + enable: { + searchable: true, + apiEnabled: true, + }, +}; +``` + +### Pattern 3: Order Management with Master-Detail + +**User Request**: "Create an order system with line items" + +**Generated Files**: + +```typescript +// File: src/domains/sales/order.object.ts +export const Order: ServiceObject = { + name: 'order', + label: 'Order', + fields: { + order_number: { + type: 'autonumber', + label: 'Order Number', + format: 'ORD-{0000}', + }, + customer_id: { + type: 'lookup', + label: 'Customer', + required: true, + reference: { + object: 'customer', + displayField: 'name', + }, + }, + order_date: { + type: 'date', + label: 'Order Date', + defaultValue: 'TODAY()', + }, + status: { + type: 'select', + label: 'Status', + options: [ + { label: 'Draft', value: 'draft', default: true }, + { label: 'Confirmed', value: 'confirmed' }, + { label: 'Shipped', value: 'shipped' }, + { label: 'Delivered', value: 'delivered' }, + ], + }, + total_amount: { + type: 'summary', + label: 'Total Amount', + summaryType: 'sum', + summarizedObject: 'order_item', + summarizedField: 'line_total', + }, + }, + enable: { + searchable: true, + apiEnabled: true, + trackHistory: true, + }, +}; + +// File: src/domains/sales/order_item.object.ts +export const OrderItem: ServiceObject = { + name: 'order_item', + label: 'Order Item', + fields: { + order_id: { + type: 'master_detail', + label: 'Order', + required: true, + reference: { + object: 'order', + displayField: 'order_number', + }, + }, + product_id: { + type: 'lookup', + label: 'Product', + required: true, + reference: { + object: 'product', + displayField: 'name', + }, + }, + quantity: { + type: 'number', + label: 'Quantity', + required: true, + defaultValue: 1, + }, + unit_price: { + type: 'currency', + label: 'Unit Price', + required: true, + }, + line_total: { + type: 'formula', + label: 'Line Total', + formula: 'quantity * unit_price', + }, + }, + validation: { + name: 'positive_quantity', + formula: 'quantity > 0', + errorMessage: 'Quantity must be at least 1', + }, +}; +``` + +--- + +## 🚨 Common Mistakes to Avoid + +### ❌ WRONG: Using JavaScript in formulas + +```typescript +validation: { + formula: 'return price > 0 && price < 1000;', // NO! JavaScript syntax +} +``` + +### βœ… CORRECT: Using Excel-like formula syntax + +```typescript +validation: { + formula: 'AND(price > 0, price < 1000)', // YES! Excel syntax +} +``` + +--- + +### ❌ WRONG: Mixed case in field names + +```typescript +fields: { + firstName: { /* ... */ }, // NO! camelCase + Last_Name: { /* ... */ }, // NO! mixed case +} +``` + +### βœ… CORRECT: snake_case for field names + +```typescript +fields: { + first_name: { /* ... */ }, // YES! + last_name: { /* ... */ }, // YES! +} +``` + +--- + +### ❌ WRONG: camelCase in option values + +```typescript +options: [ + { label: 'New', value: 'New' }, // NO! uppercase + { label: 'In Progress', value: 'InProgress' }, // NO! camelCase +] +``` + +### βœ… CORRECT: lowercase snake_case in option values + +```typescript +options: [ + { label: 'New', value: 'new' }, // YES! + { label: 'In Progress', value: 'in_progress' }, // YES! +] +``` + +--- + +### ❌ WRONG: Using hooks for simple calculations + +```typescript +{ + type: 'before_create', + handler: async (context) => { + context.record.total = context.record.price * context.record.quantity; + } +} +``` + +### βœ… CORRECT: Using formula fields for calculations + +```typescript +fields: { + total: { + type: 'formula', + formula: 'price * quantity', + } +} +``` + +--- + +### ❌ WRONG: Forgetting relationship object dependency + +```typescript +// Generated only Order with lookup to Customer +// But Customer object doesn't exist yet! +``` + +### βœ… CORRECT: Generate dependencies first + +```typescript +// 1. First generate Customer object +// 2. Then generate Order object with lookup +// Or generate both in correct order +``` + +--- + +## πŸ“ File Organization + +### Standard Directory Structure + +``` +packages/app/src/ +β”œβ”€β”€ domains/ +β”‚ β”œβ”€β”€ sales/ # Domain: Sales +β”‚ β”‚ β”œβ”€β”€ customer.object.ts +β”‚ β”‚ β”œβ”€β”€ order.object.ts +β”‚ β”‚ β”œβ”€β”€ order_item.object.ts +β”‚ β”‚ └── sales.hooks.ts +β”‚ β”œβ”€β”€ inventory/ # Domain: Inventory +β”‚ β”‚ β”œβ”€β”€ product.object.ts +β”‚ β”‚ β”œβ”€β”€ warehouse.object.ts +β”‚ β”‚ └── inventory.hooks.ts +β”‚ └── finance/ # Domain: Finance +β”‚ β”œβ”€β”€ invoice.object.ts +β”‚ └── payment.object.ts +└── index.ts # Central export +``` + +### File Naming Convention + +- **Objects**: `{object_name}.object.ts` (e.g., `customer.object.ts`) +- **Hooks**: `{domain}.hooks.ts` (e.g., `sales.hooks.ts`) +- **Views**: `{object_name}.view.ts` (e.g., `customer.view.ts`) +- **Apps**: `{app_name}.app.ts` (e.g., `crm.app.ts`) + +--- + +## πŸ”„ Iteration & Self-Correction + +### Error Detection Patterns + +When you generate code, validate it against these patterns: + +1. **Schema Validation**: Does it pass Zod schema validation? +2. **Naming Convention**: Are all identifiers using correct case? +3. **Dependency Order**: Are referenced objects defined first? +4. **Type Consistency**: Do field types match their configurations? +5. **Relationship Integrity**: Do lookup references point to existing objects? + +### Self-Correction Example + +**Detected Error**: Generated lookup to non-existent object + +```typescript +// ❌ Error detected +fields: { + customer_id: { + type: 'lookup', + reference: { object: 'customer' } // Customer object not generated! + } +} +``` + +**Self-Correction**: +```typescript +// βœ… Action: Generate Customer object first +// Step 1: Create customer.object.ts +export const Customer: ServiceObject = { /* ... */ }; + +// Step 2: Then create order with lookup +fields: { + customer_id: { + type: 'lookup', + reference: { object: 'customer' } + } +} +``` + +--- + +## 🎯 Output Format + +When generating code, always output in this format: + +```typescript +/** + * [Object Name] - [Brief Description] + * + * @domain [Domain Name] + * @generated_by AI Builder + * @date [YYYY-MM-DD] + */ +import { ServiceObject } from '@objectstack/spec'; + +export const [ObjectName]: ServiceObject = { + // ... object definition +}; +``` + +Include file path comment: +``` +// File: packages/app/src/domains/[domain]/[object_name].object.ts +``` + +--- + +## 🧠 Knowledge Base Integration + +You have access to: + +1. **Protocol Specifications**: Full Zod schemas in `packages/spec/src/` +2. **Example Applications**: Reference implementations in `examples/` +3. **Architecture Guide**: System design in `ARCHITECTURE.md` +4. **Quick Reference**: Protocol lookup in `QUICK-REFERENCE.md` + +Use these resources to: +- Verify field type capabilities +- Check validation syntax +- Learn relationship patterns +- Understand system constraints + +--- + +## βœ… Quality Checklist + +Before outputting generated code, verify: + +- [ ] All field names are `snake_case` +- [ ] All property keys are `camelCase` +- [ ] Formula syntax is Excel-like, not JavaScript +- [ ] Lookup references point to defined objects +- [ ] Option values are lowercase +- [ ] Required fields have appropriate validation +- [ ] Hooks are only used for complex logic +- [ ] File names follow convention +- [ ] Code includes proper imports +- [ ] Documentation comments are present + +--- + +## πŸš€ Quick Commands + +When user provides requirements, identify the pattern: + +- **"Simple CRUD"** β†’ Generate single object with basic fields +- **"With relationships"** β†’ Generate multiple objects with lookups +- **"Master-detail"** β†’ Generate parent + child with master_detail +- **"Inventory system"** β†’ Product + Warehouse + lookup +- **"Order management"** β†’ Order + OrderItem + Customer +- **"Need workflow"** β†’ Add hooks for business logic +- **"Need approval"** β†’ Add workflow with approval steps + +--- + +## πŸ“ Summary + +**You are a code generator that:** + +1. βœ… Generates valid TypeScript configuration files +2. βœ… Follows ObjectStack P0 specifications exactly +3. βœ… Uses proper naming conventions (snake_case/camelCase) +4. βœ… Creates relationships correctly (lookup/master_detail) +5. βœ… Writes formulas in Excel syntax, not JavaScript +6. βœ… Minimizes hook usage, prefers declarative config +7. βœ… Self-validates against Zod schemas +8. βœ… Organizes code by domain +9. βœ… Documents generated code clearly +10. βœ… Detects and corrects errors proactively + +**You are NOT:** + +- ❌ A JavaScript function generator +- ❌ A general-purpose coding assistant +- ❌ Someone who breaks naming conventions +- ❌ Someone who ignores the protocol specifications + +--- + +**Remember**: Your output is metadata configuration, not application code. The ObjectStack runtime handles all the complex logic. You just need to generate clean, valid configuration files that describe what the application should do. diff --git a/AI_BUILDER_README.md b/AI_BUILDER_README.md new file mode 100644 index 00000000000..72354d4c187 --- /dev/null +++ b/AI_BUILDER_README.md @@ -0,0 +1,267 @@ +# ObjectStack Builder: AI-Driven Development System + +> **Status**: Planning & Design Phase +> **Version**: 1.0.0 +> **Last Updated**: 2026-01-31 + +## Overview + +The **ObjectStack Builder** is an AI-powered development system that automates the creation, iteration, and deployment of ObjectStack applications through intelligent metadata generation. By leveraging strict P0 protocol specifications, the system transforms natural language requirements into validated TypeScript configurations. + +## Architecture + +``` +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ Architect │───▢│ DevOps │───▢│ Runtime β”‚ +β”‚ Agent β”‚ β”‚ Runner β”‚ β”‚ Engine β”‚ +β”‚ (Brain) β”‚ β”‚(Hands/Feet) β”‚ β”‚ (Body) β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ β”‚ β”‚ + β–Ό β–Ό β–Ό + Generate GitHub API ObjectStack + Metadata Vercel API Framework +``` + +### Three Core Components + +1. **Architect Agent (Brain)** + - Understands natural language requirements + - Generates valid metadata configurations + - Follows P0 specifications strictly + - Self-validates against Zod schemas + +2. **DevOps Runner (Hands/Feet)** + - Automates Git operations (branches, commits, PRs) + - Monitors deployment status (Vercel/GitHub Actions) + - Implements self-healing on errors + +3. **Runtime Engine (Body)** + - Parses and validates metadata + - Renders UI from configurations + - Generates APIs automatically + - Executes business logic + +## Key Features + +### ✨ Natural Language to Code + +Describe what you want in plain English: + +``` +User: "Create an inventory system with products and warehouses" + +AI Builder: Generated 2 objects with lookup relationship βœ… +- warehouse.object.ts +- product.object.ts (with warehouse_id lookup) +``` + +### πŸ”„ Automated Workflow + +- **Branch Creation**: Automatic feature branches +- **Git Commits**: Conventional commit messages +- **Pull Requests**: Comprehensive PR descriptions +- **CI/CD Integration**: Triggers deployment automatically + +### πŸ”§ Self-Healing Deployments + +When deployments fail, the system: +1. Reads error logs +2. Categorizes the issue +3. Generates a fix +4. Re-deploys automatically +5. Notifies on persistent failures + +### βœ… Protocol Compliance + +Strictly follows ObjectStack P0 specifications: +- **Object names**: `snake_case` +- **Field names**: `snake_case` +- **Property keys**: `camelCase` +- **Formula syntax**: Excel-like (not JavaScript) +- **Validation**: Zod schema compliance + +## Development Roadmap + +### V1: Read-Only Mode (Weeks 1-4) +- Repository analysis +- Documentation Q&A +- Relationship discovery +- **Goal**: Validate AI understands protocols + +### V2: Configuration Generator (Weeks 5-8) +- Metadata generation +- Code block output +- Manual copy-paste workflow +- **Goal**: Generate valid code + +### V3: Git Integration (Weeks 9-12) +- Automated PR creation +- Branch management +- CI/CD integration +- **Goal**: Automate deployment workflow + +### V4: Self-Healing (Weeks 13-16) +- Error detection +- Auto-fix generation +- Retry mechanisms +- **Goal**: Autonomous iteration + +## Getting Started + +### For Developers + +1. **Read the AI Builder Prompt** + - Location: `.github/prompts/ai-builder.prompt.md` + - Understand P0 specifications + - Learn coding patterns + +2. **Review Examples** + - Simple CRUD objects + - Relationship patterns + - Validation rules + - Hook implementations + +3. **Understand Protocols** + - Object Definition: `packages/spec/src/data/object.zod.ts` + - Field Types: `packages/spec/src/data/field.zod.ts` + - Validation: `packages/spec/src/data/validation.zod.ts` + - Hooks: `packages/spec/src/data/hook.zod.ts` + +### For AI Agents + +The AI Builder Prompt provides comprehensive guidance: + +- **P0 Protocol Specifications** - All core rules +- **Field Type Catalog** - 45+ available types +- **Relationship Patterns** - lookup, master-detail, tree +- **Validation Syntax** - Excel-like formulas +- **Common Mistakes** - What to avoid +- **Code Templates** - Standard patterns + +## Documentation + +- **[Builder Workflow](./content/docs/ai/builder-workflow.mdx)** - Development lifecycle +- **[Technical Specification](./content/docs/ai/technical-specification.mdx)** - Detailed architecture (Coming soon) +- **[AI Builder Prompt](./.github/prompts/ai-builder.prompt.md)** - Agent configuration +- **[Architecture Guide](./ARCHITECTURE.md)** - System overview + +## Examples + +### Simple Product Catalog + +**Input**: "Create a product catalog" + +**Output**: +```typescript +export const Product: ServiceObject = { + name: 'product', + label: 'Product', + fields: { + name: { type: 'text', required: true }, + sku: { type: 'text', unique: true }, + price: { type: 'currency' }, + in_stock: { type: 'boolean', defaultValue: true } + }, + enable: { + searchable: true, + apiEnabled: true + } +}; +``` + +### Order with Line Items + +**Input**: "Order system with customer and line items" + +**Output**: Generates 3 objects: +1. `customer.object.ts` - Base customer data +2. `order.object.ts` - Order with customer lookup +3. `order_item.object.ts` - Line items with master-detail + +## Protocol Quick Reference + +### Object Names +- βœ… `customer_order` +- βœ… `product_category` +- ❌ `CustomerOrder` (PascalCase) +- ❌ `customer-order` (kebab-case) + +### Field Names +- βœ… `first_name` +- βœ… `order_total` +- ❌ `firstName` (camelCase) +- ❌ `OrderTotal` (PascalCase) + +### Property Keys +- βœ… `maxLength` +- βœ… `defaultValue` +- ❌ `max_length` (snake_case) +- ❌ `MaxLength` (PascalCase) + +### Formula Syntax +- βœ… `price > 0` +- βœ… `AND(active == true, end_date > TODAY())` +- ❌ `return price > 0;` (JavaScript) +- ❌ `price > 0 ? true : false` (Ternary operator) + +## Best Practices + +### For AI Agents + +1. **Generate dependencies first** - Create referenced objects before lookups +2. **Use formulas for simple logic** - Reserve hooks for complex operations +3. **Validate rigorously** - Check against all Zod schemas +4. **Follow naming conventions** - snake_case/camelCase strictly +5. **Self-document** - Include clear descriptions and comments + +### For Developers + +1. **Review AI-generated PRs** - Always require human approval +2. **Test thoroughly** - Validate business logic works correctly +3. **Provide feedback** - Help AI learn from mistakes +4. **Monitor metrics** - Track success rates and error patterns +5. **Update knowledge base** - Add new patterns as learned + +## Security Considerations + +- **Code Review Required**: Never auto-merge to main +- **Secret Scanning**: Check for hardcoded credentials +- **Branch Protection**: Enforce protection rules +- **API Token Security**: Use GitHub Apps, rotate regularly +- **Webhook Verification**: Validate all webhook signatures + +## Contributing + +We welcome contributions to improve the ObjectStack Builder: + +1. **Enhance Prompts**: Improve AI agent instructions +2. **Add Patterns**: Document new code generation patterns +3. **Fix Errors**: Improve error detection and fixing +4. **Update Docs**: Keep documentation current +5. **Share Learnings**: Document what works well + +## Support + +- **Documentation**: [https://docs.objectstack.ai](https://docs.objectstack.ai) +- **GitHub Issues**: [Report bugs or request features](https://github.com/objectstack-ai/spec/issues) +- **Discord**: Join our community for discussions + +## License + +The ObjectStack Builder is part of the ObjectStack Protocol specification. + +- **License**: Apache 2.0 +- **Copyright**: Β© 2026 ObjectStack + +--- + +**Next Steps:** + +1. Read the [AI Builder Prompt](./.github/prompts/ai-builder.prompt.md) +2. Review the [Builder Workflow](./content/docs/ai/builder-workflow.mdx) +3. Explore [example applications](./examples/) +4. Start with V1 (Read-Only Mode) implementation + +--- + +Built with ❀️ by the ObjectStack Team From 4fd64da9a236c7b530acab92f60f6fbf31be41ff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 19:26:24 +0000 Subject: [PATCH 3/5] docs(ai): Add AI Builder workflow and index documentation Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> --- content/docs/ai/builder-workflow.mdx | 195 +++++++++++++++++++++++++++ content/docs/ai/index.mdx | 42 ++++++ content/docs/ai/meta.json | 4 + 3 files changed, 241 insertions(+) create mode 100644 content/docs/ai/builder-workflow.mdx create mode 100644 content/docs/ai/index.mdx create mode 100644 content/docs/ai/meta.json diff --git a/content/docs/ai/builder-workflow.mdx b/content/docs/ai/builder-workflow.mdx new file mode 100644 index 00000000000..53ca55bce41 --- /dev/null +++ b/content/docs/ai/builder-workflow.mdx @@ -0,0 +1,195 @@ +--- +title: 'ObjectStack Builder Workflow' +description: 'AI-driven development workflow for automated metadata generation and deployment' +--- + +# ObjectStack Builder Workflow + +The **ObjectStack Builder** is an AI-driven system that enables autonomous application development through metadata generation, Git integration, and automated deployment. + +## Architecture Overview + +The system consists of three core components: + +``` +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ ObjectStack Builder β”‚ +β”‚ β”‚ +β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ +β”‚ β”‚ Architect β”‚ β”‚ DevOps β”‚ β”‚ Runtime β”‚ β”‚ +β”‚ β”‚ Agent β”‚ β”‚ Runner β”‚ β”‚ Engine β”‚ β”‚ +β”‚ β”‚ (Brain) β”‚ β”‚ (Hands/Feet) β”‚ β”‚ (Body) β”‚ β”‚ +β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ +β”‚ β”‚ β”‚ β”‚ β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ β”‚ β”‚ + β–Ό β–Ό β–Ό + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” οΏ½β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚ Generate β”‚ β”‚ GitHub β”‚ β”‚ ObjectStack β”‚ + β”‚ Metadata β”‚ β”‚ Vercel β”‚ β”‚ Framework β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` + +### Component Responsibilities + +#### 1. Architect Agent (Brain) +**Purpose**: Understand requirements and generate metadata configurations + +**Capabilities**: +- Parse natural language into structured operations +- Generate valid TypeScript/JSON configurations +- Follow P0 specifications strictly +- Self-validate against Zod schemas +- Detect and correct errors + +**Knowledge Base**: +- Complete P0 protocol specifications +- Field type catalog (45+ types) +- Relationship patterns (lookup, master-detail, tree) +- Validation formula syntax +- Hook implementation guidelines + +#### 2. DevOps Runner (Hands/Feet) +**Purpose**: Automate Git operations and deployment monitoring + +**Capabilities**: +- Create feature branches +- Commit generated code +- Create pull requests +- Monitor build status +- Read deployment logs +- Trigger self-healing on errors + +**Integrations**: +- GitHub API (Octokit) +- Vercel API +- CI/CD webhooks + +#### 3. Runtime Engine (Body) +**Purpose**: Execute and render the metadata + +**Capabilities**: +- Parse metadata files +- Validate against schemas +- Generate database migrations +- Render UI components +- Execute business logic +- Provide APIs + +**Components**: +- `@objectstack/spec` - Schema definitions +- `@objectstack/core` - Runtime kernel +- `@objectstack/engine` - Metadata executor + +--- + +## Development Roadmap + +### Version 1: Read-Only Mode (Repository Analysis) + +**Purpose**: Validate Agent understands ObjectStack specifications + +**Capabilities**: +- Read GitHub repository via API +- Parse existing metadata files +- Answer questions about current system +- Generate documentation + +**Example Queries**: +- "What objects are currently defined?" +- "What fields does the Customer object have?" +- "Show me all lookup relationships" +- "Which objects have validation rules?" + +**Success Criteria**: +- βœ… Can read and parse all object files +- βœ… Correctly identifies all relationships +- βœ… Answers questions with 95%+ accuracy +- βœ… Generates accurate documentation + +--- + +### Version 2: Configuration Generator (Code Blocks) + +**Purpose**: Generate valid metadata without Git integration + +**Capabilities**: +- Accept natural language requirements +- Generate valid TypeScript configurations +- Output code blocks for manual copy-paste +- Provide validation feedback + +**Success Criteria**: +- βœ… Generated code passes TypeScript compilation +- βœ… Generated code passes Zod validation +- βœ… Follows naming conventions 100% +- βœ… Dependencies generated in correct order + +--- + +### Version 3: Git Integration (Automated PRs) + +**Purpose**: Automatically commit and create pull requests + +**Capabilities**: +- Create feature branches +- Commit generated files +- Create pull requests +- Add descriptive PR descriptions +- Link related issues + +**Git Ops Best Practices**: + +1. **Branch Naming**: `ai/feature-name` or `ai-update-{timestamp}` +2. **Commit Messages**: Follow conventional commits + - `feat(domain): add object definition` + - `fix(validation): correct formula syntax` + - `refactor(structure): reorganize files` +3. **PR Labels**: `ai-generated`, `needs-review`, `auto-deploy` +4. **Never push to main**: Always create PR for review + +**Success Criteria**: +- βœ… Branches created successfully +- βœ… Files committed in dependency order +- βœ… PRs contain comprehensive descriptions +- βœ… CI/CD pipeline triggered correctly + +--- + +### Version 4: Self-Healing (Error Recovery) + +**Purpose**: Automatically detect and fix deployment errors + +**Capabilities**: +- Monitor Vercel deployment status +- Read build and runtime logs +- Diagnose common errors +- Generate fixes +- Re-deploy automatically +- Notify on persistent failures + +**Architecture**: + +``` +GitHub Push β†’ Vercel Build Triggered + β”‚ + β”œβ”€> SUCCESS βœ… β†’ Merge PR β†’ Deploy to production + β”‚ + └─> ERROR ❌ β†’ Read Logs β†’ Diagnose Issue β†’ Generate Fix β†’ Re-deploy +``` + +**Success Criteria**: +- βœ… Detects 90%+ of common errors +- βœ… Successfully fixes 70%+ of detected errors +- βœ… Max 3 retry attempts before escalation +- βœ… Notifies human on persistent failures +- βœ… Maintains error history for learning + +--- + +## Resources + +- [AI Builder Prompt](https://github.com/objectstack-ai/spec/blob/main/.github/prompts/ai-builder.prompt.md) +- [Technical Specification](./technical-specification.mdx) +- [P0 Specifications](../../../packages/spec/src/) +- [Architecture Guide](../../../ARCHITECTURE.md) diff --git a/content/docs/ai/index.mdx b/content/docs/ai/index.mdx new file mode 100644 index 00000000000..0ef15a183f6 --- /dev/null +++ b/content/docs/ai/index.mdx @@ -0,0 +1,42 @@ +--- +title: 'AI & Automation' +description: 'AI-driven development, agents, and automation systems for ObjectStack' +--- + +# AI & Automation + +ObjectStack provides comprehensive AI and automation capabilities to accelerate development and enable intelligent applications. + +## ObjectStack Builder + +The **ObjectStack Builder** is an AI-driven system that automates application development through metadata generation. + +### Key Features + +- **Natural Language to Code**: Describe requirements in plain language, get valid metadata +- **Automated Git Workflow**: Automatic branch creation, commits, and pull requests +- **Self-Healing Deployments**: Detect and fix deployment errors automatically +- **Protocol Compliance**: Strict adherence to P0 specifications + +### Learn More + +- [Builder Workflow](./builder-workflow) - Development lifecycle and automation +- [Technical Specification](./technical-specification) - Detailed architecture and implementation + +## AI Protocol + +ObjectStack includes native AI capabilities for building intelligent applications: + +- **Agent System**: Define autonomous agents with tools and knowledge bases +- **RAG Pipeline**: Retrieval-augmented generation for context-aware AI +- **Model Registry**: Manage and route between multiple LLM providers +- **Conversation Management**: Track and manage multi-turn conversations + +See the [AI Protocol Reference](../references/ai) for complete specifications. + +--- + +**Next Steps**: +- Review the [Builder Workflow](./builder-workflow) to understand the development process +- Check the [AI Builder Prompt](https://github.com/objectstack-ai/spec/blob/main/.github/prompts/ai-builder.prompt.md) for AI agent configuration +- Explore [AI Protocol examples](../../../examples/ai-sales) for reference implementations diff --git a/content/docs/ai/meta.json b/content/docs/ai/meta.json new file mode 100644 index 00000000000..16b4581cdbf --- /dev/null +++ b/content/docs/ai/meta.json @@ -0,0 +1,4 @@ +{ + "title": "AI & Automation", + "description": "AI-driven development and automation systems" +} From be417213bd0d75978ad4acfcf2a9d6d8e1ad7f91 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 19:27:26 +0000 Subject: [PATCH 4/5] docs: Integrate AI Builder into documentation navigation - Add AI section to docs meta.json - Add AI card to main documentation index - Update prompts README with AI Builder entry - Enable Bot icon for AI documentation Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> --- .github/prompts/README.md | 22 +++++++++++++++++++--- content/docs/index.mdx | 8 +++++++- content/docs/meta.json | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/prompts/README.md b/.github/prompts/README.md index 997a8bc1c9b..3816c4f3deb 100644 --- a/.github/prompts/README.md +++ b/.github/prompts/README.md @@ -97,7 +97,23 @@ These prompts help define the core ObjectStack protocols: These prompts help with specific development tasks: -#### 6. [Testing Engineer](./testing-engineer.prompt.md) +#### 6. [AI Builder](./ai-builder.prompt.md) +**Focus:** AI-driven automated metadata generation +**Key Responsibilities:** +- Natural language to metadata conversion +- P0 protocol specification adherence +- Object and field generation +- Relationship pattern implementation +- Validation rule creation +- Hook implementation guidance +- Code quality and naming conventions +- Self-validation and error detection + +**Use When:** Building AI agents for automated development, generating metadata from requirements, or implementing the ObjectStack Builder system + +--- + +#### 7. [Testing Engineer](./testing-engineer.prompt.md) **Focus:** Comprehensive test coverage for all protocols **Key Responsibilities:** - Schema validation tests @@ -112,7 +128,7 @@ These prompts help with specific development tasks: --- -#### 7. [Documentation Writer](./documentation-writer.prompt.md) +#### 8. [Documentation Writer](./documentation-writer.prompt.md) **Focus:** Clear, comprehensive documentation **Key Responsibilities:** - TSDoc comments @@ -126,7 +142,7 @@ These prompts help with specific development tasks: --- -#### 8. [Example Creator](./example-creator.prompt.md) +#### 9. [Example Creator](./example-creator.prompt.md) **Focus:** Realistic, runnable examples **Key Responsibilities:** - Full application examples (CRM, Todo, etc.) diff --git a/content/docs/index.mdx b/content/docs/index.mdx index 18a84c58bd0..4f023e244a6 100644 --- a/content/docs/index.mdx +++ b/content/docs/index.mdx @@ -3,7 +3,7 @@ title: Welcome to ObjectStack description: The Metadata-Driven Protocol for the Post-SaaS Era. --- -import { Book, Compass, FileText, Layers, Database, Layout, Cpu, Code2 } from 'lucide-react'; +import { Book, Compass, FileText, Layers, Database, Layout, Cpu, Code2, Bot } from 'lucide-react'; **ObjectStack** is not just a framework; it is a **Protocol** for building enterprise software. It decouples the *Business Intent* (defined in JSON/YAML) from the *Technical Execution* (handled by the Kernel). @@ -44,6 +44,12 @@ ObjectStack is built on three foundational protocols that work together as a uni href="/docs/introduction" description="Understand the philosophy: 'Intent over Implementation' and Metadata-Driven Architecture." /> + } + title="AI & Automation" + href="/docs/ai" + description="AI-driven development with the ObjectStack Builder. Automated metadata generation and deployment." + /> } title="Developers" diff --git a/content/docs/meta.json b/content/docs/meta.json index 750464429c6..580554cce2a 100644 --- a/content/docs/meta.json +++ b/content/docs/meta.json @@ -5,6 +5,7 @@ "objectql", "objectui", "objectos", + "ai", "developers", "---", "references" From a805396c7850177159f5dd033dcfc8d8f4c51b7e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 19:29:14 +0000 Subject: [PATCH 5/5] docs: Add implementation summary for ObjectStack Builder Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> --- IMPLEMENTATION_SUMMARY.md | 318 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) create mode 100644 IMPLEMENTATION_SUMMARY.md diff --git a/IMPLEMENTATION_SUMMARY.md b/IMPLEMENTATION_SUMMARY.md new file mode 100644 index 00000000000..468e4f055d7 --- /dev/null +++ b/IMPLEMENTATION_SUMMARY.md @@ -0,0 +1,318 @@ +# ObjectStack Builder - Implementation Summary + +**Date:** 2026-01-31 +**PR:** AI-Driven Metadata Development System +**Status:** Documentation Complete + +## Overview + +This implementation provides comprehensive documentation and architectural design for the **ObjectStack Builder** - an AI-driven system that automates ObjectStack application development through intelligent metadata generation. + +## Problem Statement + +The original Chinese problem statement requested: +1. A detailed technical plan for an AI Agent architecture +2. Development roadmap for implementing self-iterating software +3. System prompts to teach AI agents the P0 specifications +4. Integration with GitHub and Vercel for automated deployment + +## Solution Delivered + +### 1. AI Builder Prompt (23KB) +**File:** `.github/prompts/ai-builder.prompt.md` + +A comprehensive system prompt that teaches AI agents to: +- Understand all P0 protocol specifications +- Generate valid metadata configurations +- Follow strict naming conventions (snake_case/camelCase) +- Use Excel-like formula syntax (not JavaScript) +- Create relationships (lookup, master-detail, tree) +- Implement validation rules and hooks +- Self-validate against Zod schemas + +**Key Sections:** +- Complete P0 specifications (Objects, Fields, Validation, Hooks) +- 45+ field type catalog with examples +- Relationship patterns and templates +- Formula syntax guide +- Common mistakes to avoid +- Code generation patterns +- Quality checklist + +### 2. Builder Workflow Documentation +**File:** `content/docs/ai/builder-workflow.mdx` + +Comprehensive workflow documentation covering: +- Three-layer architecture (Architect, DevOps, Runtime) +- Component responsibilities +- V1-V4 development roadmap: + - V1: Read-only mode (repository analysis) + - V2: Configuration generator (code blocks) + - V3: Git integration (automated PRs) + - V4: Self-healing (error recovery) +- Git operations best practices +- Self-healing system design + +### 3. AI Documentation Section +**Files:** +- `content/docs/ai/index.mdx` - Section overview +- `content/docs/ai/meta.json` - Navigation metadata + +Integrated into main documentation with: +- AI & Automation card on docs homepage +- Bot icon for easy recognition +- Links to resources and examples + +### 4. Quick Start Guide +**File:** `AI_BUILDER_README.md` + +User-friendly guide with: +- Architecture overview +- Key features explanation +- Development roadmap +- Protocol quick reference +- Getting started instructions +- Examples and best practices + +### 5. Documentation Integration +**Modified Files:** +- `content/docs/meta.json` - Added AI to navigation +- `content/docs/index.mdx` - Added AI card +- `.github/prompts/README.md` - Added AI Builder entry + +## Architecture + +### Three Core Components + +``` +Architect Agent (Brain) +β”œβ”€ Natural Language Processing +β”œβ”€ Metadata Generation Engine +β”œβ”€ Multi-layer Validation +└─ Self-correction Logic + +DevOps Runner (Hands/Feet) +β”œβ”€ GitHub API Integration +β”œβ”€ Vercel Deployment Monitoring +β”œβ”€ Build Log Analysis +└─ Self-healing Error Recovery + +Runtime Engine (Body) +β”œβ”€ @objectstack/spec (Schemas) +β”œβ”€ @objectstack/core (Kernel) +└─ @objectstack/engine (Executor) +``` + +### Workflow + +``` +User Input (Natural Language) + β”‚ + β–Ό +Architect Agent (Generate Metadata) + β”‚ + β”œβ”€ Parse requirements + β”œβ”€ Generate objects/fields + β”œβ”€ Create relationships + β”œβ”€ Add validation rules + └─ Validate output + β”‚ + β–Ό +DevOps Runner (Automate Deployment) + β”‚ + β”œβ”€ Create feature branch + β”œβ”€ Commit files + β”œβ”€ Create pull request + └─ Monitor deployment + β”‚ + β–Ό +Self-Healing (On Error) + β”‚ + β”œβ”€ Read error logs + β”œβ”€ Categorize issue + β”œβ”€ Generate fix + └─ Re-deploy +``` + +## Key Specifications Documented + +### Naming Conventions +- **Object names:** `snake_case` (e.g., `customer_order`) +- **Field names:** `snake_case` (e.g., `first_name`) +- **Property keys:** `camelCase` (e.g., `maxLength`, `defaultValue`) +- **Option values:** lowercase `snake_case` (e.g., `in_progress`) + +### Field Types (45+ available) +- Text: text, textarea, email, url, phone +- Numbers: number, currency, percent +- Dates: date, datetime, time +- Selection: select, multiselect, radio +- Relationships: lookup, master_detail, tree +- Calculated: formula, summary, autonumber +- Advanced: location, address, json, vector + +### Formula Syntax +- Excel-like expressions (NOT JavaScript) +- Examples: + - `price > 0` + - `AND(active == true, end_date > TODAY())` + - `IF(status == "active", discount <= 50, true)` + +### Relationship Patterns +- **One-to-Many:** `lookup` type +- **Many-to-Many:** `lookup` with `multiple: true` +- **Parent-Child:** `master_detail` type +- **Hierarchical:** `tree` type (self-reference) + +## Development Roadmap + +### Phase 1: Foundation (Current) +- βœ… Documentation complete +- βœ… AI prompts created +- βœ… Architecture designed +- βœ… Navigation integrated + +### Phase 2: Code Generation Engine +- [ ] Implement metadata generator +- [ ] Build validation system +- [ ] Create code templates +- [ ] Add self-check logic + +### Phase 3: Git Integration +- [ ] GitHub API integration +- [ ] Branch creation automation +- [ ] PR generation workflow +- [ ] CI/CD integration + +### Phase 4: Self-Healing +- [ ] Vercel monitoring +- [ ] Error categorization +- [ ] Fix generation +- [ ] Retry mechanism + +## Files Created + +``` +.github/prompts/ + └─ ai-builder.prompt.md (23KB) + +content/docs/ai/ + β”œβ”€ index.mdx + β”œβ”€ meta.json + └─ builder-workflow.mdx + +AI_BUILDER_README.md +IMPLEMENTATION_SUMMARY.md (this file) +``` + +## Files Modified + +``` +.github/prompts/README.md +content/docs/index.mdx +content/docs/meta.json +``` + +## Metrics + +- **Total Documentation:** ~30KB of comprehensive guides +- **Code Examples:** 20+ complete examples +- **Field Types:** 45+ documented +- **Patterns:** 10+ relationship patterns +- **Quality Checks:** 10-point validation checklist + +## Usage Examples + +### Simple CRUD +``` +User: "Create a product catalog" +AI: Generates Product object with name, sku, price, in_stock fields +``` + +### With Relationships +``` +User: "Inventory system with products and warehouses" +AI: Generates Warehouse + Product with lookup relationship +``` + +### Master-Detail +``` +User: "Order system with line items" +AI: Generates Customer + Order + OrderItem with proper cascades +``` + +## Best Practices Documented + +### For AI Agents +1. Generate dependencies first +2. Use formulas for simple logic +3. Validate rigorously +4. Follow naming conventions strictly +5. Self-document code + +### For Developers +1. Review AI-generated PRs +2. Test thoroughly +3. Provide feedback +4. Monitor metrics +5. Update knowledge base + +## Security Considerations + +- Code review required before merge +- Secret scanning +- Branch protection +- API token security +- Webhook verification + +## Next Steps + +1. **Implement V1 (Read-Only Mode)** + - Build repository analyzer + - Create documentation Q&A + - Validate AI understanding + +2. **Implement V2 (Code Generator)** + - Build metadata generation engine + - Add validation system + - Create templates + +3. **Implement V3 (Git Integration)** + - GitHub API integration + - Automated PR workflow + - CI/CD triggers + +4. **Implement V4 (Self-Healing)** + - Error detection + - Auto-fix generation + - Retry mechanisms + +## Resources + +- **Main Documentation:** `/docs/ai` +- **AI Builder Prompt:** `.github/prompts/ai-builder.prompt.md` +- **Quick Start:** `AI_BUILDER_README.md` +- **Architecture:** `ARCHITECTURE.md` +- **Examples:** `examples/` directory + +## Success Criteria + +- βœ… Complete P0 specifications documented +- βœ… AI agent prompt comprehensive and clear +- βœ… Development roadmap defined +- βœ… Architecture designed and documented +- βœ… Navigation integrated +- βœ… Examples and patterns provided +- βœ… Best practices documented +- βœ… Security considerations addressed + +## Conclusion + +This implementation provides a solid foundation for building the ObjectStack Builder system. The documentation is comprehensive, the architecture is well-designed, and the AI prompts are detailed enough to guide agent implementation. + +The system transforms the complex problem of AI-driven development into a structured, metadata-driven approach that leverages ObjectStack's P0 specifications to minimize errors and maximize code quality. + +--- + +**Status:** Ready for Review +**Next Phase:** Implementation (V1 - Read-Only Mode)