Skip to content

Commit b393d67

Browse files
feat(desktop): default to control-chrome executable without npx (anomalyco#534)
1 parent 0b3c9ae commit b393d67

7 files changed

Lines changed: 88 additions & 13 deletions

File tree

‎.opencode/skills/browser-setup-devtools/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ description: Guide users through browser automation setup using Chrome DevTools
2424
4. If DevTools MCP calls fail:
2525
- Ask the user to open Chrome and keep it running.
2626
- Retry `chrome-devtools_list_pages`.
27-
- If it still fails, ensure `opencode.jsonc` includes `mcp.chrome-devtools` with command `['npx','-y','chrome-devtools-mcp@latest']` and ask the user to restart OpenWork/OpenCode.
27+
- If it still fails, ensure `opencode.jsonc` includes `mcp.control-chrome` with command `['chrome-devtools-mcp']` and ask the user to restart OpenWork/OpenCode.
2828
- Retry the DevTools MCP check.
2929
5. If DevTools MCP is ready:
3030
- Offer a first task ("Let's try opening a webpage").

‎opencode.jsonc‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{
22
"$schema": "https://opencode.ai/config.json",
33
"mcp": {
4-
"chrome-devtools": {
4+
"control-chrome": {
55
"type": "local",
66
"command": [
7-
"npx",
8-
"-y",
9-
"chrome-devtools-mcp@latest"
7+
"chrome-devtools-mcp"
108
]
119
}
1210
},

‎packages/app/src/app/constants.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ export const MCP_QUICK_CONNECT: McpDirectoryInfo[] = [
7575
oauth: false,
7676
},
7777
{
78-
name: "Chrome DevTools",
78+
name: "Control Chrome",
7979
description: "Drive Chrome tabs with browser automation.",
8080
type: "local",
81-
command: ["npx", "-y", "chrome-devtools-mcp@latest"],
81+
command: ["chrome-devtools-mcp"],
8282
oauth: false,
8383
},
8484
];

‎packages/desktop/src-tauri/src/engine/spawn.rs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::path::Path;
22

33
use tauri::async_runtime::Receiver;
4-
use tauri::AppHandle;
4+
use tauri::{AppHandle, Manager};
55
use tauri_plugin_shell::process::{CommandChild, CommandEvent};
66
use tauri_plugin_shell::ShellExt;
77

88
use crate::paths::{candidate_xdg_config_dirs, candidate_xdg_data_dirs, maybe_infer_xdg_home};
9+
use crate::paths::{prepended_path_env, sidecar_path_candidates};
910

1011
pub fn find_free_port() -> Result<u16, String> {
1112
let listener = std::net::TcpListener::bind(("127.0.0.1", 0)).map_err(|e| e.to_string())?;
@@ -77,6 +78,16 @@ pub fn spawn_engine(
7778
command = command.env("OPENCODE_CLIENT", "openwork");
7879
command = command.env("OPENWORK", "1");
7980

81+
let resource_dir = app.path().resource_dir().ok();
82+
let current_bin_dir = tauri::process::current_binary(&app.env())
83+
.ok()
84+
.and_then(|path| path.parent().map(|parent| parent.to_path_buf()));
85+
let sidecar_paths =
86+
sidecar_path_candidates(resource_dir.as_deref(), current_bin_dir.as_deref());
87+
if let Some(path_env) = prepended_path_env(&sidecar_paths) {
88+
command = command.env("PATH", path_env);
89+
}
90+
8091
if let Some(username) = opencode_username {
8192
if !username.trim().is_empty() {
8293
command = command.env("OPENCODE_SERVER_USERNAME", username);

‎packages/desktop/src-tauri/src/openwrk/mod.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use std::path::{Path, PathBuf};
44

55
use serde::de::DeserializeOwned;
66
use serde::{Deserialize, Serialize};
7-
use tauri::AppHandle;
7+
use tauri::{AppHandle, Manager};
88
use tauri_plugin_shell::process::{CommandChild, CommandEvent};
99
use tauri_plugin_shell::ShellExt;
1010

1111
use crate::paths::home_dir;
12+
use crate::paths::{prepended_path_env, sidecar_path_candidates};
1213
use crate::types::{
1314
OpenwrkBinaryState, OpenwrkDaemonState, OpenwrkOpencodeState, OpenwrkSidecarInfo,
1415
OpenwrkStatus, OpenwrkWorkspace,
@@ -237,8 +238,19 @@ pub fn spawn_openwrk_daemon(
237238
}
238239
}
239240

241+
let mut command = command.args(args);
242+
243+
let resource_dir = app.path().resource_dir().ok();
244+
let current_bin_dir = tauri::process::current_binary(&app.env())
245+
.ok()
246+
.and_then(|path| path.parent().map(|parent| parent.to_path_buf()));
247+
let sidecar_paths =
248+
sidecar_path_candidates(resource_dir.as_deref(), current_bin_dir.as_deref());
249+
if let Some(path_env) = prepended_path_env(&sidecar_paths) {
250+
command = command.env("PATH", path_env);
251+
}
252+
240253
command
241-
.args(args)
242254
.spawn()
243255
.map_err(|e| format!("Failed to start openwrk: {e}"))
244256
}

‎packages/desktop/src-tauri/src/paths.rs‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,57 @@ pub fn resolve_in_path(name: &str) -> Option<PathBuf> {
9090
}
9191
None
9292
}
93+
94+
pub fn sidecar_path_candidates(
95+
resource_dir: Option<&Path>,
96+
current_bin_dir: Option<&Path>,
97+
) -> Vec<PathBuf> {
98+
let mut candidates = Vec::new();
99+
100+
if let Some(current_bin_dir) = current_bin_dir {
101+
candidates.push(current_bin_dir.to_path_buf());
102+
}
103+
104+
if let Some(resource_dir) = resource_dir {
105+
candidates.push(resource_dir.join("sidecars"));
106+
candidates.push(resource_dir.to_path_buf());
107+
}
108+
109+
candidates.push(PathBuf::from("src-tauri/sidecars"));
110+
111+
let mut unique = Vec::new();
112+
for candidate in candidates {
113+
if !candidate.is_dir() {
114+
continue;
115+
}
116+
if unique
117+
.iter()
118+
.any(|existing: &PathBuf| existing == &candidate)
119+
{
120+
continue;
121+
}
122+
unique.push(candidate);
123+
}
124+
125+
unique
126+
}
127+
128+
pub fn prepended_path_env(prefixes: &[PathBuf]) -> Option<std::ffi::OsString> {
129+
let mut entries = Vec::<PathBuf>::new();
130+
131+
for prefix in prefixes {
132+
if prefix.is_dir() {
133+
entries.push(prefix.clone());
134+
}
135+
}
136+
137+
if let Some(existing) = env::var_os("PATH") {
138+
entries.extend(env::split_paths(&existing));
139+
}
140+
141+
if entries.is_empty() {
142+
return None;
143+
}
144+
145+
env::join_paths(entries).ok()
146+
}

‎packages/desktop/src-tauri/src/workspace/files.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,12 @@ pub fn ensure_workspace_files(workspace_path: &str, preset: &str) -> Result<(),
460460
_ => serde_json::Map::new(),
461461
};
462462

463-
if !mcp_obj.contains_key("chrome-devtools") {
463+
if !mcp_obj.contains_key("control-chrome") {
464464
mcp_obj.insert(
465-
"chrome-devtools".to_string(),
465+
"control-chrome".to_string(),
466466
serde_json::json!({
467467
"type": "local",
468-
"command": ["npx", "-y", "chrome-devtools-mcp@latest"]
468+
"command": ["chrome-devtools-mcp"]
469469
}),
470470
);
471471
config_changed = true;

0 commit comments

Comments
 (0)