@sbuilder/cli 0.13.0 → 0.15.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
@@ -7,9 +7,10 @@ editor's AI assistant on your own machine, and build apps for the platform.
7
7
 
8
8
  ```
9
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)
10
+ sb init ask what to start: a new website built by AI, one
11
+ from a template, a repo for one of your sites, an
12
+ app or a Next.js storefront (same as npm create
13
+ sbuilder-app)
13
14
 
14
15
  Account
15
16
  sb login sign in through the browser; stores a credential
@@ -24,6 +25,9 @@ Sites
24
25
  sb site new "<description>" [--dir <path>] [--github] [--editor]
25
26
  make a site from one sentence, in a repo an AI
26
27
  agent builds in (--editor: in the editor instead)
28
+ sb site new --template <slug|id> ["<description>"] [--dir <path>] [--github]
29
+ a new site copied from a template, in the same repo
30
+ sb site templates [--json] the templates a new site can start from
27
31
  sb site init [dir] [--site <id>] [--github]
28
32
  a repo holding one site's pages, synced with
29
33
  GitHub both ways
@@ -36,6 +40,8 @@ Sites
36
40
  sb site dev [--theme] watch design/ and code/, push each save as a DRAFT
37
41
  sb site publish <file>… | --all
38
42
  make pages LIVE — named files, or every page
43
+ sb site preview <file> [--open] [--html]
44
+ a link to the page's DRAFT, rendered — nothing published
39
45
  sb site blocks the blocks your installed apps offer, with the line
40
46
  to paste into a page file
41
47
  sb site next serve the pages from a Next.js app, rendered by the
@@ -195,7 +201,7 @@ sb app init my-app --with-block
195
201
 
196
202
  Writes a working app into `./my-app` and prints what to do next. It makes **no
197
203
  network calls at all** — it is a scaffolder; `sb app create` (below) registers
198
- it. A bare `sb init` on a terminal asks what to start instead; its choice 3 runs
204
+ it. A bare `sb init` on a terminal asks what to start instead; its choice 4 runs
199
205
  this flow.
200
206
 
201
207
  ### What it writes
@@ -707,6 +713,8 @@ file missing locally without `--delete`, is printed and is **not** a failure.
707
713
  ```
708
714
  sb init # a menu: "a new website, built by AI" is choice 1
709
715
  sb site new "a shop selling handmade candles" # the same, from the command line
716
+ sb site new --template tea-shop # a new site copied from a template, in a repo like the one below
717
+ sb site templates # the templates to start from (--json for the list as JSON)
710
718
  sb site init my-shop --github # a repo for one of your sites, on a private GitHub repo
711
719
  sb site pull # take what was edited in the editor
712
720
  sb site push # save edited page files as DRAFTS
@@ -715,9 +723,11 @@ sb site push --theme # also send design/theme.json (a theme save is
715
723
  sb site status # what differs from the last sync; stale translations
716
724
  sb site dev # watch design/ and code/ and push each save as a DRAFT
717
725
  sb site publish --all # make pages live (or name files)
726
+ sb site preview design/pages/index.page.tsx # a link to that page's DRAFT, rendered (--open opens it, --html prints it); nothing published
718
727
  sb site next # serve the pages from a Next.js app (npm run dev)
719
728
  sb site next --link # mint the host secret into .env: a deployed host signs its requests
720
729
  sb site deploy --vercel # one command to production on Vercel, with your own vercel CLI (--dry-run: the plan; --rotate replaces a link made elsewhere)
730
+ sb site deploy --docker [--no-build] # the same app for any host that runs a container: Dockerfile, compose.yaml with Caddy (https by itself), .env.production
721
731
  sb site agents # the AI-agent files, for a repo made by an older CLI
722
732
  sb site agents --refresh # bring them to this CLI's text; an edited one gets <file>.new
723
733
  sb site types # design/sbuilder-env.d.ts: completion + checks for .page.tsx
@@ -731,7 +741,18 @@ description), writes the repo below into `./<name>` (`--dir` picks another folde
731
741
  offers to start it in that folder with your description. Signed out, it runs the
732
742
  `sb login` flow first. It is exactly what choice 1 of `sb init` does.
733
743
 
734
- **The Next.js storefront starter** is choice 4 of `sb init` (the menu `npm create sbuilder-app` shows). It picks one of your sites, writes its repo like `sb site init`, runs `sb site next`, adds `@sbuilder/sdk` and one hand-written route, `app/api/featured/route.ts` (JSON), which lists the store's products through `@sbuilder/sdk/storefront` (no API key, so it also works on a deployed host). The page types (`design/sbuilder-env.d.ts`) come with the repo. Then `npm install && npm run dev`, and `sb site deploy --vercel` when you want it online.
744
+ **`sb site new --template <slug|id>`** starts from a design instead of a sentence. It copies
745
+ the template into a new site in your account through the platform's own copy (pages, theme,
746
+ Code Dock files and code components come along), waits for the copy to finish, then writes
747
+ the same repo as `sb site init` around it. A description after the flag
748
+ (`sb site new --template tea-shop "a tea house in Hanoi"`) names the site and becomes the brief
749
+ Claude Code is offered, to adapt the design; without one the site takes the template's name.
750
+ **`sb site templates`** lists what there is to start from — slug, name, categories, the live
751
+ template and its preview image — and needs no sign-in. Choice 2 of `sb init` is the same flow
752
+ with a numbered list. The copy is made in your account's name, so it needs `sb login`, not an
753
+ API key.
754
+
755
+ **The Next.js storefront starter** is choice 5 of `sb init` (the menu `npm create sbuilder-app` shows). It picks one of your sites, writes its repo like `sb site init`, runs `sb site next`, adds `@sbuilder/sdk` and one hand-written route, `app/api/featured/route.ts` (JSON), which lists the store's products through `@sbuilder/sdk/storefront` (no API key, so it also works on a deployed host). The page types (`design/sbuilder-env.d.ts`) come with the repo. Then `npm install && npm run dev`, and `sb site deploy --vercel` when you want it online.
735
756
 
736
757
  **`sb site new --editor "<description>"`** builds in the editor instead: it opens the
737
758
  editor, which creates the site and starts building it. If `sb agent` is already
@@ -748,6 +769,7 @@ platform's key.
748
769
  | Flag | Effect |
749
770
  | --- | --- |
750
771
  | `--editor` | Build in the editor (the assistant, or your `sb agent`) instead of in a repo |
772
+ | `--template <slug\|id>` | Copy that template into the new site instead of starting empty (`sb site templates` lists them) |
751
773
 
752
774
  **Building with AI.** Choice 1 of `sb init` (and `sb site new`) takes your description, creates
753
775
  the site, writes the repo below and — when Claude Code is installed — starts it in
@@ -761,6 +783,28 @@ the agent how to work: native elements first, look at every section on desktop a
761
783
  mobile, ask for real facts, pull the result into the repo, **never publish unasked**.
762
784
  The agent edits the site's drafts; you review what it did as a git diff.
763
785
 
786
+ **`sb site preview <file>`** prints a link to that page's current DRAFT on the storefront,
787
+ rendered exactly as a visitor would see it once published — the editor's own Preview, from the
788
+ terminal. Nothing is published. The link works for an hour; `--open` opens it in the browser,
789
+ `--html` prints the rendered HTML instead. It shows what was last PUSHED (a file with edits not
790
+ pushed yet says so). It is minted with your `sb login` (or `SB_TOKEN`) when there is one, sent
791
+ only to that platform; otherwise with the repo's API key in `.env` (it needs `pages.read`), sent to
792
+ the `.env`'s own `SB_API` — the pair every site command uses.
793
+
794
+ **Structure is checked before anything is sent.** Every element must sit where the schema allows
795
+ it — a parent's allowed children (an `<Accordion>` holds only `<AccordionContent>`) and the
796
+ section types that live only directly in `<Page>`. `sb site push` and `sb site dev` check each
797
+ file they are about to send: one that breaks this is not sent, with `file:line:col` and what to
798
+ write instead (a removed element type: delete it), while the other files go; push then exits 1.
799
+ The rules are this CLI's copy of the schema — the message says which version, and if the editor
800
+ allows what it refuses, upgrade sb. `sb doctor` reports it for every file. `design/sbuilder-env.d.ts`
801
+ carries each element's purpose, its allowed children and an example, from the schema.
802
+
803
+ **The theme.** `sb site pull` writes `design/theme.json` — the site's saved theme, or the
804
+ default it renders with while it has none. A theme save is live at once, so `sb site push`
805
+ sends it only with `--theme`, and `sb site push --theme --dry-run` prints each token that would
806
+ change (`colors.primary: value #171717 → #e11d48`) and sends nothing.
807
+
764
808
  **What `sb site init` writes.** It signs you in if needed, lets you pick a site (or
765
809
  takes `--site <id>`), and writes:
766
810
 
@@ -801,6 +845,9 @@ repo, `sb site`, `sb site code` and `sb site mcp` read `.env`; a variable alread
801
845
  shell wins. `--github` then runs `git init`, the first commit, `gh repo create
802
846
  --private --push` and `gh secret set SB_TOKEN` (the key goes in on stdin, never on a
803
847
  command line) — the workflow is live with nothing left to paste.
848
+ Without `--github`, init still runs `git init` and makes the first commit when the folder is not
849
+ inside a git repo already and git is installed (it says which), so every later pull or agent
850
+ edit shows as a git diff.
804
851
 
805
852
  **Page files.** Each page is a `.page.tsx` file that reads like React — one tag per element,
806
853
  its settings as props:
@@ -882,6 +929,8 @@ site directly** (not *Redirect to …*).
882
929
 
