@switchboard-host/cli 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,137 @@
1
- # Temporary Holding Version
1
+ # @switchboard-host/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The `switchboard` command line tool and MCP server. Customers (or, more often, their AI
4
+ coding agent) use it to log in, fetch their website, and publish it to Switchboard:
5
+
6
+ ```sh
7
+ npx -y @switchboard-host/cli@latest init bakkerij-jansen # login + clone + set up
8
+ npx -y @switchboard-host/cli@latest deploy # commit, push, wait until live
9
+ claude mcp add --scope user switchboard -- npx -y @switchboard-host/cli@latest mcp
10
+ # native Windows (not WSL):
11
+ # claude mcp add --scope user switchboard -- cmd /c npx -y @switchboard-host/cli@latest mcp
12
+ ```
13
+
14
+ The contract this implements is ARCHITECTURE.md §10 "CLI" (commands, config locations,
15
+ exit codes) and §5 "cliauth" (device login). This README is for the **operator**.
16
+
17
+ ## How it is built
18
+
19
+ - TypeScript in `src/`, bundled by esbuild (`build.mjs`) into **one ESM file**,
20
+ `dist/switchboard.mjs`. That file is the only thing published (`"files"` in
21
+ `package.json`). The MCP SDK and zod are bundled into it as well, so the package has **no
22
+ runtime dependencies**: `npx` downloads one small tarball and starts right away.
23
+ - Node ≥ 20. Everything else is Node built-ins (`fetch`, `child_process`, `readline`, `fs`).
24
+ - The default platform URL is **baked in at build time** from `SWITCHBOARD_DEFAULT_API_URL`.
25
+ Customers never have to type it. It can be overridden per run with `--api-url` or
26
+ `SWITCHBOARD_API_URL`, and `init`/`link` also record it in `.switchboard/app.json`.
27
+ That file is committed with the code, so it is not trusted: its `api_url` is only used when
28
+ it names the same host as `--api-url` / `SWITCHBOARD_API_URL` / the stored login / the
29
+ default. Another host is ignored with a warning, so no token (stored or `SWITCHBOARD_TOKEN`)
30
+ is ever sent to a host that only a repo file named.
31
+
32
+ | file | what |
33
+ | ------------------- | ------------------------------------------------------------------------------------- |
34
+ | `src/main.ts` | command dispatch, error handling, exit codes (0 ok, 1 error, 2 deploy failed) |
35
+ | `src/context.ts` | resolves flags, env, config file and the linked project once per run |
36
+ | `src/config.ts` | config file per OS (`%APPDATA%`, `~/Library/Application Support`, `$XDG_CONFIG_HOME`) |
37
+ | `src/api.ts` | JSON API client (`/api/v1`) |
38
+ | `src/device.ts` | device login (RFC 8628 polling) |
39
+ | `src/git.ts` | git wrappers, the repo-local credential helper setup |
40
+ | `src/credential.ts` | git credential helper protocol (`switchboard git-credential get`) |
41
+ | `src/deploy.ts` | the publish flow shared by `deploy` and the MCP `deploy` tool |
42
+ | `src/mcp.ts` | stdio MCP server (`switchboard mcp`) |
43
+ | `src/messages.ts` | all customer-facing text, Dutch + English (same keys; a test checks it) |
44
+ | `src/commands/*` | the commands |
45
+
46
+ ## Develop and test
47
+
48
+ ```sh
49
+ cd cli
50
+ npm install
51
+ npm run build # → dist/switchboard.mjs
52
+ npm test # typecheck + build + node:test suite (build/test/*.test.mjs)
53
+ node dist/switchboard.mjs --help
54
+ ```
55
+
56
+ Against a local platform (backend on :8000, frontend dev server on :5173):
57
+
58
+ ```sh
59
+ SWITCHBOARD_API_URL=http://localhost:5173 node dist/switchboard.mjs login
60
+ SWITCHBOARD_API_URL=http://localhost:5173 node dist/switchboard.mjs init my-site
61
+ ```
62
+
63
+ The tests need `git` on the PATH. They run an in-process mock platform (`test/helpers.ts`)
64
+ that speaks the API subset the CLI uses and real smart-HTTP git through `git http-backend`
65
+ with token auth, so `init` and `deploy` are tested end to end, including the credential
66
+ helper and the rebase on changes made elsewhere. Nothing talks to the network.
67
+
68
+ Useful environment variables while developing:
69
+
70
+ | variable | effect |
71
+ | ------------------------------- | ---------------------------------------------------------------------------- |
72
+ | `SWITCHBOARD_API_URL` | platform base URL (`https://switchboard.example`) |
73
+ | `SWITCHBOARD_TOKEN` | use this API token instead of the stored login (CI, scripts) |
74
+ | `SWITCHBOARD_CONFIG_DIR` | use another config directory |
75
+ | `SWITCHBOARD_LANG` / `--lang` | `nl` or `en` (default: account language, then `LANG`, then Dutch) |
76
+ | `SWITCHBOARD_NO_BROWSER` | never try to open a browser during login |
77
+ | `SWITCHBOARD_CREDENTIAL_HELPER` | exact git credential helper command for `init`/`link` to configure |
78
+ | `SWITCHBOARD_CLIENT_NAME` | name shown on the approve page / token ("Claude Code op laptop" is detected) |
79
+
80
+ ## Publish to npm
81
+
82
+ The package name is `@switchboard-host/cli` (the `CLI_PACKAGE` setting of the backend and
83
+ `brand.ts` in the frontend use it in the setup prompt). One-time: create the `switchboard-host`
84
+ organisation on npmjs.com and `npm login` as a member with publish rights (2FA recommended).
85
+
86
+ ```sh
87
+ cd cli
88
+ npm version patch # or minor / major; bumps package.json
89
+ SWITCHBOARD_DEFAULT_API_URL=https://switchboard.example npm publish
90
+ ```
91
+
92
+ `prepublishOnly` refuses to build without `SWITCHBOARD_DEFAULT_API_URL`, then builds and runs
93
+ the tests. `publishConfig.access` is `public` (scoped packages are private by default).
94
+ Check what will be uploaded with `npm pack --dry-run` (it should be `dist/switchboard.mjs`,
95
+ `README.md` and `package.json` only).
96
+
97
+ ## How `npx` usage works
98
+
99
+ - `npx -y @switchboard-host/cli@latest <cmd>`: `-y` skips the "install this package?"
100
+ question (agents cannot answer it); `@latest` makes npx check the registry, so customers
101
+ always run the newest release without updating anything. npx caches the package in
102
+ `~/.npm/_npx/`, so later runs only do a quick version check.
103
+ - git needs to call the CLI back for credentials. `init`/`link` configure a **repo-local**
104
+ helper for the platform host only:
105
+
106
+ ```
107
+ [credential "https://switchboard.example"]
108
+ helper =
109
+ helper = !npx -y @switchboard-host/cli@latest git-credential
110
+ useHttpPath = true
111
+ ```
112
+
113
+ The empty `helper =` line clears any OS helper (macOS Keychain, Git Credential Manager on
114
+ Windows) for this host, so git never pops up a password dialog. When the CLI is installed
115
+ globally (`npm i -g @switchboard-host/cli`), the helper is the absolute path of the current
116
+ `node` plus the installed script instead, which is faster. `switchboard doctor` notices when
117
+ that path no longer exists (e.g. after a Node upgrade) and `switchboard link` repairs it.
118
+
119
+ - The token itself lives only in the user's config file (mode 0600), never in the repo or in
120
+ `.git/config`. The helper prints username `switchboard` + that token, and only for the
121
+ platform host. When the user is logged out it answers `quit=1`, so git stops instead of
122
+ prompting.
123
+ - Git commands the CLI runs itself (clone, fetch, push during `deploy`) pass the token through
124
+ an environment variable to an inline helper, never on the command line.
125
+
126
+ ## Commands
127
+
128
+ `login`, `logout`, `whoami`, `apps`, `init <slug> [dir]`, `link [slug]`,
129
+ `deploy [-m msg] [--no-follow]`, `status`, `logs [-f] [--role frontend|backend] [-n N]`,
130
+ `env list|set KEY VALUE|- [--secret] [--allow-empty]|unset KEY`, `open [--dashboard]`, `domains`,
131
+ `rollback [number]`, `restart`, `doctor [--fix]`, `git-credential`, `mcp`.
132
+ Every command accepts `--json` (exactly one JSON document on stdout), `--app <slug>`,
133
+ `--lang`, `--api-url`, `--verbose`.
134
+
135
+ MCP tools: `deploy`, `deployment_status`, `deployment_log`, `app_logs`, `app_status`,
136
+ `list_apps`, `env_list`, `env_set`, `env_unset`, `domains_list`, `restart`. They resolve the
137
+ website from `.switchboard/app.json` in the agent's working folder, or take a `slug` argument.