Skip to content

Commit ce7ed11

Browse files
feat: sync developer-cli from amplitude/javascript@1b44da248692 (#4)
Mirror monorepo developer-cli/ at 1b44da24869290a2a4f10ca3d4fbdc3228ada2e7. Includes: - MCP-472 charts commands and read:analytics in default OAuth scopes - BA-426/BA-444 agent device login (start/poll) and JSON output mode - MCP-431 external sync guards, public hygiene, no client-side telemetry (v1) - fastest-levenshtein dependency for CLI error hints Monorepo: 1b44da24869290a2a4f10ca3d4fbdc3228ada2e7 Checks: pnpm check:developer-cli-external-ready, sync --verify (415 tests) Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 7f47df0 commit ce7ed11

52 files changed

Lines changed: 7637 additions & 595 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,41 @@ readability; agents want minimal characters.
9595
never cost correctness).
9696
- Human-only adornments (spinners, prompts, ANSI codes) leaking into
9797
non-interactive output.
98+
99+
## Conventions for changing commands (and how they're enforced)
100+
101+
The rubric: the CLI optimizes for the agent characteristics that underpin
102+
MCP — self-describing, semantic-not-prescriptive, structured/typed, uniform,
103+
progressive, actionable-failure, stable-identity, explicit — expressed
104+
CLI-natively rather than as a bolt-on protocol.
105+
106+
**Edit / add / remove a command checklist** — each item names the guard that
107+
enforces it:
108+
109+
- API commands come from the OpenAPI spec → regenerate (`pnpm generate:cli`);
110+
the manifest is the source of truth, never hand-edit `src/generated/**`.
111+
(`verify:generated`)
112+
- Auth/meta commands are hand-authored in `catalog.ts`'s `AUTH_COMMANDS`, kept
113+
in sync with the routing in `cli.ts`. (`catalog.test.ts` parity;
114+
`auth-flag-coverage.test.ts` proves handlers only read declared/global
115+
flags, so the misplaced-flag reject can't false-positive)
116+
- Every catalog command appears in help + JSON.
117+
(`help-drift.test.ts`/`help-json-drift.test.ts`)
118+
- Only authoritative/sourced fields belong in the catalog — no invented state
119+
(e.g. no method-derived `destructive`). Adding a serialized field trips
120+
`catalog-shape.test.ts`. Scopes come from the OpenAPI `x-required-scopes`
121+
extension.
122+
- Describe behavior semantically; no audience-targeting or scripted recipes in
123+
summaries, descriptions, hints, or help. (`semantic-copy.test.ts`)
124+
- Reader-aware output: prose at a TTY, JSON when piped or with `--json`
125+
(`shouldUseJsonOutput`/`formatJsonOutput`).
126+
- Failures: a structured JSON error on stderr plus a differentiated exit code
127+
via `CliError` — never a bare `Error` for a user-facing failure. Sanctioned
128+
exceptions (e.g. a TTY-only cancellation) carry a `// plain-error-ok: <reason>`
129+
marker on the throw. (exit-code map in `error-contract.test.ts`; every
130+
`throw new Error(` without that marker fails `cli-error-usage.test.ts`)
131+
- Exception: the device-flow verbs `auth login start`/`poll` always emit
132+
their `{status,message,…}` envelope on **stdout** (it is the command's
133+
primary output, relayed to the user), signalling failure via the exit code;
134+
`poll` uses exit 75 for a still-`pending` authorization. A thrown `CliError`
135+
on these paths keeps its own `error_code`/exit code.

‎README.md‎

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,37 @@ npx @amplitude/developer-cli help
4141

4242
## Authentication
4343

44-
Run `amp auth login` to authenticate via the OAuth device flow. Creating a
45-
profile is force-explicit — name it and pick its environment:
44+
Run `amp auth login` to authenticate via the OAuth device flow. Omit
45+
`--profile` and the CLI targets `default` — the implicit profile used when you
46+
don't name one. Picking a region stays explicit:
4647

4748
```bash
48-
amp auth login --profile prod --env prod # device flow → save + activate
49+
amp auth login --region us # device flow → "default" profile
4950
amp auth status # active credential, type, expiry
5051
amp context
5152
```
5253

53-
Profiles bind a credential to an environment (its `base_url`), so a staging
54-
token can never be sent to prod. Add more and switch between them:
54+
Profiles bind a credential to a region (its `base_url`), so an EU token can
55+
never be sent to prod. Name one explicitly when you want more than one:
5556

5657
```bash
57-
amp auth login --profile staging --env staging # activates staging
58+
amp auth login --profile eu --region eu # activates the EU profile
5859
amp auth use prod # switch back (no re-auth)
5960
amp auth list # * marks the active profile
60-
amp logout --profile staging # remove one
61+
amp logout --profile eu # remove one
6162
amp logout --all # remove every profile
6263
```
6364

6465
A bare `amp auth login` re-authenticates the active profile in place. Profiles
6566
are saved to `~/.amplitude/amp/credentials.json` (0600).
6667

67-
Prefer a Personal Access Token? `amp auth pat --with-token --profile <name> --env <env>`
68-
reads a PAT from stdin (or a masked prompt at a terminal) and saves it as a
69-
profile — same force-explicit create rule, same store, just a different
70-
credential type. `--with-token` is required.
68+
Prefer a Personal Access Token? `amp auth pat --with-token --region <us|eu>` reads a
69+
PAT from stdin (or a masked prompt at a terminal) and saves it as a profile —
70+
`--profile` optional (defaults to `default`), same force-explicit create rule,
71+
same store. `--with-token` is required.
7172

7273
```bash
73-
echo "$PAT" | amp auth pat --with-token --profile ci --env prod
74+
echo "$PAT" | amp auth pat --with-token --region us
7475
```
7576

7677
For CI or a one-off shell, set a raw token — it overrides stored profiles:
@@ -82,22 +83,6 @@ export AMP_TOKEN=amp_... # amp_… is treated as a PAT, anything else a b
8283
`AMP_PROFILE` selects a stored profile by name; `amp auth token` prints the
8384
active access token to stdout (`TOKEN=$(amp auth token)`).
8485

85-
## Base URL
86-
87-
Defaults to production:
88-
89-
```text
90-
https://developer-api.amplitude.com
91-
```
92-
93-
Override for staging or a local server:
94-
95-
```bash
96-
export AMP_API_BASE_URL=http://localhost:3036
97-
# or
98-
amp --base-url http://localhost:3036 context
99-
```
100-
10186
## Examples
10287

10388
```bash

‎docs/cli.md‎

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,42 @@ OpenAPI spec. A handwritten runtime in `src/cli.ts` maps flags to HTTP requests.
55

66
## Authentication
77

8-
Authenticate via the OAuth device flow and save the result as a named profile.
9-
Creating a profile is force-explicit — name it and pick its environment:
8+
Authenticate via the OAuth device flow and save the result as a profile. Omit
9+
`--profile` and the CLI targets `default` — the implicit profile used when you
10+
don't name one. Picking a region stays explicit:
1011

1112
```bash
12-
amp auth login --profile prod --env prod
13+
amp auth login --region us
1314
```
1415

15-
That runs the device flow against the chosen environment's Developer API, saves
16+
That runs the device flow against the chosen region's Developer API, saves
1617
the token to `~/.amplitude/amp/credentials.json` (0600), and activates the
17-
profile. A
18-
profile binds a credential to an environment (`base_url`), so a staging token
19-
can never be sent to prod.
18+
profile. A profile binds a credential to a region (`base_url`), so an EU
19+
token can never be sent to prod.
2020

2121
```bash
22-
amp auth login --profile staging --env staging # activates staging
22+
amp auth login --profile eu --region eu # activates the EU profile
2323
amp auth use prod # switch (no re-auth)
2424
amp auth list # * marks the active profile
2525
amp auth status # type, base URL, expiry
26-
amp logout --profile staging # remove one
26+
amp logout --profile eu # remove one
2727
amp logout --all # remove every profile
2828
```
2929

30-
A bare `amp auth login` re-authenticates the active profile in place (env from
31-
its record). `--env` maps `local|dev|staging|prod|prod-eu` to a base URL; pass
32-
`--base-url <url>` instead to target an arbitrary host.
30+
A bare `amp auth login` re-authenticates the active profile in place (region
31+
from its record). `--region` maps `us|eu` to a base URL.
3332

3433
To use a Personal Access Token instead of the device flow:
3534

3635
```bash
37-
echo "$PAT" | amp auth pat --with-token --profile ci --env prod # stdin
38-
amp auth pat --with-token --profile ci --env prod # masked prompt at a TTY
36+
echo "$PAT" | amp auth pat --with-token --region us # stdin → "default" profile
37+
amp auth pat --with-token --profile ci --region us # name it; masked prompt at a TTY
3938
```
4039

41-
`--with-token` reads the PAT from stdin when piped (the agent / CI path) or a
42-
masked prompt at a terminal (the human path). Same force-explicit create rule
43-
and store as `login`; the credential is saved as `{ "type": "pat" }`.
40+
`--with-token` reads the PAT from stdin when piped, or from a masked prompt at a
41+
terminal. Same rules as `login`: `--profile`
42+
is optional (defaults to `default`) and `--region` is required to create a
43+
profile; the credential is saved as `{ "type": "pat" }`.
4444

4545
`--with-token` is mandatory: it makes the supply-an-existing-PAT path explicit
4646
and keeps the bare `amp auth pat` verb reserved.
@@ -54,7 +54,7 @@ profile; `amp auth status` announces when it is in effect.
5454

5555
```bash
5656
export AMP_TOKEN=amp_... # one-off / CI; overrides stored profiles
57-
export AMP_PROFILE=staging # select a stored profile by name
57+
export AMP_PROFILE=eu # select a stored profile by name
5858
```
5959

6060
Accepted forms for `--token` / `AMP_TOKEN`:
@@ -78,15 +78,27 @@ scopes below document what each command needs.
7878
| `context`, `projects list` | `read:projects` |
7979
| `events *` | `read:taxonomy`, `write:taxonomy` |
8080
| `flags *` | `read:flags`, `write:flags` |
81+
| `charts *` | `read:analytics` |
8182

8283
Route-level scopes are defined on each OpenAPI operation (`x-required-scopes`).
8384

85+
When adding new CLI scopes, ensure the OAuth client used for `amp auth login`
86+
allows those scopes before default login requests them. This requires an
87+
out-of-band update on Amplitude's side — contact Amplitude if your integration
88+
needs additional scopes.
89+
90+
## Developer API usage (server-side)
91+
92+
Authenticated requests to the Developer API (`amp projects list`, `amp flags
93+
create`, and other API commands) are measured and logged **server-side** as
94+
part of operating the service — route, HTTP status, your account/org, and client
95+
version (`User-Agent`).
96+
8497
## Global flags
8598

8699
| Flag / env | Purpose |
87100
| --------------------------------------- | ------------------------------------------ |
88-
| `--base-url` / `AMP_API_BASE_URL` | API host (default: prod) |
89-
| `--env <env>` | Friendly env name → base URL |
101+
| `--region <us\|eu>` | Data region name → base URL |
90102
| `--profile <name>` / `AMP_PROFILE` | Select a stored profile |
91103
| `--token` / `AMP_TOKEN` / saved profile | Auth token |
92104
| `--json` | Force raw JSON output (default when piped) |
@@ -97,7 +109,7 @@ Route-level scopes are defined on each OpenAPI operation (`x-required-scopes`).
97109
## Help and output
98110

99111
```bash
100-
amp help # product surfaces (context, projects, events, flags, …)
112+
amp help # product surfaces (context, projects, events, flags, charts, …)
101113
amp help flags # commands within a surface
102114
amp flags list --help # flags and examples for one command
103115
amp version
@@ -125,19 +137,12 @@ Manual checklist:
125137
3. **Projects** — `amp projects list`
126138
4. **Flags read** — `amp flags list --project <id> --limit 5`
127139
5. **Flags write** — create → get → update description → archive dry-run → archive
128-
6. **Events** — list → create → update → (optional delete with `--yes`)
140+
6. **Charts read** — `amp charts list --project <id> --limit 5`
141+
7. **Events** — list → create → update → (optional delete with `--yes`)
129142

130143
Known issue: `flags update --enabled false` fails for deployment-less flags.
131144
Avoid that path in smoke tests until it is fixed.
132145

133-
## Local server
134-
135-
Point at a running local server:
136-
137-
```bash
138-
amp --base-url http://localhost:3036 context
139-
```
140-
141146
## Generated files
142147

143148
Do not edit by hand:

0 commit comments

Comments
 (0)