@sbuilder/cli 0.7.0 → 0.9.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.
Files changed (42) hide show
  1. package/README.md +374 -145
  2. package/README.vi.md +361 -137
  3. package/dist/bin/sb.js +535 -219
  4. package/dist/bin/sb.js.map +1 -1
  5. package/dist/src/appblocks.js +67 -0
  6. package/dist/src/appblocks.js.map +1 -0
  7. package/dist/src/appcreate.js +279 -0
  8. package/dist/src/appcreate.js.map +1 -0
  9. package/dist/src/auth.js +1 -1
  10. package/dist/src/code.js +10 -10
  11. package/dist/src/code.js.map +1 -1
  12. package/dist/src/deploy.js +3 -3
  13. package/dist/src/deploy.js.map +1 -1
  14. package/dist/src/dev.js +9 -5
  15. package/dist/src/dev.js.map +1 -1
  16. package/dist/src/export.js +167 -0
  17. package/dist/src/export.js.map +1 -0
  18. package/dist/src/host.js +162 -0
  19. package/dist/src/host.js.map +1 -0
  20. package/dist/src/init.js +41 -13
  21. package/dist/src/init.js.map +1 -1
  22. package/dist/src/login.js +62 -8
  23. package/dist/src/login.js.map +1 -1
  24. package/dist/src/new.js +3 -3
  25. package/dist/src/new.js.map +1 -1
  26. package/dist/src/next.js +122 -0
  27. package/dist/src/next.js.map +1 -0
  28. package/dist/src/repo.js +118 -0
  29. package/dist/src/repo.js.map +1 -0
  30. package/dist/src/route.js +66 -0
  31. package/dist/src/route.js.map +1 -0
  32. package/dist/src/scaffold.js +169 -2
  33. package/dist/src/scaffold.js.map +1 -1
  34. package/dist/src/site.js +448 -0
  35. package/dist/src/site.js.map +1 -0
  36. package/dist/src/siteinit.js +326 -0
  37. package/dist/src/siteinit.js.map +1 -0
  38. package/dist/src/source/parse.js +470 -0
  39. package/dist/src/source/parse.js.map +1 -0
  40. package/dist/src/source/print.js +270 -0
  41. package/dist/src/source/print.js.map +1 -0
  42. package/package.json +6 -2
package/README.md CHANGED
@@ -1,29 +1,62 @@
1
1
  # @sbuilder/cli
2
2
 
3
- **`sb`** — scaffold, run and deploy an app for the **Store Builder** platform.
3
+ **`sb`** — the **Store Builder** command line: keep a site's pages in a GitHub repo, run the
4
+ editor's AI assistant on your own machine, and build apps for the platform.
4
5
 
5
6
  > 🇻🇳 Bản tiếng Việt: [**README.vi.md**](./README.vi.md)
6
7
 
7
8
  ```
8
- sb init [name] [--port 3000] scaffold an app that runs, registers, and opens
9
- inside a merchant's admin
10
- sb login sign in through the browser; stores a credential
11
- that renews itself
12
- sb logout sign this machine out and forget that credential
13
- sb dev upload an island's code to your DRAFT version
14
- every time you save it. Reads sb.json; needs
15
- sb login (or SB_TOKEN).
16
- sb deploy [--submit] push the version's payload in dependency order.
17
- --submit then sends it for review.
18
- sb new "<what to build>" make a site from one sentence: opens the editor
19
- and the assistant starts building
20
- sb agent [--codex] run the editor's AI assistant on THIS machine's
21
- Claude Code login — no API key (--codex: Codex too)
22
- sb code pull [--site <id>] [--dir <path>] [--force]
23
- mirror a site's Code Dock files into ./code
24
- sb code push [--site <id>] [--dir <path>] [--force] [--dry-run] [--delete]
25
- send local edits back; refuses a file changed
26
- in the Code Dock since your pull unless --force
9
+ Start
10
+ sb init ask what to start: a new website built by AI, a
11
+ repo for one of your sites, or an app (same as
12
+ npm create sbuilder-app)
13
+
14
+ Account
15
+ sb login sign in through the browser; stores a credential
16
+ that renews itself
17
+ sb logout sign this machine out and forget that credential
18
+ sb whoami which account (and platform) the CLI acts as
19
+
20
+ Sites
21
+ sb site new "<description>" [--dir <path>] [--github] [--editor]
22
+ make a site from one sentence, in a repo an AI
23
+ agent builds in (--editor: in the editor instead)
24
+ sb site init [dir] [--site <id>] [--github]
25
+ a repo holding one site's pages, synced with
26
+ GitHub both ways
27
+ sb site pull | push [--force] [--dry-run]
28
+ editor edits into design/pages, or your edits
29
+ back as DRAFTS
30
+ sb site publish <file>… | --all
31
+ make pages LIVE — named files, or every page
32
+ sb site blocks the blocks your installed apps offer, with the line
33
+ to paste into a page file
34
+ sb site next serve the pages from a Next.js app, rendered by the
35
+ platform's own renderer
36
+ sb site code pull [--site <id>] [--dir <path>] [--force]
37
+ mirror a site's Code Dock files into ./code
38
+ sb site code push [--site <id>] [--dir <path>] [--force] [--dry-run] [--delete]
39
+ send local edits back; refuses a file changed
40
+ in the Code Dock since your pull unless --force
41
+ sb site mcp the Store Builder MCP server, with this repo's key
42
+
43
+ Apps (for developers building on the platform)
44
+ sb app init [name] [--port 3000] [--with-block]
45
+ scaffold an app that runs, registers, and opens
46
+ inside a merchant's admin; --with-block adds a block
47
+ and its island
48
+ sb app create "<name>" [--site <id>] [--org <id>]
49
+ create the app, a draft version and a sandbox install
50
+ on one of your stores; writes .env and sb.json
51
+ sb app dev upload an island's code to your DRAFT version
52
+ every time you save it. Reads sb.json; needs
53
+ sb login (or SB_TOKEN).
54
+ sb app deploy [--submit] push the version's payload in dependency order.
55
+ --submit then sends it for review.
56
+
57
+ AI
58
+ sb agent [--codex] run the editor's AI assistant on THIS machine's
59
+ Claude Code login — no API key (--codex: Codex too)
27
60
  ```
28
61
 
