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