atagen

macltok

public
Star0
Watch0
6f1d6591c10d24ed02cad8602671b55d6cc21374
3
ssh://brewery@pls.lobotomise.me:33/atagen/macltok.git

Blame: README.md

96fdf90aacd6atagen2026-09-08 08:24 UTC1
# macltok
96fdf90aacd6atagen2026-09-08 08:24 UTC2
96fdf90aacd6atagen2026-09-08 08:24 UTC3
`macltok` is a compact Rust application backend built above `matrix-sdk` and
96fdf90aacd6atagen2026-09-08 08:24 UTC4
`matrix-sdk-ui`. It aims to provide the stateful behavior needed by a useful
96fdf90aacd6atagen2026-09-08 08:24 UTC5
Matrix client without depending on a GUI toolkit or inventing another protocol
96fdf90aacd6atagen2026-09-08 08:24 UTC6
SDK.
96fdf90aacd6atagen2026-09-08 08:24 UTC7
96fdf90aacd6atagen2026-09-08 08:24 UTC8
The crate currently provides
96fdf90aacd6atagen2026-09-08 08:24 UTC9
96fdf90aacd6atagen2026-09-08 08:24 UTC10
- typed commands, owned UI-safe events and bounded per-client transport
96fdf90aacd6atagen2026-09-08 08:24 UTC11
- Sliding Sync with normalized connection and room-list state
96fdf90aacd6atagen2026-09-08 08:24 UTC12
- independently retained live room timelines and backwards pagination
96fdf90aacd6atagen2026-09-08 08:24 UTC13
- text, emote, reply, edit, redaction, reaction, receipt and typing operations
96fdf90aacd6atagen2026-09-08 08:24 UTC14
- raw encrypted or unencrypted media acquisition with configurable byte limits
96fdf90aacd6atagen2026-09-08 08:24 UTC15
- encryption state, recovery-key import and SAS verification
62fe32759529atagen2026-09-26 08:50 UTC16
- password login and session restoration with caller-owned encrypted SQLite or
62fe32759529atagen2026-09-26 08:50 UTC17
  IndexedDB stores
