Skip to content

feat: let a desktop app run and manage Levelrail in a local VM - #1882

Merged
thegdsks merged 3 commits into
mainfrom
feat/mac-local-mode
Dec 5, 2026
Merged

thegdsks merged 3 commits into
mainfrom
feat/mac-local-mode

Conversation

@thegdsks

@thegdsks thegdsks commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

What

Command line and server support for running Levelrail in a local macOS VM and driving it from a desktop app.

  • Managed VM: pinned Lima download after confirmation, port check and safe port changes, read only shared folders and Docker socket access (both off by default), recovery of an interrupted first boot, one VM operation at a time.
  • Sign in to the local VM, reach databases and deploy folders from the Mac.
  • Local mode detection in the dashboard and a locked out dialog variant for the VM.

Please review

Four new entries in test/execgate/allowlist.txt for files that import os/exec: two run /usr/sbin/lsof with fixed flags and a port, one only looks up limactl, one only stops the child that local mode already starts.

Checked

Local pre-commit and pre-push hooks passed. Before the last merge of main, go test -short passed on the changed Go packages (internal/api filtered to the changed test files).

Confidence Score: 1/5RetriggerView in Greptile

The PR is not ready to merge because old local tokens can gain database access, login renewal breaks after port changes, and concurrent port changes can overwrite each other.

Findings

  1. P1 Security Old tokens gain database access ▶
  2. P1 Port changes block login renewal ▶
  3. P1 Port changes overwrite each other ▶
  4. P2 Undo loses to pending save ▶
Fix with agent prompt
### Issue 1
internal/apiclient/local_login.go:175-176
`detachOtherPrincipals` removes the policy from tokens that remain valid. For an earlier local login whose credentials were lost or replaced, this also removes its `Deny write` rule. The token still has `write`, so it gains permission to delete and reconfigure databases until it expires. Revoke those tokens before detaching them, or leave their restrictive policy attached.

**How this was verified:** Local logins receive `write`, the detached policy supplies their database restriction, and database deletion accepts `write` when no attached policy denies it.

### Issue 2
cmd/levelrail-cli/vm_login.go:110-111
After a successful `vm login`, changing the dashboard port with `ports set`-or letting `vm start` replace an occupied port-leaves `this-mac` pointing at the old port. `previousLocalLogin` treats the new URL as a different server, so every later `vm login` refuses to refresh the saved connection. Allow a port change after checking the saved instance identity, and retain the previous token ID so it can still be revoked.

### Issue 3
internal/localmode/ports.go:327-329
Developer-mode port changes share one request file and one result file without a lock. If two terminals run `ports set` together, the second request can replace the first before the supervisor reads it. A later request also deletes the previous result. One caller can lose its answer, and a stale full port set can undo the other caller's change. Serialize the complete read, restart, and reply cycle per data directory.

### Issue 4
web/src/hooks/useAutoMode.ts:43-48
`apply` shows the applied mode before its server write finishes, so the user can click Undo while that write is pending. `undo` sends a separate delete without waiting for or canceling the earlier write. If the write finishes last, `apply` puts the mode back into the query cache and `useUiMode` restores it locally. Order these writes, or ignore an apply result after Undo has replaced that choice.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds CLI and server support for a desktop-managed local VM.

  • The CLI sets up and resumes a managed Levelrail VM on macOS.
  • The CLI can install the pinned Lima version for its managed VM.
  • VM users can opt in to read-only host folders.
  • VM users can opt in to host Docker access with isolation checks.
  • The CLI checks and changes ports for local and VM runs.
  • Local VM sign-in saves a limited token and pins its requests to the VM forward.
  • The dashboard can detect local VM mode and suggest a setup that fits the Mac.
  • The sign-in and recovery screens now explain when a user is in the local VM.
  • Developer mode can restart its child for checked port changes and forward its address as JSON.
  • Release automation promotes the latest platform release after publishing a kit release.

Reviews (2) · Last reviewed commit: "fix: use the client command name in the ..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 158 files, which is 58 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This organization's CodeRabbit subscription is cancelled. Resubscribe in Billing to continue reviews beyond the free-tier limit.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a61bdf85-6b1f-428b-bbad-2f4b53233d67
Commits

Reviewing files that changed from the base of the PR and between 1e37e45 and 83732b2.

