(args, workspace: str, agent_config: AgentServerConfig)
| 187 | |
| 188 | |
| 189 | async def _serve(args, workspace: str, agent_config: AgentServerConfig) -> int: |
| 190 | index_path = Path.home() / ".clawcodex" / "server-sessions.json" |
| 191 | index_path.parent.mkdir(parents=True, exist_ok=True) |
| 192 | |
| 193 | server_config = ServerConfig( |
| 194 | host=args.host, |
| 195 | port=args.port, |
| 196 | auth_token=args.token or "", |
| 197 | workspace=workspace, |
| 198 | ) |
| 199 | manager = SessionManager(workspace=workspace, index_path=index_path) |
| 200 | spawn = make_spawn_agent(agent_config) |
| 201 | server = DirectConnectServer(config=server_config, manager=manager, spawn_agent=spawn) |
| 202 | |
| 203 | await server.start() |
| 204 | http_port = server.bound_http_port |
| 205 | base = f"{args.host}:{http_port}" |
| 206 | print(f"agent-server: protocol v{PROTOCOL_VERSION}") |
| 207 | print(f"agent-server: workspace {workspace}") |
| 208 | print(f"agent-server: listening on http://{base} (POST /sessions)") |
| 209 | print(f"agent-server: connect a TUI with cc://{base}") |
| 210 | if args.token: |
| 211 | print("agent-server: POST /sessions requires Authorization: Bearer <token>") |
| 212 | print("agent-server: Ctrl-C to stop") |
| 213 | |
| 214 | try: |
| 215 | await server.serve_forever() |
| 216 | finally: |
| 217 | await server.stop() |
| 218 | return 0 |
| 219 | |
| 220 | |
| 221 | __all__ = ["run_agent_server_subcommand"] |
no test coverage detected