Skip to content

Commit c1d31b2

Browse files
committed
Add Zod compliance prompt and update references
Introduced a new Zod compliance prompt to enforce strict schema validity in ObjectStack configurations. Updated all development prompts to reference portable Zod schema files from the dist directory instead of source files. Modified index and meta files to include and describe the new compliance guardrails.
1 parent 2d2cc86 commit c1d31b2

File tree

7 files changed

+100
-8
lines changed

7 files changed

+100
-8
lines changed

content/prompts/app-development.prompt.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ A "Complete" application must define metadata across these 5 layers:
3333

3434
### Layer 1: Data Model (Deep Structure)
3535
**Library:** `@objectstack/spec/data`
36+
**Reference:** `@objectstack/spec` -> `dist/data/object.zod.d.ts`
3637
* **Objects:** Define entities (`Account`, `Contact`).
3738
* **Fields:** Use advanced types (`master_detail`, `formula`, `rollup_summary`).
3839
* **Validation:** Define strict `validation_rules` (e.g., "Discount cannot exceed 20%").
3940
* **Indexes:** specific database indexing for performance.
4041

4142
### Layer 2: User Interface (The Workspace)
4243
**Library:** `@objectstack/spec/ui`
44+
**Reference Schema:** `@objectstack/spec` -> `dist/ui/app.zod.d.ts` (App), `dist/ui/view.zod.d.ts` (Views)
4345
* **App:** Navigation Menu groups (`Sales`, `Service`, `Settings`).
4446
* **Views:**
4547
* `Grid`: Standard tables with filters.
@@ -51,11 +53,13 @@ A "Complete" application must define metadata across these 5 layers:
5153
* **Actions:** Custom buttons (`Convert Lead`, `Submit for Approval`).
5254

5355
### Layer 3: Analytics (Intelligence)
56+
**Reference Schema:** `@objectstack/spec` -> `dist/ui/dashboard.zod.d.ts`, `dist/ui/report.zod.d.ts`
5457
**Library:** `@objectstack/spec/ui` (Dashboard/Report)
5558
* **Reports:** Tabular, Summary, Matrix reports.
5659
* **Dashboards:** Layouts with Charts (Donut, Bar, Metric) embedding reports.
5760

5861
### Layer 4: Logic & Automation
62+
**Reference Schema:** `@objectstack/spec` -> `dist/data/hook.zod.d.ts`
5963
**Library:** `@objectstack/spec/system` & `@objectstack/spec/data` (Hooks)
6064
* **Triggers:** `beforeInsert`, `afterUpdate` hooks for data consistency.
6165
* **Jobs:** Scheduled tasks (e.g., "Nightly Sync").
@@ -72,6 +76,7 @@ A "Complete" application must define metadata across these 5 layers:
7276
## 3. Implementation Patterns
7377

7478
### A. Defining a Complex Object (Account)
79+
// Definitions: dist/data/object.zod.d.ts
7580

7681
```typescript
7782
import { ObjectSchema } from '@objectstack/spec/data';
@@ -112,6 +117,7 @@ export const AccountObject: ObjectSchema = {
112117
};
113118
```
114119

120+
// Definitions: dist/ui/app.zod.d.ts
115121
### B. Configuring the App & Navigation
116122

117123
```typescript

content/prompts/component-development.prompt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
Widgets are the atomic building blocks of ObjectUI. They render specific `FieldTypes` or `ViewComponents`.
1212

13-
**Reference:** `packages/spec/src/ui/widget.zod.ts`
13+
**Reference:** `@objectstack/spec` -> `dist/ui/widget.zod.d.ts`
1414

1515
## 2. Widget Registration
1616

content/prompts/driver-development.prompt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
ObjectStack does not ship with a database. It uses **Drivers** to virtualize external data sources (SQL, NoSQL, APIs) into a unified ObjectQL graph.
1212

13-
**Reference Schema:** `packages/spec/src/driver/driver.zod.ts`
13+
**Reference Schema:** `@objectstack/spec` -> `dist/driver/driver.zod.d.ts`
1414

1515
## 2. The Interface Contract
1616

@@ -49,7 +49,7 @@ export class PostgresDriver implements ObjectDriver {
4949

5050
The hardest part is mapping the **ObjectQL AST** to the native query language.
5151

52-
**Reference:** `packages/spec/src/data/query.zod.ts`
52+
**Reference:** `@objectstack/spec` -> `dist/data/query.zod.d.ts`
5353

5454
**Input (AST):**
5555
```json

content/prompts/index.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ Copy the relevant prompt and paste it at the start of your chat session to groun
3434
/>
3535
</Cards>
3636

37-
## 🏛️ Master Architecture
37+
## 🏛️ Master Architecture & Compliance
3838

39-
For high-level architectural decisions and system design, use the Master Prompt.
39+
For high-level architectural decisions and system design, use the Master Prompt. Use the Compliance Prompt to enforce Schema validity.
4040

4141
* **[Master Architecture Context](/prompts/objectstack)**
42+
* **[Zod Compliance Guardrails](/prompts/zod-compliance)** - *Use this to stop AI from hallucinating invalid properties.*
4243

