Home

mweinbach / agent-coworker

publicmweinbach/agent-coworker
Overview Code History Branches Pull requestsIssuesInsights
main
HomeOverview Code PRsIssues

Add server port fallback, DI, and safer approval

9 months ago

54666f4
Authored
mweinbach2/8/2026, 5:16:30 AM
Refactor 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

5 files changed
  • src/server/startServer.ts+127−88
  • src/tools/spawnAgent.ts+26−10
  • src/utils/approval.ts+24−1
  • test/approval.test.ts+7−5
  • test/spawnAgent.tool.test.ts+154−0