oneie 3.4.2 → 3.6.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.
- package/.claude/agents/agent-director.md +902 -22
- package/.claude/agents/agent-onboard-example-output.md +600 -0
- package/.claude/agents/agent-onboard.md +576 -0
- package/.claude/commands/ONBOARDING_ENHANCEMENT_SUMMARY.md +266 -0
- package/.claude/commands/one.md +411 -10
- package/.claude/commands/release.md +64 -3
- package/CLAUDE.md +55 -69
- package/dist/commands/init.d.ts +5 -6
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +101 -101
- package/dist/commands/init.js.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/installation-setup.d.ts +24 -1
- package/dist/utils/installation-setup.d.ts.map +1 -1
- package/dist/utils/installation-setup.js +85 -1
- package/dist/utils/installation-setup.js.map +1 -1
- package/dist/utils/launch-claude.d.ts +6 -0
- package/dist/utils/launch-claude.d.ts.map +1 -0
- package/dist/utils/launch-claude.js +51 -0
- package/dist/utils/launch-claude.js.map +1 -0
- package/dist/utils/validation.d.ts +48 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +73 -0
- package/dist/utils/validation.js.map +1 -0
- package/folders.yaml +1 -1
- package/one/.obsidian/app.json +8 -0
- package/one/.obsidian/appearance.json +1 -0
- package/one/.obsidian/community-plugins.json +3 -0
- package/one/.obsidian/core-plugins.json +33 -0
- package/one/.obsidian/plugins/easy-bake/main.js +361 -0
- package/one/.obsidian/plugins/easy-bake/manifest.json +11 -0
- package/one/.obsidian/plugins/easy-bake/styles.css +10 -0
- package/one/.obsidian/workspace.json +240 -0
- package/one/connections/workflow-onboarding.md +683 -0
- package/one/events/CART-DRAWER-INTEGRATION-GUIDE.md +354 -0
- package/one/events/CRITICAL-FIXES-COMPLETE.md +504 -0
- package/one/events/DEPLOYMENT.md +178 -0
- package/one/events/ECOMMERCE-DEMO-PLAN.md +225 -0
- package/one/events/ECOMMERCE-LIVE-DEMO.md +363 -0
- package/one/events/ECOMMERCE-TEMPLATE-COMPLETE.md +735 -0
- package/one/events/ECOMMERCE-TEMPLATES-SUMMARY.md +923 -0
- package/one/events/GRADIENT-TEXT-PERMANENT-FIX.md +223 -0
- package/one/events/HANDOFF.md +313 -0
- package/one/events/IMPLEMENTATION-SUMMARY-FINAL.md +503 -0
- package/one/events/IMPLEMENTATION_SUMMARY.md +529 -0
- package/one/events/LANDING-PAGE-EXAMPLE-OUTPUT.md +666 -0
- package/one/events/LANDING-PAGE-IMPLEMENTATION.md +642 -0
- package/one/events/LANDING-PAGE-QUICKSTART.md +407 -0
- package/one/events/MULTI-ONTOLOGY-COMPLETE-GUIDE.md +1627 -0
- package/one/events/MULTI-ONTOLOGY-IMPLEMENTATION-COMPLETE.md +573 -0
- package/one/events/ONBOARDING-IMPLEMENTATION-COMPLETE copy.md +398 -0
- package/one/events/ONTOLOGY-TUTORIALS-SUMMARY.md +525 -0
- package/one/events/ONTOLOGY-TYPE-GENERATOR-SUMMARY.md +455 -0
- package/one/events/ONTOLOGY_DISCOVERY_IMPLEMENTATION.md +486 -0
- package/one/events/ONTOLOGY_DISCOVERY_QUICKSTART.md +203 -0
- package/one/events/SECURITY-AUDIT-FIXES.md +376 -0
- package/one/events/SECURITY-SCAN-COMPLETE.md +281 -0
- package/one/events/SHOP-BUILD-STATUS.md +114 -0
- package/one/events/SHOP-PREMIUM-UPDATE.md +149 -0
- package/one/events/SITE-WIDE-GRADIENT-FIX.md +299 -0
- package/one/events/STORE-PRODUCTION-READY-STATUS.md +359 -0
- package/one/events/STRIPE-PAYMENT-METHODS-GUIDE.md +429 -0
- package/one/events/agent-director-enhancement-summary.md +386 -0
- package/one/events/agent-onboard-implementation-summary.md +457 -0
- package/one/events/clean-agent-ontology-cleanup-report.md +353 -0
- package/one/events/landing-page-generator.md +458 -0
- package/one/events/onboarding-implementation-complete.md +505 -0
- package/one/events/release.md +254 -0
- package/one/events/separate-implementation-status.md +537 -0
- package/one/groups/nine-padle-contents.baked.md +1252 -0
- package/one/groups/nine-padle-contents.md +6 -0
- package/one/knowledge/100-inference-quick-reference.md +431 -0
- package/one/knowledge/agent-onboard-usage.md +612 -0
- package/one/knowledge/cli-claude-handoff.md +718 -0
- package/one/knowledge/installation-folders.md +45 -1
- package/one/knowledge/ontology-blog.yaml +31 -0
- package/one/knowledge/ontology-cheatsheet.md +591 -0
- package/one/knowledge/ontology-community.yaml +42 -0
- package/one/knowledge/ontology-core-universal.md +722 -0
- package/one/knowledge/ontology-core.yaml +50 -0
- package/one/knowledge/ontology-courses.yaml +53 -0
- package/one/knowledge/ontology-creator.md +376 -0
- package/one/knowledge/ontology-developer-guide.md +789 -0
- package/one/knowledge/ontology-education.md +920 -0
- package/one/knowledge/ontology-index.md +354 -0
- package/one/knowledge/ontology-migration-guide.md +811 -0
- package/one/knowledge/ontology-minimal.yaml +1 -1
- package/one/knowledge/ontology-portfolio.yaml +31 -0
- package/one/knowledge/ontology-quickstart.md +576 -0
- package/one/knowledge/ontology-shop.yaml +121 -0
- package/one/knowledge/ontology-tokens.yaml +32 -0
- package/one/knowledge/ontology-tutorial.md +434 -0
- package/one/knowledge/ontology-video-script.md +890 -0
- package/one/things/docs/ecommerce/ARCHITECTURE-DIAGRAM.md +467 -0
- package/one/things/docs/ecommerce/CONVERSION-ELEMENTS-IMPLEMENTATION.md +408 -0
- package/one/things/docs/ecommerce/CONVERSION-ELEMENTS-SUMMARY.md +369 -0
- package/one/things/docs/ecommerce/CONVERSION-UX-IMPLEMENTATION-SUMMARY.md +396 -0
- package/one/things/docs/ecommerce/FEATURE-SUMMARY.md +468 -0
- package/one/things/docs/ecommerce/IMPLEMENTATION-NOTES.md +582 -0
- package/one/things/docs/ecommerce/INTEGRATION-EXAMPLE.md +449 -0
- package/one/things/docs/ecommerce/QUICK-START.md +368 -0
- package/one/things/docs/ecommerce/URGENCY-IMPLEMENTATION-SUMMARY.md +498 -0
- package/one/things/docs/ecommerce/URGENCY-QUICK-REFERENCE.md +237 -0
- package/one/things/docs/ecommerce/USAGE-EXAMPLE.astro +171 -0
- package/one/things/docs/ecommerce/demo.astro +309 -0
- package/one/things/plans/agent-director-100-inference-plans.md +410 -0
- package/one/things/plans/dual-website-strategy.md +612 -0
- package/one/things/plans/feature-based-sites.md +821 -0
- package/one/things/plans/multi-ontology-architecture.md +836 -0
- package/one/things/plans/onboarding.md +32 -0
- package/one/things/plans/separate.md +15 -17
- package/one/things/plans/start-new.md +738 -0
- package/one/things/templates.md +254 -0
- package/one/things/todo.md +23 -5
- package/package.json +2 -2
- package/one/things/claude/hooks/agent-hook-manager.js +0 -525
- package/one/things/claude/hooks/agent-load-balancer.js +0 -271
- package/one/things/claude/hooks/agent-request-interceptor.js +0 -70
- package/one/things/claude/hooks/cascade-feedback.js +0 -297
- package/one/things/claude/hooks/cascade-integration-hooks.js +0 -648
- package/one/things/claude/hooks/continuous-improvement-monitor.js +0 -510
- package/one/things/claude/hooks/file-organization-engine.js +0 -427
- package/one/things/claude/hooks/file-organization-monitor.js +0 -269
- package/one/things/claude/hooks/hook-config-manager.js +0 -202
- package/one/things/claude/hooks/hook-orchestrator.js +0 -662
- package/one/things/claude/hooks/hook-performance-report.js +0 -120
- package/one/things/claude/hooks/mcp-cascade-integration.js +0 -816
- package/one/things/claude/hooks/memory-optimizer.js +0 -510
- package/one/things/claude/hooks/ontology-compliance.js +0 -394
- package/one/things/claude/hooks/ontology-hook-manager.js +0 -316
- package/one/things/claude/hooks/ontology-validation-engine.js +0 -317
- package/one/things/claude/hooks/performance-monitoring-hook.js +0 -422
- package/one/things/claude/hooks/quality-scoring-engine.js +0 -834
- package/one/things/claude/hooks/simple-load-balancer.js +0 -238
- package/one/things/claude/hooks/startup-optimizer.js +0 -625
- package/one/things/claude/hooks/story-scoring-system.js +0 -445
- package/one/things/claude/hooks/story-validation-engine.js +0 -473
- package/one/things/claude/hooks/structure-synchronizer.js +0 -194
- package/one/things/claude/hooks/sub-agent-output-validator.js +0 -647
- package/one/things/claude/hooks/sub-agent-validation-hook.js +0 -343
- package/one/things/claude/hooks/trinity-validation-system.js +0 -392
- package/one/things/plans/organizations-to-groups.md +0 -705
|
@@ -112,7 +112,48 @@ echo "# Our Vision" > /acme/things/vision.md
|
|
|
112
112
|
|
|
113
113
|
## CLI Usage
|
|
114
114
|
|
|
115
|
-
###
|
|
115
|
+
### Automatic Initialization (via `/one` Command)
|
|
116
|
+
|
|
117
|
+
When you run the `/one` command in Claude Code, it automatically performs initialization checks:
|
|
118
|
+
|
|
119
|
+
**1. Git Repository Initialization**
|
|
120
|
+
|
|
121
|
+
If `.git` directory doesn't exist:
|
|
122
|
+
```bash
|
|
123
|
+
✅ Initializing git repository...
|
|
124
|
+
git init
|
|
125
|
+
git add .
|
|
126
|
+
git commit -m "chore: initialize ONE Platform repository"
|
|
127
|
+
✅ Git repository initialized
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**2. Installation Metadata Check**
|
|
131
|
+
|
|
132
|
+
The `/one` command looks for `.oneie/installation.json`:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"owner": "John Doe",
|
|
137
|
+
"organization": {
|
|
138
|
+
"name": "Acme Corp",
|
|
139
|
+
"url": "https://acme.one.ie"
|
|
140
|
+
},
|
|
141
|
+
"installationId": "acme",
|
|
142
|
+
"createdAt": "2025-10-19T12:00:00Z"
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**3. Display Context**
|
|
147
|
+
|
|
148
|
+
When found, the `/one` command displays:
|
|
149
|
+
```
|
|
150
|
+
Account: John Doe
|
|
151
|
+
Organization: Acme Corp - https://acme.one.ie
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Manual Initialization
|
|
155
|
+
|
|
156
|
+
You can also initialize explicitly using the CLI:
|
|
116
157
|
|
|
117
158
|
```bash
|
|
118
159
|
$ npx oneie init
|
|
@@ -122,6 +163,7 @@ $ npx oneie init
|
|
|
122
163
|
✅ Creating installation folder: /acme
|
|
123
164
|
✅ Mirroring ontology structure...
|
|
124
165
|
✅ Creating README.md
|
|
166
|
+
✅ Creating .oneie/installation.json
|
|
125
167
|
✅ Creating .env.local with INSTALLATION_NAME=acme
|
|
126
168
|
|
|
127
169
|
🎉 Installation initialized!
|
|
@@ -136,6 +178,8 @@ INSTALLATION_NAME=acme
|
|
|
136
178
|
PUBLIC_INSTALLATION_NAME=acme # Exposed to frontend
|
|
137
179
|
```
|
|
138
180
|
|
|
181
|
+
Installation metadata is stored in `.oneie/installation.json` for display purposes.
|
|
182
|
+
|
|
139
183
|
## Security
|
|
140
184
|
|
|
141
185
|
### Path Validation
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
feature: blog
|
|
2
|
+
extends: core
|
|
3
|
+
description: Blog and content publishing
|
|
4
|
+
|
|
5
|
+
thingTypes:
|
|
6
|
+
- name: blog_post
|
|
7
|
+
properties:
|
|
8
|
+
title: string
|
|
9
|
+
slug: string
|
|
10
|
+
content: string
|
|
11
|
+
excerpt: string
|
|
12
|
+
featuredImage: string
|
|
13
|
+
publishedAt: number
|
|
14
|
+
tags: string[]
|
|
15
|
+
category: string
|
|
16
|
+
- name: blog_category
|
|
17
|
+
properties:
|
|
18
|
+
name: string
|
|
19
|
+
slug: string
|
|
20
|
+
description: string
|
|
21
|
+
|
|
22
|
+
connectionTypes:
|
|
23
|
+
- name: posted_in
|
|
24
|
+
fromType: blog_post
|
|
25
|
+
toType: blog_category
|
|
26
|
+
|
|
27
|
+
eventTypes:
|
|
28
|
+
- name: blog_post_published
|
|
29
|
+
thingType: blog_post
|
|
30
|
+
- name: blog_post_viewed
|
|
31
|
+
thingType: blog_post
|
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
# Multi-Ontology Architecture Cheat Sheet
|
|
2
|
+
|
|
3
|
+
**Quick Reference Guide** | **Version:** 1.0.0
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Quick Commands
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Generate types from core only
|
|
11
|
+
bun run backend/scripts/generate-ontology-types.ts
|
|
12
|
+
|
|
13
|
+
# Generate types with specific features
|
|
14
|
+
PUBLIC_FEATURES="blog,shop" bun run backend/scripts/generate-ontology-types.ts
|
|
15
|
+
|
|
16
|
+
# Generate types with all features
|
|
17
|
+
PUBLIC_FEATURES="blog,shop,courses,newsletter" bun run backend/scripts/generate-ontology-types.ts
|
|
18
|
+
|
|
19
|
+
# Validate ontology YAML
|
|
20
|
+
bun run backend/scripts/validate-ontology.ts ontology-myfeature.yaml
|
|
21
|
+
|
|
22
|
+
# Run tests for a feature
|
|
23
|
+
cd backend
|
|
24
|
+
bun test tests/myfeature.test.ts
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## YAML Template
|
|
30
|
+
|
|
31
|
+
### Minimal Feature Ontology
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
feature: myfeature
|
|
35
|
+
extends: core
|
|
36
|
+
version: "1.0.0"
|
|
37
|
+
description: "Brief description of what this feature does"
|
|
38
|
+
|
|
39
|
+
thingTypes:
|
|
40
|
+
- name: my_thing
|
|
41
|
+
description: "What this thing represents"
|
|
42
|
+
properties:
|
|
43
|
+
field1: string
|
|
44
|
+
field2: number
|
|
45
|
+
field3: boolean
|
|
46
|
+
|
|
47
|
+
connectionTypes:
|
|
48
|
+
- name: my_connection
|
|
49
|
+
description: "How things relate"
|
|
50
|
+
fromType: source_type
|
|
51
|
+
toType: target_type
|
|
52
|
+
metadata:
|
|
53
|
+
extraField: string
|
|
54
|
+
|
|
55
|
+
eventTypes:
|
|
56
|
+
- name: my_event
|
|
57
|
+
description: "What action happened"
|
|
58
|
+
thingType: my_thing
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Full Feature Ontology Template
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
# Feature Name Ontology
|
|
65
|
+
# Detailed description of feature purpose and capabilities
|
|
66
|
+
|
|
67
|
+
feature: myfeature
|
|
68
|
+
extends: core
|
|
69
|
+
version: "1.0.0"
|
|
70
|
+
description: "What this feature provides"
|
|
71
|
+
author: "Your Name"
|
|
72
|
+
dependencies:
|
|
73
|
+
- otherfeat
|
|
74
|
+
|
|
75
|
+
# ============================================================================
|
|
76
|
+
# Thing Types - Entities that exist
|
|
77
|
+
# ============================================================================
|
|
78
|
+
|
|
79
|
+
thingTypes:
|
|
80
|
+
- name: my_entity
|
|
81
|
+
description: "Primary entity description"
|
|
82
|
+
properties:
|
|
83
|
+
# Core fields
|
|
84
|
+
name: string
|
|
85
|
+
description: string
|
|
86
|
+
slug: string
|
|
87
|
+
|
|
88
|
+
# Status and metadata
|
|
89
|
+
status: string # active, inactive, draft
|
|
90
|
+
createdBy: string # User ID
|
|
91
|
+
|
|
92
|
+
# Feature-specific fields
|
|
93
|
+
customField1: string
|
|
94
|
+
customField2: number
|
|
95
|
+
customField3: boolean
|
|
96
|
+
customList: string[]
|
|
97
|
+
customObject: object
|
|
98
|
+
|
|
99
|
+
example:
|
|
100
|
+
type: my_entity
|
|
101
|
+
name: "Example Entity"
|
|
102
|
+
properties:
|
|
103
|
+
name: "Example Entity"
|
|
104
|
+
status: "active"
|
|
105
|
+
customField1: "value"
|
|
106
|
+
|
|
107
|
+
- name: my_child_entity
|
|
108
|
+
description: "Related entity"
|
|
109
|
+
properties:
|
|
110
|
+
parentId: string
|
|
111
|
+
childField: string
|
|
112
|
+
|
|
113
|
+
# ============================================================================
|
|
114
|
+
# Connection Types - Relationships
|
|
115
|
+
# ============================================================================
|
|
116
|
+
|
|
117
|
+
connectionTypes:
|
|
118
|
+
- name: owns_entity
|
|
119
|
+
description: "Creator owns entity"
|
|
120
|
+
fromType: creator # From core
|
|
121
|
+
toType: my_entity
|
|
122
|
+
metadata:
|
|
123
|
+
role: string
|
|
124
|
+
permissions: string[]
|
|
125
|
+
|
|
126
|
+
- name: parent_child
|
|
127
|
+
description: "Parent-child relationship"
|
|
128
|
+
fromType: my_entity
|
|
129
|
+
toType: my_child_entity
|
|
130
|
+
metadata:
|
|
131
|
+
order: number
|
|
132
|
+
|
|
133
|
+
- name: related_to
|
|
134
|
+
description: "Generic relationship"
|
|
135
|
+
fromType: my_entity
|
|
136
|
+
toType: my_entity # Self-referential
|
|
137
|
+
metadata:
|
|
138
|
+
relationshipType: string
|
|
139
|
+
|
|
140
|
+
# ============================================================================
|
|
141
|
+
# Event Types - Actions that occur
|
|
142
|
+
# ============================================================================
|
|
143
|
+
|
|
144
|
+
eventTypes:
|
|
145
|
+
# Lifecycle events
|
|
146
|
+
- name: entity_created
|
|
147
|
+
description: "Entity was created"
|
|
148
|
+
thingType: my_entity
|
|
149
|
+
|
|
150
|
+
- name: entity_updated
|
|
151
|
+
description: "Entity was modified"
|
|
152
|
+
thingType: my_entity
|
|
153
|
+
|
|
154
|
+
- name: entity_deleted
|
|
155
|
+
description: "Entity was deleted"
|
|
156
|
+
thingType: my_entity
|
|
157
|
+
|
|
158
|
+
# Action events
|
|
159
|
+
- name: entity_activated
|
|
160
|
+
description: "Entity became active"
|
|
161
|
+
thingType: my_entity
|
|
162
|
+
|
|
163
|
+
- name: entity_viewed
|
|
164
|
+
description: "Someone viewed entity"
|
|
165
|
+
thingType: my_entity
|
|
166
|
+
|
|
167
|
+
# Interaction events
|
|
168
|
+
- name: entity_shared
|
|
169
|
+
description: "Entity was shared"
|
|
170
|
+
thingType: my_entity
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Common Code Patterns
|
|
176
|
+
|
|
177
|
+
### 1. Create Entity with Ownership
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { mutation } from '../_generated/server';
|
|
181
|
+
import { v } from 'convex/values';
|
|
182
|
+
import type { ThingType, ConnectionType, EventType } from '../types/ontology';
|
|
183
|
+
|
|
184
|
+
export const create = mutation({
|
|
185
|
+
args: {
|
|
186
|
+
groupId: v.id('groups'),
|
|
187
|
+
name: v.string(),
|
|
188
|
+
properties: v.any(),
|
|
189
|
+
},
|
|
190
|
+
handler: async (ctx, args) => {
|
|
191
|
+
const userId = await ctx.auth.getUserIdentity();
|
|
192
|
+
if (!userId) throw new Error('Unauthorized');
|
|
193
|
+
|
|
194
|
+
// 1. Create entity
|
|
195
|
+
const entityId = await ctx.db.insert('entities', {
|
|
196
|
+
groupId: args.groupId,
|
|
197
|
+
type: 'my_entity' as ThingType,
|
|
198
|
+
name: args.name,
|
|
199
|
+
properties: {
|
|
200
|
+
...args.properties,
|
|
201
|
+
createdBy: userId.tokenIdentifier,
|
|
202
|
+
},
|
|
203
|
+
status: 'active',
|
|
204
|
+
createdAt: Date.now(),
|
|
205
|
+
updatedAt: Date.now(),
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// 2. Create ownership connection
|
|
209
|
+
await ctx.db.insert('connections', {
|
|
210
|
+
groupId: args.groupId,
|
|
211
|
+
fromEntityId: userId.tokenIdentifier,
|
|
212
|
+
toEntityId: entityId,
|
|
213
|
+
relationshipType: 'owns' as ConnectionType,
|
|
214
|
+
metadata: {
|
|
215
|
+
role: 'owner',
|
|
216
|
+
permissions: ['read', 'write', 'delete'],
|
|
217
|
+
},
|
|
218
|
+
createdAt: Date.now(),
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// 3. Log creation event
|
|
222
|
+
await ctx.db.insert('events', {
|
|
223
|
+
groupId: args.groupId,
|
|
224
|
+
type: 'entity_created' as EventType,
|
|
225
|
+
actorId: userId.tokenIdentifier,
|
|
226
|
+
targetId: entityId,
|
|
227
|
+
timestamp: Date.now(),
|
|
228
|
+
metadata: {},
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
return entityId;
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### 2. Query Entities with Connections
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { query } from '../_generated/server';
|
|
240
|
+
import { v } from 'convex/values';
|
|
241
|
+
|
|
242
|
+
export const listWithOwners = query({
|
|
243
|
+
args: {
|
|
244
|
+
groupId: v.id('groups'),
|
|
245
|
+
},
|
|
246
|
+
handler: async (ctx, args) => {
|
|
247
|
+
// Get entities
|
|
248
|
+
const entities = await ctx.db
|
|
249
|
+
.query('entities')
|
|
250
|
+
.withIndex('group_type', (q) =>
|
|
251
|
+
q.eq('groupId', args.groupId).eq('type', 'my_entity')
|
|
252
|
+
)
|
|
253
|
+
.collect();
|
|
254
|
+
|
|
255
|
+
// Get owners for each entity
|
|
256
|
+
const entitiesWithOwners = await Promise.all(
|
|
257
|
+
entities.map(async (entity) => {
|
|
258
|
+
const ownership = await ctx.db
|
|
259
|
+
.query('connections')
|
|
260
|
+
.withIndex('to_type', (q) =>
|
|
261
|
+
q.eq('toEntityId', entity._id).eq('relationshipType', 'owns')
|
|
262
|
+
)
|
|
263
|
+
.first();
|
|
264
|
+
|
|
265
|
+
const owner = ownership
|
|
266
|
+
? await ctx.db.get(ownership.fromEntityId)
|
|
267
|
+
: null;
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
...entity,
|
|
271
|
+
owner,
|
|
272
|
+
ownerRole: ownership?.metadata?.role,
|
|
273
|
+
};
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
return entitiesWithOwners;
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### 3. Type Validation
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
import { isThingType, isConnectionType, isEventType } from '../types/ontology';
|
|
286
|
+
|
|
287
|
+
// Validate thing type
|
|
288
|
+
export const validateEntity = mutation({
|
|
289
|
+
args: {
|
|
290
|
+
type: v.string(),
|
|
291
|
+
},
|
|
292
|
+
handler: async (ctx, args) => {
|
|
293
|
+
if (!isThingType(args.type)) {
|
|
294
|
+
throw new Error(`Invalid entity type: ${args.type}`);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Now TypeScript knows args.type is valid
|
|
298
|
+
const entity = await ctx.db.insert('entities', {
|
|
299
|
+
type: args.type as ThingType,
|
|
300
|
+
// ...
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### 4. Feature Detection
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
import { ONTOLOGY_METADATA } from '../types/ontology';
|
|
310
|
+
|
|
311
|
+
export const getFeatures = query({
|
|
312
|
+
handler: async () => {
|
|
313
|
+
return {
|
|
314
|
+
enabled: ONTOLOGY_METADATA.features,
|
|
315
|
+
hasBlog: ONTOLOGY_METADATA.features.includes('blog'),
|
|
316
|
+
hasShop: ONTOLOGY_METADATA.features.includes('shop'),
|
|
317
|
+
counts: {
|
|
318
|
+
things: ONTOLOGY_METADATA.thingTypeCount,
|
|
319
|
+
connections: ONTOLOGY_METADATA.connectionTypeCount,
|
|
320
|
+
events: ONTOLOGY_METADATA.eventTypeCount,
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// Conditional logic
|
|
327
|
+
export const createContent = mutation({
|
|
328
|
+
handler: async (ctx, args) => {
|
|
329
|
+
const features = ONTOLOGY_METADATA.features;
|
|
330
|
+
|
|
331
|
+
if (args.type === 'blog_post' && !features.includes('blog')) {
|
|
332
|
+
throw new Error('Blog feature not enabled');
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Create entity...
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### 5. Batch Operations
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
export const batchCreate = mutation({
|
|
344
|
+
args: {
|
|
345
|
+
groupId: v.id('groups'),
|
|
346
|
+
entities: v.array(
|
|
347
|
+
v.object({
|
|
348
|
+
type: v.string(),
|
|
349
|
+
name: v.string(),
|
|
350
|
+
properties: v.any(),
|
|
351
|
+
})
|
|
352
|
+
),
|
|
353
|
+
},
|
|
354
|
+
handler: async (ctx, args) => {
|
|
355
|
+
const results = [];
|
|
356
|
+
|
|
357
|
+
for (const entity of args.entities) {
|
|
358
|
+
if (!isThingType(entity.type)) {
|
|
359
|
+
results.push({
|
|
360
|
+
name: entity.name,
|
|
361
|
+
success: false,
|
|
362
|
+
error: 'Invalid type',
|
|
363
|
+
});
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
try {
|
|
368
|
+
const id = await ctx.db.insert('entities', {
|
|
369
|
+
groupId: args.groupId,
|
|
370
|
+
type: entity.type as ThingType,
|
|
371
|
+
name: entity.name,
|
|
372
|
+
properties: entity.properties,
|
|
373
|
+
status: 'active',
|
|
374
|
+
createdAt: Date.now(),
|
|
375
|
+
updatedAt: Date.now(),
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
results.push({
|
|
379
|
+
name: entity.name,
|
|
380
|
+
success: true,
|
|
381
|
+
id,
|
|
382
|
+
});
|
|
383
|
+
} catch (error) {
|
|
384
|
+
results.push({
|
|
385
|
+
name: entity.name,
|
|
386
|
+
success: false,
|
|
387
|
+
error: (error as Error).message,
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return results;
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### 6. Analytics from Events
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
export const getAnalytics = query({
|
|
401
|
+
args: {
|
|
402
|
+
entityId: v.id('entities'),
|
|
403
|
+
days: v.optional(v.number()),
|
|
404
|
+
},
|
|
405
|
+
handler: async (ctx, args) => {
|
|
406
|
+
const since = Date.now() - (args.days || 30) * 24 * 60 * 60 * 1000;
|
|
407
|
+
|
|
408
|
+
const events = await ctx.db
|
|
409
|
+
.query('events')
|
|
410
|
+
.withIndex('target_time', (q) =>
|
|
411
|
+
q.eq('targetId', args.entityId).gte('timestamp', since)
|
|
412
|
+
)
|
|
413
|
+
.collect();
|
|
414
|
+
|
|
415
|
+
// Group by event type
|
|
416
|
+
const byType = events.reduce((acc, event) => {
|
|
417
|
+
acc[event.type] = (acc[event.type] || 0) + 1;
|
|
418
|
+
return acc;
|
|
419
|
+
}, {} as Record<string, number>);
|
|
420
|
+
|
|
421
|
+
return {
|
|
422
|
+
period: `${args.days || 30} days`,
|
|
423
|
+
totalEvents: events.length,
|
|
424
|
+
byType,
|
|
425
|
+
timeline: events.map((e) => ({
|
|
426
|
+
type: e.type,
|
|
427
|
+
timestamp: e.timestamp,
|
|
428
|
+
actor: e.actorId,
|
|
429
|
+
})),
|
|
430
|
+
};
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## Type Reference
|
|
438
|
+
|
|
439
|
+
### Generated Types
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
// Auto-generated from ontologies
|
|
443
|
+
import type {
|
|
444
|
+
ThingType, // Union of all thing types
|
|
445
|
+
ConnectionType, // Union of all connection types
|
|
446
|
+
EventType, // Union of all event types
|
|
447
|
+
} from './types/ontology';
|
|
448
|
+
|
|
449
|
+
// Type arrays
|
|
450
|
+
import {
|
|
451
|
+
THING_TYPES, // string[] of all thing types
|
|
452
|
+
CONNECTION_TYPES, // string[] of all connection types
|
|
453
|
+
EVENT_TYPES, // string[] of all event types
|
|
454
|
+
} from './types/ontology';
|
|
455
|
+
|
|
456
|
+
// Type guards
|
|
457
|
+
import {
|
|
458
|
+
isThingType, // (value: string) => boolean
|
|
459
|
+
isConnectionType, // (value: string) => boolean
|
|
460
|
+
isEventType, // (value: string) => boolean
|
|
461
|
+
} from './types/ontology';
|
|
462
|
+
|
|
463
|
+
// Metadata
|
|
464
|
+
import {
|
|
465
|
+
ONTOLOGY_METADATA // { features, generatedAt, counts }
|
|
466
|
+
} from './types/ontology';
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Database Schema Types
|
|
470
|
+
|
|
471
|
+
```typescript
|
|
472
|
+
// Convex auto-generated types
|
|
473
|
+
import type { Doc, Id } from './_generated/dataModel';
|
|
474
|
+
|
|
475
|
+
// Entity document
|
|
476
|
+
type Entity = Doc<'entities'>;
|
|
477
|
+
type EntityId = Id<'entities'>;
|
|
478
|
+
|
|
479
|
+
// Connection document
|
|
480
|
+
type Connection = Doc<'connections'>;
|
|
481
|
+
|
|
482
|
+
// Event document
|
|
483
|
+
type Event = Doc<'events'>;
|
|
484
|
+
|
|
485
|
+
// Group document
|
|
486
|
+
type Group = Doc<'groups'>;
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
## Troubleshooting
|
|
492
|
+
|
|
493
|
+
### Issue: Types not generating
|
|
494
|
+
|
|
495
|
+
**Solution:**
|
|
496
|
+
```bash
|
|
497
|
+
# Check YAML syntax
|
|
498
|
+
bun run backend/scripts/validate-ontology.ts
|
|
499
|
+
|
|
500
|
+
# Regenerate types
|
|
501
|
+
PUBLIC_FEATURES="myfeature" bun run backend/scripts/generate-ontology-types.ts
|
|
502
|
+
|
|
503
|
+
# Check output file
|
|
504
|
+
cat backend/convex/types/ontology.ts
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### Issue: Invalid type errors
|
|
508
|
+
|
|
509
|
+
**Solution:**
|
|
510
|
+
```typescript
|
|
511
|
+
// Always use type guards
|
|
512
|
+
if (!isThingType(args.type)) {
|
|
513
|
+
throw new Error(`Invalid type: ${args.type}`);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Or validate against array
|
|
517
|
+
if (!THING_TYPES.includes(args.type)) {
|
|
518
|
+
throw new Error(`Invalid type: ${args.type}`);
|
|
519
|
+
}
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### Issue: Circular dependencies
|
|
523
|
+
|
|
524
|
+
**Solution:**
|
|
525
|
+
```yaml
|
|
526
|
+
# Feature A
|
|
527
|
+
feature: featureA
|
|
528
|
+
extends: core
|
|
529
|
+
|
|
530
|
+
# Feature B
|
|
531
|
+
feature: featureB
|
|
532
|
+
extends: core
|
|
533
|
+
|
|
534
|
+
# Integration feature (extends both)
|
|
535
|
+
feature: featureAB
|
|
536
|
+
extends: featureA,featureB
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
### Issue: Missing core types
|
|
540
|
+
|
|
541
|
+
**Solution:**
|
|
542
|
+
```yaml
|
|
543
|
+
# Always extend core
|
|
544
|
+
extends: core
|
|
545
|
+
|
|
546
|
+
# Reference core types in connections
|
|
547
|
+
connectionTypes:
|
|
548
|
+
- name: my_connection
|
|
549
|
+
fromType: creator # From core
|
|
550
|
+
toType: my_thing # From this feature
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
### Issue: Performance with many types
|
|
554
|
+
|
|
555
|
+
**Solution:**
|
|
556
|
+
```typescript
|
|
557
|
+
// Cache type sets for O(1) lookup
|
|
558
|
+
const THING_TYPE_SET = new Set(THING_TYPES);
|
|
559
|
+
|
|
560
|
+
export function isValidType(type: string): boolean {
|
|
561
|
+
return THING_TYPE_SET.has(type);
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
---
|
|
566
|
+
|
|
567
|
+
## Best Practices
|
|
568
|
+
|
|
569
|
+
1. **Always extend core** - Every feature should `extends: core`
|
|
570
|
+
2. **Use descriptive names** - `blog_post` not `post`
|
|
571
|
+
3. **Add examples** - Include example objects in YAML
|
|
572
|
+
4. **Validate inputs** - Use type guards for runtime validation
|
|
573
|
+
5. **Log events** - Track all significant actions
|
|
574
|
+
6. **Test thoroughly** - Write tests for mutations and queries
|
|
575
|
+
7. **Version properly** - Use semantic versioning (1.0.0)
|
|
576
|
+
8. **Document metadata** - Explain what goes in metadata fields
|
|
577
|
+
9. **Keep features focused** - One feature, one purpose
|
|
578
|
+
10. **Compose features** - Create integration features for cross-feature logic
|
|
579
|
+
|
|
580
|
+
---
|
|
581
|
+
|
|
582
|
+
## Quick Links
|
|
583
|
+
|
|
584
|
+
- [Complete Tutorial](/one/knowledge/ontology-tutorial.md)
|
|
585
|
+
- [Ontology Specification](/one/knowledge/ontology.md)
|
|
586
|
+
- [Engineering Guide](/one/knowledge/ontology-engineering.md)
|
|
587
|
+
- [Example Code](/backend/examples/ontology-types-usage.ts)
|
|
588
|
+
|
|
589
|
+
---
|
|
590
|
+
|
|
591
|
+
**Last Updated:** 2025-01-20
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
feature: community
|
|
2
|
+
extends: core
|
|
3
|
+
description: Forums, discussions, and direct messaging
|
|
4
|
+
|
|
5
|
+
thingTypes:
|
|
6
|
+
- name: forum_topic
|
|
7
|
+
properties:
|
|
8
|
+
title: string
|
|
9
|
+
slug: string
|
|
10
|
+
content: string
|
|
11
|
+
isPinned: boolean
|
|
12
|
+
isLocked: boolean
|
|
13
|
+
viewCount: number
|
|
14
|
+
replyCount: number
|
|
15
|
+
- name: forum_reply
|
|
16
|
+
properties:
|
|
17
|
+
content: string
|
|
18
|
+
topicId: string
|
|
19
|
+
replyToId: string
|
|
20
|
+
- name: direct_message
|
|
21
|
+
properties:
|
|
22
|
+
content: string
|
|
23
|
+
recipientId: string
|
|
24
|
+
readAt: number
|
|
25
|
+
|
|
26
|
+
connectionTypes:
|
|
27
|
+
- name: follows
|
|
28
|
+
fromType: user
|
|
29
|
+
toType: user
|
|
30
|
+
- name: member_of
|
|
31
|
+
fromType: user
|
|
32
|
+
toType: group
|
|
33
|
+
|
|
34
|
+
eventTypes:
|
|
35
|
+
- name: topic_created
|
|
36
|
+
thingType: forum_topic
|
|
37
|
+
- name: topic_replied
|
|
38
|
+
thingType: forum_reply
|
|
39
|
+
- name: message_sent
|
|
40
|
+
thingType: direct_message
|
|
41
|
+
- name: user_followed
|
|
42
|
+
thingType: user
|