Files ignored due to path filters: 1

  • sdk/typescript/src/generated/operations.ts is excluded by !**/generated/**
Files selected for processing: 158

  • .github/workflows/release-please.yml
  • .gitignore
  • VERSIONING.md
  • cmd/levelrail-cli/apps_exec_interactive.go
  • cmd/levelrail-cli/builder.go
  • cmd/levelrail-cli/builder_host.go
  • cmd/levelrail-cli/completion_dynamic_test.go
  • cmd/levelrail-cli/dev.go
  • cmd/levelrail-cli/dev_ports.go
  • cmd/levelrail-cli/doctor_client.go
  • cmd/levelrail-cli/experimental_gate_test.go
  • cmd/levelrail-cli/json_coverage_test.go
  • cmd/levelrail-cli/main.go
  • cmd/levelrail-cli/ports.go
  • cmd/levelrail-cli/ports_set.go
  • cmd/levelrail-cli/ports_test.go
  • cmd/levelrail-cli/resource_forward.go
  • cmd/levelrail-cli/session_status.go
  • cmd/levelrail-cli/system_address.go
  • cmd/levelrail-cli/system_mode.go
  • cmd/levelrail-cli/tokens_revoke.go
  • cmd/levelrail-cli/vm.go
  • cmd/levelrail-cli/vm_boot.go
  • cmd/levelrail-cli/vm_boot_test.go
  • cmd/levelrail-cli/vm_darwin.go
  • cmd/levelrail-cli/vm_docker.go
  • cmd/levelrail-cli/vm_docker_test.go
  • cmd/levelrail-cli/vm_lifecycle.go
  • cmd/levelrail-cli/vm_lifecycle_test.go
  • cmd/levelrail-cli/vm_lima.go
  • cmd/levelrail-cli/vm_lima_test.go
  • cmd/levelrail-cli/vm_login.go
  • cmd/levelrail-cli/vm_login_test.go
  • cmd/levelrail-cli/vm_loopback.go
  • cmd/levelrail-cli/vm_loopback_test.go
  • cmd/levelrail-cli/vm_ports.go
  • cmd/levelrail-cli/vm_share.go
  • cmd/levelrail-cli/vm_share_test.go
  • cmd/levelrail-cli/vm_test.go
  • docs/api-reference.md
  • docs/changelog.mdx
  • docs/cli-reference.md
  • docs/desktop-runtime.md
  • docs/local-development.md
  • docs/macos-runtime.md
  • docs/public/openapi.json
  • internal/api/audit.go
  • internal/api/code_login_settings.go
  • internal/api/database_audit.go
  • internal/api/database_tunnel.go
  • internal/api/database_tunnel_route_test.go
  • internal/api/iam_catalog.go
  • internal/api/local_login_grant_test.go
  • internal/api/local_mode.go
  • internal/api/login_options_test.go
  • internal/api/mode_suggestion.go
  • internal/api/mode_suggestion_test.go
  • internal/api/openapi_gen.go
  • internal/api/routes_database_access.go
  • internal/api/routes_docker_guard.go
  • internal/api/server_timing.go
  • internal/api/shutdown.go
  • internal/apiclient/app_tunnel.go
  • internal/apiclient/client.go
  • internal/apiclient/config.go
  • internal/apiclient/database_tunnel.go
  • internal/apiclient/local_forward.go
  • internal/apiclient/local_forward_test.go
  • internal/apiclient/local_login.go
  • internal/apiclient/local_pin.go
  • internal/apiclient/local_pin_test.go
  • internal/apiclient/mode_suggestion.go
  • internal/apiclient/repo_pointer.go
  • internal/apiclient/server_pin.go
  • internal/brand/cli_usage_test.go
  • internal/clitree/dispatched_gen.go
  • internal/clitree/tree.go
  • internal/dbauthz/dbauthz.go
  • internal/localmode/localmode.go
  • internal/localmode/localmode_test.go
  • internal/localmode/ports.go
  • internal/localmode/state.go
  • internal/modedetect/host.go
  • internal/modedetect/modedetect.go
  • internal/modedetect/modedetect_test.go
  • internal/serverready/local_holder.go
  • internal/serverready/local_holder_test.go
  • internal/vmruntime/boot.go
  • internal/vmruntime/filelock_unix.go
  • internal/vmruntime/filelock_windows.go
  • internal/vmruntime/guest/files/chrony-clock.conf
  • internal/vmruntime/guest/files/lr-isolation-check.sh.tmpl
  • internal/vmruntime/guest/guest.go
  • internal/vmruntime/guest/guest_test.go
  • internal/vmruntime/guest/provision_state.go
  • internal/vmruntime/identity_darwin.go
  • internal/vmruntime/identity_unix.go
  • internal/vmruntime/identity_windows.go
  • internal/vmruntime/lima/settings.go
  • internal/vmruntime/lima/template.go
  • internal/vmruntime/lima/template_test.go
  • internal/vmruntime/limadist/extract.go
  • internal/vmruntime/limadist/install.go
  • internal/vmruntime/limadist/install_test.go
  • internal/vmruntime/limadist/limadist.go
  • internal/vmruntime/settings.go
  • internal/vmruntime/settings_lock.go
  • internal/vmruntime/settings_lock_test.go
  • internal/vmruntime/share_identity.go
  • sdk/go/levelrail/operations_gen.go
  • sdk/python/levelrail/_operations.py
  • skills/levelrail/references/commands/INDEX.md
  • skills/levelrail/references/commands/dev.md
  • skills/levelrail/references/commands/ports.md
  • skills/levelrail/references/commands/system.md
  • skills/levelrail/references/commands/vm.md
  • test/execgate/allowlist.txt
  • web/src/components/InsecureConnectionBanner.tsx
  • web/src/components/LocalModeBanner.tsx
  • web/src/components/LockedOutDialog.tsx
  • web/src/components/LoginForm.tsx
  • web/src/components/LoginScreen.test.tsx
  • web/src/components/PasskeysCard.tsx
  • web/src/components/SignInFlow.test.tsx
  • web/src/components/SignInFlow.tsx
  • web/src/components/apps/NextStepBanner.tsx
  • web/src/components/dashboard/DashboardBanners.test.tsx
  • web/src/components/dashboard/NextSteps.tsx
  • web/src/components/mode/ModeCard.tsx
  • web/src/components/mode/ModePicker.tsx
  • web/src/components/mode/ModeSettingsCard.tsx
  • web/src/hooks/useApplyMode.ts
  • web/src/hooks/useAutoMode.ts
  • web/src/hooks/useDashboardNotices.ts
  • web/src/hooks/useUiMode.ts
  • web/src/lib/connection.test.ts
  • web/src/lib/connection.ts
  • web/src/lib/modeDetect.test.ts
  • web/src/lib/modeDetect.ts
  • web/src/lib/uiMode.ts
  • web/src/locales/de/dashboard.json
  • web/src/locales/en/common.json
  • web/src/locales/en/dashboard.json
  • web/src/locales/es/common.json
  • web/src/locales/es/dashboard.json
  • web/src/locales/fr/dashboard.json
  • web/src/locales/ja/common.json
  • web/src/locales/ja/dashboard.json
  • web/src/locales/pt-BR/common.json
  • web/src/locales/pt-BR/dashboard.json
  • web/src/locales/ru/common.json
  • web/src/locales/ru/dashboard.json
  • web/src/locales/zh-CN/common.json
  • web/src/locales/zh-CN/dashboard.json
  • web/src/queries/localMode.ts
  • web/src/queries/modeSuggestion.ts
  • web/src/queries/passkeys.ts
  • web/src/queries/signIn.ts

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added this to the v1.5.21 milestone Dec 5, 2026
@github-actions github-actions Bot added type/feature New capability or ergonomic improvement area/api internal/api area/cli cmd/levelrail-cli area/frontend web/ area/docs docs/, adr/ size/xl 500 or more lines changed, also used for every release PR labels Dec 5, 2026
@glinr-bot

glinr-bot Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

glinr-bot

A protected condition applies, so a person decides.

Gate Result Detail
not a draft pass
from this repository, not a fork pass
touches no protected path fail .github/workflows/release-please.yml
has no blocking label pass

No action taken. A person reviews this one.

Checks (shadow, nothing is enforced)

Group Check Result
required gitleaks pass
required CI required pending
advisory Web tests (4/4) pending
advisory Web tests (2/4) pending
advisory Web tests (1/4) pending
advisory Plan Go work pending
advisory Web tests (3/4) pending
advisory Lint pending
advisory Web (tsc, eslint) pending
advisory Greptile Review pending
advisory zizmor (workflow audit) pass
advisory Detect changed areas pass
advisory Dependency review pass
advisory Release web build pending
advisory commit-semver pass
advisory evaluate pending
advisory PR hygiene pass
skipped install-cli.ps1 (Windows) skipped
skipped install.sh (${{ matrix.image }}) skipped
skipped install-cli.sh (macOS) skipped
skipped Kit (vet, lint, test) skipped
skipped Terraform provider (vet, test) skipped
skipped auto-merge skipped
skipped Release pacing skipped
skipped regenerate skipped
skipped Mintlify Deployment skipped

Next steps:

  • Wait for required checks: CI required.

Comment on lines +175 to +176
if err := c.DetachPolicy(ctx, policyID, a.PrincipalType, a.PrincipalID); err != nil {
warnings = append(warnings, fmt.Sprintf("could not detach %s %s from the %s policy: %v", a.PrincipalType, a.PrincipalID, LocalLoginPolicyName, err))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 security Old tokens gain database access

detachOtherPrincipals removes the policy from tokens that remain valid. For an earlier local login whose credentials were lost or replaced, this also removes its Deny write rule. The token still has write, so it gains permission to delete and reconfigure databases until it expires. Revoke those tokens before detaching them, or leave their restrictive policy attached.

How this was verified: Local logins receive write, the detached policy supplies their database restriction, and database deletion accepts write when no attached policy denies it.

Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/apiclient/local_login.go
Line: 175-176

Comment:
**Old tokens gain database access**

`detachOtherPrincipals` removes the policy from tokens that remain valid. For an earlier local login whose credentials were lost or replaced, this also removes its `Deny write` rule. The token still has `write`, so it gains permission to delete and reconfigure databases until it expires. Revoke those tokens before detaching them, or leave their restrictive policy attached.

**How this was verified:** Local logins receive `write`, the detached policy supplies their database restriction, and database deletion accepts `write` when no attached policy denies it.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +110 to +111
if creds == (apiclient.Credentials{}) || strings.TrimRight(creds.APIURL, "/") == base {
return creds.TokenID, nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Port changes block login renewal

After a successful vm login, changing the dashboard port with ports set—or letting vm start replace an occupied port—leaves this-mac pointing at the old port. previousLocalLogin treats the new URL as a different server, so every later vm login refuses to refresh the saved connection. Allow a port change after checking the saved instance identity, and retain the previous token ID so it can still be revoked.

Prompt To Fix With AI
This is a comment left during a code review.
Path: cmd/levelrail-cli/vm_login.go
Line: 110-111

Comment:
**Port changes block login renewal**

After a successful `vm login`, changing the dashboard port with `ports set`—or letting `vm start` replace an occupied port—leaves `this-mac` pointing at the old port. `previousLocalLogin` treats the new URL as a different server, so every later `vm login` refuses to refresh the saved connection. Allow a port change after checking the saved instance identity, and retain the previous token ID so it can still be revoked.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +327 to +329
func WritePortRequest(dataDir string, r PortRequest) error {
_ = os.Remove(filepath.Join(dataDir, portResultName))
return writeJSON(filepath.Join(dataDir, portRequestName), r)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Port changes overwrite each other

Developer-mode port changes share one request file and one result file without a lock. If two terminals run ports set together, the second request can replace the first before the supervisor reads it. A later request also deletes the previous result. One caller can lose its answer, and a stale full port set can undo the other caller's change. Serialize the complete read, restart, and reply cycle per data directory.

Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/localmode/ports.go
Line: 327-329

Comment:
**Port changes overwrite each other**

Developer-mode port changes share one request file and one result file without a lock. If two terminals run `ports set` together, the second request can replace the first before the supervisor reads it. A later request also deletes the previous result. One caller can lose its answer, and a stale full port set can undo the other caller's change. Serialize the complete read, restart, and reply cycle per data directory.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +43 to +48
const saved = await putServerUiMode(mode).then(
() => true,
() => false,
)
if (saved)
queryClient.setQueryData(serverUiModeKey, { available: true, mode })

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Undo loses to pending save

apply shows the applied mode before its server write finishes, so the user can click Undo while that write is pending. undo sends a separate delete without waiting for or canceling the earlier write. If the write finishes last, apply puts the mode back into the query cache and useUiMode restores it locally. Order these writes, or ignore an apply result after Undo has replaced that choice.

Prompt To Fix With AI
This is a comment left during a code review.
Path: web/src/hooks/useAutoMode.ts
Line: 43-48

Comment:
**Undo loses to pending save**

`apply` shows the applied mode before its server write finishes, so the user can click Undo while that write is pending. `undo` sends a separate delete without waiting for or canceling the earlier write. If the write finishes last, `apply` puts the mode back into the query cache and `useUiMode` restores it locally. Order these writes, or ignore an apply result after Undo has replaced that choice.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@thegdsks
thegdsks merged commit 10c4f45 into main Dec 5, 2026
46 checks passed
@thegdsks
thegdsks deleted the feat/mac-local-mode branch December 5, 2026 04:19
@glinr-bot glinr-bot Bot mentioned this pull request Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api internal/api area/cli cmd/levelrail-cli area/docs docs/, adr/ area/frontend web/ size/xl 500 or more lines changed, also used for every release PR type/feature New capability or ergonomic improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant