fix session cmd

This commit is contained in:
Chris Tate
2026-01-11 23:53:29 -06:00
parent 24881c7327
commit 1f7ee4c525
3 changed files with 158 additions and 0 deletions
+85
View File
@@ -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 }}
+69
View File
@@ -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<String> = 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::<i32>() {
#[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<String> = 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) => {
+4
View File
@@ -215,6 +215,10 @@ Debug:
errors [--clear] View page errors
highlight <sel> 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)