feat(agents): PTY-agent spike — steer real claude/codex CLIs (Phase 5, flagged)#110
Merged
Conversation
…, flagged)
Stage C of the agent control plane: the path toward commanding REAL claude /
codex CLIs, not just LISA's own managed agents. EXPERIMENTAL, off by default.
A managed agent (Phase 3) runs LISA's own loop. A PTY agent instead spawns the
real `claude`/`codex` binary under a pseudo-terminal (node-pty), so you get that
CLI's full config (skills/MCP/hooks/model) while LISA owns stdin/stdout: it types
your task + follow-ups, can answer prompts, and reads the stream for a coarse
state + a viewable output tail. They show in the roster under their real kind
(claude-code/codex), marked controllable.
Safety / honesty:
- node-pty is an OPTIONAL dependency (zero JS deps, no new vulns); installs + CI
never fail if it can't build — PTY agents are just unavailable then.
- Off unless LISA_PTY_AGENTS=1; the start endpoint 503s otherwise (GUI surfaces
the hint). All endpoints sit behind the standard loopback-or-token auth gate.
- Controls only CLIs LISA SPAWNS — your already-open terminal sessions stay
observe-only (no control channel). Documented, not hidden.
- Privacy: the captured terminal (content) is served only on demand via
/api/agents/pty/<id>/output and is NEVER folded into the structural roster.
Implementation:
- src/agents/pty.ts — PtyAgent + PtyRegistry; pure stripAnsi (color/OSC-8/control,
built from String.fromCharCode so the source carries no raw control bytes),
derivePtyState (quiescence→state), resolveCli; dynamic node-pty import with
graceful fallback; flag gate.
- src/integrations/pty/observer.ts + registry/hub wiring — surfaces PTY agents in
the hub roster (real kind, controllable:"pty").
- AgentSession.controllable ("managed"|"pty") unifies which control-endpoint
family the UI drives; managed observer now sets controllable:"managed".
- src/web/server.ts — POST /api/agents/pty/{start,<id>/send,<id>/cancel} +
GET /<id>/output.
- GUI: delegate kind picker (managed/claude/codex) + controllable-family row
controls (send/output/cancel; approve/deny stays managed-only). Snapshot updated.
- docs/PTY_AGENTS.md.
Tests: 714 pass / 1 skip (the real-node-pty round-trip skips when the native dep
can't spawn under the tsx loader). typecheck + build clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stage C of the agent control plane — the path toward commanding real
claude/codexCLIs, not just LISA's own managed agents. Experimental, off by default.A managed agent (#108) runs LISA's own loop. A PTY agent instead spawns the real
claude/codexbinary under a pseudo-terminal (node-pty), so you get that CLI's full config — skills / MCP / hooks / model — while LISA owns stdin/stdout: it types your task + follow-ups, can answer prompts, and reads the stream for a coarse state + a viewable output tail. They appear in the roster under their real kind (claude-code/codex), marked controllable: type-into-the-CLI, ▤ output, ⏹ cancel.Why it's safe to merge while off
node-ptyis anoptionalDependency— zero JS deps, no new vulnerabilities (the tree's existing 8 are unrelated). Installs + CI never fail if it can't build; PTY agents are simply unavailable then (dynamic import → graceful fallback).LISA_PTY_AGENTS=1— the start endpoint503s otherwise (the GUI surfaces the hint). The hub observer is inert at rest (registry stays empty). All endpoints sit behind the standard loopback-or-token auth gate.peerProtocol).GET /api/agents/pty/<id>/outputand is never folded into the structural cross-agent roster.Implementation
src/agents/pty.ts—PtyAgent+PtyRegistry; purestripAnsi(color / OSC-8 hyperlinks / bare control bytes — built fromString.fromCharCodeso the source carries no raw control bytes),derivePtyState(quiescence → state),resolveCli; flag gate.src/integrations/pty/observer.ts+ registry/hub wiring.AgentSession.controllable("managed"|"pty") unifies which control-endpoint family the UI drives; managed observer now setscontrollable:"managed".src/web/server.ts—POST /api/agents/pty/{start, <id>/send, <id>/cancel}+GET /<id>/output.controllable-family row controls (approve/deny stays managed-only). Snapshot recomputed.docs/PTY_AGENTS.md.Verification
node-ptyround-trip viacatskips when the native dep can't spawn under thetsxloader — a runner artifact; the shipped path runs against compiled JS).npm run typecheck+npm run buildclean;MAIN_HTMLparses + snapshot updated.Result — control plane complete (per plan)
claude/codexCLIs under a PTY (this PR, flagged).Remaining: Phase 4 (advisor one-click) — small, lower-value given the external-session identity mismatch.
🤖 Generated with Claude Code