Using this skills to understand Agent Context Protocol when user mentioned or working with this.
ACP is a standard JSON-RPC based protocol that enables seamless communication between code editors (clients) and AI coding agents (servers). It operates over standard input/output (stdio), allowing the agent to run as a subprocess of the editor.
PDFScribe implements ACP to power its research capabilities using the local opencode binary.
AIService manages the high-level application state and selects the OpenCodeStrategy when the "OpenCode" provider is chosen.OpenCodeStrategy (in Services/Strategies/OpenCodeStrategy.swift) implements the specific ACP logic.JSONRPCClient (in Services/Infrastructure/JSONRPCClient.swift) handles encoding/decoding of JSON-RPC messages.ProcessManager manages the opencode subprocess lifecycle.The client launches opencode acp and sends an initialize request with client capabilities and info.
// OpenCodeStrategy.swift
let initParams = ["protocolVersion": 1, "capabilities": [...], "clientInfo": [...]]
client.createRequest(method: "initialize", params: initParams)
A session is created via session/new, establishing the working directory (cwd).
client.createRequest(method: "session/new", params: ["cwd": workingDirectory])
When a user sends a message, OpenCodeStrategy constructs a rich payload for session/prompt:
uri, mimeType, text).The client listens for session/update notifications to handle real-time feedback:
agent_message_chunk: Streaming text response.tool_call: Notifications when the agent (or sub-agent) executes a tool.tool_call_update: Status updates for tool execution.turn_complete: Signals the end of the agent's turn.The implementation explicitly handles sub-agent delegation. When a task tool is called, activeDelegationId is set to track the sub-agent's lifecycle. Output from the sub-agent is handled distinctly from the main agent's stream to ensure correct UI representation.