xiaohongshu
xiaohongshu
headless-terminal
This skill provides guidance for implementing headless terminal interfaces that programmatically control interactive shell sessions. Use this skill when tasks involve creating terminal emulators, implementing pseudo-terminal (PTY) wrappers, building programmatic shell interfaces, or any scenario ...
Full skill instructions
This skill guides the implementation of headless terminal interfaces—programmatic abstractions that spawn and control interactive shell sessions without a visible terminal window. These implementations enable automated interaction with command-line programs, handling of interactive prompts, and capture of terminal output.
Apply this skill when:
Before implementing, locate and understand any base interface or abstract class that defines the contract:
BaseTerminal, TerminalInterface)Choose an appropriate library for PTY interaction. Common options include:
| Library | Pros | Cons | Best For |
|---|---|---|---|
pexpect | Simple API, handles expect patterns, cross-platform | Higher-level abstraction | Most use cases |
pty + subprocess | Standard library, fine-grained control | More complex setup | Custom requirements |
tmux/screen | Session persistence, multiplexing | External dependency | Long-running sessions |
Document the reasoning for the chosen library explicitly.
Implement these essential components:
Shell Spawning: Start an interactive shell with appropriate flags
-i flag for bash to source startup filesInput Methods: Implement keystroke and command sending
\x03, Ctrl+D as \x04, Ctrl+Z as \x1a)\n vs \r\n)Output Reading: Capture terminal output reliably
Resource Management: Ensure proper cleanup
__enter__, __exit__)Critical: Always verify implementations are complete and correct.
Post-Write Verification: After writing any file, read it back to confirm:
Incremental Testing: Test each component before integration:
Assertion Quality: Avoid weak assertions that always pass:
# BAD - always passes
assert "expected" in output or True
# GOOD - actually verifies behavior
assert "expected" in output, f"Expected 'expected' in output, got: {output}"
Edge Case Testing: Explicitly test:
Problem: Code gets cut off mid-method, especially in longer files.
Prevention:
Problem: Tests that cannot fail provide false confidence.
Prevention:
Problem: Implementations fail silently on edge cases.
Prevention:
Problem: Zombie processes or unclosed file descriptors.
Prevention:
import subprocess
# After cleanup, verify no orphaned processes
result = subprocess.run(['pgrep', '-f', 'pattern'], capture_output=True)
assert result.returncode != 0, "Found orphaned processes"
Problem: Timing-dependent behavior causes flaky tests.
Prevention:
time.sleep() calls; use expect patterns when possible# BAD - arbitrary delay
time.sleep(0.1)
# GOOD - wait for specific pattern
terminal.expect(r'\$\s*$', timeout=5) # Wait for prompt
Problem: Only testing Ctrl+C while ignoring other signals.
Prevention:
\x03) for interrupt\x04) for EOF\x1a) for suspendBefore declaring implementation complete:
For detailed technical documentation on PTY handling and common implementation patterns, see references/pty_implementation.md.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience