mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Every list of the coding agents now derives from internal/agents' registry, one Def each, and Cursor's CLI (cursor-agent) is a fifth agent. The registry: - each agent's login command, login formats and capture on its Def; one message for every agent where each had its own - the agents' table, the README's list and the docs' history lists are generated from the registry (cli.DocBlocks, TestDocBlocks); scripts and Go tests take their lists from it too - each agent's own code lives in a file named for it; the structure test lets only an agent's own files choose by its name, following constants named after an agent - a VM remade by clone on/off keeps no agent's login files (agents.LoginFiles from every Def.Logins; Claude Code's .claude.json stays, as it is also history) Cursor's CLI: - `devvm --agents cursor`, `devvm agent login cursor`, history import and export of ~/.cursor/chats - the proxy captures its login at a GET endpoint, guards a shared host by path, and puts the login in only where the CLI sends it, bound to the CLI's 57 methods - account changes and the agent store are refused in a VM; Cursor's headers and trailers are scanned for tokens - e2e: Cursor's CLI in the network section, its poll behind the fake company proxy Docs: the agents' pages lead with commands, with a How it works page for the agents. Co-authored-by: JB <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
98 lines
3.3 KiB
Go
98 lines
3.3 KiB
Go
package vm
|
|
|
|
// opencode's own code in internal/vm: opencode 2 keeps its logins in its
|
|
// database, which reads its auth.json only as it's made, so devvm imports
|
|
// the store's logins into it with opencodeScript.
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"io/fs"
|
|
"strings"
|
|
|
|
"github.com/devvmhq/devvm/internal/agentlogin"
|
|
"github.com/devvmhq/devvm/internal/agents"
|
|
"github.com/devvmhq/devvm/internal/backend"
|
|
"github.com/devvmhq/devvm/internal/msg"
|
|
)
|
|
|
|
// opencodeScript is devvm's guest script that gives opencode 2 in the VM
|
|
// the store's opencode logins that changed, run by every launch's setup
|
|
// too (guest/sync.sh).
|
|
const opencodeScript = "opencode.sh"
|
|
|
|
// importOutMax is the most of opencodeScript's output devvm agent login
|
|
// reads: a few lines a provider.
|
|
const importOutMax = 1 << 20
|
|
|
|
// opencodeKeepsDB reports whether the agent keeps its logins in a database
|
|
// of its own, which devvm agent import reads with its auth export:
|
|
// opencode, from 2 on.
|
|
func opencodeKeepsDB(agent string) bool { return agent == agents.Opencode }
|
|
|
|
// opencodeSyncImport adds to a launch's setup the store's opencode logins
|
|
// as opencode auth import reads them, opencode-import.json, when kind is
|
|
// opencode's login and vmCopy the VM's copy of it.
|
|
func opencodeSyncImport(s *stage, kind string, vmCopy []byte) error {
|
|
if kind != agents.Opencode {
|
|
return nil
|
|
}
|
|
imp, err := agentlogin.OpencodeImport(vmCopy)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s.put("opencode-import.json", 0o600, imp)
|
|
return nil
|
|
}
|
|
|
|
// importLogins gives the VM's opencode, which keeps its logins in its
|
|
// database, the logins of vmCopy, the VM's copy of the store's
|
|
// (agentlogin.OpencodeImport), when the agent is opencode: with
|
|
// opencodeScript in a login shell (opencode on PATH), the logins on its
|
|
// input. devvm reads at most importOutMax bytes of what it prints, and
|
|
// stops it past that.
|
|
func (e AgentLogin) importLogins(ctx context.Context, t *target, agent string, vmCopy []byte) error {
|
|
if agent != agents.Opencode {
|
|
return nil
|
|
}
|
|
data, err := agentlogin.OpencodeImport(vmCopy)
|
|
if err != nil {
|
|
return msg.LoginCopyFailed(agents.Opencode, err.Error(), t.f.Name).Because(err)
|
|
}
|
|
script, err := fs.ReadFile(e.Assets, "guest/"+opencodeScript)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
run, cancel := context.WithCancel(ctx)
|
|
defer cancel()
|
|
log := e.vmLog()
|
|
out := &bounded{max: importOutMax, cancel: cancel}
|
|
argv := []string{"bash", "-lc", string(script), opencodeScript}
|
|
err = t.exec(run, argv, backend.ExecOpts{Stdin: bytes.NewReader(data), Stdout: io.MultiWriter(out, log), Stderr: log})
|
|
switch {
|
|
case out.over:
|
|
return msg.OpencodeImportTooMuch(t.f.Name)
|
|
case err == nil:
|
|
return nil
|
|
case ctx.Err() != nil:
|
|
return ctx.Err()
|
|
}
|
|
if failed := opencodeRefused(out.String()); len(failed) > 0 {
|
|
return backend.Logged(msg.OpencodeImportFailed(strings.Join(failed, ", "), t.f.Name))
|
|
}
|
|
return backend.Logged(msg.AgentKeyCopyFailed(agents.Opencode, t.f.Name))
|
|
}
|
|
|
|
// opencodeRefused is the providers opencodeScript's output names as
|
|
// refused by opencode's import, its "devvm-opencode-failed PROVIDER" lines.
|
|
func opencodeRefused(out string) []string {
|
|
var failed []string
|
|
for line := range strings.Lines(out) {
|
|
if p, ok := strings.CutPrefix(strings.TrimSpace(line), "devvm-opencode-failed "); ok && p != "" {
|
|
failed = append(failed, msg.Printable(p))
|
|
}
|
|
}
|
|
return failed
|
|
}
|