holosphere 2.0.0-alpha0 → 2.0.0-alpha2

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 (88) hide show
  1. package/LICENSE +162 -38
  2. package/dist/cjs/holosphere.cjs +2 -0
  3. package/dist/cjs/holosphere.cjs.map +1 -0
  4. package/dist/esm/holosphere.js +56 -0
  5. package/dist/esm/holosphere.js.map +1 -0
  6. package/dist/index-CDfIuXew.js +15974 -0
  7. package/dist/index-CDfIuXew.js.map +1 -0
  8. package/dist/index-ifOgtDvd.cjs +3 -0
  9. package/dist/index-ifOgtDvd.cjs.map +1 -0
  10. package/dist/indexeddb-storage-CMW4qRQS.js +96 -0
  11. package/dist/indexeddb-storage-CMW4qRQS.js.map +1 -0
  12. package/dist/indexeddb-storage-DLZOgetM.cjs +2 -0
  13. package/dist/indexeddb-storage-DLZOgetM.cjs.map +1 -0
  14. package/dist/memory-storage-DQzcAZlf.js +47 -0
  15. package/dist/memory-storage-DQzcAZlf.js.map +1 -0
  16. package/dist/memory-storage-DmePEP2q.cjs +2 -0
  17. package/dist/memory-storage-DmePEP2q.cjs.map +1 -0
  18. package/dist/secp256k1-CP0ZkpAx.cjs +13 -0
  19. package/dist/secp256k1-CP0ZkpAx.cjs.map +1 -0
  20. package/dist/secp256k1-vOXp40Fx.js +2281 -0
  21. package/dist/secp256k1-vOXp40Fx.js.map +1 -0
  22. package/docs/FOSDEM_PROPOSAL.md +388 -0
  23. package/docs/LOCALFIRST.md +266 -0
  24. package/docs/contracts/api-interface.md +793 -0
  25. package/docs/data-model.md +476 -0
  26. package/docs/gun-async-usage.md +338 -0
  27. package/docs/plan.md +349 -0
  28. package/docs/quickstart.md +674 -0
  29. package/docs/research.md +362 -0
  30. package/docs/spec.md +244 -0
  31. package/docs/storage-backends.md +326 -0
  32. package/docs/tasks.md +947 -0
  33. package/package.json +1 -1
  34. package/tests/unit/ai/aggregation.test.js +0 -295
  35. package/tests/unit/ai/breakdown.test.js +0 -446
  36. package/tests/unit/ai/classifier.test.js +0 -294
  37. package/tests/unit/ai/council.test.js +0 -262
  38. package/tests/unit/ai/embeddings.test.js +0 -384
  39. package/tests/unit/ai/federation-ai.test.js +0 -344
  40. package/tests/unit/ai/h3-ai.test.js +0 -458
  41. package/tests/unit/ai/index.test.js +0 -304
  42. package/tests/unit/ai/json-ops.test.js +0 -307
  43. package/tests/unit/ai/llm-service.test.js +0 -390
  44. package/tests/unit/ai/nl-query.test.js +0 -383
  45. package/tests/unit/ai/relationships.test.js +0 -311
  46. package/tests/unit/ai/schema-extractor.test.js +0 -384
  47. package/tests/unit/ai/spatial.test.js +0 -279
  48. package/tests/unit/ai/tts.test.js +0 -279
  49. package/tests/unit/content.test.js +0 -332
  50. package/tests/unit/contract/core.test.js +0 -88
  51. package/tests/unit/contract/crypto.test.js +0 -198
  52. package/tests/unit/contract/data.test.js +0 -223
  53. package/tests/unit/contract/federation.test.js +0 -181
  54. package/tests/unit/contract/hierarchical.test.js +0 -113
  55. package/tests/unit/contract/schema.test.js +0 -114
  56. package/tests/unit/contract/social.test.js +0 -217
  57. package/tests/unit/contract/spatial.test.js +0 -110
  58. package/tests/unit/contract/subscriptions.test.js +0 -128
  59. package/tests/unit/contract/utils.test.js +0 -159
  60. package/tests/unit/core.test.js +0 -152
  61. package/tests/unit/crypto.test.js +0 -328
  62. package/tests/unit/federation.test.js +0 -234
  63. package/tests/unit/gun-async.test.js +0 -252
  64. package/tests/unit/hierarchical.test.js +0 -399
  65. package/tests/unit/integration/scenario-01-geographic-storage.test.js +0 -74
  66. package/tests/unit/integration/scenario-02-federation.test.js +0 -76
  67. package/tests/unit/integration/scenario-03-subscriptions.test.js +0 -102
  68. package/tests/unit/integration/scenario-04-validation.test.js +0 -129
  69. package/tests/unit/integration/scenario-05-hierarchy.test.js +0 -125
  70. package/tests/unit/integration/scenario-06-social.test.js +0 -135
  71. package/tests/unit/integration/scenario-07-persistence.test.js +0 -130
  72. package/tests/unit/integration/scenario-08-authorization.test.js +0 -161
  73. package/tests/unit/integration/scenario-09-cross-dimensional.test.js +0 -139
  74. package/tests/unit/integration/scenario-10-cross-holosphere-capabilities.test.js +0 -357
  75. package/tests/unit/integration/scenario-11-cross-holosphere-federation.test.js +0 -410
  76. package/tests/unit/integration/scenario-12-capability-federated-read.test.js +0 -719
  77. package/tests/unit/performance/benchmark.test.js +0 -85
  78. package/tests/unit/schema.test.js +0 -213
  79. package/tests/unit/spatial.test.js +0 -158
  80. package/tests/unit/storage.test.js +0 -195
  81. package/tests/unit/subscriptions.test.js +0 -328
  82. package/tests/unit/test-data-permanence-debug.js +0 -197
  83. package/tests/unit/test-data-permanence.js +0 -340
  84. package/tests/unit/test-key-persistence-fixed.js +0 -148
  85. package/tests/unit/test-key-persistence.js +0 -172
  86. package/tests/unit/test-relay-permanence.js +0 -376
  87. package/tests/unit/test-second-node.js +0 -95
  88. package/tests/unit/test-simple-write.js +0 -89
