mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
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]>
57 lines
2.0 KiB
Go
57 lines
2.0 KiB
Go
package vm
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/devvmhq/devvm/internal/msg"
|
|
"github.com/devvmhq/devvm/internal/state"
|
|
)
|
|
|
|
// devvm cursor warns that Cursor's Agent will run in the VM unless Cursor's user settings on this
|
|
// machine set its route to always, and warns the same way when the file is missing or isn't JSON
|
|
// with comments; it never fails, and it never writes the file.
|
|
func TestCursorAgentWarning(t *testing.T) {
|
|
for name, tc := range map[string]struct {
|
|
settings string // "" for no file
|
|
warn bool
|
|
}{
|
|
"always": {"// mine\n{\n \"editor.fontSize\": 14,\n \"cursorAgentHost.remoteInferenceRoute\": \"always\",\n}\n", false},
|
|
"absent": {`{"editor.fontSize": 14}`, true},
|
|
"another value": {`{"cursorAgentHost.remoteInferenceRoute": "remote"}`, true},
|
|
"not a string": {`{"cursorAgentHost.remoteInferenceRoute": true}`, true},
|
|
"no file": {"", true},
|
|
"broken JSON": {`{"cursorAgentHost.remoteInferenceRoute": "always"`, true},
|
|
"not an object": {`["always"]`, true},
|
|
"too long": {`{"cursorAgentHost.remoteInferenceRoute": "always", "x": "` + strings.Repeat("x", cursorSettingsMax) + `"}`, true},
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
home := t.TempDir()
|
|
file := cursorUserSettings(home, filepath.Join(home, ".config"))
|
|
if tc.settings != "" {
|
|
if err := state.WriteFile(file, []byte(tc.settings)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
before, _ := os.ReadFile(file) //nolint:gosec // the test's own file
|
|
m, warn := cursorAgentWarning(home, filepath.Join(home, ".config"))
|
|
if warn != tc.warn {
|
|
t.Fatalf("warn %v, want %v", warn, tc.warn)
|
|
}
|
|
if warn && msg.NamesOf(m) != "cursor_agent_in_vm file="+file {
|
|
t.Errorf("the warning: %s", msg.NamesOf(m))
|
|
}
|
|
if after, _ := os.ReadFile(file); string(after) != string(before) { //nolint:gosec // the test's own file
|
|
t.Error("the settings file changed")
|
|
}
|
|
if tc.settings == "" {
|
|
if _, err := os.Stat(filepath.Dir(file)); err == nil {
|
|
t.Error("the settings folder was made")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|