Skip to content

Add AI Builder system documentation and agent prompts for P0-compliant metadata generation - #451

Closed
hotlong with Copilot wants to merge 5 commits into
mainfrom
copilot/design-agent-context-awareness
Closed

hotlong with Copilot wants to merge 5 commits into
mainfrom
copilot/design-agent-context-awareness

Conversation

Copilot AI commented Jan 31, 2026 •

Copy link
Copy Markdown
Contributor

Implements documentation infrastructure for AI-driven ObjectStack development. Addresses requirement for automated metadata generation system with GitHub/Vercel integration and self-healing deployment.

Core Deliverables

AI Agent System Prompt (.github/prompts/ai-builder.prompt.md - 23KB)

  • Complete P0 protocol specifications (Object, Field, Validation, Hook)
  • 45+ field type catalog with configuration patterns
  • Naming convention rules: snake_case identifiers, camelCase properties
  • Formula syntax: Excel-like expressions, not JavaScript
  • Relationship patterns: lookup (1:N), master_detail (cascade), tree (hierarchical)
  • Code generation templates with multi-layer validation (Zod, TypeScript, conventions)

4-Phase Development Roadmap (content/docs/ai/builder-workflow.mdx)

  • V1: Repository analysis and documentation Q&A
  • V2: Metadata generation with manual code blocks
  • V3: Automated Git workflow (branch → commit → PR → deploy)
  • V4: Self-healing error recovery with log analysis

Architecture Design

Architect Agent (Brain)          DevOps Runner              Runtime Engine
├─ NLP → Entity Extraction      ├─ GitHub API (Octokit)    ├─ @objectstack/spec
├─ Metadata Generation          ├─ Vercel Monitoring       ├─ @objectstack/core
├─ Multi-layer Validation       ├─ Build Log Analysis      └─ @objectstack/engine
└─ Dependency Ordering          └─ Auto-fix Generation

Critical Specifications

Naming Enforcement:

// Object/Field names
name: 'customer_order'      // ✓ snake_case
name: 'CustomerOrder'       // ✗ PascalCase

// Property keys
maxLength: 255              // ✓ camelCase
max_length: 255             // ✗ snake_case

// Select options
value: 'in_progress'        // ✓ lowercase
value: 'InProgress'         // ✗ mixed case

Formula Syntax:

// Validation rules use Excel-like formulas
formula: 'price > 0'                              // ✓
formula: 'AND(active == true, end_date > TODAY())' // ✓
formula: 'return price > 0;'                      // ✗ JavaScript

Relationship Generation:

// Agent must generate dependencies first
1. warehouse.object.ts      // Base object
2. product.object.ts        // References warehouse via lookup
   fields: {
     warehouse_id: {
       type: 'lookup',
       reference: { object: 'warehouse' }
     }
   }

Files Created

  • .github/prompts/ai-builder.prompt.md - Agent configuration (23KB)
  • content/docs/ai/{index,builder-workflow}.mdx - Documentation
  • AI_BUILDER_README.md - Quick reference
  • IMPLEMENTATION_SUMMARY.md - Project overview

Files Modified

  • content/docs/{meta.json,index.mdx} - Navigation integration
  • .github/prompts/README.md - Prompt registry

Self-Healing Workflow

Deploy → Build Error → Parse Logs → Categorize Issue
                            ↓
      Missing Dependency: Generate stub object
      Type Mismatch: Fix type annotations  
      Validation Failure: Correct schema
                            ↓
                    Commit Fix → Redeploy (max 3 retries)

Documentation accessible at /docs/ai with integration into main navigation.

Original prompt

