@dtudury/streamo 0.2.0 → 1.0.0

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.
@@ -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
+ }
@@ -8,7 +8,8 @@
8
8
  "Bash(git rm *)",
9
9
  "Bash(node --test)",
10
10
  "Bash(node --input-type=module --eval \"import './bin/streamo.js'\" --help)",
11
- "Bash(node bin/streamo.js --help)"
11
+ "Bash(node bin/streamo.js --help)",
12
+ "Bash(node *)"
12
13
  ]
13
14
  }
14
15
  }
package/README.md CHANGED
@@ -204,8 +204,7 @@ node --test public/streamo/Repo.test.js # single file
204
204
 
205
205
  ## roadmap
206
206
 
207
- See [ROADMAP.md](./ROADMAP.md) for what's been built, what's next, and what we're
208
- aiming at for 1.0.
207
+ See [ROADMAP.md](./ROADMAP.md) for what's been built and what's next.
209
208
 
210
209
  ## collaboration
211
210
 
package/ROADMAP.md CHANGED
@@ -5,9 +5,9 @@ picture of where the project is and where it's headed.
5
5
 
6
6
  ---
7
7
 
8
- ## where we are (0.2.0)
8
+ ## where we are (1.0.0)
9
9
 
10
- The foundation is solid and working. Here's what's in:
10
+ The foundation is solid, tested, and shipped. Here's what's in:
11
11
 
12
12
  **Core data layer**
13
13
  - `Streamo` — reactive, content-addressed, append-only byte store with a
@@ -54,7 +54,8 @@ The foundation is solid and working. Here's what's in:
54
54
  stream. `public/apps/chat/server.js` is the standalone server — its public key
55
55
  is the room address, its member list is in its own repo, and it has no special
56
56
  authority over anyone's data. Runs in the browser and from the terminal
57
- (`chat-cli.js`).
57
+ (`chat-cli.js`). Message history persists across page reloads via server-side
58
+ archiving — rejoin with the same credentials and your history comes back.
58
59
  - Homepage at `public/index.html`.
59
60
  - `StreamoServer` — reusable class that wraps signer, registry, and all sync
60
61
  methods behind a clean API. `bin/streamo.js` is now a thin CLI parser on top
@@ -67,13 +68,6 @@ The foundation is solid and working. Here's what's in:
67
68
 
68
69
  ## what's next
69
70
 
70
- ### chat persistence ← start here
71
- The chat server (`public/apps/chat/server.js`) uses `StreamoServer` and wires
72
- `archiveSync` — so the member list survives restarts automatically. Individual
73
- message history lives in each participant's own repo; persistence there depends
74
- on participants running with `--data-dir` set. The remaining work is ensuring the
75
- browser chat client also persists across page reloads.
76
-
77
71
  ### presence indicators
78
72
  Who's currently online? The `interest` / `announce` layer is ephemeral by design,
79
73
  so presence is a heartbeat + timeout — announce yourself periodically, time out
@@ -86,15 +80,37 @@ real-world test of the UI layer.
86
80
 
87
81
  ---
88
82
 
89
- ## toward 1.0
83
+ ---
84
+
85
+ ## known limitations
90
86
 
91
- One thing blocking a stable `1.0` claim:
87
+ ### multi-device write conflict detection
92
88
 
93
- 1. **Chat persistence** a chat app that loses history on restart isn't production-ready
89
+ Streamo streams are byte arrays addressed by **absolute offset**. This makes a
90
+ repo effectively single-writer: if the same keypair commits from two devices
91
+ while offline from each other, their streams diverge at the fork point. Each
92
+ commit's `dataAddress` is an offset that is only valid in the stream that
93
+ produced it — the streams cannot be structurally merged.
94
94
 
