oneie 3.6.6 → 3.6.11

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 (166) hide show
  1. package/.claude/agents/agent-backend.md +83 -0
  2. package/.claude/agents/agent-designer.md +97 -0
  3. package/.claude/agents/agent-director.md +118 -7
  4. package/.claude/agents/agent-documenter.md +93 -0
  5. package/.claude/agents/agent-frontend.md +96 -0
  6. package/.claude/agents/agent-ops.md +182 -25
  7. package/.claude/agents/agent-problem-solver.md +166 -0
  8. package/.claude/agents/agent-quality.md +127 -0
  9. package/.claude/commands/build.md +293 -0
  10. package/.claude/commands/cascade.md +231 -127
  11. package/.claude/commands/mcp-toggle.md +93 -0
  12. package/.claude/commands/onboard.md +179 -0
  13. package/.claude/commands/one.md +236 -516
  14. package/.claude/commands/plan.md +394 -80
  15. package/.claude/commands/release.md +41 -19
  16. package/.claude/commands/server.md +335 -0
  17. package/.claude/hooks/root-cleanup.py +75 -0
  18. package/.claude/skills/INDEX.md +523 -0
  19. package/.claude/skills/REGISTRY.md +529 -0
  20. package/.claude/skills/agent-backend-create-mutation.md +319 -0
  21. package/.claude/skills/agent-designer-create-wireframe.md +341 -0
  22. package/.claude/skills/agent-frontend-create-page.md +413 -0
  23. package/.claude/skills/agents/README.md +238 -0
  24. package/dist/clone-web.js +1 -1
  25. package/dist/clone-web.js.map +1 -1
  26. package/folders.yaml +1 -1
  27. package/one/.obsidian/workspace.json +38 -38
  28. package/one/connections/api/queries-reference.md +842 -0
  29. package/one/connections/api-reference.md +1011 -0
  30. package/one/connections/integration-examples.md +875 -0
  31. package/one/connections/integration-guide.md +869 -0
  32. package/one/connections/integration-phase2.md +736 -0
  33. package/one/events/API_ROUTES_FIXES_SUMMARY.md +262 -0
  34. package/one/events/ASTRO-INTEGRATION-EXAMPLES.md +636 -0
  35. package/one/events/BEFORE_AFTER_COMPARISON.md +960 -0
  36. package/one/events/CONNECTIONS_DEMO.md +501 -0
  37. package/one/events/DELIVERABLES.md +432 -0
  38. package/one/events/DEMO-GROUPS-PAGE.md +392 -0
  39. package/one/events/DEMO-TESTING-SUMMARY.md +518 -0
  40. package/one/events/DEMO_COMPONENTS.md +487 -0
  41. package/one/events/DEMO_HOOKS_INDEX.md +334 -0
  42. package/one/events/DEMO_INFRASTRUCTURE.md +905 -0
  43. package/one/events/DEMO_INFRASTRUCTURE_SUMMARY.md +570 -0
  44. package/one/events/DEMO_INTEGRATION_CHECKLIST.md +431 -0
  45. package/one/events/DEMO_QUICK_REFERENCE.md +441 -0
  46. package/one/events/DEMO_SETUP.md +476 -0
  47. package/one/events/EFFECT_TS_API_PATTERN.md +478 -0
  48. package/one/events/GROUPS_DEMO_IMPLEMENTATION.md +414 -0
  49. package/one/events/HOOKS-DEMO.md +441 -0
  50. package/one/events/ONTOLOGY-HOOKS-README.md +700 -0
  51. package/one/events/ONTOLOGY-INTEGRATION-MANIFEST.md +365 -0
  52. package/one/events/QA-CHECKLIST.md +674 -0
  53. package/one/events/QUICK-START-ONTOLOGY.md +408 -0
  54. package/one/events/SEARCH_DEMO_CODE_REFERENCE.md +639 -0
  55. package/one/events/SEARCH_DEMO_DELIVERY.md +415 -0
  56. package/one/events/SEARCH_DEMO_SUMMARY.md +303 -0
  57. package/one/events/SEARCH_DEMO_VISUAL_GUIDE.md +381 -0
  58. package/one/events/TEST-PLAN-INDEX.md +346 -0
  59. package/one/events/TEST-PLAN.md +1417 -0
  60. package/one/events/TESTING-DELIVERY.txt +372 -0
  61. package/one/events/TRANSITIONS-QUICK-START.md +141 -0
  62. package/one/events/TYPESCRIPT_FIXES.md +152 -0
  63. package/one/events/TYPESCRIPT_FIXES_COMPLETE.txt +412 -0
  64. package/one/events/TYPESCRIPT_FIXES_INDEX.md +341 -0
  65. package/one/events/VIEW-TRANSITIONS.md +428 -0
  66. package/one/events/backend-integration-tests.md +606 -0
  67. package/one/events/backend-structure-diagram.txt +393 -0
  68. package/one/events/backend-structure-summary.txt +269 -0
  69. package/one/events/cloudflare-pages-infrastructure-setup.md +264 -0
  70. package/one/events/convex-analysis-index.md +304 -0
  71. package/one/events/convex-structure-analysis.md +700 -0
  72. package/one/events/design-spec-complete.md +208 -0
  73. package/one/events/ontology-test-examples.md +562 -0
  74. package/one/events/phase1-backend-implementation-complete.md +518 -0
  75. package/one/events/test-dashboard.md +345 -0
  76. package/one/events/test-index.md +361 -0
  77. package/one/events/test-report-ontology.md +582 -0
  78. package/one/events/testing-summary.md +344 -0
  79. package/one/groups/features.md +2878 -0
  80. package/one/groups/strategy copy.md +869 -0
  81. package/one/knowledge/backend-api-reference.md +710 -0
  82. package/one/knowledge/documentation-summary.md +285 -0
  83. package/one/knowledge/lessons-learned.md +294 -4
  84. package/one/knowledge/ontology-visual-guide.md +360 -0
  85. package/one/knowledge/ontology.md +9 -17
  86. package/one/things/demo-accessibility-animations.md +999 -0
  87. package/one/things/demo-components.md +1304 -0
  88. package/one/things/demo-design-summary.md +629 -0
  89. package/one/things/demo-design-system.md +919 -0
  90. package/one/things/demo-page-layouts.md +989 -0
  91. package/one/things/designs/accessibility-audit.md +790 -0
  92. package/one/things/designs/component-specifications.md +757 -0
  93. package/one/things/designs/design-overview.md +318 -0
  94. package/one/things/designs/design-tokens.md +414 -0
  95. package/one/things/designs/wireframes-dashboard.md +653 -0
  96. package/one/things/docs/api-requests.md +923 -0
  97. package/one/things/features/0 All Features.md +2 -0
  98. package/one/things/implementation/backend-guide.md +412 -0
  99. package/one/things/plans/2-backend-agnostic-frontend.md +11 -8
  100. package/one/things/plans/ai-elements.md +1259 -0
  101. package/one/things/plans/ai-integration.md +947 -0
  102. package/one/things/plans/ai-sdk.md +761 -0
  103. package/one/things/plans/app.md +1 -1
  104. package/one/things/plans/architecture-summary.md +283 -0
  105. package/one/things/plans/async-ai-agents.md +215 -0
  106. package/one/things/plans/backend-agnostic-frontend.md +11 -6
  107. package/one/things/plans/backend-cleanup-quickstart.md +346 -0
  108. package/one/things/plans/backend-ontology-conformance.md +416 -0
  109. package/one/things/plans/backend-status.md +541 -0
  110. package/one/things/plans/backend-structure.md +799 -0
  111. package/one/things/plans/backend-target-structure.md +438 -0
  112. package/one/things/plans/backend.md +1133 -0
  113. package/one/things/plans/better-auth-any-backend.md +11 -11
  114. package/one/things/plans/cli-updates-required.md +280 -0
  115. package/one/things/plans/complete-step-by-step.md +1302 -0
  116. package/one/things/plans/convex-agents.md +1005 -0
  117. package/one/things/plans/deployment-architecture.md +426 -0
  118. package/one/things/plans/development-plan.md +1220 -0
  119. package/one/things/plans/effect.md +808 -48
  120. package/one/things/plans/integrate-frontend-and-backend.md +579 -0
  121. package/one/things/plans/mcp-clear-context-prompt.md +60 -0
  122. package/one/things/plans/mcp-simple.md +228 -0
  123. package/one/things/plans/one.md +8 -7
  124. package/one/things/plans/ontology-6-dimensions.md +20 -14
  125. package/one/things/plans/quick-wins.md +1273 -0
  126. package/one/things/plans/readme-backend-cleanup.md +361 -0
  127. package/one/things/plans/separate-demo.md +830 -0
  128. package/one/things/plans/separate.md +3 -3
  129. package/one/things/plans/sequence.md +1897 -0
  130. package/one/things/plans/sync-checklist.md +321 -0
  131. package/one/things/plans/unified-implementation-plan.md +3 -3
  132. package/one/things/plans/update-demos.md +513 -0
  133. package/package.json +1 -1
  134. package/.claude/agents/backend-specialist.md +0 -169
  135. package/.claude/agents/designer.md +0 -216
  136. package/.claude/agents/frontend-specialist.md +0 -236
  137. package/.claude/commands/done.md +0 -35
  138. package/.claude/commands/infer.md +0 -138
  139. package/.claude/commands/next.md +0 -53
  140. package/.claude/commands/one copy.md +0 -565
  141. package/.claude/commands/one-template.md +0 -106
  142. package/.claude/commands/one-v1.md +0 -609
  143. package/.claude/hooks/__pycache__/knowledge-post.cpython-313.pyc +0 -0
  144. package/.claude/hooks/__pycache__/knowledge-pre.cpython-313.pyc +0 -0
  145. package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
  146. package/one/groups/nine-padel-customers.md +0 -138
  147. package/one/groups/nine-padel-data-structure.md +0 -167
  148. package/one/groups/nine-padel-ontology-specification.md +0 -359
  149. package/one/groups/nine-padel-ontology.md +0 -143
  150. package/one/groups/nine-padel-strategy.md +0 -234
  151. package/one/groups/nine-padel.md +0 -211
  152. package/one/groups/nine-padle-contents.baked.md +0 -1252
  153. package/one/groups/nine-padle-contents.md +0 -6
  154. package/one/things/features/1-1-agent-prompts/design.md +0 -470
  155. package/one/things/features/1-1-agent-prompts/tests.md +0 -264
  156. package/one/things/features/1-2-yaml-orchestrator/design.md +0 -497
  157. package/one/things/features/1-2-yaml-orchestrator/tests.md +0 -227
  158. package/one/things/features/1-3-event-coordination/design.md +0 -544
  159. package/one/things/features/1-3-event-coordination/tests.md +0 -223
  160. package/one/things/features/1-4-knowledge-management/design.md +0 -609
  161. package/one/things/features/1-4-knowledge-management/tests.md +0 -195
  162. package/one/things/features/1-5-quality-loops/design.md +0 -797
  163. package/one/things/features/1-5-quality-loops/tests.md +0 -212
  164. package/one/things/features/1-6-numbering-structure/design.md +0 -610
  165. package/one/things/features/1-6-numbering-structure/tests.md +0 -213
  166. package/one/things/features/dataprovider-interface/1-tests.md +0 -1522
