| name | when-bridging-web-cli-use-web-cli-teleport |
| description | Bridge web interfaces with CLI workflows for seamless bidirectional integration Use when this capability is needed. |
| metadata | {"author":"dnyoussef"} |
Web-CLI Teleport SOP
Overview
Bridge web interfaces with CLI workflows for seamless integration, enabling web applications to trigger CLI commands and CLI tools to display web interfaces.
Agents & Responsibilities
backend-dev
Role: Implement bridge API and integration logic
Responsibilities:
- Build REST API for CLI integration
- Implement WebSocket for real-time communication
- Handle authentication and security
- Manage state synchronization
system-architect
Role: Design bridge architecture and patterns
Responsibilities:
- Design integration architecture
- Define communication protocols
- Plan security model
- Ensure scalability
Phase 1: Design Bridge Architecture
Objective
Design architecture for bidirectional web-CLI communication.
Scripts
npx claude-flow@alpha architect design \
--type "web-cli-bridge" \
--output bridge-architecture.json
cat > api-spec.yaml <<EOF
openapi: 3.0.0
info:
title: Web-CLI Bridge API
version: 1.0.0
paths:
/cli/execute:
post:
summary: Execute CLI command from web
requestBody:
content:
application/json:
schema:
type: object
properties:
command: { type: string }
args: { type: array }
responses:
'200':
description: Command output
/web/render:
post:
summary: Render web UI from CLI
requestBody:
content:
application/json:
schema:
type: object
properties:
component: { type: string }
data: { type: object }
EOF
npx claude-flow@alpha memory store \
--key "bridge/architecture" \
--file bridge-architecture.json
Architecture Patterns
Web → CLI:
Web UI → REST API → CLI Executor → Command → Output → API → Web UI
CLI → Web:
CLI Tool → WebSocket → Web Server → Browser → UI Render
Bidirectional:
Web UI ←→ WebSocket ←→ Bridge Server ←→ CLI Tools
Phase 2: Implement Web Interface
Objective
Build web interface that can trigger and monitor CLI commands.
Scripts
npx create-react-app web-cli-bridge
cd web-cli-bridge
npm install axios socket.io-client
npx claude-flow@alpha generate component \
--name "CLIExecutor" \
--type "react" \
--output src/components/CLIExecutor.jsx
npm run build
npx claude-flow@alpha deploy web \
--source ./build \
--target ./deploy/web
Web Component Example
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import io from 'socket.io-client';
function CLIExecutor() {
const [command, setCommand] = useState('');
const [output, setOutput] = useState('');
const [socket, setSocket] = useState(null);
useEffect(() => {
const newSocket = io('http://localhost:3001');
setSocket(newSocket);
newSocket.on('cli-output', (data) => {
setOutput(prev => prev + data + '\n');
});
return () => newSocket.close();
}, []);
const executeCommand = async () => {
try {
const response = await axios.post('/api/cli/execute', {
command,
args: command.().()
});
(response..);
} (error) {
();
}
};
(
);
}
;
Phase 3: Implement CLI Bridge
Objective
Build CLI-side bridge that connects to web interface.
Scripts
mkdir cli-bridge
cd cli-bridge
npm init -y
npm install express socket.io cors child_process
npx claude-flow@alpha generate server \
--type "bridge" \
--output server.js
node server.js &
curl -X POST http://localhost:3001/api/cli/execute \
-H "Content-Type: application/json" \
-d '{"command": "ls", "args": ["-la"]}'
Bridge Server Implementation
const express = require('express');
const http = require('http');
const socketIo = require('socket.io');
const { exec } = require('child_process');
const cors = require('cors');
const app = express();
const server = http.createServer(app);
const io = socketIo(server, { cors: { origin: '*' } });
app.use(cors());
app.use(express.json());
app.post('/api/cli/execute', (req, res) => {
const { command, args = [] } = req.body;
const fullCommand = `${command} ${args.join(' ')}`;
exec(fullCommand, (error, stdout, stderr) => {
if (error) {
return res.status(500).json({
error: error.message,
stderr
});
}
res.({
: stdout,
stderr
});
io.(, stdout);
});
});
app.(, {
{ component, data } = req.;
io.(, {
component,
data
});
res.({ : });
});
io.(, {
.();
socket.(, {
.();
});
});
server.(, {
.();
});
CLI Tool Integration
#!/bin/bash
render_web_ui() {
local component=$1
local data=$2
curl -X POST http://localhost:3001/api/web/render \
-H "Content-Type: application/json" \
-d "{\"component\": \"$component\", \"data\": $data}"
}
analyze_code() {
local path=$1
local results=$(npx claude-flow@alpha analyze "$path" --format json)
render_web_ui "AnalysisResults" "$results"
echo "Results sent to web interface"
}
analyze_code ./src
Phase 4: Test Integration
Objective
Validate bidirectional communication and error handling.
Scripts
curl -X POST http://localhost:3001/api/cli/execute \
-H "Content-Type: application/json" \
-d '{"command": "npx", "args": ["claude-flow@alpha", "swarm", "status"]}'
bash cli-tool-with-web.sh
node test-websocket.js
npm test -- --testPathPattern=integration
npx artillery quick --count 10 -n 20 http://localhost:3001/api/cli/execute
Integration Tests
const request = require('supertest');
const io = require('socket.io-client');
const app = require('../server');
describe('Web-CLI Bridge Integration', () => {
let socket;
beforeAll((done) => {
socket = io('http://localhost:3001');
socket.on('connect', done);
});
afterAll(() => {
socket.close();
});
it('should execute CLI command from web', async () => {
const response = await request(app)
.post('/api/cli/execute')
.send({ command: 'echo', args: ['test'] });
expect(response.status).toBe(200);
expect(response.body.output).toContain('test');
});
it('should broadcast CLI output via WebSocket', () => {
socket.(, {
(data).();
();
});
(app)
.()
.({ : , : [] });
});
(, () => {
response = (app)
.()
.({
: ,
: { : }
});
(response.).();
(response..).();
});
});
Phase 5: Deploy and Monitor
Objective
Deploy bridge to production and monitor performance.
Scripts
npm run build:web
npm run build:server
cat > Dockerfile <<EOF
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
EXPOSE 3001
CMD ["node", "server.js"]
EOF
docker build -t web-cli-bridge .
docker run -d -p 3001:3001 web-cli-bridge
cat > prometheus.yml <<EOF
scrape_configs:
- job_name: 'bridge'
static_configs:
- targets: ['localhost:3001']
EOF
mkdir logs
node server.js > logs/bridge.log 2>&1 &
tail -f logs/bridge.log
curl http://localhost:3001/health
Success Criteria
Performance Targets
- API response time: <200ms
- WebSocket latency: <50ms
- Command execution: <5s
- Uptime: >99.9%
Best Practices
- Security: Implement authentication and authorization
- Error Handling: Graceful error handling on both sides
- Logging: Comprehensive logging for debugging
- Rate Limiting: Prevent abuse
- Validation: Validate all inputs
- Monitoring: Track performance metrics
- Documentation: Document API and protocols
- Testing: Comprehensive integration tests
Common Issues & Solutions
Issue: Command Execution Timeout
Symptoms: Long-running commands hang
Solution: Implement timeout mechanism, use async execution
Issue: WebSocket Disconnections
Symptoms: Frequent disconnections
Solution: Implement reconnection logic, use heartbeat
Issue: Security Vulnerabilities
Symptoms: Unauthorized command execution
Solution: Implement authentication, whitelist commands
Integration Points
- swarm-orchestration: Execute orchestration from web
- performance-analysis: Display metrics in web UI
- slash-commands: Expose commands via web
References
- WebSocket Protocol
- REST API Design
- CLI Integration Patterns
- Security Best Practices
Converted and distributed by TomeVault — claim your Tome and manage your conversions.