open-standards/joule-code/examples/l3-jouleclaw
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Transaction Science df42af5c22
All checks were successful
standards workspaces build + test / jouleclaw-rs (pull_request) Successful in 2m10s
standards workspaces build + test / aac-rs (pull_request) Successful in 39s
standards workspaces build + test / joule-code-rs (pull_request) Successful in 44s
standards workspaces build + test / joulecontract-rs (pull_request) Successful in 36s
standards workspaces build + test / map-rs (pull_request) Successful in 31s
standards workspaces build + test / mesh-rs (pull_request) Successful in 25s
standards workspaces build + test / openpay (pull_request) Successful in 1m23s
joule-code conformance gate / Build + round-trip C1-C4 vectors (pull_request) Successful in 1m29s
jouleclaw public surface must stay documented / Public-surface audit (jouleclaw-rs) (pull_request) Successful in 1m1s
standards workspaces build + test / eoc-rs (pull_request) Successful in 1m47s
standards workspaces build + test / jcp-rs (pull_request) Successful in 1m17s
standards workspaces build + test / proof-rs (pull_request) Successful in 1m16s
standards workspaces build + test / sandbox-rs (pull_request) Successful in 2m9s
standards workspaces build + test / smart-byte-rs (pull_request) Successful in 2m35s
standards workspaces build + test / arl-rs (pull_request) Successful in 2m17s
standards workspaces build + test / joule-ui-rs (pull_request) Successful in 2m49s
standards workspaces build + test / jouledesk-rs (pull_request) Successful in 4m29s
standards workspaces build + test / joulehook-rs (pull_request) Successful in 2m44s
standards workspaces build + test / sense-rs (pull_request) Successful in 2m47s
standards workspaces build + test / macOS energy backend (jcp-energy) (pull_request) Successful in 2m22s
jouleclaw-harness-econ: an in-process decode is metered by the process counter, and only that work
`detect_in_process_meter` is for work that runs on this process's own threads.
Each caller that meters model work was checked against that, and adopted it
only where it holds.

- jouleclaw-harness-econ: `local_model_econ`, `swebench_local_coder` and
  `swebench_local_suite` meter a decode that runs in this process, on the
  loader's CPU kernels and rayon pool; the examples build the loader with
  `rayon` only, without its GPU `fabric`, and the metered window is the decode
  alone (the `python3` judge, a subprocess, runs outside it). They now use the
  in-process meter, so on macOS 27.0.1, where the host meter is the load-average
  estimator, a dispatch is a live hardware reading of its own CPU energy.
  `window_joules` already refuses a window the counter did not advance across.
  `meter_probe` reports both meters. Run here on a host under load average ~50:
  the host meter was the estimator (115.6 J over 2.89 s, Estimator, SocTotal),
  the in-process meter process-cpu (2.397 J over 2.84 s, HwShunt, ProcessCpu)
  for the same one-thread spin.
- jouledesk-github stays on `detect_meter`: its model runs in a
  `llama-completion` subprocess, which a per-process counter would bill
  nothing. Its docs say so, and a test pins the meter to the host meter.
- l3-jouleclaw's `run` binary stays on the host counter, and says why: `llama`
  is a subprocess, and the in-process `jouleclaw-runtime` engine boots the Apple
  backend's GPU kernels (Metal and MPS matmuls, the quantized GEMVs that serve
  decode), whose energy is the GPU's.
- jouleclaw-loader-gguf is unchanged: its metered paths (`tune_shape_live`,
  `fabric_calibrate`, `mpp_energy`) compare or calibrate GPU against CPU
  members, so they need the whole SoC, not one process's CPU.

