Skip to content

Add local CLI backend support#137

Merged
simantak-dabhade merged 7 commits into
mainfrom
feat/cli-mvp
Jun 9, 2026
Merged

Add local CLI backend support#137
simantak-dabhade merged 7 commits into
mainfrom
feat/cli-mvp

Conversation

@pranavjana

@pranavjana pranavjana commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add local trusted backend routes for CLI dataset operations
  • add Convex internal helpers for owner-scoped dataset creation/listing/row reads
  • wire CLI routes to latest local-mode auth using the local BigSet user
  • fix release packaging so Adam's launcher can deploy Convex and start the standalone frontend

Notes

Verification

  • npm run build in backend/
  • make -f makefiles/Makefile build-release
  • launched the release zip through the Adam CLI with a fresh --home

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af84d35f-a183-4ddf-a3a1-aac2c33bce3c

📥 Commits

Reviewing files that changed from the base of the PR and between 046138e and 49a9753.

📒 Files selected for processing (1)
  • backend/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/index.ts

📝 Walkthrough

Walkthrough

This PR implements backend HTTP API routes for local trusted CLI access to dataset operations. It adds Zod-based request validation and a requireLocalCli guard that checks local-mode environment and admin-key presence. Three new internal Convex functions (createForOwnerInternal, listByOwnerInternal, getOwnedInternal) and one row-listing function enforce owner-scoped access. The CLI routes call these internal functions to list, create, fetch, and manage dataset populations. Build scripts are updated to reflect a new nested frontend directory structure.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as Local CLI
  participant Guard as requireLocalCli
  participant HTTP as HTTP Endpoint (POST /cli/datasets/:id/populate/start)
  participant Convex as Convex internal mutation (claim/start populate)
  participant Workflow as Populate Workflow Runner
  participant AbortReg as AbortRegistry

  CLI->>Guard: request to start populate
  Guard->>HTTP: allows request
  HTTP->>Convex: claim populate + create run record
  Convex->>Workflow: start populate workflow (returns runId)
  Workflow->>AbortReg: register running dataset -> runId
  HTTP->>CLI: HTTP 202 { runId }
Loading

