Command Component
Execute shell commands as declarative components with automatic output capture, error handling, and task lifecycle tracking. Provides both component and hook interfaces for maximum flexibility.Planned API
Proposed Usage
Basic Command Execution
With Children (Output Handling)
Environment Variables
Shell Command (String Form)
Parallel Commands
Sequential Pipeline
Props (Planned)
Command to execute.String form (shell):Executed via shell, supports pipes/redirects/chaining.Array form (direct):Direct execution, safer for untrusted input (no shell injection).With args prop:Equivalent to
["git", "commit", "-m", "message"]Arguments when cmd is string (single command).Ignored when cmd is array.
Working directory for command execution.Respects worktree context if inside
<Worktree> component.Priority: Explicit cwd > worktree context > process.cwd()Environment variables merged with process.env.Variables override process.env for this command only.
Timeout in milliseconds (default 5 minutes).Command killed if exceeds timeout.Set to 0 for no timeout (use cautiously).
Callback when command completes successfully (exitCode 0).Receives stdout, stderr, exitCode, duration.
Callback when command fails (non-zero exit or timeout).Error includes stdout/stderr captured before failure.Note: onError prevents error propagation. Omit to throw errors.
Optional render function receiving command output.Called after command completes successfully.Enables conditional rendering based on output.
Implementation Status
1
Design Phase
Component API designed alongside useCommand hook proposal.
2
useCommand Hook (Pending)
Underlying hook implementation provides core command execution logic.
3
Component Wrapper (Pending)
Declarative component wrapping useCommand hook with task tracking.
4
Worktree Integration (Pending)
Auto-detect worktree context and use as default cwd.
5
Testing (Future)
Unit tests for success/error cases, timeout handling, environment isolation.
Design Rationale
Component vs Hook
Component form: Declarative, fits orchestration patternsTask Lifecycle Integration
Shell vs Direct Execution
String cmd → shell execution:- Supports pipes, redirects, chaining
- Subject to shell injection if cmd includes untrusted input
- Use for trusted commands with shell features
- No shell involved, safer
- No pipes/redirects/chaining
- Recommended for dynamic commands
Worktree Context Integration
<Worktree> automatically execute in worktree directory.
Examples of Use Cases
Use Case 1: CI Pipeline
Use Case 2: Git Workflow
Use Case 3: Build Matrix
Related
useCommand Hook
Imperative hook for command execution - underlying implementation
Worktree Component
Git worktree isolation - Command respects worktree cwd
Parallel Component
Run multiple commands concurrently
Step Component
Sequential execution - natural container for Command
Alternatives Considered
- Direct Bun.spawn in components: No task tracking, verbose
- Shell scripts: External to orchestration, not resumable
- Agent-based command execution: Overkill for simple commands
- Imperative-only (no component): Doesn’t fit declarative pattern