From 1f7ee4c5254fb99ed2e2ca476383e1eafe7d645a Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Sun, 11 Jan 2026 23:53:29 -0600 Subject: [PATCH] fix session cmd --- .github/workflows/ci.yml | 85 ++++++++++++++++++++++++++++++++++++++++ cli/src/main.rs | 69 ++++++++++++++++++++++++++++++++ cli/src/output.rs | 4 ++ 3 files changed, 158 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a941286 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,85 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + typescript: + name: TypeScript (Node ${{ matrix.node-version }}) + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20, 22] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 + + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: pnpm + + - name: Install dependencies + run: pnpm install + + - name: Typecheck + run: pnpm typecheck + + - name: Format check + run: pnpm format:check + + - name: Install Playwright browsers + run: pnpm exec playwright install --with-deps chromium + + - name: Run tests + run: pnpm test + + rust: + name: Rust (${{ matrix.os }} - ${{ matrix.target }}) + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: macos-latest + target: aarch64-apple-darwin + - os: macos-latest + target: x86_64-apple-darwin + - os: windows-latest + target: x86_64-pc-windows-msvc + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - name: Cache Cargo dependencies + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + cli/target/ + key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('cli/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-${{ matrix.target }}- + + - name: Build release binary + run: cargo build --release --manifest-path cli/Cargo.toml --target ${{ matrix.target }} diff --git a/cli/src/main.rs b/cli/src/main.rs index cb0f767..8eec97e 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -6,6 +6,7 @@ mod output; use serde_json::json; use std::env; +use std::fs; use std::process::exit; use commands::{gen_id, parse_command, ParseError}; @@ -14,6 +15,68 @@ use flags::{clean_args, parse_flags}; use install::run_install; use output::{print_help, print_response}; +fn run_session(args: &[String], session: &str, json_mode: bool) { + let subcommand = args.get(1).map(|s| s.as_str()); + + match subcommand { + Some("list") => { + let tmp = env::temp_dir(); + let mut sessions: Vec = Vec::new(); + + if let Ok(entries) = fs::read_dir(&tmp) { + for entry in entries.flatten() { + let name = entry.file_name().to_string_lossy().to_string(); + // Look for socket files (Unix) or pid files + if name.starts_with("agent-browser-") && name.ends_with(".pid") { + let session_name = name + .strip_prefix("agent-browser-") + .and_then(|s| s.strip_suffix(".pid")) + .unwrap_or(""); + if !session_name.is_empty() { + // Check if session is actually running + let pid_path = tmp.join(&name); + if let Ok(pid_str) = fs::read_to_string(&pid_path) { + if let Ok(pid) = pid_str.trim().parse::() { + #[cfg(unix)] + let running = unsafe { libc::kill(pid, 0) == 0 }; + #[cfg(windows)] + let running = true; // Simplified for Windows + if running { + sessions.push(session_name.to_string()); + } + } + } + } + } + } + } + + if json_mode { + println!( + r#"{{"success":true,"data":{{"sessions":{}}}}}"#, + serde_json::to_string(&sessions).unwrap_or_default() + ); + } else if sessions.is_empty() { + println!("No active sessions"); + } else { + println!("Active sessions:"); + for s in &sessions { + let marker = if s == session { "→" } else { " " }; + println!("{} {}", marker, s); + } + } + } + None | Some(_) => { + // Just show current session + if json_mode { + println!(r#"{{"success":true,"data":{{"session":"{}"}}}}"#, session); + } else { + println!("{}", session); + } + } + } +} + fn main() { let args: Vec = env::args().skip(1).collect(); let flags = parse_flags(&args); @@ -31,6 +94,12 @@ fn main() { return; } + // Handle session separately (doesn't need daemon) + if clean.get(0).map(|s| s.as_str()) == Some("session") { + run_session(&clean, &flags.session, flags.json); + return; + } + let cmd = match parse_command(&clean, &flags) { Ok(c) => c, Err(e) => { diff --git a/cli/src/output.rs b/cli/src/output.rs index 18b4eba..9a4a775 100644 --- a/cli/src/output.rs +++ b/cli/src/output.rs @@ -215,6 +215,10 @@ Debug: errors [--clear] View page errors highlight Highlight element +Sessions: + session Show current session name + session list List active sessions + Setup: install Install browser binaries install --with-deps Also install system dependencies (Linux)