Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T03:10:38.557Z 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

headless.rs

144 lines · 5.0 KB · rust
1use std::path::PathBuf;
2use std::sync::Arc;
3
4use client::{Client, ProxySettings, RefreshLlmTokenListener, UserStore};
5use db::AppDatabase;
6use extension::ExtensionHostProxy;
7use fs::RealFs;
8use gpui::http_client::read_proxy_from_env;
9use gpui::{App, AppContext as _, Entity};
10use gpui_tokio::Tokio;
11use language::LanguageRegistry;
12use language_extension::LspAccess;
13use node_runtime::{NodeBinaryOptions, NodeRuntime};
14use project::project_settings::ProjectSettings;
15use prompt_store::PromptBuilder;
16use release_channel::{AppCommitSha, AppVersion};
17use reqwest_client::ReqwestClient;
18use settings::{Settings, SettingsStore};
19use util::ResultExt as _;
20
21pub struct AgentCliAppState {
22    pub languages: Arc<LanguageRegistry>,
23    pub client: Arc<Client>,
24    pub user_store: Entity<UserStore>,
25    pub fs: Arc<dyn fs::Fs>,
26    pub node_runtime: NodeRuntime,
27}
28
29pub fn init(cx: &mut App) -> Arc<AgentCliAppState> {
30    let app_commit_sha = option_env!("ZED_COMMIT_SHA").map(|s| AppCommitSha::new(s.to_owned()));
31
32    let app_version = AppVersion::load(
33        env!("ZED_PKG_VERSION"),
34        option_env!("ZED_BUILD_ID"),
35        app_commit_sha,
36    );
37
38    release_channel::init(app_version.clone(), cx);
39    gpui_tokio::init(cx);
40
41    let settings_store = SettingsStore::new(cx, &settings::default_settings());
42    cx.set_global(settings_store);
43    theme_settings::init(theme::LoadThemes::JustBase, cx);
44
45    let user_agent = format!(
46        "Omega Agent CLI/{} ({}; {})",
47        app_version,
48        std::env::consts::OS,
49        std::env::consts::ARCH
50    );
51    let proxy_str = ProxySettings::get_global(cx).proxy.to_owned();
52    let proxy_url = proxy_str
53        .as_ref()
54        .and_then(|input| input.parse().ok())
55        .or_else(read_proxy_from_env);
56    let http = {
57        let _guard = Tokio::handle(cx).enter();
58        ReqwestClient::proxy_and_user_agent(proxy_url, &user_agent)
59            .expect("could not start HTTP client")
60    };
61    cx.set_http_client(Arc::new(http));
62
63    let client = Client::production(cx);
64    cx.set_http_client(client.http_client());
65
66    let app_db = AppDatabase::new();
67    cx.set_global(app_db);
68
69    let git_binary_path = None;
70    let fs = Arc::new(RealFs::new(
71        git_binary_path,
72        cx.background_executor().clone(),
73    ));
74    <dyn fs::Fs>::set_global(fs.clone(), cx);
75
76    let mut languages = LanguageRegistry::new(cx.background_executor().clone());
77    languages.set_language_server_download_dir(paths::languages_dir().clone());
78    let languages = Arc::new(languages);
79
80    let user_store = cx.new(|cx| UserStore::new(client.clone(), cx));
81
82    extension::init(cx);
83
84    let (mut node_options_tx, node_options_rx) = watch::channel(None);
85    cx.observe_global::<SettingsStore>(move |cx| {
86        let settings = &ProjectSettings::get_global(cx).node;
87        let options = NodeBinaryOptions {
88            allow_path_lookup: !settings.ignore_system_version,
89            allow_binary_download: true,
90            use_paths: settings.path.as_ref().map(|node_path| {
91                let node_path = PathBuf::from(shellexpand::tilde(node_path).as_ref());
92                let npm_path = settings
93                    .npm_path
94                    .as_ref()
95                    .map(|path| PathBuf::from(shellexpand::tilde(&path).as_ref()));
96                (
97                    node_path.clone(),
98                    npm_path.unwrap_or_else(|| {
99                        let base_path = PathBuf::new();
100                        node_path.parent().unwrap_or(&base_path).join("npm")
101                    }),
102                )
103            }),
104        };
105        node_options_tx.send(Some(options)).log_err();
106    })
107    .detach();
108    let node_runtime = NodeRuntime::new(client.http_client(), None, node_options_rx);
109
110    let extension_host_proxy = ExtensionHostProxy::global(cx);
111    debug_adapter_extension::init(extension_host_proxy.clone(), cx);
112    language_extension::init(LspAccess::Noop, extension_host_proxy, languages.clone());
113    language_model::init(cx);
114    RefreshLlmTokenListener::register(client.clone(), user_store.clone(), cx);
115    language_models::init(user_store.clone(), client.clone(), cx);
116    languages::init(languages.clone(), fs.clone(), node_runtime.clone(), cx);
117    prompt_store::init(cx);
118    terminal_view::init(cx);
119
120    // The eval CLI runs headless with no controlling TTY, so PTY allocation and
121    // acquiring a controlling terminal fail with `ENOTTY`. Tell the agent to run
122    // its terminal commands without a PTY (and non-interactively) instead.
123    cx.set_global(acp_thread::HeadlessTerminal(true));
124
125    let stdout_is_a_pty = false;
126    let prompt_builder = PromptBuilder::load(fs.clone(), stdout_is_a_pty, cx);
127    agent_ui::init(
128        fs.clone(),
129        prompt_builder,
130        languages.clone(),
131        true,
132        true,
133        cx,
134    );
135
136    Arc::new(AgentCliAppState {
137        languages,
138        client,
139        user_store,
140        fs,
141        node_runtime,
142    })
143}
144
Served at tenant.openagents/omega Member data and write actions are omitted.