96fdf90aacd6atagen2026-09-08 08:24 UTC18
96fdf90aacd6atagen2026-09-08 08:24 UTC19
Matrix room, event, user, device and transaction identifiers remain strongly
96fdf90aacd6atagen2026-09-08 08:24 UTC20
typed. A toolkit timeline identity covers local echoes without pretending they
96fdf90aacd6atagen2026-09-08 08:24 UTC21
already have remote event IDs.
96fdf90aacd6atagen2026-09-08 08:24 UTC22
96fdf90aacd6atagen2026-09-08 08:24 UTC23
## Consuming the engine
96fdf90aacd6atagen2026-09-08 08:24 UTC24
31ce2453c82fatagen2026-09-24 13:07 UTC25
spawn `Engine::run`, drain the `EventStream` from its own task, and talk to the
31ce2453c82fatagen2026-09-24 13:07 UTC26
engine through `ClientHandle`. every command answers once, awaited
31ce2453c82fatagen2026-09-24 13:07 UTC27
(`handle.send_message(..).await?`) or as a `Pending` you can await later or
31ce2453c82fatagen2026-09-24 13:07 UTC28
drop. a sent message answers when the sdk send queue has it, delivery shows up
31ce2453c82fatagen2026-09-24 13:07 UTC29
as the timeline item's send state. reads like `rooms`, `members` and `media`
31ce2453c82fatagen2026-09-24 13:07 UTC30
go straight to the sdk. the stream only carries state
31ce2453c82fatagen2026-09-24 13:07 UTC31
b2b7e7479384atagen2026-09-26 09:40 UTC32
some commands put an event on the stream before they answer. `Open`, `Close`,
b2b7e7479384atagen2026-09-26 09:40 UTC33
`OpenThread`, `CloseThread`, `Resync`, `Paginate`, `Logout` and the
b2b7e7479384atagen2026-09-26 09:40 UTC34
verification actions all do. the stream is bounded, so a task that drains it
b2b7e7479384atagen2026-09-26 09:40 UTC35
and awaits one of those answers deadlocks once it fills. from the draining
b2b7e7479384atagen2026-09-26 09:40 UTC36
task, `try_send` the command and drop the `Pending`, the events tell you how it
b2b7e7479384atagen2026-09-26 09:40 UTC37
went
b2b7e7479384atagen2026-09-26 09:40 UTC38
d5d8097c3afdatagen2026-09-26 09:33 UTC39
start a timeline from `TimelineReset`, then apply each `TimelineChanged` whole
d5d8097c3afdatagen2026-09-26 09:33 UTC40
with `TimelineDiff::try_apply_all`. snapshots are `imbl::Vector`s, re-exported
d5d8097c3afdatagen2026-09-26 09:33 UTC41
as `macltok::imbl`, so a copy costs nothing. when a batch doesn't fit none of it
d5d8097c3afdatagen2026-09-26 09:33 UTC42
lands. stop applying, call `resync`, and pick up from the next `TimelineReset`
96fdf90aacd6atagen2026-09-08 08:24 UTC43
713205a95af2atagen2026-09-26 09:24 UTC44
with `sqlite` or `indexeddb`, a `SessionStore` holds one login's record and its
713205a95af2atagen2026-09-26 09:24 UTC45
store. `EncryptedSessionStore` seals the record with the store's passphrase, in a
713205a95af2atagen2026-09-26 09:24 UTC46
file you pick natively or an IndexedDB database beside the store in a browser.
713205a95af2atagen2026-09-26 09:24 UTC47
logging in saves the first record and `Session::restore` loads it. on every
713205a95af2atagen2026-09-26 09:24 UTC48
`SessionTokensChanged`, `save` a fresh `ClientHandle::session_record()` before
713205a95af2atagen2026-09-26 09:24 UTC49
the next refresh, refresh tokens only work once
fa9114fcf75fatagen2026-09-24 12:51 UTC50
fe4133dbcd47atagen2026-09-26 09:05 UTC51
`Engine::run` resolves to a `Termination` saying why it stopped, and
fe4133dbcd47atagen2026-09-26 09:05 UTC52
`Termination::retain` says what to do about it. after `LoggedOut` or
713205a95af2atagen2026-09-26 09:24 UTC53
`AccessRevoked` the record and the store are dead, `discard` them once the
713205a95af2atagen2026-09-26 09:24 UTC54
client is dropped, since an open store won't go quietly. `SoftLoggedOut` wants
6f1d6591c10datagen2026-09-26 09:52 UTC55
the store kept and a fresh login as the same device, or the e2ee keys go with
6f1d6591c10datagen2026-09-26 09:52 UTC56
it. `soft_log_out` swaps the record for one naming that device, so a restart
6f1d6591c10datagen2026-09-26 09:52 UTC57
gets `Restore::SoftLoggedOut` and `SoftLogout::password_login` rather than
6f1d6591c10datagen2026-09-26 09:52 UTC58
nothing, and the login overwrites it with a live record. `ShutDown` and
6f1d6591c10datagen2026-09-26 09:52 UTC59
`HandlesDropped` keep everything. an `Err` is a real failure and kills nothing.
6f1d6591c10datagen2026-09-26 09:52 UTC60
one store directory per login, the sdk won't share a crypto store between
6f1d6591c10datagen2026-09-26 09:52 UTC61
devices
96fdf90aacd6atagen2026-09-08 08:24 UTC62
62fe32759529atagen2026-09-26 08:50 UTC63
## wasm
62fe32759529atagen2026-09-26 08:50 UTC64
62fe32759529atagen2026-09-26 08:50 UTC65
macltok builds for `wasm32-unknown-unknown`. the `indexeddb` feature gives you
62fe32759529atagen2026-09-26 08:50 UTC66
`StoreConfig::indexeddb` in place of `StoreConfig::sqlite`, and asking for either
62fe32759529atagen2026-09-26 08:50 UTC67
on the wrong target won't compile. `Engine::run` hands back a `LocalBoxFuture`
62fe32759529atagen2026-09-26 08:50 UTC68
there, so spawn it with `wasm_bindgen_futures::spawn_local`
62fe32759529atagen2026-09-26 08:50 UTC69
62fe32759529atagen2026-09-26 08:50 UTC70
getrandom picks its browser backend from a cfg flag, and `.cargo/config.toml`
62fe32759529atagen2026-09-26 08:50 UTC71
only reaches this crate's own builds. every cdylib that pulls macltok in needs
62fe32759529atagen2026-09-26 08:50 UTC72
it too
62fe32759529atagen2026-09-26 08:50 UTC73
62fe32759529atagen2026-09-26 08:50 UTC74
```toml
62fe32759529atagen2026-09-26 08:50 UTC75
[target.wasm32-unknown-unknown]
62fe32759529atagen2026-09-26 08:50 UTC76
rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""]
62fe32759529atagen2026-09-26 08:50 UTC77
```
62fe32759529atagen2026-09-26 08:50 UTC78
62fe32759529atagen2026-09-26 08:50 UTC79
what's different in a browser
62fe32759529atagen2026-09-26 08:50 UTC80
62fe32759529atagen2026-09-26 08:50 UTC81
- a panic aborts the whole instance. natively a panicking command costs its
62fe32759529atagen2026-09-26 08:50 UTC82
  caller an `Interrupted`, here it takes the engine and everything else with it
