9 months ago
54666f4Refactor startServer to extract createServer and add serveWithPortFallback/isAddrInUse helpers so binding to port 0 falls back to random ephemeral ports when necessary. Keep existing websocket/session behavior but centralize server creation and error handling. Introduce dependency injection in createSpawnAgentTool (SpawnAgentDeps) so generateText, stepCountIs, getModel, loadSubAgentPrompt and classifyCommand can be mocked for tests; pass a safeApprove callback into createSubAgentTools to control auto-approval behavior. Adjust imports to avoid name collisions. Tighten command approval in utils/approval.ts by adding hasShellControlOperators and changing classifyCommand to treat commands containing control operators or dangerous patterns as requiring a prompt (no auto-approve). Update tests accordingly and add a new spawnAgent tool test (test/spawnAgent.tool.test.ts) to verify sub-agent tool selection, model selection, and safe bash approval behavior.
Parent8cf8490