29
62
  Node 20 or newer. Written in TypeScript, published compiled — an installed copy
@@ -36,13 +69,14 @@ has no dependencies and nothing to build.
36
69
  - [What this is, and what it is not](#what-this-is-and-what-it-is-not)
37
70
  - [Getting it](#getting-it)
38
71
  - [The five-minute path](#the-five-minute-path)
39
- - [`sb init`](#sb-init--scaffold-an-app-that-runs)
40
- - [`sb.json`](#sbjson--the-file-dev-and-deploy-read)
72
+ - [`sb app init` and `sb app create`](#sb-app-init-and-sb-app-create--an-app-that-runs-and-is-registered)
73
+ - [`sb.json`](#sbjson--the-file-sb-app-dev-and-sb-app-deploy-read)
41
74
  - [`sb login` / `sb logout`](#sb-login--sb-logout--sign-in-through-the-browser)
42
- - [`sb dev`](#sb-dev--save-upload-refresh)
43
- - [`sb deploy`](#sb-deploy--the-whole-payload-in-dependency-order)
44
- - [`sb code`](#sb-code--your-code-dock-files-as-a-folder)
45
- - [`sb new`](#sb-new--a-site-from-one-sentence)
75
+ - [`sb app dev`](#sb-app-dev--save-upload-refresh)
76
+ - [`sb app deploy`](#sb-app-deploy--the-whole-payload-in-dependency-order)
77
+ - [`sb site code`](#sb-site-code--your-code-dock-files-as-a-folder)
78
+ - [`sb site`](#sb-site--a-site-as-a-repo-you-build-with-ai-synced-with-github)
79
+ - [What changed in 0.9](#what-changed-in-09)
46
80
  - [`sb agent`](#sb-agent--the-editor-assistant-on-your-own-login)
47
81
  - [Environment variables](#environment-variables)
48
82
  - [CI](#ci)
@@ -92,7 +126,7 @@ sb --help
92
126
  Node 20 or newer. The package ships compiled, so an installed copy has no
93
127
  dependencies and nothing to build.
94
128
 
95
- The scaffold `sb init` writes is deliberately the same way: no dependencies, no
129
+ The scaffold `sb app init` writes is deliberately the same way: no dependencies, no
96
130
  build, plain ESM — because that is the code you actually run.
97
131
 
98
132
  > Working on the CLI itself, rather than using it? [CONTRIBUTING.md](./CONTRIBUTING.md).
@@ -101,49 +135,48 @@ build, plain ESM — because that is the code you actually run.
101
135
 
102
136
  ## The five-minute path
103
137
 
104
- The whole loop, start to finish. Steps 2 and 3 are yours — see `/app-docs` — and
105
- everything else is one command.
138
+ The whole loop, start to finish. Registering the app (`sb app create`) needs an
139
+ organization you belong to and a store of yours — see `/app-docs`.
106
140
 
107
141
  ```bash
108
- # 1. A working app on your machine
109
- sb init my-app --port 4000
142
+ # 1. A working app on your machine, with a block merchants can drag onto a page
143
+ sb app init my-app --port 4000 --with-block
110
144
  cd my-app
111
- cp .env.example .env # fill in SB_CLIENT_ID and SB_CLIENT_SECRET
112
- npm start
113
- ```
114
-
115
- 2. **Create the app** in your organization, and note the `clientId` /
116
- `clientSecret` it returns. The secret is shown **once**.
117
- 3. **Create a DRAFT version** pointing at your local URLs — embed URL
118
- `http://localhost:4000/embed`, redirect URI
119
- `http://localhost:4000/oauth/callback`. **No tunnel is needed:** a draft
120
- version may point at `http://localhost` and a sandbox install may frame it,
121
- so the entire development loop runs on your own machine. A tunnel is only for
122
- checking the public URLs before you submit.
123
145
 
124
- ```bash
125
- # 4. Sign in once (prints a code you type in the browser)
146
+ # 2. Sign in once (prints a code you type in the browser)
126
147
  sb login
127
148
 
128
- # 5. Write sb.json with the ids you now have (see below), then:
129
- sb dev # edit an island, save, refresh
149
+ # 3. Create the app, a draft version pointing at localhost, and a sandbox install
150
+ # on one of your stores. Writes .env (the client secret, once) and sb.json.
151
+ sb app create "My app"
152
+ npm start # the app, on http://localhost:4000
153
+
154
+ # 4. Send the block and its island to the draft, then edit the island:
155
+ sb app deploy
156
+ sb app dev # edit an island, save, refresh
130
157
 
131
- # 6. Push the whole payload, and send it for review
132
- sb deploy --submit
158
+ # 5. When it is ready: public https URLs on the version, then
159
+ sb app deploy --submit
133
160
  ```
134
161
 
162
+ **No tunnel is needed:** a draft version may point at `http://localhost` and a
163
+ sandbox install may frame it, so the entire development loop runs on your own
164
+ machine. A tunnel is only for checking the public URLs before you submit.
165
+
135
166
  ---
136
167
 
137
- ## `sb init` — scaffold an app that runs
168
+ ## `sb app init` and `sb app create` — an app that runs, and is registered
138
169
 
139
170
  ```bash
140
- sb init my-app
141
- sb init my-app --port 4000
171
+ sb app init my-app
172
+ sb app init my-app --port 4000
173
+ sb app init my-app --with-block
142
174
  ```
143
175
 
144
176
  Writes a working app into `./my-app` and prints what to do next. It makes **no
145
- network calls at all** — it is a scaffolder, not a registration step. Creating
146
- the app and creating a version are still yours to do.
177
+ network calls at all** — it is a scaffolder; `sb app create` (below) registers
178
+ it. A bare `sb init` on a terminal asks what to start instead; its choice 3 runs
179
+ this flow.
147
180
 
148
181
  ### What it writes
149
182
 
@@ -157,9 +190,22 @@ Five files, and nothing else:
157
190
  | `README.md` | The same next steps the command prints, for when the terminal has scrolled |
158
191
  | `.gitignore` | `node_modules` and `.env` |
159
192
 
160
- There are deliberately **no blocks, no islands and no app data**. Each is a real
161
- feature with its own guide, and none is needed to watch an app appear inside a
162
- merchant's admin for the first time.
193
+ Without `--with-block` there are deliberately **no blocks, no islands and no app
194
+ data**. Each is a real feature with its own guide, and none is needed to watch an
195
+ app appear inside a merchant's admin for the first time.
196
+
197
+ ### `--with-block` — a block a merchant can drag onto a page
198
+
199
+ Three more files:
200
+
201
+ | File | What it is |
202
+ | --- | --- |
203
+ | `blocks.json` | One block, "Hello card": a `flex-block` with a `heading` and a `button`, and a trait to edit the heading. It is exactly the body of `PUT .../blocks` (see `/block-docs`) |
204
+ | `islands/hello-card.js` | The island the block names: it counts clicks on the button. A plain class the page's loader constructs; it registers under `app.<appId>.hello-card` by reading that name off the page, so no id is pasted into it |
205
+ | `sb.json` | What `sb app dev` and `sb app deploy` read, with the three ids **empty** until `sb app create` fills them |
206
+
207
+ The repository's tests run `blocks.json` through the platform's own block
208
+ validator, so what the flag writes is what the server accepts.
163
209
 
164
210
  ### The name
165
211
 
@@ -169,9 +215,9 @@ lower-cased, any run of characters outside `a-z 0-9 . _ -` collapsed to a single
169
215
 
170
216
  | You type | You get |
171
217
  | --- | --- |
172
- | `sb init my-app` | `./my-app` |
173
- | `sb init "My App!"` | `./my-app` |
174
- | `sb init` | `./my-app` |
218
+ | `sb app init my-app` | `./my-app` |
219
+ | `sb app init "My App!"` | `./my-app` |
220
+ | `sb app init` | `./my-app` |
175
221
 
176
222
  ### What it refuses
177
223
 
@@ -186,24 +232,73 @@ Pick an empty directory, or move those files aside.
186
232
 
187
233
  A partial scaffold is worse than none, because it leaves a directory that looks
188
234
  initialised and is not. An *existing* directory is otherwise fine — running
189
- `sb init` inside a fresh `git clone` is normal, and refusing it because `.git`
235
+ `sb app init` inside a fresh `git clone` is normal, and refusing it because `.git`
190
236
  exists would refuse the common case.
191
237
 
192
238
  ### Flags
193
239
 
194
240
  | Flag | Default | Effect |
195
241
  | --- | --- | --- |
196
- | `--port <n>` | `3000` | The port baked into `.env.example`, the generated README and every URL the command prints. A value that is not a positive number is refused with `--port must be a number` |
242
+ | `--port <n>` | `3000` | The port baked into `.env.example`, the generated README, every URL the command prints and (with `--with-block`) the draft URLs in `sb.json`. A value that is not a positive number is refused with `--port must be a number` |
243
+ | `--with-block` | off | Also write `blocks.json`, `islands/hello-card.js` and `sb.json` |
244
+
245
+ ### `sb app create "<name>"` — the app, a draft, and a sandbox install
246
+
247
+ ```bash
248
+ sb login
249
+ sb app create "My app"
250
+ sb app create "My app" --site <site-id> --org <org-id>
251
+ ```
252
+
253
+ Run it inside the app folder. With your `sb login` session it:
254
+
255
+ 1. creates the **app** in your organization — the response carries the OAuth client
256
+ secret **once**;
257
+ 2. writes `.env` with `SB_CLIENT_ID` and `SB_CLIENT_SECRET` (mode `0600`, added to
258
+ `.gitignore` when missing) — everything that could refuse that write (a missing
259
+ folder, a symbolic link) is checked **before** the app is created, because nothing
260
+ can recover the secret afterwards;
261
+ 3. creates a **draft version** pointing at `http://localhost:<port>/embed` with
262
+ redirect URI `/oauth/callback` (the addresses already in `sb.json` when it names
263
+ some; scope `products.read`);
264
+ 4. **installs** that draft on one of your stores — the consent a merchant gives; for a
265
+ member of the publishing organization it records a *sandbox* install. The
266
+ authorization code it returns lasts 60 seconds and is not redeemed, so **the app has
267
+ no access token yet**: with `npm start` running, approve the install again ("Install
268
+ on my store" in the developer portal) and the app receives its token at
269
+ `/oauth/callback`; the embedded screen works without one;
270
+ 5. fills `sb.json` (`orgId`, `appId`, `versionId`, `siteId`, `version`), keeping every
271
+ other key, and prints where the app opens: the store's **Apps** screen in the admin
272
+ and the app's page in the developer portal.
273
+
274
+ **The client secret goes to `.env` and nowhere else** — never to the terminal.
275
+ Which organization and store: `--org` and `--site` name them; with neither, the only
276
+ one is taken, and several are asked about on a terminal (anywhere else it refuses,
277
+ listing them, and creates nothing).
278
+
279
+ **It stops where it must, and says where.** A step the server refuses leaves the app
280
+ and the secret in place and names what exists; run it again and it continues from the
281
+ app. If `sb.json` already names an app and a version it creates nothing. The install
282
+ needs a **user session** (`sb login`, or a user token in `SB_TOKEN`) — an API key or a
283
+ deploy key cannot give consent.
284
+
285
+ | Flag | Effect |
286
+ | --- | --- |
287
+ | `--site <id>` | The store to install the draft on (its id or slug) |
288
+ | `--org <id>` | The organization that publishes the app |
289
+ | `--yes` | Accept scopes or addresses in `sb.json` beyond the scaffold's own (loopback URLs, `products.read`). Without it, a terminal is asked and anything else refuses — before creating anything. What will be installed is printed first either way |
290
+ | `--port <n>` | The port the draft's URLs name when `sb.json` has none; `3000` by default |
197
291
 
198
292
  ---
199
293
 
200
- ## `sb.json` — the file `dev` and `deploy` read
294
+ ## `sb.json` — the file `sb app dev` and `sb app deploy` read
201
295
 
202
- Both `sb dev` and `sb deploy` read an `sb.json` from the **current directory**.
296
+ Both `sb app dev` and `sb app deploy` read an `sb.json` from the **current directory**.
203
297
 
204
- **`sb init` does not write it, and it cannot**: three of its five required fields
205
- are ids the platform mints when you create the app and its draft version, which
206
- has not happened yet at `init` time. Write it by hand once you have them:
298
+ **`sb app create` writes it** — three of its five required fields are ids the
299
+ platform mints when the app and its draft version are created, and `sb app init
300
+ --with-block` ships it with those three empty. Without `sb app create`, write it by
301
+ hand once you have the ids:
207
302
 
208
303
  ```json
209
304
  {
@@ -222,26 +317,26 @@ has not happened yet at `init` time. Write it by hand once you have them:
222
317
  | `orgId` | The organization that owns the app |
223
318
  | `appId` | The app |
224
319
  | `versionId` | The **draft** version being edited |
225
- | `island` | The island `sb dev` uploads to |
226
- | `entry` | The file `sb dev` watches, relative to `sb.json` |
320
+ | `island` | The island `sb app dev` uploads to |
321
+ | `entry` | The file `sb app dev` watches, relative to `sb.json` |
227
322
 
228
323
  A missing key is refused by name — `sb.json is missing "versionId".` — and a
229
- missing file is refused with the list of what it needs. `sb deploy` requires all
324
+ missing file is refused with the list of what it needs. `sb app deploy` requires all
230
325
  five even though its own work is described by the optional keys below, so fill
231
326
  them in even if you are only deploying blocks.
232
327
 
233
328
  ### Optional — each one found becomes a deploy step
234
329
 
235
- | Key | Type | What `sb deploy` does with it |
330
+ | Key | Type | What `sb app deploy` does with it |
236
331
  | --- | --- | --- |
237
332
  | `version` | object | `PUT` as the version's fields — `scopes`, `embedUrl`, `redirectUri` and the rest |
238
333
  | `blocks` | path | The block manifest, `PUT` as the body of `.../blocks` |
239
334
  | `islands` | array of `{name, entry}` | Declares every `name`, then uploads every `entry` |
240
335
 
241
- An `sb.json` with only the five required keys is valid: `sb dev` works, and
242
- `sb deploy` finds no steps to run.
336
+ An `sb.json` with only the five required keys is valid: `sb app dev` works, and
337
+ `sb app deploy` finds no steps to run.
243
338
 
244
- `sb code` reads one more optional key from the same file, `siteId`, and nothing
339
+ `sb site code` reads one more optional key from the same file, `siteId`, and nothing
245
340
  else: it does not need the five required keys.
246
341
 
247
342
  A fuller one:
@@ -272,6 +367,7 @@ A fuller one:
272
367
 
273
368
  ```bash
274
369
  sb login
370
+ sb whoami
275
371
  sb logout
276
372
  ```
277
373
 
@@ -297,8 +393,8 @@ local and a production sign-in coexist), in
297
393
  only (mode `0600`). `sb login` is a separate signed-in device on your account,
298
394
  listed with your other sessions; signing out everywhere ends it too.
299
395
 
300
- **It renews itself.** When the server refuses the access token, `sb dev`,
301
- `sb deploy` and `sb code` rotate the pair once, save it, and retry the request. Two `sb`
396
+ **It renews itself.** When the server refuses the access token, `sb app dev`,
397
+ `sb app deploy` and `sb site code` rotate the pair once, save it, and retry the request. Two `sb`
302
398
  processes renewing at the same moment take turns through a lock file beside
303
399
  the credentials, and the second one adopts the pair the first one saved — a
304
400
  refresh token presented twice would end the session. If the renewal itself is
@@ -307,15 +403,24 @@ refused, the entry is deleted and the CLI says to run `sb login` again.
307
403
  `sb logout` revokes this device's session on the server and deletes its entry
308
404
  from the file. Your other devices stay signed in.
309
405
 
406
+ **On a terminal it opens the page for you** — the `/device` page only, never the
407
+ code, which you still type. It stays closed in CI, when the output is not a
408
+ terminal, or with `SB_NO_BROWSER=1`; the address is printed either way. Once
409
+ approved, it says which account it signed in as.
410
+
411
+ `sb whoami` prints that account and the platform address (`me@shop.vn on
412
+ https://api.sbuilder.io.vn`), or that `SB_TOKEN` holds an API key or a deploy
413
+ key, or `Not signed in` (exit 1).
414
+
310
415
  `SB_TOKEN`, when set, **takes precedence** over the stored credential — see
311
416
  [Environment variables](#environment-variables).
312
417
 
313
418
  ---
314
419
 
315
- ## `sb dev` — save, upload, refresh
420
+ ## `sb app dev` — save, upload, refresh
316
421
 
317
422
  ```bash
318
- SB_TOKEN=<your token> sb dev
423
+ SB_TOKEN=<your token> sb app dev
319
424
  ```
320
425
 
321
426
  Watches the `entry` file from `sb.json` and uploads it to the version's `island`
@@ -338,16 +443,16 @@ command removes is the friction of finding the endpoint: you save, it uploads,
338
443
  approval pins a payload, and an island swapped after review is code running on
339
444
  merchants' pages that nobody looked at.
340
445
 
341
- `sb dev` takes no flags. It uploads **one** island — the one named in `sb.json`.
342
- To push several at once, use `sb deploy` with an `islands` array.
446
+ `sb app dev` takes no flags. It uploads **one** island — the one named in `sb.json`.
447
+ To push several at once, use `sb app deploy` with an `islands` array.
343
448
 
344
449
  ---
345
450
 
346
- ## `sb deploy` — the whole payload, in dependency order
451
+ ## `sb app deploy` — the whole payload, in dependency order
347
452
 
348
453
  ```bash
349
- SB_TOKEN=<your token> sb deploy
350
- SB_TOKEN=<your token> sb deploy --submit
454
+ SB_TOKEN=<your token> sb app deploy
455
+ SB_TOKEN=<your token> sb app deploy --submit
351
456
  ```
352
457
 
353
458
  Runs every step your `sb.json` describes, in this order:
@@ -380,14 +485,14 @@ What the command owes you instead is to say where it stopped:
380
485
  Stopped at: island "countdown"
381
486
 
382
487
  This version is in review or already approved, so its code is frozen.
383
- Create a new draft version and point sb dev at that one.
488
+ Create a new draft version and point sb app dev at that one.
384
489
  (server: version has left draft)
385
490
 
386
491
  Already applied: version fields, blocks, island declarations
387
492
 
388
493
  This left the version UNFINISHED, not broken — a draft is allowed to be
389
494
  partway through, and it simply cannot be submitted until the rest lands.
390
- Fix the cause and run sb deploy again; every step is safe to repeat.
495
+ Fix the cause and run sb app deploy again; every step is safe to repeat.
391
496
  ```
392
497
 
393
498
  Every write is idempotent, so resuming is simply running it again.
@@ -413,12 +518,12 @@ earlier, with more room to explain than a status code has.
413
518
 
414
519
  ---
415
520
 
416
- ## `sb code` — your Code Dock files as a folder
521
+ ## `sb site code` — your Code Dock files as a folder
417
522
 
418
523
  ```bash
419
- sb code pull --site <site-id>
524
+ sb site code pull --site <site-id>
420
525
  # edit code/site/css/main.css in your own editor, then
421
- sb code push
526
+ sb site code push
422
527
  ```
423
528
 
424
529
  Mirrors a site's **Code Dock** files — the site-wide and per-page CSS, JavaScript
@@ -442,7 +547,7 @@ keeps its local path, because it is tracked by its id, and its content still syn
442
547
  A Code Dock file with no name pulls as `unnamed-<id>.<ext>` and is
443
548
  tracked by its id.
444
549
 
445
- Symbolic links never lead `sb code` outside the root: a file that is a link, or whose
550
+ Symbolic links never lead `sb site code` outside the root: a file that is a link, or whose
446
551
  folder leads outside the root through one, is named and skipped — pull writes nothing
447
552
  through it, push sends nothing from it — while the other files still sync and the run
448
553
  exits `1`. Two links are refused before anything is sent: a `.sb-code.json` that is a
@@ -451,19 +556,19 @@ to sync through it deliberately.
451
556
 
452
557
  `.sb-code.json` records, per file, the server's id and metadata, its `updatedAt`
453
558
  and a sha256 of the content **as last pulled or pushed**. That is the base both
454
- directions compare against, which is how `sb code` tells your edit from an edit
559
+ directions compare against, which is how `sb site code` tells your edit from an edit
455
560
  made in the Code Dock. **Commit it**: a CI push then judges conflicts against the
456
561
  last pull you committed.
457
562
 
458
563
  ### Pull
459
564
 
460
- `sb code pull` writes every file the server has. It **never overwrites a local
565
+ `sb site code pull` writes every file the server has. It **never overwrites a local
461
566
  edit**:
462
567
 
463
568
  - Your file changed and the server's did not: it is left alone and printed as
464
- `pending` — `sb code push` sends it. Exit `0`.
569
+ `pending` — `sb site code push` sends it. Exit `0`.
465
570
  - Both changed: the file is kept, named, and the run exits `1`.
466
- - `sb code pull --force` overwrites every local edit with the server's version,
571
+ - `sb site code pull --force` overwrites every local edit with the server's version,
467
572
  in both cases.
468
573
  - A file deleted on the server is removed locally only if you never edited it.
469
574
 
@@ -471,7 +576,7 @@ It ends with a summary line: written, pending, kept, removed.
471
576
 
472
577
  ### Push
473
578
 
474
- `sb code push` builds a plan against the manifest:
579
+ `sb site code push` builds a plan against the manifest:
475
580
 
476
581
  | Plan | When | Needs |
477
582
  | --- | --- | --- |
@@ -482,7 +587,7 @@ It ends with a summary line: written, pending, kept, removed.
482
587
  Creates run first, then updates, then deletes. Each update and delete carries the
483
588
  `updatedAt` from your last pull, and **the server compares it inside the write**:
484
589
  a file changed in the Code Dock since then answers `409 code_file_changed`, that
485
- one file is refused ("changed in the Code Dock since your pull; run sb code pull,
590
+ one file is refused ("changed in the Code Dock since your pull; run sb site code pull,
486
591
  or push --force"), the rest of the run continues, and the exit code is `1`.
487
592
 
488
593
  **The manifest is written after every operation**, so a run that stops halfway —
@@ -547,14 +652,14 @@ A `wbk_` key whose manifest shares **no** file with the server's list is refused
547
652
  as belonging to a different site, so a CI key cannot write site A's files onto
548
653
  site B. `--force` overrides it.
549
654
 
550
- ### CI for `sb code`
655
+ ### CI for `sb site code`
551
656
 
552
657
  Create an API key in the merchant's **Settings → API keys** with `codefiles.write`
553
658
  (add `pages.read` if CI creates files in a page folder the manifest does not
554
659
  know yet), and store it as the CI secret `SB_TOKEN`:
555
660
 
556
661
  ```bash
557
- SB_TOKEN="$SB_API_KEY" sb code push
662
+ SB_TOKEN="$SB_API_KEY" sb site code push
558
663
  ```
559
664
 
560
665
  A key without `codefiles.write` is refused by the server and nothing is written.
@@ -571,27 +676,147 @@ file missing locally without `--delete`, is printed and is **not** a failure.
571
676
 
572
677
  ---
573
678
 
574
- ## `sb new` — a site from one sentence
575
-
576
- ```
577
- sb new "a shop selling handmade candles"
578
- ```
679
+ ## `sb site` — a site as a repo you build with AI, synced with GitHub
680
+
681
+ ```
682
+ sb init # a menu: "a new website, built by AI" is choice 1
683
+ sb site new "a shop selling handmade candles" # the same, from the command line
684
+ sb site init my-shop --github # a repo for one of your sites, on a private GitHub repo
685
+ sb site pull # take what was edited in the editor
686
+ sb site push # save edited page files as DRAFTS
687
+ sb site publish --all # make pages live (or name files)
688
+ sb site next # serve the pages from a Next.js app (npm run dev)
689
+ sb site mcp # the Store Builder MCP server, with this repo's key
690
+ ```
691
+
692
+ **`sb site new "<description>"`** creates a site (named from the first words of your
693
+ description), writes the repo below into `./<name>` (`--dir` picks another folder,
694
+ `--github` also makes the private GitHub repo) and — when Claude Code is installed —
695
+ offers to start it in that folder with your description. Signed out, it runs the
696
+ `sb login` flow first. It is exactly what choice 1 of `sb init` does.
697
+
698
+ **`sb site new --editor "<description>"`** builds in the editor instead: it opens the
699
+ editor, which creates the site and starts building it. If `sb agent` is already
700
+ running it does the work; if not and Claude Code is installed, the command serves as
701
+ the agent itself and stays open until you press Ctrl-C. With neither, or with the
702
+ bridge switched off, the platform's assistant builds it on your plan's allowance.
703
+ The link opens only for the account that asked and lasts 15 minutes; opening it a
704
+ second time inside those 15 minutes makes a second site. While your `sb agent` is
705
+ running, every new site you start from here, the home page or the dashboard picks
706
+ "Claude Code (sb agent)"; that stays the site's setting: with no `sb agent` running
707
+ the assistant on that site stops and says so, rather than falling back to the
708
+ platform's key.
579
709
 
580
- Opens the editor, which creates the site and starts building it. Signed out, it
581
- runs the `sb login` flow first. If `sb agent` is already running it does the work;
582
- if not and Claude Code is installed, `sb new` serves as the agent itself and stays
583
- open until you press Ctrl-C. With neither, or with the bridge switched off, the
584
- platform's assistant builds it on your plan's allowance.
585
-
586
- The link opens only for the account that asked and lasts 15 minutes. Opening it a
587
- second time inside those 15 minutes makes a second site.
710
+ | Flag | Effect |
711
+ | --- | --- |
712
+ | `--editor` | Build in the editor (the assistant, or your `sb agent`) instead of in a repo |
713
+
714
+ **Building with AI.** Choice 1 of `sb init` (and `sb site new`) takes your description, creates
715
+ the site, writes the repo below and — when Claude Code is installed — starts it in
716
+ that folder with your description, so building starts right there. Any agent works:
717
+ the repo carries `.mcp.json`, `.cursor/mcp.json` and `.vscode/mcp.json`, so Claude
718
+ Code, Cursor and VS Code see the Store Builder tools as soon as the folder is opened
719
+ (approve the `sbuilder` server once), and `AGENTS.md` (imported by `CLAUDE.md`) tells
720
+ the agent how to work: native elements first, look at every section on desktop and
721
+ mobile, ask for real facts, pull the result into the repo, **never publish unasked**.
722
+ The agent edits the site's drafts; you review what it did as a git diff.
723
+
724
+ **What `sb site init` writes.** It signs you in if needed, lets you pick a site (or
725
+ takes `--site <id>`), and writes:
726
+
727
+ | Path | What it is |
728
+ | --- | --- |
729
+ | `design/pages/*.page.tsx` | One page's draft as source (see *Page files* below) |
730
+ | `code/` | The site's Code Dock files (`sb site code pull --dir code`) |
731
+ | `.sb-site.json` | What was last synced — commit it |
732
+ | `.env` | An API key minted for this repo, mode `0600`, git-ignored |
733
+ | `.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json` | The MCP server, started as `sb site mcp` |
734
+ | `AGENTS.md`, `CLAUDE.md` | How an AI agent works in this repo |
735
+ | `.github/workflows/sbuilder.yml` | The GitHub half of the sync |
736
+
737
+ The key is named `AI agent · <folder>` and carries every content permission your
738
+ account may delegate — never members, roles, site settings or export. Revoke it in
739
+ Settings -> API keys. If it cannot be minted, init says so and carries on. Inside the
740
+ repo, `sb site`, `sb site code` and `sb site mcp` read `.env`; a variable already set in your
741
+ shell wins. `--github` then runs `git init`, the first commit, `gh repo create
742
+ --private --push` and `gh secret set SB_TOKEN` (the key goes in on stdin, never on a
743
+ command line) — the workflow is live with nothing left to paste.
744
+
745
+ **Page files.** Each page is a `.page.tsx` file that reads like React — one tag per element,
746
+ its settings as props:
747
+
748
+ ```tsx
749
+ export default (
750
+ <Page id="ROOT">
751
+ <FlexSection id="fs_a5608576" style={{ padding: "40px 24px" }} mobile={{ style: { padding: "24px 16px" } }}>
752
+ <Heading id="he_91c2" level={1} text="Trà Thái Nguyên" />
753
+ <Button text="Mua ngay" />
754
+ </FlexSection>
755
+ </Page>
756
+ );
757
+ ```
758
+
759
+ Edit text and settings, move or add elements (a new one needs no `id` — it gets one on push),
760
+ then `sb site push`. Keep the existing `id`s: they are how an edit made in the editor and one made
761
+ here are told apart. A page file holds **data, not code** — no logic, no variables, no text
762
+ between tags (`text="…"` instead); anything else is refused with `file:line:col` and nothing is
763
+ sent. The format is exact both ways: every page the platform has stored prints to source and
764
+ reads back identical, so pulling and pushing cannot damage a page. Elements kept outside the
765
+ page tree (a list's empty state, quantity buttons) are under `export const detached`.
766
+
767
+ **Installed apps.** An app's block arrives in the page file as its full subtree, its root
768
+ carrying `appBlockId`. It belongs to the app: the platform discards edits inside it, so
769
+ `sb site push` refuses them before sending, naming the block — change only its
770
+ `appBlockValues`, move it, or remove it whole. `sb site blocks` lists the blocks your
771
+ installed apps offer, each with the line to paste (`<FlexBlock appBlockRef="ins_…/badge" />`)
772
+ and the settings it takes. Their app data and island scripts render on the Next.js host
773
+ too. Every warning the platform returns on a save is printed, never swallowed.
774
+
775
+ **Run it as a Next.js app.** `sb site next` adds a Next.js host to the repo: `npm install`,
776
+ then `npm run dev`, and `http://localhost:3000` serves every page file **rendered by the
777
+ platform's own renderer** — the Go code compiled to WebAssembly (`@sbuilder/render`), so a page
778
+ looks here byte for byte as it does on the store, never "close". Save a `.page.tsx`, refresh,
779
+ see it — before anything is pushed. The data a page shows (products, articles, theme, settings)
780
+ comes from `POST /api/v1/pages/{id}/render-context` with the repo's key; `/_wb/*` (cart,
781
+ checkout, forms, the islands runtime) and any path with no page file go to the live store
782
+ (`SB_STOREFRONT` in `.env`). A route you add under `app/` wins over the page catch-all, so
783
+ hand-written React pages live beside the builder's. Deploy it anywhere Next.js runs.
784
+
785
+ **The workflow is the whole GitHub integration** — no GitHub App, no webhook. A push to
786
+ `main` touching `design/` or `code/` saves drafts; every 30 minutes (and on demand) it
787
+ pulls what changed in the editor and commits it. Running it by hand with *publish*
788
+ ticked makes every page live.
789
+
790
+ **Nothing is overwritten silently.** `.sb-site.json` records each page's server `rev`
791
+ and the file's hash as last synced. A pull overwrites a file only if you have not
792
+ edited it; a push sends `baseRev` and the server refuses a page edited in the editor
793
+ since. A page edited on both sides is named and skipped (exit 1); `--force` picks a
794
+ side — the editor's on pull, yours on push.
795
+
796
+ **Push saves drafts; `sb site publish` is the only thing here that goes live**, and it
797
+ publishes only the files you name or, with `--all`, every page. Pages are not created
798
+ or deleted from files: create one in the editor (or let the agent), then pull; a page
799
+ deleted on the platform keeps its file and is named. With an API key it uses
800
+ `/api/v1/pages/{id}/document` and needs no `--site`.
801
+
802
+ ## What changed in 0.9
803
+
804
+ The commands moved into groups. **The old names still work in 0.9** and print one
805
+ line on stderr naming the new form (stdout is untouched — `sb mcp` speaks the MCP
806
+ protocol over it, and repos made by 0.8 still start it):
807
+
808
+ | 0.8 | 0.9 |
809
+ | --- | --- |
810
+ | `sb dev` | `sb app dev` |
811
+ | `sb deploy` | `sb app deploy` |
812
+ | `sb code …` | `sb site code …` |
813
+ | `sb new "…"` | `sb site new --editor "…"` |
814
+ | `sb mcp` | `sb site mcp` |
815
+ | `sb init <name>` | `sb app init <name>` |
588
816
 
589
- While your `sb agent` is running, every new site you start from `sb new`, the home
590
- page or the dashboard picks "Claude Code (sb agent)", so its first build uses your
591
- Claude Code login. That stays the site's setting: with no `sb agent` running the
592
- assistant on that site stops and says so, rather than falling back to the
593
- platform's key. Keep it running (`sb agent install`) or change the provider in the
594
- assistant's settings.
817
+ `sb export next` was **removed**: `sb site next` makes a Next.js app rendered by the
818
+ platform's own renderer, which a snapshot of published HTML never was. `sb export …`
819
+ now exits `1` and says so.
595
820
 
596
821
  ## `sb agent` — the editor assistant on your own login
597
822
 
@@ -609,7 +834,7 @@ Ctrl-C stops it, and it reconnects on its own if the network drops.
609
834
  - macOS and Linux. Windows is not supported yet (npm's `.cmd` shims cannot be
610
835
  started without a shell, and a shell would re-parse the prompt).
611
836
  - Install and log in to the CLI first (`claude`, or `codex login`).
612
- - The platform admin must switch the option on (Admin → Settings); until then
837
+ - The platform admin must switch the option on (Admin → AI assistant); until then
613
838
  `sb agent` stops and says so.
614
839
  - Claude Code runs with every built-in tool off. **Codex jobs are refused unless
615
840
  you start `sb agent --codex`**: Codex can read files on this machine through
@@ -653,11 +878,11 @@ A user access token expires, so it is the wrong credential for a pipeline. Use a
653
878
  1. In the Developer portal, open your organization and go to **Deploy keys**
654
879
  (an owner or admin can do this), then create one. The secret starts with
655
880
  `sbdk_` and is shown **once**.
656
- 2. Store it as the CI secret `SB_TOKEN`. `sb dev` and `sb deploy` accept it
657
- exactly like a pasted token. (`sb code` does not: see its own CI recipe.)
881
+ 2. Store it as the CI secret `SB_TOKEN`. `sb app dev` and `sb app deploy` accept it
882
+ exactly like a pasted token. (`sb site code` does not: see its own CI recipe.)
658
883
 
659
884
  ```bash
660
- SB_TOKEN="$SB_DEPLOY_KEY" sb deploy
885
+ SB_TOKEN="$SB_DEPLOY_KEY" sb app deploy
661
886
  ```
662
887
 
663
888
  A deploy key does not expire and belongs to the organization, not to the person
@@ -673,29 +898,31 @@ refused.
673
898
 
674
899
  ## Environment variables
675
900
 
676
- Two are read by the CLI itself:
901
+ Three are read by the CLI itself:
677
902
 
678
903
  | Variable | Required by | Default |
679
904
  | --- | --- | --- |
680
- | `SB_TOKEN` | `sb dev`, `sb deploy`, `sb code` — optional | none — the `sb login` credential is used; with neither, each stops and names `sb login` |
681
- | `SB_API` | every command but `sb init` | `https://api.sbuilder.io.vn` — set `http://localhost:8080` for a local platform |
905
+ | `SB_TOKEN` | `sb app dev`, `sb app deploy`, `sb app create`, `sb site code` — optional | none — the `sb login` credential is used; with neither, each stops and names `sb login` |
906
+ | `SB_API` | every command but `sb app init` | `https://api.sbuilder.io.vn` — set `http://localhost:8080` for a local platform |
907
+ | `SB_NO_BROWSER` | `sb login` | unset — set it to stop `sb login` opening the `/device` page (CI and non-terminals never open it) |
908
+ | `SB_STOREFRONT` | the `sb site next` app | the live store's address (`sb site init` writes it into `.env`) — where `/_wb/*` and paths with no page file are forwarded |
682
909
 
683
- `SB_TOKEN` **overrides** the stored `sb login` credential when set. For `sb dev`
684
- and `sb deploy` it is a token for the **organization that owns the app** — the
910
+ `SB_TOKEN` **overrides** the stored `sb login` credential when set. For `sb app dev`
911
+ and `sb app deploy` it is a token for the **organization that owns the app** — the
685
912
  same user access token you would put in an `Authorization: Bearer` header against
686
913
  the org-scoped routes. It is **not** a `wba_` app token; those belong to an
687
- install, and an install cannot edit the app it is an install of. For `sb code` it
914
+ install, and an install cannot edit the app it is an install of. For `sb site code` it
688
915
  is a user token with access to the site, or a merchant `wbk_` API key (see
689
- [`sb code`](#sb-code--your-code-dock-files-as-a-folder)).
916
+ [`sb site code`](#sb-site-code--your-code-dock-files-as-a-folder)).
690
917
 
691
918
  A pasted token cannot renew itself, and the CLI never tries to refresh it. When
692
- the server refuses a pasted token, `sb dev` and `sb deploy` say
919
+ the server refuses a pasted token, `sb app dev` and `sb app deploy` say
693
920
  `SB_TOKEN was refused: it has expired or been revoked` and point you at
694
- `sb login`. `sb code` says
921
+ `sb login`. `sb site code` says
695
922
  ``Not signed in, or the token was refused (expired or revoked). Run `sb login`, or set SB_TOKEN to an API key (wbk_…) with codefiles.read / codefiles.write from Settings -> API keys.``
696
- instead, and never suggests a deploy key, because `sb code` refuses one.
923
+ instead, and never suggests a deploy key, because `sb site code` refuses one.
697
924
 
698
- Three more are read by the app `sb init` writes, from its own `.env`:
925
+ Three more are read by the app `sb app init` writes, from its own `.env`:
699
926
 
700
927
  | Variable | Read by | What it is |
701
928
  | --- | --- | --- |
@@ -713,9 +940,9 @@ Every command exits `0` on success and `1` on a refusal it can explain. Anything
713
940
  else is a bug in the tool and gets a stack trace, because a scaffolder that
714
941
  swallows its own failures is one nobody can report.
715
942
 
716
- `sb dev` and `sb deploy` translate the server codes below rather than passing
717
- them through verbatim. `sb code` words its own refusals: the refused-token one
718
- is above, and the [`sb code`](#sb-code--your-code-dock-files-as-a-folder)
943
+ `sb app dev` and `sb app deploy` translate the server codes below rather than passing
944
+ them through verbatim. `sb site code` words its own refusals: the refused-token one
945
+ is above, and the [`sb site code`](#sb-site-code--your-code-dock-files-as-a-folder)
719
946
  section describes the command.
720
947
 
721
948
  | Server code | What `sb` says instead |
@@ -737,15 +964,16 @@ shrug.
737
964
 
738
965
  Stated so you can plan around it rather than discover it.
739
966
 
740
- - **It does not create the app, the version, or the install.** `sb init` makes no
741
- network calls. Those steps are yours, by hand or by your own script; the CLI
742
- starts being useful once those ids exist.
743
- - **It does not write `sb.json`**, for the same reason.
967
+ - **`sb app init` makes no network calls.** Registering the app is `sb app create`,
968
+ which makes a *draft* and a *sandbox* install on your own store — nothing is
969
+ submitted for review or made public, and it never creates an organization.
970
+ - **It never prints the client secret.** It goes to `.env` (mode `0600`) and nowhere
971
+ else; lose it and rotate it in the developer portal.
744
972
  - **It never asks for a password.** `sb login` signs in through the browser,
745
973
  and the only thing it stores is the credential file described above.
746
- - **`sb dev` is not hot reload**, and no future version of it can be while an
974
+ - **`sb app dev` is not hot reload**, and no future version of it can be while an
747
975
  island's code is served from the platform's object store.
748
- - **`sb deploy` is not atomic**, deliberately.
976
+ - **`sb app deploy` is not atomic**, deliberately.
749
977
 
750
978
  ---
751
979
 
@@ -753,18 +981,19 @@ Stated so you can plan around it rather than discover it.
753
981
 
754
982
  | Symptom | Cause | Fix |
755
983
  | --- | --- | --- |
756
- | `Not signed in. Run sb login …` | `dev`/`deploy` have no credential | `sb login`, or set `SB_TOKEN` |
984
+ | `Not signed in. Run sb login …` | `sb app dev` / `sb app deploy` have no credential | `sb login`, or set `SB_TOKEN` |
757
985
  | `Your sb login has expired or was revoked.` | The stored session ended (signed out everywhere, or it lapsed) | `sb login` again |
758
986
  | `SB_TOKEN was refused: …` | The pasted token expired or was revoked | `sb login`, or a fresh token |
759
- | `Not signed in, or the token was refused …` | `sb code` has no credential, the pasted `SB_TOKEN` was refused, or the server still answered 401 after renewing your `sb login` | `sb login`, or set `SB_TOKEN` to a `wbk_` API key with `codefiles.read` / `codefiles.write` from Settings → API keys |
987
+ | `Not signed in, or the token was refused …` | `sb site code` has no credential, the pasted `SB_TOKEN` was refused, or the server still answered 401 after renewing your `sb login` | `sb login`, or set `SB_TOKEN` to a `wbk_` API key with `codefiles.read` / `codefiles.write` from Settings → API keys |
760
988
  | `No sb.json here.` | Run from the wrong directory | `cd` to the folder holding `sb.json` |
989
+ | `sb.json is missing "orgId". It is empty until sb app create fills it in.` | The scaffold's ids are still empty | `sb app create "<name>"` |
761
990
  | `sb.json is missing "versionId".` | A required key is absent or empty | Add all five required keys |
762
991
  | `unknown command: …` | Typo, or a stale `dist/` | `npm run build --workspace cli` |
763
992
  | `--port must be a number` | `--port` got a non-positive or non-numeric value | Pass a positive integer |
764
993
  | Uploads refused with `not_draft` | The version left draft; approval pins its payload | Create a new draft version and point `sb.json` at it |
765
- | Uploads refused with `island_not_found` | The version does not declare that island | Declare it first — `sb deploy` with an `islands` array does this in the right order |
766
- | `--submit` refused for loopback URLs | `version.embedUrl` / `version.redirectUri` still point at localhost | Set public `https` URLs, `sb deploy` again, then submit |
767
- | The island changed and the page did not | `sb dev` is not hot reload | Refresh the page |
994
+ | Uploads refused with `island_not_found` | The version does not declare that island | Declare it first — `sb app deploy` with an `islands` array does this in the right order |
995
+ | `--submit` refused for loopback URLs | `version.embedUrl` / `version.redirectUri` still point at localhost | Set public `https` URLs, `sb app deploy` again, then submit |
996
+ | The island changed and the page did not | `sb app dev` is not hot reload | Refresh the page |
768
997
  | `sb` reports a flag this page does not list | You are running an older `dist/` | Rebuild |
769
998
 
770
999
  ---