g3 console init
This commit is contained in:
@@ -5,7 +5,7 @@ use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
use std::path::PathBuf;
|
||||
use sysinfo::{Pid, Signal, System, Process};
|
||||
use tracing::{debug, error, info};
|
||||
use tracing::{debug, info};
|
||||
use crate::models::LaunchParams;
|
||||
|
||||
pub struct ProcessController {
|
||||
@@ -120,8 +120,8 @@ impl ProcessController {
|
||||
// We need to scan for it by matching workspace and recent start time
|
||||
info!("Scanning for newly launched g3 process in workspace: {}", workspace);
|
||||
|
||||
// Wait a moment for the process to fully start
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
// Wait even longer for the process to fully start and appear in process list
|
||||
std::thread::sleep(std::time::Duration::from_millis(2500));
|
||||
|
||||
// Refresh and scan for the process
|
||||
self.system.refresh_processes();
|
||||
@@ -149,11 +149,11 @@ impl ProcessController {
|
||||
});
|
||||
|
||||
if has_workspace {
|
||||
// Check if it's recent (started within last 5 seconds)
|
||||
// Check if it's recent (started within last 10 seconds)
|
||||
let now = std::time::SystemTime::now();
|
||||
let start_time = std::time::UNIX_EPOCH + std::time::Duration::from_secs(process.start_time());
|
||||
if let Ok(duration) = now.duration_since(start_time) {
|
||||
if duration.as_secs() < 5 {
|
||||
if duration.as_secs() < 10 {
|
||||
found_pid = Some(pid.as_u32());
|
||||
break;
|
||||
}
|
||||
@@ -161,7 +161,42 @@ impl ProcessController {
|
||||
}
|
||||
}
|
||||
|
||||
let pid = found_pid.unwrap_or(intermediate_pid);
|
||||
let pid = if let Some(found) = found_pid {
|
||||
found
|
||||
} else {
|
||||
// If we couldn't find it, try one more refresh after a longer delay
|
||||
info!("Process not found on first scan, trying again...");
|
||||
std::thread::sleep(std::time::Duration::from_millis(2000));
|
||||
self.system.refresh_processes();
|
||||
|
||||
// Try the scan again with full logic
|
||||
let mut retry_found = None;
|
||||
for (pid, process) in self.system.processes() {
|
||||
let cmd = process.cmd();
|
||||
let cmd_str = cmd.join(" ");
|
||||
|
||||
let is_g3 = process.name().contains("g3") || cmd_str.contains("g3");
|
||||
if !is_g3 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let has_workspace = cmd.iter().any(|arg| {
|
||||
if let Ok(path) = PathBuf::from(arg).canonicalize() {
|
||||
if let Ok(ws) = workspace_path.canonicalize() {
|
||||
return path == ws;
|
||||
}
|
||||
}
|
||||
false
|
||||
});
|
||||
|
||||
if has_workspace {
|
||||
retry_found = Some(pid.as_u32());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
retry_found.unwrap_or(intermediate_pid)
|
||||
};
|
||||
|
||||
info!("Launched g3 process with PID {}", pid);
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use crate::models::{ExecutionMethod, Instance, InstanceStatus, InstanceType};
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::Result;
|
||||
use chrono::{DateTime, Utc};
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use sysinfo::{System, Process, Pid};
|
||||
use sysinfo::{System, Pid, Process};
|
||||
use tracing::{debug, warn};
|
||||
|
||||
pub struct ProcessDetector {
|
||||
@@ -46,14 +45,26 @@ impl ProcessDetector {
|
||||
) -> Option<Instance> {
|
||||
let cmd_str = cmd.join(" ");
|
||||
|
||||
// Check if this is a g3 binary
|
||||
let is_g3_binary = cmd.get(0).map(|s| s.ends_with("g3")).unwrap_or(false);
|
||||
// Check if this is a g3 binary (more comprehensive check)
|
||||
let is_g3_binary = cmd.get(0).map(|s| {
|
||||
s.ends_with("g3") || s.ends_with("/g3") || s.contains("/target/release/g3") || s.contains("/target/debug/g3")
|
||||
}).unwrap_or(false);
|
||||
|
||||
// Check if this is cargo run with g3
|
||||
let is_cargo_run = cmd.get(0).map(|s| s.contains("cargo")).unwrap_or(false)
|
||||
&& cmd.iter().any(|s| s == "run" || s.contains("g3"));
|
||||
|
||||
if !is_g3_binary && !is_cargo_run {
|
||||
let is_cargo_run = cmd.get(0).map(|s| s.contains("cargo")).unwrap_or(false) && cmd.iter().any(|s| s == "run");
|
||||
|
||||
// Also check if any part of the command line contains g3-related patterns
|
||||
let has_g3_pattern = cmd_str.contains("g3 ")
|
||||
|| cmd_str.contains("/g3 ")
|
||||
|| cmd_str.contains("g3-")
|
||||
|| cmd_str.ends_with("g3")
|
||||
|| cmd_str.contains("--workspace") // g3-specific flag
|
||||
|| cmd_str.contains("--autonomous"); // g3-specific flag
|
||||
|
||||
// Accept if it's a g3 binary, cargo run with g3 patterns, or has g3-specific flags
|
||||
let is_g3_process = is_g3_binary || (is_cargo_run && has_g3_pattern) || has_g3_pattern;
|
||||
|
||||
if !is_g3_process {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -100,7 +111,7 @@ impl ProcessDetector {
|
||||
})
|
||||
}
|
||||
|
||||
fn extract_workspace(&self, pid: Pid, process: &Process, cmd: &[String]) -> Option<PathBuf> {
|
||||
fn extract_workspace(&self, pid: Pid, _process: &Process, cmd: &[String]) -> Option<PathBuf> {
|
||||
// Look for --workspace flag
|
||||
for i in 0..cmd.len() {
|
||||
if cmd[i] == "--workspace" && i + 1 < cmd.len() {
|
||||
|
||||
Reference in New Issue
Block a user