Ran: `cargo test -p jouleclaw-harness-econ`, `cargo check` of its examples,
`cargo test -p jouledesk-github` (13 passed), and `cargo test` in
l3-jouleclaw. No model was loaded; the examples' model runs were not repeated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-30 22:21:00 -04:00
..
src jouleclaw-harness-econ: an in-process decode is metered by the process counter, and only that work 2026-09-30 22:21:00 -04:00
tests l3-jouleclaw: a fabric-priced projection is graded by its weakest input 2026-09-30 20:48:47 -04:00
Cargo.lock l3-jouleclaw: a fabric-priced projection is graded by its weakest input 2026-09-30 20:48:47 -04:00
Cargo.toml l3-jouleclaw: a fabric-priced projection is graded by its weakest input 2026-09-30 20:48:47 -04:00
README.md jouleclaw-energy: a live IOReport reading is a hardware reading, and only a live one 2026-09-30 20:17:13 -04:00

L3 binding — JouleClaw model tier → Joule Code cascade

A consumer binding example: how to wire JouleClaw's L3 (Model) tier into the Joule Code cascade. It is a standalone workspace, so the standard's reference library keeps no JouleClaw dependency.

A coding request that misses the cheaper tiers (L0 cache, L1 lawful, L2 embed) is generated by a local model at L3, producing a content-addressed CodingOp and a joules-class Receipt.

Three backends, same slot

All implement JouleClaw's jouleclaw_llm_cheap::LlmBackend, so they drop into the same cascade stage:

  • EchoBackend (from JouleClaw) — deterministic, model-free; used by the unit tests so the wiring is verifiable with no model present.
  • JouleclawRuntimeBackend (here) — runs the model in-process on JouleClaw's own from-scratch GGUF tensor runtime (jouleclaw-runtime): no external binary, no FFI. Tokenize → build the decode-step graph → compile against the registered kernels (jouleclaw-backend-reference / -apple) → autoregressive decode → detokenize, all in Rust the family wrote. This is the default backend for the run binary.
  • LlamaCompletionBackend (here) — drives a real on-device GGUF via llama-completion (llama.cpp). Set JOULE_CODE_L3_ENGINE=llama to use it.

Either local path: no datacenter, no network. In production the cheapest capable backend is chosen by jouleclaw_dispatch::ModelBank's cost table.

Run it against a local model

# Default: in-process on jouleclaw-runtime (the from-scratch tensor engine).
cargo run --release --bin run -- /path/to/model.gguf "Write a Rust function that reverses a string."
# or: JOULE_CODE_L3_MODEL=/path/to/model.gguf cargo run --release --bin run

# Use the llama.cpp shell-out backend instead:
JOULE_CODE_L3_ENGINE=llama cargo run --release --bin run -- /path/to/model.gguf "..."

The run binary generates with the local model, content-addresses the result as a CodingOp (tier L3), and puts the host energy spent during the inference on the receipt, tagged with the provenance of whatever metered it:

  • Apple Silicon whose IOReport CPU energy rail is live — JouleClaw's IOReport counter, a live vendor energy counter: a real local measurement, tagged HwShunt (with measured_uj set).
  • Apple Silicon whose CPU rail is not live — macOS 27.0.1 for an unprivileged process, observed on an M5 Max and an M3 Ultra — JouleClaw's load-average estimator, tagged Estimator. Not a measurement.
  • Anywhere else, Linux and Windows included — the token-count estimate, tagged Estimator. This binding builds jouleclaw-energy with the ioreport feature only, so it reads no RAPL or NVML counter even where one exists.

The printout names the meter that ran and the IOReport status, and says whether the figure was measured or estimated.

Verified live: the llama.cpp path against a local 350M GGUF, and the in-process from-scratch runtime against ternary-bonsai-1.7b-q2_0 (qwen3, Q2_0) — real text generated, a real op_id, the cascade closing at L3.

Tests

cargo test   # EchoBackend path — no model required

# In-process from-scratch runtime against a real GGUF (opt-in):
JOULE_BONSAI=/path/to/ternary-bonsai-1.7b-q2_0.gguf \
  cargo test --release --test runtime_l3 -- --ignored --nocapture