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.
- package/LICENSE +162 -38
- package/dist/cjs/holosphere.cjs +2 -0
- package/dist/cjs/holosphere.cjs.map +1 -0
- package/dist/esm/holosphere.js +56 -0
- package/dist/esm/holosphere.js.map +1 -0
- package/dist/index-CDfIuXew.js +15974 -0
- package/dist/index-CDfIuXew.js.map +1 -0
- package/dist/index-ifOgtDvd.cjs +3 -0
- package/dist/index-ifOgtDvd.cjs.map +1 -0
- package/dist/indexeddb-storage-CMW4qRQS.js +96 -0
- package/dist/indexeddb-storage-CMW4qRQS.js.map +1 -0
- package/dist/indexeddb-storage-DLZOgetM.cjs +2 -0
- package/dist/indexeddb-storage-DLZOgetM.cjs.map +1 -0
- package/dist/memory-storage-DQzcAZlf.js +47 -0
- package/dist/memory-storage-DQzcAZlf.js.map +1 -0
- package/dist/memory-storage-DmePEP2q.cjs +2 -0
- package/dist/memory-storage-DmePEP2q.cjs.map +1 -0
- package/dist/secp256k1-CP0ZkpAx.cjs +13 -0
- package/dist/secp256k1-CP0ZkpAx.cjs.map +1 -0
- package/dist/secp256k1-vOXp40Fx.js +2281 -0
- package/dist/secp256k1-vOXp40Fx.js.map +1 -0
- package/docs/FOSDEM_PROPOSAL.md +388 -0
- package/docs/LOCALFIRST.md +266 -0
- package/docs/contracts/api-interface.md +793 -0
- package/docs/data-model.md +476 -0
- package/docs/gun-async-usage.md +338 -0
- package/docs/plan.md +349 -0
- package/docs/quickstart.md +674 -0
- package/docs/research.md +362 -0
- package/docs/spec.md +244 -0
- package/docs/storage-backends.md +326 -0
- package/docs/tasks.md +947 -0
- package/package.json +1 -1
- package/tests/unit/ai/aggregation.test.js +0 -295
- package/tests/unit/ai/breakdown.test.js +0 -446
- package/tests/unit/ai/classifier.test.js +0 -294
- package/tests/unit/ai/council.test.js +0 -262
- package/tests/unit/ai/embeddings.test.js +0 -384
- package/tests/unit/ai/federation-ai.test.js +0 -344
- package/tests/unit/ai/h3-ai.test.js +0 -458
- package/tests/unit/ai/index.test.js +0 -304
- package/tests/unit/ai/json-ops.test.js +0 -307
- package/tests/unit/ai/llm-service.test.js +0 -390
- package/tests/unit/ai/nl-query.test.js +0 -383
- package/tests/unit/ai/relationships.test.js +0 -311
- package/tests/unit/ai/schema-extractor.test.js +0 -384
- package/tests/unit/ai/spatial.test.js +0 -279
- package/tests/unit/ai/tts.test.js +0 -279
- package/tests/unit/content.test.js +0 -332
- package/tests/unit/contract/core.test.js +0 -88
- package/tests/unit/contract/crypto.test.js +0 -198
- package/tests/unit/contract/data.test.js +0 -223
- package/tests/unit/contract/federation.test.js +0 -181
- package/tests/unit/contract/hierarchical.test.js +0 -113
- package/tests/unit/contract/schema.test.js +0 -114
- package/tests/unit/contract/social.test.js +0 -217
- package/tests/unit/contract/spatial.test.js +0 -110
- package/tests/unit/contract/subscriptions.test.js +0 -128
- package/tests/unit/contract/utils.test.js +0 -159
- package/tests/unit/core.test.js +0 -152
- package/tests/unit/crypto.test.js +0 -328
- package/tests/unit/federation.test.js +0 -234
- package/tests/unit/gun-async.test.js +0 -252
- package/tests/unit/hierarchical.test.js +0 -399
- package/tests/unit/integration/scenario-01-geographic-storage.test.js +0 -74
- package/tests/unit/integration/scenario-02-federation.test.js +0 -76
- package/tests/unit/integration/scenario-03-subscriptions.test.js +0 -102
- package/tests/unit/integration/scenario-04-validation.test.js +0 -129
- package/tests/unit/integration/scenario-05-hierarchy.test.js +0 -125
- package/tests/unit/integration/scenario-06-social.test.js +0 -135
- package/tests/unit/integration/scenario-07-persistence.test.js +0 -130
- package/tests/unit/integration/scenario-08-authorization.test.js +0 -161
- package/tests/unit/integration/scenario-09-cross-dimensional.test.js +0 -139
- package/tests/unit/integration/scenario-10-cross-holosphere-capabilities.test.js +0 -357
- package/tests/unit/integration/scenario-11-cross-holosphere-federation.test.js +0 -410
- package/tests/unit/integration/scenario-12-capability-federated-read.test.js +0 -719
- package/tests/unit/performance/benchmark.test.js +0 -85
- package/tests/unit/schema.test.js +0 -213
- package/tests/unit/spatial.test.js +0 -158
- package/tests/unit/storage.test.js +0 -195
- package/tests/unit/subscriptions.test.js +0 -328
- package/tests/unit/test-data-permanence-debug.js +0 -197
- package/tests/unit/test-data-permanence.js +0 -340
- package/tests/unit/test-key-persistence-fixed.js +0 -148
- package/tests/unit/test-key-persistence.js +0 -172
- package/tests/unit/test-relay-permanence.js +0 -376
- package/tests/unit/test-second-node.js +0 -95
- package/tests/unit/test-simple-write.js +0 -89
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# Gun Async Utilities Usage Guide
|
|
2
|
+
|
|
3
|
+
This document explains how to use the async/await patterns with GunDB in HoloSphere.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
GunDB is callback-based by default, but HoloSphere provides Promise-based wrappers and async utilities to make it easier to work with modern JavaScript patterns.
|
|
8
|
+
|
|
9
|
+
## Basic Operations
|
|
10
|
+
|
|
11
|
+
### gunPromise - Get data with async/await
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
import { gunAsync } from 'holosphere';
|
|
15
|
+
import Gun from 'gun';
|
|
16
|
+
|
|
17
|
+
const gun = Gun();
|
|
18
|
+
|
|
19
|
+
// Get data using async/await
|
|
20
|
+
const data = await gunAsync.gunPromise(gun.get('mypath'));
|
|
21
|
+
console.log(data);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### gunPut - Write data with async/await
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
// Write data and wait for acknowledgement
|
|
28
|
+
const ack = await gunAsync.gunPut(gun.get('mypath'), {
|
|
29
|
+
id: 'item1',
|
|
30
|
+
value: 'Hello World'
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (ack.err) {
|
|
34
|
+
console.error('Write failed:', ack.err);
|
|
35
|
+
} else {
|
|
36
|
+
console.log('Write successful');
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Collection Operations
|
|
41
|
+
|
|
42
|
+
### gunMap - Get all items from a map
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
// Get all items under a path
|
|
46
|
+
const items = await gunAsync.gunMap(gun.get('users'), 500);
|
|
47
|
+
|
|
48
|
+
Object.entries(items).forEach(([key, value]) => {
|
|
49
|
+
console.log(`${key}:`, value);
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### gunMapIterator - Iterate over map items
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// Use async iteration
|
|
57
|
+
for await (const [key, value] of gunAsync.gunMapIterator(gun.get('users'))) {
|
|
58
|
+
console.log(`User ${key}:`, value);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### gunCollect - Collect streaming data
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
// Collect all data that arrives in 1 second
|
|
66
|
+
const results = await gunAsync.gunCollect(gun.get('events'), 1000);
|
|
67
|
+
|
|
68
|
+
results.forEach(({ key, data }) => {
|
|
69
|
+
console.log(`Event ${key}:`, data);
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Advanced Patterns
|
|
74
|
+
|
|
75
|
+
### gunWaitFor - Wait for a condition
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
// Wait for data to meet a specific condition
|
|
79
|
+
try {
|
|
80
|
+
const result = await gunAsync.gunWaitFor(
|
|
81
|
+
gun.get('status'),
|
|
82
|
+
(data) => data && data.ready === true,
|
|
83
|
+
5000 // 5 second timeout
|
|
84
|
+
);
|
|
85
|
+
console.log('Status is ready:', result);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('Timeout waiting for ready status');
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### gunBatchGet - Read multiple paths
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
// Read multiple paths in parallel
|
|
95
|
+
const results = await gunAsync.gunBatchGet(gun, [
|
|
96
|
+
'users/alice',
|
|
97
|
+
'users/bob',
|
|
98
|
+
'users/charlie'
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
console.log('Alice:', results['users/alice']);
|
|
102
|
+
console.log('Bob:', results['users/bob']);
|
|
103
|
+
console.log('Charlie:', results['users/charlie']);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### gunBatchPut - Write multiple paths
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
// Write to multiple paths in parallel
|
|
110
|
+
const results = await gunAsync.gunBatchPut(gun, {
|
|
111
|
+
'users/alice': { id: 'alice', name: 'Alice' },
|
|
112
|
+
'users/bob': { id: 'bob', name: 'Bob' },
|
|
113
|
+
'users/charlie': { id: 'charlie', name: 'Charlie' }
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
console.log('All writes completed:', results);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### gunRetry - Retry failed operations
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
// Retry an operation with exponential backoff
|
|
123
|
+
const result = await gunAsync.gunRetry(
|
|
124
|
+
async () => {
|
|
125
|
+
const data = await gunAsync.gunPromise(gun.get('flaky-endpoint'));
|
|
126
|
+
if (!data) throw new Error('No data');
|
|
127
|
+
return data;
|
|
128
|
+
},
|
|
129
|
+
3, // max retries
|
|
130
|
+
100 // base delay in ms
|
|
131
|
+
);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### gunStream - Create async iterable stream
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
// Create a real-time stream
|
|
138
|
+
const stream = gunAsync.gunStream(gun.get('live-feed'));
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
for await (const { key, data } of stream) {
|
|
142
|
+
console.log('New data:', key, data);
|
|
143
|
+
|
|
144
|
+
// Stop after 10 items
|
|
145
|
+
if (someCondition) {
|
|
146
|
+
stream.stop();
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error('Stream error:', error);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Integration with HoloSphere
|
|
156
|
+
|
|
157
|
+
### Using with HoloSphere instance
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
import HoloSphere, { gunAsync } from 'holosphere';
|
|
161
|
+
|
|
162
|
+
const holosphere = new HoloSphere({
|
|
163
|
+
appName: 'myapp',
|
|
164
|
+
peers: ['https://relay.example.com/gun']
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Direct Gun access with async utilities
|
|
168
|
+
const userData = await gunAsync.gunPromise(
|
|
169
|
+
holosphere.gun.get('mypath')
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
// Or use HoloSphere's built-in async methods
|
|
173
|
+
const data = await holosphere.read('h3index', 'messages');
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Combining with subscriptions
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
// Set up a subscription
|
|
180
|
+
const subscription = holosphere.subscribe(
|
|
181
|
+
'h3index',
|
|
182
|
+
'events',
|
|
183
|
+
(data, key) => {
|
|
184
|
+
console.log('Event update:', key, data);
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// Also collect historical data
|
|
189
|
+
const historical = await gunAsync.gunCollect(
|
|
190
|
+
holosphere.gun.get(`${holosphere.config.appName}/h3index/events`),
|
|
191
|
+
2000
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
console.log('Historical events:', historical);
|
|
195
|
+
|
|
196
|
+
// Later, unsubscribe
|
|
197
|
+
subscription.unsubscribe();
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Best Practices
|
|
201
|
+
|
|
202
|
+
### 1. Set appropriate timeouts
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
// Short timeout for local operations
|
|
206
|
+
const localData = await gunAsync.gunPromise(gun.get('local'), 500);
|
|
207
|
+
|
|
208
|
+
// Longer timeout for network operations
|
|
209
|
+
const remoteData = await gunAsync.gunPromise(gun.get('remote'), 3000);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### 2. Handle errors properly
|
|
213
|
+
|
|
214
|
+
```javascript
|
|
215
|
+
try {
|
|
216
|
+
const result = await gunAsync.gunPut(gun.get('path'), data);
|
|
217
|
+
if (result.timeout) {
|
|
218
|
+
console.warn('Write timed out (may still succeed)');
|
|
219
|
+
}
|
|
220
|
+
} catch (error) {
|
|
221
|
+
console.error('Write definitely failed:', error);
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 3. Use batch operations for efficiency
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
// DON'T: Sequential reads
|
|
229
|
+
const user1 = await gunAsync.gunPromise(gun.get('users/1'));
|
|
230
|
+
const user2 = await gunAsync.gunPromise(gun.get('users/2'));
|
|
231
|
+
const user3 = await gunAsync.gunPromise(gun.get('users/3'));
|
|
232
|
+
|
|
233
|
+
// DO: Parallel batch read
|
|
234
|
+
const users = await gunAsync.gunBatchGet(gun, [
|
|
235
|
+
'users/1',
|
|
236
|
+
'users/2',
|
|
237
|
+
'users/3'
|
|
238
|
+
]);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### 4. Clean up streams
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
const stream = gunAsync.gunStream(gun.get('feed'));
|
|
245
|
+
|
|
246
|
+
// Always stop streams when done
|
|
247
|
+
try {
|
|
248
|
+
for await (const item of stream) {
|
|
249
|
+
// Process item
|
|
250
|
+
}
|
|
251
|
+
} finally {
|
|
252
|
+
stream.stop();
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## API Reference
|
|
257
|
+
|
|
258
|
+
### gunPromise(gunChain, timeout)
|
|
259
|
+
- **gunChain**: Gun chain reference
|
|
260
|
+
- **timeout**: Timeout in ms (default: 1000)
|
|
261
|
+
- **Returns**: Promise<any>
|
|
262
|
+
|
|
263
|
+
### gunPut(gunChain, data, timeout)
|
|
264
|
+
- **gunChain**: Gun chain reference
|
|
265
|
+
- **data**: Data to write
|
|
266
|
+
- **timeout**: Timeout in ms (default: 1000)
|
|
267
|
+
- **Returns**: Promise<Object>
|
|
268
|
+
|
|
269
|
+
### gunMap(gunChain, timeout)
|
|
270
|
+
- **gunChain**: Gun chain reference
|
|
271
|
+
- **timeout**: Collection duration in ms (default: 300)
|
|
272
|
+
- **Returns**: Promise<Object>
|
|
273
|
+
|
|
274
|
+
### gunMapIterator(gunChain)
|
|
275
|
+
- **gunChain**: Gun chain reference
|
|
276
|
+
- **Returns**: AsyncGenerator<[key, value]>
|
|
277
|
+
|
|
278
|
+
### gunCollect(gunChain, duration)
|
|
279
|
+
- **gunChain**: Gun chain reference
|
|
280
|
+
- **duration**: Collection duration in ms (default: 500)
|
|
281
|
+
- **Returns**: Promise<Array<{key, data}>>
|
|
282
|
+
|
|
283
|
+
### gunWaitFor(gunChain, predicate, timeout)
|
|
284
|
+
- **gunChain**: Gun chain reference
|
|
285
|
+
- **predicate**: Condition function (data) => boolean
|
|
286
|
+
- **timeout**: Timeout in ms (default: 5000)
|
|
287
|
+
- **Returns**: Promise<any>
|
|
288
|
+
|
|
289
|
+
### gunBatchGet(gun, paths)
|
|
290
|
+
- **gun**: Gun instance
|
|
291
|
+
- **paths**: Array of path strings
|
|
292
|
+
- **Returns**: Promise<Object>
|
|
293
|
+
|
|
294
|
+
### gunBatchPut(gun, pathDataMap)
|
|
295
|
+
- **gun**: Gun instance
|
|
296
|
+
- **pathDataMap**: Object mapping paths to data
|
|
297
|
+
- **Returns**: Promise<Object>
|
|
298
|
+
|
|
299
|
+
### gunRetry(operation, maxRetries, baseDelay)
|
|
300
|
+
- **operation**: Async function to retry
|
|
301
|
+
- **maxRetries**: Max retry attempts (default: 3)
|
|
302
|
+
- **baseDelay**: Base delay in ms (default: 100)
|
|
303
|
+
- **Returns**: Promise<any>
|
|
304
|
+
|
|
305
|
+
### gunStream(gunChain)
|
|
306
|
+
- **gunChain**: Gun chain reference
|
|
307
|
+
- **Returns**: Object with async iterator and stop() method
|
|
308
|
+
|
|
309
|
+
## Troubleshooting
|
|
310
|
+
|
|
311
|
+
### Timeouts
|
|
312
|
+
|
|
313
|
+
If operations timeout frequently:
|
|
314
|
+
- Increase timeout values
|
|
315
|
+
- Check network connectivity
|
|
316
|
+
- Verify Gun peers are reachable
|
|
317
|
+
- Consider using retry utilities
|
|
318
|
+
|
|
319
|
+
### Memory issues with streams
|
|
320
|
+
|
|
321
|
+
Always call `stream.stop()` when done:
|
|
322
|
+
```javascript
|
|
323
|
+
const stream = gunAsync.gunStream(gun.get('data'));
|
|
324
|
+
// ... use stream
|
|
325
|
+
stream.stop(); // Important!
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Batch operations not completing
|
|
329
|
+
|
|
330
|
+
Ensure all paths exist or handle null values:
|
|
331
|
+
```javascript
|
|
332
|
+
const results = await gunAsync.gunBatchGet(gun, paths);
|
|
333
|
+
paths.forEach(path => {
|
|
334
|
+
if (!results[path]) {
|
|
335
|
+
console.warn(`No data at ${path}`);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
```
|
package/docs/plan.md
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
|
|
2
|
+
# Implementation Plan: HoloSphere - Holonic Geospatial Communication Infrastructure
|
|
3
|
+
|
|
4
|
+
**Branch**: `001-holosphere-holonic-geospatial` | **Date**: 2025-10-07 | **Spec**: [spec.md](./spec.md)
|
|
5
|
+
**Input**: Feature specification from `/Users/roberto/Projects/Liminal/holosphere2/specs/001-holosphere-holonic-geospatial/spec.md`
|
|
6
|
+
|
|
7
|
+
## Execution Flow (/plan command scope)
|
|
8
|
+
```
|
|
9
|
+
1. Load feature spec from Input path
|
|
10
|
+
→ If not found: ERROR "No feature spec at {path}"
|
|
11
|
+
2. Fill Technical Context (scan for NEEDS CLARIFICATION)
|
|
12
|
+
→ Detect Project Type from file system structure or context (web=frontend+backend, mobile=app+api)
|
|
13
|
+
→ Set Structure Decision based on project type
|
|
14
|
+
3. Fill the Constitution Check section based on the content of the constitution document.
|
|
15
|
+
4. Evaluate Constitution Check section below
|
|
16
|
+
→ If violations exist: Document in Complexity Tracking
|
|
17
|
+
→ If no justification possible: ERROR "Simplify approach first"
|
|
18
|
+
→ Update Progress Tracking: Initial Constitution Check
|
|
19
|
+
5. Execute Phase 0 → research.md
|
|
20
|
+
→ If NEEDS CLARIFICATION remain: ERROR "Resolve unknowns"
|
|
21
|
+
6. Execute Phase 1 → contracts, data-model.md, quickstart.md, agent-specific template file (e.g., `CLAUDE.md` for Claude Code, `.github/copilot-instructions.md` for GitHub Copilot, `GEMINI.md` for Gemini CLI, `QWEN.md` for Qwen Code, or `AGENTS.md` for all other agents).
|
|
22
|
+
7. Re-evaluate Constitution Check section
|
|
23
|
+
→ If new violations: Refactor design, return to Phase 1
|
|
24
|
+
→ Update Progress Tracking: Post-Design Constitution Check
|
|
25
|
+
8. Plan Phase 2 → Describe task generation approach (DO NOT create tasks.md)
|
|
26
|
+
9. STOP - Ready for /tasks command
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**IMPORTANT**: The /plan command STOPS at step 7. Phases 2-4 are executed by other commands:
|
|
30
|
+
- Phase 2: /tasks command creates tasks.md
|
|
31
|
+
- Phase 3-4: Implementation execution (manual or via tools)
|
|
32
|
+
|
|
33
|
+
## Summary
|
|
34
|
+
HoloSphere is a JavaScript library implementing holonic geospatial communication infrastructure by combining H3 hexagonal geospatial indexing with GunDB distributed peer-to-peer storage. It enables developers to build distributed applications where data is organized by both geographic location (physical space) and noospheric location (conceptual space), stored in holons categorized by lenses, with support for federation, real-time synchronization, and offline operation. The system operates at multiple scales from global (H3 resolution 0) to hyper-local (~1m² at resolution 15) and supports cross-dimensional linking between spatial and conceptual organization schemes.
|
|
35
|
+
|
|
36
|
+
## Technical Context
|
|
37
|
+
**Language/Version**: JavaScript (ES2020+) with both Node.js 18+ and modern browsers (ES6 modules)
|
|
38
|
+
**Primary Dependencies**: GunDB (distributed storage with radisk adapter), h3-js (hexagonal geospatial indexing), @noble/curves (secp256k1 cryptography), ajv (JSON Schema validation)
|
|
39
|
+
**Storage**: GunDB with radisk local persistence adapter (IndexedDB in browser, filesystem in Node.js)
|
|
40
|
+
**Testing**: Vitest (unit tests covering all core functionality per constitutional requirement)
|
|
41
|
+
**Target Platform**: Cross-platform - Node.js 18+ and modern browsers (Chrome/Firefox/Safari), distributed via npm and CDN
|
|
42
|
+
**Project Type**: Single library project (npm package with dual ESM/CommonJS exports)
|
|
43
|
+
**Performance Goals**: <1MB bundle size (minified+gzipped), lazy crypto initialization, 1-hour schema cache TTL, efficient multi-scale queries
|
|
44
|
+
**Constraints**: Offline-first capability, P2P operation without central servers, local-first with radisk persistence, tree-shakeable ESM exports
|
|
45
|
+
**Scale/Scope**: Support 16 H3 resolution levels (global to ~1m²), arbitrary holon/lens combinations, federated cross-dimensional data sharing
|
|
46
|
+
|
|
47
|
+
## Constitution Check
|
|
48
|
+
*GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*
|
|
49
|
+
|
|
50
|
+
**Alignment with Constitutional Principles**:
|
|
51
|
+
|
|
52
|
+
✅ **I. Holonic Architecture**: Design supports autonomous holons with spatial hierarchy (H3 resolutions 0-15) and data independence per holon/lens combination.
|
|
53
|
+
|
|
54
|
+
✅ **II. Spatial-First Design**: H3 hexagonal indexing is the universal spatial reference system; all geographic data organized by H3 cell IDs.
|
|
55
|
+
|
|
56
|
+
✅ **III. Decentralization & Federation**: GunDB P2P architecture with no central servers; bidirectional federation supports both geographic and noospheric dimensions.
|
|
57
|
+
|
|
58
|
+
✅ **IV. Single Source of Truth**: Holograms (references) prevent data duplication; original data lives in one location with automatic resolution.
|
|
59
|
+
|
|
60
|
+
✅ **V. Lens-Based Data Organization**: Data separated into categorical lenses with independent schemas, validation rules, and federation configuration.
|
|
61
|
+
|
|
62
|
+
✅ **VI. Real-time Reactive Systems**: Built-in GunDB subscriptions for live data updates; event-driven architecture with callback mechanisms.
|
|
63
|
+
|
|
64
|
+
✅ **VII. Cryptographic Security**: secp256k1 (Noble curves) for signatures; password-based holon access control; verifiable social content.
|
|
65
|
+
|
|
66
|
+
✅ **VIII. Schema Flexibility**: Optional JSON Schema 2019 validation; strict/permissive modes; 1-hour cache TTL for performance.
|
|
67
|
+
|
|
68
|
+
✅ **IX. Cross-Protocol Interoperability**: Unified interface for Nostr and ActivityPub; capability-based access control; stigmergic coordination.
|
|
69
|
+
|
|
70
|
+
✅ **X. Hierarchical Aggregation**: Automatic upcast propagation through H3 parent-child relationships; multi-scale query support.
|
|
71
|
+
|
|
72
|
+
✅ **XI. Developer Experience**: Consistent API across operations; Node.js/browser/CDN support; mandatory unit tests per feature.
|
|
73
|
+
|
|
74
|
+
✅ **XII. Performance & Persistence**: Radisk storage by default; lazy crypto initialization; tree-shakeable ESM; <1MB bundle target.
|
|
75
|
+
|
|
76
|
+
**Design Constraints Compliance**:
|
|
77
|
+
- ✅ H3 format validation (hexagons start with '8', ≥15 chars)
|
|
78
|
+
- ✅ Path structure: `appname/holon/lens/key`
|
|
79
|
+
- ✅ Optional `_meta` field convention
|
|
80
|
+
- ✅ Automatic ID generation if not provided
|
|
81
|
+
- ✅ Non-blocking validation by default (strict mode optional)
|
|
82
|
+
|
|
83
|
+
**Design Patterns Compliance**:
|
|
84
|
+
- ✅ Modular delegation (separate modules: schema.js, content.js, federation.js, etc.)
|
|
85
|
+
- ✅ Async-first (all I/O operations return Promises)
|
|
86
|
+
- ✅ Options objects for configuration with sensible defaults
|
|
87
|
+
- ✅ Unsubscribe pattern (subscriptions return objects with `unsubscribe()` method)
|
|
88
|
+
- ✅ Capability tokens for authorization
|
|
89
|
+
|
|
90
|
+
**Initial Assessment**: **PASS** - Design fully aligns with all constitutional principles and constraints.
|
|
91
|
+
|
|
92
|
+
## Project Structure
|
|
93
|
+
|
|
94
|
+
### Documentation (this feature)
|
|
95
|
+
```
|
|
96
|
+
specs/[###-feature]/
|
|
97
|
+
├── plan.md # This file (/plan command output)
|
|
98
|
+
├── research.md # Phase 0 output (/plan command)
|
|
99
|
+
├── data-model.md # Phase 1 output (/plan command)
|
|
100
|
+
├── quickstart.md # Phase 1 output (/plan command)
|
|
101
|
+
├── contracts/ # Phase 1 output (/plan command)
|
|
102
|
+
└── tasks.md # Phase 2 output (/tasks command - NOT created by /plan)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Source Code (repository root)
|
|
106
|
+
```
|
|
107
|
+
src/
|
|
108
|
+
├── core/ # Core HoloSphere class and initialization
|
|
109
|
+
├── spatial/ # H3 geospatial operations and hierarchy
|
|
110
|
+
├── storage/ # GunDB integration and radisk adapter
|
|
111
|
+
├── schema/ # JSON Schema validation and caching
|
|
112
|
+
├── federation/ # Federation logic and hologram resolution
|
|
113
|
+
├── content/ # Social protocol integration (Nostr, ActivityPub)
|
|
114
|
+
├── crypto/ # Cryptographic operations (secp256k1, signatures)
|
|
115
|
+
├── subscriptions/ # Real-time subscription management
|
|
116
|
+
├── utils/ # Shared utilities and helpers
|
|
117
|
+
└── index.js # Public API exports
|
|
118
|
+
|
|
119
|
+
tests/
|
|
120
|
+
├── unit/ # Unit tests per feature module
|
|
121
|
+
│ ├── core.test.js
|
|
122
|
+
│ ├── spatial.test.js
|
|
123
|
+
│ ├── storage.test.js
|
|
124
|
+
│ ├── schema.test.js
|
|
125
|
+
│ ├── federation.test.js
|
|
126
|
+
│ ├── content.test.js
|
|
127
|
+
│ ├── crypto.test.js
|
|
128
|
+
│ └── subscriptions.test.js
|
|
129
|
+
├── integration/ # Cross-module integration tests
|
|
130
|
+
└── contract/ # API contract tests (Phase 1 generated)
|
|
131
|
+
|
|
132
|
+
dist/ # Build outputs (ESM/CommonJS/CDN)
|
|
133
|
+
├── esm/
|
|
134
|
+
├── cjs/
|
|
135
|
+
└── cdn/
|
|
136
|
+
|
|
137
|
+
package.json # npm package configuration
|
|
138
|
+
vitest.config.js # Test configuration
|
|
139
|
+
tsconfig.json # TypeScript definitions (optional)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Structure Decision**: Single library project structure (Option 1). HoloSphere is a standalone JavaScript library distributed as an npm package with multiple module export formats. The modular architecture follows constitutional delegation principles with each module having a single clear responsibility. Tests are organized by type (unit/integration/contract) with mandatory unit test coverage per feature module.
|
|
143
|
+
|
|
144
|
+
## Phase 0: Outline & Research
|
|
145
|
+
1. **Extract unknowns from Technical Context** above:
|
|
146
|
+
- For each NEEDS CLARIFICATION → research task
|
|
147
|
+
- For each dependency → best practices task
|
|
148
|
+
- For each integration → patterns task
|
|
149
|
+
|
|
150
|
+
2. **Generate and dispatch research agents**:
|
|
151
|
+
```
|
|
152
|
+
For each unknown in Technical Context:
|
|
153
|
+
Task: "Research {unknown} for {feature context}"
|
|
154
|
+
For each technology choice:
|
|
155
|
+
Task: "Find best practices for {tech} in {domain}"
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
3. **Consolidate findings** in `research.md` using format:
|
|
159
|
+
- Decision: [what was chosen]
|
|
160
|
+
- Rationale: [why chosen]
|
|
161
|
+
- Alternatives considered: [what else evaluated]
|
|
162
|
+
|
|
163
|
+
**Output**: research.md with all NEEDS CLARIFICATION resolved
|
|
164
|
+
|
|
165
|
+
## Phase 1: Design & Contracts
|
|
166
|
+
*Prerequisites: research.md complete*
|
|
167
|
+
|
|
168
|
+
1. **Extract entities from feature spec** → `data-model.md`:
|
|
169
|
+
- Entity name, fields, relationships
|
|
170
|
+
- Validation rules from requirements
|
|
171
|
+
- State transitions if applicable
|
|
172
|
+
|
|
173
|
+
2. **Generate API contracts** from functional requirements:
|
|
174
|
+
- For each user action → endpoint
|
|
175
|
+
- Use standard REST/GraphQL patterns
|
|
176
|
+
- Output OpenAPI/GraphQL schema to `/contracts/`
|
|
177
|
+
|
|
178
|
+
3. **Generate contract tests** from contracts:
|
|
179
|
+
- One test file per endpoint
|
|
180
|
+
- Assert request/response schemas
|
|
181
|
+
- Tests must fail (no implementation yet)
|
|
182
|
+
|
|
183
|
+
4. **Extract test scenarios** from user stories:
|
|
184
|
+
- Each story → integration test scenario
|
|
185
|
+
- Quickstart test = story validation steps
|
|
186
|
+
|
|
187
|
+
5. **Update agent file incrementally** (O(1) operation):
|
|
188
|
+
- Run `.specify/scripts/bash/update-agent-context.sh claude`
|
|
189
|
+
**IMPORTANT**: Execute it exactly as specified above. Do not add or remove any arguments.
|
|
190
|
+
- If exists: Add only NEW tech from current plan
|
|
191
|
+
- Preserve manual additions between markers
|
|
192
|
+
- Update recent changes (keep last 3)
|
|
193
|
+
- Keep under 150 lines for token efficiency
|
|
194
|
+
- Output to repository root
|
|
195
|
+
|
|
196
|
+
**Output**: data-model.md, /contracts/*, failing tests, quickstart.md, agent-specific file
|
|
197
|
+
|
|
198
|
+
## Phase 2: Task Planning Approach
|
|
199
|
+
*This section describes what the /tasks command will do - DO NOT execute during /plan*
|
|
200
|
+
|
|
201
|
+
**Task Generation Strategy**:
|
|
202
|
+
|
|
203
|
+
1. **Foundation Tasks** (TDD: Tests first):
|
|
204
|
+
- Project setup (package.json, build config, test config)
|
|
205
|
+
- Core infrastructure (Gun initialization, radisk setup)
|
|
206
|
+
- Unit test files for each module (failing tests initially)
|
|
207
|
+
|
|
208
|
+
2. **Module Implementation Tasks** (from data-model.md):
|
|
209
|
+
- **Core Module** (`src/core/`): HoloSphere class, initialization, configuration
|
|
210
|
+
- **Spatial Module** (`src/spatial/`): H3 operations, holon conversion, hierarchy navigation
|
|
211
|
+
- **Storage Module** (`src/storage/`): GunDB wrapper, radisk integration, path management
|
|
212
|
+
- **Schema Module** (`src/schema/`): Ajv integration, validation, caching
|
|
213
|
+
- **Federation Module** (`src/federation/`): Federation setup, hologram resolution, propagation
|
|
214
|
+
- **Content Module** (`src/content/`): Social protocol adapters (Nostr, ActivityPub)
|
|
215
|
+
- **Crypto Module** (`src/crypto/`): secp256k1 operations, signing, verification, capability tokens
|
|
216
|
+
- **Subscriptions Module** (`src/subscriptions/`): Real-time subscription management
|
|
217
|
+
|
|
218
|
+
3. **API Contract Tasks** (from contracts/api-interface.md):
|
|
219
|
+
- Each API method → contract test (validates signature, params, return types)
|
|
220
|
+
- Contract tests must fail initially (no implementation yet)
|
|
221
|
+
- Group by functional area (spatial, data, schema, federation, etc.)
|
|
222
|
+
|
|
223
|
+
4. **Integration Tasks** (from quickstart.md):
|
|
224
|
+
- Each quickstart scenario → integration test
|
|
225
|
+
- Scenario 1: Geographic storage/retrieval
|
|
226
|
+
- Scenario 2: Hierarchical federation
|
|
227
|
+
- Scenario 3: Real-time subscriptions
|
|
228
|
+
- Scenario 4: Schema validation
|
|
229
|
+
- Scenario 5: Multi-scale queries
|
|
230
|
+
- Scenario 6: Cross-protocol social
|
|
231
|
+
- Scenario 7: Offline persistence
|
|
232
|
+
- Scenario 8: Authorization
|
|
233
|
+
- Scenario 9: Cross-dimensional federation
|
|
234
|
+
|
|
235
|
+
5. **Build & Distribution Tasks**:
|
|
236
|
+
- Vite configuration for multi-format build (ESM, CommonJS, CDN)
|
|
237
|
+
- Bundle size optimization (<1MB target)
|
|
238
|
+
- CDN bundle with radisk included
|
|
239
|
+
- npm package configuration (dual exports)
|
|
240
|
+
|
|
241
|
+
**Ordering Strategy**:
|
|
242
|
+
|
|
243
|
+
**Phase A: Foundation** (Sequential):
|
|
244
|
+
1. Project setup (package.json, dependencies)
|
|
245
|
+
2. Vitest configuration
|
|
246
|
+
3. Vite build configuration
|
|
247
|
+
4. Create all test file stubs (unit, contract, integration) - [P]
|
|
248
|
+
|
|
249
|
+
**Phase B: Core Implementation** (Mostly parallel with dependencies):
|
|
250
|
+
5. [P] Core module + unit tests
|
|
251
|
+
6. [P] Spatial module + unit tests (depends on: Core)
|
|
252
|
+
7. [P] Storage module + unit tests (depends on: Core)
|
|
253
|
+
8. Schema module + unit tests (depends on: Core, Storage) [P after storage]
|
|
254
|
+
9. Federation module + unit tests (depends on: Storage, Spatial) [P after storage]
|
|
255
|
+
10. [P] Crypto module + unit tests
|
|
256
|
+
11. Content module + unit tests (depends on: Crypto, Storage)
|
|
257
|
+
12. Subscriptions module + unit tests (depends on: Storage)
|
|
258
|
+
|
|
259
|
+
**Phase C: API Integration** (After core modules):
|
|
260
|
+
13. Wire up public API in src/index.js
|
|
261
|
+
14. Contract tests for spatial operations
|
|
262
|
+
15. Contract tests for data operations
|
|
263
|
+
16. Contract tests for schema operations
|
|
264
|
+
17. Contract tests for federation operations
|
|
265
|
+
18. Contract tests for crypto operations
|
|
266
|
+
19. Contract tests for social protocol operations
|
|
267
|
+
20. Contract tests for subscription operations
|
|
268
|
+
|
|
269
|
+
**Phase D: Integration & Validation** (After API complete):
|
|
270
|
+
21. Integration test: Scenario 1 (geographic storage)
|
|
271
|
+
22. Integration test: Scenario 2 (federation)
|
|
272
|
+
23. Integration test: Scenario 3 (subscriptions)
|
|
273
|
+
24. Integration test: Scenario 4 (schema validation)
|
|
274
|
+
25. Integration test: Scenario 5 (hierarchical queries)
|
|
275
|
+
26. Integration test: Scenario 6 (social protocols)
|
|
276
|
+
27. Integration test: Scenario 7 (offline persistence)
|
|
277
|
+
28. Integration test: Scenario 8 (authorization)
|
|
278
|
+
29. Integration test: Scenario 9 (cross-dimensional)
|
|
279
|
+
|
|
280
|
+
**Phase E: Build & Distribution** (After tests pass):
|
|
281
|
+
30. ESM build configuration
|
|
282
|
+
31. CommonJS build configuration
|
|
283
|
+
32. CDN bundle build (with radisk)
|
|
284
|
+
33. Bundle size validation (<1MB)
|
|
285
|
+
34. Package.json exports configuration
|
|
286
|
+
35. TypeScript definitions (.d.ts) generation
|
|
287
|
+
|
|
288
|
+
**Task Metadata**:
|
|
289
|
+
- Tasks marked [P] can execute in parallel (no shared dependencies)
|
|
290
|
+
- Each task includes: dependencies, acceptance criteria, test verification
|
|
291
|
+
- TDD approach: Test files created before implementation
|
|
292
|
+
- Module order follows constitutional delegation pattern
|
|
293
|
+
|
|
294
|
+
**Estimated Output**: ~35-40 numbered, dependency-ordered tasks in tasks.md
|
|
295
|
+
|
|
296
|
+
**Coverage Requirements** (per Constitution XI):
|
|
297
|
+
- Every feature module MUST have dedicated unit tests
|
|
298
|
+
- Unit test coverage target: ≥80% line coverage
|
|
299
|
+
- Contract tests: 100% API surface coverage
|
|
300
|
+
- Integration tests: All 9 quickstart scenarios
|
|
301
|
+
|
|
302
|
+
**IMPORTANT**: This phase is executed by the /tasks command, NOT by /plan
|
|
303
|
+
|
|
304
|
+
## Phase 3+: Future Implementation
|
|
305
|
+
*These phases are beyond the scope of the /plan command*
|
|
306
|
+
|
|
307
|
+
**Phase 3**: Task execution (/tasks command creates tasks.md)
|
|
308
|
+
**Phase 4**: Implementation (execute tasks.md following constitutional principles)
|
|
309
|
+
**Phase 5**: Validation (run tests, execute quickstart.md, performance validation)
|
|
310
|
+
|
|
311
|
+
## Complexity Tracking
|
|
312
|
+
*Fill ONLY if Constitution Check has violations that must be justified*
|
|
313
|
+
|
|
314
|
+
| Violation | Why Needed | Simpler Alternative Rejected Because |
|
|
315
|
+
|-----------|------------|-------------------------------------|
|
|
316
|
+
| [e.g., 4th project] | [current need] | [why 3 projects insufficient] |
|
|
317
|
+
| [e.g., Repository pattern] | [specific problem] | [why direct DB access insufficient] |
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
## Progress Tracking
|
|
321
|
+
*This checklist is updated during execution flow*
|
|
322
|
+
|
|
323
|
+
**Phase Status**:
|
|
324
|
+
- [x] Phase 0: Research complete (/plan command)
|
|
325
|
+
- [x] Phase 1: Design complete (/plan command)
|
|
326
|
+
- [x] Phase 2: Task planning complete (/plan command - describe approach only)
|
|
327
|
+
- [ ] Phase 3: Tasks generated (/tasks command)
|
|
328
|
+
- [ ] Phase 4: Implementation complete
|
|
329
|
+
- [ ] Phase 5: Validation passed
|
|
330
|
+
|
|
331
|
+
**Gate Status**:
|
|
332
|
+
- [x] Initial Constitution Check: PASS
|
|
333
|
+
- [x] Post-Design Constitution Check: PASS
|
|
334
|
+
- [x] All NEEDS CLARIFICATION resolved
|
|
335
|
+
- [x] Complexity deviations documented (none - full constitutional compliance)
|
|
336
|
+
|
|
337
|
+
**Generated Artifacts**:
|
|
338
|
+
- [x] `/specs/001-holosphere-holonic-geospatial/research.md` - Technical decisions and research
|
|
339
|
+
- [x] `/specs/001-holosphere-holonic-geospatial/data-model.md` - Entity definitions and relationships
|
|
340
|
+
- [x] `/specs/001-holosphere-holonic-geospatial/contracts/api-interface.md` - Public API contract
|
|
341
|
+
- [x] `/specs/001-holosphere-holonic-geospatial/quickstart.md` - Integration test scenarios
|
|
342
|
+
- [x] `/Users/roberto/Projects/Liminal/holosphere2/CLAUDE.md` - Agent context file
|
|
343
|
+
|
|
344
|
+
**Next Steps**:
|
|
345
|
+
➡️ Run `/tasks` command to generate tasks.md from this plan
|
|
346
|
+
➡️ Implementation will follow task ordering in Phase 2 approach
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
*Based on Constitution v1.1.0 - See `.specify/memory/constitution.md`*
|