phibac developer docs

CLI reference

The CLI is the command-line tool you run in a terminal to create apps, publish their collections, generate TypeScript types, run a local server and connect an AI coding tool to the server's agent tools. Once it is installed in your project, you run it with npx phibac followed by a command, as the guides do. This page lists every command with its flags, the environment variables it reads, what it prints and its exit codes.

Install and run

The CLI needs Node.js 22 or later. Install it in your project from the npm registry:

npm install --save-dev phibac

npx phibac then runs the CLI installed in the project. Run every command from the folder that holds pb.config.ts: npx phibac init writes that file there, and npx phibac deploy and npx phibac generate read it from there.

Command What it does
npx phibac init --name <name> --origin <url> Creates an app and writes pb.config.ts.
npx phibac deploy Previews, then publishes the collections in pb.config.ts.
npx phibac generate [--out <file>] Writes TypeScript types for those collections.
npx phibac dev Runs a local server.
npx phibac mcp Connects an AI coding tool to the server's agent tools.

Options that work everywhere:

  • npx phibac --help (also -h or help) prints the list of commands and variables, and exits with 0.
  • npx phibac <command> --help (or -h) prints that command's usage and exits with 0, whatever else is on the line.
  • npx phibac --version (also -v or -V) prints the CLI's version.
  • npx phibac with no command prints the list of commands to the error output and exits with 2. An unknown command prints error: unknown command "<name>" and the list, and exits with 2.

Environment variables

Variable Used by Meaning
PB_BASE_URL every command The server to talk to. The default is http://localhost:8787, the local server; set it to https://phibac.com to use this server. A slash at the end is ignored. npx phibac dev does not pass it on to the local server.
PB_TOKEN init, deploy, native, mcp Your developer token, which starts with pbd_. Not needed for the local server, except by mcp: see below.
PB_SERVER_BIN dev The path of a pb-server program to run instead of the one installed with the CLI.
PB_RELEASES_URL dev Where to download pb-server from, when PB_SERVER_BIN is not set and no server package is installed.

