mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Any work that can take noticeable time now runs under the UI's status line: a Reporter's Status with a label message, or a LoggedCmd step. The UI: - status lines are a stack: a Status or LoggedCmd inside another shows its own line, then the outer one is drawn again, where before it ended the outer one for good - a message (Info, Warn, Note, Say, data on Stdout/Stderr) clears the line, prints and draws it again below; an unended line holds it - a question (Ask, Confirm, Answer, Secret), the picker and ui.Terminal hold it until they're done - no status line starts once the run is interrupted, as nothing would clear it - the run log's path is read without the log's lock, as the status line reads it under outMu Covered, by site and label: - finder.target: finding_vm; Lima's limactl --version: checking_backend - bringUp's checks (seeds, instance, recordFolder, hostChecks, ssh, requirements) and a running VM's go-on (proxy, pins, mount check): checking_vm; startOnce after the agent: starting; the self-check's probes: checking_network; pinHostKeys: reading_host_keys - setUpVM (sync, ssh config, links, clone seed): setting_up_vm; each devcontainer command: running_script; makeMachine: creating; buildOnce: checking_image; paste's count and rm: reading_pasted - volumeOf's lookup (diskutil), for launch, adopt, move, ls and rm: looking_up_volume - vm.ListAll (devvm ls): reading_vms; devvm doctor's checks: doctor_checking - devvm agent import: agent_import_reading (walk, links, opencode), agent_store_saving (copy, marketplace git checks, tmutil); devvm agent save: agent_save_reading, agent_save_comparing, agent_store_saving - devvm stop (from its pins check on): checking_vm; a delete, an orphan's teardown and Lima's DeleteImage: deleting; devvm git-protect and clone on/off's .git work (leftBehind, mountFolder, unmountFolder): git_protecting; git-protect's re-read: finding_vm - devvm clone add: clone_reading, clone_adding; clone fetch: clone_fetching; planClone: clone_planning; the clone check before rm or a remake: clone_checking; history export and import: history_exporting, history_importing; a remake's home: saving_home, restoring_home - devvm upgrade's install: upgrade_installing; the shared tools' step back and .NET's downloads: resolving_tools; gc's caches: reading_space; the retention settings (daily and in gc): retaining Work that takes the terminal stays off: the shell, ssh-add's passphrase (checkAgent, Agent.Ensure, reloadAgent) and an agent's login. Tests and guard: - msg.Fake: OnStatus and Showing; its LoggedCmd shows its step - backendtest.Fake: OnCall - TestLaunchStatusLines: every backend call of a new, running and stopped VM's launch runs under a status line but the shell's and Running's (pid files) - TestSSHAddOffStatusLine: ssh-add, on the user's agent or devvm's, never runs under one; chflagsCalls fails a .git lock or unlock with none - the structure test's status-lines rule (statusSites, statusFree) - TestStatusLinesNest, TestMessagesClearTheStatusLine, TestQuestionsHoldTheStatusLine, TestSecretAndPickerHoldTheStatusLine, TestTerminalHoldsTheStatusLine, TestNoStatusLineOnceInterrupted, TestFakeStatus, TestAgentImportStatus, TestAgentSaveStatus, TestDoctorReport, TestProblems, TestList, TestListLooksUpVolumesOnce, TestVolumeOfCache, TestWithSDKDownloads, TestRetainStatus, TestSetCloneOn, TestTeardownLeavesNothing The rule is written in the cli skill (rule 14, checklist, review), the codebase-standards skill (Show what devvm waits for, its checklist line and rules.md's row), Contributing's CLI page (Status lines), its tests and structure pages, and the troubleshooting page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
93 lines
3.1 KiB
Go
93 lines
3.1 KiB
Go
package vm
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/devvmhq/devvm/internal/backend"
|
|
"github.com/devvmhq/devvm/internal/gitprotect"
|
|
"github.com/devvmhq/devvm/internal/msg"
|
|
"github.com/devvmhq/devvm/internal/netpolicy"
|
|
"github.com/devvmhq/devvm/internal/tools"
|
|
"github.com/devvmhq/devvm/internal/vmname"
|
|
)
|
|
|
|
// Listed is a project VM as devvm ls shows it. A field is "" when the VM's
|
|
// state doesn't record it (its creation didn't finish).
|
|
type Listed struct {
|
|
Name vmname.VM
|
|
Status string // as its backend reports it
|
|
Image string // its image: base, or its layers joined with +
|
|
Tools []string // its shared tools: node claude
|
|
From string // the container image its base started from (--from), if any
|
|
Git string // its .git protection: on, off, or clone for a --clone VM
|
|
Net string // its tier, or unenforced (netpolicy.Listed)
|
|
// Learning is since when it learns the hosts it reaches, on the
|
|
// internet tier; the zero time when it doesn't.
|
|
Learning time.Time
|
|
Backend string
|
|
Folder string
|
|
// FolderState is what's at Folder's path (Env.FolderOf): a VM whose
|
|
// folder is gone or not connected is deleted only by name, with
|
|
// devvm rm VM.
|
|
FolderState FolderState
|
|
// Links is how many links it has to other VMs' ports, as a client.
|
|
Links int
|
|
}
|
|
|
|
// ListAll is devvm ls's list: the project VMs every backend has (List),
|
|
// and the states it couldn't read, under a status line, as it runs each
|
|
// backend's list and looks up each VM's folder.
|
|
func ListAll(ctx context.Context, e *Env) ([]Listed, []Known, error) {
|
|
defer e.Status(msg.ReadingVMs())()
|
|
inv, err := ReadInventory(ctx, e.Dirs, e.Registry, AllBackends)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
ls, err := inv.List(ctx, e)
|
|
return ls, inv.Unreadable(), err
|
|
}
|
|
|
|
// List lists the project VMs the backends' lists have, sorted by name
|
|
// (ReadInventory, AllBackends): it fails as the inventory's Err does. A
|
|
// VM whose state can't be read is listed with its status alone, as one
|
|
// with no state is. Each VM's folder is e's (Env.FolderOf), so its run
|
|
// looks each mount's volume up once.
|
|
func (inv *Inventory) List(ctx context.Context, e *Env) ([]Listed, error) {
|
|
if err := inv.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
var out []Listed
|
|
for _, k := range inv.VMs {
|
|
if !k.Listed {
|
|
continue
|
|
}
|
|
l, err := e.listed(ctx, k)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out = append(out, l)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// listed is one VM's row, from its backend and its state: its status
|
|
// alone for a state that can't be read.
|
|
func (e *Env) listed(ctx context.Context, k Known) (Listed, error) {
|
|
in := k.Instance
|
|
l := Listed{Name: in.Name, Status: string(in.Status), Backend: k.Backend.Name(), FolderState: FolderThere}
|
|
st := k.State
|
|
if st == nil {
|
|
return l, nil
|
|
}
|
|
l.Image, l.Tools, l.Git, l.Folder = st.Image, tools.Names(st), gitprotect.Mode(st), st.Dir
|
|
l.FolderState, l.Links = e.FolderOf(ctx, st), len(linksOf(st).Links)
|
|
if l.Image != "" {
|
|
l.From = st.From
|
|
}
|
|
var err error
|
|
l.Net, err = netpolicy.Listed(ctx, k.Backend, st, in.Status == backend.StatusRunning)
|
|
l.Learning = netpolicy.LearningOf(st).Since
|
|
return l, err
|
|
}
|