Skip to content

Allow dev build to opt into production backend (per-account, at-your-own-risk) #376

Open

Description

@neuromechanist

Summary

The -dev pre-release CLI is currently hard-pinned to the dev backend at runtime, regardless of any per-account apiUrl stored in ~/.config/nemar/config.json. This is the right default (safety: dev builds shouldn't accidentally hit prod), but it leaves no opt-in path for users who knowingly want to test a dev CLI feature against production data.

Proposal: let an account stored under `nemar auth` opt into pointing a dev build at `api.nemar.org` (or another whitelisted prod URL), with explicit warnings and at the user's own risk.

Current behavior

`src/lib/api.ts:60-68`:

```ts
function getApiUrl(): string {
if (process.env.TEST_API_URL) return process.env.TEST_API_URL;
if (IS_DEV_BUILD) return DEFAULT_API_URL; // dev build always uses dev backend
const config = getConfig();
return config.apiUrl || DEFAULT_API_URL;
}
```

`IS_DEV_BUILD` is true when the compiled-in `DEFAULT_API_URL` points at a `*.workers.dev` host. Stored `apiUrl` is silently ignored.

Use cases

  • A user wants to validate a new dev-CLI flow (e.g. `dataset download`, `dataset get`) against a real production dataset that doesn't exist in dev D1.
  • A power user wants bleeding-edge client features but is comfortable that the dev CLI may fail or be incomplete.
  • Internal QA wants to dry-run a soon-to-ship CLI against prod before cutting the patch.

Proposed UX

Opt-in is per account, scoped under `nemar auth`:

```bash

Opt this account into prod from a dev build

nemar auth set-api-url https://api.nemar.org --allow-prod-on-dev

Or interactively:

nemar auth login --api-url https://api.nemar.org # prompts:

You are running a -dev build of nemar-cli. Pointing it at the

production backend (api.nemar.org) is opt-in and at your own risk:

- dev features may not exist on prod and will fail

- dev features may have different schemas than prod expects

- this account will not be auto-migrated when you switch builds

Continue? [y/N]

```

Visible at runtime:

```text
[nemar] dev build pointing at production backend (account: yahya)
[nemar] you opted in via 'auth set-api-url --allow-prod-on-dev'; switch back with 'auth set-api-url --reset'
```

Implementation sketch

  1. Add a per-account flag (e.g. `allowProdOnDev: boolean`) to the `Account` schema in `src/lib/config.ts`.
  2. In `src/lib/api.ts` `getApiUrl()`: when `IS_DEV_BUILD` is true, check the active account; if `allowProdOnDev` is set and the stored `apiUrl` is on a whitelist (`api.nemar.org`, the SCCN prod workers.dev host), honor the stored URL. Otherwise fall through to the dev default.
  3. Print a one-line banner each session when a dev build is hitting prod (similar to `printMaintenanceBanner`).
  4. New CLI surface:
    • `nemar auth set-api-url [--allow-prod-on-dev]`
    • `nemar auth set-api-url --reset` (clear back to default)
    • `nemar auth login --api-url ` (existing, but on dev build prompt the warning before storing)
  5. Block the legacy/sunset URLs (already in `LEGACY_API_URLS`) so the opt-in cannot be used to revive them.

Risks / safety

  • Schema drift: a dev CLI may send/expect fields that prod doesn't recognize. Failures are user-visible and recoverable; document that dev features may 4xx/5xx on prod.
  • Auth tokens: tokens are scoped per-backend, so a prod token in a dev account directory won't accidentally leak to dev. Confirm in implementation that the token store is keyed on `apiUrl` (already true).
  • Accidental opt-in: require an explicit `--allow-prod-on-dev` flag and a confirmation prompt; never auto-flip on plain `--api-url`.
  • Visibility: every dev-build → prod-backend session logs a banner so the user can't forget the state.

Acceptance

  • A user on a `-dev` CLI can run `nemar auth set-api-url https://api.nemar.org --allow-prod-on-dev` and have subsequent commands hit prod for that account only.
  • Other accounts on the same machine continue to hit dev (or whatever they're configured for).
  • Without the explicit flag, a dev CLI continues to ignore stored `apiUrl` and use the dev backend (current behavior, unchanged).
  • A banner prints on every command when the dev build is hitting prod.
  • Documented in `docs/getting-started/` and `docs/commands/auth.md` with an "at your own risk" callout.

Out of scope

  • Making prod-on-dev the default.
  • Cross-account global settings (it's per-account by design).
  • Pointing prod builds at dev (already supported via stored `apiUrl` on prod builds; not part of this).

Activity

  1. added
    feature
    on Apr 28, 2026
  2. added
    P3
    cli
    on Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3clifeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions