Skip to main content

sim_codec_bridge/
lib.rs

1//! BRIDGE packet line codec for SIM.
2//!
3//! This crate provides `codec:bridge`, the strict reversible text face for one
4//! BRIDGE packet per frame. BRIDGE is a single packet protocol for exchanges
5//! between SIM, humans, and models; this crate owns the packet *record model* and
6//! its codec, and nothing that runs, sends, or repairs a packet (that is
7//! `sim-lib-bridge`).
8//!
9//! # The packet
10//!
11//! ```text
12//! BridgePacket
13//!   header    move, from, to, role, parents, task, output, ceiling, provenance
14//!   body      an ordered list of typed parts (a closed part book):
15//!             Given Frame Call Weave Check Evidence Review Vote Patch
16//!             Fetch Return Receipt Attest
17//!   warrant   content ids of the books/specs the packet was built against
18//! ```
19//!
20//! BRIEF, ASK, LOOM, and COLLAB are not separate protocols -- they are
21//! `BridgeProfileSpec` shapes over the body (frame-led, call-led, weave-led, and
22//! review/vote/patch-led). A packet body must derive exactly one profile; there
23//! is one codec and one checker for all four (`standard_profile_book`).
24//!
25//! # What this crate guarantees
26//!
27//! - **Reversible identity.** `packet_content_id` / `stamp_packet_cid` /
28//!   `verify_packet_cid` give a packet a content-addressed cid, and
29//!   `assert_roundtrip` proves the line form (`encode_bridge_text` /
30//!   `decode_bridge_text`) decodes back to the identical record.
31//! - **Move, profile, and part legality.** `BridgeBook::validate_packet` checks
32//!   every packet before text decode or expression encode returns canonical
33//!   data. `BridgeMoveBook` / `standard_move_book` say which move may answer
34//!   which explicit parent `#move=<intent>` evidence (a `vote` may not answer a
35//!   `request`); `BridgeProfileBook` / `standard_profile_book` require BRIEF,
36//!   ASK, LOOM, or COLLAB to be the single body match; and
37//!   `BridgePartBook` / `standard_part_book` say which typed parts are legal and
38//!   whether an unknown part is rejected or preserved as inert data
39//!   (`UnknownPolicy`, `AuthorityClass`).
40//! - **Total text ownership.** `assert_total_ownership` proves every rendered byte
41//!   a model sees belongs to a structural token, a frame sentence
42//!   (`render_frame_part`), a part line, or a nonce-fenced datum -- there is no
43//!   free-prose channel for a hidden instruction. A `Frame` renders both a checked
44//!   record and a fluent cited sentence.
45//! - **Warrants.** `warrant_for_packet` records the move/frame/part-spec content
46//!   ids so a receiver can validate a packet against its *own* books across a
47//!   trust or version boundary. The standard codec accepts missing warrants
48//!   under shared trust; a book configured with `BridgeWarrantPolicy::Verify`
49//!   requires and checks a matching warrant.
50//!
51//! The runtime side -- send/receive checking, capability ceilings, model
52//! requests, the frontier engine, and the profile helpers -- lives in
53//! `sim-lib-bridge`; the human review surface lives in `sim-lib-view-bridge`.
54
55#![forbid(unsafe_code)]
56#![deny(missing_docs)]
57
58mod call;
59mod canonical;
60mod collab;
61mod frame_book;
62mod frame_render;
63mod identity;
64mod line;
65mod move_book;
66mod ownership;
67mod packet;
68mod part_book;
69mod profile;
70mod render;
71mod shape;
72mod warrant;
73mod weave;
74
75#[cfg(test)]
76mod tests;
77#[cfg(test)]
78mod validation_tests;
79
80pub use call::{BridgeCallArgument, BridgeCallPayload, CallArgumentMedia, validate_call_payload};
81pub use canonical::{BridgeCodec, BridgeCodecLib};
82pub use collab::{
83    BridgeAttestPayload, BridgeEvidencePayload, BridgePatchPayload, BridgeReceiptPayload,
84    BridgeReviewPayload, BridgeScore, BridgeVotePayload, validate_collab_payload,
85};
86pub use frame_book::{
87    BridgeFrameBook, BridgeFramePayload, FrameHoleKind, FrameHoleSpec, FrameKind, FrameSpec,
88    standard_frame_book,
89};
90pub use frame_render::{render_frame, render_frame_with_prose};
91pub use identity::{
92    canonical_packet_datum, content_id_string, packet_content_id, stamp_packet_cid,
93    verify_packet_cid,
94};
95pub use line::{decode_bridge_text, decode_bridge_text_with_limits, encode_bridge_text};
96pub use move_book::{BridgeMoveBook, BridgeMoveSpec, ReplyRule, standard_move_book};
97pub use ownership::{OwnedSpan, assert_roundtrip, assert_total_ownership};
98pub use packet::{
99    BridgeHeader, BridgePacket, BridgePart, BridgeProvenance, expr_to_packet, packet_to_expr,
100};
101pub use part_book::{
102    AuthorityClass, BridgeBook, BridgePartBook, BridgePartSpec, RenderClass, UnknownPolicy,
103    standard_part_book,
104};
105pub use profile::{
106    BridgeProfileBook, BridgeProfileSpec, ProfilePartCount, ProfilePartRule, ask_profile_spec,
107    ask_profile_symbol, bridge_profile_shape_expr, brief_profile_spec, brief_profile_symbol,
108    collab_profile_spec, collab_profile_symbol, loom_profile_spec, loom_profile_symbol,
109    standard_profile_book,
110};
111pub use render::{render_frame_part, render_frame_part_with_prose};
112pub use shape::bridge_packet_shape_symbol;
113pub use warrant::{
114    BridgeWarrant, BridgeWarrantPolicy, frame_book_content_id, move_book_content_id,
115    part_spec_content_id, warrant_for_packet,
116};
117pub use weave::{
118    BridgeWeavePayload, BridgeWeaveRow, WeavePart, derive_weave_result_shape,
119    validate_weave_payload,
120};
121
122/// Cookbook recipes for this codec, embedded at build time.
123pub static RECIPES: sim_cookbook::EmbeddedDir =
124    include!(concat!(env!("OUT_DIR"), "/cookbook_recipes.rs"));