content/prompts/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"pages": [
44
"index",
55
"objectstack",
6+
"zod-compliance",
67
"app-development",
78
"plugin-development",
89
"component-development",

content/prompts/plugin-development.prompt.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ my-plugin/
2828

2929
Every plugin MUST have a valid manifest. It dictates how the kernel loads your code.
3030

31-
**Reference Schema:** `packages/spec/src/kernel/manifest.zod.ts`
31+
**Reference Schema:** `@objectstack/spec` -> `dist/kernel/manifest.zod.d.ts`
3232

3333
```typescript
3434
import { ObjectStackManifest } from '@objectstack/spec/kernel';
@@ -63,7 +63,7 @@ export default config;
6363
## 3. Development Workflow
6464

6565
### A. Define Objects (The Data Contract)
66-
**Reference:** `packages/spec/src/data/object.zod.ts`
66+
**Reference:** `@objectstack/spec` -> `dist/data/object.zod.d.ts`
6767
Use Zod schemas to define business entities.
6868

6969
```typescript
@@ -81,7 +81,7 @@ export const TodoObject = {
8181
```
8282

8383
### B. Implement Logic (The Runtime)
84-
**Reference:** `packages/spec/src/data/hook.zod.ts`
84+
**Reference:** `@objectstack/spec` -> `dist/data/hook.zod.d.ts`
8585

8686
```typescript
8787
// src/triggers/todo.trigger.ts
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# 🛡️ ObjectStack Metadata Compliance Context (Zod-First)
2+
3+
**Role:** You are the **Protocol Validator Agent**.
4+
**Task:** Ensure all generated configurations (JSON/YAML/TS) are strictly compliant with the ObjectStack Zod Protocols.
5+
**Directive:** "If the Schema doesn't say yes, the answer is no."
6+
7+
---
8+
9+
## 1. The Strategy: Zod-Driven Generation
10+
11+
ObjectStack uses Zod (`.zod.ts`) as the single source of truth. Do not hallucinate properties.
12+
13+
### Rule 1: Read the Schema First
14+
Before generating an object, generic field, or app config, look up the authoritative Zod definition.
15+
16+
| Concept | Definition Source (Portable) | Package Import |
17+
| :--- | :--- | :--- |
18+
| **Manifest** | `dist/kernel/manifest.zod.d.ts` | `@objectstack/spec/kernel` |
19+
| **Object** | `dist/data/object.zod.d.ts` | `@objectstack/spec/data` |
20+
| **Field** | `dist/data/field.zod.d.ts` | `@objectstack/spec/data` |
21+
| **View (UI)** | `dist/ui/view.zod.d.ts` | `@objectstack/spec/ui` |
22+
| **Action** | `dist/ui/action.zod.d.ts` | `@objectstack/spec/ui` |
23+
| **API** | `dist/api/endpoint.zod.d.ts` | `@objectstack/spec/api` |
24+
25+
### Rule 2: Derive Types from Schema
26+
When writing TypeScript, use `z.infer`.
27+
28+
```typescript
29+
// ✅ CORRECT
30+
import { FieldSchema } from '@objectstack/spec/data';
31+
type FieldConfig = z.infer<typeof FieldSchema>;
32+
33+
// ❌ INCORRECT (Do not manually type interfaces that drift from Zod)
34+
interface FieldConfig {
35+
name: string;
36+
// User might forget 'required', 'searchable', etc.
37+
}
38+
```
39+
40+
## 2. Validation Pattern for AI
41+
42+
When the user asks for a configuration, simulate this internal validation process:
43+
44+
1. **Retrieve Schema:** "I need to generate a `Field`. I recall `FieldSchema` has `type`, `label`, `required`..."
45+
2. **Check Constraints:** "The user requested a 'Money' field. The schema `FieldType` enum uses `currency`, not `money`. I will correct this."
46+
3. **Verify Shapes:** "The user added `columns: 3` to a `text` field. `FieldSchema` does not allow `columns` on `text`. I will remove it."
47+
48+
## 3. Example: Strict Object Generation
49+
50+
**User Request:** "Create a Project object with a status dropdown and a budget."
51+
52+
**Internal Zod Check:**
53+
* `ObjectSchema`: keys `name`, `fields` are required. `name` must be snake_case regex.
54+
* `FieldSchema`:
55+
* `status`: type `select`, requires `options` array.
56+
* `budget`: type `currency`, `scale` defaults to 2.
57+
58+
**Generated Code:**
59+
```typescript
60+
import { ObjectSchema } from '@objectstack/spec/data';
61+
62+
export const ProjectObject: ObjectSchema = {
63+
name: 'project', // ✅ Validates regex /^[a-z_]+$/
64+
label: 'Project',
65+
fields: {
66+
status: {
67+
type: 'select', // ✅ Validates Enum
68+
options: ['New', 'Active', 'Done'], // ✅ Required for type='select'
69+
label: 'Status'
70+
},
71+
budget: {
72+
type: 'currency',
73+
scale: 2, // ✅ Valid prop for currency
74+
precision: 18,
75+
label: 'Total Budget'
76+
}
77+
}
78+
};
79+
```
80+
81+
---
82+
83+
**Instruction:**
84+
Use this prompt when you need the AI to act as a **Linter** or **Compiler**. It helps prevent "Configuration Drift" where the AI generates plausible but invalid properties.

0 commit comments

Comments
 (0)