@@ -0,0 +1,700 @@
1
+ # Ontology Hooks & Feature Integration
2
+
3
+ Complete React hooks and Astro integration for the 6-dimension ontology.
4
+
5
+ ## Overview
6
+
7
+ This module provides a complete abstraction layer for ontology operations, enabling:
8
+
9
+ - **Backend independence**: Works with any provider (Convex, Notion, WordPress, etc.)
10
+ - **Feature flags**: Selective feature enablement
11
+ - **Graceful degradation**: Frontend-only fallback mode
12
+ - **Type safety**: Full TypeScript inference
13
+ - **Real-time data**: Live subscriptions via hooks
14
+ - **Server-side rendering**: Astro integration with fallbacks
15
+
16
+ ## Quick Start
17
+
18
+ ### 1. Install Dependencies
19
+
20
+ ```bash
21
+ bun add effect # Effect-TS for functional programming
22
+ ```
23
+
24
+ ### 2. Configure Feature Flags
25
+
26
+ Create `.env.local`:
27
+
28
+ ```bash
29
+ # Enable features (defaults to all disabled)
30
+ VITE_FEATURE_AUTH=true
31
+ VITE_FEATURE_GROUPS=true
32
+ VITE_FEATURE_REALTIME=true
33
+ VITE_FEATURE_SEARCH=true
34
+
35
+ # Or use JSON
36
+ VITE_FEATURES='{"auth":true,"groups":true,"realtime":true}'
37
+ ```
38
+
39
+ ### 3. Wrap App with Provider
40
+
41
+ ```tsx
42
+ import { DataProviderProvider } from '@/hooks/ontology';
43
+ import { convexProvider } from '@/lib/ontology/providers/convex';
44
+
45
+ export default function App() {
46
+ return (
47
+ <DataProviderProvider provider={convexProvider}>
48
+ <YourApp />
49
+ </DataProviderProvider>
50
+ );
51
+ }
52
+ ```
53
+
54
+ ### 4. Use Hooks in Components
55
+
56
+ ```tsx
57
+ import { useThings, useCurrentUser } from '@/hooks/ontology';
58
+
59
+ export function MyComponent() {
60
+ const { things, loading } = useThings({ type: 'course' });
61
+ const { user } = useCurrentUser();
62
+
63
+ if (loading) return <div>Loading...</div>;
64
+
65
+ return (
66
+ <div>
67
+ <h1>Welcome, {user?.name}!</h1>
68
+ {things?.map(t => (
69
+ <div key={t._id}>{t.name}</div>
70
+ ))}
71
+ </div>
72
+ );
73
+ }
74
+ ```
75
+
76
+ ## Hook Reference
77
+
78
+ ### Provider Hooks
79
+
80
+ **`useProvider()`** - Access current backend provider
81
+
82
+ ```tsx
83
+ const provider = useProvider();
84
+
85
+ if (!provider) {
86
+ return <FrontendOnlyUI />;
87
+ }
88
+ ```
89
+
90
+ **`useIsProviderAvailable()`** - Check provider availability
91
+
92
+ ```tsx
93
+ const isOnline = useIsProviderAvailable();
94
+ ```
95
+
96
+ **`useProviderCapability(capability)`** - Check specific capability
97
+
98
+ ```tsx
99
+ const hasRealtime = useProviderCapability('realtime');
100
+ ```
101
+
102
+ ### Group Hooks (Multi-Tenancy)
103
+
104
+ **`useGroup()`** - CRUD operations on groups
105
+
106
+ ```tsx
107
+ const { get, create, update, loading } = useGroup();
108
+
109
+ const org = await create({
110
+ name: 'My Org',
111
+ type: 'organization',
112
+ plan: 'pro'
113
+ });
114
+ ```
115
+
116
+ **`useGroups(filter?)`** - List groups
117
+
118
+ ```tsx
119
+ const { groups, loading } = useGroups({
120
+ type: 'organization',
121
+ status: 'active'
122
+ });
123
+ ```
124
+
125
+ **`useCurrentGroup(groupId)`** - Get group from list
126
+
127
+ ```tsx
128
+ const { group } = useCurrentGroup(groupId);
129
+ ```
130
+
131
+ **`useChildGroups(parentGroupId)`** - Get sub-groups
132
+
133
+ ```tsx
134
+ const { groups: departments } = useChildGroups(organizationId);
135
+ ```
136
+
137
+ ### People Hooks (Authorization)
138
+
139
+ **`usePerson()`** - CRUD operations on people
140
+
141
+ ```tsx
142
+ const { get, list, hasPermission } = usePerson();
143
+
144
+ const canAdmin = hasPermission('org_manage', 'org_owner');
145
+ ```
146
+
147
+ **`useCurrentUser()`** - Get authenticated user
148
+
149
+ ```tsx
150
+ const { user, isAuthenticated, loading } = useCurrentUser();
151
+
152
+ if (!isAuthenticated) return <LoginPage />;
153
+ ```
154
+
155
+ **`useHasRole(role)`** - Check user role
156
+
157
+ ```tsx
158
+ const isOwner = useHasRole('org_owner');
159
+ ```
160
+
161
+ **`useCanAccess(permission)`** - Check permission
162
+
163
+ ```tsx
164
+ const canManage = useCanAccess('org_manage');
165
+ ```
166
+
167
+ **`useGroupMembers(groupId)`** - List group members
168
+
169
+ ```tsx
170
+ const { members } = useGroupMembers(organizationId);
171
+ ```
172
+
173
+ ### Thing Hooks (Entities)
174
+
175
+ **`useThing()`** - CRUD operations on entities
176
+
177
+ ```tsx
178
+ const { get, create, update, remove, loading } = useThing();
179
+
180
+ const course = await create({
181
+ type: 'course',
182
+ name: 'React 101',
183
+ properties: { description: '...' }
184
+ });
185
+ ```
186
+
187
+ **`useThings(filter?)`** - List entities
188
+
189
+ ```tsx
190
+ const { things, loading } = useThings({
191
+ type: 'course',
192
+ status: 'published'
193
+ });
194
+ ```
195
+
196
+ **`useThingsByType(type)`** - Get entities of type
197
+
198
+ ```tsx
199
+ const { things: courses } = useThingsByType('course');
200
+ ```
201
+
202
+ **`useThingSearch(query, type?)`** - Search entities
203
+
204
+ ```tsx
205
+ const { things: results } = useThingSearch('React', 'course');
206
+ ```
207
+
208
+ **`usePublishedThings(type?)`** - Get published entities
209
+
210
+ ```tsx
211
+ const { things } = usePublishedThings('blog_post');
212
+ ```
213
+
214
+ ### Connection Hooks (Relationships)
215
+
216
+ **`useConnection()`** - Create/update connections
217
+
218
+ ```tsx
219
+ const { create, update, remove } = useConnection();
220
+
221
+ await create({
222
+ fromEntityId: userId,
223
+ toEntityId: courseId,
224
+ relationshipType: 'enrolled_in'
225
+ });
226
+ ```
227
+
228
+ **`useConnections(filter?)`** - List connections
229
+
230
+ ```tsx
231
+ const { connections } = useConnections({
232
+ relationshipType: 'enrolled_in'
233
+ });
234
+ ```
235
+
236
+ **`useRelatedEntities(entityId, relationshipType, direction)`** - Get related entities
237
+
238
+ ```tsx
239
+ const { entities: students } = useRelatedEntities(
240
+ courseId,
241
+ 'enrolled_in',
242
+ 'to'
243
+ );
244
+ ```
245
+
246
+ **`useFollowing(userId)`** - Get accounts user follows
247
+
248
+ ```tsx
249
+ const { entities: following } = useFollowing(userId);
250
+ ```
251
+
252
+ **`useFollowers(entityId)`** - Get followers
253
+
254
+ ```tsx
255
+ const { entities: followers } = useFollowers(authorId);
256
+ ```
257
+
258
+ **`useEnrollments(courseId)`** - Get students in course
259
+
260
+ ```tsx
261
+ const { entities: students } = useEnrollments(courseId);
262
+ ```
263
+
264
+ ### Event Hooks (Activity Logging)
265
+
266
+ **`useEvent()`** - Record new event
267
+
268
+ ```tsx
269
+ const { record, loading } = useEvent();
270
+
271
+ await record({
272
+ type: 'course_enrolled',
273
+ targetId: courseId,
274
+ metadata: { enrolledAt: Date.now() }
275
+ });
276
+ ```
277
+
278
+ **`useEvents(filter?)`** - List events
279
+
280
+ ```tsx
281
+ const { events } = useEvents({
282
+ type: 'course_completed',
283
+ limit: 20
284
+ });
285
+ ```
286
+
287
+ **`useActivityFeed(limit?)`** - Get recent activity
288
+
289
+ ```tsx
290
+ const { events: feed } = useActivityFeed(50);
291
+ ```
292
+
293
+ **`useAuditTrail(targetId)`** - Get entity history
294
+
295
+ ```tsx
296
+ const { events: history } = useAuditTrail(courseId);
297
+ ```
298
+
299
+ **`useUserHistory(userId)`** - Get user's actions
300
+
301
+ ```tsx
302
+ const { events: actions } = useUserHistory(userId);
303
+ ```
304
+
305
+ ### Search Hooks (Knowledge)
306
+
307
+ **`useSearch(query, options?)`** - Full-text/semantic search
308
+
309
+ ```tsx
310
+ const { results, loading } = useSearch('React tutorial', {
311
+ type: 'course',
312
+ limit: 20
313
+ });
314
+ ```
315
+
316
+ **`useLabels(category?)`** - Get labels/tags
317
+
318
+ ```tsx
319
+ const { labels: skills } = useLabels('skill');
320
+ ```
321
+
322
+ **`useEntityLabels(entityId)`** - Get entity's labels
323
+
324
+ ```tsx
325
+ const { labels } = useEntityLabels(courseId);
326
+ ```
327
+
328
+ **`useEntitiesByLabel(labelId)`** - Get entities with label
329
+
330
+ ```tsx
331
+ const { entities } = useEntitiesByLabel(pythonSkillId);
332
+ ```
333
+
334
+ **`useSimilarEntities(entityId, limit?)`** - Find similar items
335
+
336
+ ```tsx
337
+ const { results: similar } = useSimilarEntities(courseId, 10);
338
+ ```
339
+
340
+ **`useRecommendations(userId, limit?)`** - AI-powered recommendations
341
+
342
+ ```tsx
343
+ const { results: recommended } = useRecommendations(userId, 20);
344
+ ```
345
+
346
+ ## Feature Flags
347
+
348
+ ### Available Flags
349
+
350
+ ```typescript
351
+ interface FeatureFlags {
352
+ auth: boolean; // User authentication
353
+ groups: boolean; // Multi-tenant groups
354
+ permissions: boolean; // Role-based access
355
+ realtime: boolean; // WebSocket subscriptions
356
+ search: boolean; // Full-text search
357
+ knowledge: boolean; // Vector search/RAG
358
+ connections: boolean; // Relationships
359
+ events: boolean; // Activity logging
360
+ inference: boolean; // AI/LLM integration
361
+ blockchain: boolean; // NFTs/smart contracts
362
+ payments: boolean; // Payment processing
363
+ marketplace: boolean; // Buy/sell features
364
+ community: boolean; // Comments/reactions
365
+ }
366
+ ```
367
+
368
+ ### Configuration
369
+
370
+ ```typescript
371
+ import { features, isFeatureEnabled, getFeatureMode } from '@/lib/ontology/features';
372
+
373
+ // Direct check
374
+ if (features.auth) { /* */ }
375
+
376
+ // Function check
377
+ if (isFeatureEnabled('groups')) { /* */ }
378
+
379
+ // Get mode
380
+ const mode = getFeatureMode(); // 'frontend-only' | 'authenticated' | 'multi-tenant' | 'full'
381
+ ```
382
+
383
+ ### Environment Variables
384
+
385
+ ```bash
386
+ # Individual flags
387
+ VITE_FEATURE_AUTH=true
388
+ VITE_FEATURE_GROUPS=true
389
+ VITE_FEATURE_REALTIME=true
390
+
391
+ # Or JSON config
392
+ VITE_FEATURES='{"auth":true,"groups":true,"realtime":true,"search":true}'
393
+ ```
394
+
395
+ ### Presets
396
+
397
+ ```typescript
398
+ import { FEATURE_PRESETS } from '@/lib/ontology/features';
399
+
400
+ // Frontend-only (no backend)
401
+ FEATURE_PRESETS.frontendOnly
402
+
403
+ // Static site with search
404
+ FEATURE_PRESETS.basicStatic
405
+
406
+ // SaaS app
407
+ FEATURE_PRESETS.saas
408
+
409
+ // Full-featured platform
410
+ FEATURE_PRESETS.full
411
+
412
+ // Marketplace
413
+ FEATURE_PRESETS.marketplace
414
+ ```
415
+
416
+ ## Astro Integration
417
+
418
+ ### SSR Data Fetching
419
+
420
+ ```astro
421
+ ---
422
+ import { getThings, getRecentEvents } from '@/lib/ontology/astro-helpers';
423
+
424
+ // Server-side fetching (runs at build time)
425
+ const courses = await getThings({ type: 'course', status: 'published' });
426
+ const events = await getRecentEvents(20);
427
+ ---
428
+
429
+ <Layout>
430
+ {courses.map(course => (
431
+ <div>{course.name}</div>
432
+ ))}
433
+ </Layout>
434
+ ```
435
+
436
+ ### Static Paths
437
+
438
+ ```astro
439
+ ---
440
+ import { getStaticPaths } from '@/lib/ontology/astro-helpers';
441
+
442
+ export const getStaticPaths = () => getStaticPaths('course');
443
+ ---
444
+ ```
445
+
446
+ ### Protected Routes
447
+
448
+ ```astro
449
+ ---
450
+ import { getCurrentUser } from '@/lib/ontology/astro-helpers';
451
+ import { assertFeatureEnabled } from '@/lib/ontology/features';
452
+
453
+ assertFeatureEnabled('auth');
454
+
455
+ const user = await getCurrentUser(Astro.request);
456
+ if (!user) return Astro.redirect('/login');
457
+ ---
458
+ ```
459
+
460
+ ### Fallback Pattern
461
+
462
+ ```astro
463
+ ---
464
+ import { getThingWithFallback } from '@/lib/ontology/astro-helpers';
465
+ import { getEntry } from 'astro:content';
466
+
467
+ const thing = await getThingWithFallback(id);
468
+ if (!thing) {
469
+ const post = await getEntry('blog', id);
470
+ if (!post) return Astro.redirect('/404');
471
+ }
472
+ ---
473
+ ```
474
+
475
+ ## API Reference
476
+
477
+ ### Type Definitions
478
+
479
+ All types are exported from hooks:
480
+
481
+ ```typescript
482
+ import {
483
+ type Thing,
484
+ type Connection,
485
+ type Event,
486
+ type Person,
487
+ type Group,
488
+ type Label,
489
+ type SearchResult
490
+ } from '@/hooks/ontology';
491
+ ```
492
+
493
+ ### Error Handling
494
+
495
+ All hooks include `error` state:
496
+
497
+ ```tsx
498
+ const { data, loading, error } = useThings();
499
+
500
+ if (error) {
501
+ return <div>Error: {error.message}</div>;
502
+ }
503
+ ```
504
+
505
+ ### Loading States
506
+
507
+ All hooks include `loading` state:
508
+
509
+ ```tsx
510
+ const { loading, data } = useThings();
511
+
512
+ if (loading) return <Skeleton />;
513
+ ```
514
+
515
+ ### Callbacks
516
+
517
+ All async operations support callbacks:
518
+
519
+ ```tsx
520
+ const { create } = useThing();
521
+
522
+ create(input, {
523
+ onSuccess: (result) => toast.success('Created!'),
524
+ onError: (error) => toast.error(error.message),
525
+ onFinally: () => setOpen(false)
526
+ });
527
+ ```
528
+
529
+ ## Advanced Patterns
530
+
531
+ ### Computed Hooks
532
+
533
+ Chain hooks for derived data:
534
+
535
+ ```tsx
536
+ function UserCourses({ userId }) {
537
+ const { entities: enrolled } = useUserEnrollments(userId);
538
+ const { entities: completed } = useRelatedEntities(
539
+ userId,
540
+ 'completed',
541
+ 'from'
542
+ );
543
+
544
+ return (
545
+ <div>
546
+ <h3>Enrolled: {enrolled.length}</h3>
547
+ <h3>Completed: {completed.length}</h3>
548
+ </div>
549
+ );
550
+ }
551
+ ```
552
+
553
+ ### Conditional Features
554
+
555
+ ```tsx
556
+ import { useCanAccess } from '@/hooks/ontology';
557
+
558
+ function AdminPanel() {
559
+ const canAccess = useCanAccess('org_manage');
560
+
561
+ if (!canAccess) {
562
+ return <AccessDenied />;
563
+ }
564
+
565
+ return <AdminUI />;
566
+ }
567
+ ```
568
+
569
+ ### Real-time Subscriptions
570
+
571
+ ```tsx
572
+ import { useEventStream } from '@/hooks/ontology';
573
+
574
+ function LiveFeed() {
575
+ const { events, isSubscribed } = useEventStream(
576
+ { type: 'course_completed' },
577
+ (event) => {
578
+ console.log('New event:', event);
579
+ }
580
+ );
581
+
582
+ return (
583
+ <div>
584
+ {isSubscribed ? '🟢 Live' : '⚪ Offline'}
585
+ {events.map(e => <EventCard event={e} />)}
586
+ </div>
587
+ );
588
+ }
589
+ ```
590
+
591
+ ### Search with Facets
592
+
593
+ ```tsx
594
+ function AdvancedSearch() {
595
+ const { results, facets } = useFacetedSearch('Python', {
596
+ category: 'skill',
597
+ type: 'course'
598
+ });
599
+
600
+ return (
601
+ <div>
602
+ <Filters facets={facets} />
603
+ <Results results={results} />
604
+ </div>
605
+ );
606
+ }
607
+ ```
608
+
609
+ ## Testing
610
+
611
+ ### Mock Provider
612
+
613
+ ```typescript
614
+ const mockProvider = {
615
+ things: {
616
+ list: async () => [{ _id: '1', name: 'Test', type: 'course' }],
617
+ get: async (id) => ({ _id: id, name: 'Test' })
618
+ }
619
+ };
620
+ ```
621
+
622
+ ### Test Example
623
+
624
+ ```typescript
625
+ import { renderHook, waitFor } from '@testing-library/react';
626
+ import { useThings } from '@/hooks/ontology';
627
+
628
+ it('should load things', async () => {
629
+ const { result } = renderHook(() => useThings());
630
+
631
+ await waitFor(() => {
632
+ expect(result.current.loading).toBe(false);
633
+ });
634
+
635
+ expect(result.current.things).toHaveLength(1);
636
+ });
637
+ ```
638
+
639
+ ## Performance Tips
640
+
641
+ 1. **Use specific queries**: Filter by type/status instead of loading everything
642
+ 2. **Limit results**: Use `limit` parameter to paginate
643
+ 3. **Cache aggressively**: Results are cached by React Query
644
+ 4. **Lazy load**: Use `client:idle` for below-fold components
645
+ 5. **Debounce search**: Built-in 300ms debounce on useSearch
646
+ 6. **Static generation**: Use Astro for static pages when possible
647
+
648
+ ## File Structure
649
+
650
+ ```
651
+ web/src/
652
+ ├── hooks/ontology/
653
+ │ ├── index.ts # Barrel export
654
+ │ ├── useProvider.ts # Provider context
655
+ │ ├── useGroup.ts # Groups (5 hooks)
656
+ │ ├── usePerson.ts # People (5 hooks)
657
+ │ ├── useThing.ts # Things (6 hooks)
658
+ │ ├── useConnection.ts # Connections (8 hooks)
659
+ │ ├── useEvent.ts # Events (7 hooks)
660
+ │ └── useSearch.ts # Knowledge (8 hooks)
661
+ │
662
+ ├── lib/ontology/
663
+ │ ├── features.ts # Feature flags
664
+ │ ├── astro-helpers.ts # Astro SSR helpers
665
+ │ └── providers/ # Provider implementations
666
+ │ ├── index.ts
667
+ │ ├── convex.ts
668
+ │ ├── notion.ts
669
+ │ ├── markdown.ts
670
+ │ └── ...
671
+ │
672
+ └── examples/
673
+ ├── ASTRO-INTEGRATION-EXAMPLES.md
674
+ └── ONTOLOGY-HOOKS-README.md (this file)
675
+ ```
676
+
677
+ ## Summary
678
+
679
+ **Total Hooks Created**: 43
680
+ - **Provider**: 4 hooks
681
+ - **Groups**: 4 hooks
682
+ - **People**: 5 hooks
683
+ - **Things**: 6 hooks
684
+ - **Connections**: 8 hooks
685
+ - **Events**: 7 hooks
686
+ - **Search**: 8 hooks
687
+
688
+ **Features**: 13 configurable flags
689
+ **Astro Helpers**: 8 SSR utilities
690
+ **Examples**: 8 complete Astro pages
691
+
692
+ All hooks follow the same pattern:
693
+ - Type-safe inputs and outputs
694
+ - Loading/error states
695
+ - Success/error callbacks
696
+ - Feature availability checks
697
+ - Provider fallback support
698
+ - React Query caching
699
+
700
+ Ready for production use across any backend provider!