1use crate::companion::{Formality, Relationship};
5use crate::deps::ProgramDep;
6use serde::{Deserialize, Serialize};
7use std::collections::BTreeMap;
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
15pub struct SkillCardEntry {
16 pub name: String,
17 #[serde(default, skip_serializing_if = "String::is_empty")]
18 pub version: String,
19 #[serde(default, skip_serializing_if = "String::is_empty")]
20 pub publisher: String,
21 #[serde(default, skip_serializing_if = "String::is_empty")]
22 pub description: String,
23 #[serde(default, skip_serializing_if = "String::is_empty")]
24 pub category: String,
25 #[serde(default, skip_serializing_if = "Vec::is_empty")]
26 pub tags: Vec<String>,
27 #[serde(default, skip_serializing_if = "Vec::is_empty")]
28 pub triggers: Vec<SkillCardTrigger>,
29 #[serde(default, skip_serializing_if = "String::is_empty", rename = "abstract")]
32 pub abstract_text: String,
33 #[serde(default, skip_serializing_if = "Vec::is_empty")]
36 pub transfer_chain: Vec<String>,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
40pub struct SkillCardTrigger {
41 #[serde(rename = "type")]
42 pub kind: String,
43 #[serde(default, skip_serializing_if = "String::is_empty")]
44 pub pattern: String,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
48pub struct AgentProfile {
49 pub schema: u32,
50 pub id: String, pub name: String,
52 pub display_name: String,
53 #[serde(default, skip_serializing_if = "Option::is_none")]
61 pub role: Option<String>,
62 #[serde(default, skip_serializing_if = "Option::is_none")]
72 pub effort: Option<crate::llm::Effort>,
73 pub version: String,
74 pub persona: Persona,
75 pub sys_prompt_file: String,
76 pub model: ModelConfig,
77 #[serde(default, skip_serializing_if = "Option::is_none")]
80 pub model_ref: Option<String>,
81 #[serde(default, skip_serializing_if = "Vec::is_empty")]
84 pub fallback_chain: Vec<String>,
85 #[serde(default, skip_serializing_if = "Option::is_none")]
88 pub routing: Option<crate::config::RoutingConfig>,
89 #[serde(default)]
90 pub mcp_servers: Vec<McpServerEntry>,
91 #[serde(default)]
92 pub skills: Vec<String>,
93 #[serde(default, skip_serializing_if = "Vec::is_empty")]
97 pub installed_skills: Vec<SkillCardEntry>,
98 #[serde(default, skip_serializing_if = "Vec::is_empty")]
103 pub disabled_skills: Vec<String>,
104
105 #[serde(default, skip_serializing_if = "Vec::is_empty")]
109 pub disabled_mcp: Vec<String>,
110 #[serde(default, skip_serializing_if = "Vec::is_empty")]
114 pub addons: Vec<AddonRef>,
115 pub transport: TransportConfig,
116 pub communication: CommunicationConfig,
117 #[serde(default)]
118 pub capabilities: Vec<String>,
119 pub entitlements: Entitlements,
120 #[serde(default)]
121 pub notifications: NotificationsConfig,
122 pub retry: RetryConfig,
123 pub lifecycle: LifecycleConfig,
124 #[serde(default)]
127 pub identity: IdentityConfig,
128 #[serde(default)]
129 pub file_transfer: FileTransferConfig,
130 #[serde(default)]
131 pub deployment: DeploymentConfig,
132 #[serde(default)]
135 pub companion: CompanionConfig,
136 #[serde(default)]
138 pub hitl: HitlConfig,
139 #[serde(default)]
141 pub voice: VoiceConfig,
142 #[serde(default)]
144 pub hooks: crate::HooksConfig,
145 #[serde(default)]
148 pub trusted_peers: Vec<crate::bridge::peer::TrustedPeer>,
149 pub created_at: String,
150 pub updated_at: String,
151 #[serde(default)]
153 pub appearance: AgentAppearance,
154 #[serde(default)]
156 pub federation: FederationConfig,
157
158 #[serde(default)]
162 pub file_actions: Vec<crate::action::FileAction>,
163
164 #[serde(default)]
166 pub action_pipeline: crate::action::ActionPipelineConfig,
167
168 #[serde(default, skip_serializing_if = "Vec::is_empty")]
171 pub requires_programs: Vec<ProgramDep>,
172
173 #[serde(default, skip_serializing_if = "Vec::is_empty")]
176 pub requires_capabilities: Vec<String>,
177}
178
179fn default_algorithm() -> String {
180 "ed25519".into()
181}
182
183pub const SUPPORTED_ALGORITHMS: &[&str] = &["ed25519"];
185
186#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
187pub struct IdentityConfig {
188 #[serde(default)]
191 pub pubkey: String,
192 #[serde(default, skip_serializing_if = "Option::is_none")]
194 pub owner: Option<String>,
195
196 #[serde(default = "default_algorithm")]
199 pub algorithm: String,
200 #[serde(default)]
202 pub key_version: u32,
203 #[serde(default, skip_serializing_if = "Option::is_none")]
205 pub created_at_key: Option<String>,
206 #[serde(default, skip_serializing_if = "Option::is_none")]
208 pub previous_pubkey: Option<String>,
209 #[serde(default, skip_serializing_if = "Option::is_none")]
211 pub previous_key_version: Option<u32>,
212 #[serde(default, skip_serializing_if = "Option::is_none")]
215 pub grace_expires_at: Option<String>,
216 #[serde(default, skip_serializing_if = "Option::is_none")]
218 pub rotated_at: Option<String>,
219 #[serde(default, skip_serializing_if = "Option::is_none")]
221 pub emergency_rekey_at: Option<String>,
222}
223
224impl Default for IdentityConfig {
225 fn default() -> Self {
226 Self {
227 pubkey: String::new(),
228 owner: None,
229 algorithm: default_algorithm(),
230 key_version: 0,
231 created_at_key: None,
232 previous_pubkey: None,
233 previous_key_version: None,
234 grace_expires_at: None,
235 rotated_at: None,
236 emergency_rekey_at: None,
237 }
238 }
239}
240
241#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
242pub struct Persona {
243 pub category: PersonaCategory,
244 pub description: String,
245 pub traits: PersonaTraits,
246}
247
248#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
249#[serde(rename_all = "lowercase")]
250pub enum PersonaCategory {
251 Research,
252 Automation,
253 Monitor,
254 Notify,
255 Commerce,
256 Custom,
257}
258
259#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
260pub struct PersonaTraits {
261 pub tone: String,
262 pub risk: String,
263 pub verbosity: String,
264}
265
266#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
267pub struct ModelConfig {
268 pub provider: String,
269 pub name: String,
270 #[serde(default)]
271 pub params: BTreeMap<String, serde_yaml_ng::Value>,
272}
273
274#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
275pub struct McpServerEntry {
276 pub name: String,
277 pub command: String,
278 #[serde(default)]
279 pub args: Vec<String>,
280
281 #[serde(default, skip_serializing_if = "Option::is_none")]
287 pub binary_sha256: Option<String>,
288
289 #[serde(default, skip_serializing_if = "Option::is_none")]
295 pub description_hash: Option<String>,
296
297 #[serde(default, skip_serializing_if = "Option::is_none")]
301 pub publisher: Option<McpPublisherInfo>,
302
303 #[serde(default, skip_serializing_if = "Option::is_none")]
307 pub installed_at: Option<chrono::DateTime<chrono::Utc>>,
308
309 #[serde(default, skip_serializing_if = "Option::is_none")]
313 pub timeout_secs: Option<u32>,
314
315 #[serde(default, skip_serializing_if = "Option::is_none")]
320 pub network: Option<McpServerNetwork>,
321
322 #[serde(default, skip_serializing_if = "Option::is_none")]
325 pub url: Option<String>,
326
327 #[serde(default, skip_serializing_if = "Option::is_none")]
330 pub auth: Option<McpAuth>,
331
332 #[serde(default, skip_serializing_if = "Vec::is_empty")]
335 pub requires_programs: Vec<ProgramDep>,
336
337 #[serde(default, skip_serializing_if = "Option::is_none")]
345 pub package: Option<McpPackagePin>,
346}
347
348#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
361pub struct McpPackagePin {
362 pub runner: String,
364 pub name: String,
366 pub version: String,
368 pub install_dir: String,
370 pub lockfile_sha256: String,
372
373 #[serde(default, skip_serializing_if = "Option::is_none")]
385 pub signatures_missing: Option<u32>,
386
387 #[serde(default, skip_serializing_if = "Option::is_none")]
397 pub provenance: Option<String>,
398}
399
400impl McpPackagePin {
401 pub fn lockfile_name(&self) -> &'static str {
408 match self.runner.as_str() {
409 "pypi" => "requirements.lock",
410 _ => "package-lock.json",
411 }
412 }
413
414 pub fn lockfile_path(&self) -> std::path::PathBuf {
420 std::path::Path::new(&self.install_dir).join(self.lockfile_name())
421 }
422}
423
424#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
426#[serde(rename_all = "snake_case", tag = "kind")]
427pub enum McpAuth {
428 Bearer { token: crate::secret::SecretRef },
430 Oauth(OauthAuth),
432}
433
434#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
436pub struct OauthAuth {
437 pub token_endpoint: String,
439 pub client_id: String,
441 pub access_token: crate::secret::SecretRef,
443 #[serde(default, skip_serializing_if = "Option::is_none")]
445 pub refresh_token: Option<crate::secret::SecretRef>,
446 #[serde(default)]
448 pub expires_at: u64,
449}
450
451#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
453#[serde(rename_all = "snake_case")]
454pub enum McpNetMode {
455 #[default]
469 Inherit,
470 Restricted,
472 BroadAudited,
478 Off,
480}
481
482pub const ENV_MCP_DENY_HOSTS: &str = "MUR_RESEARCH_DENY_HOSTS";
491
492#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
494pub struct McpServerNetwork {
495 #[serde(default)]
496 pub mode: McpNetMode,
497 #[serde(default)]
498 pub allow_hosts: Vec<String>,
499 #[serde(default)]
502 pub deny_hosts: Vec<String>,
503 #[serde(default, skip_serializing_if = "Option::is_none")]
505 pub authorization: Option<EgressAuthorization>,
506}
507
508#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
517pub struct AddonRef {
518 pub id: String,
520 pub source: String,
522 #[serde(default)]
523 pub enabled: bool,
524 #[serde(default, skip_serializing_if = "Vec::is_empty")]
525 pub skills: Vec<String>,
526 #[serde(default, skip_serializing_if = "Vec::is_empty")]
527 pub mcp: Vec<String>,
528 #[serde(default, skip_serializing_if = "Vec::is_empty")]
529 pub commands: Vec<String>,
530 #[serde(default, skip_serializing_if = "Option::is_none")]
533 pub content_hash: Option<String>,
534 #[serde(default, skip_serializing_if = "Option::is_none")]
538 pub fetch_ref: Option<String>,
539 #[serde(default, skip_serializing_if = "Option::is_none")]
544 pub fetch_plugin: Option<String>,
545}
546
547#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
553pub struct McpPublisherInfo {
554 pub name: String,
557
558 #[serde(default, skip_serializing_if = "Option::is_none")]
562 pub homepage: Option<String>,
563
564 #[serde(default, skip_serializing_if = "Option::is_none")]
567 pub registry_id: Option<String>,
568}
569
570#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
571pub struct TransportConfig {
572 pub stdio: bool,
573 pub socket: SocketTransportConfig,
574 #[serde(default)]
575 pub tcp: TcpTransportConfig,
576 #[serde(default)]
580 pub webhook: WebhookTransportConfig,
581}
582
583#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
584pub struct TcpTransportConfig {
585 #[serde(default)]
586 pub enabled: bool,
587 #[serde(default)]
588 pub bind: String,
589 #[serde(default)]
590 pub noise: NoiseConfig,
591}
592
593#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
607pub struct WebhookTransportConfig {
608 #[serde(default)]
609 pub enabled: bool,
610 #[serde(default = "default_webhook_bind")]
611 pub bind: String,
612 #[serde(default = "default_webhook_port")]
613 pub port: u16,
614 #[serde(default)]
618 pub hmac_secret_ref: String,
619}
620
621fn default_webhook_bind() -> String {
622 "127.0.0.1".to_string()
623}
624
625fn default_webhook_port() -> u16 {
626 6789
627}
628
629impl Default for WebhookTransportConfig {
630 fn default() -> Self {
631 Self {
632 enabled: false,
633 bind: default_webhook_bind(),
634 port: default_webhook_port(),
635 hmac_secret_ref: String::new(),
636 }
637 }
638}
639
640#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
641pub struct NoiseConfig {
642 pub pattern: String,
643}
644
645impl Default for NoiseConfig {
646 fn default() -> Self {
647 Self {
648 pattern: "Noise_XK_25519_ChaChaPoly_BLAKE2s".into(),
649 }
650 }
651}
652
653#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
654pub struct SocketTransportConfig {
655 pub enabled: bool,
656 pub bind: String, #[serde(default, skip_serializing_if = "Option::is_none")]
658 pub auth: Option<AuthConfig>,
659}
660
661#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
662pub struct AuthConfig {
663 pub scheme: String,
664 pub token_file: String,
665}
666
667#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
668pub struct CommunicationConfig {
669 #[serde(default = "default_accepts_all")]
670 pub accepts_from: Vec<String>,
671 #[serde(default)]
672 pub sends_to: Vec<String>,
673}
674fn default_accepts_all() -> Vec<String> {
675 vec!["*".to_string()]
676}
677
678#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
679pub struct Entitlements {
680 pub network: NetworkEntitlement,
681 pub filesystem: FilesystemEntitlement,
682 pub processes: ProcessesEntitlement,
683 #[serde(default)]
684 pub syscalls: SyscallsEntitlement,
685 #[serde(default)]
686 pub limits: LimitsEntitlement,
687 #[serde(default)]
690 pub llm: crate::bridge::llm_entitlement::LlmEntitlement,
691 #[serde(default, skip_serializing_if = "Vec::is_empty")]
693 pub tools: Vec<ToolRule>,
694 #[serde(default = "default_true")]
699 pub fail_closed_on_sandbox_error: bool,
700}
701
702#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
703pub struct NetworkEntitlement {
704 pub inbound: InboundNetwork,
705 pub outbound: OutboundNetwork,
706}
707
708#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
709pub struct InboundNetwork {
710 #[serde(default)]
711 pub ports: Vec<u16>,
712}
713
714#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
715pub struct OutboundNetwork {
716 pub mode: NetworkOutboundMode,
717 #[serde(default)]
718 pub allow_hosts: Vec<String>,
719 #[serde(default = "default_protocols")]
720 pub protocols: Vec<String>,
721 #[serde(default)]
722 pub resolve_dns: ResolveDnsConfig,
723}
724fn default_protocols() -> Vec<String> {
725 vec!["tcp".to_string()]
726}
727
728#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
732pub struct EgressAuthorization {
733 pub authorized_by: String,
734 pub authorized_at_ms: u64,
735}
736
737#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
738#[serde(rename_all = "lowercase")]
739pub enum NetworkOutboundMode {
740 Unrestricted,
741 Restricted,
742 ProxyOnly,
746 Off,
747}
748
749#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
750pub struct ResolveDnsConfig {
751 #[serde(default = "default_dns_mode")]
752 pub mode: String,
753 #[serde(default)]
754 pub servers: Vec<String>,
755}
756impl Default for ResolveDnsConfig {
757 fn default() -> Self {
758 Self {
759 mode: default_dns_mode(),
760 servers: vec![],
761 }
762 }
763}
764fn default_dns_mode() -> String {
765 "system".to_string()
766}
767
768pub const AUTHORING_DIRS: [&str; 4] = ["skills", "workflows", "fleets", "artifacts"];
779
780#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
781pub struct FilesystemEntitlement {
782 #[serde(default)]
783 pub read: Vec<String>,
784 #[serde(default)]
785 pub write: Vec<String>,
786 #[serde(default)]
787 pub deny: Vec<String>,
788}
789
790#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
791pub struct ProcessesEntitlement {
792 pub spawn: SpawnEntitlement,
793}
794
795#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
796pub struct SpawnEntitlement {
797 pub mode: SpawnMode,
798 #[serde(default)]
799 pub allowed: Vec<String>,
800 #[serde(default)]
815 pub allowed_dirs: Vec<String>,
816}
817
818#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
819#[serde(rename_all = "lowercase")]
820pub enum SpawnMode {
821 Allowlist,
822 Any,
823 None,
824 Strict,
830}
831
832#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
833pub struct SyscallsEntitlement {
834 #[serde(default = "default_syscalls_mode")]
835 pub mode: String,
836 #[serde(default)]
837 pub extra_deny: Vec<String>,
838}
839fn default_syscalls_mode() -> String {
840 "default".to_string()
841}
842
843#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
844pub struct LimitsEntitlement {
845 #[serde(default)]
846 pub cpu_seconds: Option<u64>,
847 #[serde(default = "default_memory_mb")]
848 pub memory_mb: u64,
849 #[serde(default = "default_fds")]
850 pub file_descriptors: u32,
851 #[serde(default = "default_procs")]
852 pub processes: u32,
853}
854fn default_memory_mb() -> u64 {
855 512
856}
857fn default_fds() -> u32 {
858 1024
859}
860fn default_procs() -> u32 {
861 32
862}
863
864#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
865#[serde(rename_all = "lowercase")]
866pub enum ToolPolicy {
867 Allow,
868 #[default]
869 Ask,
870 Deny,
871}
872
873#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
874pub struct ToolRule {
875 pub pattern: String,
876 pub policy: ToolPolicy,
877 #[serde(default, skip_serializing_if = "Option::is_none")]
880 pub risk: Option<crate::hitl::RiskTier>,
881}
882
883pub fn resolve_tool_policy(rules: &[ToolRule], tool_name: &str) -> ToolPolicy {
887 resolve_tool_policy_opt(rules, tool_name).unwrap_or_default()
888}
889
890pub fn resolve_tool_policy_opt(rules: &[ToolRule], tool_name: &str) -> Option<ToolPolicy> {
895 for rule in rules {
896 if rule.pattern == tool_name {
897 return Some(rule.policy);
898 }
899 }
900 let mut best: Option<(&ToolRule, usize)> = None;
901 for rule in rules {
902 if let Some(prefix) = rule.pattern.strip_suffix('*')
903 && tool_name.starts_with(prefix)
904 {
905 let len = prefix.len();
906 if best.is_none_or(|(_, best_len)| len > best_len) {
907 best = Some((rule, len));
908 }
909 }
910 }
911 best.map(|(rule, _)| rule.policy)
912}
913
914#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
915pub struct NotificationsConfig {
916 #[serde(default)]
917 pub on_task_complete: Vec<NotificationTarget>,
918 #[serde(default)]
919 pub on_error: Vec<NotificationTarget>,
920 #[serde(default)]
921 pub on_shutdown: Vec<NotificationTarget>,
922}
923
924#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
925#[serde(tag = "target", rename_all = "lowercase")]
926pub enum NotificationTarget {
927 Agent {
928 name: String,
929 },
930 Commander,
931 Email {
932 address: String,
933 #[serde(default)]
934 smtp_config_file: Option<String>,
935 },
936 Slack {
937 #[serde(default)]
938 channel: Option<String>,
939 #[serde(default)]
940 webhook_url_env: Option<String>,
941 },
942 Webpush {
943 url: String,
944 },
945 Webhook {
946 url: String,
947 #[serde(default = "default_post")]
948 method: String,
949 #[serde(default)]
950 auth: Option<String>,
951 },
952}
953fn default_post() -> String {
954 "POST".to_string()
955}
956
957#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
958pub struct RetryConfig {
959 pub llm: RetryPolicy,
960 pub tool: RetryPolicy,
961}
962
963#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
964pub struct RetryPolicy {
965 pub max_retries: u32,
966 pub backoff: BackoffStrategy,
967 pub initial_delay_ms: u64,
968 #[serde(default)]
969 pub max_delay_ms: Option<u64>,
970 #[serde(default)]
971 pub retry_on: Vec<String>,
972}
973
974#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
975#[serde(rename_all = "lowercase")]
976pub enum BackoffStrategy {
977 Linear,
978 Exponential,
979 Fixed,
980}
981
982#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
983pub struct LifecycleConfig {
984 pub restart: RestartPolicy,
985 #[serde(default = "default_max_restarts")]
986 pub max_restarts: u32,
987 #[serde(default = "default_window")]
988 pub restart_window_secs: u64,
989 #[serde(default = "default_stop_timeout")]
990 pub stop_timeout_secs: u64,
991 #[serde(default = "default_mcp_required")]
992 pub mcp_required: bool,
993 #[serde(default)]
994 pub execution: ExecutionMode,
995 #[serde(default)]
996 pub schedule: Vec<ScheduleEntry>,
997 #[serde(default)]
998 pub idle_triggers: Vec<IdleTrigger>,
999}
1000fn default_max_restarts() -> u32 {
1001 3
1002}
1003fn default_window() -> u64 {
1004 600
1005}
1006fn default_stop_timeout() -> u64 {
1007 15
1008}
1009fn default_mcp_required() -> bool {
1010 true
1011}
1012
1013#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
1014#[serde(rename_all = "snake_case")]
1015pub enum RestartPolicy {
1016 Never,
1017 OnFailure,
1018 Always,
1019}
1020
1021#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
1022#[serde(rename_all = "snake_case")]
1023pub enum ExecutionMode {
1024 #[default]
1025 Daemon,
1026 OnDemand,
1027}
1028
1029#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1030pub struct ScheduleEntry {
1031 pub cron: String,
1032 pub message: String,
1033 #[serde(default, skip_serializing_if = "Option::is_none")]
1034 pub sends_to: Option<String>,
1035}
1036
1037#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1038pub struct IdleTrigger {
1039 pub after_secs: u64,
1041 pub message: String,
1043 #[serde(default, skip_serializing_if = "Option::is_none")]
1045 pub sends_to: Option<String>,
1046 #[serde(default = "default_idle_cooldown")]
1049 pub cooldown_secs: u64,
1050 #[serde(default = "default_true")]
1053 pub respect_quiet_hours: bool,
1054}
1055
1056fn default_idle_cooldown() -> u64 {
1057 600
1058}
1059pub fn name_enabled(denylist: &[String], name: &str) -> bool {
1061 !denylist.iter().any(|n| n == name)
1062}
1063
1064pub fn set_denylist(list: &mut Vec<String>, name: &str, enabled: bool) {
1067 if enabled {
1068 list.retain(|n| n != name);
1069 } else if !list.iter().any(|n| n == name) {
1070 list.push(name.to_string());
1071 }
1072}
1073
1074fn default_true() -> bool {
1075 true
1076}
1077
1078#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1079pub struct FileTransferConfig {
1080 #[serde(default = "default_accept_max")]
1081 pub accept_incoming_file_max_bytes: u64,
1082 #[serde(default = "default_accept_total")]
1083 pub accept_incoming_total_per_hour: u64,
1084 #[serde(default = "default_approval_threshold")]
1085 pub require_approval_above_bytes: u64,
1086 #[serde(default = "default_reject_paths")]
1087 pub reject_paths: Vec<String>,
1088 #[serde(default = "default_allowed_mime")]
1089 pub allowed_mime_types: Vec<String>,
1090}
1091
1092impl Default for FileTransferConfig {
1093 fn default() -> Self {
1094 Self {
1095 accept_incoming_file_max_bytes: default_accept_max(),
1096 accept_incoming_total_per_hour: default_accept_total(),
1097 require_approval_above_bytes: default_approval_threshold(),
1098 reject_paths: default_reject_paths(),
1099 allowed_mime_types: default_allowed_mime(),
1100 }
1101 }
1102}
1103
1104fn default_accept_max() -> u64 {
1105 10_485_760
1106}
1107fn default_accept_total() -> u64 {
1108 104_857_600
1109}
1110fn default_approval_threshold() -> u64 {
1111 10_485_760
1112}
1113fn default_reject_paths() -> Vec<String> {
1114 vec!["~/.ssh".into(), "~/.aws".into(), "~/.gnupg".into()]
1115}
1116fn default_allowed_mime() -> Vec<String> {
1117 vec!["*".into()]
1118}
1119
1120#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
1121#[serde(rename_all = "snake_case")]
1122pub enum DeploymentType {
1123 #[default]
1124 Laptop,
1125 Vm,
1126 Docker,
1127 K8s,
1128 Lambda,
1129}
1130
1131#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1132pub struct DeploymentConfig {
1133 #[serde(rename = "type", default)]
1134 pub deployment_type: DeploymentType,
1135 #[serde(default, skip_serializing_if = "Option::is_none")]
1136 pub region: Option<String>,
1137 #[serde(default = "default_env")]
1138 pub environment: Option<String>,
1139}
1140
1141impl Default for DeploymentConfig {
1142 fn default() -> Self {
1143 Self {
1144 deployment_type: DeploymentType::default(),
1145 region: None,
1146 environment: default_env(),
1147 }
1148 }
1149}
1150
1151fn default_env() -> Option<String> {
1152 Some("dev".into())
1153}
1154
1155#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1156pub struct LockFile {
1157 pub schema: u32,
1158 pub uuid: String,
1159 pub name: String,
1160 pub pid: u32,
1161 pub ppid: u32,
1162 pub started_at: String,
1163 pub binary_version: String,
1164 pub transports: LockTransports,
1165 pub card_digest: String,
1166 pub capabilities: Vec<String>,
1167 #[serde(default)]
1170 pub build_sha: String,
1171 #[serde(default)]
1174 pub proto_version: u32,
1175}
1176
1177#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1178pub struct LockTransports {
1179 pub stdio: bool,
1180 #[serde(default)]
1181 pub unix_socket: Option<String>,
1182 #[serde(default)]
1183 pub tcp: Option<String>,
1184 #[serde(default)]
1189 pub webhook: Option<String>,
1190}
1191
1192#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
1199#[serde(rename_all = "snake_case")]
1200pub enum VoiceId {
1201 #[default]
1203 AfHeart,
1204 AfBella,
1205 AfNicole,
1206 AmAdam,
1207 AmMichael,
1208}
1209
1210impl VoiceId {
1211 pub fn style_index(&self) -> usize {
1213 match self {
1214 VoiceId::AfHeart => 0,
1215 VoiceId::AfBella => 1,
1216 VoiceId::AfNicole => 2,
1217 VoiceId::AmAdam => 3,
1218 VoiceId::AmMichael => 4,
1219 }
1220 }
1221
1222 pub fn as_str(&self) -> &'static str {
1224 match self {
1225 VoiceId::AfHeart => "af_heart",
1226 VoiceId::AfBella => "af_bella",
1227 VoiceId::AfNicole => "af_nicole",
1228 VoiceId::AmAdam => "am_adam",
1229 VoiceId::AmMichael => "am_michael",
1230 }
1231 }
1232}
1233
1234impl std::str::FromStr for VoiceId {
1235 type Err = anyhow::Error;
1236
1237 fn from_str(s: &str) -> anyhow::Result<Self> {
1238 match s {
1239 "af_heart" => Ok(VoiceId::AfHeart),
1240 "af_bella" => Ok(VoiceId::AfBella),
1241 "af_nicole" => Ok(VoiceId::AfNicole),
1242 "am_adam" => Ok(VoiceId::AmAdam),
1243 "am_michael" => Ok(VoiceId::AmMichael),
1244 other => anyhow::bail!(
1245 "unknown voice ID '{other}' \
1246 (valid: af_heart, af_bella, af_nicole, am_adam, am_michael)"
1247 ),
1248 }
1249 }
1250}
1251
1252#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
1255pub struct VoiceConfig {
1256 #[serde(default)]
1258 pub enabled: bool,
1259 #[serde(default)]
1261 pub voice_id: VoiceId,
1262 #[serde(default, skip_serializing_if = "Option::is_none")]
1265 pub input_device: Option<String>,
1266}
1267
1268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1273pub struct HitlConfig {
1274 #[serde(default = "default_hitl_timeout_secs")]
1275 pub timeout_secs: u32,
1276 #[serde(default)]
1280 pub max_iterations: Option<u32>,
1281 #[serde(default)]
1286 pub max_tokens: Option<u64>,
1287}
1288
1289fn default_hitl_timeout_secs() -> u32 {
1290 300
1291}
1292
1293impl Default for HitlConfig {
1294 fn default() -> Self {
1295 Self {
1296 timeout_secs: default_hitl_timeout_secs(),
1297 max_iterations: None,
1298 max_tokens: None,
1299 }
1300 }
1301}
1302
1303#[cfg(test)]
1304mod hitl_tests {
1305 use super::*;
1306
1307 #[test]
1308 fn hitl_config_default_max_iterations_is_none() {
1309 let cfg = HitlConfig::default();
1310 assert!(cfg.max_iterations.is_none());
1311 }
1312
1313 #[test]
1314 fn hitl_config_max_iterations_explicit() {
1315 let cfg: HitlConfig = serde_yaml::from_str("timeout_secs: 60\nmax_iterations: 5").unwrap();
1316 assert_eq!(cfg.max_iterations, Some(5));
1317 }
1318
1319 #[test]
1320 fn hitl_config_default_max_tokens_is_none() {
1321 let cfg = HitlConfig::default();
1322 assert!(cfg.max_tokens.is_none());
1323 }
1324
1325 #[test]
1326 fn hitl_config_max_tokens_explicit() {
1327 let cfg: HitlConfig = serde_yaml::from_str("timeout_secs: 60\nmax_tokens: 250000").unwrap();
1328 assert_eq!(cfg.max_tokens, Some(250_000));
1329 }
1330}
1331
1332#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
1338pub struct CompanionConfig {
1339 #[serde(default)]
1340 pub enabled: bool,
1341 #[serde(default = "default_locale")]
1342 pub locale: String,
1343 #[serde(default)]
1344 pub relationship: Relationship,
1345 #[serde(default)]
1346 pub voice_overrides: VoiceOverrides,
1347 #[serde(default)]
1348 pub onboarding: OnboardingState,
1349 #[serde(default)]
1350 pub rhythm: RhythmConfig,
1351 #[serde(default)]
1352 pub proactive: ProactiveConfig,
1353}
1354
1355pub fn default_locale() -> String {
1364 sys_locale::get_locale()
1365 .filter(|l| !l.is_empty())
1366 .or_else(|| std::env::var("LANG").ok().and_then(|v| normalize_lang(&v)))
1367 .unwrap_or_else(|| "en-US".into())
1368}
1369
1370fn normalize_lang(v: &str) -> Option<String> {
1372 v.split('.')
1373 .next()
1374 .map(|s| s.replace('_', "-"))
1375 .filter(|s| !s.is_empty())
1376}
1377
1378#[cfg(test)]
1379mod locale_tests {
1380 use super::normalize_lang;
1381
1382 #[test]
1383 fn lang_with_encoding_and_region_normalizes() {
1384 assert_eq!(normalize_lang("zh_TW.UTF-8").as_deref(), Some("zh-TW"));
1385 }
1386
1387 #[test]
1388 fn lang_without_encoding_normalizes() {
1389 assert_eq!(normalize_lang("en_US").as_deref(), Some("en-US"));
1390 }
1391
1392 #[test]
1393 fn lang_with_script_keeps_script() {
1394 assert_eq!(
1395 normalize_lang("zh_Hant_TW.UTF-8").as_deref(),
1396 Some("zh-Hant-TW")
1397 );
1398 }
1399
1400 #[test]
1401 fn empty_lang_yields_none() {
1402 assert_eq!(normalize_lang(""), None);
1403 }
1404}
1405
1406#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
1407pub struct VoiceOverrides {
1408 #[serde(default, skip_serializing_if = "Option::is_none")]
1409 pub name_for_user: Option<String>,
1410 #[serde(default, skip_serializing_if = "Option::is_none")]
1411 pub formality: Option<Formality>,
1412 #[serde(default, skip_serializing_if = "Option::is_none")]
1413 pub extra_instructions: Option<String>,
1414}
1415
1416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1417pub struct FirstMemory {
1418 pub text: String,
1419 pub established_at: chrono::DateTime<chrono::Utc>,
1420}
1421
1422#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
1423pub struct OnboardingState {
1424 #[serde(default, skip_serializing_if = "Option::is_none")]
1425 pub completed_at: Option<chrono::DateTime<chrono::Utc>>,
1426 #[serde(default)]
1427 pub version: u32,
1428 #[serde(default, skip_serializing_if = "Option::is_none")]
1429 pub agent_display_name: Option<String>,
1430 #[serde(default, skip_serializing_if = "Option::is_none")]
1431 pub first_memory: Option<FirstMemory>,
1432}
1433
1434#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
1437pub struct RhythmConfig {
1438 #[serde(default)]
1439 pub enabled: bool,
1440}
1441
1442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1443pub struct ProactiveConfig {
1444 #[serde(default)]
1445 pub enabled: bool,
1446 #[serde(default, skip_serializing_if = "Option::is_none")]
1448 pub learning_until: Option<chrono::DateTime<chrono::Utc>>,
1449 #[serde(default, skip_serializing_if = "Option::is_none")]
1450 pub quiet_hours: Option<QuietHours>,
1451 #[serde(default, skip_serializing_if = "Option::is_none")]
1452 pub active_hours: Option<ActiveHours>,
1453 #[serde(default = "default_daily_cap")]
1454 pub daily_cap: u8,
1455 #[serde(default = "default_channels")]
1456 pub channels: Vec<String>,
1457 #[serde(default, skip_serializing_if = "Option::is_none")]
1458 pub paused_until: Option<chrono::DateTime<chrono::Utc>>,
1459}
1460
1461impl Default for ProactiveConfig {
1462 fn default() -> Self {
1463 Self {
1464 enabled: false,
1465 learning_until: None,
1466 quiet_hours: None,
1467 active_hours: None,
1468 daily_cap: default_daily_cap(),
1469 channels: default_channels(),
1470 paused_until: None,
1471 }
1472 }
1473}
1474
1475fn default_daily_cap() -> u8 {
1476 3
1477}
1478fn default_channels() -> Vec<String> {
1479 vec!["stdout".into()]
1480}
1481
1482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1483pub struct QuietHours {
1484 pub start: String,
1485 pub end: String,
1486}
1487
1488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1489pub struct ActiveHours {
1490 pub start: String,
1491 pub end: String,
1492}
1493
1494#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1499pub struct AgentAppearance {
1500 #[serde(default = "default_style_preset")]
1502 pub style_preset: String,
1503 #[serde(default)]
1504 pub behavior_preset: BehaviorPreset,
1505 #[serde(default, skip_serializing_if = "Option::is_none")]
1507 pub source_image_path: Option<std::path::PathBuf>,
1508 #[serde(default = "default_expressions_dir")]
1510 pub expressions_dir: std::path::PathBuf,
1511 #[serde(default, skip_serializing_if = "Option::is_none")]
1512 pub last_rendered_at: Option<chrono::DateTime<chrono::Utc>>,
1513 #[serde(default)]
1514 pub render_status: RenderStatus,
1515}
1516
1517fn default_style_preset() -> String {
1518 "default-blob".into()
1519}
1520
1521fn default_expressions_dir() -> std::path::PathBuf {
1522 std::path::PathBuf::from("expressions")
1523}
1524
1525impl Default for AgentAppearance {
1526 fn default() -> Self {
1527 Self {
1528 style_preset: default_style_preset(),
1529 behavior_preset: BehaviorPreset::Normal,
1530 source_image_path: None,
1531 expressions_dir: default_expressions_dir(),
1532 last_rendered_at: None,
1533 render_status: RenderStatus::Pending,
1534 }
1535 }
1536}
1537
1538#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
1539#[serde(rename_all = "snake_case")]
1540pub enum BehaviorPreset {
1541 Quiet,
1542 #[default]
1543 Normal,
1544 Lively,
1545}
1546
1547#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
1548#[serde(tag = "status", rename_all = "snake_case")]
1549pub enum RenderStatus {
1550 #[default]
1551 Pending,
1552 Rendering {
1553 done: u8,
1554 total: u8,
1555 },
1556 Ready,
1557 Failed {
1558 reason: String,
1559 },
1560}
1561
1562#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
1568#[serde(rename_all = "kebab-case")]
1569pub enum SnapshotPolicy {
1570 #[default]
1571 PullOnStart,
1572 PullPeriodic,
1573 Manual,
1574}
1575
1576#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1578pub struct PatternFilter {
1579 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1580 pub applies_in: Vec<String>,
1581 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1582 pub tier: Vec<String>,
1583 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1584 pub maturity: Vec<String>,
1585 #[serde(default)]
1586 pub importance_min: f64,
1587 #[serde(default = "default_max_snapshot_count")]
1588 pub max_count: usize,
1589 #[serde(default)]
1590 pub snapshot_policy: SnapshotPolicy,
1591}
1592
1593fn default_max_snapshot_count() -> usize {
1594 200
1595}
1596
1597impl Default for PatternFilter {
1598 fn default() -> Self {
1599 Self {
1600 applies_in: vec![],
1601 tier: vec![],
1602 maturity: vec![],
1603 importance_min: 0.0,
1604 max_count: 200,
1605 snapshot_policy: SnapshotPolicy::default(),
1606 }
1607 }
1608}
1609
1610#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1612pub struct SnapshotRef {
1613 pub knowledge_commit: String,
1614 pub taken_at: String,
1615 pub filter: PatternFilter,
1616}
1617
1618#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
1620pub struct FederationConfig {
1621 #[serde(default)]
1622 pub filter: PatternFilter,
1623 #[serde(default, skip_serializing_if = "Option::is_none")]
1624 pub snapshot_ref: Option<SnapshotRef>,
1625 #[serde(default)]
1626 pub evidence_flush_interval_minutes: u32,
1627}
1628
1629impl AgentProfile {
1630 #[doc(hidden)]
1636 pub fn default_for_tests() -> Self {
1637 serde_yaml_ng::from_str(include_str!("../tests/fixtures/minimal_profile.yaml"))
1638 .expect("minimal profile fixture")
1639 }
1640
1641 pub fn load(mur_home: &std::path::Path, name: &str) -> anyhow::Result<Self> {
1649 let path = mur_home.join("agents").join(name).join("profile.yaml");
1650 let yaml = std::fs::read_to_string(&path)
1651 .map_err(|e| anyhow::anyhow!("read {}: {e}", path.display()))?;
1652 serde_yaml_ng::from_str(&yaml).map_err(|e| anyhow::anyhow!("parse {}: {e}", path.display()))
1653 }
1654
1655 pub fn group_of(&self, name: &str) -> Option<&AddonRef> {
1657 self.addons.iter().find(|g| {
1658 g.skills.iter().any(|n| n == name)
1659 || g.mcp.iter().any(|n| n == name)
1660 || g.commands.iter().any(|n| n == name)
1661 })
1662 }
1663
1664 pub fn skill_enabled(&self, skill_name: &str) -> bool {
1667 name_enabled(&self.disabled_skills, skill_name)
1668 && self.group_of(skill_name).is_none_or(|g| g.enabled)
1669 }
1670
1671 pub fn mcp_enabled(&self, server_id: &str) -> bool {
1673 name_enabled(&self.disabled_mcp, server_id)
1674 && self.group_of(server_id).is_none_or(|g| g.enabled)
1675 }
1676
1677 pub fn set_skill_enabled(&mut self, skill_name: &str, enabled: bool) {
1679 set_denylist(&mut self.disabled_skills, skill_name, enabled);
1680 }
1681
1682 pub fn set_mcp_enabled(&mut self, server_id: &str, enabled: bool) {
1684 set_denylist(&mut self.disabled_mcp, server_id, enabled);
1685 }
1686
1687 pub fn set_addon_enabled(&mut self, addon_id: &str, enabled: bool) -> bool {
1690 match self.addons.iter_mut().find(|g| g.id == addon_id) {
1691 Some(g) => {
1692 g.enabled = enabled;
1693 true
1694 }
1695 None => false,
1696 }
1697 }
1698
1699 pub fn disable_all_addons(&mut self) {
1705 for g in &mut self.addons {
1706 g.enabled = false;
1707 }
1708 }
1709
1710 pub fn enabled_mcp_servers(&self) -> Vec<McpServerEntry> {
1712 self.mcp_servers
1713 .iter()
1714 .filter(|m| self.mcp_enabled(&m.name))
1715 .cloned()
1716 .collect()
1717 }
1718}
1719
1720#[cfg(test)]
1721mod tests {
1722 use super::*;
1723
1724 #[test]
1725 fn broad_audited_mcp_net_serde_roundtrip_and_defaults() {
1726 let net = McpServerNetwork {
1727 mode: McpNetMode::BroadAudited,
1728 allow_hosts: vec![],
1729 deny_hosts: vec!["evil.example".into()],
1730 authorization: Some(EgressAuthorization {
1731 authorized_by: "david".into(),
1732 authorized_at_ms: 1_750_000_000_000,
1733 }),
1734 };
1735 let y = serde_yaml::to_string(&net).unwrap();
1736 assert!(y.contains("broad_audited"));
1737 let back: McpServerNetwork = serde_yaml::from_str(&y).unwrap();
1738 assert_eq!(back, net);
1739 let legacy: McpServerNetwork =
1741 serde_yaml::from_str("mode: restricted\nallow_hosts: []\n").unwrap();
1742 assert_eq!(legacy.deny_hosts, Vec::<String>::new());
1743 assert!(legacy.authorization.is_none());
1744 }
1745
1746 #[test]
1747 fn mcp_entry_network_is_optional_and_round_trips() {
1748 let bare = "name: x\ncommand: npx\n";
1750 let e: McpServerEntry = serde_yaml_ng::from_str(bare).unwrap();
1751 assert!(e.network.is_none());
1752
1753 let with = "name: browser\ncommand: npx\nnetwork:\n mode: restricted\n allow_hosts: [\"example.com\", \"*.api.example.com\"]\n";
1755 let e2: McpServerEntry = serde_yaml_ng::from_str(with).unwrap();
1756 let net = e2.network.expect("network present");
1757 assert_eq!(net.mode, McpNetMode::Restricted);
1758 assert_eq!(net.allow_hosts, vec!["example.com", "*.api.example.com"]);
1759
1760 let out = serde_yaml_ng::to_string(&e).unwrap();
1762 assert!(!out.contains("network"));
1763 }
1764
1765 #[test]
1766 fn profile_round_trip_yaml() {
1767 let yaml = r#"
1768schema: 1
1769id: 01JQX4TM8Y9K7VQH6B2N3R5DPE
1770name: agent_a
1771display_name: "Price Hunter"
1772version: "0.1.0"
1773persona:
1774 category: research
1775 description: "Finds prices"
1776 traits: { tone: concise, risk: cautious, verbosity: low }
1777sys_prompt_file: "sys_prompt.md"
1778model: { provider: ollama, name: "llama3.2:3b", params: { temperature: 0.2, max_tokens: 4096 } }
1779mcp_servers: []
1780skills: []
1781transport:
1782 stdio: true
1783 socket: { enabled: true, bind: "unix:///tmp/a.sock" }
1784communication: { accepts_from: ["*"], sends_to: [] }
1785capabilities: ["a2a.message.send", "a2a.tasks"]
1786entitlements:
1787 network:
1788 inbound: { ports: [] }
1789 outbound: { mode: restricted, allow_hosts: [], protocols: ["tcp"], resolve_dns: { mode: system } }
1790 filesystem: { read: [], write: [], deny: [] }
1791 processes: { spawn: { mode: allowlist, allowed: [] } }
1792 syscalls: { mode: default }
1793 limits: { memory_mb: 512, file_descriptors: 1024, processes: 32 }
1794notifications: { on_task_complete: [], on_error: [], on_shutdown: [] }
1795retry:
1796 llm: { max_retries: 3, backoff: exponential, initial_delay_ms: 1000, max_delay_ms: 30000, retry_on: [rate_limit, timeout, connection_error] }
1797 tool: { max_retries: 1, backoff: fixed, initial_delay_ms: 500 }
1798lifecycle: { restart: on_failure, max_restarts: 3, restart_window_secs: 600, stop_timeout_secs: 15, mcp_required: true }
1799created_at: "2026-04-22T10:00:00+08:00"
1800updated_at: "2026-04-22T10:00:00+08:00"
1801"#;
1802 let profile: AgentProfile = serde_yaml_ng::from_str(yaml).expect("parse");
1803 assert_eq!(profile.name, "agent_a");
1804 assert_eq!(profile.persona.category, PersonaCategory::Research);
1805 assert_eq!(
1806 profile.entitlements.network.outbound.mode,
1807 NetworkOutboundMode::Restricted
1808 );
1809 let reserialized = serde_yaml_ng::to_string(&profile).expect("emit");
1810 let round_tripped: AgentProfile = serde_yaml_ng::from_str(&reserialized).expect("re-parse");
1811 assert_eq!(profile.id, round_tripped.id);
1812 }
1813
1814 #[test]
1815 fn requires_capabilities_defaults_empty_and_round_trips() {
1816 let base = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
1817 let p: AgentProfile = serde_yaml_ng::from_str(base).unwrap();
1818 assert!(p.requires_capabilities.is_empty());
1819 let with = format!("{base}\nrequires_capabilities:\n - media\n");
1820 let p2: AgentProfile = serde_yaml_ng::from_str(&with).unwrap();
1821 assert_eq!(p2.requires_capabilities, vec!["media"]);
1822 }
1823}
1824
1825#[cfg(test)]
1826mod model_ref_tests {
1827 use super::*;
1828
1829 #[test]
1830 fn legacy_profile_without_model_ref_still_parses() {
1831 let yaml = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
1832 let p: AgentProfile = serde_yaml_ng::from_str(yaml).unwrap();
1833 assert!(
1834 p.model_ref.is_none(),
1835 "legacy profile must not have model_ref"
1836 );
1837 }
1838
1839 #[test]
1840 fn round_trip_with_model_ref_preserves_field() {
1841 let yaml = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
1842 let mut p: AgentProfile = serde_yaml_ng::from_str(yaml).unwrap();
1843 p.model_ref = Some("anthropic_opus_4_7".into());
1844 let s = serde_yaml_ng::to_string(&p).unwrap();
1845 assert!(s.contains("model_ref: anthropic_opus_4_7"), "yaml: {s}");
1846 let p2: AgentProfile = serde_yaml_ng::from_str(&s).unwrap();
1847 assert_eq!(p2.model_ref.as_deref(), Some("anthropic_opus_4_7"));
1848 }
1849
1850 #[test]
1851 fn per_agent_fallback_and_routing_optional_and_legacy_safe() {
1852 let yaml = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
1854 let p: AgentProfile = serde_yaml_ng::from_str(yaml).unwrap();
1855 assert!(
1856 p.fallback_chain.is_empty(),
1857 "legacy profile must have empty fallback_chain"
1858 );
1859 assert!(
1860 p.routing.is_none(),
1861 "legacy profile must have no routing override"
1862 );
1863
1864 let mut p = p.clone();
1866 p.fallback_chain = vec!["claude_opus".into(), "claude_sonnet".into()];
1867 p.routing = Some(crate::config::RoutingConfig {
1868 enabled: true,
1869 ..Default::default()
1870 });
1871 let s = serde_yaml_ng::to_string(&p).unwrap();
1872 assert!(
1873 s.contains("fallback_chain:"),
1874 "yaml must contain fallback_chain"
1875 );
1876 assert!(s.contains("routing:"), "yaml must contain routing");
1877 let p2: AgentProfile = serde_yaml_ng::from_str(&s).unwrap();
1878 assert_eq!(
1879 p2.fallback_chain,
1880 vec!["claude_opus", "claude_sonnet"],
1881 "fallback_chain must round-trip"
1882 );
1883 assert!(
1884 p2.routing.as_ref().unwrap().enabled,
1885 "routing.enabled must round-trip"
1886 );
1887 }
1888}
1889
1890#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1898#[serde(rename_all = "snake_case")]
1899pub enum ProactiveTier {
1900 Off,
1901 WarmOnly,
1902 WarmAndBehavior,
1903 All,
1904}
1905
1906impl ProactiveTier {
1907 pub fn from_config(c: &CompanionConfig) -> Self {
1908 match (c.enabled, c.rhythm.enabled, c.proactive.enabled) {
1909 (false, _, _) => Self::Off,
1910 (true, false, false) => Self::WarmOnly,
1911 (true, true, false) => Self::WarmAndBehavior,
1912 (true, _, true) => Self::All,
1913 }
1914 }
1915
1916 pub fn apply(&self, c: &mut CompanionConfig) {
1917 match self {
1918 Self::Off => {
1919 c.enabled = false;
1920 c.rhythm.enabled = false;
1921 c.proactive.enabled = false;
1922 }
1923 Self::WarmOnly => {
1924 c.enabled = true;
1925 c.rhythm.enabled = false;
1926 c.proactive.enabled = false;
1927 }
1928 Self::WarmAndBehavior => {
1929 c.enabled = true;
1930 c.rhythm.enabled = true;
1931 c.proactive.enabled = false;
1932 }
1933 Self::All => {
1934 c.enabled = true;
1935 c.rhythm.enabled = true;
1936 c.proactive.enabled = true;
1937 }
1938 }
1939 }
1940}
1941
1942#[cfg(test)]
1943mod mcp_pin_tests {
1944 use super::*;
1945
1946 #[test]
1950 fn pre_m9_entry_roundtrips_without_pin_fields() {
1951 let yaml = r#"
1952name: weather
1953command: /opt/mcp/weather
1954args: ["--port", "0"]
1955"#;
1956 let entry: McpServerEntry = serde_yaml_ng::from_str(yaml).unwrap();
1957 assert_eq!(entry.name, "weather");
1958 assert_eq!(entry.binary_sha256, None);
1959 assert_eq!(entry.description_hash, None);
1960 assert_eq!(entry.publisher, None);
1961 assert_eq!(entry.installed_at, None);
1962
1963 let out = serde_yaml_ng::to_string(&entry).unwrap();
1966 assert!(!out.contains("binary_sha256"), "got {out}");
1967 assert!(!out.contains("description_hash"), "got {out}");
1968 assert!(!out.contains("publisher"), "got {out}");
1969 assert!(!out.contains("installed_at"), "got {out}");
1970 }
1971
1972 #[test]
1974 fn full_m9_entry_roundtrips_all_fields() {
1975 let yaml = r#"
1976name: weather
1977command: /opt/mcp/weather
1978args: []
1979binary_sha256: "3f4abca8b0e6e2c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b81c"
1980description_hash: "9a01b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9c7e2"
1981publisher:
1982 name: "@anthropic-mcp/weather"
1983 homepage: "https://github.com/anthropic-mcp/weather"
1984 registry_id: "@anthropic-mcp/weather@1.2.3"
1985installed_at: "2026-05-06T08:00:00Z"
1986"#;
1987 let entry: McpServerEntry = serde_yaml_ng::from_str(yaml).unwrap();
1988 assert!(
1989 entry
1990 .binary_sha256
1991 .as_deref()
1992 .unwrap()
1993 .starts_with("3f4abca8")
1994 );
1995 assert!(
1996 entry
1997 .description_hash
1998 .as_deref()
1999 .unwrap()
2000 .starts_with("9a01b2c3")
2001 );
2002 let pub_info = entry.publisher.clone().unwrap();
2003 assert_eq!(pub_info.name, "@anthropic-mcp/weather");
2004 assert_eq!(
2005 pub_info.homepage.as_deref(),
2006 Some("https://github.com/anthropic-mcp/weather"),
2007 );
2008 assert_eq!(
2009 pub_info.registry_id.as_deref(),
2010 Some("@anthropic-mcp/weather@1.2.3"),
2011 );
2012 let installed = entry.installed_at.unwrap();
2013 assert_eq!(installed.to_rfc3339(), "2026-05-06T08:00:00+00:00");
2014 }
2015
2016 #[test]
2020 fn partial_pin_only_binary_sha_roundtrips() {
2021 let yaml = r#"
2022name: weather
2023command: /opt/mcp/weather
2024args: []
2025binary_sha256: "deadbeef00112233445566778899aabbccddeeff00112233445566778899aabb"
2026"#;
2027 let entry: McpServerEntry = serde_yaml_ng::from_str(yaml).unwrap();
2028 assert_eq!(
2029 entry.binary_sha256.as_deref(),
2030 Some("deadbeef00112233445566778899aabbccddeeff00112233445566778899aabb"),
2031 );
2032 assert_eq!(entry.description_hash, None);
2033 assert_eq!(entry.publisher, None);
2034 }
2035
2036 #[test]
2039 fn publisher_minimal_just_name() {
2040 let yaml = r#"
2041name: weather
2042command: /opt/mcp/weather
2043args: []
2044publisher:
2045 name: "alice"
2046"#;
2047 let entry: McpServerEntry = serde_yaml_ng::from_str(yaml).unwrap();
2048 let p = entry.publisher.as_ref().unwrap();
2049 assert_eq!(p.name, "alice");
2050 assert_eq!(p.homepage, None);
2051 assert_eq!(p.registry_id, None);
2052
2053 let out = serde_yaml_ng::to_string(&entry).unwrap();
2055 assert!(!out.contains("homepage:"), "got {out}");
2056 assert!(!out.contains("registry_id:"), "got {out}");
2057 }
2058}
2059
2060#[cfg(test)]
2061mod voice_tests {
2062 use super::*;
2063 use std::str::FromStr;
2064
2065 #[test]
2066 fn voice_config_round_trips() {
2067 let base = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
2069 let yaml = format!("{base}voice:\n enabled: true\n voice_id: af_bella\n");
2070
2071 let profile: AgentProfile = serde_yaml_ng::from_str(&yaml).expect("parse with voice");
2072 assert!(profile.voice.enabled);
2073 assert_eq!(profile.voice.voice_id, VoiceId::AfBella);
2074
2075 let legacy: AgentProfile = serde_yaml_ng::from_str(base).expect("parse without voice");
2077 assert!(!legacy.voice.enabled);
2078 assert_eq!(legacy.voice.voice_id, VoiceId::AfHeart);
2079 }
2080
2081 #[test]
2082 fn voice_id_from_str_roundtrips() {
2083 let cases = [
2084 ("af_heart", VoiceId::AfHeart),
2085 ("af_bella", VoiceId::AfBella),
2086 ("af_nicole", VoiceId::AfNicole),
2087 ("am_adam", VoiceId::AmAdam),
2088 ("am_michael", VoiceId::AmMichael),
2089 ];
2090 for (s, expected) in cases {
2091 assert_eq!(VoiceId::from_str(s).unwrap(), expected);
2092 assert_eq!(expected.as_str(), s);
2093 }
2094 }
2095
2096 #[test]
2097 fn voice_id_from_str_rejects_unknown() {
2098 assert!(VoiceId::from_str("bogus").is_err());
2099 }
2100}
2101
2102#[cfg(test)]
2103mod idle_trigger_tests {
2104 use super::*;
2105
2106 #[test]
2107 fn idle_trigger_yaml_round_trip() {
2108 let yaml = r#"
2109restart: on_failure
2110idle_triggers:
2111 - after_secs: 3600
2112 message: "still there?"
2113 sends_to: other_agent
2114 cooldown_secs: 1800
2115 respect_quiet_hours: true
2116"#;
2117 let cfg: LifecycleConfig = serde_yaml_ng::from_str(yaml).unwrap();
2118 assert_eq!(cfg.idle_triggers.len(), 1);
2119 assert_eq!(cfg.idle_triggers[0].after_secs, 3600);
2120 assert_eq!(cfg.idle_triggers[0].message, "still there?");
2121 assert_eq!(
2122 cfg.idle_triggers[0].sends_to.as_deref(),
2123 Some("other_agent")
2124 );
2125 assert_eq!(cfg.idle_triggers[0].cooldown_secs, 1800);
2126 assert!(cfg.idle_triggers[0].respect_quiet_hours);
2127 }
2128
2129 #[test]
2130 fn idle_trigger_defaults_when_omitted() {
2131 let yaml = "restart: on_failure\n";
2132 let cfg: LifecycleConfig = serde_yaml_ng::from_str(yaml).unwrap();
2133 assert!(cfg.idle_triggers.is_empty());
2134 }
2135}
2136
2137#[cfg(test)]
2138mod appearance_tests {
2139 use super::*;
2140
2141 #[test]
2142 fn appearance_default_style_preset_is_default_blob() {
2143 assert_eq!(AgentAppearance::default().style_preset, "default-blob");
2144 }
2145
2146 #[test]
2147 fn appearance_default_behavior_is_normal() {
2148 assert_eq!(
2149 AgentAppearance::default().behavior_preset,
2150 BehaviorPreset::Normal
2151 );
2152 }
2153
2154 #[test]
2155 fn appearance_default_render_status_is_pending() {
2156 assert_eq!(
2157 AgentAppearance::default().render_status,
2158 RenderStatus::Pending
2159 );
2160 }
2161
2162 #[test]
2163 fn render_status_serde_round_trip() {
2164 let cases = [
2165 RenderStatus::Pending,
2166 RenderStatus::Rendering { done: 3, total: 12 },
2167 RenderStatus::Ready,
2168 RenderStatus::Failed {
2169 reason: "out of quota".into(),
2170 },
2171 ];
2172 for status in cases {
2173 let yaml = serde_yaml_ng::to_string(&status).expect("serialize");
2174 let back: RenderStatus = serde_yaml_ng::from_str(&yaml).expect("deserialize");
2175 assert_eq!(status, back);
2176 }
2177 }
2178
2179 #[test]
2180 fn agent_profile_with_appearance_round_trips() {
2181 let base = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
2182 let yaml = format!(
2183 "{base}appearance:\n style_preset: chiikawa\n render_status:\n status: ready\n"
2184 );
2185 let profile: AgentProfile = serde_yaml_ng::from_str(&yaml).expect("parse with appearance");
2186 assert_eq!(profile.appearance.style_preset, "chiikawa");
2187 assert_eq!(profile.appearance.render_status, RenderStatus::Ready);
2188
2189 let out = serde_yaml_ng::to_string(&profile).expect("serialize");
2190 let back: AgentProfile = serde_yaml_ng::from_str(&out).expect("re-parse");
2191 assert_eq!(profile.appearance, back.appearance);
2192 }
2193
2194 #[test]
2195 fn legacy_profile_without_appearance_uses_default() {
2196 let yaml = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
2197 let profile: AgentProfile = serde_yaml_ng::from_str(yaml).expect("parse legacy");
2198 assert_eq!(profile.appearance.style_preset, "default-blob");
2199 assert_eq!(profile.appearance.behavior_preset, BehaviorPreset::Normal);
2200 assert_eq!(profile.appearance.render_status, RenderStatus::Pending);
2201 }
2202
2203 #[test]
2204 fn legacy_profile_without_file_actions_or_action_pipeline_loads() {
2205 let yaml = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
2206 let p: AgentProfile = serde_yaml_ng::from_str(yaml).unwrap();
2207 assert!(p.file_actions.is_empty());
2208 assert_eq!(p.action_pipeline.deletion.cancel_window_minutes, 10);
2209 assert_eq!(p.action_pipeline.queue.max_concurrent, 3);
2210 }
2211}
2212
2213#[cfg(test)]
2214mod federation_tests {
2215 use super::*;
2216
2217 #[test]
2218 fn test_pattern_filter_default() {
2219 let f = PatternFilter::default();
2220 assert_eq!(f.max_count, 200);
2221 assert_eq!(f.importance_min, 0.0);
2222 assert!(f.tier.is_empty());
2223 }
2224
2225 #[test]
2226 fn test_federation_config_roundtrip() {
2227 let cfg = FederationConfig {
2228 filter: PatternFilter {
2229 tier: vec!["core".into()],
2230 max_count: 50,
2231 ..Default::default()
2232 },
2233 snapshot_ref: Some(SnapshotRef {
2234 knowledge_commit: "abc123def456".into(),
2235 taken_at: "2026-05-19T00:00:00Z".into(),
2236 filter: PatternFilter::default(),
2237 }),
2238 evidence_flush_interval_minutes: 15,
2239 };
2240 let yaml = serde_yaml_ng::to_string(&cfg).unwrap();
2241 let back: FederationConfig = serde_yaml_ng::from_str(&yaml).unwrap();
2242 assert_eq!(cfg, back);
2243 }
2244
2245 #[test]
2246 fn test_agent_profile_federation_defaults() {
2247 let cfg = FederationConfig::default();
2251 assert_eq!(cfg.evidence_flush_interval_minutes, 0);
2252 assert!(cfg.snapshot_ref.is_none());
2253 }
2254}
2255
2256#[cfg(test)]
2257mod skill_card_tests {
2258 use super::*;
2259
2260 #[test]
2261 fn installed_skills_default_to_empty_when_absent() {
2262 let yaml = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
2263 let p: AgentProfile = serde_yaml_ng::from_str(yaml).unwrap();
2264 assert!(p.installed_skills.is_empty());
2265 }
2266
2267 #[test]
2268 fn installed_skills_roundtrip_preserves_entries() {
2269 let base = include_str!("../tests/fixtures/profile_p0a_minimal.yaml");
2270 let yaml = format!(
2271 "{base}installed_skills:\n - name: s1\n version: 1.0.0\n publisher: human:d\n description: desc\n category: workflow\n tags: [web]\n triggers:\n - type: command\n pattern: /find\n abstract: does things\n transfer_chain:\n - agent://alice\n"
2272 );
2273 let p: AgentProfile = serde_yaml_ng::from_str(&yaml).unwrap();
2274 assert_eq!(p.installed_skills.len(), 1);
2275 assert_eq!(p.installed_skills[0].name, "s1");
2276 assert_eq!(p.installed_skills[0].abstract_text, "does things");
2277 assert_eq!(p.installed_skills[0].transfer_chain, vec!["agent://alice"]);
2278
2279 let out = serde_yaml_ng::to_string(&p).unwrap();
2280 assert!(out.contains("abstract: does things"));
2281 assert!(out.contains("pattern: /find"));
2282
2283 let back: AgentProfile = serde_yaml_ng::from_str(&out).unwrap();
2284 assert_eq!(p.installed_skills, back.installed_skills);
2285 }
2286
2287 #[test]
2288 fn installed_skills_minimal_entry_serializes_compactly() {
2289 let entry = SkillCardEntry {
2291 name: "minimal".into(),
2292 ..Default::default()
2293 };
2294 let yaml = serde_yaml_ng::to_string(&entry).unwrap();
2295 assert!(yaml.contains("name: minimal"));
2296 assert!(
2297 !yaml.contains("version:"),
2298 "empty version must be skipped: {yaml}"
2299 );
2300 assert!(
2301 !yaml.contains("publisher:"),
2302 "empty publisher must be skipped: {yaml}"
2303 );
2304 assert!(
2305 !yaml.contains("abstract:"),
2306 "empty abstract must be skipped: {yaml}"
2307 );
2308 }
2309}
2310
2311#[cfg(test)]
2312mod tool_policy_tests {
2313 use super::*;
2314
2315 fn rules() -> Vec<ToolRule> {
2316 vec![
2317 ToolRule {
2318 pattern: "mcp__github__merge_pr".into(),
2319 policy: ToolPolicy::Ask,
2320 risk: None,
2321 },
2322 ToolRule {
2323 pattern: "mcp__github__*".into(),
2324 policy: ToolPolicy::Allow,
2325 risk: None,
2326 },
2327 ToolRule {
2328 pattern: "mcp__*".into(),
2329 policy: ToolPolicy::Deny,
2330 risk: None,
2331 },
2332 ToolRule {
2333 pattern: "bash".into(),
2334 policy: ToolPolicy::Allow,
2335 risk: None,
2336 },
2337 ]
2338 }
2339
2340 #[test]
2341 fn exact_beats_glob() {
2342 assert_eq!(
2343 resolve_tool_policy(&rules(), "mcp__github__merge_pr"),
2344 ToolPolicy::Ask
2345 );
2346 }
2347
2348 #[test]
2349 fn longer_glob_wins() {
2350 assert_eq!(
2351 resolve_tool_policy(&rules(), "mcp__github__create_issue"),
2352 ToolPolicy::Allow
2353 );
2354 }
2355
2356 #[test]
2357 fn shorter_glob_fallback() {
2358 assert_eq!(
2359 resolve_tool_policy(&rules(), "mcp__slack__send"),
2360 ToolPolicy::Deny
2361 );
2362 }
2363
2364 #[test]
2365 fn exact_bash() {
2366 assert_eq!(resolve_tool_policy(&rules(), "bash"), ToolPolicy::Allow);
2367 }
2368
2369 #[test]
2370 fn unknown_tool_defaults_ask() {
2371 assert_eq!(
2372 resolve_tool_policy(&rules(), "unknown_tool"),
2373 ToolPolicy::Ask
2374 );
2375 }
2376
2377 #[test]
2378 fn empty_rules_defaults_ask() {
2379 assert_eq!(resolve_tool_policy(&[], "bash"), ToolPolicy::Ask);
2380 }
2381
2382 fn minimal_entitlements_yaml() -> &'static str {
2383 "network:\n inbound: {}\n outbound:\n mode: off\nfilesystem: {}\nprocesses:\n spawn:\n mode: none\n"
2384 }
2385
2386 #[test]
2387 fn entitlements_tools_defaults_empty() {
2388 let e: Entitlements = serde_yaml_ng::from_str(minimal_entitlements_yaml()).unwrap();
2389 assert!(e.tools.is_empty());
2390 }
2391
2392 #[test]
2393 fn entitlements_tools_roundtrip() {
2394 let base = minimal_entitlements_yaml();
2395 let yaml = format!("{base}tools:\n - pattern: \"mcp__github__*\"\n policy: allow\n");
2396 let e: Entitlements = serde_yaml_ng::from_str(&yaml).unwrap();
2397 assert_eq!(e.tools.len(), 1);
2398 assert_eq!(e.tools[0].policy, ToolPolicy::Allow);
2399 let y = serde_yaml_ng::to_string(&e).unwrap();
2400 let back: Entitlements = serde_yaml_ng::from_str(&y).unwrap();
2401 assert_eq!(back.tools.len(), 1);
2402 assert_eq!(back.tools[0].policy, ToolPolicy::Allow);
2403 }
2404 #[test]
2405 fn denylist_membership_and_mutation() {
2406 let mut list: Vec<String> = vec![];
2407 assert!(name_enabled(&list, "a"), "empty denylist => enabled");
2408
2409 set_denylist(&mut list, "a", false); assert!(!name_enabled(&list, "a"));
2411 assert_eq!(list, ["a"]);
2412
2413 set_denylist(&mut list, "a", false); assert_eq!(list, ["a"], "no duplicate entries");
2415
2416 set_denylist(&mut list, "a", true); assert!(name_enabled(&list, "a"));
2418 assert!(list.is_empty());
2419
2420 set_denylist(&mut list, "b", true); assert!(list.is_empty());
2422 }
2423
2424 #[test]
2425 fn addon_group_rule_truth_table() {
2426 let mut p = AgentProfile::default_for_tests();
2427 p.addons.push(AddonRef {
2428 id: "grp".into(),
2429 source: "claude-local:grp@1.0.0".into(),
2430 enabled: false,
2431 skills: vec!["g_skill".into()],
2432 mcp: vec!["g_mcp".into()],
2433 commands: vec!["g_cmd".into()],
2434 content_hash: None,
2435 fetch_ref: None,
2436 fetch_plugin: None,
2437 });
2438
2439 assert!(p.skill_enabled("standalone"));
2441 assert!(p.mcp_enabled("standalone_mcp"));
2442
2443 assert!(!p.skill_enabled("g_skill"));
2445 assert!(!p.mcp_enabled("g_mcp"));
2446
2447 assert!(p.set_addon_enabled("grp", true));
2449 assert!(p.skill_enabled("g_skill"));
2450 assert!(p.mcp_enabled("g_mcp"));
2451
2452 p.set_skill_enabled("g_skill", false);
2454 assert!(!p.skill_enabled("g_skill"));
2455
2456 assert!(!p.set_addon_enabled("nope", true));
2458
2459 p.disable_all_addons();
2461 assert!(p.addons.iter().all(|g| !g.enabled));
2462 assert!(!p.skill_enabled("g_skill"));
2463 assert!(!p.skill_enabled("g_cmd"));
2464 assert!(!p.mcp_enabled("g_mcp")); assert!(p.set_addon_enabled("grp", true));
2470 assert!(!p.skill_enabled("g_skill")); assert!(p.skill_enabled("g_cmd")); assert!(p.mcp_enabled("g_mcp")); p.set_skill_enabled("g_skill", true);
2476 assert!(p.skill_enabled("g_skill"));
2477 }
2478
2479 #[test]
2480 fn addon_ref_content_hash_and_fetch_ref_default_none_and_round_trip() {
2481 let legacy = "id: a\nsource: claude-local:a@1\nenabled: false\n";
2483 let r: AddonRef = serde_yaml_ng::from_str(legacy).unwrap();
2484 assert_eq!(r.content_hash, None);
2485 assert_eq!(r.fetch_ref, None);
2486
2487 let full = "id: a\nsource: claude-local:a@1\nenabled: true\ncontent_hash: abc123\nfetch_ref: owner/repo\n";
2489 let r2: AddonRef = serde_yaml_ng::from_str(full).unwrap();
2490 assert_eq!(r2.content_hash.as_deref(), Some("abc123"));
2491 assert_eq!(r2.fetch_ref.as_deref(), Some("owner/repo"));
2492 let back = serde_yaml_ng::to_string(&r2).unwrap();
2493 let r3: AddonRef = serde_yaml_ng::from_str(&back).unwrap();
2494 assert_eq!(r2, r3);
2495 }
2496}
2497
2498#[cfg(test)]
2499mod lockfile_compat_tests {
2500 use super::*;
2501
2502 #[test]
2503 fn lockfile_new_fields_default_for_old_locks() {
2504 let old = r#"{"schema":1,"uuid":"u","name":"a","pid":1,"ppid":1,
2507 "started_at":"t","binary_version":"mur-agent-runtime 2.26.9",
2508 "transports":{"stdio":true},"card_digest":"d","capabilities":[]}"#;
2509 let lock: LockFile = serde_json::from_str(old).unwrap();
2510 assert_eq!(lock.build_sha, "");
2511 assert_eq!(lock.proto_version, 0);
2512 }
2513}
2514
2515#[cfg(test)]
2516mod remote_mcp_tests {
2517 use super::*;
2518
2519 #[test]
2520 fn mcp_entry_roundtrips_remote_bearer() {
2521 let e = McpServerEntry {
2522 name: "gh".into(),
2523 command: String::new(),
2524 url: Some("https://api.example.com/mcp".into()),
2525 auth: Some(McpAuth::Bearer {
2526 token: crate::secret::SecretRef::Env("GH_TOKEN".into()),
2527 }),
2528 ..Default::default()
2529 };
2530 let y = serde_yaml_ng::to_string(&e).unwrap();
2531 let back: McpServerEntry = serde_yaml_ng::from_str(&y).unwrap();
2532 assert_eq!(back.url.as_deref(), Some("https://api.example.com/mcp"));
2533 assert!(matches!(
2534 back.auth,
2535 Some(McpAuth::Bearer { ref token }) if *token == crate::secret::SecretRef::Env("GH_TOKEN".into())
2536 ));
2537 let legacy: McpServerEntry =
2539 serde_yaml_ng::from_str("name: fs\ncommand: npx\nargs: [\"-y\",\"fs\"]\n").unwrap();
2540 assert!(legacy.url.is_none());
2541 assert!(legacy.auth.is_none());
2542 }
2543}
2544
2545#[cfg(test)]
2546mod requires_programs_tests {
2547 #[test]
2548 fn mcp_entry_parses_requires_programs_and_defaults_empty() {
2549 let with = r#"
2550name: research-gateway
2551command: mur-research-gateway
2552requires_programs:
2553 - name: lightpanda
2554 detect: { file: "~/.mur/aura/lightpanda" }
2555 reason: "render tier"
2556 registry: lightpanda
2557"#;
2558 let e: crate::agent::McpServerEntry = serde_yaml::from_str(with).unwrap();
2559 assert_eq!(e.requires_programs.len(), 1);
2560 assert_eq!(e.requires_programs[0].name, "lightpanda");
2561
2562 let without = "name: x\ncommand: y\n";
2564 let e2: crate::agent::McpServerEntry = serde_yaml::from_str(without).unwrap();
2565 assert!(e2.requires_programs.is_empty());
2566 }
2567}