62fe32759529atagen2026-09-26 08:50 UTC83
- `MediaUploadProgress` only ever reports completion, the sdk's wasm http path
62fe32759529atagen2026-09-26 08:50 UTC84
  has no upload progress
62fe32759529atagen2026-09-26 08:50 UTC85
- the sdk doesn't retry requests or time them out individually. sync still
62fe32759529atagen2026-09-26 08:50 UTC86
  restarts itself with backoff, that part is ours
62fe32759529atagen2026-09-26 08:50 UTC87
- two tabs or workers on one store each need `StoreConfig::with_lock_holder`
62fe32759529atagen2026-09-26 08:50 UTC88
  with a name of their own, or they both think they hold the crypto store
62fe32759529atagen2026-09-26 08:50 UTC89
96fdf90aacd6atagen2026-09-08 08:24 UTC90
## Dependency policy
96fdf90aacd6atagen2026-09-08 08:24 UTC91
96fdf90aacd6atagen2026-09-08 08:24 UTC92
UI frameworks, image decoders, application-directory discovery and logging
96fdf90aacd6atagen2026-09-08 08:24 UTC93
subscribers do not belong in this crate. SQLite remains optional through the
62fe32759529atagen2026-09-26 08:50 UTC94
`sqlite` and `bundled-sqlite` features, IndexedDB through `indexeddb`. Media
62fe32759529atagen2026-09-26 08:50 UTC95
decoding belongs to the consumer.
96fdf90aacd6atagen2026-09-08 08:24 UTC96
96fdf90aacd6atagen2026-09-08 08:24 UTC97
## Verification
96fdf90aacd6atagen2026-09-08 08:24 UTC98
96fdf90aacd6atagen2026-09-08 08:24 UTC99
```sh
96fdf90aacd6atagen2026-09-08 08:24 UTC100
nix develop --command cargo fmt -- --check
96fdf90aacd6atagen2026-09-08 08:24 UTC101
nix develop --command cargo test --all-targets
96fdf90aacd6atagen2026-09-08 08:24 UTC102
nix develop --command cargo test --all-targets --features sqlite
96fdf90aacd6atagen2026-09-08 08:24 UTC103
nix develop --command cargo clippy --all-targets -- -D warnings
96fdf90aacd6atagen2026-09-08 08:24 UTC104
nix develop --command cargo clippy --all-targets --features sqlite -- -D warnings
96fdf90aacd6atagen2026-09-08 08:24 UTC105
nix flake check
96fdf90aacd6atagen2026-09-08 08:24 UTC106
```