@blinkdotnew/cli 0.1.1
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/AGENTS.md +291 -0
- package/dist/cli.js +1005 -0
- package/package.json +33 -0
- package/src/cli.ts +69 -0
- package/src/commands/ai.ts +164 -0
- package/src/commands/auth.ts +44 -0
- package/src/commands/connector.ts +32 -0
- package/src/commands/db.ts +98 -0
- package/src/commands/deploy.ts +119 -0
- package/src/commands/notify.ts +40 -0
- package/src/commands/project.ts +93 -0
- package/src/commands/rag.ts +71 -0
- package/src/commands/realtime.ts +34 -0
- package/src/commands/storage.ts +94 -0
- package/src/commands/web.ts +52 -0
- package/src/lib/api-app.ts +39 -0
- package/src/lib/api-resources.ts +36 -0
- package/src/lib/auth.ts +28 -0
- package/src/lib/config.ts +58 -0
- package/src/lib/output.ts +50 -0
- package/src/lib/project.ts +39 -0
- package/tsconfig.json +14 -0
- package/tsup.config.ts +13 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
# @blinkdotnew/cli — Blink Platform CLI
|
|
2
|
+
|
|
3
|
+
The unified CLI for the Blink platform. Pre-installed in every Blink Claw agent (Fly.io machine). Also usable by developers for CI/CD and "Deploy to Blink" workflows.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @blinkdotnew/cli deploy # human use
|
|
7
|
+
blink deploy proj_xxx ./dist --prod # agent use (zero config — env vars already set)
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## ⚠️ Critical: Two Backends, Never Mix
|
|
13
|
+
|
|
14
|
+
Every command routes to one of two backends. **Wrong backend = silent failure or wrong data.**
|
|
15
|
+
|
|
16
|
+
| Backend | Env var | Default | Owns |
|
|
17
|
+
|---|---|---|---|
|
|
18
|
+
| `blink.new` (auto-engineer, Next.js) | `BLINK_APP_URL` | `https://blink.new` | Deploy, project CRUD, logs, env vars, auth |
|
|
19
|
+
| `core.blink.new` (blink-apis, Express) | `BLINK_APIS_URL` | `https://core.blink.new` | DB, storage, AI, realtime, RAG, notify, connectors |
|
|
20
|
+
|
|
21
|
+
**Rule**: hosting/project/deploy → `BLINK_APP_URL`. Resources/AI/data → `BLINK_APIS_URL`.
|
|
22
|
+
|
|
23
|
+
In code: `src/lib/api-app.ts` → blink.new, `src/lib/api-resources.ts` → core.blink.new.
|
|
24
|
+
`x-blink-agent-id` header is sent **only** on `api-resources.ts` calls (for per-agent billing).
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Package Structure
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
packages/cli/
|
|
32
|
+
├── src/
|
|
33
|
+
│ ├── cli.ts # Entry point — registers all command groups
|
|
34
|
+
│ ├── commands/
|
|
35
|
+
│ │ ├── ai.ts # blink ai image/video/animate/speech/transcribe/text → core.blink.new
|
|
36
|
+
│ │ ├── auth.ts # blink login/logout/whoami → blink.new
|
|
37
|
+
│ │ ├── connector.ts # blink connector exec → core.blink.new
|
|
38
|
+
│ │ ├── db.ts # blink db query/exec/list → core.blink.new
|
|
39
|
+
│ │ ├── deploy.ts # blink deploy / deployments / rollback → blink.new
|
|
40
|
+
│ │ ├── notify.ts # blink notify email → core.blink.new
|
|
41
|
+
│ │ ├── project.ts # blink project / blink link / blink status → blink.new
|
|
42
|
+
│ │ ├── rag.ts # blink rag search/upload/collections → core.blink.new
|
|
43
|
+
│ │ ├── realtime.ts # blink realtime publish → core.blink.new
|
|
44
|
+
│ │ ├── storage.ts # blink storage upload/download/list/delete/url → core.blink.new
|
|
45
|
+
│ │ └── web.ts # blink fetch / blink search → core.blink.new
|
|
46
|
+
│ └── lib/
|
|
47
|
+
│ ├── api-app.ts # HTTP client → BLINK_APP_URL (blink.new)
|
|
48
|
+
│ ├── api-resources.ts # HTTP client → BLINK_APIS_URL (core.blink.new) + x-blink-agent-id
|
|
49
|
+
│ ├── auth.ts # Token resolution: --token flag > BLINK_API_KEY env > config file
|
|
50
|
+
│ ├── config.ts # Read/write ~/.config/blink/config.toml
|
|
51
|
+
│ ├── output.ts # chalk colors, ora spinners, cli-table3 tables, --json mode
|
|
52
|
+
│ └── project.ts # Read/write .blink/project.json, resolveProjectId()
|
|
53
|
+
├── dist/cli.js # Built ESM bundle (~40KB), shebang prepended by tsup
|
|
54
|
+
├── package.json # name: @blinkdotnew/cli, bin: { blink: ./dist/cli.js }
|
|
55
|
+
└── tsup.config.ts # banner: #!/usr/bin/env node, no splitting
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Full Command Reference
|
|
61
|
+
|
|
62
|
+
### Auth (→ blink.new)
|
|
63
|
+
```bash
|
|
64
|
+
blink login # Browser OAuth (Phase 2) or no-op if BLINK_API_KEY set
|
|
65
|
+
blink login --interactive # Prompt for API key — for headless/SSH
|
|
66
|
+
blink logout # Remove ~/.config/blink/config.toml entry
|
|
67
|
+
blink whoami # Show current user + workspace
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Project (→ blink.new)
|
|
71
|
+
```bash
|
|
72
|
+
blink link [project_id] # Interactive picker or direct link → writes .blink/project.json
|
|
73
|
+
blink unlink # Remove .blink/project.json
|
|
74
|
+
blink status # Show linked project + auth source
|
|
75
|
+
blink project list
|
|
76
|
+
blink project create <name>
|
|
77
|
+
blink project delete <project_id> [--yes]
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Deploy (→ blink.new)
|
|
81
|
+
```bash
|
|
82
|
+
blink deploy [project] [dir] # Upload pre-built output dir to Blink hosting
|
|
83
|
+
blink deploy --prod # Promote to production domain
|
|
84
|
+
blink deploy --preview # Preview deployment (default)
|
|
85
|
+
blink deployments [project] # List deployments
|
|
86
|
+
blink rollback [project] [dep_id] # Rollback production
|
|
87
|
+
```
|
|
88
|
+
**Deploy sends JSON with base64-encoded files** (not tar.gz). The `POST /api/project/[id]/deploy` endpoint in auto-engineer receives it, uploads to S3, updates Cloudflare KV.
|
|
89
|
+
|
|
90
|
+
### Database (→ core.blink.new /api/db/[project_id]/sql)
|
|
91
|
+
```bash
|
|
92
|
+
blink db query <sql> # Uses linked project
|
|
93
|
+
blink db query <project_id> <sql> # Explicit project
|
|
94
|
+
blink db exec <file.sql>
|
|
95
|
+
blink db list [table] # List tables or rows
|
|
96
|
+
```
|
|
97
|
+
**Arg disambiguation**: two args → arg1=project_id, arg2=sql. One arg → arg1=sql, uses linked project.
|
|
98
|
+
|
|
99
|
+
### Storage (→ core.blink.new /api/storage/[project_id]/...)
|
|
100
|
+
```bash
|
|
101
|
+
blink storage upload <file>
|
|
102
|
+
blink storage upload <project_id> <file> [--path images/photo.jpg]
|
|
103
|
+
blink storage list [prefix]
|
|
104
|
+
blink storage download <path> [output]
|
|
105
|
+
blink storage delete <path>
|
|
106
|
+
blink storage url <path>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### AI (→ core.blink.new /api/v1/ai/...)
|
|
110
|
+
```bash
|
|
111
|
+
blink ai text <prompt> [--model anthropic/claude-haiku-4.5]
|
|
112
|
+
blink ai image <prompt> [--model fal-ai/nano-banana] [--n 1] [--output file.jpg]
|
|
113
|
+
blink ai image-edit <prompt> <image-url> [--model fal-ai/nano-banana/edit]
|
|
114
|
+
blink ai video <prompt> [--model fal-ai/veo3.1/fast] [--duration 5s] [--aspect 16:9]
|
|
115
|
+
blink ai animate <prompt> <image-url-or-local-file> [--model ...] [--duration 5s]
|
|
116
|
+
blink ai speech <text> [--voice alloy] [--output speech.mp3]
|
|
117
|
+
blink ai transcribe <file-or-url> [--language en]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Web & Data (→ core.blink.new /api/v1/...)
|
|
121
|
+
```bash
|
|
122
|
+
blink fetch <url> [--method GET] [--body '{"k":"v"}'] [--header "X-Foo: bar"]
|
|
123
|
+
blink search <query> [--count 5]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Realtime (→ core.blink.new /api/realtime/[project_id]/publish)
|
|
127
|
+
```bash
|
|
128
|
+
blink realtime publish <channel> <data> # Linked project
|
|
129
|
+
blink realtime publish <project_id> <channel> <data>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### RAG (→ core.blink.new /api/rag/[project_id]/...)
|
|
133
|
+
```bash
|
|
134
|
+
blink rag search <query> [--ai] [--limit 5]
|
|
135
|
+
blink rag search <project_id> <query>
|
|
136
|
+
blink rag upload <file> [--collection <id>]
|
|
137
|
+
blink rag collections [project_id]
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Notifications (→ core.blink.new /api/notifications/[project_id]/email)
|
|
141
|
+
```bash
|
|
142
|
+
blink notify email <to> <subject> [body]
|
|
143
|
+
blink notify email <project_id> <to> <subject> [body]
|
|
144
|
+
blink notify email <to> <subject> --file ./body.html
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Connectors (→ core.blink.new /api/v1/connectors/[provider]/execute)
|
|
148
|
+
```bash
|
|
149
|
+
blink connector exec <provider> <action> [params-json] [--account <id>] [--method POST]
|
|
150
|
+
# e.g.: blink connector exec notion search_pages '{"query":"notes"}'
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Session Context
|
|
154
|
+
```bash
|
|
155
|
+
blink use <project_id> # Prints export command
|
|
156
|
+
eval $(blink use <project_id> --export) # Sets BLINK_ACTIVE_PROJECT in shell
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Global Flags (all commands)
|
|
160
|
+
```
|
|
161
|
+
--token <key> Override BLINK_API_KEY for this command
|
|
162
|
+
--json Machine-readable JSON output (disables spinners/colors)
|
|
163
|
+
--yes Skip confirmation prompts
|
|
164
|
+
--profile <name> Use named config profile (see ~/.config/blink/config.toml)
|
|
165
|
+
--debug Verbose request logging
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Auth Resolution (priority: high → low)
|
|
171
|
+
|
|
172
|
+
1. `--token <key>` flag
|
|
173
|
+
2. `BLINK_API_KEY` environment variable ← **always set in Claw Fly machines**
|
|
174
|
+
3. `~/.config/blink/config.toml` `[default]` or named `[profile]`
|
|
175
|
+
|
|
176
|
+
**In Fly machines**: `BLINK_API_KEY`, `BLINK_AGENT_ID`, `BLINK_APIS_URL`, `BLINK_APP_URL` are injected at machine creation — zero config needed.
|
|
177
|
+
|
|
178
|
+
**Multi-account** (for developers with multiple workspaces):
|
|
179
|
+
```toml
|
|
180
|
+
# ~/.config/blink/config.toml
|
|
181
|
+
[default]
|
|
182
|
+
api_key = "blnk_ak_..."
|
|
183
|
+
workspace_id = "wsp_xxx"
|
|
184
|
+
|
|
185
|
+
[work]
|
|
186
|
+
api_key = "blnk_ak_..."
|
|
187
|
+
workspace_id = "wsp_yyy"
|
|
188
|
+
```
|
|
189
|
+
Switch: `blink --profile work deploy`
|
|
190
|
+
|
|
191
|
+
**Project context** (priority: high → low):
|
|
192
|
+
1. `<project_id>` positional argument
|
|
193
|
+
2. `BLINK_ACTIVE_PROJECT` environment variable (`blink use` sets this)
|
|
194
|
+
3. `.blink/project.json` in current directory
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## How It's Used in Blink Claw Agents
|
|
199
|
+
|
|
200
|
+
Each Claw agent is a Fly.io Firecracker VM running the OpenClaw Docker image. The CLI is pre-installed at `/usr/local/bin/blink` in that image. Skills use it instead of raw curl:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
# Before (fragile curl):
|
|
204
|
+
curl -H "Authorization: Bearer ${BLINK_API_KEY}" -H "x-blink-agent-id: ${BLINK_AGENT_ID}" \
|
|
205
|
+
"${BLINK_APIS_URL}/api/v1/ai/image" -d '{"prompt":"..."}'
|
|
206
|
+
|
|
207
|
+
# After (CLI one-liner):
|
|
208
|
+
blink ai image "$PROMPT" --json
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Skill scripts live in `openclaw/skills/blink-*/scripts/`. After any CLI command change, update the relevant skill scripts.
|
|
212
|
+
|
|
213
|
+
**Machine env vars injected at agent creation** (`src/app/api/claw/agents/route.ts`):
|
|
214
|
+
```
|
|
215
|
+
BLINK_API_KEY → auth for all CLI commands
|
|
216
|
+
BLINK_AGENT_ID → sent as x-blink-agent-id on resource calls (billing)
|
|
217
|
+
BLINK_APIS_URL → https://core.blink.new
|
|
218
|
+
BLINK_APP_URL → https://blink.new
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Development
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
cd blink-sdk/packages/cli
|
|
227
|
+
npm install
|
|
228
|
+
npm run build # tsup → dist/cli.js
|
|
229
|
+
node dist/cli.js --help # test
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Adding a new command:**
|
|
233
|
+
1. Create `src/commands/my-command.ts` — export `registerMyCommands(program: Command)`
|
|
234
|
+
2. Determine correct backend: resource API → import from `api-resources.ts`, management → from `api-app.ts`
|
|
235
|
+
3. Register in `src/cli.ts`: `import { registerMyCommands } from './commands/my-command.js'` + call it
|
|
236
|
+
4. Rebuild: `npm run build`
|
|
237
|
+
5. Update relevant skill scripts in `openclaw/skills/`
|
|
238
|
+
6. Update this AGENTS.md command reference
|
|
239
|
+
|
|
240
|
+
**Adding a new argument pattern:**
|
|
241
|
+
Commander.js does NOT support `[optional] <required>` — the optional arg swallows the required one.
|
|
242
|
+
Always use `<arg1> [arg2]` and disambiguate in the action handler:
|
|
243
|
+
```typescript
|
|
244
|
+
.action((arg1, arg2) => {
|
|
245
|
+
if (arg2 !== undefined) {
|
|
246
|
+
projectId = requireProjectId(arg1); value = arg2
|
|
247
|
+
} else {
|
|
248
|
+
projectId = requireProjectId(); value = arg1
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Publishing
|
|
256
|
+
|
|
257
|
+
**GitHub Actions**: `.github/workflows/publish-cli.yml` in the `blink-new/blink-sdk` repo.
|
|
258
|
+
|
|
259
|
+
**Trigger**: push to `main` with a change to `packages/cli/package.json` (version bump).
|
|
260
|
+
**Auth**: OIDC Trusted Publisher — no NPM_TOKEN stored. Configured on npmjs.com: org `blinkdotnew`, package `cli`, repo `blink-new/blink-sdk`, workflow `publish-cli.yml`, environment `npm`.
|
|
261
|
+
|
|
262
|
+
**To release a new version:**
|
|
263
|
+
```bash
|
|
264
|
+
cd blink-sdk
|
|
265
|
+
git checkout main && git pull origin main
|
|
266
|
+
# Edit packages/cli/package.json — bump version (e.g. 0.1.0 → 0.1.1)
|
|
267
|
+
npm run build # verify it builds
|
|
268
|
+
git commit -am "chore(cli): bump version to 0.1.1"
|
|
269
|
+
git push origin main
|
|
270
|
+
# → GitHub Actions publishes @blinkdotnew/cli@0.1.1 to npm (~60s)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Version convention:**
|
|
274
|
+
- `0.1.x` — patch: bug fixes, minor arg/output improvements
|
|
275
|
+
- `0.x.0` — minor: new commands, new capabilities
|
|
276
|
+
- `x.0.0` — major: breaking changes to command syntax
|
|
277
|
+
|
|
278
|
+
**Docker image update**: after publishing, update the `RUN npm install -g @blinkdotnew/cli@X.X.X` line in the Blink Claw Dockerfile (in `openclaw/`) and push to main to trigger a Docker rebuild.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## npmjs.com Setup (one-time, already done)
|
|
283
|
+
|
|
284
|
+
OIDC Trusted Publisher must be configured at npmjs.com:
|
|
285
|
+
- Organization: `blinkdotnew`
|
|
286
|
+
- Package: `cli`
|
|
287
|
+
- GitHub repo: `blink-new/blink-sdk`
|
|
288
|
+
- Workflow file: `publish-cli.yml`
|
|
289
|
+
- Environment: `npm`
|
|
290
|
+
|
|
291
|
+
GitHub repo must have environment `npm` created (Settings → Environments → New environment → `npm`).
|