Skip to main content

agentmux_common/deeplinks/
types.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The shape of the deep-link registry, as `registry.rs` holds it. The app's twin is
5//! `frontend/app/deeplinks/registry-types.ts`; both are generated from
6//! `crates/common/deeplinks/destinations.json` by `scripts/gen-deeplinks.mjs`.
7
8/// What a variable segment, a parameter or an anchor holds.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum Kind {
11    Enum,
12    Id,
13    Slug,
14    Int,
15    Opaque,
16    Path,
17    Name,
18}
19
20/// What showing a view does beyond showing (G1): a view whose effect is not `None` is a worker.
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub enum Effect {
23    None,
24    Starts,
25    Network,
26}
27
28/// What a view shows, which decides who may open and capture it (G5).
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum Sensitivity {
31    Public,
32    Private,
33    Secret,
34    /// Decided by the path (G7).
35    Path,
36    /// As the widget declares.
37    Widget,
38}
39
40/// Whether an agent may open a view by MuxAPI.
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub enum AgentRule {
43    Yes,
44    /// Only its own place (the var or parameter marked `agent_own` names the caller).
45    Own,
46    /// Only an open pane is revealed; nothing is started (G1).
47    Reveal,
48    /// Only a package the person approved.
49    Approved,
50    No,
51}
52
53#[derive(Debug, Clone, Copy, PartialEq, Eq)]
54pub struct EnumValue {
55    pub id: &'static str,
56    pub label_key: &'static str,
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq)]
60pub struct Var {
61    pub name: &'static str,
62    pub kind: Kind,
63    pub values: &'static [EnumValue],
64    pub min: Option<i64>,
65    pub max: Option<i64>,
66    pub agent_own: bool,
67}
68
69#[derive(Debug, Clone, Copy, PartialEq, Eq)]
70pub enum Segment {
71    Lit(&'static str),
72    Var(Var),
73}
74
75#[derive(Debug, Clone, Copy, PartialEq, Eq)]
76pub struct Param {
77    pub name: &'static str,
78    pub kind: Kind,
79    pub label_key: &'static str,
80    pub values: &'static [EnumValue],
81    pub min: Option<i64>,
82    pub max: Option<i64>,
83    /// Allowed only when the place's enum var (`.0`) holds one of these values (`.1`).
84    pub only_with: Option<(&'static str, &'static [&'static str])>,
85    pub agent_own: bool,
86}
87
88#[derive(Debug, Clone, Copy, PartialEq, Eq)]
89pub struct Anchor {
90    pub label_key: &'static str,
91}
92
93#[derive(Debug, Clone, Copy, PartialEq, Eq)]
94pub struct Place {
95    pub id: &'static str,
96    /// None when the place is one enum segment: each value is labelled instead.
97    pub label_key: Option<&'static str>,
98    pub segments: &'static [Segment],
99    /// The enum var is the pane's section (`<view>:section`, R14).
100    pub sections: bool,
101    pub anchor: Option<Anchor>,
102    pub params: &'static [Param],
103}
104
105#[derive(Debug, Clone, Copy, PartialEq, Eq)]
106pub struct View {
107    pub id: &'static str,
108    /// The pane view it opens (block `meta.view`); None for a view that is not a pane.
109    pub pane_view: Option<&'static str>,
110    pub label_key: &'static str,
111    pub icon: &'static str,
112    pub build: u32,
113    pub effect: Effect,
114    pub sensitivity: Sensitivity,
115    pub agent: AgentRule,
116    pub surfaces: &'static [&'static str],
117    pub command: Option<&'static str>,
118    /// The link's view is `<id>.<package>` (a widget).
119    pub prefix: bool,
120    pub requires_place: bool,
121    pub places: &'static [Place],
122}
123
124#[derive(Debug, Clone, Copy, PartialEq, Eq)]
125pub struct Alias {
126    pub from: &'static [&'static str],
127    pub to: &'static [&'static str],
128}
129
130#[derive(Debug, Clone, Copy, PartialEq, Eq)]
131pub struct Unlinked {
132    pub view: &'static str,
133    pub reason: &'static str,
134}
135
136#[derive(Debug)]
137pub struct Registry {
138    pub grammar: u32,
139    /// The build this AgentMux has: a view of a later build is declared and opens nothing.
140    pub build: u32,
141    pub max_bytes: usize,
142    pub separator: &'static str,
143    pub views: &'static [View],
144    pub aliases: &'static [Alias],
145    pub unlinked: &'static [Unlinked],
146    pub errors: &'static [(&'static str, &'static str)],
147}
148
149impl Registry {
150    pub fn view(&self, id: &str) -> Option<&'static View> {
151        self.views.iter().find(|v| v.id == id)
152    }
153
154    /// The sentence a refusal of `code` says.
155    pub fn reason(&self, code: &str) -> &'static str {
156        self.errors.iter().find(|(c, _)| *c == code).map(|(_, r)| *r).unwrap_or("the link is refused")
157    }
158}