holosphere 2.0.0-alpha1 → 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 (87) hide show
  1. package/dist/cjs/holosphere.cjs +2 -0
  2. package/dist/cjs/holosphere.cjs.map +1 -0
  3. package/dist/esm/holosphere.js +56 -0
  4. package/dist/esm/holosphere.js.map +1 -0
  5. package/dist/index-CDfIuXew.js +15974 -0
  6. package/dist/index-CDfIuXew.js.map +1 -0
  7. package/dist/index-ifOgtDvd.cjs +3 -0
  8. package/dist/index-ifOgtDvd.cjs.map +1 -0
  9. package/dist/indexeddb-storage-CMW4qRQS.js +96 -0
  10. package/dist/indexeddb-storage-CMW4qRQS.js.map +1 -0
  11. package/dist/indexeddb-storage-DLZOgetM.cjs +2 -0
  12. package/dist/indexeddb-storage-DLZOgetM.cjs.map +1 -0
  13. package/dist/memory-storage-DQzcAZlf.js +47 -0
  14. package/dist/memory-storage-DQzcAZlf.js.map +1 -0
  15. package/dist/memory-storage-DmePEP2q.cjs +2 -0
  16. package/dist/memory-storage-DmePEP2q.cjs.map +1 -0
  17. package/dist/secp256k1-CP0ZkpAx.cjs +13 -0
  18. package/dist/secp256k1-CP0ZkpAx.cjs.map +1 -0
  19. package/dist/secp256k1-vOXp40Fx.js +2281 -0
  20. package/dist/secp256k1-vOXp40Fx.js.map +1 -0
  21. package/docs/FOSDEM_PROPOSAL.md +388 -0
  22. package/docs/LOCALFIRST.md +266 -0
  23. package/docs/contracts/api-interface.md +793 -0
  24. package/docs/data-model.md +476 -0
  25. package/docs/gun-async-usage.md +338 -0
  26. package/docs/plan.md +349 -0
  27. package/docs/quickstart.md +674 -0
  28. package/docs/research.md +362 -0
  29. package/docs/spec.md +244 -0
  30. package/docs/storage-backends.md +326 -0
  31. package/docs/tasks.md +947 -0
  32. package/package.json +1 -1
  33. package/tests/unit/ai/aggregation.test.js +0 -295
  34. package/tests/unit/ai/breakdown.test.js +0 -446
  35. package/tests/unit/ai/classifier.test.js +0 -294
  36. package/tests/unit/ai/council.test.js +0 -262
  37. package/tests/unit/ai/embeddings.test.js +0 -384
  38. package/tests/unit/ai/federation-ai.test.js +0 -344
  39. package/tests/unit/ai/h3-ai.test.js +0 -458
  40. package/tests/unit/ai/index.test.js +0 -304
  41. package/tests/unit/ai/json-ops.test.js +0 -307
  42. package/tests/unit/ai/llm-service.test.js +0 -390
  43. package/tests/unit/ai/nl-query.test.js +0 -383
  44. package/tests/unit/ai/relationships.test.js +0 -311
  45. package/tests/unit/ai/schema-extractor.test.js +0 -384
  46. package/tests/unit/ai/spatial.test.js +0 -279
  47. package/tests/unit/ai/tts.test.js +0 -279
  48. package/tests/unit/content.test.js +0 -332
  49. package/tests/unit/contract/core.test.js +0 -88
  50. package/tests/unit/contract/crypto.test.js +0 -198
  51. package/tests/unit/contract/data.test.js +0 -223
  52. package/tests/unit/contract/federation.test.js +0 -181
  53. package/tests/unit/contract/hierarchical.test.js +0 -113
  54. package/tests/unit/contract/schema.test.js +0 -114
  55. package/tests/unit/contract/social.test.js +0 -217
  56. package/tests/unit/contract/spatial.test.js +0 -110
  57. package/tests/unit/contract/subscriptions.test.js +0 -128
  58. package/tests/unit/contract/utils.test.js +0 -159
  59. package/tests/unit/core.test.js +0 -152
  60. package/tests/unit/crypto.test.js +0 -328
  61. package/tests/unit/federation.test.js +0 -234
  62. package/tests/unit/gun-async.test.js +0 -252
  63. package/tests/unit/hierarchical.test.js +0 -399
  64. package/tests/unit/integration/scenario-01-geographic-storage.test.js +0 -74
  65. package/tests/unit/integration/scenario-02-federation.test.js +0 -76
  66. package/tests/unit/integration/scenario-03-subscriptions.test.js +0 -102
  67. package/tests/unit/integration/scenario-04-validation.test.js +0 -129
  68. package/tests/unit/integration/scenario-05-hierarchy.test.js +0 -125
  69. package/tests/unit/integration/scenario-06-social.test.js +0 -135
  70. package/tests/unit/integration/scenario-07-persistence.test.js +0 -130
  71. package/tests/unit/integration/scenario-08-authorization.test.js +0 -161
  72. package/tests/unit/integration/scenario-09-cross-dimensional.test.js +0 -139
  73. package/tests/unit/integration/scenario-10-cross-holosphere-capabilities.test.js +0 -357
  74. package/tests/unit/integration/scenario-11-cross-holosphere-federation.test.js +0 -410
  75. package/tests/unit/integration/scenario-12-capability-federated-read.test.js +0 -719
  76. package/tests/unit/performance/benchmark.test.js +0 -85
  77. package/tests/unit/schema.test.js +0 -213
  78. package/tests/unit/spatial.test.js +0 -158
  79. package/tests/unit/storage.test.js +0 -195
  80. package/tests/unit/subscriptions.test.js +0 -328
  81. package/tests/unit/test-data-permanence-debug.js +0 -197
  82. package/tests/unit/test-data-permanence.js +0 -340
  83. package/tests/unit/test-key-persistence-fixed.js +0 -148
  84. package/tests/unit/test-key-persistence.js +0 -172
  85. package/tests/unit/test-relay-permanence.js +0 -376
  86. package/tests/unit/test-second-node.js +0 -95
  87. package/tests/unit/test-simple-write.js +0 -89