package/docs/tasks.md ADDED
@@ -0,0 +1,947 @@
1
+ # Tasks: HoloSphere - Holonic Geospatial Communication Infrastructure
2
+
3
+ **Input**: Design documents from `/Users/roberto/Projects/Liminal/holosphere2/specs/001-holosphere-holonic-geospatial/`
4
+ **Prerequisites**: plan.md, research.md, data-model.md, contracts/, quickstart.md (all present)
5
+ **Branch**: `001-holosphere-holonic-geospatial`
6
+
7
+ ## Execution Flow (main)
8
+ ```
9
+ 1. Load plan.md from feature directory ✓
10
+ → Tech stack: JavaScript ES2020+, GunDB, h3-js, @noble/curves, Ajv
11
+ → Structure: Single library project (src/, tests/)
12
+ 2. Load design documents ✓
13
+ → data-model.md: 9 entities (Holon, Lens, Data Object, etc.)
14
+ → contracts/api-interface.md: 10 API categories, ~30 methods
15
+ → quickstart.md: 9 integration test scenarios
16
+ → research.md: Technical decisions and tooling
17
+ 3. Generate tasks by category:
18
+ → Setup: npm project, Vite, Vitest, ESLint
19
+ → Tests: Contract tests (30), Integration tests (9), Unit tests (8 modules)
20
+ → Core: 8 modules (core, spatial, storage, schema, federation, content, crypto, subscriptions)
21
+ → Integration: Public API wiring, build configuration
22
+ → Polish: Bundle optimization, TypeScript definitions, documentation
23
+ 4. Apply task rules:
24
+ → Test files in parallel [P]
25
+ → Module implementations in parallel where no dependencies [P]
26
+ → TDD order enforced (tests before implementation)
27
+ 5. Total tasks: 42 numbered tasks (T001-T042)
28
+ 6. Dependencies mapped (see Dependencies section)
29
+ 7. Parallel execution examples provided
30
+ 8. Validation: All contracts tested, all entities modeled, TDD order preserved
31
+ ```
32
+
33
+ ## Format: `[ID] [P?] Description`
34
+ - **[P]**: Can run in parallel (different files, no dependencies)
35
+ - Include exact file paths in descriptions
36
+ - Repository root: `/Users/roberto/Projects/Liminal/holosphere2/`
37
+
38
+ ---
39
+
40
+ ## Phase 3.1: Setup & Infrastructure
41
+
42
+ ### T001: Initialize npm project with dependencies
43
+ **File**: `package.json`
44
+ **Description**: Create package.json with:
45
+ - Package name: `holosphere`
46
+ - Type: `module` (ESM)
47
+ - Dependencies: `gun` (GunDB), `h3-js`, `@noble/curves`, `ajv`
48
+ - Dev dependencies: `vite`, `vitest`, `eslint`, `prettier`
49
+ - Scripts: `dev`, `build`, `test`, `test:coverage`, `lint`, `format`
50
+
51
+ **Acceptance**: `npm install` completes without errors
52
+
53
+ ---
54
+
55
+ ### T002: Configure Vitest for unit and integration testing
56
+ **File**: `vitest.config.js`
57
+ **Description**: Create Vitest configuration:
58
+ - Test file patterns: `**/*.test.js`
59
+ - Coverage provider: `v8`
60
+ - Coverage threshold: 80% line coverage
61
+ - Test environment: `node` (default)
62
+ - Include directories: `tests/unit/`, `tests/integration/`, `tests/contract/`
63
+
64
+ **Acceptance**: `npm test` runs (no tests yet, but config loads)
65
+
66
+ ---
67
+
68
+ ### T003: [P] Configure Vite for multi-format build
69
+ **File**: `vite.config.js`
70
+ **Description**: Create Vite build configuration:
71
+ - Entry point: `src/index.js`
72
+ - Output formats: ESM (`dist/esm/`), CommonJS (`dist/cjs/`), UMD (`dist/cdn/`)
73
+ - Library name: `HoloSphere`
74
+ - External dependencies: none (bundle all for CDN)
75
+ - Minification: terser for production
76
+ - Sourcemaps enabled
77
+
78
+ **Acceptance**: `npm run build` creates all three output formats
79
+
80
+ ---
81
+
82
+ ### T004: [P] Configure ESLint and Prettier
83
+ **Files**: `.eslintrc.json`, `.prettierrc.json`
84
+ **Description**:
85
+ - ESLint: ES2020 environment, recommended rules, async-await support
86
+ - Prettier: 2-space indent, single quotes, semicolons, trailing commas
87
+ - ESLint plugin prettier integration
88
+
89
+ **Acceptance**: `npm run lint` and `npm run format` execute without errors
90
+
91
+ ---
92
+
93
+ ### T005: Create source directory structure
94
+ **Directories**: Create all module directories per plan.md:
95
+ ```
96
+ src/
97
+ ├── core/
98
+ ├── spatial/
99
+ ├── storage/
100
+ ├── schema/
101
+ ├── federation/
102
+ ├── hierarchical/
103
+ ├── content/
104
+ ├── crypto/
105
+ ├── subscriptions/
106
+ └── utils/
107
+ ```
108
+
109
+ **Acceptance**: Directory tree matches plan.md structure
110
+
111
+ ---
112
+
113
+ ### T006: Create test directory structure
114
+ **Directories**: Create test directories:
115
+ ```
116
+ tests/
117
+ ├── unit/
118
+ ├── integration/
119
+ └── contract/
120
+ ```
121
+
122
+ **Acceptance**: All test directories exist
123
+
124
+ ---
125
+
126
+ ## Phase 3.2: Tests First (TDD) ⚠️ MUST COMPLETE BEFORE 3.3
127
+
128
+ **CRITICAL: These tests MUST be written and MUST FAIL before ANY implementation**
129
+
130
+ ### Contract Tests (API Interface) - All [P]
131
+
132
+ ### T007: [P] Contract test: Core initialization
133
+ **File**: `tests/contract/core.test.js`
134
+ **Description**: Test `new HoloSphere(config)` constructor:
135
+ - Default config creates instance
136
+ - Custom appName, peers, radisk config works
137
+ - Invalid config throws TypeError
138
+ - Instance has all expected methods
139
+
140
+ **Acceptance**: Test written, fails (HoloSphere not implemented)
141
+
142
+ ---
143
+
144
+ ### T008: [P] Contract test: Spatial operations
145
+ **File**: `tests/contract/spatial.test.js`
146
+ **Description**: Test spatial API methods:
147
+ - `toHolon(lat, lng, resolution)` → H3 string
148
+ - `getParents(holonId, maxResolution)` → parent array
149
+ - `getChildren(holonId)` → 7 children
150
+ - `isValidH3(holonId)` → boolean
151
+ - Error cases: invalid coords, out of range resolution
152
+
153
+ **Acceptance**: Test written, fails (spatial methods not implemented)
154
+
155
+ ---
156
+
157
+ ### T009: [P] Contract test: Data operations (write/read/update/delete)
158
+ **File**: `tests/contract/data.test.js`
159
+ **Description**: Test CRUD API methods:
160
+ - `write(holonId, lensName, data, options)` → boolean
161
+ - `read(holonId, lensName, dataId?)` → object | array | null
162
+ - `update(holonId, lensName, dataId, updates, options)` → boolean
163
+ - `delete(holonId, lensName, dataId, options)` → boolean
164
+ - Validate signatures, parameter types, return values
165
+
166
+ **Acceptance**: Test written, fails (data methods not implemented)
167
+
168
+ ---
169
+
170
+ ### T010: [P] Contract test: Schema operations
171
+ **File**: `tests/contract/schema.test.js`
172
+ **Description**: Test schema API methods:
173
+ - `setSchema(lensName, schemaUri, strict?)` → void
174
+ - `getSchema(lensName)` → object | null
175
+ - `clearSchema(lensName)` → void
176
+ - Validate JSON Schema 2019 format enforcement
177
+
178
+ **Acceptance**: Test written, fails (schema methods not implemented)
179
+
180
+ ---
181
+
182
+ ### T011: [P] Contract test: Federation operations
183
+ **File**: `tests/contract/federation.test.js`
184
+ **Description**: Test federation API methods:
185
+ - `federate(sourceHolon, targetHolon, lensName, options)` → boolean
186
+ - `getFederatedData(holonId, lensName, options)` → array
187
+ - `unfederate(sourceHolon, targetHolon, lensName)` → boolean
188
+ - Options: direction, mode, filter validation
189
+
190
+ **Acceptance**: Test written, fails (federation methods not implemented)
191
+
192
+ ---
193
+
194
+ ### T012: [P] Contract test: Hierarchical operations
195
+ **File**: `tests/contract/hierarchical.test.js`
196
+ **Description**: Test upcast API method:
197
+ - `upcast(holonId, lensName, dataId, options)` → boolean
198
+ - Options: maxLevel, operation validation
199
+ - Error: noospheric holons (no hierarchy)
200
+
201
+ **Acceptance**: Test written, fails (upcast not implemented)
202
+
203
+ ---
204
+
205
+ ### T013: [P] Contract test: Subscription operations
206
+ **File**: `tests/contract/subscriptions.test.js`
207
+ **Description**: Test subscription API:
208
+ - `subscribe(holonId, lensName, callback, options)` → { unsubscribe }
209
+ - Callback invoked on data changes
210
+ - Unsubscribe stops callbacks
211
+ - Options: includeFederated, throttle, filter
212
+
213
+ **Acceptance**: Test written, fails (subscribe not implemented)
214
+
215
+ ---
216
+
217
+ ### T014: [P] Contract test: Cryptographic operations
218
+ **File**: `tests/contract/crypto.test.js`
219
+ **Description**: Test crypto API methods:
220
+ - `sign(content, privateKey)` → signature string
221
+ - `verify(content, signature, publicKey)` → boolean
222
+ - `issueCapability(permissions, scope, recipient, options)` → token
223
+ - `verifyCapability(token, requiredPermission, scope)` → boolean
224
+ - Lazy loading verification (crypto module not loaded until first use)
225
+
226
+ **Acceptance**: Test written, fails (crypto methods not implemented)
227
+
228
+ ---
229
+
230
+ ### T015: [P] Contract test: Social protocol operations
231
+ **File**: `tests/contract/social.test.js`
232
+ **Description**: Test social protocol API:
233
+ - `publishNostr(event, holonId, lensName?)` → boolean
234
+ - `publishActivityPub(object, holonId, lensName?)` → boolean
235
+ - `querySocial(holonId, options)` → array
236
+ - Nostr NIP-01 and ActivityPub format validation
237
+
238
+ **Acceptance**: Test written, fails (social methods not implemented)
239
+
240
+ ---
241
+
242
+ ### T016: [P] Contract test: Utility operations
243
+ **File**: `tests/contract/utils.test.js`
244
+ **Description**: Test utility API:
245
+ - `metrics()` → object (writes, reads, subscriptions counts)
246
+ - Error types: ValidationError, AuthorizationError, HolosphereError
247
+ - Error object structure and properties
248
+
249
+ **Acceptance**: Test written, fails (utils not implemented)
250
+
251
+ ---
252
+
253
+ ### Integration Tests (Quickstart Scenarios) - All [P]
254
+
255
+ ### T017: [P] Integration test: Scenario 1 - Geographic data storage and retrieval
256
+ **File**: `tests/integration/scenario-01-geographic-storage.test.js`
257
+ **Description**: Implement quickstart scenario 1:
258
+ - Convert lat/lng to H3 holon
259
+ - Write temperature data to lens
260
+ - Read data by location + category + ID
261
+ - Query all data in category
262
+
263
+ **Acceptance**: Test written, fails (full workflow not implemented)
264
+
265
+ ---
266
+
267
+ ### T018: [P] Integration test: Scenario 2 - Hierarchical federation
268
+ **File**: `tests/integration/scenario-02-federation.test.js`
269
+ **Description**: Implement quickstart scenario 2:
270
+ - Create local data
271
+ - Federate local → regional holon
272
+ - Query regional (includes local via hologram)
273
+ - Update local, verify regional sees change (single source of truth)
274
+
275
+ **Acceptance**: Test written, fails (federation workflow not implemented)
276
+
277
+ ---
278
+
279
+ ### T019: [P] Integration test: Scenario 3 - Real-time subscriptions
280
+ **File**: `tests/integration/scenario-03-subscriptions.test.js`
281
+ **Description**: Implement quickstart scenario 3:
282
+ - Subscribe to holon/lens changes
283
+ - Write data, verify callback invoked
284
+ - Update data, verify callback invoked again
285
+ - Unsubscribe, verify no more callbacks
286
+
287
+ **Acceptance**: Test written, fails (subscription workflow not implemented)
288
+
289
+ ---
290
+
291
+ ### T020: [P] Integration test: Scenario 4 - Schema validation
292
+ **File**: `tests/integration/scenario-04-validation.test.js`
293
+ **Description**: Implement quickstart scenario 4:
294
+ - Define JSON Schema for lens
295
+ - Permissive mode: invalid data succeeds with warning
296
+ - Strict mode: invalid data throws ValidationError
297
+ - Valid data succeeds in both modes
298
+
299
+ **Acceptance**: Test written, fails (validation workflow not implemented)
300
+
301
+ ---
302
+
303
+ ### T021: [P] Integration test: Scenario 5 - Multi-scale hierarchical queries
304
+ **File**: `tests/integration/scenario-05-hierarchy.test.js`
305
+ **Description**: Implement quickstart scenario 5:
306
+ - Create data at high resolution (local)
307
+ - Upcast to parent hierarchy
308
+ - Query at different scales (neighborhood, city, region)
309
+ - Verify data propagated to all parent levels
310
+
311
+ **Acceptance**: Test written, fails (hierarchy workflow not implemented)
312
+
313
+ ---
314
+
315
+ ### T022: [P] Integration test: Scenario 6 - Cross-protocol social content
316
+ **File**: `tests/integration/scenario-06-social.test.js`
317
+ **Description**: Implement quickstart scenario 6:
318
+ - Publish Nostr event to geographic holon
319
+ - Publish ActivityPub object to noospheric holon
320
+ - Query all social (unified interface)
321
+ - Filter by protocol
322
+ - Verify cryptographic signatures
323
+
324
+ **Acceptance**: Test written, fails (social workflow not implemented)
325
+
326
+ ---
327
+
328
+ ### T023: [P] Integration test: Scenario 7 - Offline persistence
329
+ **File**: `tests/integration/scenario-07-persistence.test.js`
330
+ **Description**: Implement quickstart scenario 7:
331
+ - Initialize with radisk
332
+ - Write data
333
+ - Simulate restart (new instance)
334
+ - Read previously written data (recovered from disk)
335
+ - Offline write, verify immediately available
336
+
337
+ **Acceptance**: Test written, fails (persistence workflow not implemented)
338
+
339
+ ---
340
+
341
+ ### T024: [P] Integration test: Scenario 8 - Authorization with capability tokens
342
+ **File**: `tests/integration/scenario-08-authorization.test.js`
343
+ **Description**: Implement quickstart scenario 8:
344
+ - User A creates data
345
+ - User B attempts unauthorized delete → AuthorizationError
346
+ - User A issues capability token to User B
347
+ - User B deletes with valid token → success
348
+ - Verify data deleted
349
+
350
+ **Acceptance**: Test written, fails (authorization workflow not implemented)
351
+
352
+ ---
353
+
354
+ ### T025: [P] Integration test: Scenario 9 - Cross-dimensional federation
355
+ **File**: `tests/integration/scenario-09-cross-dimensional.test.js`
356
+ **Description**: Implement quickstart scenario 9:
357
+ - Create data in geographic holon
358
+ - Create data in noospheric holon (URI)
359
+ - Federate geographic ↔ noospheric (bidirectional)
360
+ - Query geographic → includes noospheric data
361
+ - Query noospheric → includes geographic data
362
+
363
+ **Acceptance**: Test written, fails (cross-dimensional workflow not implemented)
364
+
365
+ ---
366
+
367
+ ## Phase 3.3: Core Implementation (ONLY after tests are failing)
368
+
369
+ **Prerequisites**: All tests (T007-T025) written and failing
370
+
371
+ ### Unit Tests (Module-specific) - All [P]
372
+
373
+ ### T026: [P] Unit test for core module
374
+ **File**: `tests/unit/core.test.js`
375
+ **Description**: Unit tests for `src/core/`:
376
+ - HoloSphere class initialization
377
+ - Config validation and defaults
378
+ - GunDB instance creation
379
+ - Radisk adapter integration
380
+ - Log level configuration
381
+
382
+ **Acceptance**: Test written, fails (core module not implemented)
383
+
384
+ ---
385
+
386
+ ### T027: [P] Unit test for spatial module
387
+ **File**: `tests/unit/spatial.test.js`
388
+ **Description**: Unit tests for `src/spatial/`:
389
+ - H3 validation (starts with '8', ≥15 chars)
390
+ - Coordinate to H3 conversion
391
+ - Parent/child hierarchy navigation
392
+ - Resolution extraction
393
+ - Edge cases (poles, dateline)
394
+
395
+ **Acceptance**: Test written, fails (spatial module not implemented)
396
+
397
+ ---
398
+
399
+ ### T028: [P] Unit test for storage module
400
+ **File**: `tests/unit/storage.test.js`
401
+ **Description**: Unit tests for `src/storage/`:
402
+ - Path construction (`appname/holon/lens/key`)
403
+ - Gun graph operations (get, put, once)
404
+ - Radisk persistence
405
+ - Path encoding (special characters)
406
+ - Error handling
407
+
408
+ **Acceptance**: Test written, fails (storage module not implemented)
409
+
410
+ ---
411
+
412
+ ### T029: [P] Unit test for schema module
413
+ **File**: `tests/unit/schema.test.js`
414
+ **Description**: Unit tests for `src/schema/`:
415
+ - JSON Schema 2019 validation
416
+ - Ajv validator compilation
417
+ - Schema caching (1-hour TTL)
418
+ - Cache expiration and recompilation
419
+ - Strict vs permissive mode
420
+
421
+ **Acceptance**: Test written, fails (schema module not implemented)
422
+
423
+ ---
424
+
425
+ ### T030: [P] Unit test for federation module
426
+ **File**: `tests/unit/federation.test.js`
427
+ **Description**: Unit tests for `src/federation/`:
428
+ - Hologram creation (reference structure)
429
+ - Hologram resolution (dereference)
430
+ - Circular reference detection
431
+ - Federation config validation
432
+ - Inbound/outbound/bidirectional modes
433
+
434
+ **Acceptance**: Test written, fails (federation module not implemented)
435
+
436
+ ---
437
+
438
+ ### T031: [P] Unit test for content module
439
+ **File**: `tests/unit/content.test.js`
440
+ **Description**: Unit tests for `src/content/`:
441
+ - Nostr event format validation (NIP-01)
442
+ - ActivityPub object format validation
443
+ - Protocol adapter interface
444
+ - Stigmergic access level filtering
445
+ - Content transformation (to/from HoloSphere format)
446
+
447
+ **Acceptance**: Test written, fails (content module not implemented)
448
+
449
+ ---
450
+
451
+ ### T032: [P] Unit test for crypto module
452
+ **File**: `tests/unit/crypto.test.js`
453
+ **Description**: Unit tests for `src/crypto/`:
454
+ - secp256k1 signing and verification
455
+ - Capability token generation
456
+ - Token expiration validation
457
+ - Nonce uniqueness (replay protection)
458
+ - Lazy initialization (module not loaded until first use)
459
+
460
+ **Acceptance**: Test written, fails (crypto module not implemented)
461
+
462
+ ---
463
+
464
+ ### T033: [P] Unit test for subscriptions module
465
+ **File**: `tests/unit/subscriptions.test.js`
466
+ **Description**: Unit tests for `src/subscriptions/`:
467
+ - Gun `.on()` listener attachment
468
+ - Callback invocation on data changes
469
+ - Throttling mechanism
470
+ - Filter predicate application
471
+ - Unsubscribe cleanup
472
+
473
+ **Acceptance**: Test written, fails (subscriptions module not implemented)
474
+
475
+ ---
476
+
477
+ ### T033.5: [P] Unit test for hierarchical module
478
+ **File**: `tests/unit/hierarchical.test.js`
479
+ **Description**: Unit tests for `src/hierarchical/`:
480
+ - Upcast operation with summarize mode
481
+ - Upcast operation with aggregate mode
482
+ - Upcast operation with concatenate mode
483
+ - MaxLevel limit enforcement (default: 3 levels)
484
+ - Parent hierarchy traversal
485
+ - Error: noospheric holons (no hierarchy support)
486
+
487
+ **Acceptance**: Test written, fails (hierarchical module not implemented)
488
+
489
+ ---
490
+
491
+ ### Module Implementations
492
+
493
+ ### T034: [P] Implement core module
494
+ **File**: `src/core/holosphere.js`
495
+ **Description**: Implement HoloSphere class:
496
+ - Constructor with config validation
497
+ - Initialize GunDB with radisk adapter
498
+ - Set up logging (structured JSON format)
499
+ - Store app configuration
500
+ - Export class
501
+
502
+ **Dependencies**: None
503
+ **Acceptance**: Unit tests (T026) pass
504
+
505
+ ---
506
+
507
+ ### T035: [P] Implement spatial module
508
+ **File**: `src/spatial/h3-operations.js`
509
+ **Description**: Implement H3 spatial operations:
510
+ - `toHolon(lat, lng, resolution)` using h3-js `geoToH3()`
511
+ - `getParents(holonId, maxResolution)` using `h3ToParent()` iteratively
512
+ - `getChildren(holonId)` using `h3ToChildren()`
513
+ - `isValidH3(holonId)` using `h3IsValid()` + format check
514
+ - `getResolution(holonId)` using `h3GetResolution()`
515
+ - Input validation and error handling
516
+
517
+ **Dependencies**: T034 (core)
518
+ **Acceptance**: Unit tests (T027) and contract tests (T008) pass
519
+
520
+ ---
521
+
522
+ ### T036: Implement storage module
523
+ **File**: `src/storage/gun-wrapper.js`
524
+ **Description**: Implement GunDB storage wrapper:
525
+ - Path construction (`buildPath(appname, holon, lens, key)`)
526
+ - `write(path, data)` → Gun `.put()` with radisk persistence
527
+ - `read(path)` → Gun `.once()` with Promise wrapper
528
+ - `delete(path)` → Gun `.put(null)` for tombstone
529
+ - `subscribe(path, callback)` → Gun `.on()` with cleanup
530
+ - Path encoding for special characters
531
+
532
+ **Dependencies**: T034 (core)
533
+ **Acceptance**: Unit tests (T028) pass
534
+
535
+ ---
536
+
537
+ ### T036.5: Implement global data operations
538
+ **File**: `src/storage/global-tables.js`
539
+ **Description**: Extend storage for non-location-specific data (FR-044, FR-045):
540
+ - `writeGlobal(table, data)` → Nostr write to `appname/{table}/{data.id}` (id extracted from data)
541
+ - `readGlobal(table, key?)` → Nostr read from global path
542
+ - `updateGlobal(table, key, updates)` → merge updates
543
+ - `deleteGlobal(table, key)` → tombstone
544
+ - No holon parameter required
545
+ - Consistent CRUD operations matching holon-based data API
546
+
547
+ **Dependencies**: T036 (storage module)
548
+ **Acceptance**: Extended unit tests (T028) pass with global operations
549
+
550
+ ---
551
+
552
+ ### T037: Implement schema module
553
+ **File**: `src/schema/validator.js`
554
+ **Description**: Implement JSON Schema validation:
555
+ - `compileSchema(schemaUri)` → Ajv validator with caching
556
+ - `validate(data, lensName, strict)` → boolean | ValidationError
557
+ - Schema cache with TTL (1 hour default)
558
+ - Cache invalidation and recompilation
559
+ - Logging for validation failures (permissive mode)
560
+
561
+ **Dependencies**: T036 (storage for schema retrieval)
562
+ **Acceptance**: Unit tests (T029) and contract tests (T010) pass
563
+
564
+ ---
565
+
566
+ ### T038: Implement federation module
567
+ **File**: `src/federation/hologram.js`
568
+ **Description**: Implement federation and holograms:
569
+ - `createHologram(sourceHolon, targetHolon, lensName, dataId)` → hologram object
570
+ - `resolveHologram(hologram, visitedSet)` → actual data
571
+ - Circular reference detection (max depth: 10)
572
+ - `setupFederation(source, target, lens, options)` → config
573
+ - `propagateData(data, federation)` → create holograms in target
574
+
575
+ **Dependencies**: T036 (storage), T035 (spatial for hierarchy)
576
+ **Acceptance**: Unit tests (T030) and contract tests (T011) pass
577
+
578
+ ---
579
+
580
+ ### T039: [P] Implement crypto module (lazy loading)
581
+ **File**: `src/crypto/secp256k1.js`
582
+ **Description**: Implement cryptographic operations:
583
+ - Dynamic import of `@noble/curves/secp256k1`
584
+ - `sign(content, privateKey)` → signature
585
+ - `verify(content, signature, publicKey)` → boolean
586
+ - `issueCapability(permissions, scope, recipient, options)` → token
587
+ - `verifyCapability(token, requiredPermission, scope)` → boolean
588
+ - Nonce generation and replay protection
589
+
590
+ **Dependencies**: None (lazy loaded)
591
+ **Acceptance**: Unit tests (T032) and contract tests (T014) pass
592
+
593
+ ---
594
+
595
+ ### T040: Implement content module
596
+ **File**: `src/content/social-protocols.js`
597
+ **Description**: Implement social protocol adapters:
598
+ - Nostr adapter: NIP-01 event validation, signing, verification
599
+ - ActivityPub adapter: JSON-LD validation, HTTP signatures
600
+ - `publishNostr(event, holonId, lensName)` → write to storage
601
+ - `publishActivityPub(object, holonId, lensName)` → write to storage
602
+ - `querySocial(holonId, options)` → filter by protocol and access level
603
+
604
+ **Dependencies**: T036 (storage), T039 (crypto for signatures)
605
+ **Acceptance**: Unit tests (T031) and contract tests (T015) pass
606
+
607
+ ---
608
+
609
+ ### T041: Implement subscriptions module
610
+ **File**: `src/subscriptions/manager.js`
611
+ **Description**: Implement subscription management:
612
+ - `subscribe(holonId, lensName, callback, options)` → subscription object
613
+ - Gun `.on()` listener with throttle and filter
614
+ - Callback invocation on data changes
615
+ - `unsubscribe()` cleanup (remove listener)
616
+ - Subscription registry for tracking active subscriptions
617
+
618
+ **Dependencies**: T036 (storage)
619
+ **Acceptance**: Unit tests (T033) and contract tests (T013) pass
620
+
621
+ ---
622
+
623
+ ### T041.5: Implement hierarchical upcast module
624
+ **File**: `src/hierarchical/upcast.js`
625
+ **Description**: Implement hierarchical aggregation with operations (FR-025 to FR-027):
626
+ - `upcast(holonId, lensName, dataId, options)` → boolean
627
+ - Operation modes: 'summarize' (count), 'aggregate' (merge objects), 'concatenate' (arrays)
628
+ - Traverse H3 parent hierarchy up to maxLevel (default: 3)
629
+ - Write holograms to parent holons referencing original data
630
+ - Error handling for noospheric holons (no spatial hierarchy)
631
+ - Integration with spatial module for parent traversal
632
+ - Integration with storage module for hologram creation
633
+
634
+ **Dependencies**: T035 (spatial), T036 (storage), T038 (federation for holograms)
635
+ **Acceptance**: Unit tests (T033.5) and contract tests (T012) pass
636
+
637
+ ---
638
+
639
+ ## Phase 3.4: Integration & Public API
640
+
641
+ ### T042: Wire up public API exports
642
+ **File**: `src/index.js`
643
+ **Description**: Create main entry point exporting HoloSphere class with all methods:
644
+ - Import and attach all modules to HoloSphere prototype
645
+ - Core: constructor
646
+ - Spatial: toHolon, getParents, getChildren, isValidH3
647
+ - Data: write, read, update, delete, writeGlobal, readGlobal, updateGlobal, deleteGlobal
648
+ - Schema: setSchema, getSchema, clearSchema
649
+ - Federation: federate, getFederatedData, unfederate
650
+ - Hierarchical: upcast
651
+ - Subscriptions: subscribe
652
+ - Crypto: sign, verify, issueCapability, verifyCapability
653
+ - Social: publishNostr, publishActivityPub, querySocial
654
+ - Utils: metrics
655
+ - Export error classes: ValidationError, AuthorizationError, HolosphereError
656
+
657
+ **Dependencies**: All modules (T034-T041.5)
658
+ **Acceptance**: All contract tests (T007-T016) pass
659
+
660
+ ---
661
+
662
+ ### T043: Verify all integration tests pass
663
+ **Files**: `tests/integration/scenario-*.test.js`
664
+ **Description**: Run all integration tests and verify end-to-end workflows:
665
+ - All 9 quickstart scenarios execute successfully
666
+ - No test failures, no errors
667
+ - Data persists correctly with radisk
668
+ - Federation works across dimensions
669
+ - Authorization enforced properly
670
+
671
+ **Dependencies**: T042 (public API complete)
672
+ **Acceptance**: All integration tests (T017-T025) pass
673
+
674
+ ---
675
+
676
+ ## Phase 3.5: Build, Distribution & Polish
677
+
678
+ ### T044: Configure ESM build
679
+ **File**: `vite.config.js` (already created in T003, update if needed)
680
+ **Description**: Ensure ESM build configuration:
681
+ - Entry: `src/index.js`
682
+ - Output: `dist/esm/holosphere.js`
683
+ - Format: `es`
684
+ - Tree-shakeable exports
685
+ - Sourcemaps
686
+
687
+ **Dependencies**: T043 (tests passing)
688
+ **Acceptance**: `npm run build` creates `dist/esm/holosphere.js`
689
+
690
+ ---
691
+
692
+ ### T045: Configure CommonJS build
693
+ **File**: `vite.config.js` (update)
694
+ **Description**: Add CommonJS build target:
695
+ - Output: `dist/cjs/holosphere.cjs`
696
+ - Format: `cjs`
697
+ - Externalize peer dependencies (optional)
698
+
699
+ **Dependencies**: T044
700
+ **Acceptance**: `npm run build` creates `dist/cjs/holosphere.cjs`
701
+
702
+ ---
703
+
704
+ ### T046: Configure CDN bundle with radisk
705
+ **File**: `vite.config.js` (update)
706
+ **Description**: Add UMD bundle for CDN:
707
+ - Output: `dist/cdn/holosphere.min.js`
708
+ - Format: `umd`
709
+ - Global name: `HoloSphere`
710
+ - Bundle ALL dependencies (Gun, h3-js, @noble/curves, Ajv, radisk)
711
+ - Minify with terser
712
+
713
+ **Dependencies**: T045
714
+ **Acceptance**: `npm run build` creates `dist/cdn/holosphere.min.js`
715
+
716
+ ---
717
+
718
+ ### T047: Validate bundle size (<1MB target)
719
+ **File**: Create `scripts/check-bundle-size.js`
720
+ **Description**: Script to validate bundle size:
721
+ - Read `dist/cdn/holosphere.min.js` size
722
+ - Calculate gzipped size
723
+ - Assert <1MB (1,048,576 bytes)
724
+ - Exit with error if exceeds limit
725
+ - Add to `npm test` script
726
+
727
+ **Dependencies**: T046
728
+ **Acceptance**: Bundle size <1MB minified+gzipped
729
+
730
+ ---
731
+
732
+ ### T048: Configure package.json exports
733
+ **File**: `package.json` (update)
734
+ **Description**: Add package exports configuration:
735
+ ```json
736
+ {
737
+ "type": "module",
738
+ "main": "./dist/cjs/holosphere.cjs",
739
+ "module": "./dist/esm/holosphere.js",
740
+ "browser": "./dist/cdn/holosphere.min.js",
741
+ "exports": {
742
+ ".": {
743
+ "import": "./dist/esm/holosphere.js",
744
+ "require": "./dist/cjs/holosphere.cjs"
745
+ }
746
+ }
747
+ }
748
+ ```
749
+
750
+ **Dependencies**: T046
751
+ **Acceptance**: `npm pack` creates package with correct exports
752
+
753
+ ---
754
+
755
+ ### T049: [P] Generate TypeScript definitions
756
+ **File**: Create `scripts/generate-types.js` or use `tsc`
757
+ **Description**: Generate TypeScript `.d.ts` files:
758
+ - Create type definitions for HoloSphere class
759
+ - Define all method signatures with parameter types
760
+ - Export error class types
761
+ - Include JSDoc comments from source
762
+ - Output to `dist/types/index.d.ts`
763
+ - Add `"types": "./dist/types/index.d.ts"` to package.json
764
+
765
+ **Dependencies**: T042 (source complete)
766
+ **Acceptance**: `dist/types/index.d.ts` exists with all API types
767
+
768
+ ---
769
+
770
+ ### T050: [P] Verify code coverage ≥80%
771
+ **File**: N/A (run coverage report)
772
+ **Description**: Run `npm run test:coverage` and verify:
773
+ - Line coverage ≥80% across all modules
774
+ - All modules have unit tests
775
+ - Contract tests cover 100% of public API
776
+ - Integration tests cover all user stories
777
+ - Generate HTML coverage report
778
+
779
+ **Dependencies**: T043 (all tests passing)
780
+ **Acceptance**: Coverage report shows ≥80% line coverage
781
+
782
+ ---
783
+
784
+ ### T051: [P] Create README.md with quickstart
785
+ **File**: `README.md`
786
+ **Description**: Create comprehensive README:
787
+ - Project description
788
+ - Installation (npm, CDN)
789
+ - Quick start example (basic usage)
790
+ - Link to full API documentation
791
+ - Link to quickstart scenarios
792
+ - Contributing guidelines
793
+ - License (specify)
794
+
795
+ **Dependencies**: T048 (package configured)
796
+ **Acceptance**: README covers installation and basic usage
797
+
798
+ ---
799
+
800
+ ### T052: [P] Performance validation
801
+ **File**: Create `tests/performance/benchmark.test.js`
802
+ **Description**: Performance tests:
803
+ - Initialization time <50ms (without crypto lazy load)
804
+ - Write operation <20ms (avg)
805
+ - Read operation <10ms (avg)
806
+ - Subscription overhead <5ms
807
+ - Hologram resolution <15ms (single level)
808
+
809
+ **Dependencies**: T043
810
+ **Acceptance**: All performance benchmarks meet targets
811
+
812
+ ---
813
+
814
+ ## Dependencies
815
+
816
+ **Sequential Dependencies**:
817
+ - Setup (T001-T006) → Tests (T007-T033) → Implementation (T034-T041) → Integration (T042-T043) → Build (T044-T052)
818
+
819
+ **Module Dependencies**:
820
+ - T035 (spatial), T036 (storage), T039 (crypto) depend on T034 (core)
821
+ - T037 (schema) depends on T036 (storage)
822
+ - T038 (federation) depends on T035 (spatial) and T036 (storage)
823
+ - T040 (content) depends on T036 (storage) and T039 (crypto)
824
+ - T041 (subscriptions) depends on T036 (storage)
825
+ - T042 (public API) depends on all modules (T034-T041)
826
+
827
+ **Test Dependencies**:
828
+ - Contract tests (T007-T016) can run in parallel
829
+ - Integration tests (T017-T025) can run in parallel
830
+ - Unit tests (T026-T033) can run in parallel
831
+ - All tests must be written before implementation begins
832
+
833
+ **Build Dependencies**:
834
+ - T045 (CJS) depends on T044 (ESM)
835
+ - T046 (CDN) depends on T045 (CJS)
836
+ - T047 (size check) depends on T046 (CDN)
837
+ - T048 (exports) depends on T046 (all builds complete)
838
+
839
+ ---
840
+
841
+ ## Parallel Execution Examples
842
+
843
+ ### Launch all contract tests together (T007-T016):
844
+ ```bash
845
+ # Use Task tool or run tests in parallel
846
+ vitest run tests/contract/core.test.js &
847
+ vitest run tests/contract/spatial.test.js &
848
+ vitest run tests/contract/data.test.js &
849
+ vitest run tests/contract/schema.test.js &
850
+ vitest run tests/contract/federation.test.js &
851
+ vitest run tests/contract/hierarchical.test.js &
852
+ vitest run tests/contract/subscriptions.test.js &
853
+ vitest run tests/contract/crypto.test.js &
854
+ vitest run tests/contract/social.test.js &
855
+ vitest run tests/contract/utils.test.js &
856
+ wait
857
+ ```
858
+
859
+ ### Launch all integration tests together (T017-T025):
860
+ ```bash
861
+ vitest run tests/integration/scenario-01-geographic-storage.test.js &
862
+ vitest run tests/integration/scenario-02-federation.test.js &
863
+ vitest run tests/integration/scenario-03-subscriptions.test.js &
864
+ vitest run tests/integration/scenario-04-validation.test.js &
865
+ vitest run tests/integration/scenario-05-hierarchy.test.js &
866
+ vitest run tests/integration/scenario-06-social.test.js &
867
+ vitest run tests/integration/scenario-07-persistence.test.js &
868
+ vitest run tests/integration/scenario-08-authorization.test.js &
869
+ vitest run tests/integration/scenario-09-cross-dimensional.test.js &
870
+ wait
871
+ ```
872
+
873
+ ### Launch parallel unit tests (T026-T033):
874
+ ```bash
875
+ vitest run tests/unit/core.test.js &
876
+ vitest run tests/unit/spatial.test.js &
877
+ vitest run tests/unit/storage.test.js &
878
+ vitest run tests/unit/schema.test.js &
879
+ vitest run tests/unit/federation.test.js &
880
+ vitest run tests/unit/content.test.js &
881
+ vitest run tests/unit/crypto.test.js &
882
+ vitest run tests/unit/subscriptions.test.js &
883
+ wait
884
+ ```
885
+
886
+ ### Launch parallel module implementations (T034, T035, T036, T039):
887
+ ```bash
888
+ # Independent modules with no cross-dependencies
889
+ # Task: "Implement core module in src/core/holosphere.js"
890
+ # Task: "Implement spatial module in src/spatial/h3-operations.js (depends on core)"
891
+ # Task: "Implement storage module in src/storage/gun-wrapper.js (depends on core)"
892
+ # Task: "Implement crypto module in src/crypto/secp256k1.js (independent, lazy loaded)"
893
+ ```
894
+
895
+ ---
896
+
897
+ ## Notes
898
+
899
+ - **[P] tasks** = Different files, no dependencies, safe to parallelize
900
+ - **TDD Enforcement**: All tests (T007-T033) MUST be written and failing before implementation (T034-T041)
901
+ - **Constitutional Compliance**: Every module has unit tests (per Constitution XI)
902
+ - **Coverage Target**: ≥80% line coverage enforced in T050
903
+ - **Commit Strategy**: Commit after each task or logical group
904
+ - **Error Handling**: All modules must use structured logging (JSON format)
905
+
906
+ ---
907
+
908
+ ## Validation Checklist
909
+
910
+ **Pre-Implementation Gates**:
911
+ - [x] All contracts have corresponding tests (T007-T016)
912
+ - [x] All entities have model/implementation tasks (9 entities → 8 modules)
913
+ - [x] All tests come before implementation (Phase 3.2 before 3.3)
914
+ - [x] Parallel tasks truly independent (verified file paths)
915
+ - [x] Each task specifies exact file path
916
+ - [x] No [P] task modifies same file as another [P] task
917
+
918
+ **Post-Implementation Gates**:
919
+ - [ ] All contract tests pass (run after T042)
920
+ - [ ] All integration tests pass (run after T043)
921
+ - [ ] All unit tests pass (continuous)
922
+ - [ ] Code coverage ≥80% (T050)
923
+ - [ ] Bundle size <1MB (T047)
924
+ - [ ] Performance benchmarks met (T052)
925
+
926
+ ---
927
+
928
+ ## Summary
929
+
930
+ **Total Tasks**: 52 (T001-T052)
931
+ **Parallel Opportunities**:
932
+ - 10 contract tests [P]
933
+ - 9 integration tests [P]
934
+ - 8 unit tests [P]
935
+ - 4 module implementations [P] (core, spatial, storage, crypto initially)
936
+ - 3 polish tasks [P] (types, coverage, docs)
937
+
938
+ **Estimated Phases**:
939
+ 1. Setup: 6 tasks (sequential)
940
+ 2. Tests: 27 tasks (mostly parallel)
941
+ 3. Implementation: 9 tasks (parallel with dependencies)
942
+ 4. Integration: 2 tasks (sequential)
943
+ 5. Build & Polish: 8 tasks (mixed)
944
+
945
+ **Critical Path**: Setup → Tests → Core modules → Storage → Federation → Public API → Integration → Build
946
+
947
+ **Next Step**: Begin with T001 (Initialize npm project)