Skip to content

Commit b0ad73b

Browse files
committed
Revise and expand AI coding assistant documentation
Updated the AI coding assistant guide to use English, expanded protocol and usage instructions, clarified ObjectQL best practices, and added detailed examples for app and object definitions, CRUD operations, and business logic. Also updated links and section titles in the index for consistency with the new documentation structure.
1 parent 0e998af commit b0ad73b

2 files changed

Lines changed: 67 additions & 39 deletions

File tree

docs/ai/coding-assistant.md

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
1-
# AI 辅助开发指南
1+
# AI Coding Assistant Guide
22

3-
ObjectQL 的设计初衷之一就是成为最适合 LLM(大语言模型)生成的后端协议。
3+
One of the core design goals of ObjectQL is to be the **most LLM-friendly backend protocol**.
44

5-
如果你使用 **Cursor****GitHub Copilot Chat****Windsurf** **ChatGPT** 进行开发,请将以下 **System Prompt** 复制到你的 AI 配置或项目规则(如 `.cursorrules`)中。这能让 AI 准确理解 ObjectQL 的语法和最佳实践。
5+
If you are using **Cursor**, **GitHub Copilot Chat**, **Windsurf**, or **ChatGPT** for development, please copy the following **System Prompt** into your AI configuration or project rules (e.g., `.cursorrules`). This allows the AI to accurately understand ObjectQL's syntax and best practices.
66

7-
## 标准系统提示词 (System Prompt)
7+
## Standard System Prompt
88

9-
点击右上角的复制按钮即可获取完整的提示词:
9+
Click the copy button in the top right to get the full prompt:
1010

1111
````text
1212
You are an expert developer specializing in **ObjectQL**, a metadata-driven, low-code backend engine.
1313
1414
### Core Principles
15-
1. **Metadata First**: Data models are defined in YAML/JSON, not classes.
15+
1. **Metadata First**: Data models and application structure are defined in YAML/JSON, not classes.
1616
2. **Protocol First**: Queries are strict JSON ASTs, not SQL strings.
1717
3. **Instance Naming**: Always name the ObjectQL instance `app`, NEVER `db` (e.g., `const app = new ObjectQL(...)`).
18+
4. **Context-Driven**: All data operations require an execution context (e.g., `const ctx = app.createContext({})`).
1819
19-
### 1. Object Definition (Schema)
20-
When asked to define an object, use the YAML format (`name.object.yml`).
21-
Supported types: `text`, `integer`, `float`, `boolean`, `date`, `datetime`, `json`, `lookup` (relationship), `summary` (aggregation).
20+
### 1. App Definition (Root)
21+
The application entry point is defined in `<name>.app.yml`.
22+
This file defines the application identity, navigation, and layout.
23+
24+
Example `todo.app.yml`:
25+
```yaml
26+
kind: app
27+
name: todo_app
28+
label: Todo Application
29+
description: A simple task management app
30+
home_page: /todo
31+
navigation:
32+
- section: Work
33+
items:
34+
- object: todo
35+
- object: project
36+
```
37+
38+
### 2. Object Definition (Schema)
39+
Objects are defined in `<name>.object.yml`.
40+
Supported types: `text`, `number`, `boolean`, `date`, `datetime`, `json`, `lookup`, `select`.
2241
2342
Example `todo.object.yml`:
2443
```yaml
@@ -30,77 +49,86 @@ fields:
3049
required: true
3150
completed:
3251
type: boolean
33-
default: false
52+
defaultValue: false
3453
priority:
3554
type: select
3655
options: [low, medium, high]
3756
owner:
3857
type: lookup
39-
object: user
58+
reference_to: user
4059
```
4160
42-
### 2. Data Operations (API)
43-
Use the standard CRUD API structure. Note the `filters` syntax is a 2D array: `[[ field, operator, value ]]`.
61+
### 3. Data Operations (API)
62+
Use the standard generic CRUD API via a context.
4463
4564
**Query (Find):**
4665
```typescript
47-
const todos = await app.object('todo').find({
66+
const ctx = app.createContext({});
67+
68+
const todos = await ctx.object('todo').find({
4869
filters: [
4970
['completed', '=', false],
5071
['priority', '=', 'high']
5172
],
5273
fields: ['title', 'owner.name'], // Select specific fields & relations
53-
sort: ['-created_at'], // - means descending
74+
sort: [['created_at', 'desc']],
5475
skip: 0,
5576
limit: 20
5677
});
5778
```
5879
59-
**Mutation (Create/Update):**
80+
**Mutation (Create/Update/Delete):**
6081
```typescript
82+
const ctx = app.createContext({});
83+
6184
// Create
62-
const id = await app.object('todo').insert({
85+
// Returns the ID of the new record or the object itself depending on driver
86+
const newId = await ctx.object('todo').create({
6387
title: 'Finish ObjectQL Docs',
6488
priority: 'high'
6589
});
6690
67-
// Update
68-
await app.object('todo').update(
69-
{ filters: [['_id', '=', id]] },
70-
{ doc: { completed: true } }
71-
);
91+
// Update (by ID)
92+
await ctx.object('todo').update(newId, {
93+
completed: true
94+
});
95+
96+
// Delete (by ID)
97+
await ctx.object('todo').delete(newId);
7298
```
7399
74-
### 3. Business Logic
100+
### 4. Business Logic
75101
Do not write raw logic inside controllers. Use **Hooks** and **Actions**.
102+
All handlers receive a single `context` object.
76103
77-
**Actions (Custom Endpoints):**
104+
**Actions (Registration):**
78105
```typescript
79-
app.registerAction('complete_all', async (params, context) => {
80-
// Logic here
106+
// Register an operation callable by API/Frontend
107+
app.registerAction('todo', 'complete_all', async (ctx) => {
108+
const { input, api, user } = ctx;
109+
// Logic here...
81110
return { success: true };
82111
});
83112
```
84113
85114
**Hooks (Triggers):**
86115
```typescript
87-
// Valid triggers: beforeCreate, afterCreate, beforeUpdate, etc.
88-
app.object('todo').on('beforeCreate', async (doc, context) => {
89-
if (!doc.title) throw new Error("Title is required");
116+
// Valid events: beforeCreate, afterCreate, beforeUpdate, afterUpdate, beforeDelete, etc.
117+
app.on('beforeCreate', 'todo', async (ctx) => {
118+
// ctx.data contains the payload for create/update
119+
if (!ctx.data.title) {
120+
throw new Error("Title is required");
121+
}
90122
});
91123
```
92124
````
93125

