* feat: refine OpenCode session reuse strategy and cleanup * fix: harden OpenCode session selection and lint errors * refactor: centralize OpenCode reuse resolution flow * fix: return 404 for missing session in message route * feat: replace force remap with terminal reload control * fix: protect project path from session kill cleanup * fix: preserve fullscreen alignment without reload action * fix: harden OpenCode session id handling and title reuse selection * fix: show OpenCode reload control and remap before restart * fix: preserve title-only OpenCode reuse with fallback mapping persistence * fix: resolve remaining PR315 Bugbot findings * fix: keep OpenCode discovery title-based without timestamp sorting * fix: avoid enrichment race fallout in session listing * fix: guard OpenCode discovery parse with array check * fix: stabilize Linear comment integration check * fix: harden OpenCode discovery and prompt option flow * ux: clarify OpenCode terminal restart action * fix: remap OpenCode session fresh on each restart * fix: validate remap session ids before reuse * fix: clean archived metadata only after purge * docs: align OpenCode remap selection with title-based behavior * fix: harden opencode cleanup and ignore local sisyphus state * test: add timeout cleanup coverage for session enrichment * fix: harden Linear integration helper against transient non-JSON errors * fix: make linear integration assertions resilient to eventual consistency * fix: remove unused fs import after rebase * fix: address remaining Bugbot blockers for opencode session handling * fix: avoid stale metadata overwrite during restore post-launch * fix: forward subagent in orchestrator flows and defer reuse lookup * fix: apply configured subagent fallback for session spawn * fix: scope archived cleanup by project and delay archive restore write * fix: normalize orchestrator strategy aliases in start display logic * fix: centralize orchestrator strategy normalization in core * fix: derive orchestrator reuse display from spawn result * fix: keep cleanup results consistent across project-id collisions * fix: namespace cleanup results when session IDs collide * fix: harden GitHub issue stateReason fallback Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * fix: avoid false failing CI state mapping Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * fix: add tmux command timeouts Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * fix: bound session API enrichment latency Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * fix: repair scm-github merge resolution Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * fix: repair lifecycle-manager test merge Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * fix: delay archive metadata recreation until restore passes Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * test: restore claim-pr session mocks Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * fix: address review findings for OpenCode lifecycle PR - Fix stripControlChars to preserve newlines for reload commands - Add SessionNotFoundError and use instanceof checks in API routes - Document orchestratorSessionStrategy in YAML example - Validate existingSessionId with asValidOpenCodeSessionId() - Extract inline Node script to buildSessionLookupScript helper - Create OpenCodeSessionManager interface for remap capability - Create OpenCodeAgentConfig type for agent-specific config - Change default orchestratorSessionStrategy from delete to reuse Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: guard reused session display without metadata * chore: add agent config files to .gitignore Agent configuration files (CLAUDE.md, AGENTS.md, IMPROVEMENTS.md, etc.) are personal and project-specific. They should not be committed to the repository. Changes: - Remove CLAUDE.md from git tracking - Add agent config files to .gitignore - Create .gitignore-template for reference Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: update gitignore for agent config folder structure Reorganized agent configuration files: - CLAUDE.md and AGENTS.md stay in root (agents read them there) - Tracking files move to .opencode/ (IMPROVEMENTS.md, etc.) - Optional Claude files in .claude/ Updated .gitignore to ignore folders instead of individual files. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: tighten opencode remap and session discovery safeguards * fix: address Bugbot findings in session manager * fix: scope opencode discovery to opencode sessions * fix: restore concurrent listing and strict permission literals * fix: throw SessionNotFoundError, parallelize list enrichment, fix permissions type - Session manager now throws SessionNotFoundError instead of plain Error for missing sessions, so web API routes correctly return 404 (not 500) - Parallelize session enrichment in list() — was sequential, causing O(N) latency for N sessions with subprocess enrichment - Fix AgentLaunchConfig.permissions type to accept legacy "skip" value (AgentPermissionInput instead of AgentPermissionMode) - Add happy-path and validation tests for /api/sessions/:id/message route - Update all test mocks to use SessionNotFoundError Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: route ao send through session manager * feat: add purge option to orchestrator stop * fix: register opencode agent in web services * test: align web API missing-session coverage * fix: match notifier config by plugin name * refactor: dedupe session lookup and tmux buffer send flow * test: update send lifecycle wait expectation * fix: harden send routing and cleanup purge controls --------- Co-authored-by: Harsh <harsh@Ubuntu-24-Forrest.lan> Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Prateek <karnalprateek@gmail.com> |
||
|---|---|---|
| .. | ||
| src | ||
| README.md | ||
| package.json | ||
| tsconfig.json | ||
README.md
@agent-orchestrator/plugin-runtime-tmux
Runtime plugin for executing agent sessions in tmux.
What This Does
Creates isolated tmux sessions for each agent. Each session runs in a separate tmux session with:
- Working directory set to workspace path
- Environment variables from config
- Agent launch command executed automatically
How It Works
Creating a Session
const handle = await runtime.create({
sessionId: "my-app-3",
workspacePath: "/Users/dev/.worktrees/my-app/my-app-3",
launchCommand: "claude -p 'Fix bug in auth module'",
environment: {
AO_SESSION_ID: "my-app-3",
AO_PROJECT_ID: "my-app",
},
});
What happens:
- Validates
sessionId(only alphanumeric, dash, underscore allowed) - Creates detached tmux session:
tmux new-session -d -s my-app-3 -c /path/to/workspace - Sets environment variables:
tmux ... -e KEY=VALUE - Sends launch command:
tmux send-keys -t my-app-3 "claude -p '...'" Enter - Returns RuntimeHandle with tmux session name
Sending Messages
await runtime.sendMessage(handle, "Fix the test failure in auth.test.ts");
What happens:
- Clears partial input:
tmux send-keys -t my-app-3 C-u - For short messages (<200 chars, no newlines): sends directly with
-lflag (literal mode) - For long/multiline messages: writes to temp file →
tmux load-buffer→tmux paste-buffer - Waits 300ms (let tmux process the text)
- Sends Enter:
tmux send-keys -t my-app-3 Enter
Why the complexity?
send-keyswithout-linterprets special strings ("Enter", "Space") as key names- Long strings can overflow tmux's command buffer
- Multiline strings need special handling
Getting Output
const output = await runtime.getOutput(handle, 50); // last 50 lines
Uses tmux capture-pane -t my-app-3 -p -S -50 to capture terminal buffer.
Checking if Alive
const alive = await runtime.isAlive(handle);
Uses tmux has-session -t my-app-3 (exit code 0 = exists, 1 = doesn't exist).
Destroying
await runtime.destroy(handle);
Kills tmux session: tmux kill-session -t my-app-3 (ignores errors if already dead).
Attaching to Sessions
For Terminal plugins (iTerm2, web):
const attachInfo = await runtime.getAttachInfo(handle);
// Returns: { type: "tmux", target: "my-app-3", command: "tmux attach -t my-app-3" }
Security
Session ID validation:
const SAFE_SESSION_ID = /^[a-zA-Z0-9_-]+$/;
Only allows safe characters. Prevents shell injection via session name (used in tmux commands).
Error Handling
- Session creation fails → cleans up (kills session) before throwing
- Message send fails → throws (caller should handle)
- Session already dead →
destroy()silently succeeds (idempotent)
Metrics
const metrics = await runtime.getMetrics(handle);
// Returns: { uptimeMs: 123456 }
Tracks uptime (stored in RuntimeHandle.data.createdAt).
Testing
This plugin is tested indirectly via packages/core/src/__tests__/tmux.test.ts (utility functions) and integration tests.
To test manually:
# Start a test session
tmux new-session -d -s test-session -c /tmp
tmux send-keys -t test-session "echo hello" Enter
# Capture output
tmux capture-pane -t test-session -p
# Kill session
tmux kill-session -t test-session
Common Issues
tmux not installed
If tmux is not in PATH, all operations fail. Install via:
- macOS:
brew install tmux - Linux:
apt-get install tmuxoryum install tmux
Session name conflicts
If a session with the same ID already exists, create() fails. The orchestrator should ensure unique session IDs.
Detached sessions persist after orchestrator crashes
tmux sessions keep running even if the orchestrator dies. Use tmux list-sessions to find orphans, tmux kill-session -t <name> to clean up.
Limitations
- macOS/Linux only — tmux is not available on Windows (use WSL)
- No Windows native support — use runtime-process instead on Windows
- Terminal buffer size —
getOutput()limited by tmux buffer size (default 2000 lines) - No resource limits — agents can consume unlimited CPU/memory (use docker/k8s runtimes for isolation)
Architecture Notes
Why tmux over raw processes?
- Sessions persist across orchestrator restarts
- Easy to attach for debugging:
tmux attach -t session-name - Terminal emulation (colors, ANSI codes work)
- Works well with interactive AI tools (Claude Code, Aider)
Why detached mode?
- Orchestrator doesn't block waiting for agent
- Multiple agents can run in parallel
- Humans can attach later without interrupting agent