Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/dev-tabs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@concile/cli": patch
"@concile/vite": patch
---

`concile dev --run "<cmd>"` shows the backend and your app in separate tabs, so each one's output and URL stay apart. The app starts once the backend is up. The React + Vite starter now runs `concile dev --run vite`, and the `@concile/vite` plugin proxies to that backend instead of starting a second one. `concile init` in an existing app starts its own dev script next to the backend. Without a terminal, or with `CONCILE_TABS=0`, output stays as prefixed lines. The SQLite ExperimentalWarning no longer prints.
5 changes: 5 additions & 0 deletions .changeset/init-project-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@concile/cli": patch
---

`concile init` asks for a project name on one line, like create-convex, with an editable default. `.` uses the current folder when it is empty. It no longer lists other folders. The banner is redrawn in the brand style.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ You didn't have to write a websocket server. You didn't write a REST endpoint. Y
npx concile init
```

Run it in an empty folder to get a starter app, or inside the app you already have. It asks a couple of quick questions, shows every file it will add, and changes nothing until you say yes. Want a new folder? Run `npx concile init my-app`. Then:
Run it in an existing app, and it configures Concile there. Run it in an empty directory, and it prompts for a project name to set up a starter app. Type `.` at that prompt to use the current directory. It lists every file it will touch and waits for your confirmation before writing anything. Then start the dev environment:

```bash
npx concile dev
npm run dev
```

Got a starter app? Run `npm run dev` instead. It starts the app and the backend together. Open it in two browser tabs (http://localhost:5173 for React + Vite, http://localhost:3001 for Next.js). Type in one. It shows up in the other.
Your app and the backend boot together in separate terminal tabs. Open http://localhost:5173 for React + Vite, or http://localhost:3001 for Next.js, across two browser windows. Type a message in one window, and it appears in the other.

Adding Concile to an existing project? Run `npx concile dev --run "npm run dev"` to spin up your dev script alongside the backend. If you only need the backend running, use `npx concile dev`.

Need the flags for scripts or CI? Run `npx concile init --yes`, or see `npx concile init --help`.

Expand Down
4 changes: 4 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions docs/core-concepts/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,32 @@ concile dev
| `--storage-bucket <name>` | `CONCILE_STORAGE_BUCKET` env, else unset (filesystem) | Select the S3-compatible file-storage backend, see [File storage](/docs/core-concepts/file-storage) |
| `--storage-endpoint <url>` | `CONCILE_STORAGE_ENDPOINT` env, else unset | S3-compatible endpoint (MinIO, R2, …) |
| `--web <dir>` | unset | Serve a static web UI directory at the site root, alongside the API |
| `--run "<cmd>"` | unset | Start your frontend dev command next to the backend, see [Run your app alongside](#run-your-app-alongside) |
| `--no-ui` | unset | Plain output: no terminal dashboard and no `--run` tabs |

The database and storage settings fall back to the same environment variables under `dev` as under
`serve`: `CONCILE_DATABASE_URL`, `CONCILE_STORAGE_BUCKET`, and `CONCILE_STORAGE_ENDPOINT` (plus the
rest of the `CONCILE_STORAGE_*` family) all work, with the flag winning when both are set. Both
commands resolve storage through the same boot path.

### Run your app alongside

Pass `--run "<cmd>"` to launch your frontend dev server alongside the backend from a single command:

```bash
concile dev --run "npm run dev"
```

The app waits to launch until the backend starts listening, avoiding port conflicts. Concile also
exposes the backend URL to your app through `CONCILE_DEV_BACKEND`. In an interactive terminal, the
app and backend run in dedicated tabs. Press `j` and `k` to cycle through tabs, `r` to restart the
active process, and `q` to quit both. In non-interactive environments like CI, under coding agents,
or when piping stdout, the tab interface is disabled. Logs from the app stream inline with an `app
│` prefix. Pass `--no-ui` or set `CONCILE_TABS=0` to force this view in a regular terminal.

Both starter templates rely on this pattern. The React + Vite starter runs `concile dev --run vite`
inside `npm run dev`, while the Next.js starter runs `concile dev --run "next dev -p 3001"`.

### Admin key handling

`dev` reads `CONCILE_ADMIN_KEY` if set (blank/whitespace-only counts as unset, with a warning). If
Expand Down
4 changes: 2 additions & 2 deletions docs/deploy/local-dev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Here is a look at every flag `concile dev` accepts:
| `--database-url <url>` | unset | Takes a `postgres://` or `postgresql://` connection string. When this is set, concile uses Postgres instead of SQLite; see [Postgres](/docs/deploy/postgres) for more. It can also be read from `CONCILE_DATABASE_URL`, though the flag takes priority. |
| `--storage-bucket <name>` | unset | Selects the S3-compatible file storage backend (using a bucket name). If left unset, it uses local filesystem storage under `<data dir>/storage`. It can also be read from `CONCILE_STORAGE_BUCKET`. |
| `--storage-endpoint <url>` | unset | Sets an S3-compatible endpoint (like MinIO, R2, etc.), which only matters if you also use `--storage-bucket`. It can also be read from `CONCILE_STORAGE_ENDPOINT`. |
| `--run "<cmd>"` | unset | Starts your frontend dev command next to the backend, so one command runs both. For example `--run "next dev -p 3001"`. Its output shows with an `app │` prefix, and it stops when `concile dev` stops. The Next.js starter's `npm run dev` uses this. |
| `--no-ui` | unset | Turns off the full-screen terminal dashboard (Bun only) and prints plain lines. `--run` turns it off too. |
| `--run "<cmd>"` | unset | Starts your frontend dev command next to the backend, so one command runs both. For example `--run "next dev -p 3001"`. The app starts once the backend is up. In a terminal, each one gets its own tab: `j`/`k` switch, `r` restarts, `q` quits both. In CI, agents and pipes, or with `CONCILE_TABS=0`, the app's lines show with an `app │` prefix instead. Both starters' `npm run dev` use this. |
| `--no-ui` | unset | Turns off the full-screen terminal dashboard (Bun only) and the `--run` tabs, and prints plain lines. |