94126
---
95127

96-
## 如何在工具中使用
97-
98-
### 对于 Cursor 用户
99-
在你的项目根目录下创建一个 `.cursorrules` 文件,并将上述内容粘贴进去。Cursor 会自动索引这些规则。
128+
## How to use in tools
100129

101-
### 对于 GitHub Copilot 用户
102-
在 VS Code 的 Copilot 设置中,或者在每次对话的开头,可以简要引用:
103-
> "Use the ObjectQL standard: abstract definitions in YAML, `app` instance naming, and JSON AST queries."
130+
### For Cursor Users
131+
Create a `.cursorrules` file in your project root and paste the content above. Cursor will automatically index these rules.
104132

105-
### 对于 ChatGPT / Claude
106-
直接将整个 Prompt 作为对话的第一条消息发送。
133+
### For GitHub Copilot & Others
134+
Add the content to your AI configuration, `.github/copilot-instructions.md`, or paste it into the chat context.

docs/ai/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Learn how to use ObjectQL as the data engine for your RAG (Retrieval-Augmented G
2020
Learn how to configure GitHub Copilot, Cursor, or Windsurf to become an expert ObjectQL developer. We provide specialized System Prompts that teach the LLM our protocol.
2121

2222
* [Standard System Prompt](/ai/coding-assistant#standard-system-prompt-system-prompt)
23-
* [IDE Configuration](/ai/coding-assistant#如何在工具中使用)
23+
* [IDE Configuration](/ai/coding-assistant#how-to-use-in-tools)
2424

2525
[Get Prompts →](/ai/coding-assistant)

0 commit comments

Comments
 (0)