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