Skip to content

The Circuits

The machine as signal flow diagrams. For humans.

Each circuit is a mermaid graph definition. GitHub renders them natively.


Signals flow down (candle → thought → proposal). Outcomes flow back up (settlement → propagation → observers). The circuit is a loop. The fold is one tick of the clock.

graph TD
    subgraph Post [One per asset pair]
        RC[RawCandle] --> IB[IndicatorBank]
        IB --> CD[Candle]
        CD --> MO[MarketObserver x6]
        CD --> EO[ExitObserver x4]
        MO -->|thought Vector| EO
        EO -->|composed + distances| BR[Broker x24]
    end
    MO -.->|uses| VO[Vocabulary]
    MO -.->|uses| TE[ThoughtEncoder ctx]
    EO -.->|uses| VO
    EO -.->|uses| TE
    BR -->|Proposals| TR[Treasury]
    TR -->|TreasurySettlement| EN[Enterprise]
    EN -->|Settlement| Post
    Post -->|post-propagate| BR
    BR -->|Direction + thought + weight| MO
    BR -->|optimal Distances + composed + weight| EO
    TR -->|active trades| Post
    Post -->|new Levels| TR

Note: dashed arrows (-.->|uses|) show tools the observers call, not data flow. The observer calls Vocabulary for ASTs, then ThoughtEncoder for Vectors. Vocabulary and ThoughtEncoder are tools, not upstream producers.

Component legend:

NodeContainsProduces
IndicatorBankstreaming state (ring buffers, EMA accumulators)Candle (100+ indicators)
Vocabularypure functions, no stateVec<ThoughtAST> — data, not execution
ThoughtEncoderatoms (permanent dict) + compositions (LRU cache, eventually-consistent via returned misses)Vector from AST
MarketObserver ×Nlens (MarketLens), reckoner :discrete (Up/Down), noise-subspace, window-sampler, curve, engram gate(Vector, Prediction, edge, misses*)
ExitObserver ×Mlens (ExitLens), 4× reckoner :continuous (trail, stop, tp, runner-trail), default-distances(Distances, experience) via cascade + misses*
Broker ×N×Mreckoner :discrete (Grace/Violence), noise-subspace, curve, papers (deque), 4× scalar-accumulator, engram gatePrediction + edge()
Postindicator-bank, candle-window, market-observers, exit-observers, registryVec<Proposal> + Vec<Vector> + misses*
Treasuryavailable ◄──► reserved, trades, trade-origins, next-trade-idTreasurySettlement on settle
Enterpriseposts, treasury, market-thoughts-cache(Vec<LogEntry>, misses*) per candle

*misses = Vec<(ThoughtAST, Vector)> — cache misses returned as values, inserted by the binary between candles.

Edge legend — data flow (solid arrows):

From → ToTypeMethod
RC → IBRawCandletick(raw) → Candle
CD → MOCandle (via candle-window slice)observe-candle(window, ctx) → (Vector, Prediction, edge, misses)
CD → EOCandle (for exit facts)encode-exit-facts(candle) → Vec<ThoughtAST>
MO → EOVector (market thought)evaluate-and-compose(thought, fact-asts, ctx) → (Vector, misses)
EO → BRcomposed Vector + (Distances, experience)recommended-distances(composed, accums) → (Distances, f64)
BR → TRProposal (the barrage)submit-proposal(proposal)
TR → ENTreasurySettlementsettle-triggered(prices) → (Vec<TreasurySettlement>, Vec<LogEntry>)
EN → PostSettlement (enriched)post-propagate(post, slot-idx, thought, outcome, weight, direction, optimal)
Post → BRpropagation argsbroker.propagate(thought, outcome, weight, direction, optimal, observers)
BR → MODirection + thought + weightresolve(thought, direction, weight)
BR → EOoptimal Distances + composed + weightobserve-distances(composed, optimal, weight)
TR → Postactive trades for trigger updatetrades-for-post(post-idx) — step 3c
Post → TRnew Levelsupdate-trade-stops(trade-id, new-levels) — step 3c

Tool usage (dashed arrows):

ObserverToolPurpose
MO, EOVocabularyproduce Vec<ThoughtAST> from Candle
MO, EOThoughtEncoder (ctx)evaluate ASTs into Vectors

Pure. No learning. No state (except the ThoughtEncoder’s eventually-consistent cache). RawCandle in, Vector out.

graph TD
    RC[RawCandle] --> IB[IndicatorBank]
    IB -->|Candle| OBS[Observer selects lens]
    OBS -->|lens modules| VO[Vocabulary]
    VO -->|ThoughtASTs| OBS
    OBS -->|Bundle AST| TE[ThoughtEncoder]
    TE -->|Vector + misses| OUT[thought vector]

The observer selects which vocabulary modules fire (its lens). The vocabulary produces ASTs — data describing what to think. The observer wraps them in a Bundle. The encoder evaluates — computing the minimum work via cache. Atoms are permanent. Compositions are optimistic (LRU, eventually-consistent via returned misses).


The feedback loop. Where Grace and Violence shape the next prediction.

graph TD
    TH[thought] --> RK[Reckoner]
    RK -->|predict| PR[Prediction]
    PR --> ACT[action in world]
    ACT -->|outcome| OC[Grace or Violence]
    OC -->|observe| RK

