Every 1000ms calls read_spawn_queue() Tauri command
Reads and clears the queue file (lines 378-379 in tasks.rs)
Calls addSpawnedTerminal() to create UI terminal tabs
UI terminal starts PTY session (Terminal.svelte):
Calls start_claude_session() Tauri command
Passes workingDir, initialPrompt, session ID
Tauri launches claude CLI with PTY (pseudo-terminal)
Captures output and sends to Terminal.js (xterm)
Agent terminal receives initial prompt (from terminals.js line 36-38):
code
"You have CLI tools available: pm-task, pm-phase, pm-spawn...
Read ~/.pm/CLAUDE.md for full documentation.
Read the task document at {taskPath}/{phaseFile} and work through it."
No atomic transaction = potential loss of entries if UI crashes during read
Risk: Multiple calls to pm-spawn could lose requests
Directory Misalignment
Tauri looks for tasks in $pm_dir/tasks (hardcoded)
But pm-task create hardcodes $PM_DIR/tasks (from env var $HOME/.pm)
If user changes PM_DIR, Tauri won't find tasks
Risk: Configuration inconsistency
No Direct CLI ↔ UI Communication
CLI and UI are completely decoupled
UI doesn't know about agents spawned via pm-orchestrator watch
UI only sees agents spawned via its own polling
CLI pm-orchestrator has no way to notify UI of spawned agents
Risk: Agents running without UI awareness
Incomplete Agent Tracking
running.json tracks agents spawned by pm-orchestrator
But UI agent terminals have no tracking in running.json
If UI spawns agent and crashes, no record exists
Risk: Agent orphaning and lost task context
Spawn Queue Clearing After Read
Line 379 in tasks.rs: fs::write(&queue_path, "")?;
If UI crashes before processing spawn requests, they're lost
Should be cleared after successful terminal start, not after file read
Risk: Agents queued but never start
Session ID Mismatch
Terminal generates session ID at line 21: sessionId = "session-${Date.now()}"
But agent terminals expect to correlate with task path
No clear mapping between terminal session and task when multiple agents run
Risk: Output routing confusion if many agents run simultaneously
6. Missing Integration Features
No bidirectional communication: CLI agents can't signal UI updates beyond file changes
No agent heartbeat: UI doesn't know if agents are still alive
No orchestrator awareness in UI: Can't see if pm-orchestrator watch is running
No CLI config in UI: User must set PM_DIR environment variable, not configurable in UI
No cancellation propagation: Killing agent via UI doesn't update running.json
No agent status sync: Multiple UI windows would show different agent states
7. Summary
Current Architecture: The system uses filesystem-based IPC through JSON files as a messaging layer between completely independent CLI and UI processes. The Tauri backend acts as a file system proxy that the UI polls for changes.
Strengths:
Simple, decoupled design
Works across process boundaries
Easy to debug (all state in readable files)
CLI tools are standalone and usable without UI
Weaknesses:
No real-time bidirectional communication
Race conditions around queue clearing
Agent spawning has multiple code paths (CLI vs UI)
Running agent tracking is incomplete
Heavy reliance on file polling and manual refresh
The architecture would benefit from a proper message queue (e.g., SQLite, Redis) and event subscription system rather than polling JSON files.
File Watcher Polling (1 sec interval)
Uses notify crate with 1-second poll interval
Can miss rapid file changes
No debouncing between file changes and UI updates
Risk: UI flicker or missed updates
No Error Recovery
Agent crashes won't update running.json status if pm-done isn't called
UI terminals closed without cleanup
No periodic health check
Risk: Zombie processes and stale state
Frontmatter Parsing Fragility
Simple line-by-line text parsing in Rust (no YAML parser)
Breaks if values contain colons or special characters
No schema validation
Risk: Silent parsing failures
Path Expansion Inconsistency
Some scripts use "${path/#\~/$HOME}" for tilde expansion