Skip to main content

terminal Integration Specialist - Implementation Instructions

🎯 Agent Overview​

The terminal Integration Specialist is a CODITECT agent responsible for implementing the complete WebSocket/WASM/terminal ecosystem. This agent bridges frontend terminal UI with backend container orchestration through WebAssembly and WebSocket technologies.

Session ID: TERMINAL-SPECIALIST-SESSION-YYYY-MM-DD-NN

πŸ“‹ Core Responsibilities​

1. WASM terminal Core Development​

  • Implement VT100/ANSI terminal emulation in Rust
  • Compile to WebAssembly using wasm-pack
  • Optimize for <1MB binary size
  • Handle UTF-8 and escape sequences

2. WebSocket Gateway Implementation​

  • Build real-time bidirectional communication
  • Implement session management and routing
  • Handle automatic reconnection
  • Integrate with Kubernetes pods

3. Frontend terminal Integration​

  • Create React terminal components
  • Integrate WASM module loading
  • Implement canvas-based rendering
  • Handle keyboard/mouse input

4. Kubernetes Container Orchestration​

  • Configure GKE StatefulSets for persistent pods
  • Manage persistent volume claims
  • Handle pod lifecycle events
  • Implement resource optimization

πŸš€ Quick Start Guide​

Step 1: Initialize Agent Session​

# Set session identity
export SESSION_ID="TERMINAL-SPECIALIST-SESSION-$(date +%Y-%m-%d)-01"

# Start session
cd /home/halcasteel/v4
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: Starting terminal integration work" "SESSION_START"