A CLI flag will always override its environment variable equivalent if both are set.

Expand Down
8 changes: 8 additions & 0 deletions docs/deploy/vite-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ That's the entire configuration. You do not need to add any options.
npx vite
```

<Callout type="info" title="Started with concile dev --run vite?">

If you run `concile dev --run vite`, the backend is already active in its own tab. The plugin reads
`CONCILE_DEV_BACKEND` and routes requests to that existing instance instead of booting a new one.
The React + Vite starter uses this setup out of the box.

</Callout>

The backend starts up right along with the dev server. You will see its log lines appear in the same
terminal, prefixed with `[concile]`. Open your app at the Vite URL, and you'll find the engine's
surfaces are there too, all on the very same origin:
Expand Down
14 changes: 8 additions & 6 deletions docs/get-started/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ npx concile init my-app
cd my-app
```

`init` creates the folder and a `concile/` directory with a sample `messages` table, query and
mutation. It also installs the packages. Already have an app? Run `npx concile init` inside it
instead. To see every option, run `npx concile init --help`.
`init` generates the project folder, sets up a `concile/` directory with a sample `messages` schema,
query, and mutation, and installs dependencies. In an empty folder, run `npx concile init` without a
name, and it prompts you for one. Type `.` to use that folder. Working in an existing project? Run
`npx concile init` directly in that repo. Run `npx concile init --help` to view all available flags.

</Step>

Expand Down Expand Up @@ -107,9 +108,10 @@ admin key → 3q2xN7vRkYw8pTzL5mA9cB1dE6fGhJ0u
The admin key is a fresh random value on each run (unless you set `CONCILE_ADMIN_KEY` yourself).
Yours will differ.

Did `init` give you a starter app? Run `npm run dev` instead. It starts the app and the backend
together. Then open it in two browser tabs: http://localhost:5173 for React + Vite,
http://localhost:3001 for Next.js.
If you generated a starter app with `init`, run `npm run dev`. This boots both your app and the
backend in separate terminal tabs. Use `j` and `k` to toggle between tabs, and hit `q` to shut down
both processes. Next, open your app across two browser windows: http://localhost:5173 for React +
Vite, or http://localhost:3001 for Next.js.

</Step>

