Skip to main content

sim_lib_intent/
kinds.rs

1//! Intent kinds and their required fields.
2//!
3//! An Intent is an `Expr::Map` tagged with a `kind` symbol in the `intent`
4//! namespace (for example `intent/wire`). Kinds are open metadata, not a closed
5//! kernel enum. This module lists the baseline Intent kinds and the fields each
6//! kind must carry, which the validator uses to fail closed on a malformed
7//! Intent.
8
9use sim_kernel::Symbol;
10
11/// The namespace every Intent `kind` symbol lives in.
12pub const INTENT_NAMESPACE: &str = "intent";
13
14/// The map key that tags an Intent with its kind.
15pub const KIND_KEY: &str = "kind";
16
17/// The map key carrying the Intent origin (operator + logical tick).
18pub const ORIGIN_KEY: &str = "origin";
19
20/// The origin sub-key naming the operator (`human` or `agent`).
21pub const OPERATOR_KEY: &str = "operator";
22
23/// The origin sub-key carrying the logical tick.
24pub const AT_TICK_KEY: &str = "at-tick";
25
26/// The baseline Intent kind names (the local part of the `intent/*` symbol).
27pub const INTENT_KINDS: &[&str] = &[
28    "tap",
29    "select",
30    "edit-field",
31    "move",
32    "wire",
33    "unwire",
34    "create",
35    "delete",
36    "invoke",
37    "set-lens",
38    "set-mode",
39    "open",
40    "commit",
41    "cancel",
42    "scrub",
43    "set-param",
44    "performance-event",
45    "piano-roll-edit",
46    "player-rack-edit",
47    "arranger-edit",
48    "approve",
49    "reject",
50    "ask",
51    "split-mission",
52    "pause-agent",
53    "rerun-validation",
54    "replay-cassette",
55    "open-source",
56];
57
58/// The qualified symbol for an Intent kind name, e.g. `intent/wire`.
59pub fn intent_kind(name: &str) -> Symbol {
60    Symbol::qualified(INTENT_NAMESPACE, name)
61}
62
63/// Is `name` a recognized baseline Intent kind (local part only)?
64pub fn is_known_kind_name(name: &str) -> bool {
65    INTENT_KINDS.contains(&name)
66}
67
68/// Is `symbol` a recognized baseline Intent kind (`intent/<known>`)?
69pub fn is_known_kind(symbol: &Symbol) -> bool {
70    symbol.namespace.as_deref() == Some(INTENT_NAMESPACE) && is_known_kind_name(&symbol.name)
71}
72
73/// The fields a given Intent kind must carry (besides `kind` and `origin`).
74pub fn required_fields(kind_name: &str) -> &'static [&'static str] {
75    match kind_name {
76        "tap" => &["target", "control"],
77        "select" => &["targets"],
78        "edit-field" => &["target", "path", "value"],
79        "move" => &["node", "at"],
80        "wire" => &["from", "to"],
81        "unwire" => &["edge"],
82        "create" => &["class", "at", "args"],
83        "delete" => &["targets"],
84        "invoke" => &["target", "op", "args"],
85        "set-lens" => &["pane", "lens"],
86        "set-mode" => &["mode"],
87        "open" => &["value", "pane"],
88        "commit" => &["pane"],
89        "cancel" => &["pane"],
90        "scrub" => &["target", "at"],
91        "set-param" => &["target", "param", "value"],
92        "performance-event" => &["target", "source", "input", "event"],
93        "piano-roll-edit" => &["target", "action"],
94        "player-rack-edit" => &["target", "action"],
95        "arranger-edit" => &["target", "action"],
96        "approve" => &["mission"],
97        "reject" => &["mission"],
98        "ask" => &["mission", "question"],
99        "split-mission" => &["mission", "goals"],
100        "pause-agent" => &["mission"],
101        "rerun-validation" => &["mission"],
102        "replay-cassette" => &["mission", "at"],
103        "open-source" => &["location"],
104        _ => &[],
105    }
106}