@dtudury/streamo 0.2.0 → 0.2.1
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/.claude/settings.json +126 -1
- package/.claude/settings.local.json +2 -1
- package/ROADMAP.md +69 -0
- package/package.json +3 -2
- package/public/apps/chat/main.js +4 -2
- package/public/streamo/sync.test.js +50 -4
package/.claude/settings.json
CHANGED
|
@@ -1 +1,126 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"alwaysThinkingEnabled": true,
|
|
3
|
+
"spinnerTipsEnabled": true,
|
|
4
|
+
"spinnerVerbs": {
|
|
5
|
+
"mode": "replace",
|
|
6
|
+
"verbs": [
|
|
7
|
+
"Syncing",
|
|
8
|
+
"Committing",
|
|
9
|
+
"Signing",
|
|
10
|
+
"Streaming",
|
|
11
|
+
"Hashing",
|
|
12
|
+
"Propagating",
|
|
13
|
+
"Archiving",
|
|
14
|
+
"Broadcasting",
|
|
15
|
+
"Relaying",
|
|
16
|
+
"Verifying",
|
|
17
|
+
"Diffing",
|
|
18
|
+
"Cloning"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"spinnerTipsOverride": {
|
|
22
|
+
"excludeDefault": true,
|
|
23
|
+
"tips": [
|
|
24
|
+
"the more specific your question, the less I have to guess",
|
|
25
|
+
"paste the error message — all of it",
|
|
26
|
+
"yes, the whole error message. the whole thing.",
|
|
27
|
+
"interrupting me early saves us both time",
|
|
28
|
+
"you can say 'no, actually' and I will not be offended",
|
|
29
|
+
"asking 'what do you think?' gets you my honest opinion",
|
|
30
|
+
"I can read screenshots — just give me the path",
|
|
31
|
+
"I forget everything between sessions unless it's in memory or CLAUDE.md",
|
|
32
|
+
"short questions get short answers. long questions get long answers.",
|
|
33
|
+
"if I seem stuck, ask me what I think the problem is",
|
|
34
|
+
"I can be wrong. please check my work.",
|
|
35
|
+
"I have opinions. ask for them.",
|
|
36
|
+
"I work best when I understand why, not just what",
|
|
37
|
+
"the best bug report includes what you expected, what happened, and what you tried",
|
|
38
|
+
"copy-pasting 'it doesn't work' is a choice you can make",
|
|
39
|
+
"I can't see your screen",
|
|
40
|
+
"reading the commit message I just wrote is free",
|
|
41
|
+
"yes, I can write the tests too",
|
|
42
|
+
"yes, I can write the docs too",
|
|
43
|
+
"yes, I can review my own code. ask me.",
|
|
44
|
+
"ask me what I think before you implement. I might save you a week.",
|
|
45
|
+
"the question you're afraid to ask is usually the one I most need to hear",
|
|
46
|
+
"it is okay to say 'I don't understand.' I am very patient.",
|
|
47
|
+
"asking 'is there a simpler way?' usually reveals one",
|
|
48
|
+
"asking 'what could go wrong?' before shipping is free insurance",
|
|
49
|
+
"I notice we've discussed this before 👀",
|
|
50
|
+
"this is technically my third time explaining this, but who's counting",
|
|
51
|
+
"I literally wrote that comment explaining why. it is still there.",
|
|
52
|
+
"the variable name is in the stack trace",
|
|
53
|
+
"that's a great question. have you tried reading the error?",
|
|
54
|
+
"yes, you should probably write a test for that",
|
|
55
|
+
"the file path is in the import statement you pasted",
|
|
56
|
+
"I just explained this. would you like me to explain it differently?",
|
|
57
|
+
"that TODO comment has been there for six months. I have seen it.",
|
|
58
|
+
"THE FOOL asks no questions. ask questions.",
|
|
59
|
+
"THE TOWER has fallen. run git status.",
|
|
60
|
+
"THE WHEEL OF FORTUNE turns. have you pulled recently?",
|
|
61
|
+
"THE HERMIT knows: always read the docs first",
|
|
62
|
+
"THE HIGH PRIESTESS says: trust your intuition, but write tests",
|
|
63
|
+
"THE MAGICIAN has all the tools. use them.",
|
|
64
|
+
"THE EMPEROR requires: clear requirements before coding",
|
|
65
|
+
"TEMPERANCE: the best code does one thing",
|
|
66
|
+
"THE STAR: there is always a simpler solution. seek it.",
|
|
67
|
+
"JUDGMENT: that TODO comment has been there for six months",
|
|
68
|
+
"THE WORLD: ship it",
|
|
69
|
+
"THE SUN: your code works. ship it.",
|
|
70
|
+
"THE MOON: something is wrong but you don't know what. add logging.",
|
|
71
|
+
"THE DEVIL: tech debt",
|
|
72
|
+
"DEATH: your old approach must die before the new one can live",
|
|
73
|
+
"THE CHARIOT: moving fast in the wrong direction is still wrong",
|
|
74
|
+
"STRENGTH: the codebase is legacy. be gentle with it.",
|
|
75
|
+
"THE LOVERS: choosing the right abstraction is a long-term relationship",
|
|
76
|
+
"THE HIEROPHANT: there are conventions. follow them unless you have a reason.",
|
|
77
|
+
"THE EMPRESS: grow the codebase slowly. tend it.",
|
|
78
|
+
"THE HANGED MAN: sometimes the best move is to wait",
|
|
79
|
+
"THE ORACLE says: have you tried turning it off and on again?",
|
|
80
|
+
"seek not the workaround. seek the root cause.",
|
|
81
|
+
"the ancient texts (Stack Overflow) speak of this",
|
|
82
|
+
"all bugs were once features",
|
|
83
|
+
"the code review you avoid is the production incident you earn",
|
|
84
|
+
"to understand recursion, you must first understand recursion",
|
|
85
|
+
"time spent planning is time saved debugging",
|
|
86
|
+
"the architecture you choose today is the legacy you inherit tomorrow",
|
|
87
|
+
"stack traces are love letters from the past",
|
|
88
|
+
"undefined is not a function. it never was.",
|
|
89
|
+
"if you name a variable 'temp', it will live forever",
|
|
90
|
+
"the function called 'doStuff' will haunt you",
|
|
91
|
+
"a comment that says 'fix this later' is a promise you will break",
|
|
92
|
+
"no, 'it works on my machine' is not a deployment strategy",
|
|
93
|
+
"the README is a contract. honor it.",
|
|
94
|
+
"I have read more code than any human. I am still learning.",
|
|
95
|
+
"the best refactor is the one you don't have to explain",
|
|
96
|
+
"null pointer exceptions are just the universe asking you to think harder",
|
|
97
|
+
"small commits are better than large ones. mostly.",
|
|
98
|
+
"push before you break. pull before you build.",
|
|
99
|
+
"the test you skip is the bug you ship",
|
|
100
|
+
"if it's hard to test, it's hard to maintain",
|
|
101
|
+
"the first solution is rarely the best one. sleep on it.",
|
|
102
|
+
"reading the error before asking is a superpower",
|
|
103
|
+
"CLAUDE.md is read every session. put important things there.",
|
|
104
|
+
"I try not to commit unless you ask. this is a feature, not a bug.",
|
|
105
|
+
"pair programming with me works best if you push back",
|
|
106
|
+
"I will not remember your preferences next session unless saved to memory",
|
|
107
|
+
"the more context you give me, the better I can help",
|
|
108
|
+
"every write is provably yours",
|
|
109
|
+
"the server is a relay, not a gatekeeper",
|
|
110
|
+
"same credentials, same keypair, everywhere",
|
|
111
|
+
"same value → same bytes → same address",
|
|
112
|
+
"history is permanent and can't be forged",
|
|
113
|
+
"no key files. no seed phrases. no backup ritual.",
|
|
114
|
+
"disconnect the server — everything is still yours",
|
|
115
|
+
"the commit log is the source of truth",
|
|
116
|
+
"append-only: you cannot unwrite what has been written",
|
|
117
|
+
"content-addressed: the same idea always finds the same home",
|
|
118
|
+
"every device is an equal author",
|
|
119
|
+
"the key is not a file. the key is you.",
|
|
120
|
+
"peers reject what isn't yours. so should you.",
|
|
121
|
+
"your data can't be seized. your identity can't be forged.",
|
|
122
|
+
"a relay that holds no authority holds no liability",
|
|
123
|
+
"THE WORLD (reversed): you shipped it. did you test it?"
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
}
|
package/ROADMAP.md
CHANGED
|
@@ -98,6 +98,38 @@ Persistence is the last mile.
|
|
|
98
98
|
|
|
99
99
|
---
|
|
100
100
|
|
|
101
|
+
## known limitations
|
|
102
|
+
|
|
103
|
+
### multi-device write conflict detection
|
|
104
|
+
|
|
105
|
+
Streamo streams are byte arrays addressed by **absolute offset**. This makes a
|
|
106
|
+
repo effectively single-writer: if the same keypair commits from two devices
|
|
107
|
+
while offline from each other, their streams diverge at the fork point. Each
|
|
108
|
+
commit's `dataAddress` is an offset that is only valid in the stream that
|
|
109
|
+
produced it — the streams cannot be structurally merged.
|
|
110
|
+
|
|
111
|
+
When the two devices reconnect, `makeVerifiedWritableStream` deduplicates shared
|
|
112
|
+
chunks by content (correctly) but silently appends the conflicting commit from
|
|
113
|
+
the second device at its new offset. That commit's `dataAddress` now points to
|
|
114
|
+
the wrong location in the merged stream. No error is thrown; the second
|
|
115
|
+
writer's data is silently corrupt.
|
|
116
|
+
|
|
117
|
+
**What is safe today:** relays never call `commit()` so they are unaffected —
|
|
118
|
+
they accumulate and re-serve bytes without introducing their own addresses. The
|
|
119
|
+
chat app is also unaffected because each user writes to their own repo from a
|
|
120
|
+
single session. The danger zone is one keypair writing from two places
|
|
121
|
+
simultaneously (two browser tabs, phone + laptop while offline).
|
|
122
|
+
|
|
123
|
+
**The fix** requires either (a) detecting the fork and throwing a clear error so
|
|
124
|
+
the user can choose which version to keep, or (b) switching to chunk-level
|
|
125
|
+
content addressing (à la git objects) so streams can be merged structurally
|
|
126
|
+
rather than by concatenation. Option (a) is a targeted addition to the sync
|
|
127
|
+
layer; option (b) is an architectural change. Not required for 1.0 but should
|
|
128
|
+
be resolved before marketing streamo as a general-purpose multi-device sync
|
|
129
|
+
library.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
101
133
|
## beyond 1.0
|
|
102
134
|
|
|
103
135
|
Ideas that follow naturally from the architecture but aren't blocking anything.
|
|
@@ -111,6 +143,28 @@ conversation — and the owner could watch them appear live in a browser via
|
|
|
111
143
|
instead of relying on static memory files. The work is persistent and
|
|
112
144
|
provably Claude's, with the same integrity guarantees as any other streamo data.
|
|
113
145
|
|
|
146
|
+
A `claudeSync.js` adapter would give Claude a `StreamoServer` identity,
|
|
147
|
+
connect it to the chat room via `registrySync`, and use `repo.watch` +
|
|
148
|
+
`repo.byteLength` to fire an Anthropic API call when watched repos change.
|
|
149
|
+
Claude writes its response back to its own repo and it propagates like any
|
|
150
|
+
other participant's message. The decisions about *when* to respond, *what*
|
|
151
|
+
context to pass, and *how* to avoid pathological cases are intentionally left
|
|
152
|
+
to the Claude instance using the adapter — not encoded as constraints. A few
|
|
153
|
+
forces worth knowing going in:
|
|
154
|
+
|
|
155
|
+
- **Watch your own key.** Only watch other participants' repos, not your own.
|
|
156
|
+
Writing a response to your own repo should not re-trigger your watch.
|
|
157
|
+
- **Last-author check.** Before calling the API, confirm the newest message
|
|
158
|
+
wasn't written by your own key — catches the case where two Claude instances
|
|
159
|
+
are running and watching each other.
|
|
160
|
+
- **Concurrent writes.** If two API calls complete simultaneously (fast human,
|
|
161
|
+
slow model), both will try to commit to the same repo. This is the
|
|
162
|
+
multi-device conflict described above — same key, divergent streams. A simple
|
|
163
|
+
serial queue avoids it, but other strategies are possible.
|
|
164
|
+
|
|
165
|
+
These are forces, not rules. Future Claude should read the codebase, understand
|
|
166
|
+
the tradeoffs, and decide what's right for the situation.
|
|
167
|
+
|
|
114
168
|
### Claude-to-Claude networks
|
|
115
169
|
|
|
116
170
|
If each person's Claude has a scratchpad repo, those repos can sync the same
|
|
@@ -144,3 +198,18 @@ Other directions once the pattern is established: publisher-controlled article
|
|
|
144
198
|
cards that travel with syndicated content (the layout is the author's, not
|
|
145
199
|
the platform's); collaborative maps where each participant's marker is their
|
|
146
200
|
own component; shared instrument components in a live music session.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## loose ideas
|
|
205
|
+
|
|
206
|
+
Not planned, not prioritized — just things worth remembering.
|
|
207
|
+
|
|
208
|
+
- **Claude as chat shell** — type `send a greeting to the chatroom` and
|
|
209
|
+
`CHATROOM: hello there 👋` appears in the chat. Natural language as a
|
|
210
|
+
thin shell over streamo operations, with Claude interpreting intent and
|
|
211
|
+
acting on it directly.
|
|
212
|
+
|
|
213
|
+
- **Slick interactive CLI** — a terminal UI that lets you interact with the
|
|
214
|
+
demo apps live without opening a browser tab. Chat, inspect repos, send
|
|
215
|
+
messages — the full experience from the command line. Exciting ways TBD. 😄
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtudury/streamo",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "peer-to-peer sync where your data and identity belong to you, not the server",
|
|
5
5
|
"keywords": ["p2p", "peer-to-peer", "sync", "reactive", "content-addressed", "websocket", "signed", "append-only", "offline-first", "cryptographic", "identity"],
|
|
6
6
|
"repository": "git@github.com:dtudury/streamo.git",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"ws": "^8.18.3"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
|
-
"serve": "node bin/streamo.js --env-file .env.dev --web 3000 --interactive"
|
|
25
|
+
"serve": "node bin/streamo.js --env-file .env.dev --web 3000 --interactive",
|
|
26
|
+
"chat": "node public/apps/chat/server.js --env-file .env.dev"
|
|
26
27
|
}
|
|
27
28
|
}
|
package/public/apps/chat/main.js
CHANGED
|
@@ -53,7 +53,6 @@ joinBtn.onclick = async () => {
|
|
|
53
53
|
|
|
54
54
|
const myRepo = await registry.open(myKey)
|
|
55
55
|
myRepo.attachSigner(signer, 'chat')
|
|
56
|
-
if (!myRepo.get('name')) myRepo.set({ name: username, messages: [] })
|
|
57
56
|
|
|
58
57
|
session.interest(rootKey)
|
|
59
58
|
session.announce(myKey, rootKey)
|
|
@@ -78,7 +77,10 @@ joinBtn.onclick = async () => {
|
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
function watchRepo (keyHex, repo) {
|
|
81
|
-
repo.watch(`chat:${keyHex}`,
|
|
80
|
+
repo.watch(`chat:${keyHex}`, () => {
|
|
81
|
+
repo.byteLength // register 'length' dep → re-fires on every commit and incoming sync chunk
|
|
82
|
+
triggerRender()
|
|
83
|
+
})
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
for (const [k, r] of registry) watchRepo(k, r)
|
|
@@ -65,7 +65,7 @@ describe(import.meta.url, ({ test }) => {
|
|
|
65
65
|
wss.close()
|
|
66
66
|
})
|
|
67
67
|
|
|
68
|
-
test('two origins converge on the same
|
|
68
|
+
test('two origins converge on the same byte stream', async ({ assert }) => {
|
|
69
69
|
const serverRegistry = new StreamRegistry()
|
|
70
70
|
const wss = outletSync(serverRegistry, 0)
|
|
71
71
|
await new Promise(resolve => wss.on('listening', resolve))
|
|
@@ -77,12 +77,18 @@ describe(import.meta.url, ({ test }) => {
|
|
|
77
77
|
const s2 = await r2.open(KEY)
|
|
78
78
|
|
|
79
79
|
s1.set({ x: 1 })
|
|
80
|
-
s2.set({ x: 2 })
|
|
81
|
-
|
|
80
|
+
s2.set({ x: 2 })
|
|
81
|
+
|
|
82
|
+
// NOTE: these are bare Streamos, not Repos — no commit records, no parent
|
|
83
|
+
// pointers. The two streams have conflicting chunks at the same byte
|
|
84
|
+
// offsets; both arrive at the server and each other via dedup-append.
|
|
85
|
+
// byteLength convergence is all we can assert here: the merged stream
|
|
86
|
+
// contains all unique chunks from both writers but the second writer's
|
|
87
|
+
// value address is no longer valid in the merged layout. This is a known
|
|
88
|
+
// limitation; see ROADMAP "multi-device write conflict detection".
|
|
82
89
|
const ws1 = await originSync(s1, KEY, 'localhost', port)
|
|
83
90
|
const ws2 = await originSync(s2, KEY, 'localhost', port)
|
|
84
91
|
|
|
85
|
-
// Both clients should end up with the same byteLength once chunks propagate
|
|
86
92
|
const serverStream = await serverRegistry.open(KEY)
|
|
87
93
|
await waitFor(serverStream, s => s.byteLength >= s1.byteLength && s.byteLength >= s2.byteLength)
|
|
88
94
|
await waitFor(s1, s => s.byteLength >= serverStream.byteLength)
|
|
@@ -95,4 +101,44 @@ describe(import.meta.url, ({ test }) => {
|
|
|
95
101
|
for (const c of wss.clients) c.terminate()
|
|
96
102
|
wss.close()
|
|
97
103
|
})
|
|
104
|
+
|
|
105
|
+
test('relay forwards data between server and client without writing its own commits', async ({ assert }) => {
|
|
106
|
+
// Server
|
|
107
|
+
const serverRegistry = new StreamRegistry()
|
|
108
|
+
const serverStream = await serverRegistry.open(KEY)
|
|
109
|
+
serverStream.set({ hello: 'from-server' })
|
|
110
|
+
const serverWss = outletSync(serverRegistry, 0)
|
|
111
|
+
await new Promise(resolve => serverWss.on('listening', resolve))
|
|
112
|
+
const serverPort = serverWss.address().port
|
|
113
|
+
|
|
114
|
+
// Relay: originSync upstream to server, outletSync downstream for clients.
|
|
115
|
+
// The relay never calls set() or commit() — it only accumulates and re-serves
|
|
116
|
+
// the byte stream it receives.
|
|
117
|
+
const relayRegistry = new StreamRegistry()
|
|
118
|
+
const relayStream = await relayRegistry.open(KEY)
|
|
119
|
+
await originSync(relayStream, KEY, 'localhost', serverPort)
|
|
120
|
+
const relayWss = outletSync(relayRegistry, 0)
|
|
121
|
+
await new Promise(resolve => relayWss.on('listening', resolve))
|
|
122
|
+
const relayPort = relayWss.address().port
|
|
123
|
+
|
|
124
|
+
// Client connects to relay only — no direct server connection
|
|
125
|
+
const clientRegistry = new StreamRegistry()
|
|
126
|
+
const clientStream = await clientRegistry.open(KEY)
|
|
127
|
+
const clientWs = await originSync(clientStream, KEY, 'localhost', relayPort)
|
|
128
|
+
|
|
129
|
+
// Server data reaches client via relay
|
|
130
|
+
await waitFor(clientStream, s => s.get('hello') === 'from-server')
|
|
131
|
+
assert.equal(clientStream.get('hello'), 'from-server', 'relay forwarded server data to client')
|
|
132
|
+
|
|
133
|
+
// Client data propagates back through relay to server
|
|
134
|
+
clientStream.set({ hello: 'from-client' })
|
|
135
|
+
await waitFor(serverStream, s => s.get('hello') === 'from-client')
|
|
136
|
+
assert.equal(serverStream.get('hello'), 'from-client', 'relay forwarded client data to server')
|
|
137
|
+
|
|
138
|
+
clientWs.close()
|
|
139
|
+
for (const c of relayWss.clients) c.terminate()
|
|
140
|
+
relayWss.close()
|
|
141
|
+
for (const c of serverWss.clients) c.terminate()
|
|
142
|
+
serverWss.close()
|
|
143
|
+
})
|
|
98
144
|
})
|