## ADDED Requirements ### Requirement: API can spawn a tool instance The system SHALL provide an endpoint to create and start a tool instance. #### Scenario: Spawn code-server - **WHEN** a POST request is made to /api/v1/tool-instances with tool_id and project_id - **THEN** the system creates a ToolInstance record - **AND** generates a Docker Compose service definition - **AND** starts the container via Docker Compose API - **AND** returns the tool instance with status "creating" #### Scenario: Spawn with config overrides - **WHEN** a spawn request includes config overrides - **THEN** the overrides are merged with scope-resolved configs - **AND** applied to the container environment ### Requirement: Spawn validates prerequisites The system SHALL validate prerequisites before spawning. #### Scenario: Valid project - **WHEN** the spawn request references a project - **THEN** the project must exist and belong to the user - **AND** the tool definition must exist in the registry #### Scenario: Duplicate spawn prevention - **WHEN** a spawn request is made for an already-running instance - **THEN** the system returns the existing instance - **AND** does not create a duplicate container