Files
w3cjandClaude Opus 5.5 6965efcc0a fix(vm): devvm agent login claude --setup-token shows Claude Code's address (#57)
An agent's login in the VM ran with devvm's own writers as its output,
so os/exec gave limactl shell pipes, Lima added no ssh -t, and claude
setup-token, which draws full-screen, showed nothing and waited.

When devvm's stdin and stdout are terminals and both output streams are
files, the login now gets stdout and stderr as the files they are
(ui.Terminal, set by cli as vm.Env.Terminal), so Lima gives it a
terminal in the VM, as devvm's shell has. Without a terminal it keeps
pipes, and --setup-token warns first (setup_token_no_terminal). Its
output reaches devvm's output alone, never the run log, as before. On a
terminal, Ctrl-C goes to the login in the VM, which ends, and devvm
says the login ended or saved nothing.

- internal/ui: Terminal, over Files, never a half pair; TestTerminal.
- internal/vm: Env.Terminal; AgentLogin.loginOpts; the warning; why an
  interrupted login's cleanup stays as endLogin's backstop; endLogin's
  comment for a login on a terminal; TestAgentLoginTerminal
  (fails without the fix).
- internal/backend: ExecOpts says a terminal's files pass on as they
  are; Lima's TestExecStreamsAsGiven.
- internal/cli: vmEnv sets Terminal; agent_login.txtar checks the
  warning.
- locales/en.toml, internal/msg: setup_token_no_terminal.
- tests/e2e: OnTTY, out of TTYRun; network's check that
  devvm agent login claude --setup-token on a terminal shows the
  address, waiting for its devvm to end before the next login.
- Docs: internals/network.md, using/coding-agents.md,
  contributing/extending.md and tests.md; CHANGELOG Fixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 15:32:47 -07:00

60 lines
1.7 KiB
Go

//go:build e2e
package e2e
import (
"io"
"os"
"regexp"
"runtime"
"time"
)
// TTYRun runs args in dir on a terminal of its own (macOS's script,
// Python's pty on Linux, where script isn't always installed), input
// typed into it, as a question in a terminal needs. Its output is the
// terminal's. input is typed once the question ([y/N] or [Y/n]) shows,
// within 30 s, and the input stays open a moment after, as the end of
// input in a terminal is an answer of its own.
func TTYRun(s *S, dir, input string, args ...string) (Res, error) {
var at int64
if st, err := os.Stat(s.sb.logFile()); err == nil {
at = st.Size()
}
return s.Run(Cmd{Args: OnTTY(args...), Dir: dir, Input: &typist{log: s.sb.logFile(), at: at, input: input + "\n"}})
}
// OnTTY is args run on a terminal of their own: macOS's script, or
// Python's pty on Linux, where script isn't always installed.
func OnTTY(args ...string) []string {
if runtime.GOOS != "darwin" {
return append([]string{"python3", "-c", "import os, pty, sys; sys.exit(os.waitstatus_to_exitcode(pty.spawn(sys.argv[1:])))"}, args...)
}
return append([]string{"script", "-q", "/dev/null"}, args...)
}
// typist is a terminal's input: its answer once the check's log, past
// at, shows a question, then nothing for 3 s, then its end.
type typist struct {
log string
at int64
input string
typed bool
}
func (t *typist) Read(p []byte) (int, error) {
if t.typed {
time.Sleep(3 * time.Second)
return 0, io.EOF
}
question := regexp.MustCompile(`\[(y/N|Y/n)\]`)
for range 150 {
if b, err := os.ReadFile(t.log); err == nil && int64(len(b)) > t.at && question.Match(b[t.at:]) {
break
}
time.Sleep(200 * time.Millisecond)
}
t.typed = true
return copy(p, t.input), nil
}