Expand Down
6 changes: 4 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
"clean": "rm -rf dist .turbo"
},
"dependencies": {
"@clack/core": "^1.5.1",
"@clack/prompts": "^1.8.1",
"@concile/admin": "workspace:*",
"@concile/blobstore": "workspace:*",
"@concile/blobstore-fs": "workspace:*",
"@concile/blobstore-s3": "workspace:*",
"@concile/codegen": "workspace:*",
"@concile/component": "workspace:*",
"@concile/dashboard": "workspace:*",
"@concile/deploy": "workspace:*",
"@concile/docstore": "workspace:*",
"@concile/docstore-postgres": "workspace:*",
Expand All @@ -63,8 +65,8 @@
"@concile/values": "workspace:*",
"esbuild": "^0.27.0",
"magicast": "^0.5.5",
"ws": "^8.18.0",
"@concile/dashboard": "workspace:*"
"mprocs": "0.9.6",
"ws": "^8.18.0"
},
"devDependencies": {
"@electric-sql/pglite": "^0.2.17",
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/usr/bin/env node
import { runCli } from "./cli";

// node:sqlite prints an ExperimentalWarning on every start. It says nothing users can act on, so
// it is dropped; every other warning still shows.
const emitWarning = process.emitWarning.bind(process);
process.emitWarning = ((warning: string | Error, ...rest: unknown[]) => {
const message = typeof warning === "string" ? warning : warning.message;
const type = typeof rest[0] === "string" ? rest[0] : (rest[0] as { type?: string } | undefined)?.type;
if (type === "ExperimentalWarning" && message.includes("SQLite")) return;
return (emitWarning as (...a: unknown[]) => void)(warning, ...rest);
}) as typeof process.emitWarning;

runCli(process.argv.slice(2))
.then((code) => process.exit(code))
.catch((e) => {
Expand Down
14 changes: 13 additions & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { fleetCommand } from "./fleet";
import { objectstoreCommand } from "./objectstore";
import { loadEnvFiles } from "./env-files";
import { runAlongside } from "./run-alongside";
import { afterBackend, backendUrl, BACKEND_ENV, mprocsBinary, runInTabs, wantTabs } from "./dev-tabs";

function parseFlags(args: string[]): DevOptions {
const out: DevOptions = {};
Expand All @@ -46,6 +47,15 @@ function parseFlags(args: string[]): DevOptions {

export async function devCommand(args: string[]): Promise<number> {
const flags = parseFlags(args);
// --run in a real terminal: the backend and the app each get a tab. This process only hosts them.
if (flags.run && wantTabs({ noUi: flags.noUi, env: process.env, stdinTTY: Boolean(process.stdin.isTTY), stdoutTTY: Boolean(process.stdout.isTTY) })) {
const binary = mprocsBinary();
if (binary) {
const { port, ip } = resolveDevOptions(flags);
const devArgs = args.filter((a, i) => a !== "--run" && args[i - 1] !== "--run");
return runInTabs(binary, { devArgs, run: flags.run, cwd: process.cwd(), url: backendUrl(ip, port) });
}
}
// Before anything reads the environment: .env.local, then .env, never overriding a set variable.
loadEnvFiles(flags.functionsDir ? dirname(resolve(process.cwd(), flags.functionsDir)) : process.cwd());
const { functionsDir, projectRoot } = await resolveFunctionsDir(flags.functionsDir, process.cwd());
Expand Down Expand Up @@ -113,7 +123,7 @@ export async function devCommand(args: string[]): Promise<number> {

// --run: the frontend dev server, started after the backend is listening so it can connect at once.
if (flags.run) {
const app = runAlongside(flags.run, { cwd: projectRoot, write: (l) => process.stdout.write(l) });
const app = runAlongside(flags.run, { cwd: projectRoot, write: (l) => process.stdout.write(l), env: { [BACKEND_ENV]: backendUrl(opts.ip, opts.port) } });
void app.exited.then((code) => process.stdout.write(`app exited (code ${code}). The backend keeps running.\n`));
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"] as const) {
process.once(sig, () => {
Expand Down Expand Up @@ -311,6 +321,8 @@ export async function runCli(argv: string[]): Promise<number> {
}
case "dev":
return devCommand(rest);
case "__after-backend": // internal: the app tab of `dev --run`
return afterBackend(rest);
case "serve":
return serveCommand(rest);
case "deploy":
Expand Down
101 changes: 101 additions & 0 deletions packages/cli/src/dev-tabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* `concile dev --run "<cmd>"` in a real terminal: the backend and the app each get their own tab
* (mprocs, a terminal UI for running several processes). Each tab shows one process's own output,
* so it is always clear which URL belongs to which server. Without a terminal (CI, agents, pipes)
* the caller keeps the plain prefixed output instead.
*/
import { spawn } from "node:child_process";
import { createRequire } from "node:module";
import { mkdtempSync, writeFileSync } from "node:fs";
import { createConnection } from "node:net";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { isAgent } from "./init/flags";

/** Env var the app process gets: where the backend listens. @concile/vite proxies to it instead of starting its own. */
export const BACKEND_ENV = "CONCILE_DEV_BACKEND";

/** The mprocs binary, or null when the package or this platform's build is missing. */
export function mprocsBinary(): string | null {
try {
return createRequire(import.meta.url)("mprocs") as string;
} catch {
return null;
}
}

export function wantTabs(o: { noUi?: boolean; env: NodeJS.ProcessEnv; stdinTTY: boolean; stdoutTTY: boolean }): boolean {
if (o.noUi || o.env.CONCILE_TABS === "0" || o.env.CI) return false;
if (isAgent(o.env)) return false;
return o.stdinTTY && o.stdoutTTY;
}

/** The URL the app reaches the backend on. A wildcard bind is still reached through loopback. */
export function backendUrl(ip: string, port: number): string {
const host = ip === "0.0.0.0" || ip === "::" ? "127.0.0.1" : ip.includes(":") ? `[${ip}]` : ip;
return `http://${host}:${port}`;
}

/** @internal exported for tests. The mprocs config: the backend tab, then the app tab. */
export function tabsConfig(o: { devArgs: string[]; run: string; cwd: string; url: string }): object {
const bin = fileURLToPath(new URL("./bin.js", import.meta.url));
return {
proc_list_title: "concile dev",
procs: {
concile: { cmd: [process.execPath, bin, "dev", "--no-ui", ...o.devArgs], cwd: o.cwd },
// The app waits for the backend, so it can connect at once and never takes the backend's port.
app: { cmd: [process.execPath, bin, "__after-backend", o.url, o.run], cwd: o.cwd, env: { [BACKEND_ENV]: o.url } },
},
};
}

/** Runs both processes in tabs and returns when the user quits. */
export function runInTabs(binary: string, o: { devArgs: string[]; run: string; cwd: string; url: string }): Promise<number> {
const dir = mkdtempSync(join(tmpdir(), "concile-tabs-"));
const config = join(dir, "mprocs.yaml"); // JSON is valid YAML
writeFileSync(config, JSON.stringify(tabsConfig(o)));
return new Promise((resolve) => {
const child = spawn(binary, ["--config", config], { stdio: "inherit", cwd: o.cwd });
child.on("error", () => resolve(1));
child.on("exit", (code) => resolve(code ?? 0));
});
}

function portOpen(host: string, port: number): Promise<boolean> {
return new Promise((resolve) => {
const s = createConnection({ host, port });
s.once("connect", () => { s.destroy(); resolve(true); });
s.once("error", () => resolve(false));
});
}

/**
* `concile __after-backend <url> <cmd>` (internal, the app tab): waits until the backend
* listens, then runs the app command in this terminal. After a minute it starts the app anyway.
*/
export async function afterBackend(args: string[], opts: { timeoutMs?: number; write?: (s: string) => void } = {}): Promise<number> {
const [url, command] = args;
if (!url || !command) return 2;
const write = opts.write ?? ((s: string) => process.stdout.write(s));
const { hostname, port } = new URL(url);
const host = hostname.replace(/^\[|\]$/g, "");
const deadline = Date.now() + (opts.timeoutMs ?? 60_000);
let said = false;
while (!(await portOpen(host, Number(port)))) {
if (Date.now() > deadline) {
write(`The backend is not up yet. Starting the app anyway.\n`);
break;
}
if (!said) write(`Waiting for the backend on ${url}…\n`);
said = true;
await new Promise((r) => setTimeout(r, 200));
}
return new Promise((resolve) => {
const child = spawn(command, { shell: true, stdio: "inherit" });
const forward = (sig: NodeJS.Signals) => child.kill(sig);
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"] as const) process.on(sig, forward);
child.on("error", (e) => { write(`Could not start "${command}": ${e.message}\n`); resolve(1); });
child.on("exit", (code, signal) => resolve(code ?? (signal ? 1 : 0)));
});
}
Loading
Loading