883
930
  **Deploy to Vercel: `sb site deploy --vercel`.** One command takes a repo set up with `sb site next` to a production deployment, using **your own `vercel` CLI**. It is detected; if it is not on your PATH the command prints the install and login steps and exits non-zero — `sb` never installs anything globally. In order: it makes sure `.vercelignore` lists `.env*` — `vercel deploy` reads `.vercelignore` alone and never the contents of `.gitignore`, so without it `.env` (the repo's API key) would be uploaded; `sb site next` writes the file, and here a missing line is added only after you say yes (or with `--yes`); it reuses the host link in `.env` (it mints one only when there is none; a link made elsewhere is replaced only with `--rotate`, which stops the old secret at once — `--yes` never rotates, and the addresses are validated before anything is minted); it checks that the site's primary domain **is** `SB_PUBLIC_URL`, the same check the deployed host makes at startup, and stops with the fix before changing anything on Vercel; it runs `vercel link` (once; off a terminal that needs `--yes`); it sets `SB_HOST_SECRET`, `SB_SITE_ID`, `SB_PUBLIC_URL` and `SB_STOREFRONT` for Production with `vercel env add`, each value on **stdin** (never in argv, never printed; the secret is masked even in a failing `vercel` message); and it runs `vercel deploy --prod` and prints the URL. `SB_PUBLIC_URL` and `SB_STOREFRONT` are read from the shell, else from `.env`. A variable Vercel already has is replaced only after you confirm (or pass `--yes`), so running it again is safe. **Preview deployments get `SB_STOREFRONT` only:** they pass published pages through with `noindex` and skip the origin check, so they need nothing else, and Vercel gives preview variables to every branch's build — the secret stays out of reach of a pull request's build script. (With no secret a preview follows the store's redirect from its built-in address, said once on stderr.) `--dry-run` prints the plan without running `vercel`, calling the platform or printing a value. The domain itself is added to the project with `vercel domains add <domain>`; the command reminds you. It names the Vercel project and organization before it sets anything, and refuses a `.vercel/project.json` that git tracks (a cloned repo could aim your deploy, and your secrets, at someone else's project) unless you pass `--yes` (which accepts that project). Before minting anything it checks the primary domain without the secret; when a link was replaced and a later step fails, it says the live host's old secret is already rejected, so the live site is degraded until the deploy finishes. If it fails after minting a host link it says so: production keeps the previous secret until a deploy finishes, and running the same command again reuses the new link.
884
931
 
932
+ **Anywhere else: `sb site deploy --docker`.** The same app, packaged for any host that runs a container — a server of your own, Fly.io, Railway, Render, Cloud Run, Coolify, Kubernetes. It makes the checks `--vercel` makes, with the same code: the host link in `.env` is reused (minted when there is none; a link made elsewhere is replaced only with `--rotate`), and the site's primary domain must **be** `SB_PUBLIC_URL` — nothing is written before that passes. Then it writes, each **only when missing** (a file you have is never overwritten): a `Dockerfile` (Node 22, runs as the unprivileged `node` user, `next start` as PID 1), a `.dockerignore`, a `compose.yaml` and a `Caddyfile` for the primary domain. Whatever `.dockerignore` you have, `.env` and `.env*` are made to be in it (after any negation, where they win), so an image never holds the repo's key or the host secret. It writes `.env.production` (mode 0600, added to `.gitignore`): `SB_HOST_SECRET`, `SB_SITE_ID`, `SB_PUBLIC_URL`, `SB_STOREFRONT` and `SB_TRUST_PROXY` — never `SB_TOKEN`; a line you added there is kept. Last, `docker build -t <folder>` when `docker` is on your PATH (`--no-build` skips it; without docker the files are still the result). The image carries no configuration: the variables arrive at run time. **On a server of your own**, point the domain's DNS at it and run `docker compose up -d --build` — Caddy answers on 80 and 443 and gets the HTTPS certificate by itself. **On a container platform**, deploy the `Dockerfile`, import `.env.production` as its environment and add the domain there. `SB_TRUST_PROXY=1` is right behind Caddy and behind most platforms' single proxy; a container reached with no proxy in front cannot tell its visitors apart, so always put one there. `--dry-run` prints the plan and changes nothing.
933
+
885
934
  **Addresses.** Besides an exact page path, a preview maps `/products/<slug>`, `/collections/<slug>`,
886
935
  `/blog/<slug>` and `/courses/<slug>` to the page file of that type (the one marked
887
936
  `defaultTemplate: true`, else the only one), and `/<locale>/…` — for each locale in
@@ -970,7 +1019,8 @@ changing `name`, `slug`, `type`, `isHomepage`, `settings` or `defaultTemplate` i
970
1019
  file renames or re-types it. `path` is derived and only informational. When the platform
971
1020
  settles on something other than what you asked (a slug is made unique) push says so, and
972
1021
  after every save the file is rewritten to what the platform stored — minted ids and the
973
- facts it settled on — so the next `sb site pull` changes nothing. A file with no
1022
+ facts it settled on, with shared sections and overlays in place as a pull writes them — so
1023
+ the next `sb site pull` changes nothing. A file with no
974
1024
  `export const page` and no manifest entry is still only reported.
975
1025
 
976
1026
  Facts are merged three ways like the document: what was last synced is the base. A fact only
@@ -987,7 +1037,8 @@ With an API key (`/api/v1`) the platform also fences the write itself: each fact
987
1037
  pages: it lists them first, asks on a terminal, and off a terminal also needs `--yes`
988
1038
  (nothing is deleted otherwise). `--prune` refuses when `design/pages/` is absent, since
989
1039
  every page would then look deleted. A page deleted on the platform keeps its file, named
990
- by pull.
1040
+ by pull. A tracked file you deleted stays deleted on `sb site pull` (named, exit 0) until you
1041
+ prune the page; `sb site pull --force` writes it back.
991
1042
 
992
1043
  ### The rest of the site as files
993
1044
 
@@ -1332,6 +1383,7 @@ Stated so you can plan around it rather than discover it.
1332
1383
 
1333
1384
  | Symptom | Cause | Fix |
1334
1385
  | --- | --- | --- |
1386
+ | A page answers `decode input: json: unknown field …` — the installed @sbuilder/render is older than the platform | The platform's renderer moved on and this app's lockfile still pins an older `@sbuilder/render` | `npm install @sbuilder/render@latest`, restart |
1335
1387
  | `Not signed in. Run sb login …` | `sb app dev` / `sb app deploy` have no credential | `sb login`, or set `SB_TOKEN` |
1336
1388
  | `Your sb login has expired or was revoked.` | The stored session ended (signed out everywhere, or it lapsed) | `sb login` again |
1337
1389
  | `SB_TOKEN was refused: …` | The pasted token expired or was revoked | `sb login`, or a fresh token |
package/README.vi.md CHANGED
@@ -8,8 +8,8 @@ trợ lý AI của editor trên máy bạn, và xây app cho nền tảng.
8
8
  ```
9
9
  Bắt đầu
10
10
  sb init hỏi bạn muốn bắt đầu gì: website mới do AI dựng,
11
- repo cho một site của bạn, hay app (giống npm
12
- create sbuilder-app)
11
+ website từ một mẫu, repo cho một site của bạn, app
12
+ hay Next.js storefront (giống npm create sbuilder-app)
13
13
 
14
14
  Tài khoản
15
15
  sb login đăng nhập qua trình duyệt; lưu một credential tự
@@ -24,6 +24,9 @@ Site
24
24
  sb site new "<mô tả>" [--dir <path>] [--github] [--editor]
25
25
  tạo site từ một câu, trong một repo để AI agent dựng
26
26
  (--editor: dựng ngay trong editor)
27
+ sb site new --template <slug|id> ["<mô tả>"] [--dir <path>] [--github]
28
+ site mới chép từ một mẫu, trong cùng kiểu repo đó
29
+ sb site templates [--json] các mẫu mà một site mới có thể bắt đầu từ đó
27
30
  sb site init [dir] [--site <id>] [--github]
28
31
  repo chứa các trang của một site, đồng bộ hai
29
32
  chiều với GitHub
@@ -37,6 +40,8 @@ Site
37
40
  sb site dev [--theme] theo dõi design/ và code/, mỗi lần lưu là một BẢN NHÁP
38
41
  sb site publish <file>… | --all
39
42
  đưa trang lên LIVE — file chỉ định, hoặc mọi trang
43
+ sb site preview <file> [--open] [--html]
44
+ liên kết tới BẢN NHÁP của trang, đã render — không xuất bản
40
45
  sb site blocks các block app đã cài cho phép đặt, kèm dòng để dán
41
46
  vào file trang
42
47
  sb site next phục vụ các trang từ một app Next.js, render bằng
@@ -195,7 +200,7 @@ sb app init my-app --with-block
195
200
 
196
201
  Ghi một app chạy được vào `./my-app` và in ra việc cần làm tiếp theo. Nó **không
197
202
  gọi mạng một lần nào** — đây là công cụ tạo khung; `sb app create` (bên dưới) mới là
198
- bước đăng ký. Gõ `sb init` trần trong terminal sẽ hỏi bạn muốn bắt đầu gì; lựa chọn 3
203
+ bước đăng ký. Gõ `sb init` trần trong terminal sẽ hỏi bạn muốn bắt đầu gì; lựa chọn 4
199
204
  chạy đúng luồng này.
200
205
 
201
206
  ### Nó ghi ra những gì
@@ -709,6 +714,8 @@ theo dõi bị mất ở máy khi không có `--delete`, được in ra và **kh
709
714
  ```
710
715
  sb init # một menu: lựa chọn 1 là "website mới do AI dựng"
711
716
  sb site new "cửa hàng nến thơm thủ công" # y hệt, từ dòng lệnh
717
+ sb site new --template tea-shop # site mới chép từ một mẫu, trong một repo như bên dưới
718
+ sb site templates # các mẫu có thể bắt đầu từ đó (--json: danh sách dạng JSON)
712
719
  sb site init my-shop --github # repo cho một site của bạn, trên repo GitHub riêng tư
713
720
  sb site pull # lấy những gì đã sửa trong editor
714
721
  sb site push # lưu file trang đã sửa thành BẢN NHÁP
@@ -717,9 +724,11 @@ sb site push --theme # gửi cả design/theme.json (lưu theme có
717
724
  sb site status # điều khác với lần đồng bộ gần nhất; bản dịch lỗi thời
718
725
  sb site dev # theo dõi design/ và code/, mỗi lần lưu là một BẢN NHÁP
719
726
  sb site publish --all # xuất bản trang (hoặc chỉ định file)
727
+ sb site preview design/pages/index.page.tsx # liên kết tới BẢN NHÁP của trang, đã render (--open mở nó, --html in HTML); không xuất bản gì
720
728
  sb site next # phục vụ các trang từ một app Next.js (npm run dev)
721
729
  sb site next --link # tạo host secret vào .env: host đã deploy ký các request của nó
722
730
  sb site deploy --vercel # một lệnh lên production trên Vercel, bằng vercel CLI của bạn (--dry-run: chỉ in kế hoạch; --rotate thay link do nơi khác tạo)
731
+ sb site deploy --docker [--no-build] # cùng app đó cho mọi host chạy container: Dockerfile, compose.yaml có Caddy (tự có https), .env.production
723
732
  sb site agents # các file cho AI agent, cho repo tạo bởi bản CLI cũ
724
733
  sb site agents --refresh # đưa chúng về văn bản của bản CLI này; file đã sửa nhận <file>.new
725
734
  sb site types # design/sbuilder-env.d.ts: gợi ý + kiểm tra cho .page.tsx
@@ -732,7 +741,17 @@ sb site mcp # MCP server của Store Builder, với k
732
741
  — nếu máy có Claude Code — đề nghị mở nó trong thư mục đó với mô tả của bạn. Nếu chưa đăng
733
742
  nhập, nó chạy luồng `sb login` trước. Đây đúng là việc lựa chọn 1 của `sb init` làm.
734
743
 
735
- **Starter Next.js storefront** là lựa chọn 4 của `sb init` (menu mà `npm create sbuilder-app` hiện ra). Nó chọn một site của bạn, tạo repo như `sb site init`, chạy `sb site next`, thêm `@sbuilder/sdk` và một route viết tay, `app/api/featured/route.ts` (JSON), liệt kê sản phẩm của cửa hàng qua `@sbuilder/sdk/storefront` (không cần API key, nên chạy được cả trên host đã deploy). Kiểu cho trang (`design/sbuilder-env.d.ts`) đi kèm repo. Sau đó `npm install && npm run dev`, và `sb site deploy --vercel` khi muốn đưa lên mạng.
744
+ **`sb site new --template <slug|id>`** bắt đầu từ một thiết kế thay vì một câu mô tả. Lệnh chép
745
+ mẫu vào một site mới trong tài khoản của bạn bằng chính tính năng sao chép của nền tảng (trang,
746
+ theme, file Code Dock và code component đều đi kèm), chờ việc sao chép xong, rồi viết đúng repo
747
+ như `sb site init` quanh site đó. Một mô tả sau flag
748
+ (`sb site new --template tea-shop "quán trà ở Hà Nội"`) đặt tên site và trở thành yêu cầu đưa cho
749
+ Claude Code để chỉnh lại thiết kế; không có mô tả thì site lấy tên của mẫu.
750
+ **`sb site templates`** liệt kê các mẫu — slug, tên, danh mục, site thật của mẫu và ảnh xem trước —
751
+ và không cần đăng nhập. Lựa chọn 2 của `sb init` là cùng luồng này với một danh sách đánh số.
752
+ Bản sao được tạo dưới tên tài khoản của bạn, nên cần `sb login`, không dùng được API key.
753
+
754
+ **Starter Next.js storefront** là lựa chọn 5 của `sb init` (menu mà `npm create sbuilder-app` hiện ra). Nó chọn một site của bạn, tạo repo như `sb site init`, chạy `sb site next`, thêm `@sbuilder/sdk` và một route viết tay, `app/api/featured/route.ts` (JSON), liệt kê sản phẩm của cửa hàng qua `@sbuilder/sdk/storefront` (không cần API key, nên chạy được cả trên host đã deploy). Kiểu cho trang (`design/sbuilder-env.d.ts`) đi kèm repo. Sau đó `npm install && npm run dev`, và `sb site deploy --vercel` khi muốn đưa lên mạng.
736
755
 
737
756
  **`sb site new --editor "<mô tả>"`** dựng trong editor: lệnh mở editor, editor tạo site và
738
757
  bắt đầu dựng. Nếu `sb agent` đang chạy thì `sb agent` làm việc này; nếu chưa chạy mà máy có
@@ -747,6 +766,7 @@ của nền tảng.
747
766
  | Flag | Tác dụng |
748
767
  | --- | --- |
749
768
  | `--editor` | Dựng trong editor (trợ lý, hoặc `sb agent` của bạn) thay vì trong một repo |
769
+ | `--template <slug\|id>` | Chép mẫu đó vào site mới thay vì bắt đầu trống (`sb site templates` liệt kê các mẫu) |
750
770
 
751
771
  **Dựng bằng AI.** Lựa chọn 1 của `sb init` (và `sb site new`) lấy mô tả của bạn, tạo site, viết repo
752
772
  dưới đây và — nếu máy có Claude Code — mở nó ngay trong thư mục đó với mô tả của bạn,
@@ -758,6 +778,27 @@ không đọc `.codex/config.toml`), còn `AGENTS.md` (được `CLAUDE.md` và
758
778
  từng section trên desktop và mobile, hỏi dữ liệu thật, kéo kết quả về repo, **không
759
779
  bao giờ tự xuất bản**. Agent sửa bản nháp của site; bạn duyệt lại bằng git diff.
760
780
 
781
+ **`sb site preview <file>`** in ra liên kết tới BẢN NHÁP hiện tại của trang trên storefront,
782
+ render đúng như khách sẽ thấy khi xuất bản — chính nút Preview của editor, từ terminal. Không có
783
+ gì được xuất bản. Liên kết dùng được một giờ; `--open` mở nó trong trình duyệt, `--html` in ra HTML
784
+ đã render. Nó hiển thị bản đã PUSH gần nhất (file có chỉnh sửa chưa push sẽ được báo). Liên kết
785
+ được tạo bằng `sb login` (hoặc `SB_TOKEN`) nếu có, chỉ gửi tới nền tảng đó; không thì bằng
786
+ API key của repo trong `.env` (cần quyền `pages.read`), gửi tới `SB_API` của chính `.env` đó — cặp mà mọi lệnh
787
+ site đều dùng.
788
+
789
+ **Cấu trúc được kiểm tra trước khi gửi.** Mỗi phần tử phải nằm ở chỗ schema cho phép — các con
790
+ được phép của phần tử cha (`<Accordion>` chỉ chứa `<AccordionContent>`) và các loại section chỉ
791
+ nằm trực tiếp trong `<Page>`. `sb site push` và `sb site dev` kiểm tra từng file sắp gửi: file vi phạm
792
+ không được gửi, kèm `file:line:col` và cách viết đúng (loại phần tử đã bị gỡ: xoá nó), các file khác vẫn
793
+ đi; push sau đó thoát với mã 1. Luật là bản schema của chính CLI này — thông báo ghi phiên bản, và nếu
794
+ editor cho phép điều nó từ chối thì hãy nâng cấp sb. `sb doctor` báo cho mọi file.
795
+ `design/sbuilder-env.d.ts` ghi công dụng, các con được phép và ví dụ của từng phần tử, lấy từ schema.
796
+
797
+ **Theme.** `sb site pull` ghi `design/theme.json` — theme site đã lưu, hoặc theme mặc định site đang
798
+ dùng khi chưa lưu. Lưu theme có hiệu lực ngay, nên `sb site push` chỉ gửi nó khi có `--theme`, và
799
+ `sb site push --theme --dry-run` in từng token sẽ đổi (`colors.primary: value #171717 → #e11d48`) mà
800
+ không gửi gì.
801
+
761
802
  **`sb site init` viết ra những gì.** Nó đăng nhập nếu cần, cho bạn chọn site (hoặc nhận
762
803
  `--site <id>`), rồi viết:
763
804
 
@@ -799,6 +840,9 @@ Settings -> API keys. Nếu không tạo được key, init nói rõ rồi làm
799
840
  `--github` chạy tiếp `git init`, commit đầu tiên, `gh repo create --private --push` và
800
841
  `gh secret set SB_TOKEN` (key đi qua stdin, không bao giờ nằm trên dòng lệnh) — workflow
801
842
  chạy được ngay, không phải dán gì.
843
+ Không có `--github`, init vẫn chạy `git init` và tạo commit đầu tiên khi thư mục chưa nằm trong
844
+ một repo git và máy có git (nó báo trường hợp nào), để mọi lần pull hay chỉnh sửa của agent về sau
845
+ đều hiện thành git diff.
802
846
 
803
847
  **File trang.** Mỗi trang là một file `.page.tsx` đọc như React — mỗi phần tử một thẻ, cài
804
848
  đặt của nó là prop:
@@ -878,6 +922,8 @@ site directly** (không phải *Redirect to …*).
878
922
 
879
923
  **Deploy lên Vercel: `sb site deploy --vercel`.** Một lệnh đưa repo đã làm bằng `sb site next` lên bản production, dùng **`vercel` CLI của chính bạn**. Lệnh dò tìm nó; nếu không có trên PATH, lệnh in các bước cài và đăng nhập rồi thoát với mã khác 0 — `sb` không bao giờ cài gì ở mức toàn máy. Thứ tự: đảm bảo `.vercelignore` có dòng `.env*` — `vercel deploy` chỉ đọc `.vercelignore`, không bao giờ đọc nội dung `.gitignore`, nên nếu thiếu thì `.env` (API key của repo) sẽ bị tải lên; `sb site next` tạo sẵn file này, còn ở đây dòng thiếu chỉ được thêm sau khi bạn đồng ý (hoặc với `--yes`); dùng lại host link trong `.env` (chỉ tạo mới khi chưa có; link do nơi khác tạo chỉ bị thay bằng `--rotate`, làm secret cũ ngừng dùng ngay — `--yes` không bao giờ xoay vòng, và các địa chỉ được kiểm tra trước khi tạo gì); kiểm tra tên miền chính của site **đúng là** `SB_PUBLIC_URL`, cùng phép kiểm tra host đã deploy làm lúc khởi động, và dừng kèm cách sửa trước khi đổi bất cứ thứ gì trên Vercel; chạy `vercel link` (một lần; ngoài terminal cần `--yes`); đặt `SB_HOST_SECRET`, `SB_SITE_ID`, `SB_PUBLIC_URL` và `SB_STOREFRONT` cho Production bằng `vercel env add`, mỗi giá trị đi qua **stdin** (không bao giờ trong argv, không bao giờ in ra; secret được che ngay cả trong thông báo lỗi của `vercel`); rồi chạy `vercel deploy --prod` và in URL. `SB_PUBLIC_URL` và `SB_STOREFRONT` lấy từ shell, không thì từ `.env`. Biến Vercel đã có chỉ bị thay sau khi bạn xác nhận (hoặc truyền `--yes`), nên chạy lại là an toàn. **Bản deploy preview chỉ nhận `SB_STOREFRONT`:** chúng chuyển tiếp trang đã xuất bản kèm `noindex` và bỏ qua kiểm tra origin nên không cần gì khác, và Vercel đưa biến preview cho build của mọi nhánh — secret nằm ngoài tầm của build script trong một pull request. (Không có secret thì preview đi theo redirect của cửa hàng từ địa chỉ có sẵn, báo một lần trên stderr.) `--dry-run` in kế hoạch mà không chạy `vercel`, không gọi nền tảng, không in giá trị nào. Tên miền được thêm vào project bằng `vercel domains add <domain>`; lệnh sẽ nhắc bạn. Lệnh nêu tên project và tổ chức Vercel trước khi đặt biến, và từ chối `.vercel/project.json` đang được git theo dõi (một repo clone có thể hướng deploy và secret của bạn tới project của người khác) trừ khi bạn truyền `--yes` (chấp nhận project đó). Trước khi tạo bất cứ gì, lệnh kiểm tra tên miền chính khi chưa có secret; nếu một link đã bị thay mà bước sau lỗi, lệnh nói rõ secret cũ của host đang chạy đã bị từ chối nên site đang chạy bị suy giảm cho tới khi deploy xong. Nếu lỗi xảy ra sau khi đã tạo host link, lệnh nói rõ: production vẫn giữ secret cũ cho tới khi một lần deploy xong, và chạy lại cùng lệnh sẽ dùng link mới.
880
924
 
925
+ **Mọi nơi khác: `sb site deploy --docker`.** Cùng app đó, đóng gói cho bất kỳ host nào chạy được container — máy chủ của bạn, Fly.io, Railway, Render, Cloud Run, Coolify, Kubernetes. Lệnh làm đúng các kiểm tra của `--vercel`, bằng cùng một đoạn code: dùng lại host link trong `.env` (chỉ tạo mới khi chưa có; link do nơi khác tạo chỉ bị thay bằng `--rotate`), và tên miền chính của site phải **đúng là** `SB_PUBLIC_URL` — chưa qua bước này thì không file nào được ghi. Sau đó nó ghi, mỗi file **chỉ khi còn thiếu** (file bạn đã có không bao giờ bị ghi đè): `Dockerfile` (Node 22, chạy bằng user `node` không có đặc quyền, `next start` là PID 1), `.dockerignore`, `compose.yaml` và `Caddyfile` cho tên miền chính. Dù `.dockerignore` của bạn là gì, `.env` và `.env*` luôn được đưa vào (sau mọi dòng phủ định, nơi chúng thắng), nên image không bao giờ chứa key của repo hay host secret. Lệnh ghi `.env.production` (mode 0600, thêm vào `.gitignore`): `SB_HOST_SECRET`, `SB_SITE_ID`, `SB_PUBLIC_URL`, `SB_STOREFRONT` và `SB_TRUST_PROXY` — không bao giờ có `SB_TOKEN`; dòng bạn tự thêm vào được giữ nguyên. Cuối cùng là `docker build -t <tên thư mục>` khi có `docker` trên PATH (`--no-build` để bỏ qua; không có docker thì các file vẫn là kết quả). Image không mang cấu hình nào: các biến đến lúc chạy. **Trên máy chủ của bạn**, trỏ DNS của tên miền về máy đó rồi chạy `docker compose up -d --build` — Caddy nghe cổng 80 và 443 và tự lấy chứng chỉ HTTPS. **Trên một nền tảng container**, deploy `Dockerfile`, nhập `.env.production` làm biến môi trường và thêm tên miền ở đó. `SB_TRUST_PROXY=1` đúng khi đứng sau Caddy và sau proxy duy nhất của đa số nền tảng; container được truy cập mà không có proxy phía trước thì không phân biệt được khách, nên luôn đặt một proxy ở đó. `--dry-run` in kế hoạch và không đổi gì.
926
+
881
927
  **Địa chỉ.** Ngoài đường dẫn trang chính xác, preview ánh xạ `/products/<slug>`,
882
928
  `/collections/<slug>`, `/blog/<slug>` và `/courses/<slug>` tới file trang cùng loại (file có
883
929
  `defaultTemplate: true`, nếu không thì file duy nhất), và `/<locale>/…` — với mỗi locale trong
@@ -960,7 +1006,8 @@ khi push; đổi `name`, `slug`, `type`, `isHomepage`, `settings` hay `defaultTe
960
1006
  file đã theo dõi là đổi tên hoặc đổi loại trang. `path` được suy ra, chỉ để tham khảo. Khi
961
1007
  nền tảng chốt khác điều bạn xin (slug bị làm cho không trùng) push sẽ nói ra, và sau mỗi
962
1008
  lần lưu file được ghi lại đúng như nền tảng đã lưu — id mới được cấp và các thông tin nó
963
- đã chốt — nên `sb site pull` kế tiếp không đổi gì. File không có `export const page` và
1009
+ đã chốt, cùng các phần dùng chung và overlay nằm đúng chỗ như khi pull ghi — nên `sb site
1010
+ pull` kế tiếp không đổi gì. File không có `export const page` và
964
1011
  chưa có trong manifest vẫn chỉ được nêu tên.
965
1012
 
966
1013
  Các thông tin này được trộn ba chiều như tài liệu: lần đồng bộ gần nhất là gốc. Thông tin chỉ
@@ -976,7 +1023,9 @@ Với API key (`/api/v1`) nền tảng còn rào chính lần ghi: mỗi thông
976
1023
  `missing` và trang vẫn ở lại nền tảng (exit 1). `sb site push --prune` xoá các trang đó:
977
1024
  nó liệt kê trước, hỏi lại khi chạy trên terminal, và ngoài terminal còn cần `--yes` (không
978
1025
  thì không xoá gì). `--prune` từ chối khi không có `design/pages/`, vì khi đó mọi trang đều
979
- trông như đã bị xoá. Trang bị xoá trên nền tảng vẫn giữ file, pull sẽ nêu tên.
1026
+ trông như đã bị xoá. Trang bị xoá trên nền tảng vẫn giữ file, pull sẽ nêu tên. File đã
1027
+ theo dõi mà bạn xoá thì `sb site pull` vẫn để nguyên là đã xoá (nêu tên, exit 0) cho tới khi
1028
+ bạn prune trang; `sb site pull --force` ghi nó lại.
980
1029
 
981
1030
  ### Phần còn lại của site thành file
982
1031
 
@@ -1322,6 +1371,7 @@ Nói ra để bạn tính đường trước, thay vì tự phát hiện giữa
1322
1371
 
1323
1372
  | Hiện tượng | Nguyên nhân | Cách xử lý |
1324
1373
  | --- | --- | --- |
1374
+ | Trang báo `decode input: json: unknown field …` — @sbuilder/render đã cài cũ hơn nền tảng | Renderer của nền tảng đã đổi, còn lockfile của app vẫn ghim `@sbuilder/render` cũ | `npm install @sbuilder/render@latest`, khởi động lại |
1325
1375
  | `Not signed in. Run sb login …` | `sb app dev` / `sb app deploy` không có credential nào | `sb login`, hoặc đặt `SB_TOKEN` |
1326
1376
  | `Your sb login has expired or was revoked.` | Phiên đã lưu đã kết thúc (đăng xuất mọi nơi, hoặc hết hạn) | Chạy lại `sb login` |
1327
1377
  | `SB_TOKEN was refused: …` | Token dán tay đã hết hạn hoặc bị thu hồi | `sb login`, hoặc lấy token mới |