A developer token is a secret key that lets the CLI create and change your apps and their schemas. Which one the CLI uses depends on the server it talks to:

  • The local server (PB_BASE_URL unset, or http://localhost:8787, http://127.0.0.1:8787 or http://[::1]:8787): init, deploy and native use the local server's own key, which npx phibac dev makes in ./.pb/developer-token in the folder you start it from. Run them from that folder. If the server is still starting, they wait up to about 10 seconds for it. Without the file they use PB_TOKEN; and when the local key may not change an app (one made with another account's token) and PB_TOKEN is set, they repeat that request once with PB_TOKEN.
  • Any other server: PB_TOKEN. Create a token on that server's account page, in its developer section (https://phibac.com/account/developer on this server). It is shown once. Keep it in the environment, not in a file you commit:
export PB_TOKEN=pbd_...

mcp always uses PB_TOKEN, for the local server too. A token works only on the server that made it. The CLI sends it only in the Authorization header, never in an address, and removes it from anything it prints.

The CLI itself reads no other variables. The demo apps' pb.config.ts files read PB_APP themselves, through process.env, to choose the app ID: a config file is TypeScript that runs in Node.js, so it can read any variable you set (see Put your app on the internet).

Exit codes and errors

Exit code Meaning
0 Success.
1 Failure: the server refused the request, could not be reached, or a file is missing or wrong.
2 Usage error: a required flag is missing, a flag is unknown, or the command does not take the words given.

Errors go to the error output, in one of these forms:

  • A usage error: error: <what is wrong> followed by the command's usage, such as error: --name is required.
  • An error from the server: error: <code>: <message>, then hint: <how to fix it>, and, when the server gives reasons, one per line after reasons:. The codes are explained in Errors and how to fix them.
  • Any other failure: error: <what went wrong and what to do>, such as error: No local developer key found. Start the local server first with npx phibac dev in this same folder, then run this again., error: PB_TOKEN is not set. Create a developer token in the developer section of your account page at https://server.example.com/account/developer, then run: export PB_TOKEN=pbd_... (for a server other than the local one) or error: could not reach the server at http://localhost:8787. ….

A mistake in pb.config.ts is an error that names the file, the collection and the field, before anything is sent to the server. pb.config.ts reference lists the rules.

init

npx phibac init --name "Notes" --origin http://localhost:5173

Creates an app owned by your developer account on the server, with one origin, and writes pb.config.ts in the current folder with the new app's ID and a commented example collection.

Flag Meaning
--name <name> Required. The app's name, which users see on the page that asks them to connect it. 1 to 100 bytes.
--origin <url> Optional. An origin the app's page is served from (scheme, host and optional port, no path), such as https://notes.example.com. Use https; plain http is accepted only on localhost, 127.0.0.1 and [::1], for development.

Needs a developer key: the local server's own, or PB_TOKEN for any other server (see Environment variables). It does nothing if pb.config.ts already exists in the folder: it stops with an error and changes nothing on the server. On success it prints:

Created app app_01M7E9YEJZZSYKAAB14AMBBJPR (Notes, origin http://localhost:5173).
Wrote pb.config.ts.
Next: define your collections in pb.config.ts (see the commented example), then run: phibac deploy

Leave --origin out for an app that is only a mobile app, and register that app with phibac native set. An app with no origin and no native app can be used only while you develop.

npx phibac init registers one origin. To register more, see Sign users in.

Fails with exit code 2 when a flag is missing or unknown, and with 1 when no developer key is found, the server cannot be reached, the server refuses the app (for example invalid_request for a bad origin or name, or unauthorized for a bad token), or the file cannot be written; in the last case the app was created and the error gives its ID.

native

npx phibac native set --ios A1B2C3D4E5.com.example.notes --android com.example.notes=14:6D:E9:...
npx phibac native show

Registers the iOS and Android apps that are the app in pb.config.ts, so that a phone hands a sign-in back to those apps and to no other. The server has this today; the mobile SDK that uses it is not released yet (see Apps on a phone).

Command Meaning
phibac native set Replaces the list of each platform you name. A platform you do not name is left as it is.
phibac native show Prints what is registered and the address a sign-in returns to.
Flag of set Meaning
--ios <team>.<bundle> An iOS app: your Apple team ID (10 capital letters and digits), a dot, and the app's bundle ID. May be repeated. --ios none clears the list.
--android <package>=<fingerprints> An Android app: its package name, =, and the SHA-256 fingerprints of the certificates it is signed with, separated by commas. A debug build, an upload key and the store's signing key each have their own. May be repeated. --android none clears the list.

Needs a developer key, as init does. Fails with exit code 2 when a value is not in one of these shapes, and with 1 when the server refuses it.

deploy

npx phibac deploy

Reads pb.config.ts, checks it, and publishes its collections to the server, for the app its app value names. It takes no flags.

  1. It checks the file. A mistake stops it with an error that names the collection and field; nothing is sent.
  2. It previews every collection (a dry run that publishes nothing) and prints one line per collection:
    • same (version 1.0, nothing to publish): the published schema already matches.
    • additive (will become version 1.1): an additive change, published as a new minor version, or a new collection or major version.
    • breaking, followed by the reasons, such as - field removed: color, and a line saying to set the collection's version one higher or undo the change.
    • failed (<code>), with the server's code, message and hint on the error output.
  3. If any collection is breaking or failed, it publishes nothing and exits with 1.
  4. Otherwise it publishes each additive collection, printing published <name> version <major>.<minor>, then Published 2 collections. (the number it published). When every collection is same, it prints Nothing to publish: every collection is already up to date.
Previewing 2 collections for app app_01M7E9YEJZZSYKAAB14AMBBJPR on http://localhost:8787
com.example.notes.comment  additive (will become version 1.0)
com.example.notes.note     additive (will become version 1.1)
published com.example.notes.comment version 1.0
published com.example.notes.note version 1.1
Published 2 collections.

If publishing fails part way, which needs an error after a successful preview, it lists on the error output the collections it published and the ones it did not, then the error, and exits with 1. Run it again: the collections already published show as same.

A pb.config.ts with no collections prints that there is nothing to publish and exits with 0. Needs a developer key, as init does. Change your schema safely explains additive and breaking changes.

generate

npx phibac generate

Writes TypeScript types for the collections in pb.config.ts, each at the major version (version) the file names, from the schemas published on the server. Publish first with npx phibac deploy.

Flag Meaning
--out <file> Where to write the types. The default is src/pb-types.ts. Missing folders are created and an existing file is overwritten.

Needs no token. On success it prints, for example:

Wrote src/pb-types.ts (2 collections: com.example.notes.comment@1, com.example.notes.note@1).

The file holds, for each collection, an interface named after the collection's name in PascalCase plus V and the major version (com.example.notes.note at version 1 is ComExampleNotesNoteV1), with each field's description as a comment and fields that are not required marked optional; and SCHEMA_MAJORS, the major version of each collection, to pass to connect({ schemaMajors }). Field types become string (string, datetime, fileRef, recordRef), number (number, integer), boolean, a union of the listed strings (enumOf) or unknown (json). Define your data shows a whole file.

Fails with exit code 1 when pb.config.ts is missing, wrong or has no collections, and when the server answers with an error, such as not_found for a collection or version that is not published.

dev

npx phibac dev

Runs a server on your computer for development and keeps running until you press Ctrl-C. It takes no flags. It starts the server with these settings, whatever your own values for them are:

  • PB_MODE=dev: development mode, with no limits on storage, requests or downloads.
  • PB_LOCAL_DEV=1: the local server makes its own developer key in ./.pb/developer-token before it starts answering, shows on the page what an email would have said instead of sending it (any email address works for signing up), and accepts connections only from this computer.
  • PB_DATA_DIR=./.pb: everything is kept in the folder ./.pb inside the current folder.
  • PB_PORT=8787 and PB_BASE_URL=http://localhost:8787: the server is at http://localhost:8787.

Your other environment variables are passed to the server as they are. When you have set PB_BASE_URL to another server for npx phibac deploy, it says that the local server uses its own address. It makes sure the .gitignore file in the current folder ignores the ./.pb folder: it adds a .pb/ line, or creates the file with that line, and prints one line when it does (or, if it cannot, a line asking you to add .pb/ to .gitignore yourself). Then it prints this line, followed by the server's own log:

Starting /full/path/to/pb-server (PB_MODE=dev, data in ./.pb, http://localhost:8787). Press Ctrl-C to stop.

Which server program it runs:

  • PB_SERVER_BIN set: the program at that path.
  • Otherwise the server package installed with the CLI for this computer, @phibac/server-<platform>-<processor> (darwin-arm64, darwin-x64, linux-x64, linux-arm64 or win32-x64). npm installs it with phibac as an optional dependency, only the one for your computer. Its version must be the CLI's; if it is not, or its program is missing, dev stops and says to reinstall.
  • Otherwise PB_RELEASES_URL set: it downloads the server release for the CLI's version from that address once, checks it against the SHA-256 checksum published next to it, keeps it in a cache folder under your home folder (~/.cache/), and runs it. The address must use https (http://localhost is allowed for tests). The release file is named after pb-server, the operating system (darwin, linux or windows) and the processor (amd64 or arm64). It refuses to run a download whose checksum is missing or different.
  • None of these: it stops, says why (no server package for this computer, or the package was skipped by installing with --omit=optional) and exits with 1.

Its exit code is the server's. When the server is stopped by a signal, it is 128 plus the signal's number. Develop on your own machine explains the local server, its data folder and how to start again with empty data.

mcp

npx phibac mcp

Connects an AI coding tool that runs its tools as a local command (over standard input and output) to the server's agent tools, at PB_BASE_URL/mcp. It takes no flags. It reads one JSON-RPC message per line from standard input, sends each to the server with your developer token, and writes each answer to standard output as one line. A line that is not JSON is answered with a JSON-RPC error. When the server refuses a message or cannot be reached, the answer is a JSON-RPC error whose message holds the server's code, message and hint, such as unauthorized: the developer token is invalid or revoked hint: create a new developer token on your account page; for a message without an ID (a notification), that error goes to the error output instead. It exits with 0 when its input closes.

Needs PB_TOKEN, for the local server too: it does not use ./.pb/developer-token, because the AI tool starts it from its own folder. Without PB_TOKEN it exits with 1 at once. You do not run it yourself: you tell the AI tool to start npx phibac mcp, with PB_BASE_URL and PB_TOKEN in its environment. Developer API and agent tools explains how, and what the tools can do.