A mobile-first coding terminal that connects to your development environment and coding assistant through QR code scanning, providing a terminal interface, code diff viewing, and command execution capabilities.
- π± Mobile-First Interface: Native mobile app built with React Native and Expo
- π QR Code Connection: Secure connection setup via QR code scanning
- π» Terminal Interface: Full terminal access with xterm.js integration
- π Code Diff Viewer: Visualize and apply code changes
- β‘ Command Execution: Allow-listed command execution with security controls
- π Auto-Reconnection: Automatic reconnection with session persistence
- π Security: JWT authentication, CORS protection, and command allowlisting
Cockpit Coder/
βββ frontend/ # React Native/Expo mobile app
β βββ app/ # App screens and components
β βββ components/ # Reusable UI components
β βββ lib/ # Utilities and API clients
β βββ assets/ # Static assets (HTML, CSS, JS)
βββ backend/ # Go server
β βββ cmd/server/ # Application entry point
β βββ internal/ # Core business logic
β βββ go.mod # Go module definition
βββ README.md # This file
- Node.js 18+ and npm
- Go 1.21+
- Expo CLI (
npm install -g expo-cli
) - React Native CLI (
npm install -g react-native-cli
) - Xcode (for iOS) or Android Studio (for Android)
- Physical device or emulator/simulator
# Clone the repository
git clone <repository-url>
cd cockpit-coder
# Install dependencies
cd frontend
npm install
# Install Expo Go app on your mobile device
# Search for "Expo Go" on App Store or Google Play
# Open new terminal and navigate to backend
cd backend
# Install Go dependencies
make deps
# Build the server
make build
# Start the server
make run
# In frontend directory
npx expo start
# Scan QR code with Expo Go app on your mobile device
# Or press 'a' to open in Android emulator or 'i' for iOS simulator
- Open the app on your mobile device
- Click "Connect to Coding Agent"
- Scan the QR code displayed in your terminal (if running in development mode)
- Or use the connection information provided by the backend server
cd frontend
# Start development server
npx expo start
# Start with specific platform
npx expo start --ios
npx expo start --android
# Build for production
eas build --platform ios
eas build --platform android
cd backend
# Run tests
make test
# Format code
make fmt
# Run linter
make lint
# Build for production
make build
# Run with hot reload (requires air)
make dev
# API Configuration
API_BASE_URL=http://localhost:8080
WS_URL=ws://localhost:8080
# Development
EXPO_DEV_SERVER_URL=http://localhost:19006
# Server Configuration
PORT=8080
JWT_SECRET=your_secure_jwt_secret_here
# Security
CORS_ORIGINS=http://localhost:19006,exp://localhost:19000
REPO_ALLOWLIST=/path/to/your/repo
CMD_ALLOWLIST=npm test,go test,git status,ls,cd,pwd
# URLs
WS_URL=ws://localhost:8080
API_BASE=http://localhost:8080
frontend/
βββ app/ # App screens and navigation
β βββ _layout.tsx # Root layout
β βββ index.tsx # Home screen
β βββ screens/ # Feature screens
β β βββ QRConnectScreen.tsx
β β βββ TerminalScreen.tsx
β β βββ DiffsScreen.tsx
β β βββ CommandsScreen.tsx
βββ components/ # Reusable UI components
β βββ ui/ # Base UI components
β β βββ Button.tsx
β β βββ Card.tsx
β β βββ Input.tsx
β β βββ Tabs.tsx
β βββ DiffList.tsx # Code diff viewer
β βββ Terminal.tsx # Terminal wrapper
βββ lib/ # Utilities and API clients
β βββ api.ts # HTTP API client
β βββ storage.ts # Secure storage
β βββ wsClient.ts # WebSocket client
β βββ utils.ts # Helper functions
βββ assets/ # Static assets
βββ terminal/ # xterm.js files
βββ index.html
βββ xterm.js
βββ xterm.css
backend/
βββ cmd/server/ # Application entry point
β βββ main.go
βββ internal/
β βββ auth/ # JWT authentication
β β βββ jwt.go
β βββ httpserver/ # HTTP server and routes
β β βββ server.go
β βββ session/ # Session and task management
β β βββ manager.go
β βββ pty/ # PTY operations
β βββ pty.go
βββ go.mod
βββ go.sum
βββ Makefile
βββ README.md
All API requests require a JWT token in the Authorization header:
Authorization: Bearer <token>
POST /api/session
Content-Type: application/json
{
"repo": "/path/to/repository",
"label": "My Session",
"via": "mobile"
}
GET /api/session/{sessionId}
Authorization: Bearer <token>
POST /api/tasks
Authorization: Bearer <token>
Content-Type: application/json
{
"instruction": "Fix the bug in user authentication",
"branch": "main",
"context": {
"files": ["auth.js", "user.js"],
"hints": "Check the login validation logic"
},
"agent": "cline"
}
GET /api/tasks/{taskId}
Authorization: Bearer <token>
GET /api/tasks/{taskId}/patches
Authorization: Bearer <token>
POST /api/tasks/{taskId}/apply
Authorization: Bearer <token>
Content-Type: application/json
{
"select": [
{
"file": "src/auth.js",
"hunks": [0, 2]
}
],
"commitMessage": "Fix authentication bug"
}
POST /api/cmd
Authorization: Bearer <token>
Content-Type: application/json
{
"cmd": "npm test",
"cwd": "/path/to/repository",
"timeoutMs": 300000
}
ws://localhost:8080/ws/pty?sessionId=<id>&token=<token>
ws://localhost:8080/ws/events?sessionId=<id>&token=<token>
Only commands specified in CMD_ALLOWLIST
environment variable can be executed. Examples:
CMD_ALLOWLIST=npm test,go test,git status,ls,cd,pwd,cat,echo,mkdir,rmdir
Only repositories specified in REPO_ALLOWLIST
environment variable can be accessed:
REPO_ALLOWLIST=/home/user/projects/myapp,/var/www/production
- Use a strong, randomly generated JWT secret
- Set appropriate token expiration times
- Store secrets securely (not in code)
Configure CORS origins appropriately for your deployment:
CORS_ORIGINS=https://yourdomain.com,https://app.yourdomain.com
# Configure EAS
eas build:configure
# Build for iOS
eas build --platform ios
# Build for Android
eas build --platform android
# Submit to stores
eas submit --platform ios
eas submit --platform android
# Dockerfile
FROM golang:1.21-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o server ./cmd/server
FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/server .
EXPOSE 8080
CMD ["./server"]
# Build and run
docker build -t cockpit-coder-backend .
docker run -p 8080:8080 cockpit-coder-backend
PORT=8080
JWT_SECRET=your_production_jwt_secret
CORS_ORIGINS=https://yourapp.com
REPO_ALLOWLIST=/opt/app,/var/www
CMD_ALLOWLIST=npm test,git status,ls
WS_URL=wss://yourapp.com
API_BASE=https://yourapp.com
- Metro bundler errors: Clear cache with
npx expo start --clear
- Missing dependencies: Run
npm install
in frontend directory - Expo Go connection issues: Ensure device and computer are on same network
- Port already in use: Change
PORT
environment variable - Import errors: Run
make deps
to download dependencies - Permission denied: Ensure server has execute permissions
- QR code not scanning: Ensure backend is running and accessible
- WebSocket connection failed: Check firewall settings
- Authentication errors: Verify JWT secret and token validity
# Enable React Native debugging
npx expo start --dev-client
# Enable Metro bundler debugging
npx expo start --debug
# Enable debug logging
DEBUG=true ./bin/server
# Enable verbose logging
LOG_LEVEL=debug ./bin/server
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
make test
for backend,npm test
for frontend) - Run code quality checks (
make check
for backend,npm run lint
for frontend) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow the existing code style
- Write comprehensive tests
- Update documentation for new features
- Use semantic versioning
- Include changelog entries for significant changes
This project is licensed under the MIT License - see the LICENSE file for details.
- π§ Email: support@cockpitcoder.com
- π Issues: GitHub Issues
- π Documentation: Wiki
- Expo for the amazing React Native framework
- xterm.js for the terminal emulator
- React Native for the cross-platform mobile development
- Go for the backend server