Files
6c36850251 feat(cursor): devvm cursor opens this folder's VM in the Cursor editor
devvm cursor is devvm code's twin for Cursor, the editor. It gets the
folder's VM ready as devvm host does, then runs
`cursor --remote ssh-remote+HOST DIR` in devvm's place, with the SSH
agent devvm started with. Without `cursor` on PATH it fails with
no_cursor_command, naming the host to connect to.

Cursor's Agent and your sign-in (from CJ's manual check with a real
login): recent Cursor runs Agent in the editor's server in the VM, which
holds your Cursor sign-in in memory only (no token on disk, in any
environment or command line) and calls Cursor from the VM. Cursor's
`cursorAgentHost.remoteInferenceRoute` is application-scoped, so it's
read only from the user settings on this machine; with it set to
"always", Agent's own requests go through the Cursor app here, while
the VM's server still talks to Cursor.

- vm: Code and Cursor share openRemote; vm.CursorCommand names the
  editor's command, apart from the CLI agent's agents.Cursor. After
  LookPath finds `cursor`, devvm reads Cursor's user settings on this
  machine (platform.AppSettingsDir: Application Support on macOS,
  $XDG_CONFIG_HOME or ~/.config on Linux) through safefile.Read, 1 MiB
  at most, read-only, as JSON with comments, and warns with
  cursor_agent_in_vm unless the route is "always". It never fails on
  the file.
- sync.sh: Cursor's ~/.cursor-server/data/Machine/settings.json gets VS
  Code's remote.autoForwardPorts, git.terminalAuthentication and
  github.gitAuthentication off, in one loop over both editors' files.
  devvm doesn't write the route there, since Cursor ignores it.
- structure: nameFree lets a literal that is an agent's name stand in
  one file, with its reason, and fails when it frees nothing.
- cli: cursor.go (--ssh-config, --here, --parent), registered beside
  code; cursor_failed, no_cursor_command, cursor_agent_in_vm and their
  doc links; ssh_host_info names Cursor too; the cli skill's judgment
  note: an editor's command is a bare verb named after the editor's.
- Tests: host_code.txtar (cursor, its full-name host, the missing
  command, the warning and no warning once the route is set),
  guest.txtar, TestCursorAgentWarning (always, absent, other values, no
  file, broken JSON, too long, a FIFO, the XDG path; never written),
  e2e network: devvm cursor passes the editor only the host and folder,
  a fake editor sign-in on this machine reaches neither the VM's home,
  its processes' environments nor the proxy's logs, and a Cursor login
  in the store reaches the CLI's methods while the agent store's are
  refused.
- Docs: SSH and editors (commands first; "Cursor's Agent": it runs in
  the VM with your sign-in, the user-settings line, what it doesn't
  cover, open only VMs you trust; if Tab doesn't work on the allowlist
  tier, devvm network allow api3.cursor.sh), the agents page's Cursor
  notes, Commands, attack vectors, design, the home page, CHANGELOG,
  generated CLI pages.

Reviewed adversarially before the push: the settings read (size, FIFOs,
links), the warning's wording and when it fires. Researched with PR
#44's design as reference only.

Co-authored-by: JB <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-13 00:05:36 -07:00

38 lines
1.1 KiB
Go

package cli
import (
"github.com/spf13/cobra"
"github.com/devvmhq/devvm/internal/msg"
"github.com/devvmhq/devvm/internal/vm"
)
// newCodeCmd is devvm code.
func newCodeCmd(a *app) *cobra.Command {
var include bool
cmd := &cobra.Command{
Use: "code",
Annotations: about{
docs: "using/ssh#vs-code-and-cursor", group: groupVM,
noJSON: "it opens VS Code",
}.annotations(),
Short: "Open this folder's VM in VS Code over Remote-SSH",
Long: "Get this folder's VM ready as devvm host does, then open its folder in VS Code over Remote-SSH, " +
"with VS Code's code command.",
Example: examples(
"devvm code", "open this folder's VM in VS Code",
"devvm code --ssh-config", "the same, adding devvm's Include line to ~/.ssh/config without asking",
),
Args: noArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return a.env(func(env *vm.Env) error {
env.AddInclude = include
return vm.Launch{Env: env}.Code(cmd.Context())
}, msg.CodeFailed)
},
}
addSSHConfigFlag(cmd.Flags(), &include)
addFolderFlags(cmd, a)
return cmd
}