基于以下内容,编写详细的技术方案和开发计划
这是一个非常前沿且架构清晰的构想。利用 元数据驱动 (Metadata-Driven) 的架构(即 @objectstack/spec)结合 AI Agent,是实现软件自我迭代的最佳路径。因为 AI 只需要理解和生成结构化的 JSON/TypeScript 配置,而不需要处理底层复杂的 UI 渲染和数据库连接,这极大地降低了出错率。
基于你提供的 P0 核心元数据,我为你设计了一套 Agent 架构方案,名为 "ObjectStack Builder"。
核心架构概览
该系统由三个核心部分组成:

  • Architect Agent (大脑): 理解用户需求,基于 P0 规范生成元数据配置。
  • DevOps Runner (手脚): 集成 GitHub API 进行代码提交,集成 Vercel API 监控部署状态。
  • Runtime Engine (躯干): 即你现有的 @objectstack 框架,负责消费元数据并渲染应用。
    第一阶段:设计 Agent 的 "上下文认知" (Context)
    Agent 必须完全理解 P0 规范。我们需要将你提供的 object, field, validation, query, hook 转化为 Agent 的 System Prompt 或 RAG (检索增强生成) 知识库。
  1. 提示词工程 (Prompt Engineering) 策略
    不要直接把 Zod 代码扔给 Agent,而是将其转化为“规则集”。

System Prompt 示例片段:
你是一个基于 @objectstack/spec 的企业软件架构师。你的工作是根据用户需求生成 TypeScript 配置文件。
核心规则:

  • Object: 必须包含 name (snake_case) 和 fields。
  • Fields: 仅限使用以下类型:text, number, lookup, master_detail, formula 等 [引用你的列表]。
  • Validation: 业务逻辑必须通过 formula 字符串实现,而不是 JS 代码。
  • Hooks: 只有在需要复杂后端逻辑(如调用外部 API、级联更新)时才使用 Hooks。
  1. 元数据生成映射
    Agent 的输出需要严格对应你的目录结构:
  • 用户指令:"我想做一个简单的库存管理,有产品和仓库。"
  • Agent 动作:生成以下文件内容。
    File: packages/app/src/domains/inventory/warehouse.object.ts
    import { ServiceObject } from '@objectstack/spec';

export const Warehouse: ServiceObject = {
name: 'warehouse',
label: '仓库',
description: '存储产品的物理位置',
primaryKey: 'id',
fields: {
name: { type: 'text', label: '仓库名称', required: true, unique: true },
location: { type: 'text', label: '地址' },
capacity: { type: 'number', label: '最大容量' }
},
enable: { search: true, apiEnabled: true }
};

File: packages/app/src/domains/inventory/product.object.ts
import { ServiceObject } from '@objectstack/spec';

export const Product: ServiceObject = {
name: 'product',
label: '产品',
fields: {
name: { type: 'text', label: '产品名称', required: true },
sku: { type: 'text', label: 'SKU', unique: true },
price: { type: 'currency', label: '单价' },
// 自动关联仓库 (Lookup)
warehouse_id: {
type: 'lookup',
label: '所属仓库',
reference: { object: 'warehouse' }
}
},
validation: {
// 对应你的 1.3 Validation
name: 'positive_price',
errorMessage: '价格必须大于0',
formula: 'price > 0'
}
};

第二阶段:构建自动化迭代循环 (The Loop)
要实现“自我迭代”,Agent 需要通过 GitHub 和 Vercel 完成闭环。
步骤 1:读取与规划 (Read & Plan)
Agent 使用 GitHub API (Octokit) 读取仓库当前的 packages/spec 目录,理解现有数据模型,避免命名冲突。
步骤 2:代码生成与写入 (Code Generation)
Agent 在内存中生成 TypeScript AST (抽象语法树) 或直接生成字符串。

  • 技巧: 使用 AST 工具 (如 ts-morph) 比纯文本生成更安全,可以确保留导入 (Imports) 正确。
    步骤 3:提交与版本控制 (Git Ops)
    Agent 不直接推送到 main 分支,而是创建一个 feature/v{n} 分支。
    // 伪代码:Agent 的提交逻辑
    const branchName = ai-update-${Date.now()};
    await github.createBranch(branchName);

