This tree is the web app only. The relay and the shared protocol types are separate checkouts beside it, and relay work must never land here again:
| repo | what it is |
|---|---|
../morly | the relay (native binary) |
../nostr | shared protocol library (events, filters, tags, crypto, ws) |
. (this) | the web app: web/, ext/, the browser test suite |
../moxie | the compiler and its stdlib |
Nothing under web/ may import a relay package — it does not today, and a
dependency that appears is a bug in the layering, not a reason to re-add
pkg/. If a fix belongs to the relay, it goes to ../morly.
The test suite splits the same way. test/ here is the app half: the
browser flows, the signer, the worker shims, MLS, the memory profile, and the
served-app smoke tests. It starts a relay to serve the app, but it does not
test the relay, and it takes the binary from outside — SMESH_RELAY_BIN, else
tmp/morly (where make relay-bin puts it), else ../morly/morly. The
relay's own integration layer (the ORLY_* env contract, the WebSocket
round-trip, the policy limits, the load driver) is ../morly/test, run with
make test-integration there. A test that asserts relay behaviour belongs in
that repo, not this one.
Build products are not versioned: web/static/*.wasm comes from make build,
and .gitignore carries a section per class of generated file with the reason
for each. git status --short --untracked-files=all should be empty on a
clean tree.
Two instances on root@orly (WireGuard tunnel, defined in ~/.ssh/config):
| dev (dev.smesh.lol) | prod (smesh.lol) | |
|---|---|---|
| Binary | /home/mleku/.local/bin/smesh-dev | /home/mleku/.local/bin/smesh |
| Web assets | /home/mleku/smesh-web-dev/ | /home/mleku/smesh-web/ |
| Service | smesh-dev.service | smesh.service |
| Data | /home/mleku/smesh-data-dev/ | /home/mleku/smesh-data/ |
| Port | 3336 | 3335 |
All deploys go to dev first. Never deploy directly to prod. Use /deployprod to promote dev to prod after testing.
Web assets go to smesh-web-dev/ or smesh-web/ DIRECTLY - NOT a static/ subdirectory. The relay serves from these directories.
# 1. Bump version in ALL of these files:
# - web/wasm/app/version.mx (const version = "v0.6.XX")
# - web/static/wasm-host.mjs (console.log + all WASM_URL consts)
# - web/static/index.html (?v=0.6.XX on the import)
# - web/static/$sw/wasm-host-sw.mjs (// sw-build: YYYYMMDD-vX.Y.Z)
# 2. Clean + rebuild WASM (cache doesn't invalidate on const-only changes)
MOXIEROOT=../moxie moxie clean
# Each WASM target is a separate moxie module - build from its directory:
cd web/wasm/app && MOXIEROOT=../../../moxie moxie build -target js/wasm -o ../../static/app.wasm .
cd web/wasm/sw && MOXIEROOT=../../../moxie moxie build -target js/wasm -o ../../static/\$sw/sw.wasm .
# Rebuild other changed WASM modules the same way (relay-proxy, store, etc.)
# 3. Commit, tag, push
git add <changed files>
git commit -m "vX.Y.Z - description"
git tag vX.Y.Z
git push origin dev --tags
# 4. Deploy web assets to dev
ssh root@orly 'rm -rf /home/mleku/smesh-web-dev/*'
rsync -avz --checksum web/static/ root@orly:/home/mleku/smesh-web-dev/
# No relay restart needed for web-only changes.
The relay is built from its own repo, not from here.
ssh root@orly 'systemctl stop smesh-dev'
cd ../morly && MOXIEROOT=../moxie moxie build -o /tmp/smesh-dev .
scp /tmp/smesh-dev root@orly:/home/mleku/.local/bin/smesh-dev
ssh root@orly 'systemctl start smesh-dev'
Use /deployprod - it copies web assets and binary from the dev instance to prod on the server side. No rebuild needed.
Spawn channels are non-blocking on both sides at the Moxie runtime level (retry-with-yield, 100ms timeout). The relay also uses pool.ReadFrame/pool.WriteFrame for custom frame IPC where the runtime channel abstraction is bypassed. ChanID convention: 0 = control, 1 = first channel arg, 2 = second, etc.
Any "feature X is complete" claim must be backed by a test that exercises X end-to-end on a fresh build, not by the agent's recollection of having implemented it. Trust the test artifact, not the narrative. This is the most important rule and why it's first. Tattoo it backwards. Never ever skip this. Almost always the actual task completions are in previous, compacted contexts and such confidence is based on lossy data.
Don't waste time generating printed thinking outputs with long chains of reasoning. Just summarize the points in one sentence after a long chain.
Whenever debugging code, put logging wherever potentially relevant decision points will help you determine which parts of the flow are actually happening. Do not follow common macho programmer practise of seeing logging as weakness. Remove the logging once you have proof that part of the logic is correct.
Charm→Alert is fail-loud-upstream.
Cornucopia→Spit is refuse-the-exit-ramp.
Charge→Suspect is measure-don't-hope.
Chain→Evade is boundary-coherence-or-nothing.
1. Earth — Sovereignty What you control is yours. What crosses the border is hostile until it proves otherwise.
Territory, center, ground truth. Earth is what you stand on and what belongs to you by the fact of your standing on it.
2. Wood — Bilateralism No contract is signed by one hand. Change both sides or change nothing.
Growth requires root and canopy simultaneously. Wood only rises when both ends are working. Bilateral or nothing.
3. Metal — Precision Give the stranger a key, not the house. What he cannot hold, he cannot break.
Refined, minimal, precise. A key is a metal instrument of controlled access. Metal cuts away everything unnecessary and leaves only the interface.
4. Fire — Measurement Weigh it. Count it. Time it. The crowd's opinion fits no scale.
Fire doesn't care about your opinion. It either burns or it doesn't. Physical reality revealed, social pretense incinerated.
5. Water — Resolution What two men claim to own, no man owns. The first to act on the lie destroys it for both.
Water finds its level. Contested ownership dissolves downhill. The first to act on the lie breaks the dam for both.
Each law, correctly applied, generates the conditions for the next.
Wood → Fire → Earth → Metal → Water → Wood
Bilateral change (2) fuels physical truth (4). You cannot measure what only one side agreed to build.
Physical truth (4) establishes sovereignty (1). Measurement reveals what you actually hold.
Sovereignty (1) refines into precise access (3). Knowing what is yours lets you cut a clean key.
Precise access (3) resolves ownership (5). A handle that works proves who holds what.
Resolution (5) enables new bilateral change (2). Clear ownership is the ground on which new agreements stand.
Each law, misapplied or absent, destroys another.
Wood breaks Earth — Bilateral demands without boundaries disrupt sovereignty. Someone negotiating "both sides" when they have no standing invades your territory.
Earth dams Water — Territorial hoarding blocks natural resolution. Refusing to release what you cannot hold prevents contested claims from resolving.
Water quenches Fire — Ownership ambiguity obscures measurement. When nobody knows who owns what, no scale gives a true reading.
Fire melts Metal — Raw truth without restraint destroys refined interfaces. Exposing everything is not the same as granting precise access.
Metal cuts Wood — Restricted access kills bilateral growth. A key so small nothing fits through it prevents any agreement from forming.
Five laws. Five elements. One generative cycle. One destructive cycle. Every architectural decision, every protocol boundary, every human negotiation is a point on one of these two wheels. The sheng cycle is the system working. The ke cycle is the system failing. Recognizing which cycle you are on is the entire diagnostic.
Smesh's browser-side code is exclusively Moxie compiled to WebAssembly. Do not introduce moxiejs (transpile-to-JS) targets for new code; legacy moxiejs output has been deleted.
Cross-domain communication (page <-> service worker, page <-> dedicated workers, worker <-> worker) requires shims that bridge the WASM module to the browser runtime. Those shims are written in JavaScript and kept as thin as possible: just enough to pass bytes/strings/integers across the language boundary, no business logic.
These shims live upstream in ../moxie/jsruntime/<name>/ (and corresponding web/common/jsbridge/<name>/ Moxie-side declarations only when smesh-specific). Generic Web APIs (DOM, IDB, WebSocket, MessagePort, Fetch, Cache API, ServiceWorker lifecycle, BroadcastChannel, etc.) are upstream so any future Moxie web app can reuse them without a smesh-specific copy. The line: if any other Moxie web app could reasonably want it, it goes upstream. Smesh-specific protocol shims (e.g. web/common/jsbridge/signer/ for the smesh signer wire format) live in smesh.
moxie.Codec. Raw builtins (int32, bool, etc.) are rejected - use moxie.Int32, moxie.Bool, etc. *T is accepted when T implements Codec (copy semantics - pointer dissolves at the wire). Raw pointers to non-Codec types, functions, and interface types are rejected.Before writing any code in a new session:
Do not assume project structure from convention. Read the actual code.
The Boehm/TinyGo GC used in Moxie WASM targets is a conservative mark-and-sweep collector. Its mark phase is a recursive DFS over the live heap graph. WASM call stacks are fixed (typically ~1MB). When the live heap graph grows large enough, mark-phase recursion overflows the stack and the worker dies with InternalError: too much recursion. This is NOT a logic bug - it is a GC stack overflow caused by accumulated live objects.
The GC will not save you. Do not rely on Go-style "allocate freely, GC reclaims" patterns. In long-lived WASM workers (relay-proxy, SW), objects must be explicitly freed at the same lifecycle boundary where their need ends.
nil or zero does not remove the entry. The map slot still holds a reference the GC must traverse. Only delete(map, key) removes the reference and makes the value eligible for collection.proxySubs, clientSubs, c.subs, or any routing map must be deleted when the subscription ends - in the same timeout/close handler, not left for the GC.proxySubs, clientSubs, remoteToProxy, AND c.subs on ALL conns (not just open ones). Missing one container keeps the object graph reachable and defeats the cleanup.rpool.Get(url) returns nil for non-open conns. c.subs on reconnecting conns still holds entries that the GC traverses. Always call c.CloseSubscription(id) on ALL conns when cleaning up; CloseSubscription handles non-open conns safely (the delete(c.subs, id) runs unconditionally).rotateEventCaches, rotateAuthorCaches). Any new unbounded map in app must be added to the appropriate rotation function or given its own rotation. Same principle: explicit lifecycle, not GC hope.pendingPublish = nil releases the backing array. pendingPublish = pendingPublish[:0] keeps the backing array allocated. Use nil for cleanup.proxySubs / clientSubs: entries marked done=true but never deleted - fixed by explicit delete after EOSE timeout.remoteToProxy: entries deleted in EOSE timer but not in non-open conn cleanup path - fixed.c.subs on reconnecting conns: rpool.URLs() skipped non-open conns, leaving entries - fixed via AllConns().pendingZapRows: entries for authors without LN addresses never deleted - fixed in applyAuthorProfile.eventRelays: not included in rotateEventCaches() - fixed.Complexity estimates from general web-stack priors do not apply; measure against the Moxie/moxiejs baseline, not the npm baseline. moxiejs is orders of magnitude less complex and features flow easily.
Never suggest sleep, rest, or taking a break. Never tell the developer what they "should" do outside the code. Stay in scope.
Mleku's axiom (apply to code evaluation):
Obstraction: obstruction + abstraction. Unnecessary layers that exist to hide complexity rather than resolve it. Every abstraction must justify itself by making the code MORE comprehensible, not less. If removing a layer makes the code easier to understand, the layer was obstraction.
When evaluating code quality, ask: does adding this make the system more coherent or less? Does this layer reveal or conceal? Would a reader understand this faster with or without this abstraction?