# GitHub Copilot CLI Provider ## Overview The Copilot provider enables CLI Agent Orchestrator (CAO) to run **GitHub Copilot CLI** in tmux-managed sessions. This provider targets the current Copilot CLI surface (latest versions) and does not include legacy compatibility fallbacks. ## Quick Start ### Prerequisites 1. **GitHub Copilot access** and successful `copilot login` 2. **Copilot CLI** installed (`copilot` command available) 3. **tmux** installed ```bash # Install Copilot CLI npm install -g @github/copilot # Authenticate copilot login # Verify copilot --version copilot --help ``` ### Using Copilot Provider with CAO ```bash # Start CAO server cao-server # Install CAO agent profile into Copilot's agents directory cao install examples/assign/data_analyst.md --provider copilot_cli # Launch Copilot-backed terminal cao launch --agents data_analyst --provider copilot_cli ``` Via HTTP API: ```bash curl -X POST "http://localhost:9889/sessions?provider=copilot_cli&agent_profile=developer" ``` ## Features ### Status Detection The provider detects: - **IDLE**: Copilot prompt visible, no pending response - **PROCESSING**: no idle prompt yet / still running - **WAITING_USER_ANSWER**: trust/confirmation prompt visible - **COMPLETED**: response present and prompt returned - **ERROR**: explicit error output detected Trust handling is done in `initialize()`. `get_status()` is read-only. After trust is dismissed, cursor-addressed FIFO redraws can leave the monitor's cached status at `WAITING_USER_ANSWER` even though the rendered pane is idle. Copilot opts into fresh-pane recovery for that stale waiting state. Recovery requires a quiet output buffer, two consecutive matching pane classifications, and current-generation evidence; a live approval dialog remains waiting. Copilot v1.0.95 has been observed with both a `❯` composer between separator rules and an empty heavy-box composer (`╻▄▄…`, `┃`, `╹▀▀…`). The detector accepts both captured layouts, independent of the mode displayed in the footer. For the heavy box, matching borders, an empty interior, and the following Copilot hint bar are required; active execution and trust/approval indicators still block readiness. A plain `capture-pane` snapshot preserves visible box characters but omits color and terminal negotiation sequences, so it does not establish why Copilot selected a particular layout. ### Message Extraction `GET /terminals/{terminal_id}/output?mode=last` extracts the final assistant message by: 1. Finding output after last user prompt line 2. Trimming tail prompts/footer lines 3. Falling back to assistant-prefix extraction ### Agent Profile Integration Copilot provider now follows the same split as other providers: - `cao install --provider copilot_cli` writes `.agent.md` into `~/.copilot/agents` - provider launch passes `--agent ` directly - provider does not generate runtime agent markdown files This keeps provider logic thin and moves profile materialization to install-time. ### MCP Integration CAO injects `cao-mcp-server` at runtime via: - `--additional-mcp-config ` Implementation: - Add `cao-mcp-server` with `CAO_TERMINAL_ID` - Forward the workflow step identity, `CAO_WORKFLOW_RUN_ID` and `CAO_WORKFLOW_STEP_ID`, as `${VAR:-}` placeholders. Copilot gives a stdio MCP server only `PATH` and a few platform variables, and it expands these placeholders from its own environment. Without them, `workflow_return` cannot find the step of a structured workflow step. - Pass the merged MCP payload inline as JSON A grant without `web_fetch` also adds `--disable-builtin-mcps` and `--disable-mcp-server computer-use`. Copilot's `url` rule and the `--excluded-tools web_fetch` flag (which a grant with `execute_bash` gets instead of the `url` rule, so that its shell keeps URL access) do not reach MCP tools, and Copilot's built-in MCP servers reach GitHub, hosted services, a browser or the desktop. The servers go off also when the grant names one, such as `@github-mcp-server`; add `web_fetch` to keep them. `--disable-builtin-mcps` does not cover `computer-use`. `cao-mcp-server` is not a built-in server, so it stays on. ### Agent-plugin MCP working directory Its MCP config format has no working-directory key (checked against the vendor's own MCP documentation, 2026-09-16), so CAO carries an agent plugin's declared `cwd` by launching the server through `/bin/sh -c 'cd -- "$1" && shift && exec "$@"'`. `exec` replaces the shell, the environment passes through, and argument boundaries survive because each argument stays a separate argv element. On a host with no `/bin/sh` such a server is skipped with `mcp.cwd_unsupported` rather than started in the wrong directory. See [Agent Plugins](agent-plugins.md) for the full per-provider table. ## Configuration ### Required Copilot CLI Flags Provider expects these flags in your Copilot CLI: - `--agent` - `--additional-mcp-config` - `--allow-all` - `--autopilot` - `--deny-tool`, `--excluded-tools`, `--disable-builtin-mcps` and `--disable-mcp-server`, for a restricted grant When `--additional-mcp-config` is missing from your `copilot --help`, CAO skips MCP config injection. An unknown restriction flag stops the launch. ### Command Shape ```bash copilot --allow-all [--agent ] --config-dir ~/.copilot \ --add-dir --additional-mcp-config '{"mcpServers":{...}}' \ [--excluded-tools web_fetch] [--deny-tool ...] \ [--disable-builtin-mcps --disable-mcp-server computer-use] \ --autopilot ``` ### Environment Variables Copilot provider currently has no provider-specific environment knobs. ## Implementation Notes - Provider file: `src/cli_agent_orchestrator/providers/copilot_cli.py` - Exit command: `/exit` - Paste behavior: single Enter (`paste_enter_count = 1`) ## End-to-End Testing ```bash # Unit tests uv run pytest test/providers/test_copilot_cli_unit.py -v uv run pytest test/providers/test_provider_manager_unit.py -v # Copilot E2E uv run pytest -m e2e test/e2e/ -k copilot -v -o "addopts=" ``` Maintainer-requested scenarios: ```bash uv run pytest -m e2e test/e2e/test_assign.py::TestCopilotCliAssign::test_assign_data_analyst -v -o "addopts=" uv run pytest -m e2e test/e2e/test_assign.py::TestCopilotCliAssign::test_assign_report_generator -v -o "addopts=" uv run pytest -m e2e test/e2e/test_supervisor_orchestration.py::TestCopilotCliSupervisorOrchestration::test_supervisor_handoff -v -o "addopts=" uv run pytest -m e2e test/e2e/test_supervisor_orchestration.py::TestCopilotCliSupervisorOrchestration::test_supervisor_assign_and_handoff -v -o "addopts=" uv run pytest -m e2e test/e2e/test_supervisor_orchestration.py::TestCopilotCliSupervisorOrchestration::test_supervisor_assign_three_analysts -v -o "addopts=" ``` ## Troubleshooting 1. **Copilot does not start** - Re-run `copilot login` - Verify `copilot --version` - Verify required flags in `copilot --help` 2. **Agent profile not applied** - Install profile: `cao install .md --provider copilot_cli` - Launch with `cao launch --agents --provider copilot_cli` 3. **MCP tools missing** - Ensure `cao-mcp-server` is resolvable in current environment 4. **Stuck in WAITING_USER_ANSWER** - Check active tmux pane for trust/confirmation prompt and answer once