await github.createOrUpdateFile({
path: 'packages/app/src/domains/inventory/product.object.ts',
content: generatedCode,
message: 'feat(inventory): add product and warehouse objects'
});

await github.createPullRequest({
title: 'AI Iteration: Inventory Module',
head: branchName,
base: 'main'
});

步骤 4:部署与反馈 (Deploy & Feedback)
这是最关键的一步。

  • GitHub 触发 Vercel 预览部署。
  • Agent 监听 Vercel 的 Webhook。
    • 如果是 🟢 Success: Agent 将 PR 合并到主分支,通知用户“新版本已发布”。
    • 如果是 🔴 Error: Agent 读取 Vercel 的 Build Logs。
      • 分析错误(例如:Schema validation failed: 'warehouse' object not found)。
      • 自我修复: Agent 意识到定义了 Lookup 但忘了先提交 Warehouse 对象,于是修正顺序,重新提交代码。
        第三阶段:深入 P0 规范的 Agent 实现细节
        针对你提供的具体规范,Agent 需要具备特定的“技能”:
  1. 处理复杂字段 (Lookup/Master-Detail)
    当用户说“订单包含多个商品”时,Agent 必须识别这是 1.2 Field 中的 master_detail 关系。
  • 策略: Agent 会先生成主表 order,再生成子表 order_item,并在子表中添加指向 order 的 master_detail 字段。
  1. 编写业务逻辑 (Validation & Formulas)
    当用户说“折扣不能超过 50%”时。
  • 策略: Agent 查阅 1.3 Validation 规范,生成:
    {
    name: 'max_discount',
    formula: 'discount_rate <= 50',
    errorMessage: '折扣率不能超过50%'
    }

    注意:Agent 需要被训练成生成类似 Excel 的公式语法,而不是 JavaScript。

  1. 生成后端钩子 (Hooks)
    这是最难的部分。如果用户要求“创建订单后自动发邮件”。
  • 策略: Agent 查阅 1.5 Hook 规范,识别为 after_create。
  • 代码生成: Agent 需要能够编写通过 TypeScript 编译的函数。
    // generated: order.hook.ts
    {
    type: 'after_create',
    handler: async (context) => {
    // Agent 需要知道 context 中有什么
    const email = context.record.customer_email;
    // Agent 可能会调用预置的发送邮件工具函数
    await sendEmail(email, '订单确认');
    }
    }

第四阶段:开发路线图建议
建议按照以下顺序开发 Agent:

  • V1 (只读模式): Agent 可以读取 GitHub 上的现有代码,回答“当前系统有哪些对象?”、“客户表有哪些字段?”。这是为了验证它对 @objectstack/spec 的理解能力。
  • V2 (配置生成器): 输入需求,Agent 输出符合 P0 规范的 JSON/TS 代码块,人工复制粘贴。
  • V3 (Git 集成): Agent 直接向 GitHub 提交 PR。此时你需要配置 CI/CD 中的 Type Check,确保 Agent 提交的代码符合 TS 类型定义。
  • V4 (自我修复): 接入 Vercel 报错日志,实现闭环迭代。
    总结
    你的 @objectstack/spec 定义非常规范,这实际上解决了 AI 编程最大的难题——不确定性。通过强制 AI 输出符合 Zod 结构的数据,你将“编程问题”降维成了“填空题”,这使得自动化迭代不仅可行,而且会非常稳定。
    下一步建议:
    你需要我为你写一个 System Prompt 的模板 吗?这个模板将专门用于教导 GPT-4/Claude 如何严格遵守你的 1.1 - 1.5 规范来生成代码。

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel

vercel Bot commented Jan 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jan 31, 2026 7:30pm

Request Review

Copilot AI and others added 3 commits January 31, 2026 19:25
- 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>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
- 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>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview — a805396c Deployed Jan 31, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants