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.
Files changed (143) hide show
  1. package/.claude/agents/agent-director.md +902 -22
  2. package/.claude/agents/agent-onboard-example-output.md +600 -0
  3. package/.claude/agents/agent-onboard.md +576 -0
  4. package/.claude/commands/ONBOARDING_ENHANCEMENT_SUMMARY.md +266 -0
  5. package/.claude/commands/one.md +411 -10
  6. package/.claude/commands/release.md +64 -3
  7. package/CLAUDE.md +55 -69
  8. package/dist/commands/init.d.ts +5 -6
  9. package/dist/commands/init.d.ts.map +1 -1
  10. package/dist/commands/init.js +101 -101
  11. package/dist/commands/init.js.map +1 -1
  12. package/dist/index.js +6 -5
  13. package/dist/index.js.map +1 -1
  14. package/dist/utils/installation-setup.d.ts +24 -1
  15. package/dist/utils/installation-setup.d.ts.map +1 -1
  16. package/dist/utils/installation-setup.js +85 -1
  17. package/dist/utils/installation-setup.js.map +1 -1
  18. package/dist/utils/launch-claude.d.ts +6 -0
  19. package/dist/utils/launch-claude.d.ts.map +1 -0
  20. package/dist/utils/launch-claude.js +51 -0
  21. package/dist/utils/launch-claude.js.map +1 -0
  22. package/dist/utils/validation.d.ts +48 -0
  23. package/dist/utils/validation.d.ts.map +1 -0
  24. package/dist/utils/validation.js +73 -0
  25. package/dist/utils/validation.js.map +1 -0
  26. package/folders.yaml +1 -1
  27. package/one/.obsidian/app.json +8 -0
  28. package/one/.obsidian/appearance.json +1 -0
  29. package/one/.obsidian/community-plugins.json +3 -0
  30. package/one/.obsidian/core-plugins.json +33 -0
  31. package/one/.obsidian/plugins/easy-bake/main.js +361 -0
  32. package/one/.obsidian/plugins/easy-bake/manifest.json +11 -0
  33. package/one/.obsidian/plugins/easy-bake/styles.css +10 -0
  34. package/one/.obsidian/workspace.json +240 -0
  35. package/one/connections/workflow-onboarding.md +683 -0
  36. package/one/events/CART-DRAWER-INTEGRATION-GUIDE.md +354 -0
  37. package/one/events/CRITICAL-FIXES-COMPLETE.md +504 -0
  38. package/one/events/DEPLOYMENT.md +178 -0
  39. package/one/events/ECOMMERCE-DEMO-PLAN.md +225 -0
  40. package/one/events/ECOMMERCE-LIVE-DEMO.md +363 -0
  41. package/one/events/ECOMMERCE-TEMPLATE-COMPLETE.md +735 -0
  42. package/one/events/ECOMMERCE-TEMPLATES-SUMMARY.md +923 -0
  43. package/one/events/GRADIENT-TEXT-PERMANENT-FIX.md +223 -0
  44. package/one/events/HANDOFF.md +313 -0
  45. package/one/events/IMPLEMENTATION-SUMMARY-FINAL.md +503 -0
  46. package/one/events/IMPLEMENTATION_SUMMARY.md +529 -0
  47. package/one/events/LANDING-PAGE-EXAMPLE-OUTPUT.md +666 -0
  48. package/one/events/LANDING-PAGE-IMPLEMENTATION.md +642 -0
  49. package/one/events/LANDING-PAGE-QUICKSTART.md +407 -0
  50. package/one/events/MULTI-ONTOLOGY-COMPLETE-GUIDE.md +1627 -0
  51. package/one/events/MULTI-ONTOLOGY-IMPLEMENTATION-COMPLETE.md +573 -0
  52. package/one/events/ONBOARDING-IMPLEMENTATION-COMPLETE copy.md +398 -0
  53. package/one/events/ONTOLOGY-TUTORIALS-SUMMARY.md +525 -0
  54. package/one/events/ONTOLOGY-TYPE-GENERATOR-SUMMARY.md +455 -0
  55. package/one/events/ONTOLOGY_DISCOVERY_IMPLEMENTATION.md +486 -0
  56. package/one/events/ONTOLOGY_DISCOVERY_QUICKSTART.md +203 -0
  57. package/one/events/SECURITY-AUDIT-FIXES.md +376 -0
  58. package/one/events/SECURITY-SCAN-COMPLETE.md +281 -0
  59. package/one/events/SHOP-BUILD-STATUS.md +114 -0
  60. package/one/events/SHOP-PREMIUM-UPDATE.md +149 -0
  61. package/one/events/SITE-WIDE-GRADIENT-FIX.md +299 -0
  62. package/one/events/STORE-PRODUCTION-READY-STATUS.md +359 -0
  63. package/one/events/STRIPE-PAYMENT-METHODS-GUIDE.md +429 -0
  64. package/one/events/agent-director-enhancement-summary.md +386 -0
  65. package/one/events/agent-onboard-implementation-summary.md +457 -0
  66. package/one/events/clean-agent-ontology-cleanup-report.md +353 -0
  67. package/one/events/landing-page-generator.md +458 -0
  68. package/one/events/onboarding-implementation-complete.md +505 -0
  69. package/one/events/release.md +254 -0
  70. package/one/events/separate-implementation-status.md +537 -0
  71. package/one/groups/nine-padle-contents.baked.md +1252 -0
  72. package/one/groups/nine-padle-contents.md +6 -0
  73. package/one/knowledge/100-inference-quick-reference.md +431 -0
  74. package/one/knowledge/agent-onboard-usage.md +612 -0
  75. package/one/knowledge/cli-claude-handoff.md +718 -0
  76. package/one/knowledge/installation-folders.md +45 -1
  77. package/one/knowledge/ontology-blog.yaml +31 -0
  78. package/one/knowledge/ontology-cheatsheet.md +591 -0
  79. package/one/knowledge/ontology-community.yaml +42 -0
  80. package/one/knowledge/ontology-core-universal.md +722 -0
  81. package/one/knowledge/ontology-core.yaml +50 -0
  82. package/one/knowledge/ontology-courses.yaml +53 -0
  83. package/one/knowledge/ontology-creator.md +376 -0
  84. package/one/knowledge/ontology-developer-guide.md +789 -0
  85. package/one/knowledge/ontology-education.md +920 -0
  86. package/one/knowledge/ontology-index.md +354 -0
  87. package/one/knowledge/ontology-migration-guide.md +811 -0
  88. package/one/knowledge/ontology-minimal.yaml +1 -1
  89. package/one/knowledge/ontology-portfolio.yaml +31 -0
  90. package/one/knowledge/ontology-quickstart.md +576 -0
  91. package/one/knowledge/ontology-shop.yaml +121 -0
  92. package/one/knowledge/ontology-tokens.yaml +32 -0
  93. package/one/knowledge/ontology-tutorial.md +434 -0
  94. package/one/knowledge/ontology-video-script.md +890 -0
  95. package/one/things/docs/ecommerce/ARCHITECTURE-DIAGRAM.md +467 -0
  96. package/one/things/docs/ecommerce/CONVERSION-ELEMENTS-IMPLEMENTATION.md +408 -0
  97. package/one/things/docs/ecommerce/CONVERSION-ELEMENTS-SUMMARY.md +369 -0
  98. package/one/things/docs/ecommerce/CONVERSION-UX-IMPLEMENTATION-SUMMARY.md +396 -0
  99. package/one/things/docs/ecommerce/FEATURE-SUMMARY.md +468 -0
  100. package/one/things/docs/ecommerce/IMPLEMENTATION-NOTES.md +582 -0
  101. package/one/things/docs/ecommerce/INTEGRATION-EXAMPLE.md +449 -0
  102. package/one/things/docs/ecommerce/QUICK-START.md +368 -0
  103. package/one/things/docs/ecommerce/URGENCY-IMPLEMENTATION-SUMMARY.md +498 -0
  104. package/one/things/docs/ecommerce/URGENCY-QUICK-REFERENCE.md +237 -0
  105. package/one/things/docs/ecommerce/USAGE-EXAMPLE.astro +171 -0
  106. package/one/things/docs/ecommerce/demo.astro +309 -0
  107. package/one/things/plans/agent-director-100-inference-plans.md +410 -0
  108. package/one/things/plans/dual-website-strategy.md +612 -0
  109. package/one/things/plans/feature-based-sites.md +821 -0
  110. package/one/things/plans/multi-ontology-architecture.md +836 -0
  111. package/one/things/plans/onboarding.md +32 -0
  112. package/one/things/plans/separate.md +15 -17
  113. package/one/things/plans/start-new.md +738 -0
  114. package/one/things/templates.md +254 -0
  115. package/one/things/todo.md +23 -5
  116. package/package.json +2 -2
  117. package/one/things/claude/hooks/agent-hook-manager.js +0 -525
  118. package/one/things/claude/hooks/agent-load-balancer.js +0 -271
  119. package/one/things/claude/hooks/agent-request-interceptor.js +0 -70
  120. package/one/things/claude/hooks/cascade-feedback.js +0 -297
  121. package/one/things/claude/hooks/cascade-integration-hooks.js +0 -648
  122. package/one/things/claude/hooks/continuous-improvement-monitor.js +0 -510
  123. package/one/things/claude/hooks/file-organization-engine.js +0 -427
  124. package/one/things/claude/hooks/file-organization-monitor.js +0 -269
  125. package/one/things/claude/hooks/hook-config-manager.js +0 -202
  126. package/one/things/claude/hooks/hook-orchestrator.js +0 -662
  127. package/one/things/claude/hooks/hook-performance-report.js +0 -120
  128. package/one/things/claude/hooks/mcp-cascade-integration.js +0 -816
  129. package/one/things/claude/hooks/memory-optimizer.js +0 -510
  130. package/one/things/claude/hooks/ontology-compliance.js +0 -394
  131. package/one/things/claude/hooks/ontology-hook-manager.js +0 -316
  132. package/one/things/claude/hooks/ontology-validation-engine.js +0 -317
  133. package/one/things/claude/hooks/performance-monitoring-hook.js +0 -422
  134. package/one/things/claude/hooks/quality-scoring-engine.js +0 -834
  135. package/one/things/claude/hooks/simple-load-balancer.js +0 -238
  136. package/one/things/claude/hooks/startup-optimizer.js +0 -625
  137. package/one/things/claude/hooks/story-scoring-system.js +0 -445
  138. package/one/things/claude/hooks/story-validation-engine.js +0 -473
  139. package/one/things/claude/hooks/structure-synchronizer.js +0 -194
  140. package/one/things/claude/hooks/sub-agent-output-validator.js +0 -647
  141. package/one/things/claude/hooks/sub-agent-validation-hook.js +0 -343
  142. package/one/things/claude/hooks/trinity-validation-system.js +0 -392
  143. package/one/things/plans/organizations-to-groups.md +0 -705
@@ -0,0 +1,789 @@
1
+ # Multi-Ontology Architecture: Developer Guide
2
+
3
+ **Version:** 1.0.0
4
+ **Last Updated:** 2025-10-20
5
+ **Status:** Complete
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [Architecture Overview](#architecture-overview)
10
+ 2. [YAML Format Specification](#yaml-format-specification)
11
+ 3. [Type Generation Internals](#type-generation-internals)
12
+ 4. [Best Practices](#best-practices)
13
+ 5. [Advanced Patterns](#advanced-patterns)
14
+ 6. [Performance Optimization](#performance-optimization)
15
+ 7. [Testing Strategies](#testing-strategies)
16
+
17
+ ---
18
+
19
+ ## Architecture Overview
20
+
21
+ ### The Problem: Schema Bloat
22
+
23
+ Traditional platforms hardcode ALL possible entity types into a single massive schema:
24
+
25
+ ```typescript
26
+ // ❌ Traditional approach
27
+ type EntityType =
28
+ | 'user'
29
+ | 'page'
30
+ | 'blog_post'
31
+ | 'product'
32
+ | 'course'
33
+ | 'portfolio_item'
34
+ | 'video'
35
+ | 'podcast'
36
+ | 'nft'
37
+ | 'token'
38
+ | ... // 100+ more types
39
+ ```
40
+
41
+ **Problems:**
42
+
43
+ - **Schema bloat**: Every installation loads types they'll never use
44
+ - **Tight coupling**: Adding a new feature requires changing core
45
+ - **Slow queries**: Indexes become massive and unwieldy
46
+ - **Poor DX**: Autocomplete suggests 100+ irrelevant types
47
+ - **Multi-backend impossible**: Can't run different backends with different features
48
+
49
+ ### The Solution: Composable Ontologies
50
+
51
+ The multi-ontology architecture uses **feature-specific YAML files** that compose at runtime:
52
+
53
+ ```
54
+ ┌─────────────────────────────────────┐
55
+ │ ontology-core.yaml (always loaded) │
56
+ │ - page, user, file, link, note │
57
+ └─────────────────────────────────────┘
58
+ ↓
59
+ ┌─────────────────────────────────────┐
60
+ │ ontology-blog.yaml (if enabled) │
61
+ │ - blog_post, blog_category │
62
+ │ extends: core │
63
+ └─────────────────────────────────────┘
64
+ ↓
65
+ ┌─────────────────────────────────────┐
66
+ │ ontology-shop.yaml (if enabled) │
67
+ │ - product, order, cart, payment │
68
+ │ extends: core │
69
+ └─────────────────────────────────────┘
70
+ ↓
71
+ ┌─────────────────────────────────────┐
72
+ │ Generated TypeScript Types │
73
+ │ - Only includes enabled features │
74
+ │ - Full type safety │
75
+ │ - Validation functions │
76
+ └─────────────────────────────────────┘
77
+ ```
78
+
79
+ **Benefits:**
80
+
81
+ - **Load only what you need**: Core + enabled features
82
+ - **Type safety**: Full TypeScript validation
83
+ - **Loose coupling**: Features are independent
84
+ - **Multi-backend support**: Different backends, different features
85
+ - **Better DX**: Autocomplete shows only relevant types
86
+
87
+ ---
88
+
89
+ ## YAML Format Specification
90
+
91
+ ### File Structure
92
+
93
+ ```yaml
94
+ feature: {feature-name} # REQUIRED: Feature identifier (lowercase, no spaces)
95
+ extends: {base-feature} | null # OPTIONAL: Base feature to inherit from
96
+ description: {description} # REQUIRED: Human-readable description
97
+
98
+ thingTypes: # OPTIONAL: Entity types this feature adds
99
+ - name: {type-name} # REQUIRED: Type name (lowercase_underscore)
100
+ properties: # REQUIRED: Property definitions
101
+ {field}: {type} # field: string | number | boolean | object | string[] | number[]
102
+
103
+ connectionTypes: # OPTIONAL: Relationship types this feature adds
104
+ - name: {type-name} # REQUIRED: Connection name (lowercase_underscore)
105
+ fromType: {thing-type} | '*' # REQUIRED: Source thing type (* = any)
106
+ toType: {thing-type} | '*' # REQUIRED: Target thing type (* = any)
107
+
108
+ eventTypes: # OPTIONAL: Event types this feature adds
109
+ - name: {event-name} # REQUIRED: Event name (past tense, lowercase_underscore)
110
+ thingType: {thing-type} | '*' # REQUIRED: Thing type this event applies to (* = any)
111
+ ```
112
+
113
+ ### Naming Conventions
114
+
115
+ **Feature Names:**
116
+ - Lowercase, no spaces
117
+ - Use hyphens for multi-word features
118
+ - Examples: `core`, `blog`, `shop`, `social-media`
119
+
120
+ **Thing Type Names:**
121
+ - Lowercase with underscores
122
+ - Singular nouns
123
+ - Examples: `blog_post`, `product`, `user`, `shopping_cart`
124
+
125
+ **Connection Type Names:**
126
+ - Lowercase with underscores
127
+ - Action verbs (present tense)
128
+ - Examples: `created_by`, `posted_in`, `purchased`, `in_stock`
129
+
130
+ **Event Type Names:**
131
+ - Lowercase with underscores
132
+ - Past tense verbs
133
+ - Examples: `blog_post_published`, `product_created`, `order_placed`
134
+
135
+ ### Property Types
136
+
137
+ **Primitive Types:**
138
+
139
+ ```yaml
140
+ properties:
141
+ name: string # Text
142
+ age: number # Integer or float
143
+ active: boolean # true/false
144
+ metadata: object # JSON object (any structure)
145
+ ```
146
+
147
+ **Array Types:**
148
+
149
+ ```yaml
150
+ properties:
151
+ tags: string[] # Array of strings
152
+ scores: number[] # Array of numbers
153
+ items: object[] # Array of objects (not validated)
154
+ ```
155
+
156
+ **Complex Types:**
157
+
158
+ For complex nested structures, use `object`:
159
+
160
+ ```yaml
161
+ properties:
162
+ address: object # { street, city, zip, country }
163
+ settings: object # { theme, language, notifications }
164
+ ```
165
+
166
+ > **Note:** Object properties are not validated by the type system. Validation happens at runtime in mutation handlers.
167
+
168
+ ### Inheritance with `extends`
169
+
170
+ Features can inherit types from a base feature:
171
+
172
+ ```yaml
173
+ # ontology-blog.yaml
174
+ feature: blog
175
+ extends: core # Inherits: page, user, file, link, note
176
+ description: Blog and content publishing
177
+
178
+ thingTypes:
179
+ - name: blog_post # ✅ Can use inherited types
180
+ properties:
181
+ authorId: string # ✅ References 'user' from core
182
+ ```
183
+
184
+ **Inheritance Rules:**
185
+
186
+ 1. **Transitive:** If `portfolio` extends `blog` and `blog` extends `core`, portfolio gets all types from both
187
+ 2. **No circular dependencies:** `blog → portfolio → blog` will error
188
+ 3. **No override:** You can't redefine types from base features
189
+
190
+ ---
191
+
192
+ ## Type Generation Internals
193
+
194
+ ### Generation Script: `scripts/generate-ontology-types.ts`
195
+
196
+ The type generator:
197
+
198
+ 1. **Load enabled features** from `PUBLIC_FEATURES` environment variable
199
+ 2. **Read YAML files** from `/one/knowledge/ontology-{feature}.yaml`
200
+ 3. **Resolve dependencies** (handle `extends` relationships)
201
+ 4. **Merge types** from all enabled features
202
+ 5. **Generate TypeScript** code with validation functions
203
+ 6. **Write output** to `convex/types/ontology.ts`
204
+
205
+ ### Generated Code Structure
206
+
207
+ The generator produces:
208
+
209
+ ```typescript
210
+ // convex/types/ontology.ts
211
+
212
+ // 1. Type unions
213
+ export type ThingType = 'page' | 'user' | 'blog_post' | 'product' | ...;
214
+ export type ConnectionType = 'created_by' | 'posted_in' | ...;
215
+ export type EventType = 'thing_created' | 'blog_post_published' | ...;
216
+
217
+ // 2. Constant arrays
218
+ export const THING_TYPES: readonly ThingType[] = ['page', 'user', ...];
219
+ export const CONNECTION_TYPES: readonly ConnectionType[] = ['created_by', ...];
220
+ export const EVENT_TYPES: readonly EventType[] = ['thing_created', ...];
221
+
222
+ // 3. Type guards
223
+ export function isThingType(type: string): type is ThingType {
224
+ return THING_TYPES.includes(type as ThingType);
225
+ }
226
+
227
+ export function isConnectionType(type: string): type is ConnectionType {
228
+ return CONNECTION_TYPES.includes(type as ConnectionType);
229
+ }
230
+
231
+ export function isEventType(type: string): type is EventType {
232
+ return EVENT_TYPES.includes(type as EventType);
233
+ }
234
+
235
+ // 4. Feature helpers
236
+ export const ENABLED_FEATURES = ['core', 'blog', 'shop'];
237
+
238
+ export function hasFeature(feature: string): boolean {
239
+ return ENABLED_FEATURES.includes(feature);
240
+ }
241
+
242
+ // 5. Schema metadata
243
+ export const ONTOLOGY_SCHEMA = {
244
+ features: {
245
+ core: { thingTypes: ['page', 'user'], connectionTypes: [...], eventTypes: [...] },
246
+ blog: { thingTypes: ['blog_post'], connectionTypes: [...], eventTypes: [...] },
247
+ // ...
248
+ }
249
+ };
250
+
251
+ export function getThingTypeSchema(type: ThingType): ThingTypeSchema | undefined {
252
+ // Returns full schema for a thing type
253
+ }
254
+ ```
255
+
256
+ ### Dependency Resolution Algorithm
257
+
258
+ ```typescript
259
+ function resolveFeatureDependencies(features: string[]): string[] {
260
+ const resolved = new Set<string>();
261
+ const visited = new Set<string>();
262
+
263
+ function visit(feature: string, path: string[] = []) {
264
+ // Detect circular dependencies
265
+ if (path.includes(feature)) {
266
+ throw new Error(`Circular dependency: ${path.join(' → ')} → ${feature}`);
267
+ }
268
+
269
+ // Skip if already resolved
270
+ if (resolved.has(feature)) return;
271
+
272
+ // Mark as visited
273
+ visited.add(feature);
274
+
275
+ // Load feature YAML
276
+ const ontology = loadOntologyYAML(feature);
277
+
278
+ // Resolve parent first (depth-first)
279
+ if (ontology.extends) {
280
+ visit(ontology.extends, [...path, feature]);
281
+ }
282
+
283
+ // Add this feature
284
+ resolved.add(feature);
285
+ }
286
+
287
+ // Visit all enabled features
288
+ for (const feature of features) {
289
+ visit(feature);
290
+ }
291
+
292
+ return Array.from(resolved);
293
+ }
294
+ ```
295
+
296
+ **Example:**
297
+
298
+ ```
299
+ Enabled features: ['blog', 'shop', 'portfolio']
300
+
301
+ Dependency tree:
302
+ blog → core
303
+ shop → core
304
+ portfolio → blog → core
305
+
306
+ Resolved order: ['core', 'blog', 'shop', 'portfolio']
307
+ ```
308
+
309
+ ---
310
+
311
+ ## Best Practices
312
+
313
+ ### 1. Keep Features Focused
314
+
315
+ **✅ Good:**
316
+
317
+ ```yaml
318
+ # ontology-blog.yaml
319
+ feature: blog
320
+ thingTypes:
321
+ - name: blog_post
322
+ - name: blog_category
323
+ - name: blog_tag
324
+ ```
325
+
326
+ **❌ Bad:**
327
+
328
+ ```yaml
329
+ # ontology-blog.yaml (bloated!)
330
+ feature: blog
331
+ thingTypes:
332
+ - name: blog_post
333
+ - name: blog_category
334
+ - name: product # ❌ Wrong feature!
335
+ - name: shopping_cart # ❌ Wrong feature!
336
+ ```
337
+
338
+ **Guideline:** If a type doesn't make sense without the feature, it belongs in that feature.
339
+
340
+ ---
341
+
342
+ ### 2. Use Inheritance Wisely
343
+
344
+ **✅ Good:**
345
+
346
+ ```yaml
347
+ # ontology-advanced-blog.yaml
348
+ feature: advanced-blog
349
+ extends: blog # ✅ Builds on top of blog
350
+ thingTypes:
351
+ - name: blog_series
352
+ - name: blog_newsletter
353
+ ```
354
+
355
+ **❌ Bad:**
356
+
357
+ ```yaml
358
+ # ontology-products.yaml
359
+ feature: products
360
+ extends: blog # ❌ Products have nothing to do with blog!
361
+ ```
362
+
363
+ **Guideline:** Only extend features that are semantically related.
364
+
365
+ ---
366
+
367
+ ### 3. Define Properties Exhaustively
368
+
369
+ **✅ Good:**
370
+
371
+ ```yaml
372
+ thingTypes:
373
+ - name: product
374
+ properties:
375
+ name: string
376
+ sku: string
377
+ price: number
378
+ inventory: number
379
+ description: string
380
+ images: string[]
381
+ status: string
382
+ createdAt: number
383
+ updatedAt: number
384
+ ```
385
+
386
+ **❌ Bad:**
387
+
388
+ ```yaml
389
+ thingTypes:
390
+ - name: product
391
+ properties:
392
+ data: object # ❌ Too vague!
393
+ ```
394
+
395
+ **Guideline:** Be explicit about properties. Use `object` only for truly dynamic data.
396
+
397
+ ---
398
+
399
+ ### 4. Use Semantic Connection Names
400
+
401
+ **✅ Good:**
402
+
403
+ ```yaml
404
+ connectionTypes:
405
+ - name: purchased # ✅ Clear action
406
+ fromType: user
407
+ toType: product
408
+
409
+ - name: in_cart # ✅ Clear state
410
+ fromType: user
411
+ toType: product
412
+ ```
413
+
414
+ **❌ Bad:**
415
+
416
+ ```yaml
417
+ connectionTypes:
418
+ - name: user_product # ❌ Too vague!
419
+ fromType: user
420
+ toType: product
421
+ ```
422
+
423
+ **Guideline:** Connection names should describe the relationship clearly.
424
+
425
+ ---
426
+
427
+ ### 5. Use Past Tense for Events
428
+
429
+ **✅ Good:**
430
+
431
+ ```yaml
432
+ eventTypes:
433
+ - name: product_created
434
+ - name: order_placed
435
+ - name: payment_processed
436
+ ```
437
+
438
+ **❌ Bad:**
439
+
440
+ ```yaml
441
+ eventTypes:
442
+ - name: create_product # ❌ Present tense!
443
+ - name: place_order # ❌ Imperative!
444
+ ```
445
+
446
+ **Guideline:** Events describe what **happened** (past tense).
447
+
448
+ ---
449
+
450
+ ## Advanced Patterns
451
+
452
+ ### Pattern 1: Multi-Backend Support
453
+
454
+ Run different backends with different feature sets:
455
+
456
+ ```bash
457
+ # Backend A (blog-focused)
458
+ PUBLIC_FEATURES="core,blog,portfolio"
459
+
460
+ # Backend B (e-commerce focused)
461
+ PUBLIC_FEATURES="core,shop,payments,inventory"
462
+
463
+ # Backend C (minimal)
464
+ PUBLIC_FEATURES="core"
465
+ ```
466
+
467
+ Each backend generates types for only its enabled features!
468
+
469
+ ---
470
+
471
+ ### Pattern 2: Feature Flags with Runtime Checks
472
+
473
+ ```typescript
474
+ import { hasFeature } from './types/ontology';
475
+
476
+ export const createBlogPost = mutation({
477
+ handler: async (ctx, args) => {
478
+ // Runtime check
479
+ if (!hasFeature('blog')) {
480
+ throw new Error('Blog feature not enabled');
481
+ }
482
+
483
+ // Type-safe (TypeScript knows 'blog_post' exists)
484
+ await ctx.db.insert('things', {
485
+ type: 'blog_post',
486
+ // ...
487
+ });
488
+ },
489
+ });
490
+ ```
491
+
492
+ ---
493
+
494
+ ### Pattern 3: Versioned Ontologies
495
+
496
+ Support multiple versions of the same feature:
497
+
498
+ ```yaml
499
+ # ontology-blog-v1.yaml
500
+ feature: blog-v1
501
+ extends: core
502
+ thingTypes:
503
+ - name: blog_post_v1
504
+
505
+ # ontology-blog-v2.yaml
506
+ feature: blog-v2
507
+ extends: core
508
+ thingTypes:
509
+ - name: blog_post_v2
510
+ properties:
511
+ # New fields
512
+ ```
513
+
514
+ Enable one or both:
515
+
516
+ ```bash
517
+ PUBLIC_FEATURES="core,blog-v1,blog-v2"
518
+ ```
519
+
520
+ ---
521
+
522
+ ### Pattern 4: Conditional Type Loading
523
+
524
+ ```typescript
525
+ // Load types dynamically based on environment
526
+ const features = process.env.PUBLIC_FEATURES?.split(',') || ['core'];
527
+
528
+ if (features.includes('blog')) {
529
+ // Blog-specific initialization
530
+ }
531
+ ```
532
+
533
+ ---
534
+
535
+ ### Pattern 5: Type Composition
536
+
537
+ Combine multiple features to build complex applications:
538
+
539
+ ```yaml
540
+ # ontology-marketplace.yaml
541
+ feature: marketplace
542
+ extends: shop
543
+ description: Multi-vendor marketplace (combines shop + vendors)
544
+
545
+ thingTypes:
546
+ - name: vendor
547
+ - name: vendor_product # Product with vendor info
548
+
549
+ connectionTypes:
550
+ - name: sold_by
551
+ fromType: vendor_product
552
+ toType: vendor
553
+ ```
554
+
555
+ ---
556
+
557
+ ## Performance Optimization
558
+
559
+ ### 1. Minimize Enabled Features
560
+
561
+ Only enable features you actually use:
562
+
563
+ ```bash
564
+ # ❌ Loading everything (slow)
565
+ PUBLIC_FEATURES="core,blog,shop,courses,portfolio,social,videos,podcasts,nft,tokens"
566
+
567
+ # ✅ Load only what you need (fast)
568
+ PUBLIC_FEATURES="core,blog"
569
+ ```
570
+
571
+ **Impact:**
572
+ - Smaller TypeScript bundle
573
+ - Faster type checking
574
+ - Fewer database indexes
575
+
576
+ ---
577
+
578
+ ### 2. Use Wildcard Types Sparingly
579
+
580
+ ```yaml
581
+ # ❌ Wildcard creates many indexes
582
+ connectionTypes:
583
+ - name: viewed_by
584
+ fromType: '*' # Creates index for EVERY thing type
585
+ toType: user
586
+
587
+ # ✅ Be specific
588
+ connectionTypes:
589
+ - name: viewed_by
590
+ fromType: blog_post # Only blog_post → user
591
+ toType: user
592
+ ```
593
+
594
+ ---
595
+
596
+ ### 3. Cache Generated Types
597
+
598
+ The generated `ontology.ts` file is deterministic. Cache it:
599
+
600
+ ```typescript
601
+ // Check if types are up-to-date
602
+ const hash = hashFile('/one/knowledge/ontology-*.yaml');
603
+ if (cachedHash === hash) {
604
+ console.log('Types are up-to-date');
605
+ return;
606
+ }
607
+
608
+ // Regenerate only if changed
609
+ generateOntologyTypes();
610
+ ```
611
+
612
+ ---
613
+
614
+ ### 4. Lazy Load Feature Validators
615
+
616
+ Don't load validators for disabled features:
617
+
618
+ ```typescript
619
+ // ❌ Load all validators upfront
620
+ import { validateBlogPost } from './validators/blog';
621
+ import { validateProduct } from './validators/shop';
622
+
623
+ // ✅ Lazy load only when needed
624
+ const validators = {
625
+ get blog_post() {
626
+ if (!hasFeature('blog')) throw new Error('Blog not enabled');
627
+ return require('./validators/blog').validateBlogPost;
628
+ },
629
+ get product() {
630
+ if (!hasFeature('shop')) throw new Error('Shop not enabled');
631
+ return require('./validators/shop').validateProduct;
632
+ },
633
+ };
634
+ ```
635
+
636
+ ---
637
+
638
+ ## Testing Strategies
639
+
640
+ ### 1. Test Ontology Loading
641
+
642
+ ```typescript
643
+ import { describe, it, expect } from 'bun:test';
644
+ import { loadOntology } from './scripts/generate-ontology-types';
645
+
646
+ describe('Ontology Loading', () => {
647
+ it('should load core ontology', () => {
648
+ const core = loadOntology('core');
649
+ expect(core.thingTypes).toContain('page');
650
+ expect(core.thingTypes).toContain('user');
651
+ });
652
+
653
+ it('should resolve dependencies', () => {
654
+ const features = ['blog', 'shop'];
655
+ const resolved = resolveFeatureDependencies(features);
656
+ expect(resolved).toEqual(['core', 'blog', 'shop']);
657
+ });
658
+
659
+ it('should detect circular dependencies', () => {
660
+ expect(() => {
661
+ resolveFeatureDependencies(['circular-a', 'circular-b']);
662
+ }).toThrow('Circular dependency');
663
+ });
664
+ });
665
+ ```
666
+
667
+ ---
668
+
669
+ ### 2. Test Type Guards
670
+
671
+ ```typescript
672
+ describe('Type Guards', () => {
673
+ it('should validate thing types', () => {
674
+ expect(isThingType('blog_post')).toBe(true);
675
+ expect(isThingType('invalid')).toBe(false);
676
+ });
677
+
678
+ it('should validate connection types', () => {
679
+ expect(isConnectionType('created_by')).toBe(true);
680
+ expect(isConnectionType('invalid')).toBe(false);
681
+ });
682
+
683
+ it('should validate event types', () => {
684
+ expect(isEventType('thing_created')).toBe(true);
685
+ expect(isEventType('invalid')).toBe(false);
686
+ });
687
+ });
688
+ ```
689
+
690
+ ---
691
+
692
+ ### 3. Test Feature Flags
693
+
694
+ ```typescript
695
+ describe('Feature Flags', () => {
696
+ it('should detect enabled features', () => {
697
+ process.env.PUBLIC_FEATURES = 'core,blog';
698
+ expect(hasFeature('blog')).toBe(true);
699
+ expect(hasFeature('shop')).toBe(false);
700
+ });
701
+
702
+ it('should list all enabled features', () => {
703
+ process.env.PUBLIC_FEATURES = 'core,blog,shop';
704
+ expect(ENABLED_FEATURES).toEqual(['core', 'blog', 'shop']);
705
+ });
706
+ });
707
+ ```
708
+
709
+ ---
710
+
711
+ ### 4. Integration Tests
712
+
713
+ Test mutations with different feature sets:
714
+
715
+ ```typescript
716
+ describe('Blog Mutations (blog enabled)', () => {
717
+ beforeAll(() => {
718
+ process.env.PUBLIC_FEATURES = 'core,blog';
719
+ regenerateTypes();
720
+ });
721
+
722
+ it('should create blog post', async () => {
723
+ const id = await createBlogPost({
724
+ title: 'Test Post',
725
+ content: 'Content',
726
+ });
727
+ expect(id).toBeDefined();
728
+ });
729
+ });
730
+
731
+ describe('Blog Mutations (blog disabled)', () => {
732
+ beforeAll(() => {
733
+ process.env.PUBLIC_FEATURES = 'core';
734
+ regenerateTypes();
735
+ });
736
+
737
+ it('should reject blog post creation', async () => {
738
+ await expect(createBlogPost({
739
+ title: 'Test Post',
740
+ content: 'Content',
741
+ })).rejects.toThrow('Blog feature not enabled');
742
+ });
743
+ });
744
+ ```
745
+
746
+ ---
747
+
748
+ ## Debugging
749
+
750
+ ### Enable Verbose Logging
751
+
752
+ ```bash
753
+ ONTOLOGY_DEBUG=true bun run scripts/generate-ontology-types.ts
754
+ ```
755
+
756
+ **Output:**
757
+
758
+ ```
759
+ [DEBUG] Loading feature: core
760
+ [DEBUG] Thing types: page, user, file, link, note
761
+ [DEBUG] Connection types: created_by, updated_by, viewed_by, favorited_by
762
+ [DEBUG] Event types: thing_created, thing_updated, thing_deleted, thing_viewed
763
+ [DEBUG] Loading feature: blog (extends core)
764
+ [DEBUG] Inherited types: page, user, file, link, note
765
+ [DEBUG] New thing types: blog_post, blog_category
766
+ [DEBUG] New connection types: posted_in
767
+ [DEBUG] New event types: blog_post_published, blog_post_viewed
768
+ [DEBUG] Dependency resolution: core → blog
769
+ [DEBUG] Generated types written to: convex/types/ontology.ts
770
+ ```
771
+
772
+ ---
773
+
774
+ ## Summary
775
+
776
+ The multi-ontology architecture provides:
777
+
778
+ ✅ **Composability** - Features are independent and composable
779
+ ✅ **Type Safety** - Full TypeScript validation
780
+ ✅ **Flexibility** - Easy to add/remove features
781
+ ✅ **Performance** - Load only what you need
782
+ ✅ **Multi-Backend** - Different backends, different features
783
+ ✅ **Developer Experience** - Clear, focused autocomplete
784
+
785
+ **Next Steps:**
786
+
787
+ - Read the [Quick Start Guide](./ontology-quickstart.md)
788
+ - Explore [Migration Guide](./ontology-migration-guide.md)
789
+ - Study example ontologies in `/one/knowledge/ontology-*.yaml`