mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
devvm agent save refused a VM whose ~/.config/opencode held a bun.lock (which opencode's plugins' installs write), a package-lock.json, a .gitignore or a .DS_Store: the save's script sent every entry of that folder but node_modules and FolderOwn, while the host's listedPath refuses those files (fileSetting), so it saved nothing. notSettings is now their one list, as patterns path.Match and the shell's case read alike: fileSetting leaves them out and the script sends a file of those names no more, only a folder that isn't a link, which is a setting. TestAgentSaveScriptRuns plants them and a folder named old.lock, and failed with agent_save_unsafe before the fix. opencode's HistoryOwn names its native client's plugin approvals, in its state folder (cli-rs's plugin/src/loader/approval.rs and tui/src/plugins/host.rs, opencode v2.4.1): plugin-approvals.json, its .lock and the .plugin-approvals.json.<pid>.<n>.tmp it's written through, and plugin-staged, the approved trees' copies, which it reuses by their hash's name without hashing them again, so a hostile VM's export could approve a project plugin for the VM that imports it. That client doesn't ship in 2.4.1. TestHistoryExportRuns and TestHistoryImportRuns plant them, with plugin-notes.json as the control, and failed on fedora without the entries. The history scripts' framing (onInputCmd) now says why on its stderr, which goes to the VM's log, when its input was cut short: TestOnInputCutShort checks it for every cut, an empty input included, and none for a whole one, and failed before. TestHistoryScriptsOnInput holds each script under 128 KiB, Linux's limit on one argument, which bash -c "$s" passes it as. The CLI scripts match the framing's new start. Docs: the save's and the store's table say which files stay in the VM; the import's and How it works' lists name the plugin approvals; the release page gets opencode's lock files in a save and the approvals; the changelog's opencode block gets the save's fix, and the hardening line names approved plugins. The review's optional wording: the design note's `*` matches every resource, and the plain-password steps set this machine's password first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
32 lines
1.5 KiB
Go
32 lines
1.5 KiB
Go
package vm
|
|
|
|
import (
|
|
"io"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// onInputCmd is the command that runs the script that comes first on its
|
|
// input, as onInput frames it: a line with the script's length in bytes,
|
|
// then the script, then the rest of the input, which the script gets as
|
|
// its own. It reads exactly that many bytes (dd bs=1, so not one byte of
|
|
// the rest), and runs the script only when it read them all, so an input
|
|
// cut short runs nothing, and says so on its stderr, which goes to the
|
|
// VM's log.
|
|
const onInputCmd = `if IFS= read -r n && s=$(dd bs=1 count="$n" 2>/dev/null) && [ "$(printf %s "$s" | wc -c)" -eq "$n" ] 2>/dev/null; then exec bash -c "$s" bash; fi; echo "devvm: The script on the input was cut short, so it didn't run" >&2; exit 1`
|
|
|
|
// onInput returns the command and the input that run script in a VM with
|
|
// rest as its input: the script goes on the input, never in the command's
|
|
// arguments, as ssh's shared connection on macOS fails to start a session
|
|
// whose command is that long ("mm_send_fd: sendmsg: Message too long"),
|
|
// which an export's or an import of agents' history is. A script's
|
|
// trailing newlines go, as the shell's $(…) takes them off.
|
|
func onInput(script string, rest io.Reader) (argv []string, stdin io.Reader) {
|
|
script = strings.TrimRight(script, "\n")
|
|
in := strings.NewReader(strconv.Itoa(len(script)) + "\n" + script)
|
|
if rest == nil {
|
|
return []string{"bash", "-c", onInputCmd}, in
|
|
}
|
|
return []string{"bash", "-c", onInputCmd}, io.MultiReader(in, rest)
|
|
}
|