Skip to main content

subspace_core/
features.rs

1//! Registered feature policy shared by configuration, settings and runtimes.
2
3/// A registered feature's lifecycle stage.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum FeatureStage {
6    Experimental,
7    Stable,
8    Removed,
9}
10
11/// Static metadata and policy for one registered feature.
12#[derive(Clone, Copy, Debug, PartialEq, Eq)]
13pub struct FeatureSpec {
14    pub id: &'static str,
15    pub title: &'static str,
16    pub description: &'static str,
17    pub stage: FeatureStage,
18    pub default_enabled: bool,
19    pub toggleable: bool,
20}
21
22/// Pi chat is opt-in while its adapter is limited to Pi 1.0.4 and does not
23/// provide Copilot's sandbox, native host tools or Copilot-only controls.
24pub const PI_CHAT: FeatureSpec = FeatureSpec {
25    id: "app.pi-chat",
26    title: "Pi chat",
27    description: "Alternative local chat limited to Pi 1.0.4, without Copilot's sandbox, native host tools, automatic resource discovery, or Copilot-only controls.",
28    stage: FeatureStage::Experimental,
29    default_enabled: false,
30    toggleable: true,
31};
32
33/// ACP chat is opt-in while it runs external agents whose own tools, sandbox
34/// and permission rules Subspace does not control.
35pub const ACP_CHAT: FeatureSpec = FeatureSpec {
36    id: "app.acp-chat",
37    title: "ACP agent chat",
38    description: "Alternative local chat with an Agent Client Protocol agent such as OpenCode, Claude Code, Codex or Gemini CLI. The agent keeps its own tools, sandbox and sign-in; Subspace shows its permission requests and serves board tools to it over MCP.",
39    stage: FeatureStage::Experimental,
40    default_enabled: false,
41    toggleable: true,
42};
43
44/// A bounded app or board feature id made from nonempty ASCII segments.
45pub fn valid_id(id: &str) -> bool {
46    const MAX_ID_BYTES: usize = 128;
47    if id.is_empty() || id.len() > MAX_ID_BYTES || !id.is_ascii() {
48        return false;
49    }
50    let segments = id.split('.').collect::<Vec<_>>();
51    let valid_shape = matches!(segments.as_slice(), ["app", _])
52        || matches!(segments.as_slice(), ["board", _, _, ..]);
53    valid_shape
54        && segments.iter().all(|segment| {
55            !segment.is_empty()
56                && segment
57                    .bytes()
58                    .all(|byte| byte.is_ascii_alphanumeric() || byte == b'-')
59        })
60}
61
62#[cfg(test)]
63mod tests {
64    use super::{ACP_CHAT, FeatureSpec, FeatureStage, PI_CHAT, valid_id};
65
66    #[test]
67    fn acp_chat_is_an_opt_in_experiment() {
68        assert!(valid_id(ACP_CHAT.id));
69        assert_eq!(ACP_CHAT.stage, FeatureStage::Experimental);
70        const {
71            assert!(!ACP_CHAT.default_enabled);
72            assert!(ACP_CHAT.toggleable);
73        }
74        assert!(ACP_CHAT.description.contains("permission requests"));
75    }
76
77    #[test]
78    fn feature_ids_are_namespaced_ascii_segments() {
79        assert!(valid_id("app.pi-chat"));
80        assert!(valid_id("board.github.pull-requests.preview"));
81        for invalid in [
82            "",
83            "pi-chat",
84            "app",
85            "app.two.parts",
86            "board.github",
87            "board..preview",
88            "board.git_hub.preview",
89            "board.github.white space",
90            "board.github.é",
91        ] {
92            assert!(!valid_id(invalid), "{invalid}");
93        }
94        assert!(!valid_id(&format!("app.{}", "x".repeat(125))));
95    }
96
97    #[test]
98    fn pi_chat_declares_the_initial_adapter_constraints() {
99        assert_eq!(PI_CHAT.id, "app.pi-chat");
100        assert_eq!(PI_CHAT.title, "Pi chat");
101        assert_eq!(PI_CHAT.stage, FeatureStage::Experimental);
102        const {
103            assert!(!PI_CHAT.default_enabled);
104            assert!(PI_CHAT.toggleable);
105        }
106        assert!(PI_CHAT.description.contains("Pi 1.0.4"));
107        assert!(PI_CHAT.description.contains("without Copilot's sandbox"));
108        let copied: FeatureSpec = PI_CHAT;
109        assert_eq!(copied, PI_CHAT);
110    }
111}