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",
31    "edit-field",
32    "move",
33    "wire",
34    "unwire",
35    "create",
36    "delete",
37    "invoke",
38    "dismiss",
39    "set-lens",
40    "set-mode",
41    "open",
42    "commit",
43    "cancel",
44    "scrub",
45    "set-param",
46    "performance-event",
47    "piano-roll-edit",
48    "player-rack-edit",
49    "arranger-edit",
50    "approve",
51    "reject",
52    "ask",
53    "split-mission",
54    "pause-agent",
55    "rerun-validation",
56    "replay-cassette",
57    "open-source",
58];
59
60/// The qualified symbol for an Intent kind name, e.g. `intent/wire`.
61pub fn intent_kind(name: &str) -> Symbol {
62    Symbol::qualified(INTENT_NAMESPACE, name)
63}
64
65/// Is `name` a recognized baseline Intent kind (local part only)?
66pub fn is_known_kind_name(name: &str) -> bool {
67    INTENT_KINDS.contains(&name)
68}
69
70/// Is `symbol` a recognized baseline Intent kind (`intent/<known>`)?
71pub fn is_known_kind(symbol: &Symbol) -> bool {
72    symbol.namespace.as_deref() == Some(INTENT_NAMESPACE) && is_known_kind_name(&symbol.name)
73}
74
75/// The fields a given Intent kind must carry (besides `kind` and `origin`).
76pub fn required_fields(kind_name: &str) -> &'static [&'static str] {
77    match kind_name {
78        "tap" => &["target", "control"],
79        "select" => &["targets"],
80        "edit" => &["target", "path"],
81        "edit-field" => &["target", "path", "value"],
82        "move" => &["node", "at"],
83        "wire" => &["from", "to"],
84        "unwire" => &["edge"],
85        "create" => &["class", "at", "args"],
86        "delete" => &["targets"],
87        "invoke" => &["target", "op", "args"],
88        "dismiss" => &[],
89        "set-lens" => &["pane", "lens"],
90        "set-mode" => &["mode"],
91        "open" => &["value", "pane"],
92        "commit" => &["pane"],
93        "cancel" => &["pane"],
94        "scrub" => &["target", "at"],
95        "set-param" => &["target", "param", "value"],
96        "performance-event" => &["target", "source", "input", "event"],
97        "piano-roll-edit" => &["target", "action"],
98        "player-rack-edit" => &["target", "action"],
99        "arranger-edit" => &["target", "action"],
100        "approve" => &["mission"],
101        "reject" => &["mission"],
102        "ask" => &["mission", "question"],
103        "split-mission" => &["mission", "goals"],
104        "pause-agent" => &["mission"],
105        "rerun-validation" => &["mission"],
106        "replay-cassette" => &["mission", "at"],
107        "open-source" => &["location"],
108        _ => &[],
109    }
110}