Files
magpie/internal/agent/cursorlocal_env_windows.go
T
yetone f77ef6106e agent: Cursor Private Inference is connected by its row's switch, as other agents are, with no command to run (mamba on Discord: 这个单独搞个启动命令和别的供应商格格不入啊) — its Open configuration's base URL and key are kept in the state.vscdb regular Cursor shares, and are regular Cursor's own override settings too, so magpie still writes nothing of Cursor's. It sets CURSOR_LOCAL_AGENT_BASE_URL (<gateway>/v1) and CURSOR_LOCAL_AGENT_API_KEY (magpie-cursor-local), which only this build reads, for the user: launchctl setenv on the Mac (apps opened from the Dock or Finder from then on have them), HKCU\Environment plus a WM_SETTINGCHANGE on Windows, ~/.config/environment.d/magpie-cursor-local.conf (from the next login) and systemctl --user set-environment on Linux; switched off, it clears them. magpie notes it in cursor-local.env in its config folder, which the row reads as connected, and sets them again whenever it serves the gateway (launchd forgets them at a restart; the port may have changed). The row has the provider field (magpie) and the connect switch; connecting says to quit the app and open it again, and that a base URL in Open configuration still comes first. The launch command stays as the square beside it, for a start from a shell. TestCursorLocalConnects (connect sets them, a serve sets them again, disconnect clears them, off a serve sets nothing) fails on the old code; cursor-local-launch.test.cjs now checks the switch connects it with no command copied (WebKit, en and zh); agy-launch passes. Not tried with the real app (not installed here), and launchctl/the registry are not touched under tests. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-05 00:18:22 +08:00

40 lines
1.1 KiB
Go

package agent
import (
"testing"
ptr "unsafe"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
)
// setUserEnv sets the variables in the user's environment in the registry,
// and tells Explorer, so an app opened from the Start menu from now on has
// them; nil removes them.
func setUserEnv(env map[string]string) error {
if testing.Testing() {
return nil
}
k, err := registry.OpenKey(registry.CURRENT_USER, `Environment`, registry.QUERY_VALUE|registry.SET_VALUE)
if err != nil {
return err
}
defer k.Close()
for _, n := range cursorLocalVars {
if v, ok := env[n]; ok {
err = k.SetStringValue(n, v)
} else if err = k.DeleteValue(n); err == registry.ErrNotExist {
err = nil
}
if err != nil {
return err
}
}
const hwndBroadcast, wmSettingChange, smtoAbortIfHung = 0xffff, 0x001A, 0x0002
what, _ := windows.UTF16PtrFromString("Environment")
var res uintptr
windows.NewLazySystemDLL("user32.dll").NewProc("SendMessageTimeoutW").Call(
hwndBroadcast, wmSettingChange, 0, uintptr(ptr.Pointer(what)), smtoAbortIfHung, 5000, uintptr(ptr.Pointer(&res)))
return nil
}