···11+# @sitebase/cli
22+33+The sitebase CLI is a tool for managing your standard.site data from the command line.
44+55+## Installation
66+77+```bash
88+# From the monorepo
99+bun install
1010+bun run --filter @sitebase/cli build
1111+1212+# Link globally (optional)
1313+bun link
1414+```
1515+1616+## Setting the target publication
1717+1818+All commands except `auth *` and `pub list` require a target publication.
1919+2020+The target is determined from these sources, in order of precedence:
2121+2222+1. `--pub-id <rkey>` argument passed to the command
2323+2. `.sitebase.json` file in the current directory with a `publicationId` property
2424+3. `SITEBASE_PUB_ID` environment variable
2525+2626+The value is the **rkey** of the publication record (the last segment of the AT URI).
2727+2828+## Commands
2929+3030+### Auth
3131+3232+#### `auth login <handle>`
3333+3434+Logs in to an ATProto account via OAuth.
3535+3636+- Launches a temporary local HTTP server to handle the OAuth callback
3737+- Opens your browser to the authorization page
3838+- Requests the [standard.site auth bundle](https://pdsls.dev/at://did:plc:re3ebnp5v7ffagz6rb6xfei4/com.atproto.lexicon.schema/site.standard.authFull)
3939+- Stores session data in `$HOME/.sitebase/session.json`
4040+4141+```bash
4242+sitebase auth login <atproto-handle>
4343+```
4444+4545+#### `auth logout`
4646+4747+Clears the stored session data.
4848+4949+```bash
5050+sitebase auth logout
5151+```
5252+5353+### Publication
5454+5555+#### `pub list`
5656+5757+Lists all publications in the authenticated account's PDS.
5858+5959+Does not require a target publication.
6060+6161+```bash
6262+sitebase pub list
6363+```
6464+6565+#### `pub set`
6666+6767+Interactively select a publication from your account to set as the target.
6868+6969+Writes the selection to `.sitebase.json` in the current directory.
7070+7171+```bash
7272+sitebase pub set
7373+```
7474+7575+#### `pub view`
7676+7777+Displays information about the target publication (name, URL, description, AT URI).
7878+7979+```bash
8080+sitebase pub view # reads from SITEBASE_PUB_ID or .sitebase.json
8181+sitebase pub view --pub-id my-blog
8282+```
8383+8484+#### `pub edit`
8585+8686+Opens the publication metadata in `$EDITOR` for editing.
8787+8888+The publication data is presented as YAML. Save and close the editor to write changes back to the PDS.
8989+9090+```bash
9191+sitebase pub edit
9292+```
9393+9494+#### `pub export`
9595+9696+Exports all documents from the target publication to local files.
9797+9898+Uses a `sitebase.config.ts` configuration file. See [export.md](./export.md) for config format.
9999+100100+```bash
101101+# Auto-discover sitebase.config.ts in current directory
102102+sitebase pub export
103103+104104+# Specify config file
105105+sitebase pub export --config ./my-config.ts
106106+```
107107+108108+**Options:**
109109+110110+| Option | Description |
111111+|--------|-------------|
112112+| `-c, --config <file>` | Path to config file (auto-discovers `sitebase.config.ts` if not specified) |
113113+| `--init` | Create a starter `sitebase.config.ts` and `templates/post.hbs` in the current directory |
114114+115115+```bash
116116+# Initialize export config
117117+sitebase pub export --init
118118+```
119119+120120+### Documents
121121+122122+#### `doc list`
123123+124124+Lists all documents in the target publication.
125125+126126+```bash
127127+sitebase doc list
128128+sitebase doc list --tag post # Filter by tag
129129+sitebase doc list --tag draft # Show drafts
130130+```
131131+132132+#### `doc view <rkey>`
133133+134134+Displays a document's metadata and content preview.
135135+136136+```bash
137137+sitebase doc view abc123
138138+```
139139+140140+#### `doc edit <rkey>`
141141+142142+Opens a document in `$EDITOR` for editing.
143143+144144+The document is presented as a markdown file with YAML frontmatter (metadata in frontmatter, content in body). Save and close the editor to write changes back to the PDS.
145145+146146+**Content type restriction:** Only documents with `pub.sitebase.content.*` types can be edited. Documents with other content types (e.g., pckt.blog blocks) will show an error. Use `doc view` to inspect these documents instead.
147147+148148+```bash
149149+sitebase doc edit abc123
150150+```
151151+152152+#### `doc import <file>`
153153+154154+Creates a new document in the target publication from a local file.
155155+156156+The file should be markdown with YAML frontmatter containing at least a `title` field.
157157+158158+```bash
159159+sitebase doc import ./my-post.md
160160+sitebase doc import ./my-post.md --tag post --tag featured
161161+```
162162+163163+#### `doc export <rkey>`
164164+165165+Exports a single document to a local file or stdout.
166166+167167+Unlike `pub export`, this command does NOT use the config file. Instead, options are provided via command line arguments.
168168+169169+```bash
170170+# Output raw markdown to stdout
171171+sitebase doc export abc123
172172+173173+# Output to file (filename supports handlebars)
174174+sitebase doc export abc123 -o "{{publishedAt}}_{{slug title}}.md"
175175+176176+# With content template
177177+sitebase doc export abc123 -t ./templates/post.hbs -o ./content/my-post.md
178178+```
179179+180180+**Options:**
181181+182182+| Option | Description |
183183+|--------|-------------|
184184+| `-o, --output <file>` | Output filename (supports handlebars: `{{title}}`, `{{slug title}}`, `{{publishedAt}}`, etc.) |
185185+| `-t, --template <file>` | Handlebars template file for content |
186186+| `--stdout` | Output to stdout (default if no `-o`) |
187187+188188+### Drafts
189189+190190+Drafts are stored in a separate `pub.sitebase.draft` collection, not as `site.standard.document` records. This keeps unpublished work separate from your public documents.
191191+192192+See [lexicons.md](./lexicons.md) for the draft schema.
193193+194194+#### `draft list`
195195+196196+Lists all drafts for the target publication.
197197+198198+```bash
199199+sitebase draft list
200200+```
201201+202202+#### `draft new`
203203+204204+Creates a new draft and opens it in `$EDITOR`.
205205+206206+```bash
207207+sitebase draft new
208208+```
209209+210210+#### `draft edit <rkey>`
211211+212212+Opens a draft in `$EDITOR` for editing.
213213+214214+```bash
215215+sitebase draft edit abc123
216216+```
217217+218218+#### `draft publish <rkey>`
219219+220220+Publishes a draft as a `site.standard.document`.
221221+222222+- Creates a new document record with `publishedAt` set to current time
223223+- Deletes the draft record
224224+225225+```bash
226226+sitebase draft publish abc123
227227+```
228228+229229+#### `draft delete <rkey>`
230230+231231+Deletes a draft without publishing.
232232+233233+```bash
234234+sitebase draft delete abc123
235235+```