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 = 1;
13
14/// Minimum proto a peer must advertise to accept the dialed `method`. `0` means
15/// always available (never gated). Add an entry per method introduced/changed.
16pub fn method_min_proto(method: &str) -> u32 {
17 match method {
18 "channel/delegate" => 1,
19 _ => 0,
20 }
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26
27 #[test]
28 fn short_sha_is_set() {
29 // Either a real 12-char hex sha, or the "unknown" fallback.
30 assert!(
31 SHORT_SHA == "unknown" || SHORT_SHA.len() == 12,
32 "got {SHORT_SHA:?}"
33 );
34 }
35
36 #[test]
37 fn method_min_proto_gates_channel_delegate_only() {
38 // channel/delegate requires the proto that introduced it.
39 assert_eq!(method_min_proto("channel/delegate"), 1);
40 // Always-available methods are ungated (min 0).
41 assert_eq!(method_min_proto("message/send"), 0);
42 assert_eq!(method_min_proto("agent/card"), 0);
43 // The current proto is at least the highest gated method.
44 assert!(A2A_PROTO_VERSION >= 1);
45 }
46}