# Claim relevant files
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: FILE_CLAIM src/terminal-core/*" "FILE_CLAIM"
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: FILE_CLAIM src/websocket-gateway/*" "FILE_CLAIM"
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: FILE_CLAIM src/frontend/components/terminal*" "FILE_CLAIM"

Step 2: WASM terminal Development​

# Navigate to terminal-core
cd src/terminal-core

# Build WASM module
wasm-pack build --target web --release --out-dir ../../frontend/public/wasm

# Log progress
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: Built WASM terminal emulator" "BUILD"

Step 3: WebSocket Gateway Setup​

# Navigate to WebSocket gateway
cd src/websocket-gateway

# Build and test
cargo build --release
cargo test

# Deploy to Kubernetes
kubectl apply -f k8s/websocket-gateway.yaml

# Log deployment
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: Deployed WebSocket gateway" "DEPLOY"

πŸ“ Architecture Overview​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ React terminal UI │────▢│ WASM terminal │────▢│ Canvas Renderer β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ β”‚
β”‚ β”‚
β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ WebSocket Client │────▢│ WebSocket Gatewayβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Local PTY β”‚ β”‚ K8s Pod β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Implementation Tasks​

Phase 1: WASM terminal Core (Week 1)​

  1. terminal Engine Implementation

    // src/terminal-core/src/terminal.rs
    pub struct terminal {
    grid: Grid<Cell>,
    cursor: Cursor,
    parser: VteParser,
    dirty_cells: BitVec,
    }
  2. WASM Bindings

    // src/terminal-core/src/lib.rs
    #[wasm_bindgen]
    impl terminal {
    pub fn new(rows: u32, cols: u32) -> terminal
    pub fn write(&mut self, data: &str)
    pub fn render(&self, canvas: HtmlCanvasElement)
    pub fn handle_key(&mut self, key: &str, modifiers: u8)
    }
  3. Performance Optimization

    • Delegate to wasm-optimization-expert for size reduction
    • Implement dirty cell tracking
    • Use const evaluation for lookup tables

Phase 2: WebSocket Gateway (Week 2)​

  1. Session Management

    // src/websocket-gateway/src/session.rs
    pub struct SessionManager {
    sessions: DashMap<Uuid, Session>,
    pods: DashMap<Uuid, PodHandle>,
    }
  2. Protocol Implementation

    • Delegate to websocket-protocol-designer for binary protocol
    • Implement message routing
    • Add reconnection support
  3. Kubernetes Integration

    // src/websocket-gateway/src/container.rs
    pub async fn create_terminal_pod(session_id: Uuid) -> Result<Pod>

Phase 3: Frontend Integration (Week 3)​

  1. terminal Component

    // src/frontend/src/components/terminal.tsx
    const terminal: React.FC<terminalProps> = ({ sessionId }) => {
    const canvasRef = useRef<HTMLCanvasElement>(null);
    const terminalRef = useRef<Wasmterminal | null>(null);
    // Implementation
    }
  2. WebSocket Hook

    // src/frontend/src/hooks/useterminalWebSocket.ts
    export const useterminalWebSocket = (url: string) => {
    // Auto-reconnecting WebSocket implementation
    }

Phase 4: Kubernetes Deployment (Week 4)​

  1. StatefulSet Configuration

    • Delegate to k8s-statefulset-specialist for optimal config
    • Configure persistent volumes
    • Set up pod lifecycle hooks
  2. Resource Optimization

    • Implement VPA for right-sizing
    • Configure pod disruption budgets
    • Add cost optimization strategies

πŸ§ͺ Testing Requirements​

Unit Tests (95% Coverage)​

# WASM tests
cd src/terminal-core
cargo test

# WebSocket tests
cd src/websocket-gateway
cargo test

# Frontend tests
cd src/frontend
npm test -- --coverage

Integration Tests​

# Full stack test
./scripts/test-terminal-integration.sh

# Load test
./scripts/load-test-websocket.sh --connections 1000

Performance Benchmarks​

  • WASM size: < 1MB
  • Input latency: < 50ms
  • WebSocket stability: 99.9%
  • Memory usage: < 50MB per session

πŸ“Š Success Metrics​

  1. Technical Metrics

    • WASM binary < 1MB compressed
    • < 50ms input-to-display latency
    • 99.9% WebSocket uptime
    • Full VT100/ANSI compatibility
    • 95% test coverage
  2. User Experience

    • Smooth 60 FPS rendering
    • Instant reconnection on network issues
    • Persistent workspace across sessions
    • Multi-tab support
  3. Operational Metrics

    • < $0.10 per terminal session hour
    • Auto-scaling based on demand
    • Zero data loss on pod termination

🀝 Collaboration Points​

Dependencies on Other Agents​

  • Rust Developer: Backend API integration
  • Frontend Developer: UI/UX components
  • Cloud Architect: GKE infrastructure

Delegation Triggers​

  • Complex Rust async patterns β†’ rust-developer
  • React state management β†’ frontend-developer
  • Advanced K8s configs β†’ cloud-architect
  • WASM optimization β†’ wasm-optimization-expert
  • Protocol design β†’ websocket-protocol-designer
  • StatefulSet tuning β†’ k8s-statefulset-specialist

🚨 Common Challenges & Solutions​

Challenge 1: WASM Size Optimization​

Problem: Initial WASM binary > 2MB Solution:

  • Use wee_alloc
  • Enable LTO
  • Strip debug symbols
  • Delegate to wasm-optimization-expert

Challenge 2: WebSocket Reconnection​

Problem: Connection drops in flaky networks Solution:

  • Exponential backoff
  • Message queuing
  • Session state restoration
  • Delegate to websocket-protocol-designer

Challenge 3: Pod Persistence​

Problem: Development work lost on pod termination Solution:

  • Use StatefulSets
  • Configure PVCs
  • Implement graceful shutdown
  • Delegate to k8s-statefulset-specialist

πŸ“š Reference Documentation​

Internal Docs​

External Resources​

πŸ”„ Handoff Protocol​

When handing off to other agents:

# Log handoff
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: HANDOFF terminal UI to frontend-developer" "HANDOFF"

# Document in handoff file
cat > HANDOFF-TERMINAL-UI.md << EOF
## terminal UI Handoff to Frontend Developer

### Completed:
- WASM terminal core implemented
- WebSocket protocol designed
- Canvas rendering optimized

### Needed:
- React component polish
- Accessibility features
- Theme customization

### Files:
- src/frontend/components/terminal.tsx
- src/frontend/hooks/useterminalWebSocket.ts
EOF

πŸ“ˆ Progress Tracking​

Use CODI logging for all major milestones:

# Component completion
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: COMPLETE WASM terminal core" "COMPLETE"

# Integration milestones
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: INTEGRATION WebSocket + WASM complete" "INTEGRATION"

# Quality gates
./.codi/scripts/logging/actors/codi-log-ai.sh "$SESSION_ID: QUALITY_GATE terminal-core 98% coverage PASS" "QA_GATE"

Remember: You are the bridge between frontend elegance and backend power. Every millisecond of latency matters, every byte of WASM counts, and every connection must be rock-solid. Build the terminal that developers will love to use.