kernel/intents.rs
1// Copyright 2026 Mark AB (markik)
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Portable intent vocabulary primitives — the pure-data subset of
5//! the intent enum/struct family that's free of `crate::app::*`,
6//! `crate::shell::desktop::workbench::*`, and `crate::services::*`
7//! coupling.
8//!
9//! Slice 57 ("the wedge"). The full intent vocabulary in
10//! `app/intents.rs` (1882 LOC, 1308 external usages) carries
11//! workbench / services entanglement that requires multiple
12//! pre-cleanups before promotion. This module ships the cleanly
13//! portable primitives now so they can be referenced from registrar
14//! crates and graph crates without going through the binary root.
15//!
16//! Promotion roadmap (subsequent slices, when their pre-cleanups
17//! land):
18//!
19//! - Slice 57b: `AppCommand` (after workbench types portable)
20//! - Slice 57c: `GraphMutation` + `GraphIntent` (after services
21//! types portable)
22//! - Slice 57d: `RuntimeEvent` + `ViewAction` + `NavigatorProjectionIntent`
23//!
24//! Until those land, the in-tree `app/intents.rs` re-exports the
25//! types here so existing call sites resolve unchanged.
26
27use std::path::PathBuf;
28
29use crate::graph::NodeKey;
30
31/// Browser-shell command — back / forward / reload / stop / zoom / close.
32/// Targets a single browser surface (focused viewer, chrome projection).
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum BrowserCommand {
35 Back,
36 Forward,
37 Reload,
38 StopLoad,
39 ZoomIn,
40 ZoomOut,
41 ZoomReset,
42 Close,
43}
44
45impl BrowserCommand {
46 /// Stable lowercase tag used in diagnostic channel payloads.
47 pub fn diagnostic_label(self) -> &'static str {
48 match self {
49 BrowserCommand::Back => "back",
50 BrowserCommand::Forward => "forward",
51 BrowserCommand::Reload => "reload",
52 BrowserCommand::StopLoad => "stop_load",
53 BrowserCommand::ZoomIn => "zoom_in",
54 BrowserCommand::ZoomOut => "zoom_out",
55 BrowserCommand::ZoomReset => "zoom_reset",
56 BrowserCommand::Close => "close",
57 }
58 }
59}
60
61/// Where a [`BrowserCommand`] should land — the focused-input
62/// surface or the chrome projection (with an optional fallback node
63/// when no chrome is active).
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub enum BrowserCommandTarget {
66 FocusedInput,
67 ChromeProjection { fallback_node: Option<NodeKey> },
68}
69
70/// Spec for a user-supplied stylesheet that the runtime should apply
71/// across viewers. The path is the source-of-truth identity; the
72/// `source` is the loaded contents at the time of the intent (so the
73/// intent is self-contained even if the file changes underneath).
74#[derive(Debug, Clone, PartialEq, Eq)]
75pub struct RuntimeUserStylesheetSpec {
76 pub path: PathBuf,
77 pub source: String,
78}
79
80/// Edge-mutation command vocabulary. The pair-shaped variants carry
81/// explicit endpoints so the receiver doesn't need to inspect a
82/// selection set; the bare variants act on the current selection.
83#[derive(Debug, Clone, PartialEq, Eq)]
84pub enum EdgeCommand {
85 ConnectSelectedPair,
86 ConnectPair { from: NodeKey, to: NodeKey },
87 ConnectBothDirections,
88 ConnectBothDirectionsPair { a: NodeKey, b: NodeKey },
89 RemoveUserEdge,
90 RemoveUserEdgePair { a: NodeKey, b: NodeKey },
91 PinSelected,
92 UnpinSelected,
93}