|
| 1 | +--- |
| 2 | +name: upgrade-claude-adapter |
| 3 | +description: >- |
| 4 | + Sync this fork of @anthropic-ai/claude-agent-acp (packages/agent/src/adapters/claude) |
| 5 | + with a newer upstream release: bump the claude-agent-sdk / @agentclientprotocol/sdk, |
| 6 | + port upstream bug fixes and new SDK message handling, preserve the fork's divergences, |
| 7 | + verify, and update UPSTREAM.md. Use when asked to "upgrade/sync the claude adapter", |
| 8 | + "bump the agent SDK", or "port upstream claude-agent-acp changes". |
| 9 | +--- |
| 10 | + |
| 11 | +# Upgrade the Claude ACP adapter (upstream sync) |
| 12 | + |
| 13 | +This is a runbook for syncing our **fork** of `@anthropic-ai/claude-agent-acp` (the upstream |
| 14 | +Zed/agentclientprotocol ACP agent) that lives in `packages/agent/src/adapters/claude/` with a newer |
| 15 | +upstream release. The fork is heavily diverged. The job is to port the *valuable* upstream changes |
| 16 | +(SDK bumps, bug fixes, new SDK-message handling) while preserving every intentional divergence — not |
| 17 | +to make the fork identical to upstream. |
| 18 | + |
| 19 | +`UPSTREAM.md` (this directory) is the source of truth for the **fork point**, **last-synced |
| 20 | +version/commit**, the **file mapping**, the **PostHog-only code**, and the **intentional |
| 21 | +divergences**. Read it first, update it last. |
| 22 | + |
| 23 | +> This file is a runbook, not an auto-registered slash command. Invoke it by telling Claude to |
| 24 | +> "follow the upgrade skill in the claude adapter dir." Move it to `.claude/skills/<name>/SKILL.md` |
| 25 | +> if you ever want it runnable as `/<name>`. |
| 26 | +
|
| 27 | +## Inputs you need before starting |
| 28 | + |
| 29 | +1. **Upstream source checkout** — a local git clone of `github.com/agentclientprotocol/claude-agent-acp`. |
| 30 | + You need its history to diff. If the user hasn't given the path, **ask for it** (it's usually |
| 31 | + somewhere like `~/Cloud/claude-agent-acp`). Do not guess. |
| 32 | +2. **This repo** — the fork under `packages/agent/`. |
| 33 | + |
| 34 | +## Process |
| 35 | + |
| 36 | +### 0. Orient (read, don't write) |
| 37 | + |
| 38 | +- Read `UPSTREAM.md`. Note **Last sync** (commit + version), the pinned **SDK** versions, the |
| 39 | + **File Mapping**, **PostHog Code-Only Code (Do Not Sync)**, and **Intentional Divergences**. |
| 40 | +- In the upstream checkout, list the change set since the last sync and skim the changelog: |
| 41 | + - `git -C <upstream> log --oneline <last-sync-sha>..HEAD` |
| 42 | + - `git -C <upstream> show <upstream>/CHANGELOG.md:CHANGELOG.md` (or just read `CHANGELOG.md`) |
| 43 | +- Confirm the new target version + HEAD sha and the target SDK versions from the upstream |
| 44 | + `package.json`. |
| 45 | + |
| 46 | +### 1. Triage every commit |
| 47 | + |
| 48 | +Bucket each commit since the last sync: |
| 49 | + |
| 50 | +- **Port** — bug fixes and new feature / SDK-message handling that are *not* in the PostHog-only |
| 51 | + list and don't fight a divergence. |
| 52 | +- **Dep bump** — record the target SDK versions; the diff tells you if code changes ride along. |
| 53 | +- **Skip** — `chore(main): release …`, `actions/* ` CI bumps, pure dependabot **dev**-dep bumps, and |
| 54 | + anything matching the PostHog-only / divergence lists. |
| 55 | + |
| 56 | +Read intent from source diffs (exclude tests + JSON first): |
| 57 | + |
| 58 | +``` |
| 59 | +git -C <upstream> show <sha> -- src/ ':(exclude)src/tests/*' ':(exclude)*.json' |
| 60 | +``` |
| 61 | + |
| 62 | +A dependabot SDK-bump commit often *also* carries real code (new message handling). Don't assume |
| 63 | +"deps" == "no code". |
| 64 | + |
| 65 | +### 2. Map upstream → fork |
| 66 | + |
| 67 | +Upstream is one large `src/acp-agent.ts`; our fork is split. Use the File Mapping in `UPSTREAM.md`. |
| 68 | +Rough guide: |
| 69 | + |
| 70 | +| Upstream | Fork | |
| 71 | +| --- | --- | |
| 72 | +| `acp-agent.ts` prompt loop, lifecycle, cancel | `claude-agent.ts` | |
| 73 | +| inline message/stream/result/system conversion | `conversion/sdk-to-acp.ts` | |
| 74 | +| inline prompt→SDK conversion | `conversion/acp-to-sdk.ts` | |
| 75 | +| `tools.ts` (tool_use→ACP, PostToolUse hook) | `conversion/tool-use-to-acp.ts`, `hooks.ts` | |
| 76 | +| model alias resolution | `session/models.ts`, `session/model-config.ts` | |
| 77 | +| options / system prompt | `session/options.ts` | |
| 78 | +| permissions | `permissions/*` | |
| 79 | + |
| 80 | +For each upstream change, `rg` the fork for the touched symbol first — the fork usually already has a |
| 81 | +diverged version of it, so you're editing, not adding. |
| 82 | + |
| 83 | +### 3. Bump dependencies |
| 84 | + |
| 85 | +In `packages/agent/package.json`, set `@anthropic-ai/claude-agent-sdk`, `@agentclientprotocol/sdk`, |
| 86 | +and `@anthropic-ai/sdk` to the upstream `package.json` versions, then `pnpm install` from the repo |
| 87 | +root. (`packages/shared` pins its own older `@agentclientprotocol/sdk`; leave it unless a |
| 88 | +cross-package type error forces a bump.) |
| 89 | + |
| 90 | +### 4. Find the breaking-change surface |
| 91 | + |
| 92 | +Run `pnpm --filter agent typecheck`. The errors are your ACP/SDK breaking-change list. Gotchas seen |
| 93 | +in past syncs: |
| 94 | + |
| 95 | +- **The ACP SDK ships name-mangled generated types.** `dist/schema/*.gen.d.ts` shows enum literals as |
| 96 | + `n` (e.g. `StopReason = "…" | "n" | "cancelled"`). Don't trust grep there. Read the hand-written |
| 97 | + `dist/acp.d.ts`, or download the exact target to inspect cleanly: |
| 98 | + ``` |
| 99 | + cd /tmp && npm pack @agentclientprotocol/sdk@<ver> && tar xzf *.tgz |
| 100 | + rg -n "type StopReason|deleteSession|SessionModelState" package/dist/schema/types.gen.d.ts package/dist/acp.d.ts |
| 101 | + ``` |
| 102 | +- **`node -e "require('<pkg>/package.json')"` may fail** on the SDKs (exports map blocks the subpath). |
| 103 | + Read `node_modules/<pkg>/package.json` directly for the installed version. |
| 104 | +- **An ACP SDK bump can break code outside the claude adapter.** The whole `packages/agent` package |
| 105 | + must typecheck — expect to also fix `adapters/codex/*` and `server/agent-server.ts`. Keep those |
| 106 | + fixes minimal and behavior-preserving (e.g. when ACP removed the `models` response field, the codex |
| 107 | + adapter derived the model id from `configOptions` instead). |
| 108 | + |
| 109 | +### 5. Port in phases — bug fixes first, then features |
| 110 | + |
| 111 | +For each ported change: |
| 112 | + |
| 113 | +- **Preserve divergences** (see `UPSTREAM.md` → Intentional Divergences + PostHog-only). The big ones: |
| 114 | + single-session `this.session` (not `this.sessions[id]`); `interruptReason` on cancel; gateway models |
| 115 | + via `fetchGatewayModels` (not `initializationResult.models`); `_posthog/*` ext notifications; |
| 116 | + the "Unsupported slash command" gate on `knownSlashCommands`; `SYSTEM_REMINDER` stripping; plan / |
| 117 | + questions / MCP-metadata machinery. |
| 118 | +- **New SDK `system` subtypes are safe by default.** `handleSystemMessage` ends in `default: break`, |
| 119 | + and the prompt-loop top-level `switch (message.type)` only `unreachable()`s unknown top-level |
| 120 | + *types*. So a new subtype won't crash the loop — port real handling only where there's user value |
| 121 | + (e.g. `permission_denied` → failed tool_call, `tool_progress` → in_progress, `commands_changed` → |
| 122 | + available_commands_update, `mirror_error` → log). |
| 123 | +- When upstream reads new fields (`stop_details`, `getContextUsage`, `thinking`), confirm the |
| 124 | + installed SDK `.d.ts` actually has them before porting. Skip ports the fork can't use (e.g. the |
| 125 | + fork doesn't read `MAX_THINKING_TOKENS`, so upstream's `resolveThinkingConfig` was N/A). |
| 126 | +- Typecheck after each logical group, not just at the end. |
| 127 | + |
| 128 | +### 6. Verify (all of it) |
| 129 | + |
| 130 | +``` |
| 131 | +pnpm --filter agent typecheck |
| 132 | +pnpm --filter agent build |
| 133 | +npx biome check --write <changed files> # biome is the formatter/linter, not prettier/eslint |
| 134 | +pnpm typecheck # whole repo: confirms apps/code compiles vs the new ACP SDK |
| 135 | +pnpm --filter agent test |
| 136 | +pnpm --filter code test |
| 137 | +``` |
| 138 | + |
| 139 | +- The `apps/code` renderer unit tests `analytics.test.ts` and `panelLayoutStore.test.ts` are **flaky** |
| 140 | + — they sometimes throw in `getElectronTRPC` / electron-trpc `ipcLink` depending on test ordering. If |
| 141 | + they fail, re-run; a clean rerun (or `git stash` + run on the clean tree) passing confirms it's the |
| 142 | + known flake, not your change. |
| 143 | + |
| 144 | +### 7. Update `UPSTREAM.md` (do this last) |
| 145 | + |
| 146 | +- Bump **Last sync** (version + HEAD sha + date) and the pinned **SDK** versions. |
| 147 | +- Add `## Changes Ported in v<X> Sync` (one bullet per change, with PR # and short sha) and |
| 148 | + `## Skipped in v<X> Sync` (with the reason for each skip). |
| 149 | +- If a port made a former divergence match upstream, move it out of the Intentional Divergences table. |
| 150 | + |
| 151 | +## Fork facts worth remembering |
| 152 | + |
| 153 | +- **Single session.** The agent owns one `this.session` (from `BaseAcpAgent`), not a `sessions` map. |
| 154 | + Upstream's per-session refactors usually collapse to "just use `this.session`". |
| 155 | +- **Renderer uses config options only.** Model/mode/effort selection is `SessionConfigOption` end to |
| 156 | + end; the renderer never reads the legacy `models` response field or calls `unstable_setSessionModel`. |
| 157 | + That's why upstream's ACP-0.24/0.25 model-state removals are safe to follow. |
| 158 | +- **`toolUseCache` is never cleared** in the fork (created once in the constructor), so long sessions |
| 159 | + accumulate — keep the prune-at-tool_result behavior, and make any PostToolUse hook close over the |
| 160 | + data it needs rather than re-reading the cache. |
| 161 | +- **Conversion is split out.** `claude-agent.ts` calls `handleSystemMessage` / `handleStreamEvent` / |
| 162 | + `handleResultMessage` / `handleUserAssistantMessage` from `conversion/sdk-to-acp.ts`. Upstream |
| 163 | + inlines all of this in `acp-agent.ts`. |
| 164 | +- **Don't commit or push** unless the user explicitly asks. Leave the work on the current branch. |
0 commit comments