Skip to repository content108 lines · 3.7 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T04:26:26.352Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
cli.rs
1use std::path::PathBuf;
2
3use anyhow::Result;
4use collections::HashMap;
5pub use ipc_channel::ipc;
6use serde::{Deserialize, Serialize};
7
8pub mod uninstall;
9
10#[derive(Serialize, Deserialize)]
11pub struct IpcHandshake {
12 pub requests: ipc::IpcSender<CliRequest>,
13 pub responses: ipc::IpcReceiver<CliResponse>,
14}
15
16/// Controls how CLI paths are opened — whether to reuse existing windows,
17/// create new ones, or add to the sidebar.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
19#[serde(rename_all = "snake_case")]
20pub enum OpenBehavior {
21 /// Consult the user's `cli_default_open_behavior` setting.
22 #[default]
23 Default,
24 /// Always create a new window. No matching against existing worktrees.
25 /// Corresponds to `zed -n`.
26 AlwaysNew,
27 /// Create a new window unless opening a subpath of an existing project.
28 PreferNewWindow,
29 /// Match broadly including subdirectories, and fall back to any existing
30 /// window if no worktree matched. Corresponds to `zed -a`.
31 Add,
32 /// Open directories as a new workspace in the current Zed window's sidebar.
33 /// Reuse existing windows for files in open worktrees.
34 /// Corresponds to `zed -e`.
35 ExistingWindow,
36 /// New window for directories, reuse existing window for files in open
37 /// worktrees. The classic pre-sidebar behavior.
38 /// Corresponds to `zed --classic`.
39 Classic,
40 /// Replace the content of an existing window with a new workspace.
41 /// Corresponds to `zed -r`.
42 Reuse,
43}
44
45/// The setting-level enum for configuring default behavior. This only has
46/// two values because the other modes are always explicitly requested via
47/// CLI flags.
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
49#[serde(rename_all = "snake_case")]
50pub enum CliBehaviorSetting {
51 /// Open directories as a new workspace in the current Zed window's sidebar.
52 ExistingWindow,
53 /// Open paths in a new window unless they are subpaths of an existing project.
54 NewWindow,
55}
56
57#[derive(Debug, Serialize, Deserialize)]
58pub enum CliRequest {
59 Open {
60 paths: Vec<String>,
61 urls: Vec<String>,
62 diff_paths: Vec<[String; 2]>,
63 diff_all: bool,
64 wsl: Option<String>,
65 wait: bool,
66 #[serde(default)]
67 open_behavior: OpenBehavior,
68 env: Option<HashMap<String, String>>,
69 user_data_dir: Option<String>,
70 dev_container: bool,
71 #[serde(default)]
72 cwd: Option<PathBuf>,
73 },
74 SetOpenBehavior {
75 behavior: CliBehaviorSetting,
76 },
77}
78
79#[derive(Debug, Serialize, Deserialize)]
80pub enum CliResponse {
81 Ping,
82 Stdout { message: String },
83 Stderr { message: String },
84 Exit { status: i32 },
85 PromptOpenBehavior,
86}
87
88/// When Zed started not as an *.app but as a binary (e.g. local development),
89/// there's a possibility to tell it to behave "regularly".
90///
91/// Note that in the main zed binary, this variable is unset after it's read for the first time,
92/// therefore it should always be accessed through the `FORCE_CLI_MODE` static.
93pub const FORCE_CLI_MODE_ENV_VAR_NAME: &str = "ZED_FORCE_CLI_MODE";
94
95/// Abstracts the transport for sending CLI responses (Zed → CLI).
96///
97/// Production code uses `IpcSender<CliResponse>`. Tests can provide in-memory
98/// implementations to avoid OS-level IPC.
99pub trait CliResponseSink: Send + 'static {
100 fn send(&self, response: CliResponse) -> Result<()>;
101}
102
103impl CliResponseSink for ipc::IpcSender<CliResponse> {
104 fn send(&self, response: CliResponse) -> Result<()> {
105 ipc::IpcSender::send(self, response).map_err(|error| anyhow::anyhow!("{error}"))
106 }
107}
108