Skip to content

feat(adapter): add amp adapter (selective passthrough)#493

Open
rynfar wants to merge 16 commits into
mainfrom
feat/amp-adapter
Open

feat(adapter): add amp adapter (selective passthrough)#493
rynfar wants to merge 16 commits into
mainfrom
feat/amp-adapter

Conversation

@rynfar
Copy link
Copy Markdown
Owner

@rynfar rynfar commented May 7, 2026

Summary

  • Adds an adapter for Amp, Sourcegraph's coding agent (npm: @sourcegraph/amp).
  • Selective passthrough architecture: intercept /api/provider/anthropic/* (Claude inference via Claude Max), forward every other Amp endpoint to AMP_UPSTREAM_URL (default https://ampcode.com). Threads sync, attachments, telemetry, login, usage, code review, skills, MCP, permissions all keep working — entire Amp app remains usable.
  • New ampForwarder module handles HTTP and SSE streaming with proper Content-Encoding handling so Bun-fetch's auto-decoded responses don't trigger client-side ZlibError.
  • Detection by path prefix (/api/provider/anthropic/) or any x-amp-* header.
  • Snake_case tool mapping (create_file, edit_file, bash) for file-change extraction.
  • Confirmed end-to-end against real amp CLI (v0.0.1778130306-g2889d9): inference round-trips through Claude Max, free-tier user bypasses Sourcegraph's 402 paywall on amp -x.

Setup

npm install -g @sourcegraph/amp
amp login                                    # one time, against real ampcode.com
export AMP_URL=http://127.0.0.1:3456         # then point at Meridian
export AMP_API_KEY=$(python3 -c "import json,os; print(json.load(open(f'{os.path.expanduser(\"~\")}/.local/share/amp/secrets.json'))['apiKey@https://ampcode.com/'])")
amp -x "say hi"

(AMP_API_KEY is needed because Amp keys credentials by URL — the stored key is for https://ampcode.com, not the local URL.)

Configuration

Env var Default Purpose
AMP_UPSTREAM_URL https://ampcode.com Forward target for non-inference traffic
MERIDIAN_AMP_FORWARD_DISABLED unset Disable forwarding entirely

Test plan

  • Unit tests: src/__tests__/amp-adapter.test.ts (33 tests), src/__tests__/amp-forwarder.test.ts (10 tests)
  • Detection tests in src/__tests__/adapter-detection.test.ts (7 new cases)
  • HTTP-layer integration tests in src/__tests__/amp-integration.test.ts (9 tests)
  • npm test1791 passing, 0 failing
  • npm run build — clean
  • Live verification matrix against real amp CLI on port 3458:
    • Inference: I1 round-trip ✓ I2 glob/grep ✓ I3 read_file ✓ I4 create_file (file written) ✓ I5 thinking blocks (with reasoning) ✓ I7 count_tokens ✓ I8 deep mode (402 from ampcode.com proves cross-provider forwarding works) ✓
    • Forwarder: T1 threads list ✓ (after Content-Encoding fix) T2 new thread ✓ T4 search ✓ S1 skill list ✓ Tl1 tools list ✓ M1 mcp list ✓ P1 permissions list ✓ A2 usage display ✓
    • Multimodal (I9) deferred for manual UI testing — not blocking.

Notable bug found and fixed during verification

amp threads list initially failed with ZlibError. Bun's native fetch() transparently decodes gzipped response bodies but preserves the original Content-Encoding: gzip header. Forwarding that header verbatim made Amp's client try to gunzip an already-decoded body. Fix: strip Content-Encoding and Content-Length from forwarded responses (commit 510c28a). Regression test included.

Spec & plan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant