Files
w3cjandClaude Opus 5.5 90694a414f feat(agent): devvm agent import follows links out of an agent's folder when allowed
A link out of an agent's folder, such as a dotfiles repo's link into
~/.claude, was always left out. Now it's copied when you allow it:
config.toml's follow-links names folders whose links devvm follows
without asking, and otherwise devvm names each link and its target and
asks, a question --follow-links answers. Without a terminal and the
flag, links out are left out with a warning naming --follow-links.

- The store gets copies only: a linked file as a file, a linked folder
  as a folder of files; the next import replaces them, a folder that
  became a file included, and prunes them once the link is gone.
- Each link is resolved one name at a time (linkHops), then read through
  its allowed folder as a safefile.Root opened one folder at a time from
  / (openPhysical); a link inside is read only to a file in that root.
- Always refused: the home folder or a folder holding it, devvm's config,
  data and Lima folders, ~/.ssh, ~/.gnupg, ~/.aws, ~/Library/Keychains,
  ~/.config/devvm, ~/.netrc, ~/.config/gh, ~/.docker, ~/.kube, and every
  agent's logins and history, compared by name and identity (isIn); a
  follow-links folder in or holding one fails the import.
- A target in a VM's project folder warns, naming the VM; a chain through
  a link in a VM's folder to a place outside it is refused.
- Bounds: devvm agent save's, 20,000 entries, 128 MiB and 16 MiB a file,
  across one import.
- A settings file must link to a file and a settings folder to a folder.

Messages: agent_import_link_not_followed, agent_import_link_refused,
agent_import_link_too_big, agent_import_follow, agent_import_link,
agent_import_link_followed, agent_import_link_project,
agent_import_link_via_vm, agent_import_root_refused,
follow_links_invalid.

Tests: TestAgentImportFollowsLinks, TestAgentImportNestedLinks,
TestAgentImportRefusedPlaces, TestAgentImportRefusedRoots,
TestAgentImportProjectFolderLinks, TestAgentImportLinkThroughProject,
TestAgentImportRefusedOtherCase, TestAgentImportLinkBounds,
TestLinkSourceGrown, TestAgentImportLinkKinds, TestAgentImportLinkPrune,
TestAgentImportLinkedAgentFolder, TestLinkHops, TestOpenPhysical,
TestFollowLinks; testscript agent_import_links; e2e project section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-12 20:47:48 -07:00

105 lines
4.6 KiB
Go

package cli
import (
"github.com/spf13/cobra"
"github.com/devvmhq/devvm/internal/image"
"github.com/devvmhq/devvm/internal/msg"
"github.com/devvmhq/devvm/internal/vm"
)
// newAgentCmd is devvm agent: devvm's store of the agents' settings and
// logins, and agent import, which fills it from this machine.
func newAgentCmd(a *app) *cobra.Command {
cmd := &cobra.Command{
Use: "agent",
Annotations: about{
docs: "using/coding-agents#devvms-agent-store", group: groupMachine,
noJSON: "it prints its help",
}.annotations(),
Short: "Fill devvm's store of the agents' settings and logins that every VM gets",
Long: "devvm keeps the coding agents' settings in ~/.config/devvm/agents and their logins in ~/.local/share/devvm/logins, " +
"and every VM with an agent gets them from there, never from the agents' own files in your home folder. " +
"devvm agent login saves a login made in this folder's VM, devvm agent import copies those files into the store once, and devvm agent save copies a VM's settings into it.",
Example: examples(
"devvm agent login codex", "log Codex in, in this folder's VM, for every VM",
"devvm agent import", "copy every agent's settings and logins from this machine",
"devvm agent import codex", "copy only Codex's",
"devvm agent save", "copy the settings of this folder's VM's agents, after showing what changed",
),
Args: noArgs,
RunE: func(cmd *cobra.Command, _ []string) error { return cmd.Help() },
}
cmd.AddCommand(newAgentImportCmd(a), newAgentLoginCmd(a), newAgentSaveCmd(a))
return cmd
}
// newAgentSaveCmd is devvm agent save [AGENT...].
func newAgentSaveCmd(a *app) *cobra.Command {
cmd := &cobra.Command{
Use: "save [AGENT...]",
Annotations: about{
docs: "using/coding-agents#saving-a-vms-settings",
noJSON: "it shows a diff, asks, then copies files into devvm's store",
}.annotations(),
Short: "Copy the agents' settings from this folder's VM into devvm's store",
Long: "Copy the settings of AGENT, " + orList(image.Agents) + ", or of every agent this folder's VM has, from the VM into devvm's store, " +
"so every VM with the agent gets them, never its logins or history. " +
"It shows what changed and asks first, so it runs only in a terminal without --no-input, and devvm starts a stopped VM for it.",
Example: examples(
"devvm agent save", "show what changed in every agent's settings, then save them",
"devvm agent save claude", "save only Claude Code's",
),
Args: minArgs(0),
ValidArgs: image.Agents,
RunE: func(cmd *cobra.Command, args []string) error {
return a.env(func(env *vm.Env) error {
return vm.AgentSave{Env: env}.Run(cmd.Context(), args)
}, msg.AgentSaveFailed)
},
}
addFolderFlags(cmd, a)
return cmd
}
// newAgentImportCmd is devvm agent import [AGENT...] [--force]
// [--follow-links].
func newAgentImportCmd(a *app) *cobra.Command {
var force, followLinks bool
cmd := &cobra.Command{
Use: "import [AGENT...]",
Annotations: about{
docs: "using/coding-agents#importing-from-this-machine",
noJSON: "it copies files into devvm's store",
}.annotations(),
Short: "Copy the agents' settings and logins from this machine into devvm's store",
Long: "Copy the settings and logins of AGENT, " + orList(image.Agents) + ", or of every agent, from your home folder into devvm's store, never their history. " +
"It copies what a link out of an agent's folder leads to only from a folder that config.toml's follow-links names, or after naming the link and asking, which --follow-links answers. " +
"It asks before replacing what the store has.",
Example: examples(
"devvm agent import", "copy every agent's settings and logins, asking before replacing the store's",
"devvm agent import claude codex", "copy only Claude Code's and Codex's",
"devvm agent import --force", "replace the store's without asking, as a script must",
"devvm agent import --follow-links", "copy what links out of the agents' folders lead to as well, such as into a dotfiles repo",
),
Args: minArgs(0),
ValidArgs: image.Agents,
RunE: func(cmd *cobra.Command, args []string) error {
d, err := a.dirs()
if err != nil {
return failed(err, msg.AgentImportFailed)
}
store, err := a.secrets()
if err != nil {
return failed(err, msg.AgentImportFailed)
}
im := vm.AgentImport{Dirs: d, Secrets: store, Reporter: a.u, FollowLinks: followLinks}
return failed(im.Run(cmd.Context(), args, force), msg.AgentImportFailed)
},
}
addForceFlag(cmd.Flags(), &force)
cmd.Flags().BoolVar(&followLinks, "follow-links", false,
"copy what links out of the agents' folders lead to, naming each, without asking (default: ask in a terminal)")
return cmd
}