Suggested reviewers

  • simantak-dabhade
  • hwennnn
  • manav-tf
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'Add local CLI backend support' accurately describes the main change: adding backend infrastructure (routes, internal helpers, auth wiring) to support local CLI operations.
Description check ✅ Passed The PR description comprehensively covers the changeset: local backend routes, Convex internal helpers, authentication wiring, and release packaging fixes, all present in the actual changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cli-mvp

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/src/index.ts`:
- Around line 1016-1022: When handling an orphaned CLI run where aborted is
false, also clear any lingering "updating" row statuses before marking the
dataset failed: call clearAllPendingUpdateStatus(dataset._id) immediately prior
to setDatasetPopulateStatus(dataset._id, "failed", ...). This mirrors the
protected /stop route behavior and prevents stale UI shimmer indicators; ensure
you reference the same dataset._id and maintain the reply.code(200).send({
success: true }) flow.

In `@cli/src/commands/rows.ts`:
- Around line 23-38: The run() method currently lets flags.csv silently override
flags.json; add an explicit conflict check right after parsing (after const {
args, flags } = await this.parse(RowsCommand)) that detects if both flags.csv
and flags.json are true and rejects the invocation by reporting a clear error
and exiting (use the command's error/exit helper or throw an Error) so callers
get deterministic behavior; reference the run() function, the parsed flags.csv
and flags.json, and RowsCommand when locating where to add this validation.

In `@cli/src/csv.ts`:
- Around line 3-9: csvEscape currently protects delimiters but not CSV formula
injection; update csvEscape to detect values whose text begins with =, +, -, or
@ and prepend a single quote (') to neutralize formulas before applying existing
escaping rules; ensure you handle existing leading apostrophes (do not
double-prefix) and keep the current behavior of wrapping and doubling internal
quotes when /[",\n\r]/ matches so quoting and delimiter-escaping still work for
the modified text.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bcaa4d2f-d78b-4e86-8a5d-0421bc528d5d

📥 Commits

Reviewing files that changed from the base of the PR and between 625866d and ceb70ee.

⛔ Files ignored due to path filters (1)
  • cli/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (22)
  • .gitignore
  • backend/src/env.ts
  • backend/src/index.ts
  • bigset-cli-mvp.excalidraw
  • cli/bin/run.js
  • cli/package.json
  • cli/src/client.ts
  • cli/src/commands/create.ts
  • cli/src/commands/export.ts
  • cli/src/commands/list.ts
  • cli/src/commands/populate.ts
  • cli/src/commands/rows.ts
  • cli/src/commands/status.ts
  • cli/src/commands/stop.ts
  • cli/src/config.ts
  • cli/src/csv.ts
  • cli/src/index.ts
  • cli/tsconfig.json
  • frontend/convex/datasetRows.ts
  • frontend/convex/datasets.ts
  • makefiles/Makefile
  • scripts/build-release.mjs

Comment thread backend/src/index.ts
Comment thread cli/src/commands/rows.ts Outdated
Comment thread cli/src/csv.ts Outdated

@MMeteorL MMeteorL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I'm super excited about the CLI here! For the current PR, there may be one blocker:

CLI populate can leave datasets stuck in building

Code: backend/src/index.ts:957-992

Reasoning: The CLI populate route calls beginDatasetPopulate before getModelConfig, populateWorkflow.createRun, and registerDataset. If model config lookup, keychain access, or run creation fails, the catch returns 502 but never transitions the dataset out of building. The protected /populate path has explicit rollback for run creation failure; the CLI path should mirror that cleanup and mark the dataset failed or restore the prior terminal state.

The following are not blockers, just some concerns for possible future deployment on server. These security issues need resolving before deployment:

Local mode fails open if PROD is missing

Code: backend/src/env.ts:21-24, backend/src/clerk-auth.ts:88-95, frontend/lib/app-mode.ts:1, frontend/proxy.ts:4

The PR makes PROD !== "1" mean local mode. In local mode, backend requireAuth unconditionally assigns local_user_default, the frontend skips Clerk, and proxy auth is disabled. Any production/preview/staging deployment that forgets PROD=1 becomes unauthenticated by default. Local mode should require an explicit opt-in like BIGSET_LOCAL_MODE=1, with production failing closed when auth env is absent.

Local CLI/setup endpoints are unauthenticated and exposed through host ports

Code: backend/src/index.ts:726-799, backend/src/index.ts:830-1045, backend/src/index.ts:79-89, docker-compose.dev.yml:25-26, docker-compose.dev.yml:132-136

Reasoning: /local-setup/* and /cli/datasets* rely only on env.IS_LOCAL_MODE; requireLocalCli does not verify a caller token. The backend and Convex ports are published without binding to 127.0.0.1, while Fastify listens on 0.0.0.0. A LAN-reachable local instance could allow another machine/process to list datasets/rows, trigger runs, stop runs, or overwrite local credentials with a valid attacker-controlled key. Add a per-launch bearer token or equivalent local secret for these routes, bind release/dev services to loopback, and avoid exposing Convex unauthenticated local identity broadly.

Comment thread backend/src/index.ts
});
if (!dataset) return reply.code(404).send({ error: "Dataset not found" });

const populateOutcome = await beginDatasetPopulate(dataset._id, ownerId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If model config lookup, keychain access, or run creation fails, the catch returns 502 but never transitions the dataset out of building.

@pranavjana

Copy link
Copy Markdown
Collaborator Author

@MMeteorL fixed the blocker in 49a9753.

The CLI populate route now tracks when it has successfully claimed the dataset as building. If anything after that claim fails before the background run is registered, like model config lookup, keychain/credential access, or workflow run creation, the catch block now marks the dataset as failed before returning 502. So the route either starts the run or releases the dataset out of building instead of leaving it stuck.

I left the local-mode/server hardening notes untouched for this PR since those are broader future deployment concerns and this PR is scoped to the local CLI MVP.

@MMeteorL

MMeteorL commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

LGTM! Please merge this if you think fit @simantak-dabhade

@simantak-dabhade simantak-dabhade left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@simantak-dabhade simantak-dabhade merged commit 5819118 into main Jun 9, 2026
3 checks passed
@simantak-dabhade simantak-dabhade deleted the feat/cli-mvp branch June 9, 2026 23:01
@simantak-dabhade

Copy link
Copy Markdown
Contributor

Thank ya so much for this @pranavjana and thanks for the review @MMeteorL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants