Files
w3cjandClaude Opus 5.5 e97db057fd fix(agents): Claude Code's plugins get a folder of each VM's own, the store's a read-only seed (#56)
A VM's ~/.claude/plugins was the agent store's plugins folder, mounted
read-only, so everything Claude Code writes there failed with EROFS: a
plugin's data (${CLAUDE_PLUGIN_DATA}), installs, marketplace refreshes,
mcpb/ and the rest. Making the store writable would let one VM change
what Claude Code runs in every other VM, so each VM's ~/.claude/plugins
is now its own folder on its disk (CLAUDE_CODE_PLUGIN_CACHE_DIR), and the
store's folder is linked at ~/.claude/plugins-seed and read as Claude
Code's own read-only seed (CLAUDE_CODE_PLUGIN_SEED_DIR). Checked on a
devvm VM first: a seed-cached plugin from a GitHub-style marketplace
loads with only enabledPlugins, its hook writes ${CLAUDE_PLUGIN_DATA} in
the VM's own folder, installs in the VM work, and seed marketplaces
refuse updates.

- agents: Def.Seeds (Rel, Link, Entries), Seeds, SeedOf, MachineOwn;
  Env gains Home; Claude's Env sets both variables below $HOME.
- vm: the setup links a seed at its Link and stages own-dirs, which
  sync.sh makes a folder in place of a link; agentEnv writes Home values
  through homeValue (shared with toolchainEnv); a remake keeps the VM's
  own folder and skips the seed's link.
- devvm agent import copies only a seed's entries (known_marketplaces.json,
  marketplaces, cache), directly and through followed links, so the
  host's plugins' data, mcpb, synced, .trash, store and
  installed_plugins.json never reach the store.
- devvm agent save: the VM's script excludes a seed folder's other
  entries by name, and readSent refuses any (listedPath); a seed folder
  adds and changes, never removes or prunes; claudeRecords renames the
  VM's plugins path to the store's and joins known_marketplaces.json by
  key, leaving records Claude Code registered from the seed as the
  store's, and the store's file as it is when nothing changed.
- History: an export leaves the VM's plugins folder out and an import
  skips it and the seed's link: it's settings and plugin data (which can
  hold a plugin's own logins), not history, and reaches other VMs only
  through devvm agent save's reviewed diff.
- Review fixes (security-audit): historyImport refuses a name with a
  ., .. or empty part (GNU tar's anchored excludes missed
  .claude/./plugins and .claude//plugins, which now reach a writable
  folder) and deletes importSkips by path after the link sweep; the save
  script never excludes a name with a wildcard's character (it's sent
  and refused); only a marketplace record whose exact installLocation is
  clean and in the store's marketplaces joins the store's.
- Tests: claude_test.go (TestClaudePluginsSeed, TestClaudePluginsHistory,
  TestAgentImportClaudePlugins, TestAgentSaveScriptClaudePlugins,
  TestReadSentClaudePlugins, TestAgentSaveClaudePlugins), TestSeeds,
  TestListedPath cases, the agent, agent_save and sync CLI tests, goldens,
  and e2e project checks of the seed, the VM's folder and a plugin's data.
