mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
devvm takes no IMAGE word any more than any other: in a terminal a new VM's toolchains, coding agents and layers are checked in one picker, under three headings, before the network-policy question; --tools, --agents and --layers (each an exact list, or none) skip it, and a part left out takes its default: the detected toolchains, devvm setup's agents, no layers (a devcontainer.json's features still count). Without a terminal, or with --no-input, the VM gets the defaults and new_vm_gets says so in one line. devvm setup --agents (and its first-run question) chooses new VMs' agents. devvm tools in a terminal opens the same picker for the VM, its layers fixed, and turns the changes into tools add and rm. An image is base and layers only: tools are the VM's tool_names state key. build, rebuild and images rm refuse a shared tool (tool_not_layer), and devvm build builds no tool images. devvm ls gains a TOOLS column and --json tools. gc's --tools is --tool-images, so --tools has one meaning. Gone: image.Reserved, checkWord's image half (devvm WORD is no_command or no_command_like, did-you-mean over commands, msg.Closest), the lacks path in internal/vm/existing.go, and the messages vm_lacks_tools, vm_lacks_layer, layer_is_command, layer_name_command, no_image_for, no_command_or_image*, tools_not_images, tools_not_images_rm, detected, vm_is_now (vm_tools_now), secret_with_image (secret_with_claude). New: ui.Pick takes headed sections with fixed rows, ui.CanPick, vm.PickPart/PickRow/AgentsChoice/CheckPart (internal/vm/parts.go), state.KeyToolNames, state.ReadAgents/WriteAgents, paths.Dirs.Agents, project.DetectFiles. Image keys are unchanged in form: images never held tools; docker.sh's and nix.sh's comments changed, so those layers rebuild. Docs: the home page's quick start steps, diagram (sandbox.svg), cards and FAQ; README; getting started; using (images' What a new VM gets, coding agents' Running an agent, settings' agents); internals; contributing; the cli skill; AGENTS.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
172 lines
5.7 KiB
Go
172 lines
5.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/w3cj/devvm/internal/image"
|
|
"github.com/w3cj/devvm/internal/msg"
|
|
"github.com/w3cj/devvm/internal/tools"
|
|
"github.com/w3cj/devvm/internal/ui"
|
|
"github.com/w3cj/devvm/internal/vm"
|
|
)
|
|
|
|
// newToolsCmd is devvm tools: this folder's VM's shared tools, and add,
|
|
// rm and update, which change them.
|
|
func newToolsCmd(u *ui.UI) *cobra.Command {
|
|
var asJSON bool
|
|
cmd := &cobra.Command{
|
|
Use: "tools",
|
|
Short: "Show or choose this folder's VM's shared tools",
|
|
Long: "In a terminal, choose the toolchains and coding agents of this folder's VM in a list, which shows its layers too, then open a shell in it. " +
|
|
"Without a terminal, or with --json, show its shared tools, each with its version and any newer version in devvm's tools lock, " +
|
|
"which changes nothing, starts no VM and doesn't go online.",
|
|
Example: examples(
|
|
"devvm tools", "choose the VM's shared tools, or show them without a terminal",
|
|
"devvm tools add python claude", "add python and Claude Code to the VM",
|
|
"devvm tools update", "move the VM to the newest versions",
|
|
),
|
|
Args: noArgs,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
if !asJSON && u.CanPick() {
|
|
withEnv(u, func(env *vm.Env) error { return vm.Tools{Env: env}.Pick(cmd.Context(), vm.Options{}) }, msg.UpFailed)
|
|
return nil
|
|
}
|
|
var ts []tools.VMTool
|
|
withEnv(u, func(env *vm.Env) error {
|
|
var err error
|
|
ts, err = vm.Tools{Env: env}.List(cmd.Context())
|
|
return err
|
|
}, msg.ToolsFailed)
|
|
if asJSON {
|
|
return printJSON(u, toolsJSON(ts))
|
|
}
|
|
return writeTools(u.Table(), ts)
|
|
},
|
|
}
|
|
jsonFlag(cmd, &asJSON)
|
|
cmd.AddCommand(newToolsAddCmd(u), newToolsRmCmd(u), newToolsUpdateCmd(u))
|
|
return cmd
|
|
}
|
|
|
|
// toolsOutput is devvm tools --json: the VM's shared tools, each with the
|
|
// newer version the tools lock has, when it has one, and whether that one
|
|
// is built.
|
|
type toolsOutput struct {
|
|
Tools []vmToolJSON `json:"tools"`
|
|
}
|
|
|
|
type vmToolJSON struct {
|
|
Tool string `json:"tool"`
|
|
Version string `json:"version"`
|
|
Newer string `json:"newer,omitempty"`
|
|
Built *bool `json:"newer_built,omitempty"`
|
|
}
|
|
|
|
func toolsJSON(ts []tools.VMTool) toolsOutput {
|
|
out := toolsOutput{Tools: make([]vmToolJSON, 0, len(ts))}
|
|
for _, t := range ts {
|
|
j := vmToolJSON{Tool: t.Tool, Version: t.Version, Newer: t.Newer}
|
|
if t.Newer != "" {
|
|
j.Built = &t.Built
|
|
}
|
|
out.Tools = append(out.Tools, j)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// writeTools writes a VM's tools as a table, a header first.
|
|
func writeTools(tab *ui.Table, ts []tools.VMTool) error {
|
|
tab.Header("TOOL", "VERSION", "NEWER", "BUILT")
|
|
for _, t := range ts {
|
|
built := ""
|
|
if t.Newer != "" {
|
|
built = "no"
|
|
if t.Built {
|
|
built = "yes"
|
|
}
|
|
}
|
|
tab.Row(cell(t.Tool), cell(t.Version), cell(t.Newer), cell(built))
|
|
}
|
|
return tab.Flush()
|
|
}
|
|
|
|
func newToolsAddCmd(u *ui.UI) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "add TOOL...",
|
|
Short: "Add shared tools to this folder's VM, then open a shell in it",
|
|
Long: "Add shared tools to this folder's VM, then open a shell in it. " +
|
|
"TOOL is node, python, rust, go, claude, codex or opencode, each a separate word. " +
|
|
"devvm builds any of them that aren't built, and for a new agent in a running VM it asks before restarting the VM.",
|
|
Example: examples(
|
|
"devvm tools add claude", "add Claude Code to the VM",
|
|
"devvm tools add python codex", "add python and Codex",
|
|
),
|
|
Args: toolNames("add"),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
withEnv(u, func(env *vm.Env) error { return vm.Tools{Env: env}.Add(cmd.Context(), vm.Options{}, args) }, msg.UpFailed)
|
|
return nil
|
|
},
|
|
ValidArgsFunction: completeToolNames,
|
|
}
|
|
}
|
|
|
|
func newToolsRmCmd(u *ui.UI) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "rm TOOL...",
|
|
Short: "Take shared tools out of this folder's VM, then open a shell in it",
|
|
Long: "Take shared tools out of this folder's VM, each TOOL a separate word, then open a shell in it. " +
|
|
"What the VM installed itself stays.",
|
|
Example: examples(
|
|
"devvm tools rm python", "take python out of the VM",
|
|
"devvm tools rm python claude", "take out python and Claude Code",
|
|
),
|
|
Args: toolNames("rm"),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
withEnv(u, func(env *vm.Env) error { return vm.Tools{Env: env}.Remove(cmd.Context(), vm.Options{}, args) }, msg.UpFailed)
|
|
return nil
|
|
},
|
|
ValidArgsFunction: completeToolNames,
|
|
}
|
|
}
|
|
|
|
func newToolsUpdateCmd(u *ui.UI) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "update",
|
|
Short: "Move this folder's VM to the newest shared tools, then open a shell in it",
|
|
Long: "Check for newer versions of the shared tools, build them, and move this folder's VM to them, " +
|
|
"then open a shell in it. Nothing in the VM's disk changes, because its tools are mounted.",
|
|
Example: examples(
|
|
"devvm tools update", "move the VM to the newest shared tools",
|
|
),
|
|
Args: noArgs,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
withEnv(u, func(env *vm.Env) error { return vm.Tools{Env: env}.Update(cmd.Context(), vm.Options{}) }, msg.UpFailed)
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
// toolNames takes one or more TOOLs, each a word of its own: one joined
|
|
// with + or a comma is refused, naming sub, the devvm tools command (add,
|
|
// rm). add takes only shared tools' names.
|
|
func toolNames(sub string) cobra.PositionalArgs {
|
|
return func(cmd *cobra.Command, args []string) error {
|
|
if err := minArgs(1)(cmd, args); err != nil {
|
|
return err
|
|
}
|
|
names := slices.Concat(image.Toolchains, image.Agents)
|
|
for _, a := range args {
|
|
if strings.ContainsAny(a, "+,") {
|
|
return msg.ToolsJoined(sub, a)
|
|
}
|
|
if sub == "add" && !slices.Contains(names, a) {
|
|
return msg.UnknownTool(a, strings.Join(names, " "))
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|