@photon-ai/cli 0.1.4

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.
Files changed (3) hide show
  1. package/README.md +258 -0
  2. package/dist/photon.js +153 -0
  3. package/package.json +63 -0
package/README.md ADDED
@@ -0,0 +1,258 @@
1
+ # Photon CLI
2
+
3
+ Typed terminal UI for the [Photon Dashboard](https://photon.codes). Replaces the web UI for everyday work — manage projects, Spectrum users / lines / platforms, billing, and your developer profile from a terminal.
4
+
5
+ ```sh
6
+ npx @photon-ai/cli login # try it without installing
7
+ bun add -g @photon-ai/cli # or install for daily use
8
+ ```
9
+
10
+ ---
11
+
12
+ ## Install
13
+
14
+ Three options. Pick whichever fits.
15
+
16
+ ### 1. One-off — no install (`npx` / `bunx`)
17
+
18
+ ```sh
19
+ npx @photon-ai/cli login
20
+ bunx @photon-ai/cli projects ls
21
+ ```
22
+
23
+ Each invocation pulls the latest release on demand. Good for scripts, throwaway machines, or trying the CLI before committing. Requires Bun on `PATH` (the bundle has a `#!/usr/bin/env bun` shebang) — install it once with:
24
+
25
+ ```sh
26
+ curl -fsSL https://bun.sh/install | bash
27
+ ```
28
+
29
+ ### 2. Global install — daily use (`bun add -g`)
30
+
31
+ ```sh
32
+ bun add -g @photon-ai/cli
33
+ photon login
34
+ ```
35
+
36
+ After install, `photon` is on your `PATH`. The `pho` alias (see below) is created automatically the first time you run `photon`.
37
+
38
+ ### 3. Standalone binary — no Bun, no Node
39
+
40
+ For CI environments or systems where you don't want any runtime:
41
+
42
+ ```sh
43
+ # pick your platform from https://github.com/photon-hq/cli/releases/latest
44
+ curl -L -o /usr/local/bin/photon \
45
+ https://github.com/photon-hq/cli/releases/latest/download/photon-darwin-arm64
46
+ chmod +x /usr/local/bin/photon
47
+ photon --version
48
+ ```
49
+
50
+ Available for macOS (arm64 / x64) and Linux (x64 / arm64). Each binary ships with a corresponding `.sha256` checksum on the same release page.
51
+
52
+ ---
53
+
54
+ ## Quickstart
55
+
56
+ ```sh
57
+ # 1. Log in (opens a browser to approve the device)
58
+ photon login
59
+
60
+ # 2. Pick a project for this shell session
61
+ photon projects ls
62
+ export PHOTON_PROJECT_ID=<project-id>
63
+
64
+ # 3. Off you go
65
+ photon projects show
66
+ photon spectrum users ls
67
+ photon billing show
68
+ ```
69
+
70
+ ### The `pho` alias
71
+
72
+ `pho` is a shortcut for `photon`, useful for high-frequency commands. It's created automatically as a sibling symlink the first time you run `photon` after installing — so no setup needed for global installs:
73
+
74
+ ```sh
75
+ pho ls # photon projects ls
76
+ pho whoami
77
+ ```
78
+
79
+ (`npx` / `bunx` users don't get `pho` since they're already typing the full package name; the alias is only created when running through an installed `photon` binary.)
80
+
81
+ ---
82
+
83
+ ## Concepts
84
+
85
+ ### Backend host
86
+
87
+ Every command talks to a backend URL. The default — and the only URL baked into the public bundle — is production (`https://app.photon.codes`). To target any other backend (your own deployment, a staging environment, a local dev server), set `PHOTON_API_HOST`:
88
+
89
+ ```sh
90
+ export PHOTON_API_HOST=https://your.backend.tld
91
+ photon login
92
+ photon projects ls
93
+
94
+ # Or one-off, per command:
95
+ photon projects ls --api-host https://your.backend.tld
96
+
97
+ # Or inline:
98
+ PHOTON_API_HOST=https://your.backend.tld photon projects ls
99
+ ```
100
+
101
+ Resolution order: `--api-host <url>` flag → `PHOTON_API_HOST` env var → built-in production.
102
+
103
+ `photon env current` prints the resolved host:
104
+
105
+ ```sh
106
+ $ photon env current
107
+ production (https://app.photon.codes)
108
+ $ PHOTON_API_HOST=http://localhost:3000 photon env current
109
+ localhost_3000 (http://localhost:3000)
110
+ ```
111
+
112
+ Credentials are stored **per host** (`$PHOTON_CONFIG_DIR/credentials/<key>.json` by default — see [config dir](#config-dir) below — mode 600), so you can be logged into multiple backends simultaneously. The `<key>` is derived from the URL — production keeps the literal name `production` for back-compat; other hosts get a sanitized hostname where `.`, `:`, and `%` are replaced with `_` (e.g. `staging-app_photon_codes`, `localhost_3000`). The `_` substitution avoids collisions between distinct hosts like `a-b.com` and `a.b-com`.
113
+
114
+ ### Setting an active project
115
+
116
+ Most commands operate on a single project. Two ways to specify it:
117
+
118
+ ```sh
119
+ # Per command — explicit, scoped to one invocation
120
+ photon spectrum users ls --project abc123
121
+
122
+ # Per shell — set once, applies to every photon invocation in this shell
123
+ export PHOTON_PROJECT_ID='abc123'
124
+ photon spectrum users ls
125
+ photon projects show
126
+ ```
127
+
128
+ Resolution order: `--project <id>` flag → `$PHOTON_PROJECT_ID` → friendly error.
129
+
130
+ Put `export PHOTON_PROJECT_ID='…'` in your shell rc, or use [`direnv`](https://direnv.net/) to scope it to a directory. Agents and scripts should pass `--project <id>` explicitly per call (or set the env var on the spawn).
131
+
132
+ **Multi-backend note.** `$PHOTON_PROJECT_ID` is shell-global and single-valued. If you switch `PHOTON_API_HOST` between backends in the same shell, prefer `--project <id>` for the off-default calls, or use a separate shell per backend.
133
+
134
+ ### CI / scripting
135
+
136
+ Authenticate once locally, copy the token from your credentials file (under `$PHOTON_CONFIG_DIR/credentials/<key>.json`), and use it in CI:
137
+
138
+ ```sh
139
+ photon projects ls --token "$PHOTON_TOKEN"
140
+ # or
141
+ PHOTON_TOKEN=… photon projects ls
142
+ ```
143
+
144
+ Pair with `--json` for machine-readable output:
145
+
146
+ ```sh
147
+ photon projects ls --json | jq '.[] | .id'
148
+ photon billing show --json
149
+ ```
150
+
151
+ `PHOTON_TOKEN` reuses the same access token issued by the device flow (default 7d expiry — re-run `photon login` when it expires). A long-lived API-key path is on the roadmap.
152
+
153
+ ---
154
+
155
+ ## Command reference
156
+
157
+ ```text
158
+ photon
159
+ ├── ping hit /api/health
160
+ ├── env current print resolved API host
161
+ ├── login [--api-host] [--no-browser] device-auth login
162
+ ├── logout [--api-host] clear creds
163
+ ├── whoami [--api-host] who am I on this backend
164
+ ├── auth status login state across backends
165
+ ├── config show dump active config
166
+ ├── projects
167
+ │ ├── ls list projects
168
+ │ ├── show [id] project detail
169
+ │ ├── create [--name <n> --location <loc> --spectrum] new project
170
+ │ ├── update [id] [...] rename / toggle flags
171
+ │ ├── delete [id] [-y] permanent delete
172
+ │ ├── regenerate-secret [id] [-y] rotate Spectrum secret
173
+ │ ├── open [id] open dashboard in browser
174
+ │ └── check-phone <number> availability check
175
+ ├── profile show / init / update developer / org profile
176
+ ├── spectrum
177
+ │ ├── users ls / add / remove
178
+ │ ├── lines ls / add / remove
179
+ │ ├── platforms ls / enable / disable
180
+ │ ├── profile show / update
181
+ │ └── avatar upload <file>
182
+ └── billing
183
+ ├── plans available plans
184
+ ├── show current subscription
185
+ ├── checkout --plan <price-id> Stripe Checkout (browser)
186
+ └── manage Stripe Customer Portal
187
+ ```
188
+
189
+ Run `photon <cmd> --help` for the full flag list of any command.
190
+
191
+ ---
192
+
193
+ ## Flags
194
+
195
+ Only `--debug` is truly **program-level** (works in any position). Every other flag is **per-command** and must come after the subcommand:
196
+
197
+ ```sh
198
+ photon --debug projects ls --api-host https://x.tld --json # ✓ --debug global, others per-cmd
199
+ photon --api-host https://x.tld projects ls # ✗ won't work (--api-host is per-cmd)
200
+ ```
201
+
202
+ | Flag | Env var | Scope | Effect |
203
+ |---|---|---|---|
204
+ | `--debug` | `PHOTON_DEBUG=1` | program | verbose HTTP logs to stderr |
205
+ | `--api-host <url>` | `PHOTON_API_HOST` | per-cmd | override the backend URL |
206
+ | `-p, --project <id>` | `PHOTON_PROJECT_ID` | per-cmd | project id for this command; defaults to `$PHOTON_PROJECT_ID` |
207
+ | `-t, --token <token>` | `PHOTON_TOKEN` | per-cmd | bypass stored creds (CI) |
208
+ | `--json` | — | per-cmd | structured output (opt-in) |
209
+ | `--yes`, `-y` | — | per-cmd | skip destructive-action confirmation |
210
+ | `--no-browser` | — | per-cmd | don't auto-open browser (login, billing, projects open) |
211
+ | `--no-color` | `NO_COLOR=1`, `PHOTON_NO_COLOR=1` | program (env-driven) | disable colors (NO_COLOR standard) |
212
+
213
+ ### config dir
214
+
215
+ The CLI's config root is resolved in this order:
216
+
217
+ 1. `$PHOTON_CONFIG_DIR` (explicit override)
218
+ 2. `$XDG_CONFIG_HOME/photon` (XDG standard)
219
+ 3. `~/.config/photon/` (default)
220
+
221
+ If a legacy `~/.config/photon-dashboard/` directory exists from a prior pre-rename install, it migrates automatically to the new path on first run.
222
+
223
+ Other env vars: `PHOTON_TYPES_SRC` (maintainer-only, for `bun run sync:api`), `PHOTON_NO_UPDATE_NOTIFIER=1` (mute update prompt).
224
+
225
+ ---
226
+
227
+ ## Development
228
+
229
+ ```sh
230
+ git clone https://github.com/photon-hq/cli
231
+ cd cli
232
+ bun install
233
+
234
+ # Run from source
235
+ bun run src/index.ts --help
236
+
237
+ # Watch
238
+ bun run dev
239
+
240
+ # Typecheck
241
+ bun run typecheck
242
+
243
+ # Build (produces dist/photon.js)
244
+ bun run build
245
+
246
+ # Sync API types from a sibling `dashboard` checkout (maintainer)
247
+ bun run sync:api
248
+ ```
249
+
250
+ The CLI's API contract comes from the `@photon-ai/api-public` type bundle, vendored at `types/api.d.ts`. To refresh after the dashboard's API surface changes, run `bun run sync:api` (looks for the sibling checkout by default; set `PHOTON_TYPES_SRC` to override).
251
+
252
+ See [`docs/cli-design.md`](docs/cli-design.md) and [`docs/cli-build-plan.md`](docs/cli-build-plan.md) for the full architecture notes.
253
+
254
+ ---
255
+
256
+ ## Releases
257
+
258
+ Tagged via PR labels. Add the `release` label to any PR; on merge to `main`, the [Release workflow](.github/workflows/release.yaml) (a thin caller of [`photon-hq/buildspace`'s `typescript-service-release`](https://github.com/photon-hq/buildspace)) generates a version + notes, bumps `package.json`, creates a GitHub Release, and publishes to npm. Standalone binaries are uploaded by [`release-binaries.yaml`](.github/workflows/release-binaries.yaml) on each release.