95
- Chat signing is done. Components, keyed list reconciliation, SVG namespaces,
96
- `class` arrays/objects, and the CLI server unification are all done.
97
- Persistence is the last mile.
95
+ When the two devices reconnect, `makeVerifiedWritableStream` deduplicates shared
96
+ chunks by content (correctly) but silently appends the conflicting commit from
97
+ the second device at its new offset. That commit's `dataAddress` now points to
98
+ the wrong location in the merged stream. No error is thrown; the second
99
+ writer's data is silently corrupt.
100
+
101
+ **What is safe today:** relays never call `commit()` so they are unaffected —
102
+ they accumulate and re-serve bytes without introducing their own addresses. The
103
+ chat app is also unaffected because each user writes to their own repo from a
104
+ single session. The danger zone is one keypair writing from two places
105
+ simultaneously (two browser tabs, phone + laptop while offline).
106
+
107
+ **The fix** requires either (a) detecting the fork and throwing a clear error so
108
+ the user can choose which version to keep, or (b) switching to chunk-level
109
+ content addressing (à la git objects) so streams can be merged structurally
110
+ rather than by concatenation. Option (a) is a targeted addition to the sync
111
+ layer; option (b) is an architectural change. Not required for 1.0 but should
112
+ be resolved before marketing streamo as a general-purpose multi-device sync
113
+ library.
98
114
 
99
115
  ---
100
116
 
@@ -111,6 +127,28 @@ conversation — and the owner could watch them appear live in a browser via
111
127
  instead of relying on static memory files. The work is persistent and
112
128
  provably Claude's, with the same integrity guarantees as any other streamo data.
113
129
 
130
+ A `claudeSync.js` adapter would give Claude a `StreamoServer` identity,
131
+ connect it to the chat room via `registrySync`, and use `repo.watch` +
132
+ `repo.byteLength` to fire an Anthropic API call when watched repos change.
133
+ Claude writes its response back to its own repo and it propagates like any
134
+ other participant's message. The decisions about *when* to respond, *what*
135
+ context to pass, and *how* to avoid pathological cases are intentionally left
136
+ to the Claude instance using the adapter — not encoded as constraints. A few
137
+ forces worth knowing going in:
138
+
139
+ - **Watch your own key.** Only watch other participants' repos, not your own.
140
+ Writing a response to your own repo should not re-trigger your watch.
141
+ - **Last-author check.** Before calling the API, confirm the newest message
142
+ wasn't written by your own key — catches the case where two Claude instances
143
+ are running and watching each other.
144
+ - **Concurrent writes.** If two API calls complete simultaneously (fast human,
145
+ slow model), both will try to commit to the same repo. This is the
146
+ multi-device conflict described above — same key, divergent streams. A simple
147
+ serial queue avoids it, but other strategies are possible.
148
+
149
+ These are forces, not rules. Future Claude should read the codebase, understand
150
+ the tradeoffs, and decide what's right for the situation.
151
+
114
152
  ### Claude-to-Claude networks
115
153
 
116
154
  If each person's Claude has a scratchpad repo, those repos can sync the same
@@ -144,3 +182,18 @@ Other directions once the pattern is established: publisher-controlled article
144
182
  cards that travel with syndicated content (the layout is the author's, not
145
183
  the platform's); collaborative maps where each participant's marker is their
146
184
  own component; shared instrument components in a live music session.
185
+
186
+ ---
187
+
188
+ ## loose ideas
189
+
190
+ Not planned, not prioritized — just things worth remembering.
191
+
192
+ - **Claude as chat shell** — type `send a greeting to the chatroom` and
193
+ `CHATROOM: hello there 👋` appears in the chat. Natural language as a
194
+ thin shell over streamo operations, with Claude interpreting intent and
195
+ acting on it directly.
196
+
197
+ - **Slick interactive CLI** — a terminal UI that lets you interact with the
198
+ demo apps live without opening a browser tab. Chat, inspect repos, send
199
+ 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.0",
3
+ "version": "1.0.0",
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
  }
@@ -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}`, triggerRender)
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 state', async ({ assert }) => {
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 }) // will be a conflict at the streamo level, but both chunks land
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
  })