e344e961d6
- Add TerminalSession backend service for docker exec subprocess management
- Add TerminalManager for WebSocket session lifecycle management
- Create WebSocket endpoint at /ws/tool-instances/{id}/terminal
- Add session cookie authentication and instance ownership verification
- Install xterm.js with fit and web-links addons
- Create TerminalComponent with xterm.js integration
- Create TerminalPage with full-screen terminal view
- Add terminal route at /instances/:id/terminal
- Add terminal button to InstanceList for running instances
- Add terminal and arrow-left icons to icon registry
- Add comprehensive terminal CSS styles (dark theme, responsive)
Quality gates: typecheck ✓, lint ✓, build ✓, Python syntax ✓
3.9 KiB
3.9 KiB
Tool Instances Specification
Requirements
Functional Requirements
- ToolInstance Model: Store instance metadata with status tracking
- Session API: CRUD operations + lifecycle (start/stop/restart/delete)
- Docker Integration: Render compose templates and execute commands
- Status Monitoring: Real-time container status polling
- Log Access: View container logs (last 100 lines)
- Session Navigation: Active sessions appear in app shell
- URL Generation: Unique access URLs for each running instance
Non-Functional Requirements
- Security: Isolated containers, no privileged mode
- Resource Limits: CPU and memory constraints
- Error Handling: Graceful failure with cleanup
- Performance: Start time < 30 seconds
API Specification
Create Instance
POST /projects/{project_id}/repositories/{repo_id}/instances
Body: {
tool_type_id: string,
display_name: string (optional)
}
Response: {
id: string,
name: string,
display_name: string,
tool_type_id: string,
status: "pending",
created_at: string
}
List Instances
GET /projects/{project_id}/repositories/{repo_id}/instances
Response: {
instances: [...]
}
Get Instance
GET /projects/{project_id}/repositories/{repo_id}/instances/{instance_id}
Response: {
id: string,
name: string,
display_name: string,
status: string,
container_id: string | null,
url: string | null,
port: number | null,
last_started_at: string | null,
last_stopped_at: string | null,
created_at: string
}
Lifecycle Operations
POST /projects/{project_id}/repositories/{repo_id}/instances/{instance_id}/start
POST /projects/{project_id}/repositories/{repo_id}/instances/{instance_id}/stop
POST /projects/{project_id}/repositories/{repo_id}/instances/{instance_id}/restart
Response: { status: string }
Delete Instance
DELETE /projects/{project_id}/repositories/{repo_id}/instances/{instance_id}
Response: 204 No Content
Get User Sessions
GET /users/me/sessions
Response: {
sessions: [
{
id: string,
display_name: string,
tool_type_name: string,
tool_icon: string,
repository_name: string,
project_name: string,
status: string,
url: string | null
}
]
}
Docker Compose Template Variables
{{REPO_PATH}}: Absolute path to git repository on host{{INSTANCE_NAME}}: Unique instance identifier{{INSTANCE_ID}}: UUID of the instance{{TOOL_PORT}}: Assigned port for the tool{{USER_ID}}: Owner user ID{{PROJECT_ID}}: Project ID
Status Values
pending: Instance created, waiting to startbuilding: Docker compose up in progressrunning: Container is runningstopped: Container stoppederror: Container failed to start or crashed
Database Schema
CREATE TABLE tool_instances (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL,
display_name VARCHAR(255) NOT NULL,
tool_type_id UUID NOT NULL REFERENCES tool_types(id),
repository_id UUID NOT NULL REFERENCES git_repositories(id),
project_id UUID NOT NULL REFERENCES projects(id),
owner_id UUID NOT NULL REFERENCES users(id),
status VARCHAR(50) NOT NULL DEFAULT 'pending',
container_id VARCHAR(255),
compose_path VARCHAR(1024),
url VARCHAR(1024),
port INTEGER,
last_started_at TIMESTAMP WITH TIME ZONE,
last_stopped_at TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE INDEX idx_tool_instances_owner ON tool_instances(owner_id);
CREATE INDEX idx_tool_instances_repo ON tool_instances(repository_id);
CREATE INDEX idx_tool_instances_status ON tool_instances(status);
Testing Requirements
- Unit Tests: Docker command generation, template rendering
- Integration Tests: API endpoints, database operations
- Manual Testing: Container lifecycle, navigation updates