Skip to main content

mur_common/
build.rs

1//! Compile-time build identity. `SHORT_SHA` is the git commit the binary was
2//! built from (set by build.rs), or "unknown" for git-less builds (crates.io).
3//! Used to detect when a running agent's binary differs from the installed one.
4
5/// 12-char git sha of this build, or "unknown".
6pub const SHORT_SHA: &str = env!("MUR_GIT_SHA");
7
8/// A2A method-surface version. Bump ONLY on incompatible change to a dialed
9/// method (added method, changed params/result contract). Carried in
10/// `running.lock` AgentCard; dial refuses a method whose
11/// `method_min_proto` exceeds the peer's advertised proto.
12pub const A2A_PROTO_VERSION: u32 = 3;
13
14/// The first proto whose runtimes emit `turn/heartbeat` (spec 2026-09-12
15/// execution-limits ยง3.6). The dial gives such a peer a 90 s idle timeout.
16pub const HEARTBEAT_MIN_PROTO: u32 = 2;
17
18/// The first proto serving `hitl/list` and `hitl/forget` (#1806).
19pub const HITL_MEMORY_MIN_PROTO: u32 = 3;
20
21/// Minimum proto a peer must advertise to accept the dialed `method`. `0` means
22/// always available (never gated). Add an entry per method introduced/changed.
23pub fn method_min_proto(method: &str) -> u32 {
24    match method {
25        "channel/delegate" => 1,
26        crate::hitl::HITL_LIST_METHOD | crate::hitl::HITL_FORGET_METHOD => HITL_MEMORY_MIN_PROTO,
27        _ => 0,
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn short_sha_is_set() {
37        // Either a real 12-char hex sha, or the "unknown" fallback.
38        assert!(
39            SHORT_SHA == "unknown" || SHORT_SHA.len() == 12,
40            "got {SHORT_SHA:?}"
41        );
42    }
43
44    #[test]
45    fn method_min_proto_gates_channel_delegate_only() {
46        // channel/delegate requires the proto that introduced it.
47        assert_eq!(method_min_proto("channel/delegate"), 1);
48        // Always-available methods are ungated (min 0).
49        assert_eq!(method_min_proto("message/send"), 0);
50        assert_eq!(method_min_proto("agent/card"), 0);
51        assert_eq!(method_min_proto("hitl/forget"), HITL_MEMORY_MIN_PROTO);
52        const { assert!(A2A_PROTO_VERSION >= HITL_MEMORY_MIN_PROTO) };
53        // The current proto is at least the highest gated method.
54        const { assert!(A2A_PROTO_VERSION >= 1) };
55    }
56}