- Docs: coding-agents (store table, Claude Code's plugins under Mounts,
  the save's plugin example), internals/agents, a design note with its
  threat check, extending.md, CHANGELOG Fixed and After you upgrade.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 11:37:40 -07:00

150 lines
6.8 KiB
Plaintext

# devvm agent save: the folder's VM's agents' settings read from the VM
# (the stub's agent-save.tar stands for its stream), shown as a diff and a
# list of a folder's files, then saved into devvm's store after a yes. It
# always asks: without a terminal or with --no-input it's refused, and the
# store stays as it is. A stream with anything outside the agents'
# settings saves nothing.
env COPYFILE_DISABLE=1
# Its arguments are agents; without a VM there's nothing to save from.
! exec devvm agent save nope
stderr '^devvm: arg_not_choice choices='$AGENT_CHOICES' command=devvm agent save given=nope$'
project agent
! exec devvm agent save
stderr '^devvm: no_vm dir=\S*/agent$'
# A VM with Claude Code: an agent it doesn't have is warned about, and
# an empty stream is nothing to save.
exec devvm --network open --no-git-protect --agents claude
vm_name AGENT agent
stub_reset
exec devvm agent save codex
stderr '^devvm: agent_save_none agent=codex vm='$AGENT'$'
exec devvm agent save
stdout '^==> agent_save_nothing vm='$AGENT'$'
stub_calls
stdout '\.devvm-save'
stdout 'jq --argjson k'
# The VM's settings: without a terminal, the diff and the folder's files,
# then the refusal; nothing saved.
mkdir $CFG/agents/claude/.claude
cp $WORK/old-settings.json $CFG/agents/claude/.claude/settings.json
exec tar -cf $STUB_DIR/agent-save.tar -C $WORK/vm .devvm-save .claude/settings.json .claude/skills
! exec devvm agent save
stdout '^--- \S*/config/devvm/agents/claude/\.claude/settings\.json$'
stdout '^\+\+\+ '$AGENT':~/\.claude/settings\.json$'
stdout '^- "theme": "dark"$'
stdout '^\+ "theme": "light"$'
stdout '^~/\.claude/skills in '$AGENT', into \S*/config/devvm/agents/claude/\.claude/skills:$'
stdout '^ A s/SKILL\.md$'
stdout '^\+\+\+ '$AGENT':~/\.claude\.json$'
stderr '^devvm: agent_save_refused$'
! stderr agent_save_ask
cmp $CFG/agents/claude/.claude/settings.json $WORK/old-settings.json
! exists $CFG/agents/claude/.claude/skills
! exec devvm agent save --no-input
stderr '^devvm: agent_save_refused$'
# In a terminal it says what saved settings run, and asks: no saves
# nothing, yes saves them, with ~/.claude.json's subset, never its
# projects.
ttyin -stdin $WORK/no.txt
exec devvm agent save
stderr '^agent_save_runs$'
stderr 'agent_save_ask vm='$AGENT' \[y/N\] '
stdout '^==> nothing_saved$'
cmp $CFG/agents/claude/.claude/settings.json $WORK/old-settings.json
ttyin -stdin $WORK/yes.txt
exec devvm agent save claude
stdout '^==> agent_settings_saved agent=claude dir=\S*/config/devvm/agents/claude vm='$AGENT'$'
cmp $CFG/agents/claude/.claude/settings.json $WORK/vm/.claude/settings.json
cmp $CFG/agents/claude/.claude/skills/s/SKILL.md $WORK/vm/.claude/skills/s/SKILL.md
grep '"theme": "light"' $DATA/logins/claude/.claude.json
! grep projects $DATA/logins/claude/.claude.json
# Saved, it's the same as the store's.
exec devvm agent save
stdout '^==> agent_save_nothing vm='$AGENT'$'
# Claude Code's plugins: the VM's own plugins folder holds what it installed, and its seed, the
# store's, the rest, so a save adds and changes the store's plugins and never takes one out; the
# VM's marketplaces join the store's, each record naming the store's folders. The stream is only
# the seed's entries (its marketplaces, their records and the plugins' cache). A marketplace that
# Claude Code registered from the seed (m) is the store's own, and stays as the store has it; saved,
# the same folder is no change.
mkdir $CFG/agents/claude/.claude/plugins/cache/m/p/1.0.0
cp $WORK/plugin-skill.md $CFG/agents/claude/.claude/plugins/cache/m/p/1.0.0/SKILL.md
exec sh -c 'printf "{\"m\":{\"installLocation\":\"%s/.claude/plugins/marketplaces/m\"}}\n" "$CFG/agents/claude" > "$CFG/agents/claude/.claude/plugins/known_marketplaces.json"'
exec tar -cf $STUB_DIR/agent-save.tar --no-recursion -C $WORK/vm .devvm-save .devvm-save/home .devvm-save/claude.json .claude/settings.json .claude/plugins .claude/plugins/known_marketplaces.json .claude/plugins/cache .claude/plugins/cache/v .claude/plugins/cache/v/p .claude/plugins/cache/v/p/1.0.0 .claude/plugins/cache/v/p/1.0.0/SKILL.md
! exec devvm agent save
stdout '^~/\.claude/plugins in '$AGENT', into \S*/config/devvm/agents/claude/\.claude/plugins:$'
stdout '^ A cache/v/p/1\.0\.0/SKILL\.md$'
stdout '^ M known_marketplaces\.json$'
! stdout '^ D '
ttyin -stdin $WORK/yes.txt
exec devvm agent save claude
cmp $CFG/agents/claude/.claude/plugins/cache/v/p/1.0.0/SKILL.md $WORK/vm/.claude/plugins/cache/v/p/1.0.0/SKILL.md
cmp $CFG/agents/claude/.claude/plugins/cache/m/p/1.0.0/SKILL.md $WORK/plugin-skill.md
grep '"m": \{\n *"installLocation": "\S*/agents/claude/\.claude/plugins/marketplaces/m"' $CFG/agents/claude/.claude/plugins/known_marketplaces.json
grep '"v": \{\n *"installLocation": "\S*/agents/claude/\.claude/plugins/marketplaces/v"' $CFG/agents/claude/.claude/plugins/known_marketplaces.json
! grep 'u\.linux|autoUpdate' $CFG/agents/claude/.claude/plugins/known_marketplaces.json
exec devvm agent save
stdout '^==> agent_save_nothing vm='$AGENT'$'
# Anything else of the VM's plugins folder, such as a plugin's data, is the VM's own: a stream
# with it saves nothing.
exec tar -cf $STUB_DIR/agent-save.tar --no-recursion -C $WORK/vm .devvm-save .devvm-save/home .claude/plugins .claude/plugins/data .claude/plugins/data/p .claude/plugins/data/p/state.json
! exec devvm agent save
stderr '^devvm: agent_save_unsafe path=\.claude/plugins/data vm='$AGENT'$'
! exists $CFG/agents/claude/.claude/plugins/data
# A stream with a path outside the agents' settings saves nothing.
cp $WORK/new-settings.json $WORK/vm/.claude/settings.json
exec tar -cf $STUB_DIR/agent-save.tar -C $WORK/vm .devvm-save .claude/settings.json .bashrc
env DEVVM_PIPED_ANSWERS=1
stdin $WORK/yes.txt
! exec devvm agent save
env DEVVM_PIPED_ANSWERS=
stderr '^devvm: agent_save_unsafe path=\.bashrc vm='$AGENT'$'
! stdout '^\+\+\+'
cmp $CFG/agents/claude/.claude/settings.json $WORK/old-light.json
# The VM's tar failing is a failed read.
exec sh -c 'echo .devvm-save > "$STUB_DIR/shell-fails-on"'
! exec devvm agent save
stderr '^devvm: agent_save_not_read vm='$AGENT'$'
rm $STUB_DIR/shell-fails-on
-- old-settings.json --
{"theme": "dark"}
-- old-light.json --
{"theme": "light"}
-- new-settings.json --
{"theme": "blue"}
-- vm/.claude/settings.json --
{"theme": "light"}
-- vm/.claude/skills/s/SKILL.md --
# a skill made in the VM
-- vm/.bashrc --
echo hi
-- plugin-skill.md --
# the store's plugin
-- vm/.claude/plugins/known_marketplaces.json --
{
"v": {"installLocation": "/home/u.linux/.claude/plugins/marketplaces/v"},
"m": {"installLocation": "/home/u.linux/.claude/plugins-seed/marketplaces/m", "autoUpdate": false}
}
-- vm/.claude/plugins/cache/v/p/1.0.0/SKILL.md --
# a plugin installed in the VM
-- vm/.claude/plugins/data/p/state.json --
{"token":"testfake-plugin-data"}
-- vm/.devvm-save/home --
/home/u.linux
-- vm/.devvm-save/claude.json --
{"theme": "light", "projects": {"/p": {"history": ["testfake-history"]}}}
-- no.txt --
n
-- yes.txt --
y