Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T03:27:22.147Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

install_cli_binary.rs

145 lines · 5.7 KB · rust
1use super::register_app_scheme;
2use anyhow::Result;
3use gpui::{AppContext as _, AsyncApp, Context, PromptLevel, Window, actions};
4use release_channel::ReleaseChannel;
5use std::ops::Deref;
6use std::path::{Path, PathBuf};
7use util::ResultExt;
8use workspace::notifications::simple_message_notification::MessageNotification;
9use workspace::notifications::{DetachAndPromptErr, NotificationId};
10use workspace::{Toast, Workspace};
11
12actions!(
13    cli,
14    [
15        /// Installs the Omega CLI tool to the system PATH.
16        InstallCliBinary,
17    ]
18);
19
20const CANT_INSTALL_DOCS_URL: &str = "https://zed.dev/docs/macos#cant-install-cli";
21
22/// Attempts to install the CLI symlink. Returns the installed path on success,
23/// or `None` if the user dismissed the macOS administrator authentication
24/// prompt. Returns an error if the install could not be completed, most
25/// commonly because the user is not an admin.
26async fn install_script(cx: &AsyncApp) -> Result<Option<PathBuf>> {
27    let cli_path = cx.update(|cx| cx.path_for_auxiliary_executable("cli"))?;
28    let link_path = Path::new("/usr/local/bin/omega");
29    let bin_dir_path = link_path.parent().unwrap();
30
31    // Don't re-create symlink if it points to the same CLI binary.
32    if smol::fs::read_link(link_path).await.ok().as_ref() == Some(&cli_path) {
33        return Ok(Some(link_path.into()));
34    }
35
36    // If the symlink is not there or is outdated, first try replacing it
37    // without escalating.
38    smol::fs::remove_file(link_path).await.log_err();
39    if smol::fs::unix::symlink(&cli_path, link_path)
40        .await
41        .log_err()
42        .is_some()
43    {
44        return Ok(Some(link_path.into()));
45    }
46
47    // The symlink could not be created without escalating, so use osascript
48    // with admin privileges to create it.
49    let output = smol::process::Command::new("/usr/bin/osascript")
50        .args([
51            "-e",
52            &format!(
53                "do shell script \" \
54                    mkdir -p \'{}\' && \
55                    ln -sf \'{}\' \'{}\' \
56                \" with administrator privileges",
57                bin_dir_path.to_string_lossy(),
58                cli_path.to_string_lossy(),
59                link_path.to_string_lossy(),
60            ),
61        ])
62        .output()
63        .await?;
64
65    if output.status.success() {
66        return Ok(Some(link_path.into()));
67    }
68
69    // osascript reports "User canceled." (error -128) when the administrator
70    // prompt is dismissed. Treat that as a cancellation rather than a failure
71    // so we don't show an error the user already chose to avoid.
72    let stderr = String::from_utf8_lossy(&output.stderr);
73    if stderr.contains("User canceled") || stderr.contains("-128") {
74        return Ok(None);
75    }
76
77    // The privileged write failed, most commonly because the user is not an
78    // admin.
79    anyhow::bail!("error running osascript: {}", stderr.trim());
80}
81
82pub fn install_cli_binary(window: &mut Window, cx: &mut Context<Workspace>) {
83    const LINUX_PROMPT_DETAIL: &str = "If you installed Omega from our official release add ~/.local/bin to your PATH.\n\nIf you installed Omega from a different source like your package manager, then you may need to create an alias/symlink manually.\n\nDepending on your package manager, the CLI might be named omega, omega-editor or something else.";
84
85    cx.spawn_in(window, async move |workspace, cx| {
86        if cfg!(any(target_os = "linux", target_os = "freebsd")) {
87            let prompt = cx.prompt(
88                PromptLevel::Warning,
89                "CLI should already be installed",
90                Some(LINUX_PROMPT_DETAIL),
91                &["OK"],
92            );
93            cx.background_spawn(prompt).detach();
94            return Ok(());
95        }
96        let path = match install_script(cx.deref()).await {
97            Ok(Some(path)) => path,
98            // The user dismissed the administrator prompt; nothing to do.
99            Ok(None) => return Ok(()),
100            Err(error) => {
101                log::error!("failed to install the Omega CLI: {error:#}");
102                workspace.update(cx, |workspace, cx| {
103                    struct CliInstallFailed;
104
105                    workspace.show_notification(
106                        NotificationId::unique::<CliInstallFailed>(),
107                        cx,
108                        |cx| {
109                            cx.new(|cx| {
110                                MessageNotification::new(
111                                    "You can add `omega` to your PATH manually.",
112                                    cx,
113                                )
114                                .with_title("Couldn't install the Omega CLI")
115                                .more_info_message("Show me how")
116                                .more_info_url(CANT_INSTALL_DOCS_URL)
117                            })
118                        },
119                    );
120                })?;
121                return Ok(());
122            }
123        };
124
125        workspace.update_in(cx, |workspace, _, cx| {
126            struct InstalledZedCli;
127
128            workspace.show_toast(
129                Toast::new(
130                    NotificationId::unique::<InstalledZedCli>(),
131                    format!(
132                        "Installed `omega` to {}. You can launch {} from your terminal.",
133                        path.to_string_lossy(),
134                        ReleaseChannel::global(cx).display_name()
135                    ),
136                ),
137                cx,
138            )
139        })?;
140        register_app_scheme(cx).await.log_err();
141        Ok(())
142    })
143    .detach_and_prompt_err("Cannot install the Omega CLI", window, cx, |_, _, _| None);
144}
145
Served at tenant.openagents/omega Member data and write actions are omitted.