Skip to main content

Module agent

Module agent 

Source
Expand description

Agent process helpers.

All agents run in non-interactive mode (claude -p, codex exec) under a detached monitor that owns the process and its capture files (see crate::monitor). The old synchronous launch/capture path (launch_agent + capture_agent_output) was removed in 14b — the monitor is now the single way an agent process is spawned.

Functions§

agent_running
Check whether a process with the given PID is still running.
is_same_process
Whether pid is the same process instance that recorded expected_start.
looks_like_devflow_process
Best-effort, Linux-only identity check for devflow stop’s signalling fallback (T-23-52, PID reuse in a stale lock file): does /proc/<pid>/cmdline name a devflow process? Reads the NUL-separated argv and reports whether any argument’s file-name component starts with devflow. Returns false when the file cannot be read (process exited between the liveness check and this call, non-Linux, permission denied) — the fail-closed direction. A false return means “identity could not be confirmed,” and callers must treat that as “do not signal,” never as “signal anyway.”
process_start_time
A process’s start time — field 22 of /proc/<pid>/stat, in clock ticks since boot.
terminate
Send SIGTERM to pid — the crate’s one process-termination call, used by devflow stop’s signalling fallback (23c). Applies exactly the same guards agent_running applies, for reasons that are catastrophic here rather than merely wrong: signalling pid 0 would target the caller’s own process group (kill(0, sig) reaches every process in the group, including this one), and a value above i32::MAX would wrap negative through the as libc::pid_t cast — kill(-1, sig) sends the signal to every process the caller may signal. Returns whether the signal was delivered.