|
| 1 | +# Research: Cline Subagent Architecture |
| 2 | + |
| 3 | +**Date:** 2026-02-24 |
| 4 | +**Status:** TODO — pick up in next session |
| 5 | + |
| 6 | +## Research Questions |
| 7 | + |
| 8 | +1. How does Cline form subagents? How does the AI decide how many to create? |
| 9 | +2. What task distribution strategy is used? How are tasks assigned to each subagent? |
| 10 | +3. How is context shared between parent agent and subagents? |
| 11 | +4. How are subagent outputs aggregated back into the main conversation? |
| 12 | +5. What happens when a subagent task errors? Error handling and recovery. |
| 13 | +6. How could this inspire improvements to opencode's existing subagent system? |
| 14 | + |
| 15 | +## Key References |
| 16 | + |
| 17 | +- **CLI Subagent Command Transformation**: `src/integrations/cli-subagents/subagent_command.ts` |
| 18 | + - `isSubagentCommand()` — identifies simplified cline commands |
| 19 | + - `transformClineCommand()` — injects `--json -y` flags for autonomous execution |
| 20 | + |
| 21 | +- **Agent Client Protocol (ACP)**: `cli/src/acp/AcpAgent.ts` |
| 22 | + - Bridges ClineAgent with AgentSideConnection for stdio-based communication |
| 23 | + - Handles permission requests, forwards session events |
| 24 | + |
| 25 | +- **ClineAgent**: `cli/src/agent/ClineAgent.ts` |
| 26 | + - Implements ACP agent interface |
| 27 | + - Translates ACP requests into core Controller operations |
| 28 | + - Manages authentication, session modes, processes user prompts |
| 29 | + |
| 30 | +- **Message Translator**: `cli/src/agent/messageTranslator.ts` |
| 31 | + - Converts ClineMessage objects to ACP SessionUpdate messages |
| 32 | + - Computes deltas for streaming (avoids duplicate content) |
| 33 | + |
| 34 | +## CodeWiki References |
| 35 | + |
| 36 | +- https://codewiki.google/github.com/cline/cline#cli-subagent-command-transformation |
| 37 | +- https://codewiki.google/github.com/cline/cline#command-line-interface-cli-functionality |
| 38 | +- https://codewiki.google/github.com/cline/cline#agent-client-protocol-acp-integration-for-external-control |
| 39 | + |
| 40 | +## Comparison with OpenCode's Subagent System |
| 41 | + |
| 42 | +OpenCode already has subagents (`TaskTool` in `packages/opencode/src/tool/task.ts`): |
| 43 | +- Subagents are spawned via the `task` tool |
| 44 | +- Each subagent gets its own child session |
| 45 | +- Subagent types: explore, plan, general (configurable per agent) |
| 46 | +- Results returned as tool output to parent session |
| 47 | + |
| 48 | +**Gaps to investigate:** |
| 49 | +- Does Cline support parallel subagents? (OpenCode does via plan mode Phase 1) |
| 50 | +- How does Cline's ACP protocol compare to opencode's Bus event system? |
| 51 | +- Can we adopt Cline's streaming delta pattern for subagent updates? |
| 52 | + |
| 53 | +## Tonight's Session Summary (2026-02-24, 2:37 AM - 4:57 AM) |
| 54 | + |
| 55 | +### 6 PRs Submitted to opencode (sst/opencode): |
| 56 | +1. **#14820** — Streaming content duplication fix (global-sdk.tsx voided Set) |
| 57 | +2. **#14821** — Font size settings (CSS vars + terminal + UI stepper) |
| 58 | +3. **#14826** — ContextOverflowError auto-recovery (processor.ts) |
| 59 | +4. **#14827** — Prune before compaction (prompt.ts) |
| 60 | +5. **#14831** — Context usage card with compact button (session-context-tab.tsx) |
| 61 | +6. **#14835** — Wide mode setting (full-width chat toggle) |
| 62 | + |
| 63 | +### Issues Created: |
| 64 | +- #14822, #14823, #14824, #14825, #14830, #14834 |
| 65 | + |
| 66 | +### All branches merged into `origin/dev` on fork (PrakharMNNIT/opencode) |
0 commit comments