|
| 1 | +# Tandem demo: SEND side, compressed variant (Claude → Hermes). |
| 2 | +# |
| 3 | +# Uses omc_msg_sign_compressed instead of omc_msg_sign. Carries every-Nth |
| 4 | +# canonical token of the source plus the canonical hash for library lookup. |
| 5 | +# |
| 6 | +# Honest sizing finding (measured below): for SMALL single functions the |
| 7 | +# codec overhead (token array as JSON ints + extra metadata fields) exceeds |
| 8 | +# the sampling savings. The codec wins on LARGER payloads (~600B+) at N>=8. |
| 9 | +# The always-on win is library-lookup recovery itself: alpha-rename |
| 10 | +# invariant content-addressing on the receiver, no shared key. |
| 11 | +# |
| 12 | +# Run with: |
| 13 | +# ./target/release/omnimcode-standalone examples/demos/llm_tandem_send_compressed.omc |
| 14 | + |
| 15 | +fn show(label, v) { print(concat_many(label, " = ", to_string(v))); } |
| 16 | + |
| 17 | +fn measure(payload, n) { |
| 18 | + h baseline = omc_msg_sign(payload, 18173, 1); |
| 19 | + h baseline_wire = omc_msg_serialize(baseline); |
| 20 | + h baseline_size = str_len(baseline_wire); |
| 21 | + h comp = omc_msg_sign_compressed(payload, 18173, 1, n); |
| 22 | + h comp_wire = omc_msg_serialize(comp); |
| 23 | + h comp_size = str_len(comp_wire); |
| 24 | + print(concat_many( |
| 25 | + " src=", to_string(str_len(payload)), |
| 26 | + "B baseline=", to_string(baseline_size), |
| 27 | + "B comp(N=", to_string(n), ")=", to_string(comp_size), |
| 28 | + "B delta=", to_string(comp_size - baseline_size), "B" |
| 29 | + )); |
| 30 | +} |
| 31 | + |
| 32 | +fn main() { |
| 33 | + h CLAUDE_ID = 18173; |
| 34 | + h KIND_REQUEST = 1; |
| 35 | + h EVERY_N = 3; |
| 36 | + |
| 37 | + h payload = "fn compute_mean(xs) { h n = arr_len(xs); h s = 0.0; h i = 0; while i < n { s = s + arr_get(xs, i); i = i + 1; } return s / n; }"; |
| 38 | + |
| 39 | + h msg = omc_msg_sign_compressed(payload, CLAUDE_ID, KIND_REQUEST, EVERY_N); |
| 40 | + h wire = omc_msg_serialize(msg); |
| 41 | + |
| 42 | + show("packed ID ", dict_get(msg, "packed")); |
| 43 | + show("content_hash ", dict_get(msg, "content_hash")); |
| 44 | + show("attractor ", dict_get(msg, "attractor")); |
| 45 | + show("compression_ratio ", dict_get(msg, "compression_ratio")); |
| 46 | + print(""); |
| 47 | + print("compression_ratio is TOKEN-COUNT compression, not wire-byte."); |
| 48 | + print("Wire-byte break-even sweep (this payload + larger ones):"); |
| 49 | + measure(payload, 3); |
| 50 | + measure(payload, 5); |
| 51 | + h larger = concat_many(payload, "\n", |
| 52 | + "fn variance(xs) { h m = compute_mean(xs); h n = arr_len(xs); h s = 0.0; h i = 0; while i < n { h d = arr_get(xs, i) - m; s = s + d * d; i = i + 1; } return s / n; }", "\n", |
| 53 | + "fn std_dev(xs) { return sqrt(variance(xs)); }", "\n", |
| 54 | + "fn covariance(a, b) { h ma = compute_mean(a); h mb = compute_mean(b); h n = arr_len(a); h s = 0.0; h i = 0; while i < n { s = s + (arr_get(a, i) - ma) * (arr_get(b, i) - mb); i = i + 1; } return s / n; }"); |
| 55 | + measure(larger, 5); |
| 56 | + measure(larger, 8); |
| 57 | + |
| 58 | + write_file("/home/thearchitect/omc_channel/from_claude_compressed.json", wire); |
| 59 | + print(""); |
| 60 | + print("Wrote /home/thearchitect/omc_channel/from_claude_compressed.json"); |
| 61 | + print("(Single-fn payload — codec loses ~50%+ on wire bytes for this size."); |
| 62 | + print(" Real win: library-lookup recovery, demonstrated next.)"); |
| 63 | + print("Run llm_tandem_receive_compressed.omc to verify alpha-rename"); |
| 64 | + print("invariant recovery."); |
| 65 | +} |
| 66 | + |
| 67 | +main(); |
0 commit comments