The reckoner accumulates observations. The discriminant sharpens. The prediction improves. The loop is the learning. Each tick, the reckoner that predicted Grace gets stronger. The one that predicted Violence gets weaker.


The fast learning stream. Every candle. Every broker. No real capital.

graph TD
    CT[composed thought] --> REG[register paper]
    REG --> PE[PaperEntry in deque]
    PE -->|tick with price| CHK[check stops]
    CHK -->|resolved?| RES[Resolution]
    RES -->|propagate| MO[MarketObserver]
    RES -->|propagate| EO[ExitObserver]
    RES -->|propagate| BR[Broker self]

Papers play both sides (buy and sell) simultaneously. When a side’s trailing stop fires, the paper resolves. Direction: buy-side fires → :up, sell-side fires → :down. The resolution carries the optimal distances from hindsight. Papers are how the machine learns before it trades.


The capital lifecycle. Deploy, protect, recover, accumulate.

graph TD
    PR[Proposal] --> TR[Treasury evaluates]
    TR -->|fund| AV[available → reserved]
    AV --> TD[Trade :active]
    TD -->|safety-stop hit| SV[Settled :violence]
    SV --> RET1[principal - loss → available]
    TD -->|take-profit hit| PR2[PrincipalRecovered]
    PR2 --> RET2[principal → available]
    PR2 --> RN[Runner :runner]
    RN -->|runner-trail hit| SG[Settled :grace]
    SG --> RES[residue → available — permanent gain]
    TR -->|reject| DR[drained]

The treasury funds proven proposals. Capital moves from available to reserved. The trade is :active. Three trigger paths:

  • Safety-stop hit → :settled-violence. Principal minus loss returns. Bounded by the reservation.
  • Take-profit hit → :principal-recovered. Principal returns to available. Residue continues as a :runner with a wider trailing stop. Zero cost basis — house money.
  • Runner-trail hit → :settled-grace. Residue is permanent gain. Returns to available. The trade is done.

Three levels of distance knowledge. Specific to general.

graph TD
    Q[query distance] --> RK[Reckoner contextual]
    RK -->|experienced?| YES1[use reckoner answer]
    RK -->|inexperienced| SA[ScalarAccumulator global]
    SA -->|has data?| YES2[use accumulator answer]
    SA -->|empty| DEF[default crutch]

For each distance (trail, stop, tp, runner-trail): try the contextual answer first (reckoner — “for THIS thought, what distance?”). If inexperienced, try the global answer (scalar accumulator — “what does Grace prefer for this pair overall?”). If empty, use the crutch (the default value from construction).


The signal that teaches. Settlement → observers learn.

graph TD
    TS[TreasurySettlement] --> EN[Enterprise enriches]
    EN --> SET[Settlement]
    EN -->|slot-idx + thought + outcome + weight + direction + optimal| PP[post-propagate]
    PP --> BR[Broker]
    BR -->|Grace/Violence + thought + weight| BRK[broker reckoner]
    BR -->|Direction + thought + weight| MO[MarketObserver resolve]
    BR -->|optimal Distances + composed + weight| EO[ExitObserver observe-distances]
    BR -->|value + outcome + weight| SA[ScalarAccumulators]

The enterprise enriches a TreasurySettlement into a Settlement (derives direction, replays price-history via compute-optimal-distances). Routes to the post. The post calls broker.propagate. The broker fans out — weight on every edge, because a large Grace teaches harder than a marginal one: Grace/Violence to its own reckoner, Direction to the market observer, optimal Distances to the exit observer, scalar values to the accumulators. Everyone learns from one resolution.


The outer loop. The fold driver. Everything above happens INSIDE one call to on-candle. The binary is what calls it.

graph TD
    CLI[CLI args] --> BIN[Binary]
    BIN -->|construct| CTX[ctx — immutable world]
    BIN -->|construct| ENT[Enterprise — mutable state]
    DS[Data Source] -->|RawCandle stream| BIN
    BIN -->|on-candle raw ctx| ENT
    ENT -->|Vec LogEntry + cache misses| BIN
    BIN -->|insert misses| CTX
    BIN -->|flush logs| LED[Ledger — SQLite]
    BIN -->|progress| DISP[Display]
    KILL[trader-stop file] -.->|abort| BIN

The binary creates the world (ctx) and the machine (enterprise) from CLI arguments. It opens the data source — parquet or websocket. It feeds raw candles one at a time. It collects log entries and cache misses from each on-candle call. It inserts cache misses into ctx’s ThoughtEncoder between candles (the one seam). It flushes log entries to the ledger in batches. It displays progress. It checks the kill switch. When the stream ends, it prints the summary.

The binary does not think. It drives the fold and writes what happened.


The full enterprise is the composition of all sub-circuits. The encoding circuit feeds the learning circuit. The paper circuit is the learning circuit applied to hypotheticals. The funding circuit converts proposals into trades. The cascade circuit provides distances at every experience level. The propagation circuit closes the loop. The binary circuit wraps them all — it drives the fold and persists the results.

f(state, candle) → state — one tick of the clock. All circuits fire. The fold advances. Grace strengthens. Violence decays. The machine learns.