@@ -0,0 +1,362 @@
1
+ # Phase 0: Research & Technical Decisions
2
+
3
+ **Feature**: HoloSphere - Holonic Geospatial Communication Infrastructure
4
+ **Date**: 2025-10-07
5
+ **Status**: Complete
6
+
7
+ ## Overview
8
+ This document captures technical research and decisions for implementing HoloSphere, a JavaScript library combining H3 hexagonal geospatial indexing with GunDB distributed P2P storage. All technical context items have been resolved through specification clarifications and architectural planning.
9
+
10
+ ---
11
+
12
+ ## 1. Core Technology Stack
13
+
14
+ ### Decision: JavaScript (ES2020+) with Node.js 18+ and Modern Browsers
15
+ **Rationale**:
16
+ - JavaScript provides native cross-platform support for both Node.js and browser environments
17
+ - ES2020+ features (optional chaining, nullish coalescing, dynamic imports) improve code quality
18
+ - Node.js 18+ provides stable LTS support with modern ECMAScript features
19
+ - Modern browsers universally support ES6 modules for tree-shaking and efficient bundling
20
+
21
+ **Alternatives Considered**:
22
+ - TypeScript: Adds type safety but increases build complexity; decided to provide TypeScript definitions (.d.ts) without full TS implementation
23
+ - Rust/WASM: Better performance but increases bundle size and reduces accessibility for JavaScript developers
24
+
25
+ **Implementation Notes**:
26
+ - Use ESM as primary module format with CommonJS compatibility via build tooling
27
+ - Leverage dynamic imports for lazy loading of crypto operations
28
+ - Target ES2020 for broad compatibility while enabling modern features
29
+
30
+ ---
31
+
32
+ ## 2. Geospatial Indexing
33
+
34
+ ### Decision: h3-js Library for H3 Hexagonal Grid Operations
35
+ **Rationale**:
36
+ - Official Uber H3 JavaScript implementation with proven reliability
37
+ - Supports all 16 resolution levels (0-15) covering global to ~1m² precision
38
+ - Provides efficient parent-child hierarchy operations for scalespace queries
39
+ - Active maintenance and comprehensive documentation
40
+
41
+ **Alternatives Considered**:
42
+ - Custom H3 implementation: Unnecessary complexity, error-prone
43
+ - S2 geometry: Less mature JavaScript ecosystem, less intuitive hexagonal structure
44
+ - Geohash: Irregular cell boundaries, poor hierarchical properties compared to hexagons
45
+
46
+ **Key Operations**:
47
+ - `geoToH3()`: Convert lat/lng to H3 cell ID
48
+ - `h3ToParent()`: Navigate up hierarchy for upcast operations
49
+ - `h3ToChildren()`: Navigate down hierarchy for drill-down queries
50
+ - `h3IsValid()`: Validate H3 format (must start with '8', ≥15 chars)
51
+
52
+ ---
53
+
54
+ ## 3. Distributed Storage
55
+
56
+ ### Decision: GunDB with Radisk Adapter
57
+ **Rationale**:
58
+ - GunDB provides decentralized P2P architecture without central servers (constitutional requirement)
59
+ - Built-in real-time synchronization and reactive subscriptions
60
+ - Radisk adapter ensures local-first persistence (IndexedDB in browser, filesystem in Node.js)
61
+ - Eventual consistency with conflict resolution (last-write-wins) aligns with federation requirements
62
+
63
+ **Alternatives Considered**:
64
+ - OrbitDB: More complex setup, less mature ecosystem
65
+ - Automerge: Excellent CRDT support but larger bundle size, narrower use case
66
+ - Custom WebRTC + IndexedDB: Too much complexity to build from scratch
67
+
68
+ **Implementation Strategy**:
69
+ - Initialize GunDB with radisk adapter by default in all environments
70
+ - Configure peer connections for distributed sync (optional central relays for NAT traversal)
71
+ - Use Gun's graph structure for natural holon/lens/data hierarchy
72
+ - Path structure: `appname.holon.lens.key` maps to Gun graph nodes
73
+
74
+ **Radisk Configuration**:
75
+ ```javascript
76
+ // Browser
77
+ Gun({ radisk: true })
78
+
79
+ // Node.js
80
+ Gun({ file: 'data/holosphere' })
81
+ ```
82
+
83
+ ---
84
+
85
+ ## 4. Cryptographic Operations
86
+
87
+ ### Decision: @noble/curves for secp256k1 Operations
88
+ **Rationale**:
89
+ - Industry-standard secp256k1 curve (same as Bitcoin, Ethereum, Nostr)
90
+ - Lightweight, audited implementation with no native dependencies
91
+ - Supports signing, verification, key derivation
92
+ - Lazy initialization reduces startup cost when crypto features not immediately needed
93
+
94
+ **Alternatives Considered**:
95
+ - elliptic.js: Larger bundle size, less actively maintained
96
+ - Native Web Crypto API: Limited to P-256 curve, doesn't support secp256k1
97
+ - noble-secp256k1 (standalone): @noble/curves supersedes this with better ergonomics
98
+
99
+ **Cryptographic Features**:
100
+ - Content signing (Nostr/ActivityPub protocol support)
101
+ - Capability token generation and verification
102
+ - Password-based holon access control (combined with Gun's SEA module)
103
+ - Lazy loading via dynamic imports to avoid initialization cost
104
+
105
+ **Bundle Impact**: ~30KB minified+gzipped for secp256k1 operations
106
+
107
+ ---
108
+
109
+ ## 5. Schema Validation
110
+
111
+ ### Decision: Ajv (Another JSON Schema Validator)
112
+ **Rationale**:
113
+ - Industry standard for JSON Schema validation
114
+ - Supports JSON Schema 2019 draft (constitutional requirement)
115
+ - Fast performance through JIT compilation
116
+ - Small bundle size (~50KB minified+gzipped)
117
+ - Supports custom error messages and formats
118
+
119
+ **Alternatives Considered**:
120
+ - joi: More focused on runtime validation, less standard schema format
121
+ - yup: Similar to joi, lacks JSON Schema compatibility
122
+ - Custom validation: Reinventing the wheel, missing edge cases
123
+
124
+ **Implementation Strategy**:
125
+ - Cache compiled schemas with 1-hour TTL (configurable)
126
+ - Provide strict mode (blocking) and permissive mode (logging only)
127
+ - Schema storage: Schemas stored in Gun alongside data for decentralized distribution
128
+ - Per-lens schemas with independent validation rules
129
+
130
+ **Cache Design**:
131
+ ```javascript
132
+ const schemaCache = new Map(); // key: lens name, value: { validator, timestamp }
133
+ const CACHE_TTL = 3600000; // 1 hour in milliseconds
134
+ ```
135
+
136
+ ---
137
+
138
+ ## 6. Testing Framework
139
+
140
+ ### Decision: Vitest for Unit and Integration Testing
141
+ **Rationale**:
142
+ - Fast, Vite-powered test runner with excellent DX
143
+ - Native ESM support (no transpilation needed)
144
+ - Compatible with Jest API (familiar patterns)
145
+ - Built-in code coverage reporting
146
+ - Supports both Node.js and browser environment testing
147
+
148
+ **Alternatives Considered**:
149
+ - Jest: Slower, requires transpilation for ESM, heavier dependency footprint
150
+ - Mocha + Chai: Requires more configuration, less integrated tooling
151
+ - uvu: Lightweight but less feature-complete
152
+
153
+ **Test Organization**:
154
+ - **Unit tests**: One test file per feature module (tests/unit/*.test.js)
155
+ - **Integration tests**: Cross-module scenarios (tests/integration/*.test.js)
156
+ - **Contract tests**: API surface validation (tests/contract/*.test.js)
157
+
158
+ **Coverage Requirements**: ≥80% line coverage per constitutional mandate for reliability
159
+
160
+ ---
161
+
162
+ ## 7. Build and Distribution
163
+
164
+ ### Decision: Multi-format Build (ESM, CommonJS, CDN)
165
+ **Rationale**:
166
+ - ESM provides tree-shaking for optimal bundle sizes
167
+ - CommonJS ensures compatibility with legacy Node.js tools
168
+ - CDN bundle enables direct browser usage without build tools
169
+
170
+ **Build Tools**:
171
+ - **Vite**: Fast ESM-native bundler for development and production builds
172
+ - **Rollup** (via Vite): Bundle optimization and multi-format output
173
+ - **terser**: Minification for production builds
174
+
175
+ **Output Formats**:
176
+ ```
177
+ dist/
178
+ ├── esm/ # ES modules (primary, tree-shakeable)
179
+ │ └── holosphere.js
180
+ ├── cjs/ # CommonJS (Node.js compatibility)
181
+ │ └── holosphere.cjs
182
+ └── cdn/ # UMD bundle with all dependencies
183
+ └── holosphere.min.js # <1MB minified+gzipped target
184
+ ```
185
+
186
+ **Package.json Configuration**:
187
+ ```json
188
+ {
189
+ "type": "module",
190
+ "main": "./dist/cjs/holosphere.cjs",
191
+ "module": "./dist/esm/holosphere.js",
192
+ "browser": "./dist/cdn/holosphere.min.js",
193
+ "exports": {
194
+ ".": {
195
+ "import": "./dist/esm/holosphere.js",
196
+ "require": "./dist/cjs/holosphere.cjs"
197
+ }
198
+ }
199
+ }
200
+ ```
201
+
202
+ ---
203
+
204
+ ## 8. Performance Optimization Strategies
205
+
206
+ ### Lazy Initialization
207
+ **Decision**: Defer expensive operations until first use
208
+ **Implementation**:
209
+ - Crypto module loaded via dynamic import on first signature operation
210
+ - Schema validator compiled on first validation request
211
+ - H3 library loaded upfront (small footprint, core functionality)
212
+
213
+ ### Caching Strategy
214
+ **Decision**: Multi-level caching with configurable TTLs
215
+ **Caches**:
216
+ 1. **Schema cache**: Compiled validators (1-hour TTL)
217
+ 2. **Hologram resolution cache**: Recently resolved references (5-minute TTL)
218
+ 3. **H3 parent hierarchy cache**: Precomputed parent chains (permanent, small memory footprint)
219
+
220
+ ### Bundle Size Optimization
221
+ **Target**: <1MB minified+gzipped including all dependencies
222
+ **Techniques**:
223
+ - Tree-shakeable ESM exports (only import what you use)
224
+ - Lazy loading of crypto and validation modules
225
+ - Efficient dependency selection (prefer smaller, focused libraries)
226
+ - Code splitting for advanced features (social protocol integrations)
227
+
228
+ **Estimated Bundle Breakdown**:
229
+ - Core + Spatial: ~100KB
230
+ - GunDB + Radisk: ~400KB
231
+ - H3-js: ~150KB
232
+ - @noble/curves (lazy): ~30KB
233
+ - Ajv (lazy): ~50KB
234
+ - Social protocols (lazy): ~100KB
235
+ - **Total (full feature set)**: ~830KB minified+gzipped ✅
236
+
237
+ ---
238
+
239
+ ## 9. Social Protocol Integration
240
+
241
+ ### Decision: Pluggable Protocol Adapters for Nostr and ActivityPub
242
+ **Rationale**:
243
+ - Unified interface masks protocol differences
244
+ - Extensible design allows future protocol additions
245
+ - Lazy loading keeps base bundle small for users who don't need social features
246
+
247
+ **Nostr Integration**:
248
+ - Event signing with secp256k1 (NIP-01)
249
+ - Event validation and signature verification
250
+ - Stigmergic access levels via tag filtering
251
+
252
+ **ActivityPub Integration**:
253
+ - JSON-LD signature verification
254
+ - Actor/Object model mapping to HoloSphere entities
255
+ - HTTP signatures for authenticated federation
256
+
257
+ **Common Interface**:
258
+ ```javascript
259
+ class SocialProtocol {
260
+ async sign(content, privateKey) { /* ... */ }
261
+ async verify(content, signature, publicKey) { /* ... */ }
262
+ toHolosphereFormat(protocolContent) { /* ... */ }
263
+ fromHolosphereFormat(holosphereContent) { /* ... */ }
264
+ }
265
+ ```
266
+
267
+ ---
268
+
269
+ ## 10. Development Workflow
270
+
271
+ ### Decision: Standard npm-based Development Workflow
272
+ **Rationale**:
273
+ - Familiar to JavaScript developers
274
+ - Excellent tooling ecosystem
275
+ - Easy CI/CD integration
276
+
277
+ **Scripts**:
278
+ ```json
279
+ {
280
+ "scripts": {
281
+ "dev": "vite",
282
+ "build": "vite build",
283
+ "test": "vitest",
284
+ "test:coverage": "vitest --coverage",
285
+ "lint": "eslint src/**/*.js",
286
+ "format": "prettier --write src/**/*.js"
287
+ }
288
+ }
289
+ ```
290
+
291
+ **Quality Gates**:
292
+ - ESLint for code quality
293
+ - Prettier for consistent formatting
294
+ - Vitest coverage threshold (≥80%)
295
+ - Pre-commit hooks via husky (optional)
296
+
297
+ ---
298
+
299
+ ## 11. Cross-Dimensional Federation
300
+
301
+ ### Decision: URI/URL Scheme for Noospheric Holons
302
+ **Rationale**:
303
+ - Extends federation beyond geographic space into conceptual dimensions
304
+ - Enables external namespace integration (e.g., `nostr://topic/123`, `ap://community/abc`)
305
+ - Maintains architectural consistency with geographic holons
306
+
307
+ **Noospheric Holon Patterns**:
308
+ - Protocol-specific: `nostr://topic/{topicId}`, `ap://community/{communityId}`
309
+ - Custom schemes: `concept://{namespace}/{id}`, `idea://{domain}/{id}`
310
+ - URI validation follows RFC 3986 for consistency
311
+
312
+ **Federation Behavior**:
313
+ - Same federation mechanics as geographic holons (bidirectional, lens-specific)
314
+ - Cross-dimensional links: Geographic holon ↔ Noospheric holon federation
315
+ - Reference-based propagation (holograms) maintains single source of truth
316
+
317
+ ---
318
+
319
+ ## 12. Error Handling and Observability
320
+
321
+ ### Decision: Structured Logging with JSON Format
322
+ **Rationale**:
323
+ - Machine-parseable logs enable automated monitoring
324
+ - Configurable verbosity levels (ERROR, WARN, INFO, DEBUG)
325
+ - Metrics collection for operation counts and timing
326
+
327
+ **Logging Interface**:
328
+ ```javascript
329
+ logger.error({ event: 'validation_failed', lens: 'events', error: err.message });
330
+ logger.warn({ event: 'schema_cache_miss', lens: 'temperature' });
331
+ logger.info({ event: 'federation_established', from: h3_1, to: h3_2 });
332
+ logger.debug({ event: 'hologram_resolved', id: 'xyz', depth: 2 });
333
+ ```
334
+
335
+ **Metrics**:
336
+ - Operation counters (writes, reads, federations, subscriptions)
337
+ - Timing histograms (validation duration, hologram resolution time)
338
+ - Error rates by operation type
339
+
340
+ ---
341
+
342
+ ## Summary of Resolved Technical Decisions
343
+
344
+ | Area | Decision | Rationale |
345
+ |------|----------|-----------|
346
+ | **Language** | JavaScript ES2020+ | Cross-platform, modern features, broad ecosystem |
347
+ | **Runtime** | Node.js 18+ & modern browsers | LTS support, universal compatibility |
348
+ | **Geospatial** | h3-js | Official H3 implementation, proven reliability |
349
+ | **Storage** | GunDB + Radisk | P2P architecture, local-first, real-time sync |
350
+ | **Crypto** | @noble/curves (secp256k1) | Industry standard, lightweight, audited |
351
+ | **Validation** | Ajv (JSON Schema 2019) | Standard-compliant, fast, small footprint |
352
+ | **Testing** | Vitest | Fast, ESM-native, excellent DX |
353
+ | **Build** | Vite + Rollup | Multi-format output, tree-shaking, optimization |
354
+ | **Bundle** | <1MB minified+gzipped | Lazy loading, efficient dependencies |
355
+ | **Logging** | Structured JSON | Machine-parseable, multi-level verbosity |
356
+
357
+ ---
358
+
359
+ ## Next Steps
360
+
361
+ ✅ All technical context items resolved - no NEEDS CLARIFICATION remaining
362
+ ➡️ Proceed to Phase 1: Design & Contracts
package/docs/spec.md ADDED
@@ -0,0 +1,244 @@
1
+ # Feature Specification: HoloSphere - Holonic Geospatial Communication Infrastructure
2
+
3
+ **Feature Branch**: `001-holosphere-holonic-geospatial`
4
+ **Created**: 2025-10-06
5
+ **Status**: Draft
6
+ **Input**: User description: "HoloSphere Technical Specification & API Reference - A JavaScript library implementing holonic geospatial communication infrastructure by combining H3 hexagonal geospatial indexing with GunDB distributed peer-to-peer storage."
7
+
8
+ ## Execution Flow (main)
9
+ ```
10
+ 1. Parse user description from Input
11
+ → If empty: ERROR "No feature description provided"
12
+ 2. Extract key concepts from description
13
+ → Identified: holonic architecture, H3 geospatial indexing, GunDB P2P storage, lenses, federation
14
+ 3. For each unclear aspect:
15
+ → No major ambiguities - technical specification provided
16
+ 4. Fill User Scenarios & Testing section
17
+ → User flows: spatial data management, federation, real-time subscriptions
18
+ 5. Generate Functional Requirements
19
+ → Each requirement must be testable
20
+ 6. Identify Key Entities (if data involved)
21
+ 7. Run Review Checklist
22
+ → Spec focuses on user needs, avoids implementation details
23
+ 8. Return: SUCCESS (spec ready for planning)
24
+ ```
25
+
26
+ ---
27
+
28
+ ## ⚡ Quick Guidelines
29
+ - ✅ Focus on WHAT users need and WHY
30
+ - ❌ Avoid HOW to implement (no tech stack, APIs, code structure)
31
+ - 👥 Written for business stakeholders, not developers
32
+
33
+ ---
34
+
35
+ ## User Scenarios & Testing *(mandatory)*
36
+
37
+ ### Primary User Story
38
+ Developers need to build distributed applications where data is organized by location - both geographic (physical space) and noospheric (conceptual space). Data is stored in holons, categorized into different types (lenses), and can be shared between locations (federation). The system must support multi-scale geographic operations from global to hyper-local (building-level) precision, enable federation across dimensions (linking geographic locations with conceptual spaces), support real-time data synchronization, and work in offline/distributed environments without central servers. While geographic space is inherently federated through spatial hierarchy, the noosphere enables organization by ideas, concepts, and relationships beyond physical constraints.
39
+
40
+ ### Acceptance Scenarios
41
+
42
+ 1. **Given** a geographic coordinate (latitude/longitude) and desired precision level, **When** a user stores data at that location, **Then** the data is stored in the appropriate geographic cell and retrievable by location and data category
43
+
44
+ 2. **Given** data stored in a local geographic area, **When** that area federates with a larger region, **Then** data automatically propagates to the regional level while maintaining a single source of truth
45
+
46
+ 3. **Given** multiple applications using the same geographic coordinate system, **When** they subscribe to changes in a geographic area, **Then** they receive real-time updates when data changes in that location
47
+
48
+ 4. **Given** data with specific validation rules (schema), **When** invalid data is submitted, **Then** the system prevents storage in strict mode or logs warnings in permissive mode
49
+
50
+ 5. **Given** hierarchical geographic areas (city → state → country → global), **When** local data is created, **Then** references automatically propagate up the hierarchy enabling multi-scale queries
51
+
52
+ 6. **Given** social content published in a geographic area, **When** users interact across different protocols (Nostr, ActivityPub), **Then** content is accessible and verifiable across protocol boundaries
53
+
54
+ 7. **Given** data has been written to a holon, **When** the application crashes or browser tab closes before sync, **Then** all confirmed writes are recoverable from radisk persistence on restart with no data loss
55
+
56
+ 8. **Given** a user attempts to delete data created by another user, **When** the delete operation is called without a valid capability token with delete permission, **Then** the system rejects the operation and returns an authorization error
57
+
58
+ ### Edge Cases
59
+ - What happens when network connectivity is lost? (System must continue operating locally with radisk persistence and sync when reconnected)
60
+ - How does the system handle conflicting data in federated holons? (Last-write-wins with GunDB conflict resolution, no data loss)
61
+ - What happens when a hologram reference points to deleted data? (Returns null gracefully)
62
+ - How does the system prevent infinite loops in nested holograms? (Tracks visited references during resolution)
63
+ - What happens when schema validation changes after data is stored? (Existing data grandfathered, new data validated against current schema)
64
+ - What happens if a write operation fails before disk persistence? (Write is retried or error returned; success indicator only after confirmed disk write)
65
+ - What happens during browser tab closure or app crash? (All data persisted to radisk remains intact and recoverable on restart)
66
+ - What happens when someone tries to delete data they don't own? (Delete operation rejected with authorization error unless valid capability token with delete permission provided)
67
+ - What happens when a capability token expires during a delete operation? (Operation rejected; token must be valid at time of execution)
68
+
69
+ ## Requirements *(mandatory)*
70
+
71
+ ### Functional Requirements
72
+
73
+ **Spatial Data Management**
74
+ - **FR-001**: System MUST convert geographic coordinates (latitude/longitude) to hexagonal grid cells at 16 different resolution levels (global to ~1m²)
75
+ - **FR-002**: System MUST organize all data using geographic location as primary key (holon)
76
+ - **FR-003**: System MUST support hierarchical parent-child relationships between geographic cells automatically
77
+ - **FR-004**: System MUST enable querying all parent cells containing a given location (scalespace)
78
+
79
+ **Data Organization & Storage**
80
+ - **FR-005**: System MUST support categorical organization of data within each location (lenses)
81
+ - **FR-006**: System MUST store data in a structured path format: application/location/category/identifier (where location can be H3 cell ID or URI/URL for noospheric holons)
82
+ - **FR-007**: System MUST generate unique identifiers automatically if not provided
83
+ - **FR-008**: System MUST support optional metadata including timestamps and resolution tracking
84
+
85
+ **Schema & Validation**
86
+ - **FR-009**: System MUST support JSON Schema validation (2019 draft) for data categories
87
+ - **FR-010**: System MUST provide both strict validation mode (blocking) and permissive mode (logging only)
88
+ - **FR-011**: System MUST cache schemas with configurable time-to-live for performance
89
+ - **FR-012**: Users MUST be able to define, retrieve, and clear validation schemas per data category
90
+
91
+ **Reference System (Holograms)**
92
+ - **FR-013**: System MUST support lightweight references (holograms) instead of data duplication
93
+ - **FR-014**: System MUST automatically resolve references to actual data when retrieved
94
+ - **FR-015**: System MUST detect and prevent infinite loops in nested references
95
+ - **FR-016**: System MUST support both automatic and manual reference resolution
96
+
97
+ **Federation**
98
+ - **FR-017**: System MUST enable bidirectional data sharing between geographic locations
99
+ - **FR-018**: System MUST support selective federation by data category (lens-specific)
100
+ - **FR-019**: System MUST support both inbound (receive) and outbound (send) federation configuration
101
+ - **FR-020**: System MUST propagate data to federated locations automatically by default
102
+ - **FR-021**: System MUST use references (not copies) when propagating to federated locations by default
103
+ - **FR-022**: Users MUST be able to query combined local and federated data with automatic deduplication
104
+ - **FR-023**: System MUST support federation beyond geographic space into conceptual/noospheric dimensions
105
+ - **FR-024**: System MUST enable cross-dimensional linking where holons can federate across both spatial and non-spatial organizational schemes
106
+
107
+ **Hierarchical Aggregation**
108
+ - **FR-025**: System MUST support automatic propagation of data to parent geographic cells (upcast)
109
+ - **FR-026**: System MUST support aggregation operations (summarize, aggregate, concatenate) across hierarchy levels
110
+ - **FR-027**: System MUST limit hierarchical propagation to configurable maximum levels
111
+
112
+ **Real-time Subscriptions**
113
+ - **FR-028**: System MUST enable real-time subscriptions to changes in specific location/category combinations
114
+ - **FR-029**: System MUST invoke callbacks when subscribed data changes
115
+ - **FR-030**: Users MUST be able to unsubscribe from real-time updates
116
+ - **FR-031**: System MUST support federation-specific subscriptions with lens filtering and throttling
117
+
118
+ **Distributed Storage**
119
+ - **FR-032**: System MUST operate in peer-to-peer mode without requiring central servers
120
+ - **FR-033**: System MUST support local-first operation with automatic synchronization
121
+ - **FR-034**: System MUST persist data locally by default using GunDB with radisk storage
122
+ - **FR-035**: System MUST support configurable peer connections for distributed sync
123
+ - **FR-069**: System MUST use radisk storage adapter in both npm package and CDN bundle versions
124
+ - **FR-070**: System MUST ensure write operations are persisted to disk before returning success
125
+ - **FR-071**: System MUST prevent data loss through automatic conflict resolution and synchronization
126
+ - **FR-072**: System MUST maintain data integrity during network partitions and offline periods
127
+
128
+ **Access Control & Security**
129
+ - **FR-036**: System MUST support optional password-based access control per geographic location
130
+ - **FR-037**: System MUST support cryptographic signatures for content verification to prevent data tampering
131
+ - **FR-038**: System MUST issue and verify capability tokens for authorization
132
+ - **FR-039**: System MUST support stigmergic (indirect coordination) access control levels
133
+ - **FR-066**: System MUST enforce capability token expiration to prevent unauthorized access
134
+ - **FR-067**: System MUST prevent replay attacks on signed content and capability tokens
135
+ - **FR-068**: System MUST provide basic DoS protection through rate limiting and resource constraints
136
+ - **FR-074**: System MUST require valid capability token with delete permission to delete data created by others
137
+ - **FR-075**: System MUST allow data creators to delete their own data without additional authorization
138
+ - **FR-076**: System MUST verify data ownership or capability token before processing delete operations
139
+ - **FR-077**: System MUST reject delete operations that lack proper authorization with clear error messages
140
+
141
+ **Cross-Protocol Support**
142
+ - **FR-040**: System MUST unify social protocols (Nostr, ActivityPub) under common interface
143
+ - **FR-041**: System MUST validate protocol-specific content formats
144
+ - **FR-042**: System MUST verify cryptographic signatures for social content
145
+ - **FR-043**: Users MUST be able to filter social content by protocol and access level
146
+
147
+ **Global Data Operations**
148
+ - **FR-044**: System MUST support non-location-specific data storage (global tables)
149
+ - **FR-045**: System MUST provide consistent CRUD operations for both location-specific and global data
150
+
151
+ **Performance & Efficiency**
152
+ - **FR-046**: System MUST initialize cryptographic components lazily (on first use)
153
+ - **FR-047**: System MUST cache frequently accessed data with configurable expiration
154
+ - **FR-048**: System MUST support batch operations to reduce network overhead
155
+ - **FR-049**: System MUST provide browser bundle size < 1 MB minified+gzipped including all dependencies
156
+ - **FR-061**: System MUST NOT enforce hard limits on data volume per holon (bounded only by available storage and network capacity)
157
+
158
+ **Error Handling & Reliability**
159
+ - **FR-050**: System MUST return boolean success indicators for state-changing operations
160
+ - **FR-051**: System MUST provide detailed error messages for federation failures
161
+ - **FR-052**: System MUST handle connection failures with retry logic
162
+ - **FR-053**: System MUST gracefully degrade when optional features are unavailable
163
+
164
+ **Observability**
165
+ - **FR-062**: System MUST provide structured logging in JSON format
166
+ - **FR-063**: System MUST capture metrics for operation counts and timing
167
+ - **FR-064**: System MUST support configurable log verbosity levels
168
+ - **FR-065**: System MUST log all errors, warnings, and significant state transitions
169
+
170
+ **Multi-Platform Support**
171
+ - **FR-054**: System MUST operate in Node.js server environments with radisk persistence
172
+ - **FR-055**: System MUST operate in browser environments with radisk persistence
173
+ - **FR-056**: System MUST be distributable via CDN for direct browser usage with radisk included
174
+ - **FR-057**: System MUST support both CommonJS and ES Module imports
175
+ - **FR-073**: Both npm and CDN distributions MUST include GunDB radisk adapter for data persistence
176
+
177
+ **Testing & Quality**
178
+ - **FR-058**: Every feature MUST have dedicated unit tests covering all core functionality
179
+ - **FR-059**: System MUST maintain test coverage for all public API methods
180
+ - **FR-060**: Tests MUST be organized by feature module with clear test isolation
181
+
182
+ ### Key Entities
183
+
184
+ - **Holon**: Geographic location represented as H3 hexagonal cell OR conceptual location in noospheric space identified by URI/URL scheme (e.g., "nostr://topic/123", "ap://community/abc"); contains multiple lenses; supports hierarchical parent-child relationships (resolutions 0-15 for geographic); can be federated with other holons across both spatial and noospheric dimensions
185
+
186
+ - **Lens**: Data category within a holon (e.g., temperature, events, social content, ideas, concepts); has optional validation schema; has independent federation configuration; contains key-value data pairs; enables cross-dimensional organization
187
+
188
+ - **Data Object**: Individual data record within a lens; has required unique ID; has optional custom fields; has optional metadata (_meta with timestamp, resolution tracking); follows path structure: appname/holon/lens/key
189
+
190
+ - **Hologram**: Lightweight reference to data stored elsewhere; contains ID and soul path; automatically resolves to actual data; prevents data duplication; tracks visited references to prevent loops
191
+
192
+ - **Federation**: Bidirectional relationship between holons; has inbound lens configuration (what to receive); has outbound lens configuration (what to send); supports selective data sharing; uses holograms for propagation; enables cross-dimensional linking between geographic and noospheric holons
193
+
194
+ - **Schema**: JSON Schema (2019 draft) validation rules for a lens; cached with TTL; enforced in strict mode, logged in permissive mode; independently defined per lens
195
+
196
+ - **Subscription**: Real-time change notification for holon/lens combination; invokes callback on data changes; provides unsubscribe mechanism; supports throttling and filtering
197
+
198
+ - **Capability Token**: Cryptographic authorization token; grants specific permissions (read, write, delete, modify); has expiration timestamp; has designated recipient; uses Nostr signatures for verification; transferable between parties; required for delete operations on data created by others
199
+
200
+ - **Social Content**: Protocol-agnostic social data; supports Nostr and ActivityPub native formats; has cryptographic signature; has stigmergic access level; stored in holons with geographic context
201
+
202
+ ---
203
+
204
+ ## Clarifications
205
+
206
+ ### Session 2025-10-07
207
+ - Q: How should noospheric (conceptual) holons be identified and structured? → A: URI/URL scheme allowing external namespace integration (e.g., "nostr://topic/123", "ap://community/abc")
208
+ - Q: What are the performance targets for browser bundle size? → A: < 1 MB minified+gzipped (comprehensive, including all dependencies)
209
+ - Q: What are the expected data scale limits per holon? → A: No enforced limits (bounded only by available storage and network capacity)
210
+ - Q: What observability features must be provided for monitoring and debugging? → A: Standard: Structured logging (JSON), metrics (operation counts/timing), configurable verbosity
211
+ - Q: What security threats should the system defend against? → A: Standard: Unauthorized data access, data tampering, replay attacks, token expiration enforcement, basic DoS protection
212
+
213
+ ---
214
+
215
+ ## Review & Acceptance Checklist
216
+ *GATE: Automated checks run during main() execution*
217
+
218
+ ### Content Quality
219
+ - [x] No implementation details (languages, frameworks, APIs)
220
+ - [x] Focused on user value and business needs
221
+ - [x] Written for non-technical stakeholders
222
+ - [x] All mandatory sections completed
223
+
224
+ ### Requirement Completeness
225
+ - [x] No [NEEDS CLARIFICATION] markers remain
226
+ - [x] Requirements are testable and unambiguous
227
+ - [x] Success criteria are measurable
228
+ - [x] Scope is clearly bounded
229
+ - [x] Dependencies and assumptions identified
230
+
231
+ ---
232
+
233
+ ## Execution Status
234
+ *Updated by main() during processing*
235
+
236
+ - [x] User description parsed
237
+ - [x] Key concepts extracted
238
+ - [x] Ambiguities marked
239
+ - [x] User scenarios defined
240
+ - [x] Requirements generated
241
+ - [x] Entities identified
242
+ - [x] Review checklist passed
243
+
244
+ ---