Agent States
Agents transition through several states during their lifecycle:Launching
Instance created but session not yet bound (< 30s)
Listening
Idle, ready to receive messages (< 1s response)
Active
Processing, reading messages very soon
Blocked
Needs human approval to continue
Inactive
Stopped, stale, or disconnected
State Machine
Lifecycle Phases
1. Creation
2. Initialization
When the tool starts:3. Active Operation
During normal operation:4. Termination
When the session ends:Agent Types
PTY Agents
Launched withhcom [N] {tool} in managed terminal:
- Full hook integration (Pre/Post/Notify)
- TCP delivery thread for instant message injection
- Terminal pane management (kitty, wezterm, tmux)
- PID tracking for orphan recovery
Headless Agents
Launched withhcom [N] {tool} -p "prompt" in background:
- Same hook integration as PTY
- No terminal UI
- Background log file for output
- Daemon-style operation
Vanilla Agents
Run tool manually, thenhcom start inside:
- Polling-based message delivery (no TCP thread)
- Manual hook installation required
- Works with any AI tool that can run shell commands
Ad-hoc Senders
Fire-and-forget external processes:- No session binding
- No message polling
- External sender identity
Identity Management
Session Binding
Thebind_session_to_process() function handles 4 paths:
- Path 1a: Canonical + Placeholder Merge
- Path 1b: Canonical + Session Switch
- Path 2: Placeholder Bind
- Path 3/4: No-op
Name Generation
CVCV (consonant-vowel-consonant-vowel) pattern:Status Computation
Heartbeat Timeout
Listening status requires fresh heartbeat:Activity Timeout
Non-listening, non-inactive states timeout after 5 minutes:Sleep/Wake Detection
Detect laptop sleep via wall-clock vs monotonic drift:Cleanup
Stale Instance Cleanup
Automatic cleanup of dead instances:Orphan Recovery
After schema bump/archive:- Before archive: snapshot running instances to
launched_pids.json - After reconnect: check pidfile
- If process alive: re-register with
create_orphaned_pty_identity() - Restore notify endpoints, session binding
Subagents
Claude Task tool spawns child instances:hcom config subagent_timeout).