Imported from ORESoftware/rx-gleam (
AGENTS.md). Install upstream withnpx skills add ORESoftware/rx-gleam. Copyright stays with the author.
Agent instructions
Architecture invariants
- Keep the public reactive runtime single-actor.
src/should contain exactly oneactor.newcall unless this document and the formal model are intentionally revised together. - Do not introduce hidden worker pools, schedulers, implicit child processes, per-operator actors, or blocking
process.receivecalls in library source. - Keep concurrency outside the Rx runtime. Adapt external work through
rx/effect.Effect,rx/future.Future, or another explicitly modeled nonblocking boundary. - Observer callbacks, diagnostics, Future start callbacks, producer setup, and projection functions must return promptly; blocking work belongs in application-owned concurrency.
- Subscription and flow registration must remain reentrant. A callback running on the runtime actor must be able to subscribe another stream on that same runtime without waiting for the actor to reply to itself.
runtime.stopmust tear down active subscriptions and cancel active async flows before the runtime actor exits.- Keep
Observable(value, error),Future(value, error), andEffect(value, error)fully typed. Do not erase public values or errors toDynamicfor implementation convenience. - Preserve the protocol grammar
Next* (Error | Complete)?.
State machines and formal methods
- Prefer explicit algebraic data types and exhaustive
caseexpressions over wildcard branches in protocol/state-machine code. - Any new stateful operator must define its transition states, terminal behavior, cancellation behavior, and error behavior before implementation.
- Add bounded exhaustive trace generation and differential/reference-model tests for every new state machine.
- Update
formal/RxProtocol.tla,formal/RxAsyncFlow.tla, or add a focused TLA+ module when observable protocol or concurrency semantics change. - Never describe a test run as a formal proof. Only claim TLC/model-checking evidence when TLC actually ran successfully.
sh conformance/check.sh --fullmust fail whenTLA2TOOLS_JARor Java is unavailable; it must never silently degrade to a non-formal gate.
Error handling
- Domain errors use the
errortype parameter. - Protocol/library defects use dedicated library error types and must not be silently converted into domain errors.
- A stopped runtime is reported as typed
RuntimeStopped; invalid flow concurrency isInvalidConcurrency. - Cancellation is not an error and must not fabricate
ErrororCompleteunless an operator's documented contract explicitly requires it. - Prefer total functions; avoid panic/assert in library code when an ordinary typed result can represent the condition.
Operator design
- Operators must compose without changing the single-actor serialization guarantee.
merge_map,concat_map,switch_map, andexhaust_mapshould share one internal flattening transition machine rather than drift into four independent implementations.- Every operator needs protocol-preservation, ordering, cancellation, resource-lifetime, reentrancy, composition, late-completion, and shutdown tests.
- Any operator that buffers input must document whether buffering is bounded or unbounded and where backpressure/load shedding belongs.
Tooling and quality gates
.zpkg.tomlis the zed-pkg package authority.manifest.tomlis the committed Gleam dependency lock and must not drift undergleam deps download.- Keep zed lifecycle hooks,
publish.smoke_test,.githooks/, andconformance/check.shaligned. - Before push, run
zed validateandsh conformance/check.sh --fullwithTLA2TOOLS_JARset. - Use
zed r2gbefore publishing a release so the pruned installed artifact is tested rather than only the source tree. - Keep the cookbook contract at exactly 20 executable recipes unless its tests/conformance contract is intentionally revised in the same change.
- Keep
docs/USE_CASES.mdat exactly 20 server-side use cases unless its conformance contract is intentionally revised in the same change; the first five anchor cases must retain executable integration tests. - CI must keep a declared-minimum Gleam compatibility job and a current-toolchain full Zed/TLC/conformance job, with third-party Actions pinned by commit SHA.