byob_protocol/env.rs
1//! Workspace environments as clients see them: whether byob loads the workspace's own
2//! environment (flake.nix, pixi.toml, …), and whether its commands run in a container.
3
4use serde::{Deserialize, Serialize};
5
6/// Ask for the [`WorkspaceEnv`] of the chat in view, optionally changing it first.
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(tag = "kind", rename_all = "snake_case")]
9pub enum EnvAction {
10 /// Remember whether to load the workspace's project environment (`None`: forget the
11 /// answer, so byob asks again next time).
12 ProjectEnv { load: Option<bool> },
13 /// Run this workspace's commands in a container (`None`: forget, ask again if it has a
14 /// devcontainer.json).
15 Container { on: Option<bool> },
16 /// Stop the workspace's container (it starts again on the next command).
17 StopContainer,
18 /// Remove the workspace's container (packages installed in it are lost).
19 RemoveContainer,
20}
21
22/// One workspace's environment settings and state.
23#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
24pub struct WorkspaceEnv {
25 pub workspace: String,
26 /// Project files byob can load an environment from, e.g. `flake.nix`, `pixi.toml`.
27 #[serde(default)]
28 pub project_files: Vec<String>,
29 /// The remembered answer: load it (`true`), don't (`false`), or ask (`None`).
30 #[serde(default)]
31 pub project_env: Option<bool>,
32 /// `BYOB_WORKSPACE_ENV` overrides the answer (`off`/`on`), for display.
33 #[serde(default, skip_serializing_if = "Option::is_none")]
34 pub project_env_forced: Option<bool>,
35 /// What `install_packages` uses here ("Nix", "pixi"), if anything.
36 #[serde(default)]
37 pub installer: Option<String>,
38 #[serde(default)]
39 pub container: ContainerEnv,
40 /// What the last [`EnvAction`] did, or why it failed.
41 #[serde(default, skip_serializing_if = "Option::is_none")]
42 pub message: Option<String>,
43 #[serde(default)]
44 pub failed: bool,
45}
46
47/// What the engine's machine offers for workspace environments.
48#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
49pub struct EnvSupport {
50 /// Nix is installed (the Nix environment loads a folder's dev shell).
51 #[serde(default)]
52 pub nix: bool,
53 /// What `install_packages` uses ("Nix", "pixi"), if anything.
54 #[serde(default)]
55 pub installer: Option<String>,
56 /// "docker" or "podman", if one is installed.
57 #[serde(default)]
58 pub runtime: Option<String>,
59}
60
61/// The container side of a [`WorkspaceEnv`].
62#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
63pub struct ContainerEnv {
64 /// "docker" or "podman", if one is installed.
65 #[serde(default)]
66 pub runtime: Option<String>,
67 /// The workspace's `.devcontainer/devcontainer.json` (or `.devcontainer.json`), if any.
68 #[serde(default)]
69 pub devcontainer: Option<String>,
70 /// The remembered choice: commands run in the container (`true`), on this machine
71 /// (`false`), or not decided (`None`; asked if there's a devcontainer.json).
72 #[serde(default)]
73 pub use_container: Option<bool>,
74 /// The image it uses (from devcontainer.json, else the default).
75 #[serde(default)]
76 pub image: String,
77 /// The container's state ("running", "exited", …); `None` if there is none.
78 #[serde(default)]
79 pub state: Option<String>,
80}