Agent Client Protocol (ACP)¶
microharness includes a zero-dependency Agent Client Protocol (ACP) server (core/acp.py) speaking newline-delimited JSON-RPC 2.0 over stdio. Editors and orchestrators such as Zed, JetBrains IDEs, and T3 Code can launch microharness as a headless coding agent backend while keeping AgentLoop completely protocol-agnostic.
Launching the ACP Server¶
Run microharness acp (or pass --acp):
# Default workspace & configured provider/model
uv run microharness acp
# Explicit provider, model, and interactive permission prompts
uv run microharness acp --provider openrouter --model anthropic/claude-5.5-sonnet --permission-mode ask
# Sandboxed / offline-hardened ACP backend
uv run microharness acp --sandbox --no-network-tools --no-mcp
Stream Separation (stdout vs. stderr)¶
stdoutis reserved strictly for newline-delimited JSON-RPC 2.0 responses, notifications, and server-to-client requests.stderrreceives all diagnostic logs, warnings, model connection banners, and plugin notices (sys.stdoutis redirected tosys.stderrbefore CLI/model/harness setup).
Setting Up in T3 Code & Other ACP Clients¶
Option 1: Global CLI Install (Recommended)¶
Install microharness once so ACP clients can launch it from any workspace directory without uv run environment-resolution overhead:
# From PyPI (once released)
uv tool install microharness
# Or track a local git checkout cleanly
uv tool install --editable /path/to/microharness
Ensure global credentials and default model configuration exist in ~/.microharness/auth.json and ~/.microharness/config.json:
In T3 Code (Local command):
- Executable:
/Users/<you>/.local/bin/microharness(use the full path fromwhich microharness, since desktop apps may not inherit shellPATH) - Arguments (one argument per row):
acp- (Optional)
--permission-modeandaskto route mutating tool approvals to T3 Code cards - (Optional)
--no-mcpto skip connecting configured MCP servers duringsession/newfor faster session startup
Option 2: Direct from a Local Checkout (uv run)¶
If you prefer running directly from the repository without uv tool install, always pass --directory so uv resolves the microharness project regardless of the ACP client's working directory:
- Executable:
/path/to/uv(e.g.,/Users/<you>/.local/bin/uv) - Arguments:
run--directory/path/to/microharnessmicroharnessacp
Avoid bare uv run microharness acp in ACP clients
Passing uv + ["run", "microharness", "acp"] without --directory causes test sessions and external workspaces to fail ("The ACP agent could not create a test session") because uv run looks for pyproject.toml in the client's working directory instead of the microharness checkout. Calling the installed microharness binary directly also avoids uv run startup checks.
Supported Protocol Surface (ACP v1)¶
Lifecycle & Session Methods¶
| Method | Direction | Behavior |
|---|---|---|
initialize |
Client → Agent | Negotiates protocolVersion (1), returns agentInfo (microharness, package version) and agentCapabilities (loadSession, sessionCapabilities.close, sessionCapabilities.list, promptCapabilities.image, promptCapabilities.embeddedContext, mcpCapabilities.http/sse). |
session/new |
Client → Agent | Validates an absolute workspace cwd, sanitizes client-supplied mcpServers, initializes an isolated Harness + AgentLoop session returning {sessionId, models, modes, configOptions}, and emits initial available_commands_update and usage_update notifications. |
session/load |
Client → Agent | Resumes a persisted session from runs_dir (trace.json / trajectory.jsonl via load_session), replays text and image conversation history via session/update, emits available_commands_update + usage_update, and returns {models, modes, configOptions}. |
session/list |
Client → Agent | Lists active and persisted sessions (supporting optional cwd workspace filtering and cursor pagination) with sessionId, cwd, title, and ISO-8601 updatedAt. |
session/set_config_option |
Client → Agent | Dynamically switches session model, thought_level (off, low, medium, high, xhigh, max), mode (auto, ask, read-only), or cache_ttl (5m, 1h, off) and emits config_option_update (plus usage_update on model switches; legacy session/set_model and session/set_mode are also supported). |
session/prompt |
Client → Agent | Maps text, image (base64 data / mimeType or HTTP/data uri), resource, and resource_link prompt blocks into Message content, dispatches built-in slash commands (/compact, /undo, /status, /new) and custom commands / skills (/skill, /agent, /<command>), streams live session/update notifications on a worker thread, and returns {stopReason, usage?} (end_turn, cancelled, max_turn_requests, or refusal, plus per-turn inputTokens, outputTokens, totalTokens, and optional cachedReadTokens when reported). |
session/cancel |
Client → Agent (Notification) | Triggers cooperative mid-turn cancellation (CancellableModel.set_cancel_probe), aborts pending reverse requests for the session, drops incomplete tool turns cleanly, and resolves the active session/prompt with stopReason: "cancelled". |
session/close |
Client → Agent | Cancels any active turn on the session, tears down ToolProviders and Environment, and finalizes trace.json / trace.md. |
Live Streaming (session/update)¶
available_commands_update: Emitted when a session is created or loaded, advertising built-in ACP commands (compact,undo,status,new,skill,agent) alongside discovered project/global commands and skills.agent_thought_chunk: Emitted fromStreamingModelSTREAM_REASONINGdeltas (or non-streaming assistant reasoning fields), as well as childsubagentstep action summaries (↳ [agent] ...).agent_message_chunk: Emitted fromStreamingModelSTREAM_TEXTdeltas (or non-streaming assistant content).tool_call/tool_call_update: Emitted viaPRE_TOOL/POST_TOOLhooks withcore/tracer.pyaction titles, ACPkind(read,edit,search,execute,think,fetch,other),locations,rawInput,rawOutput,status(pending→in_progress→completed/failed), structureddiffcontent blocks (path,oldText,newText) on successfuledit_file/write_filecalls, and liveterminalcontent blocks (terminalId) when delegatingbashto client terminals.usage_update: Emitted on session start/load, after each step, on cancellation rollback, and when switching models with calibrated active context occupancy (used) and the active model's context window capacity (size).
Permissions, Client Callbacks & Security Guards¶
session/request_permission (--permission-mode ask)¶
When running with --permission-mode ask, GuardedEnvironment.confirm_action issues a bidirectional session/request_permission request to the client with four options (allow_once, allow_always, reject_once, reject_always).
allow_alwaysandreject_alwaysare cached per action within the session.- Denials,
cancelledoutcomes, timeouts, malformed responses, andstdindisconnects fail closed.
Client fs/* & terminal/* Delegation¶
When the client advertises clientCapabilities.fs.readTextFile, clientCapabilities.fs.writeTextFile, or clientCapabilities.terminal (and neither --sandbox nor --docker is active):
AcpClientEnvironmentdelegates workspace file reads/writes (fs/read_text_file,fs/write_text_file) and shell execution (terminal/create,terminal/wait_for_exit,terminal/output,terminal/kill,terminal/release) to the client.Environment.resolve_read_path/resolve_pathpath-traversal checks andGuardedEnvironment(read-only/ask) checks still execute before any client callback is issued, and reads outside the workspace (such as spilled logs or~/.microharness/skills/) stay local.
Client-Supplied mcpServers Trust Boundary¶
sanitize_acp_mcp_servers validates mcpServers passed in session/new / session/load:
- Rejects reserved internal bypass keys (
scope,allow_in_sandbox,sandbox,required) andenv:/bearer env:secret indirections. - Validates
http/httpsURLs and stdiocommand/args/envschemas. - Respects
--no-mcp,--no-network-tools,--sandbox/--docker, and--trust-project-tools(project.microharness/config.jsonservers and.microharness/tools/*.pyremain blocked unless--trust-project-toolsis set).
Declarative Defaults¶
Operational ACP defaults live in core/defaults.json:
| Key | Default | Description |
|---|---|---|
acp_protocol_version |
1 |
Negotiated ACP protocol version |
acp_request_timeout |
300.0 |
Timeout (seconds) for server-to-client requests |
acp_max_steps_per_turn |
30 |
Default step budget per session/prompt turn |
acp_max_sessions |
32 |
Maximum concurrent active sessions per ACP process |
acp_max_message_bytes |
10485760 |
Maximum incoming JSON-RPC frame size (10 MiB) |
acp_cancel_join_timeout |
5.0 |
Grace timeout (seconds) when joining worker threads on close/EOF |
acp_session_list_limit |
50 |
Page size returned per session/list response |
acp_session_scan_limit |
500 |
Maximum persisted sessions scanned per session/list call |