mirror of
https://github.com/actionbook/actionbook.git
synced 2026-09-19 03:28:06 +08:00
86905ebe11
* [packages/cli]feat: restore extension browser mode with bridge relay Add a WebSocket bridge server inside the daemon that transparently relays CDP messages between the Chrome extension and CdpSession. Extension mode was removed in v1.0.0; this restores it with minimal changes by reusing the existing cloud-mode CDP connection flow. - daemon/bridge.rs: WS bridge on port 19222, hello handshake with extension origin validation, bidirectional CDP message relay - daemon/server.rs: spawn bridge as tokio task (non-fatal on bind fail) - daemon/registry.rs: store SharedBridgeState for session start access - browser/session/start.rs: execute_extension() reusing cloud CDP flow - setup: unblock extension mode in wizard and --browser flag - CdpSession: zero changes - Extension side: zero changes * [packages/cli]fix: use Extension API for tab discovery in extension mode Extension bridge requires Extension.attachTab before any CDP command can be relayed. Replaced Target.getTargets + Target.attachToTarget with Extension.createTab / Extension.attachActiveTab flow. Added CdpSession.register_extension_tab() to register tabs without CDP flat-session handshake. Local and cloud modes are unaffected. * [packages/cli]fix: close tabs and detach debugger in extension mode Session close and close-tab now use Extension.closeTab / Extension.detachTab in extension mode instead of Target.closeTarget which the bridge doesn't support. Added Extension.closeTab to the extension that detaches the debugger and removes the tab via chrome.tabs.remove. Local and cloud modes are unaffected. * [packages/cli]fix: revert extension JS change, use detachTab for close Extension is loaded from CWS — local JS changes don't take effect. Reverted Extension.closeTab addition to background.js. Session close and close-tab now use Extension.detachTab to release the debugger in extension mode. Tabs are left open since CLI doesn't own the browser. * [packages/cli]fix: read default browser mode from config instead of hardcoding Local When --mode is not specified, browser start now reads browser.mode from config.toml (e.g. mode = "extension") instead of always falling back to Local mode. This allows users with extension mode configured to connect to their existing browser without explicitly passing --mode extension. * [packages/cli]fix: build.rs track branch ref for accurate BUILD_VERSION in worktrees build.rs only watched .git/HEAD which doesn't change on new commits in a worktree (it stays as ref: refs/heads/branch-name). This caused stale BUILD_VERSION, preventing daemon version-mismatch detection when the npm-installed binary shared the same cached hash. Now also watches the actual ref file and packed-refs via --git-common-dir so BUILD_VERSION updates on every new commit. Also adds a guard in start.rs Local mode section to reject non-Local modes explicitly instead of silently launching a local Chrome. * [packages/cli]fix: clippy/fmt fixes and reject concurrent CDP clients in bridge - Fix rustfmt formatting (collapsed if chains, import order, line width) - Fix clippy collapsible-if warnings - Reject concurrent CDP clients in bridge relay to prevent response channel hijacking between sessions * [packages/cli]fix: suppress result_large_err for accept_hdr_async callback The closure signature is dictated by tokio-tungstenite's API and cannot use Box<Err>. Allow the lint on this specific closure. * [root]chore: add changeset for CLI v1.2.0 (extension mode restore)
67 lines
2.4 KiB
Rust
67 lines
2.4 KiB
Rust
fn main() {
|
|
let hash = std::process::Command::new("git")
|
|
.args(["rev-parse", "--short", "HEAD"])
|
|
.output()
|
|
.ok()
|
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
.unwrap_or_default()
|
|
.trim()
|
|
.to_string();
|
|
|
|
let pkg_version = std::env::var("CARGO_PKG_VERSION").unwrap_or_default();
|
|
let build_version = if hash.is_empty() {
|
|
pkg_version
|
|
} else {
|
|
format!("{pkg_version}-{hash}")
|
|
};
|
|
|
|
println!("cargo:rustc-env=BUILD_VERSION={build_version}");
|
|
|
|
// Track git state so BUILD_VERSION updates on new commits.
|
|
//
|
|
// In a worktree, `git rev-parse --git-dir` returns something like
|
|
// `.git/worktrees/<name>`. The HEAD file there is a ref pointer
|
|
// (e.g. `ref: refs/heads/branch-name`) and doesn't change on new
|
|
// commits. We must ALSO watch the packed-refs and the actual ref file
|
|
// so that cargo reruns build.rs when the branch tip moves.
|
|
let git_dir = std::process::Command::new("git")
|
|
.args(["rev-parse", "--git-dir"])
|
|
.output()
|
|
.ok()
|
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
.unwrap_or_default()
|
|
.trim()
|
|
.to_string();
|
|
|
|
let git_common_dir = std::process::Command::new("git")
|
|
.args(["rev-parse", "--git-common-dir"])
|
|
.output()
|
|
.ok()
|
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
.unwrap_or_default()
|
|
.trim()
|
|
.to_string();
|
|
|
|
if !git_dir.is_empty() {
|
|
// HEAD itself (detects branch switches)
|
|
println!("cargo:rerun-if-changed={git_dir}/HEAD");
|
|
|
|
// Read HEAD to find the ref it points to, then watch that ref file.
|
|
// This ensures build.rs reruns when a new commit is added to the branch.
|
|
if let Ok(head_content) = std::fs::read_to_string(format!("{git_dir}/HEAD")) {
|
|
let head_content = head_content.trim();
|
|
if let Some(ref_path) = head_content.strip_prefix("ref: ") {
|
|
// Watch the loose ref in the common git dir (handles worktrees)
|
|
let common = if git_common_dir.is_empty() {
|
|
&git_dir
|
|
} else {
|
|
&git_common_dir
|
|
};
|
|
println!("cargo:rerun-if-changed={common}/{ref_path}");
|
|
// Also watch packed-refs since the ref might be packed
|
|
println!("cargo:rerun-if-changed={common}/packed-refs");
|
|
}
|
|
}
|
|
}
|
|
}
|