mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
fix(agents): imported opencode history brings no automations, approvals or resumed turns
An export of opencode's history held what opencode 2.4 acts on without asking, so a hostile VM's export could run commands in the VM that imports it (opencode v2.4.1's source): its automations (automation), each a trigger and a shell command that it approved once and never asks about again (core/src/automation/shell.ts); the requests you said always to allow (permission, which Permission.evaluate turns into allow rules); each session's own rules (session_v2.permission, a Permission.Ruleset); the subagents' jobs (job), the queued messages (session_inbox) and the suspended sessions (session_v2.time_suspended), which its service starts or resumes when it starts (core/src/session/execution/restart.ts), with the session's agent's own rules, explore's allowing shell; a project's commands (project.commands), whose start command it runs with bash -lc for each worktree (core/src/worktree.ts); and its git repositories in its data folder (snapshot, repos, worktree), whose config can name a clean filter or core.fsmonitor that its own git update-index runs (core/src/snapshot.ts, git.ts). opencodeClean now empties the tables opencodeUnattended picks (automation, permission, job, session_inbox, and any whose name starts so), sets the columns opencodeNulled picks to NULL (time_suspended, commands, in any case), keeps only the deny and ask rules with a text action of every permission column, each written again from what sqlite3 read, so a key written twice can't keep an allow effect for JSON.parse (opencodeAllowRules), drops every view, and fails its check on a generated column (opencodeHidden). Its check counts each and must print 0, so a sqlite3 without JSON leaves the database out. A view, an upper-case column, a generated column and a duplicate key bypassed the first version, as the security review showed. opencode's HistoryOwn now names its background service's registration on every channel and the files written beside it (service-*.json, service.json.*, service-*.json.*) and its git repositories (snapshot, repos, worktree): an export leaves them out and an import never writes them, while a VM made again keeps them. The import's clean-up loop expands each as a pattern; TestHistoryImportScript holds every skip to a path's plain characters. Tests that failed first (fedora's gate): TestOpencodeCleanSchema (automation and permission emptied, a session's allow rule gone), TestHistoryImportRuns and TestHistoryExportRuns (service-local.json, the handoff's and the registration's temporary files); TestOpencodeCleanSessionRules fails closed without the statements. The review's additions: TestOpencodeCleanSchema (job, session_inbox, a suspended session, a project's commands), TestOpencodeCleanSessionRules (a key written twice, a non-text action, an upper-case column), TestOpencodeCleanHidden (a view, a generated column), and the git folders in the export and import tests. The review's docs fixes across the stack land here too: the changelog's What to do steps, the release page, the coding agents page, How it works and the design note. A kept rule whose resource is missing or isn't text gets "*", as opencode's Permission.Rule needs one, and the check also counts a rule that isn't in the rebuilt form, so a copy whose rules weren't rebuilt fails closed. A stack-wide review's last docs fixes land here: devvm rm deletes opencode's worktrees with the VM, so the changelog has a What to do step to commit their work first. The export's and the import's scripts, which the stack doubled, now go on the VM's input (onInput): a line with the script's length, the script, then the import's export. In the command's arguments, quoted for ssh's shared connection, macOS's ssh failed to start the session (mm_send_fd: sendmsg: Message too long), which the mini's e2e hit, the export first and then the import. The VM reads exactly that many bytes (dd bs=1) and runs the script only when it read them all, so an input cut short runs nothing (TestOnInputCutShort), and the script gets the rest as its input. TestHistoryScriptsOnInput holds every argument under 4 KiB; TestHistoryExportRuns and the import's runs use onInput too. The stub guest takes such a script off its input (inputScript), matches its switches and files() against it and keeps an export's and an import's in history-export.sh and history-import.sh, which history, history_import, rm_vm, existing_agents and layer_add read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
24 files changed
+647
-113
No files matched your search
+9
-3
@@ -223,14 +223,20 @@ These changes are on `main` and go out in the next release.
|
||||
### What to do
|
||||
|
||||
1. Run `devvm update` in each existing VM's folder, and give the first one several minutes, because it builds base and its shared tools again ([details](https://next.devvm.dev/docs/releases/0.2.0/#pins-since-020-rc1)).
|
||||
2. If an export that `devvm history export`, `devvm rm` or a VM made again wrote holds `.local/state/opencode/machine/home-key`, replace that key in the VM it came from and in each VM you imported it into, and pair their machines again, because the machines opencode pairs trust it. The details page has the steps, and those for a VM you deleted ([history](https://next.devvm.dev/docs/using/coding-agents/#history), [details](https://next.devvm.dev/docs/releases/0.2.0/#opencodes-machine-key-in-history-exports)).
|
||||
3. If you imported opencode's settings with `devvm agent import`, restart each running VM that has opencode with `devvm restart`, because its opencode service took the password `devvm-redacted`, which every VM had. If this machine's opencode has remote access on, turn it off and on again for a new route, because your VMs got its route ([opencode's service](https://next.devvm.dev/docs/using/coding-agents/#opencodes-service), [details](https://next.devvm.dev/docs/releases/0.2.0/#opencodes-service-settings-in-vms)).
|
||||
2. If you pair machines with opencode and an export that devvm wrote holds `.local/state/opencode/machine/home-key`, replace that key and pair again in the VM it came from and in each VM you imported it into, because every machine paired with that VM trusts the key ([history](https://next.devvm.dev/docs/using/coding-agents/#history), [details](https://next.devvm.dev/docs/releases/0.2.0/#opencodes-machine-key-in-history-exports)).
|
||||
3. If you ran `devvm agent import` or `devvm agent save` for opencode, restart each running VM that has opencode with `devvm restart`, because its service took the password `devvm-redacted`, which every VM had. If this machine's opencode has remote access on, run `opencode service set remote false` and then `opencode service set remote true` on this machine, because your VMs got its route ([opencode's service](https://next.devvm.dev/docs/using/coding-agents/#opencodes-service), [details](https://next.devvm.dev/docs/releases/0.2.0/#opencodes-service-settings-in-vms)).
|
||||
4. Before `devvm rm` of a VM where opencode made worktrees, commit the work in them, because an export no longer holds opencode's worktrees, and their commits stay in your project's repository ([history](https://next.devvm.dev/docs/using/coding-agents/#importing-history), [details](https://next.devvm.dev/docs/releases/0.2.0/#opencodes-automations-and-permissions-in-history)).
|
||||
|
||||
<details><summary>If you use opencode</summary>
|
||||
|
||||
- `devvm history export` and `devvm history import` now leave out opencode's machine key (2.4 and later) and its paired machines, its service's password and its terminals' access tokens, while a VM made again keeps them ([details](https://next.devvm.dev/docs/releases/0.2.0/#opencodes-machine-key-in-history-exports)).
|
||||
- `devvm history export` and `devvm history import` now leave out opencode 2.4's machine key and paired machines, its service's password and its terminals' access tokens, which a VM made again still keeps ([details](https://next.devvm.dev/docs/releases/0.2.0/#opencodes-machine-key-in-history-exports)).
|
||||
- Each VM's opencode service now has a password of its own, which `opencode service get password` shows in the VM, and this machine's service settings and remote route never reach devvm's agent store or a VM ([details](https://next.devvm.dev/docs/releases/0.2.0/#opencodes-service-settings-in-vms)).
|
||||
|
||||
</details>
|
||||
<details><summary>Security hardening: a VM's history export can no longer have opencode run commands unasked in the VM you import it into</summary>
|
||||
|
||||
- `devvm history export` and `devvm history import` leave out opencode's automations, approvals, allow rules, resumable turns, project commands and git repositories, so make again any automation you want in the new VM ([details](https://next.devvm.dev/docs/releases/0.2.0/#opencodes-automations-and-permissions-in-history)).
|
||||
|
||||
</details>
|
||||
<details><summary>Internal changes</summary>
|
||||
|
||||
|
||||
@@ -761,10 +761,10 @@ The volume tells two disks apart that each have a folder with the same inode and
|
||||
opencode 2 keeps its sessions and its logins in one SQLite database, `~/.local/share/opencode/opencode.db` (`opencode-<channel>.db` for another channel's build), in WAL mode. An export of agents' history goes to this machine and can go into another VM of the folder, so it must carry the sessions without the logins. Leaving the database out would lose opencode's history, and opencode's own `opencode session export` runs opencode and its server once per session, which an export before `devvm rm` can't count on. devvm copies the database in the VM with the `sqlite3` that base installs (`sqlite3` on Debian and Ubuntu, `sqlite` on Alpine), as the VM's user, in a temporary folder in `~/.cache` (`opencodeClean`):
|
||||
|
||||
1. `VACUUM INTO` copies the database as one snapshot, with what its `-wal` file holds, so a login that opencode saved last, which is still only in the WAL, is in the copy and taken out with the rest.
|
||||
2. In the copy, devvm drops every trigger, so none can put a row back, and empties the tables that hold logins: opencode 2.2's `credential` (its logins and API keys), `account` and `control_account` (its console's access and refresh tokens) and `account_state`, the `session_share` table of an earlier opencode (each share's secret), and any other table whose name has `credential`, `account`, `auth`, `secret`, `token` or `share` in it, or that has a column such as `secret`, `api_key`, `access_token` or `password`, so a table that a later opencode adds for its logins is emptied too. It also deletes the rows of the `kv` table whose key starts with `wellknown:config:`, because each holds an organization's remote config, which opencode fetched with that organization's well-known login and which can hold the organization's keys. opencode fetches the config again once it has the login.
|
||||
2. In the copy, devvm drops every trigger, so none can put a row back, and empties the tables that hold logins: opencode 2.2's `credential` (its logins and API keys), `account` and `control_account` (its console's access and refresh tokens) and `account_state`, the `session_share` table of an earlier opencode (each share's secret), and any other table whose name has `credential`, `account`, `auth`, `secret`, `token` or `share` in it, or that has a column such as `secret`, `api_key`, `access_token` or `password`, so a table that a later opencode adds for its logins is emptied too. It also deletes the rows of the `kv` table whose key starts with `wellknown:config:`, because each holds an organization's remote config, which opencode fetched with that organization's well-known login and which can hold the organization's keys. opencode fetches the config again once it has the login. It also empties what would run without asking in the VM that imports the copy (`opencodeUnattended`): opencode 2.4's `automation` table, each automation's trigger and the shell command it runs, which opencode approved once, as the automation was made, and never asks about again, its `permission` table, the requests you said always to allow in a project, its `job` table, the subagents' jobs, and its `session_inbox` table, a session's queued messages, which its service starts again when it starts (`restart.ts`), and any table whose name starts with one of those names. It sets to NULL, in every table, a column named `time_suspended`, which marks a session whose turn the service resumes on its own, and one named `commands`, a project's commands, whose start command opencode runs with `bash -lc` for each worktree it makes (`opencodeNulled`). It drops every view, as a view in an emptied table's name could show a renamed table's rows, and its check fails on any table with a generated column, which `pragma_table_info` doesn't list. Each session's own rules are the `permission` column of `session_v2`, a JSON array of rules, each with an `effect` of allow, deny or ask, so in every table with a `permission` column, its name in any case, devvm keeps only the deny and ask rules with a text action, and a value that isn't such an array becomes no rules (`opencodeAllowRules`). It writes each kept rule again from the values that `sqlite3` read, because `sqlite3` reads a key written twice by its first value and opencode's `JSON.parse` by its last, so `"effect":"deny","effect":"allow"` would otherwise stay as an allow rule for opencode. A kept rule whose resource is missing or isn't text gets `*`, every resource, because opencode's rules need one. It reads that JSON only where a `CASE` has found it valid, because `sqlite3` may read both sides of an `AND` and fail on text that isn't JSON.
|
||||
3. It takes out the record of opencode's migration that imports `auth.json` (`20260805200742_import_legacy_credentials`), so the opencode that next opens the copy imports the logins that devvm's setup wrote in its own VM's `auth.json`, as it does when it first makes its database.
|
||||
4. It turns WAL off, with `secure_delete` on, and runs `VACUUM`, which writes the file again, so no free page keeps a deleted row and no `-wal` or `-journal` file is left.
|
||||
5. It checks what `sqlite3` printed, not only that it succeeded. Right after `VACUUM INTO`, the copy must have as many tables as the database, and at least one. At the end, devvm counts the triggers, the rows of each table it emptied and the `kv` rows it deleted, and each count must be `0`, so a `sqlite3` that runs nothing and prints nothing fails the check too. When a check or any step fails, the database is left out of the export and the run log says why.
|
||||
5. It checks what `sqlite3` printed, not only that it succeeded. Right after `VACUUM INTO`, the copy must have as many tables as the database, and at least one. At the end, devvm counts the triggers and views, the generated columns, the rows of each table it emptied, the values left in each column it set to NULL, the rows whose `permission` still holds anything but deny and ask rules, and the `kv` rows it deleted, and each count must be `0`, so a `sqlite3` that runs nothing and prints nothing fails the check too. When a check or any step fails, the database is left out of the export and the run log says why.
|
||||
|
||||
The export's `tar` leaves out the database and its `-wal`, `-shm` and `-journal` files as they are, matched within opencode's folder, and adds the copy at the database's path (`--transform`, which leaves symlinks' targets alone). The import does the same to an export it unpacks, in the VM, before anything reaches the home folder: it deletes the `-wal`, `-shm` and `-journal` files and any database that isn't a regular file, and puts in each database's copy, or deletes the database when the VM has no `sqlite3` or the copy fails. Each `sqlite3` runs with `trusted_schema` off, so an imported database's schema can't call the CLI's functions that write files.
|
||||
|
||||
@@ -773,9 +773,12 @@ The export's `tar` leaves out the database and its `-wal`, `-shm` and `-journal`
|
||||
- **A secret that's in a session itself,** such as a key you pasted into a prompt, stays in the session, as it does in Claude Code's and Codex's transcripts.
|
||||
- **A plugin's own storage and a remote workspace's binding stay.** opencode keeps each plugin's storage in its `kv` table, under the plugin's own prefix, and each remote workspace's binding, the record its provider needs to reconnect, in its `workspace` table. opencode's built-in plugins keep model catalogs and session records there, but a plugin you install, or a workspace provider, that keeps a token there takes it into the export.
|
||||
- **A VM without `sqlite3`,** made from an image built without it, exports and imports no opencode database, and opencode's sessions are lost from that export.
|
||||
- **opencode's own agents keep their rules.** A session keeps its agent, and a turn is checked against that agent's built-in rules too, such as `explore`'s, which allow its shell commands. With no suspended session, job or queued message, no turn starts until you send one.
|
||||
- **A host password that looks like a variable's name or a number.** Settings' copies keep a value that looks like an environment variable's name or a switch (`envName`, `plainValue`), so a service password set by hand in that form reached VMs as it was, with no `devvm-redacted` for the setup's clean-up to find; the release page says what to do.
|
||||
- **The `event` table stays as it is.** It holds the events that opencode's sessions were made from, a `session.permissions` event's rules among them, and opencode 2.4.1 writes an event into `session_v2` as it publishes it (its session projector), not when it opens a database, so the copy's rules are the ones opencode reads. A later opencode that rebuilt its sessions from that table would read the allow rules again.
|
||||
- **A remake's home folder copy** keeps opencode's database with its logins, and its home key, because it's the same VM's data going into the same folder's new VM ([the home folder's copy](#the-home-folders-copy)).
|
||||
|
||||
opencode 2.4 keeps the private Ed25519 key of its home, which every machine it pairs with `opencode machine add` trusts and which it never replaces, in a file of its own, `~/.local/state/opencode/machine/home-key`, not in the database. The database's `machine` table holds each paired machine's name and the public key it logs in to the home with, so it's the VM's own pairings, and the copy empties it with the login tables (`opencodeLogins`). The key's folder, the background service's registration (`service.json`, with the service's password, and `service.json.pty-handoff`, a terminal's handoff ticket) and the terminals' daemons (`pty`, their sockets and access tokens) are opencode's `HistoryOwn` in the agents' registry: the export leaves them out and the import never writes them, while a remake keeps them. Only the latest channel's registration is named, because that's the opencode devvm installs; another channel's is `service-<channel>.json`.
|
||||
opencode 2.4 keeps the private Ed25519 key of its home, which every machine it pairs with `opencode machine add` trusts and which it never replaces, in a file of its own, `~/.local/state/opencode/machine/home-key`, not in the database. The database's `machine` table holds each paired machine's name and the public key it logs in to the home with, so it's the VM's own pairings, and the copy empties it with the login tables (`opencodeLogins`). The key's folder, the background service's registration (`service.json`, or `service-<channel>.json` on a channel other than latest, dev, beta or next, with the service's password, written through `<file>.<id>.tmp`, and `<file>.pty-handoff`, a terminal's handoff ticket, written through `<file>.pty-handoff.<uuid>.tmp`) and the terminals' daemons (`pty`, their sockets and access tokens) are opencode's `HistoryOwn` in the agents' registry: the export leaves them out and the import never writes them, while a remake keeps them. The registrations are patterns, `service-*.json`, `service.json.*` and `service-*.json.*`, which the export's GNU `tar --exclude` and the import's `tar --exclude` and its clean-up loop, a shell glob, all expand.
|
||||
|
||||
**Threat check** (the security-audit skill, guidance mode, with its data isolation companion):
|
||||
|
||||
@@ -785,7 +788,8 @@ opencode 2.4 keeps the private Ed25519 key of its home, which every machine it p
|
||||
| The WAL or journal file carrying the rows | They never go into an export, and an import deletes them | `TestHistoryExportRuns` and `TestHistoryImportCleansOpencode` |
|
||||
| An export with the logins in it reaching another VM | The import makes the same copy in the VM before anything reaches its home folder, or leaves the database out | `TestHistoryImportCleansOpencode`, with and without `sqlite3` |
|
||||
| A trigger putting a row back as it's deleted | Every trigger is dropped first, and the rows are counted after | `TestOpencodeClean` plants one |
|
||||
| opencode's home key reaching this machine's export or another VM | The export leaves out its `machine` folder, `service.json` and `pty`, and the import never writes them, by their paths after it unpacks too; the copy of the database empties its `machine` table, the paired machines' public keys | `TestHistoryExportRuns`, `TestHistoryImportRuns` and `TestHistoryImportV010` plant them; `TestOpencodeCleanSchema` empties `machine` from opencode 2.4.1's schema; `TestHomeSkipsEveryLogin` keeps them in a remake |
|
||||
| A hostile VM's export running a command, or allowing one, without asking in the VM that imports it | The copy empties `automation`, `permission`, `job` and `session_inbox`, and every table whose name starts with one of those names, sets `time_suspended` and `commands` to NULL, keeps only the deny and ask rules of each `permission` column, written again, drops views and refuses generated columns; the counts after must be `0`. The export leaves out opencode's git repositories (`snapshot`, `repos`, `worktree`), and the import never writes them | `TestOpencodeCleanSchema` plants a row in each from opencode 2.4.1's schema, an allow rule, a suspended session and a project's commands; `TestOpencodeCleanSessionRules` plants rules that aren't deny or ask, a key written twice, values that aren't rules and a column in upper case; `TestOpencodeCleanHidden` a view and a generated column; `TestHistoryExportRuns` and `TestHistoryImportRuns` the git folders |
|
||||
| opencode's home key reaching this machine's export or another VM | The export leaves out its `machine` folder, `service.json`, `service-<channel>.json`, their handoff and temporary files, and `pty`, and the import never writes them, by their paths after it unpacks too; the copy of the database empties its `machine` table, the paired machines' public keys | `TestHistoryExportRuns`, `TestHistoryImportRuns` and `TestHistoryImportV010` plant them; `TestOpencodeCleanSchema` empties `machine` from opencode 2.4.1's schema; `TestHomeSkipsEveryLogin` keeps them in a remake |
|
||||
| A hostile database's schema running code in the VM | `trusted_schema` is off, and it runs as the VM's user on the VM's own files, which the export's code could reach anyway | Reviewed |
|
||||
|
||||
## Links out of an agent's folder
|
||||
|
||||
@@ -46,7 +46,7 @@ The tools, by group, as `--check` prints them:
|
||||
- `mise` moves base's mise (`assets/layers/base.sh`) and devvm's host mise (`internal/tools/mise.go`) together: the host one writes the lock base's installs from. `TestMisePins` fails when their versions or Linux checksums differ, and base's mise version is in the key of each tool image mise installs, so a bump builds them again.
|
||||
- The shared tools aren't pinned for users, except Cursor's CLI. Holds go in `assets/shared-tools/mise.toml` (`node = "24"` stays on that major). `testdata/mise.lock` is a fixed lock for the tests.
|
||||
- Their backends are named in `mise.toml`'s `[tool_alias]` table, for every tool that isn't one of mise's own `core:` tools, because mise's registry can move a tool to another backend in any release ([versions](../internals/images.md#versions)). A new shared tool gets its alias there, and `TestToolBackendsNamed` fails when a tool that isn't a `core:` tool has none, or when its alias isn't the backend that `tests/e2e-mise.lock` resolved.
|
||||
- When opencode's major version changes, or a bump of `e2e-tools` moves opencode to a version that adds migrations, refresh `internal/vm/testdata/opencode-<version>.sql`, the schema of opencode's database that `TestOpencodeCleanSchema` cleans. Print it with `sqlite3 ~/.local/share/opencode/opencode.db .schema` in a VM with that opencode, after `opencode auth list` has made the database, and copy only the schema, never rows. The release's own `packages/core/src/database/schema.gen.ts`, with its SQL unwrapped and the `migration` table's line after it, is the same schema line for line, so you can make the file from it instead. Name the file for the version, and in the test put each new table in its list of tables that devvm empties or keeps, which the test asks for. A table or a column that holds a login also goes into `opencodeLogins` (`internal/vm/agents.go`) and the design note's [opencode's database in history exports](design.md#opencodes-database-in-history-exports).
|
||||
- When opencode's major version changes, or a bump of `e2e-tools` moves opencode to a version that adds migrations, refresh `internal/vm/testdata/opencode-<version>.sql`, the schema of opencode's database that `TestOpencodeCleanSchema` cleans. Print it with `sqlite3 ~/.local/share/opencode/opencode.db .schema` in a VM with that opencode, after `opencode auth list` has made the database, and copy only the schema, never rows. You can also make the file from the release's `packages/core/src/database/schema.gen.ts` in opencode's repo: unwrap its SQL and add the `migration` table's line at the end, and it matches `.schema` line for line. Name the file for the version, and in the test put each new table in its list of tables that devvm empties or keeps, which the test asks for. A table or a column that holds a login also goes into `opencodeLogins` (`internal/vm/agents.go`) and the design note's [opencode's database in history exports](design.md#opencodes-database-in-history-exports).
|
||||
- `e2e-tools`, `e2e-from`, `e2e-curl` and `e2e-ubuntu` move the end-to-end tests' own pins, which keep their cached images valid between runs. `e2e-tools` resolves `tests/e2e-mise.lock` again, with devvm's pinned host mise, for both architectures' glibc and musl VMs, and refuses a tool whose download has no checksum on every platform yet. `e2e-from` moves the digests of `node:24`, `alpine:3` and `ubuntu:26.04` in `tests/e2e/from_test.go` to Docker Hub's. `e2e-curl` moves `curlImage` in `tests/e2e/transparent_test.go`, the curl image that the network checks run in containers, to curlimages/curl's newest release, by its digest. `e2e-ubuntu` moves `e2eUbuntuRelease` in `tests/e2e/sandbox_test.go`, the dated release of Ubuntu's cloud image that e2e pins base to in place of the newest, to the newest Ubuntu lists. Ubuntu removes dated releases after a few months, and e2e's going stops its first builds of base: bump `e2e-ubuntu` before that. Run `e2e-tools` after any change to `assets/shared-tools/mise.toml`, because the end-to-end tests refuse a lock resolved from another one ([end-to-end tests](tests.md#end-to-end-tests)). `mise run test` catches it first: `TestE2ELockPins` checks the lock's first line against `mise.toml` and that it locks each of its tools, and `TestE2EUbuntuPins` checks that `e2eUbuntuRelease` is a dated release of base's Ubuntu release, which `e2e-ubuntu` lists, and that `scripts/bump.sh` and `tests/e2e` name only that release.
|
||||
- `e2e-lima` moves the Lima release that CI's end-to-end workflow installs, `LIMA_VERSION` in `.github/workflows/e2e.yml`, to Lima's newest release, and `LIMA_SHA256` to its `Linux-x86_64` tarball's line in that release's `SHA256SUMS`. Lima's release notes print the SHA-256 of `SHA256SUMS` itself, so `e2e-lima` checks the downloaded file against that value first and edits nothing when they differ.
|
||||
- `assets/layers/ubuntu-cloud.gpg` is Ubuntu's cloud image signing key (fingerprint `D2EB44626FDDC30B513D5BB71A5D6C4C7DB87C81`), from keyserver.ubuntu.com. If Ubuntu changes it, pinning a new image (a first build of base, or `devvm rebuild base`) stops with `ubuntu_bad_signature`: fetch the new key, check its fingerprint against Ubuntu's announcement, and replace the file (`gpg --export FPR`).
|
||||
|
||||
@@ -70,9 +70,9 @@ devvm merges the settings and MCP servers from the store's `.claude.json` into t
|
||||
|
||||
## opencode's service
|
||||
|
||||
opencode keeps its background service's settings in `~/.config/opencode/service.json`, or in `service-<channel>.json` for a channel other than latest, dev, beta and next, as an earlier build's `service-<hash>.json` is named, and it writes each one through a temporary file beside it, `<file>.<pid>.tmp`. They hold the service's password, 32 random bytes that the service makes when it starts and the file has none, and with remote access on, the route that the service is served on, a random name that keeps its address unguessable, so opencode's own `opencode service get` hides both. They also hold the service's port, host name, CORS origins and environment. That makes them each machine's own rather than settings, so the import and the save leave out every entry of `~/.config/opencode` with one of these names, what's in a folder of that name included, and the save's script in the VM never sends them, so the VM's own file never makes a save fail. The VM's file stays in the VM, so a VM made again keeps it, and no export of the VM's history holds it, because `~/.config/opencode` isn't history.
|
||||
opencode keeps its background service's settings in `~/.config/opencode/service.json`, or in `service-<channel>.json` for a channel other than latest, dev, beta or next (an earlier build named it `service-<hash>.json`), and it writes each one through a temporary file beside it, `<file>.<pid>.tmp`. They hold the service's password, 32 random bytes that the service makes when it starts and the file has none, and with remote access on, the route that the service is served on, a random name that keeps its address unguessable. So `opencode service get` with no key hides both, and only `opencode service get password` shows the password. They also hold the service's port, host name, CORS origins and environment. That makes them each machine's own rather than settings, so the import and the save leave out every entry of `~/.config/opencode` with one of these names, what's in a folder of that name included, and the save's script in the VM never sends them, so the VM's own file never makes a save fail. The VM's file stays in the VM, so a VM made again keeps it, and no export of the VM's history holds it, because `~/.config/opencode` isn't history.
|
||||
|
||||
A store that an earlier import filled can hold them, so every start looks for them in the store's `~/.config/opencode`, which it opens as it opens [Claude Code's plugins](#claude-codes-plugins) folder, and once it finds any, it takes them out holding the store's lock and warns once, naming them. No VM gets them from the store meanwhile, because a VM's setup copies only the files that the import would copy, so a start whose clean-up fails only warns, naming the folder. An earlier devvm copied them into every VM with opencode on each launch, with `devvm-redacted` in place of the password and of each value of the environment, so every such VM's service took `devvm-redacted` as its password. Each launch's setup takes out each regular file in the VM's `~/.config/opencode` with one of these names that holds `devvm-redacted`, which only devvm's copy can, and leaves the VM's own files, links and folders, so the VM's opencode makes its own password when its service next starts. A service that's running keeps the password it started with until it stops, as when the VM restarts.
|
||||
A store that an earlier import filled can hold them, so every start looks for them in the store's `~/.config/opencode`, which it opens as it opens [Claude Code's plugins](#claude-codes-plugins) folder, and once it finds any, it takes them out holding the store's lock and warns once, naming them. No VM gets them from the store meanwhile, because a VM's setup copies only the files that the import would copy, so a start whose clean-up fails only warns, naming the folder. devvm writes `devvm-redacted` in place of a secret in every copy of a settings file that it makes, so a file with one of these names that holds it is a copy that devvm made, whose password every VM with such a copy shares. Each launch's setup takes out each such regular file in the VM's `~/.config/opencode` and leaves the VM's own files, links and folders, so the VM's opencode makes its own password when its service next starts. A service that's running keeps the password it started with until it stops, as when the VM restarts.
|
||||
|
||||
## Claude Code's login
|
||||
|
||||
@@ -130,10 +130,27 @@ With some of these keys, code in the VM can make a credential of its own that wo
|
||||
|
||||
## History exports
|
||||
|
||||
The agents' logins aren't in the export, which leaves out `~/.claude/.credentials.json`, `~/.codex/auth.json`, and opencode's `auth.json`, `account.json`, `mcp-auth.json` and `bin`, and holds nothing of `~/.pi/agent` but its sessions, so pi's `auth.json` stays out too. It also leaves out what of `~/.local/state/opencode` is the VM's own as a machine. That's its `machine` folder, whose `home-key` is the private key that every machine opencode pairs with `opencode machine add` trusts, its `service.json`, which holds the password of opencode's background service, and its `pty` folder, which holds the sockets of its terminals' daemons and their access tokens. The copy of opencode's database leaves out its `machine` table too, which holds the public keys that the machines it paired log in to it with. An import never writes them either, so the new VM's opencode makes its own, and a VM made again keeps the VM's own, because it's the same machine ([what a VM made again keeps](../using/images.md#what-a-vm-made-again-keeps)). It leaves out the VM's `~/.claude/plugins`, which holds settings and each plugin's data rather than history ([Claude Code's plugins](#claude-codes-plugins)). opencode keeps its sessions and its logins together in one database, `~/.local/share/opencode/opencode.db`, so the export holds a copy of that database without its logins. The VM makes the copy with `sqlite3`, which every base image has, and the copy has no logins, API keys or opencode account in any part of the file, not even a key you typed into opencode in the VM, while the VM's own database keeps them ([how](../contributing/design.md#opencodes-database-in-history-exports)). The export never holds the database's `-wal`, `-shm` or `-journal` files, which can hold logins that opencode saved last. When the VM has no `sqlite3`, such as a VM made from an image built without it, the export leaves the database out, so opencode's sessions aren't in it, and the run log says so. devvm starts a stopped VM for the export as a launch does, so it locks the folder's `.git` again and checks the VM's confinement first, and the VM stays running. devvm writes the file only once the export is complete, so a failed export leaves no file and leaves an existing FILE as it was. An export holds at most 2 GiB, because a VM could otherwise write until this machine's disk is full. When the VM sends more, devvm stops the export and keeps nothing of it, so `devvm history export` fails, while `devvm rm` and the commands that make a VM again warn that they kept no export and go on without one. Only you can read the file, and devvm makes the exports folder yours alone each time it writes one there, whatever its mode was before. When FILE is in a folder of your own, that folder keeps its mode. If the export fails, `devvm rm` keeps the VM, and `devvm rm --no-export` deletes it without exporting. `devvm rm VM`, for a VM whose folder is gone, exports in the same way, but only from a running VM or a `--clone` VM, because starting any other would make its folder again ([a VM whose folder is gone](../using/vms.md#a-vm-whose-folder-is-gone)).
|
||||
The agents' logins aren't in the export, which leaves out `~/.claude/.credentials.json`, `~/.codex/auth.json`, and opencode's `auth.json`, `account.json`, `mcp-auth.json` and `bin`, and holds nothing of `~/.pi/agent` but its sessions, so pi's `auth.json` stays out too. It leaves out the VM's `~/.claude/plugins`, which holds settings and each plugin's data rather than history ([Claude Code's plugins](#claude-codes-plugins)). It also leaves out what of `~/.local/state/opencode` is the VM's own as a machine:
|
||||
|
||||
- its `machine` folder, whose `home-key` is the private key that every machine opencode pairs with `opencode machine add` trusts
|
||||
- its `service.json`, or `service-<channel>.json` for another channel's opencode, which holds the password of opencode's background service, and the handoff tickets and temporary files that opencode writes beside it
|
||||
- its `pty` folder, which holds the sockets of its terminals' daemons and their access tokens
|
||||
|
||||
The copy of opencode's database leaves out its `machine` table too, which holds the public keys that the machines it paired log in to it with. An import never writes them either, so the new VM's opencode makes its own, and a VM made again keeps the VM's own, because it's the same machine ([what a VM made again keeps](../using/images.md#what-a-vm-made-again-keeps)).
|
||||
|
||||
opencode keeps its sessions and its logins together in one database, `~/.local/share/opencode/opencode.db`, so the export holds a copy of that database without its logins. The VM makes the copy with `sqlite3`, which every base image has, and the copy has no logins, API keys or opencode account in any part of the file, not even a key you typed into opencode in the VM, while the VM's own database keeps them ([how](../contributing/design.md#opencodes-database-in-history-exports)). The copy also leaves out what opencode 2.4 would act on without asking in the VM that imports it:
|
||||
|
||||
- its `automation` table, because opencode runs each automation's shell command on its schedule or event without asking again
|
||||
- its `permission` table, the requests you said always to allow
|
||||
- its `job` table, the subagents' jobs, and its `session_inbox` table, the messages queued for a session's next turn, because opencode's service starts those jobs and turns when it starts
|
||||
- each session's allow rules, as the session keeps only the deny and ask rules of its permission rules
|
||||
- each suspended session's mark, so no session resumes its turn on its own
|
||||
- each project's commands, whose start command opencode runs for each worktree it makes
|
||||
|
||||
The export also leaves out opencode's git repositories in `~/.local/share/opencode`, which are `snapshot`, `repos` and `worktree`, because a repository's config can name a command that git runs, and opencode's own git commands would run it in the VM that imports it. So the export doesn't hold opencode's worktrees, and the work in them stays in the VM, which a VM made again keeps and `devvm rm` deletes. Their commits are in the project's own repository. A view or a generated column in the database could hide rows from these steps, so the copy drops every view, and it fails its check when a table has a generated column. The export never holds the database's `-wal`, `-shm` or `-journal` files, which can hold logins that opencode saved last. When the VM has no `sqlite3`, such as a VM made from an image built without it, the export leaves the database out, so opencode's sessions aren't in it, and the run log says so. It does the same when the VM's `sqlite3` can't read JSON, which the sessions' rules are. devvm starts a stopped VM for the export as a launch does, so it locks the folder's `.git` again and checks the VM's confinement first, and the VM stays running. devvm writes the file only once the export is complete, so a failed export leaves no file and leaves an existing FILE as it was. An export holds at most 2 GiB, because a VM could otherwise write until this machine's disk is full. When the VM sends more, devvm stops the export and keeps nothing of it, so `devvm history export` fails, while `devvm rm` and the commands that make a VM again warn that they kept no export and go on without one. Only you can read the file, and devvm makes the exports folder yours alone each time it writes one there, whatever its mode was before. When FILE is in a folder of your own, that folder keeps its mode. If the export fails, `devvm rm` keeps the VM, and `devvm rm --no-export` deletes it without exporting. `devvm rm VM`, for a VM whose folder is gone, exports in the same way, but only from a running VM or a `--clone` VM, because starting any other would make its folder again ([a VM whose folder is gone](../using/vms.md#a-vm-whose-folder-is-gone)).
|
||||
|
||||
## Importing history
|
||||
|
||||
The import works on every VM, whether its base is Ubuntu's image or a Debian-, Ubuntu- or Alpine-based container image ([starting from a container image](../using/from.md)), because it unpacks the export with GNU `tar`, which Debian and Ubuntu always have and which devvm installs in every base made `--from alpine`.
|
||||
|
||||
An export holds what a VM wrote, so devvm treats it as untrusted. Its transcripts can hold what the old VM's agents read, and a VM on a less strict tier reaches more, such as your local network on the open tier. So when the export comes from a VM on a less strict tier than the VM you import it into, going from open to internet, allowlist and none, devvm warns you before it imports. devvm knows an export's tier only from the `.folder` file beside it in `~/.local/share/devvm/exports`, so it warns about an export with no tier recorded, or any FILE elsewhere, such as in the project folder that a VM can write, as if it came from an open VM. devvm never unpacks an export on this machine. It streams the file into the VM as it is, and the VM's own `tar` unpacks it there as the VM's user, so it can only write what that user can write. Before unpacking anything, the VM lists the paths in the export, and when one of them is outside <!-- the agents' history, generated from internal/agents by mise run cli-docs -->`~/.claude`, `~/.claude.json`, `~/.codex`, `~/.local/share/opencode`, `~/.local/state/opencode`, `~/.pi/agent/sessions` and `~/.cursor/chats`<!-- end of the agents' history -->, starts with `/` or has a `.`, `..` or empty part, such as `.claude/./plugins` or `.claude//plugins`, devvm imports nothing and says so, because `tar` matches the paths it leaves out against each name as the export writes it. Once it has unpacked the export, it also deletes each of those paths by its path, whatever name put a file there. It leaves out of that check, and never unpacks, the AppleDouble files whose names start with `._`, which macOS's `tar` puts beside each file that has extended attributes, so an export you packed yourself on a Mac imports. The import keeps no owner or mode from the export, so the VM user's umask applies and no file is set-user-ID. It also takes out every symbolic link that points outside the folder it's in, which is any link to an absolute path or one with a `..` part, so an agent writing to a session file can't follow a link out of its history. An export that devvm didn't write, such as a `.tar.gz` you made yourself, can hold opencode's database with its logins, so the import takes out the database's `-wal`, `-shm` and `-journal` files and puts in a copy of the database without its logins, as the export makes it, or leaves the database out when the VM has no `sqlite3`. opencode in the new VM then reads the logins that devvm gave the VM, as it does when it first makes its database. When the VM already has an opencode database, it keeps its own, and opencode's sessions from the export aren't imported.
|
||||
An export holds what a VM wrote, so devvm treats it as untrusted. Its transcripts can hold what the old VM's agents read, and a VM on a less strict tier reaches more, such as your local network on the open tier. So when the export comes from a VM on a less strict tier than the VM you import it into, going from open to internet, allowlist and none, devvm warns you before it imports. devvm knows an export's tier only from the `.folder` file beside it in `~/.local/share/devvm/exports`, so it warns about an export with no tier recorded, or any FILE elsewhere, such as in the project folder that a VM can write, as if it came from an open VM. devvm never unpacks an export on this machine. It streams the file into the VM as it is, and the VM's own `tar` unpacks it there as the VM's user, so it can only write what that user can write. Before unpacking anything, the VM lists the paths in the export, and when one of them is outside <!-- the agents' history, generated from internal/agents by mise run cli-docs -->`~/.claude`, `~/.claude.json`, `~/.codex`, `~/.local/share/opencode`, `~/.local/state/opencode`, `~/.pi/agent/sessions` and `~/.cursor/chats`<!-- end of the agents' history -->, starts with `/` or has a `.`, `..` or empty part, such as `.claude/./plugins` or `.claude//plugins`, devvm imports nothing and says so, because `tar` matches the paths it leaves out against each name as the export writes it. Once it has unpacked the export, it also deletes each of those paths by its path, whatever name put a file there. It leaves out of that check, and never unpacks, the AppleDouble files whose names start with `._`, which macOS's `tar` puts beside each file that has extended attributes, so an export you packed yourself on a Mac imports. The import keeps no owner or mode from the export, so the VM user's umask applies and no file is set-user-ID. It also takes out every symbolic link that points outside the folder it's in, which is any link to an absolute path or one with a `..` part, so an agent writing to a session file can't follow a link out of its history. An export that devvm didn't write, such as a `.tar.gz` you made yourself, can hold opencode's database with its logins, so the import takes out the database's `-wal`, `-shm` and `-journal` files and puts in a copy of the database without its logins or what opencode would act on without asking, as the export makes it ([history exports](#history-exports)), or leaves the database out when the VM has no `sqlite3`. It never writes opencode's git repositories either. opencode in the new VM then reads the logins that devvm gave the VM, as it does when it first makes its database. When the VM already has an opencode database, it keeps its own, and opencode's sessions from the export aren't imported.
|
||||
@@ -283,7 +283,7 @@ When a VM's state file held a size devvm couldn't read as a number, such as `"cp
|
||||
|
||||
### opencode's machine key in history exports
|
||||
|
||||
opencode 2.4 keeps a private key in `~/.local/state/opencode/machine/home-key`, which it makes when it first needs one, such as when you pair a machine with `opencode machine add`. Every machine it pairs trusts that key, and opencode never replaces it. It sits in opencode's state folder beside its prompt history, so `devvm history export`, and the export that `devvm rm` and a VM made again write, used to copy it into the export, and `devvm history import` put it into the VM it imported into. The export also held the state folder's copy of the password of opencode's background service, in `service.json`, and the access tokens of its terminals' daemons, in `pty`, which earlier opencode releases keep there too. The copy of opencode's database also kept its `machine` table, which holds the public keys that the paired machines log in with.
|
||||
opencode 2.4 keeps a private key in `~/.local/state/opencode/machine/home-key`, which it makes when it first needs one, such as when you pair a machine with `opencode machine add`. Every machine it pairs trusts that key, and opencode never replaces it. It sits in opencode's state folder beside its prompt history, so `devvm history export`, and the export that `devvm rm` and a VM made again write, used to copy it into the export, and `devvm history import` put it into the VM it imported into. The export also held the password of opencode's background service, which its state folder keeps in `service.json`, or in `service-<channel>.json` for another channel's opencode, with the handoff tickets and temporary files beside it. It held the access tokens of opencode's terminals' daemons too, which opencode keeps in the state folder's `pty`, as releases before 2.4 do as well. The copy of opencode's database also kept its `machine` table, which holds the public keys that the paired machines log in with.
|
||||
|
||||
An export now leaves them out and empties that table, and an import never writes them, even from an older export, so the new VM's opencode makes its own. A VM made again keeps its own, because it's the same machine ([what an export holds](../internals/agents.md#history-exports)).
|
||||
|
||||
@@ -291,24 +291,30 @@ If an export of a VM with opencode 2.4 or later holds `.local/state/opencode/mac
|
||||
|
||||
1. Quit opencode, its TUI and any `opencode serve` included, and stop its service with `opencode service stop`, because a running opencode keeps the key in memory.
|
||||
2. Delete `~/.local/state/opencode/machine/home-key`, so opencode makes a new key when it next needs one.
|
||||
3. Pair again each machine you paired there: `opencode machine add NAME --replace` prints a new join string, which that machine then joins with. In a VM you imported the export into, remove the machines it brought with `opencode machine remove NAME`.
|
||||
3. Pair each machine you paired there again with `opencode machine add NAME --replace`, which prints a new join string for that machine to join with. In a VM you imported the export into, remove the machines it brought with `opencode machine remove NAME`.
|
||||
|
||||
For a VM that you've deleted, unpair each machine it had paired, on that machine. Once the key is replaced, the old exports in `~/.local/share/devvm/exports` hold a key that nothing trusts.
|
||||
|
||||
### opencode's service settings in VMs
|
||||
|
||||
opencode 2 keeps its background service's settings in `~/.config/opencode/service.json`, or in `service-<channel>.json` on another channel. They hold the service's password, which the service makes when the file has none, and with remote access on, the secret route that the service's address is served on and your consent to remote access, beside its port, host name, CORS origins and environment. `devvm agent import` copied every file in `~/.config/opencode` into devvm's agent store, these included, and every VM with opencode got a copy at each launch, with `devvm-redacted` in place of the password and of each value of the environment, and with the route as it was. So each such VM's opencode service took `devvm-redacted` as its password, which anyone who knows devvm knows, and `devvm agent save` would have copied a VM's own file into the store.
|
||||
opencode 2 keeps its background service's settings in `~/.config/opencode/service.json`, or in `service-<channel>.json` on another channel. They hold the service's password, which the service makes when the file has none, and with remote access on, the secret route that the service's address is served on and your consent to remote access, beside its port, host name, CORS origins and environment. `devvm agent import` copied every file in `~/.config/opencode` into devvm's agent store, these included, and every VM with opencode got a copy at each launch, with `devvm-redacted` in place of the password and of each value of the environment, and with the route as it was. So each such VM's opencode service took `devvm-redacted` as its password, which anyone who knows devvm knows. `devvm agent save` copied a VM's own file into the store in the same way, and from there into every VM.
|
||||
|
||||
`devvm agent import` and `devvm agent save` now leave these files out, and no VM gets them, even from a store that holds them. A VM's start takes them out of the store and warns once, and each VM's setup takes out the copy that an earlier devvm gave it, which it knows by the `devvm-redacted` in it, so each VM's opencode makes a password of its own the next time its service starts, which `opencode service get password` shows in the VM ([opencode's service](../using/coding-agents.md#opencodes-service)).
|
||||
`devvm agent import` and `devvm agent save` now leave these files out, and no VM gets them, even from a store that holds them. A VM's start takes them out of the store and warns once, and each VM's setup takes out the copy that an earlier devvm gave it, which it knows by the `devvm-redacted` in it, so each VM's opencode makes a password of its own the next time its service starts. `opencode service get password` shows it in the VM ([opencode's service](../using/coding-agents.md#opencodes-service)).
|
||||
|
||||
A service that's running keeps its password until it stops, so restart each running VM that has opencode, with `devvm restart` in its folder. If this machine's opencode has remote access on, its route reached the store and your VMs, so turn remote access off and on again on this machine, which gives its service a new route:
|
||||
If you ran `devvm agent import` or `devvm agent save` for opencode, your VMs got such a copy. A service that's running keeps its password until it stops, so restart each running VM that has opencode, with `devvm restart` in its folder. If this machine's opencode has remote access on, its route reached the store and your VMs, so turn remote access off and on again on this machine, which gives its service a new route:
|
||||
|
||||
```sh
|
||||
opencode service set remote false # on this machine: drop the route that your VMs got
|
||||
opencode service set remote true # and get a new one
|
||||
```
|
||||
|
||||
A copy of a file that held a route but no password, which only a service that never started since you turned remote access on writes, held no `devvm-redacted`, so it stays in the VM. Once this machine's route is new, the copy's route leads nowhere.
|
||||
When this machine's service had remote access on but hadn't started since, its file held a route and no password, so the copy held no `devvm-redacted` and stays in the VM. Once this machine's route is new, that copy's route leads nowhere. A password you set yourself with `opencode service set password` reached your VMs as it was, with no `devvm-redacted` to mark the copies, when it looked to devvm like a variable's name or a number, which is any of these:
|
||||
|
||||
- capital letters, digits and `_`, starting with a letter
|
||||
- at most five digits
|
||||
- `true` or `false`
|
||||
|
||||
If yours is one, delete `~/.config/opencode/service.json` in each VM with opencode, then restart the VM, and set a new password on this machine.
|
||||
|
||||
## Hardening
|
||||
|
||||
@@ -401,3 +407,16 @@ devvm's other logs are held to their caps as well:
|
||||
### How deep a save goes
|
||||
|
||||
A chain of thousands of folders used to keep `devvm agent save` busy for a long time while it held the agent store's lock. The save now has an import's bounds on depth, so a VM that sends folders nested more than 128 deep, or a path of more than 4,096 bytes, gets nothing saved, as an import of such folders does ([saving a VM's settings](../using/coding-agents.md#saving-a-vms-settings)).
|
||||
|
||||
### opencode's automations and permissions in history
|
||||
|
||||
opencode 2.4 keeps its automations in its database, each with a schedule or an event that triggers it and a shell command that it runs, which opencode asks you to approve once, as the automation is made, and then runs without asking again. The database also keeps the requests you said always to allow in a project, and each session's own permission rules. A copy of the database in a history export kept all of them, so a hostile VM could write an automation, an allow rule or a session that allows every command into its database, and `devvm history import` would put it into the VM you imported the export into, where opencode would run its command without asking. The same went for what opencode's service starts by itself when it starts: a suspended session's turn, a subagent's job and a message queued for a session's next turn. A project's start command, which opencode runs for each worktree it makes, was in the copy too. opencode's git repositories in `~/.local/share/opencode`, its snapshots, its cache of repositories and its worktrees, were in the export too, and a repository's config can name a command that opencode's own git commands then run.
|
||||
|
||||
The copy in an export, and the copy that an import makes of a database in any export, now has:
|
||||
|
||||
- no automations, subagents' jobs or queued messages
|
||||
- no requests you said always to allow, and each session keeps only its deny and ask rules, each written again as sqlite3 reads it
|
||||
- no suspended sessions, so no turn resumes on its own
|
||||
- no project commands
|
||||
|
||||
The copy drops every view and refuses a table with a generated column, which could hide rows from these steps, and its own check counts what's left and leaves the database out unless nothing is. An export also leaves out opencode's `snapshot`, `repos` and `worktree` folders, and an import never writes them, so an export doesn't hold opencode's worktrees. Their commits are in your project's own repository, but `devvm rm` deletes the worktrees' folders with the VM, so commit the work in them first. In the new VM, make again any automation you want, and opencode asks again before the requests you had always allowed. A VM made again keeps its own, because its home folder's copy isn't an export ([what an export holds](../internals/agents.md#history-exports)).
|
||||
@@ -298,7 +298,7 @@ A login that Codex or opencode makes in a VM, whether `devvm agent login` runs i
|
||||
|
||||
### opencode's service
|
||||
|
||||
opencode's background service, which opencode starts when it needs one, signs you in with a password, and each VM's opencode makes its own the first time its service starts. To sign in to a VM's service, such as from opencode's app, read that VM's password in the VM:
|
||||
opencode's background service, which opencode starts when it needs one, asks for a password when you sign in to it, and each VM's opencode makes its own the first time its service starts. To sign in to a VM's service, such as from opencode's app, read that VM's password in the VM:
|
||||
|
||||
```sh
|
||||
opencode service get password # in the VM: its service's password, made now if it has none
|
||||
@@ -306,7 +306,7 @@ opencode service set password PASSWORD # in the VM: choose another, which stops
|
||||
```
|
||||
|
||||
- devvm never copies this machine's opencode service settings into its agent store or a VM. They're `service.json` in `~/.config/opencode`, or `service-<channel>.json` for another channel's opencode, and they hold this machine's service password and, with remote access on, the secret route that the service is served on. So `devvm agent import` and `devvm agent save` leave them out, and each VM's service settings stay in that VM.
|
||||
- When the store holds them, because an earlier `devvm agent import` copied them, a VM's start takes them out of the store and warns once. Each VM's setup also takes out the copy that an earlier devvm gave it, whose password was `devvm-redacted` in every VM, so the VM's opencode makes its own ([how](../internals/agents.md#opencodes-service)).
|
||||
- When devvm's agent store holds them, a VM's start takes them out and warns once, and each VM's setup takes out any copy of them that devvm made, so the VM's opencode makes its own password ([how](../internals/agents.md#opencodes-service)).
|
||||
- A service that's running keeps the password it started with, so after that warning, restart each running VM that has opencode:
|
||||
|
||||
```sh
|
||||
@@ -488,7 +488,7 @@ devvm looks for them only in the system's folders, never elsewhere on your `PATH
|
||||
|
||||
## History
|
||||
|
||||
Each VM's transcripts and sessions stay in that VM. `devvm history export [FILE]` saves them, and `devvm rm` saves them before it deletes a VM that has an agent. The export is a `.tar.gz` of the agents' history in the VM, <!-- the agents' history, generated from internal/agents by mise run cli-docs -->`~/.claude`, `~/.claude.json`, `~/.codex`, `~/.local/share/opencode`, `~/.local/state/opencode`, `~/.pi/agent/sessions` and `~/.cursor/chats`<!-- end of the agents' history -->, written to FILE or to `~/.local/share/devvm/exports/<vm>-<date>-<time>.tar.gz`. An export in that folder gets a `<vm>-<date>-<time>.folder` file beside it, which names the VM's project folder and the VM's [network tier](../safety/network.md#network-tiers) when devvm wrote the export. The agents' logins are never in an export, nor is the key that the machines opencode pairs trust. An export holds at most 2 GiB ([what an export holds](../internals/agents.md#history-exports)). The commands:
|
||||
Each VM's transcripts and sessions stay in that VM. `devvm history export [FILE]` saves them, and `devvm rm` saves them before it deletes a VM that has an agent. The export is a `.tar.gz` of the agents' history in the VM, <!-- the agents' history, generated from internal/agents by mise run cli-docs -->`~/.claude`, `~/.claude.json`, `~/.codex`, `~/.local/share/opencode`, `~/.local/state/opencode`, `~/.pi/agent/sessions` and `~/.cursor/chats`<!-- end of the agents' history -->, written to FILE or to `~/.local/share/devvm/exports/<vm>-<date>-<time>.tar.gz`. An export in that folder gets a `<vm>-<date>-<time>.folder` file beside it, which names the VM's project folder and the VM's [network tier](../safety/network.md#network-tiers) when devvm wrote the export. The agents' logins are never in an export, and neither is the key that every machine paired with the VM's opencode trusts. An export holds at most 2 GiB ([what an export holds](../internals/agents.md#history-exports)). The commands:
|
||||
|
||||
```sh
|
||||
devvm history # list the exports devvm saved
|
||||
@@ -538,7 +538,15 @@ devvm history import ~/backup.tar.gz # or an export of your own
|
||||
- When devvm makes a new VM that has an agent, and it saved an export for the same folder before, it offers that export. In a terminal it asks whether to import it into the new VM, with no as the default. Without a terminal, or with `--no-input`, it doesn't ask, and it says which export it found and that `devvm history import` in the folder puts it into the VM. devvm imports the export once the VM has started and before its setup, and if the import fails, devvm warns and makes the VM anyway, so you can run `devvm history import` later.
|
||||
- An export holds what a VM wrote, so devvm treats it as untrusted, and when it comes from a VM on a less strict tier than the VM you import it into, devvm warns you before it imports. It treats an export with no tier recorded, or a FILE elsewhere, as if it came from an open VM. When an export holds a path outside the agents' history folders, devvm imports nothing.
|
||||
- The import leaves out what devvm puts in the VM itself. That's the agents' logins, `~/.claude/.credentials.json`, with the old VM's own MCP servers' logins in it, `~/.codex/auth.json`, and opencode's `auth.json`, `account.json`, `mcp-auth.json` and `bin`. It's also `~/.claude.json`, whose copy in the old VM held that VM's own placeholders, and every agent's [mounted folders and copied files](#devvms-agent-store), which the new VM's setup links and copies from devvm's agent store.
|
||||
- The import also leaves out what was the old VM's own as a machine, which an export leaves out too: opencode's `~/.local/state/opencode/machine`, with the key that the machines opencode paired trust, and its `service.json` and `pty`, which hold the password of the old VM's opencode service and the access tokens of its terminals' daemons. The new VM's opencode makes its own.
|
||||
- The import also leaves out the old VM's opencode identity, as an export does: opencode's `~/.local/state/opencode/machine`, with the key that every machine paired with the old VM's opencode trusts, and its `service.json`, or `service-<channel>.json` for another channel's opencode, and `pty`, which hold the password of the old VM's opencode service and the access tokens of its terminals' daemons. The new VM's opencode makes its own.
|
||||
- opencode's sessions come without what opencode would act on without asking. Neither an export nor an import keeps:
|
||||
- automations, whose shell commands run on their schedule without asking again
|
||||
- the requests you said always to allow
|
||||
- subagents' jobs and queued messages
|
||||
- a project's commands
|
||||
- opencode's git repositories and worktrees
|
||||
|
||||
No session resumes its turn on its own, and each session keeps only its deny and ask rules ([what an export holds](../internals/agents.md#history-exports)). In the new VM, make again any automation you want, and opencode asks again before the requests you had always allowed. `devvm rm` deletes opencode's worktrees with the VM, so commit the work in them first, and their commits stay in your project's repository.
|
||||
- A file or folder the VM already has stays as it is, so importing into a VM that has history of its own adds the export's files without replacing any of its own.
|
||||
|
||||
## The VM's setup
|
||||
|
||||
@@ -329,8 +329,10 @@ type Def struct {
|
||||
// HistoryExcludes what of that an export leaves out and an import never writes: its logins.
|
||||
History, HistoryExcludes []string
|
||||
// HistoryOwn is what of its History is the VM's own as a machine, such as a private key
|
||||
// that other machines trust: an export leaves it out and an import never writes it, as
|
||||
// HistoryExcludes, but a VM made again keeps it, as that's the same machine.
|
||||
// that other machines trust, or what another VM must never take from it, such as a git
|
||||
// repository whose config can name a command that the agent's git runs: an export leaves
|
||||
// it out and an import never writes it, as HistoryExcludes, but a VM made again keeps
|
||||
// it, as that's the same machine.
|
||||
HistoryOwn []string
|
||||
// Env is the guest environment its VMs' shells get: its self-updates and telemetry off.
|
||||
Env []Env
|
||||
@@ -460,14 +462,21 @@ var Defs = []Def{
|
||||
},
|
||||
// From opencode v2.4.1's source, what of its state folder is its machine's own:
|
||||
// machine/home-key, the private Ed25519 key of its home, which every machine it pairs
|
||||
// trusts and which it never replaces; service.json, its background service's
|
||||
// registration, with the service's password, which is its name on the latest channel,
|
||||
// the one devvm installs (other channels' are service-<channel>.json), and its
|
||||
// service.json.pty-handoff, a terminal's handoff ticket; and pty, its terminals'
|
||||
// daemons' sockets and the access tokens they take.
|
||||
// trusts and which it never replaces; its background service's registration, with the
|
||||
// service's password, service.json on its latest, dev, beta and next channels and
|
||||
// service-<channel>.json on the others (service-registration.ts, registration.rs),
|
||||
// written through <file>.<id>.tmp, beside <file>.pty-handoff, a terminal's handoff
|
||||
// ticket, written through <file>.pty-handoff.<uuid>.tmp (handoff.rs); and pty, its
|
||||
// terminals' daemons' sockets and the access tokens they take. Of its data folder, its git
|
||||
// repositories, whose config and attributes can name commands that git runs, such as a
|
||||
// clean filter or core.fsmonitor, which opencode's own git commands would then run in
|
||||
// another VM: snapshot, a repository for each project's snapshots, which opencode uses
|
||||
// again when it's there (snapshot.ts), repos, its cache of repositories, and worktree,
|
||||
// its git worktrees. A pattern holds *, as GNU tar's --exclude and the shell read it.
|
||||
HistoryOwn: []string{
|
||||
OpencodeState + "/machine", OpencodeState + "/service.json", OpencodeState + "/service.json.pty-handoff",
|
||||
OpencodeState + "/pty",
|
||||
OpencodeState + "/machine", OpencodeState + "/service.json", OpencodeState + "/service-*.json",
|
||||
OpencodeState + "/service.json.*", OpencodeState + "/service-*.json.*", OpencodeState + "/pty",
|
||||
OpencodeData + "/snapshot", OpencodeData + "/repos", OpencodeData + "/worktree",
|
||||
},
|
||||
Env: []Env{{Name: "OPENCODE_DISABLE_AUTOUPDATE", Value: "1"}},
|
||||
// Its Codex login to OpenAI (its methods chatgpt-browser and chatgpt-headless), whose
|
||||
|
||||
@@ -35,8 +35,6 @@ func dynamicScripts() map[string]string {
|
||||
"internal/backend/lima/remount.go check": "a fixed mountpoint test around quoted paths",
|
||||
"internal/vm/mountcache.go script": "a fixed mountpoint test around a quoted path",
|
||||
"internal/vm/agentsave.go agentSaveScript(agents)": "built from the agents' registry: internal/vm's TestBuiltScriptsShellcheck checks it",
|
||||
"internal/vm/lifecycle.go historyExport()": "built from the agents' registry: internal/vm's TestBuiltScriptsShellcheck checks it",
|
||||
"internal/vm/lifecycle.go historyImport()": "built from the agents' registry: internal/vm's TestBuiltScriptsShellcheck checks it",
|
||||
"internal/devcontainer/devcontainer.go s": "a devcontainer.json's own command, the user's, not devvm's",
|
||||
"internal/vm/opencode.go string(script)": "assets/guest/opencode.sh, which lint:code's shellcheck checks with the assets",
|
||||
"internal/vm/paste.go script": "assets/guest/paste.sh, through pasteArgv, which lint:code's shellcheck checks with the assets",
|
||||
|
||||
@@ -391,10 +391,11 @@ func devvmGoroutineSites() map[string]string {
|
||||
func devvmUnboundedReads() map[string]string {
|
||||
const stub = "the test stubs' standard input, which devvm under test writes and closes, in a stub run only by the CLI tests"
|
||||
return map[string]string{
|
||||
"internal/ui/status.go: tail": "the run's own log, which only this run writes, read from its last size bytes",
|
||||
"internal/stubtest/stub/guest.go: guest.logScript": stub,
|
||||
"internal/stubtest/stub/stub.go: call.copyIn": stub,
|
||||
"internal/stubtest/stub/control.go: control": stub,
|
||||
"internal/ui/status.go: tail": "the run's own log, which only this run writes, read from its last size bytes",
|
||||
"internal/stubtest/stub/guest.go: guest.logScript": stub,
|
||||
"internal/stubtest/stub/guest.go: guest.inputScript": stub,
|
||||
"internal/stubtest/stub/stub.go: call.copyIn": stub,
|
||||
"internal/stubtest/stub/control.go: control": stub,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -20,11 +21,14 @@ import (
|
||||
// its second line, past its #! line or devvm's prelude, appended to $STUB_DIR/scripts, a
|
||||
// VM's setup is $STUB_DIR/sync.tar, a base build's packages
|
||||
// $STUB_DIR/packages-in.tar, what a remake puts in a new disk's home
|
||||
// $STUB_DIR/home-in.tgz, and an import of agents' history
|
||||
// $STUB_DIR/history-in.tgz. Its switches, in $STUB_DIR:
|
||||
// $STUB_DIR/home-in.tgz, an import of agents' history
|
||||
// $STUB_DIR/history-in.tgz, and the script of an export of agents' history,
|
||||
// which comes first on its input (inputScript), $STUB_DIR/history-export.sh, and an
|
||||
// import's script $STUB_DIR/history-import.sh. Its
|
||||
// switches, in $STUB_DIR:
|
||||
//
|
||||
// shell-fails every shell fails
|
||||
// shell-fails-on a shell whose arguments hold its text fails (a home folder's copy and
|
||||
// shell-fails-on a shell whose arguments, or script on its input, hold its text fails (a home folder's copy and
|
||||
// a --clone VM's git too)
|
||||
// shell-hangs every shell hangs (touching hanging first)
|
||||
// shell-waits-on a shell whose arguments hold its text touches waiting, then waits
|
||||
@@ -55,7 +59,15 @@ import (
|
||||
// paste-in where paste.sh put's stdin goes, with its folder and name in paste-put
|
||||
type guest struct {
|
||||
*call
|
||||
vm string // the VM's name, "" over ssh
|
||||
vm string // the VM's name, "" over ssh
|
||||
script string // the script the shell read on its input (logScript, inputScript)
|
||||
}
|
||||
|
||||
// mentions reports whether the shell's arguments, or the script it read
|
||||
// on its input, hold the text of the switch name.
|
||||
func (g *guest) mentions(name string) bool {
|
||||
t, ok := g.text(name)
|
||||
return ok && strings.Contains(g.joined()+"\n"+g.script, t)
|
||||
}
|
||||
|
||||
// shellPrefix starts the command line Exec gives limactl shell: the
|
||||
@@ -81,6 +93,9 @@ func (l *lima) shell() int {
|
||||
if strings.Join(g.args[max(0, len(g.args)-2):], " ") == "bash -s" || strings.HasSuffix(g.joined(), "exec 'bash' '-s'") {
|
||||
g.logScript()
|
||||
}
|
||||
if strings.Contains(g.joined(), "s=$(dd bs=1 count=") {
|
||||
g.inputScript()
|
||||
}
|
||||
if code, done := g.files(); done {
|
||||
return code
|
||||
}
|
||||
@@ -146,11 +161,13 @@ func (g *guest) git(words []string) int {
|
||||
// prelude, one eval line in place of its #! line (image.WithPrelude), with
|
||||
// any exports for a company proxy or the user's CAs before it on the same
|
||||
// line, so its second line is its own second line too. It reads the whole
|
||||
// script.
|
||||
// script and keeps it, so files() knows a script by what's in it, as it
|
||||
// knows a command by its words.
|
||||
func (g *guest) logScript() {
|
||||
b, _ := io.ReadAll(g.stdin)
|
||||
g.stdin = bytes.NewReader(nil)
|
||||
lines := strings.Split(string(b), "\n")
|
||||
g.script = string(b)
|
||||
lines := strings.Split(g.script, "\n")
|
||||
line := ""
|
||||
if len(lines) > 1 {
|
||||
line = lines[1]
|
||||
@@ -158,10 +175,32 @@ func (g *guest) logScript() {
|
||||
g.logLine(g.path("scripts"), line)
|
||||
}
|
||||
|
||||
// inputScript takes the script that comes first on the shell's input, as
|
||||
// devvm's vm.onInput frames it, a line with its length then the script,
|
||||
// and leaves the rest as the shell's input, so files() knows the script by
|
||||
// what's in it and gets the rest, as an import's export.
|
||||
func (g *guest) inputScript() {
|
||||
b, _ := io.ReadAll(g.stdin)
|
||||
n, after, _ := strings.Cut(string(b), "\n")
|
||||
size, err := strconv.Atoi(n)
|
||||
if err != nil || size < 0 || size > len(after) {
|
||||
size = len(after)
|
||||
}
|
||||
g.script, g.stdin = after[:size], strings.NewReader(after[size:])
|
||||
}
|
||||
|
||||
// files answers what moves files in and out of the guest: a home folder's
|
||||
// copy, a base build's packages and a VM's setup.
|
||||
func (g *guest) files() (code int, done bool) {
|
||||
all := g.joined()
|
||||
all := g.joined() + "\n" + g.script
|
||||
for name, text := range map[string]string{"history-export.sh": "ls -d .claude ", "history-import.sh": "--quoting-style=escape"} {
|
||||
if !strings.Contains(g.script, text) {
|
||||
continue
|
||||
}
|
||||
if err := g.put(name, []byte(g.script)); err != nil {
|
||||
return g.status(err), true
|
||||
}
|
||||
}
|
||||
out, in := strings.Contains(all, "tar -czf - --one-file-system"), strings.Contains(all, "tar -xzf - --skip-old-files")
|
||||
switch {
|
||||
case (out || in) && g.mentions("shell-fails-on"):
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
@@ -726,6 +727,72 @@ func TestShellFloods(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// An export of agents' history on bash's input (bash -s): its script is
|
||||
// kept in history-export.sh, and the switches match it as they match a
|
||||
// command's words: shell-fails-on fails it, history-floods floods.
|
||||
func TestShellHistoryExportOnInput(t *testing.T) {
|
||||
s := newSandbox(t)
|
||||
export := "cd ~ && ls -d .claude .codex 2>/dev/null | tar -czf - ."
|
||||
script := strconv.Itoa(len(export)) + "\n" + export
|
||||
sh := []string{"shell", "--workdir", "/", "vm", "bash", "-c", `IFS= read -r n && s=$(dd bs=1 count="$n" 2>/dev/null) && exec bash -c "$s"`}
|
||||
s.ok(script, "limactl", sh...)
|
||||
if got := s.read("history-export.sh"); got != export {
|
||||
t.Errorf("history-export.sh %q", got)
|
||||
}
|
||||
// An import's script, then its export, which the import keeps.
|
||||
imp := "tar -xzf - --quoting-style=escape -C x"
|
||||
s.ok(strconv.Itoa(len(imp))+"\n"+imp+"the export", "limactl", sh...)
|
||||
if got := s.read("history-in.tgz"); got != "the export" {
|
||||
t.Errorf("history-in.tgz %q", got)
|
||||
}
|
||||
if err := os.Remove(filepath.Join(s.dir, "history-in.tgz")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(s.dir, "shell-fails-on"), []byte("ls -d .claude"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code, _, _ := s.run(script, "limactl", sh...); code != 1 {
|
||||
t.Errorf("shell-fails-on its script: %d", code)
|
||||
}
|
||||
if err := os.Remove(filepath.Join(s.dir, "shell-fails-on")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.touch("history-floods")
|
||||
s.stdout, s.stderr = &gone{left: 1 << 20}, &gone{left: 1 << 30}
|
||||
if code, _, _ := s.run(script, "limactl", sh...); code != 1 {
|
||||
t.Errorf("history-floods: %d", code)
|
||||
}
|
||||
s.stdout, s.stderr = nil, nil
|
||||
// A script it can't keep fails the shell, rather than leave a test reading an old one.
|
||||
if err := os.Remove(filepath.Join(s.dir, "history-export.sh")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(s.dir, "history-export.sh"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code, _, _ := s.run(script, "limactl", sh...); code == 0 {
|
||||
t.Error("a script it couldn't keep: 0")
|
||||
}
|
||||
// An import whose input it can't keep fails too.
|
||||
if err := os.Mkdir(filepath.Join(s.dir, "history-in.tgz"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code, _, _ := s.run(strconv.Itoa(len(imp))+"\n"+imp+"history", "limactl", sh...); code == 0 {
|
||||
t.Error("an import it couldn't keep: 0")
|
||||
}
|
||||
}
|
||||
|
||||
// On its switch, opencode.sh says opencode refused the provider the
|
||||
// switch names, and fails.
|
||||
func TestShellOpencodeRefuses(t *testing.T) {
|
||||
s := newSandbox(t)
|
||||
s.write("opencode-refuses", "openrouter\n")
|
||||
code, out, _ := s.run("", "limactl", "shell", "--workdir", "/", "vm", "sh", "-c", "cd '/' && exec 'bash' '-lc' 'script' 'opencode.sh'")
|
||||
if code != 1 || out != "devvm-opencode-failed openrouter\n" {
|
||||
t.Errorf("opencode.sh: %d, printed %q", code, out)
|
||||
}
|
||||
}
|
||||
|
||||
// A history import's tar: its input kept, and refused as unsafe on its
|
||||
// switch.
|
||||
func TestShellHistory(t *testing.T) {
|
||||
|
||||
+93
-11
@@ -66,6 +66,72 @@ const opencodeLogins = `type = 'table' AND name NOT LIKE 'sqlite\_%' ESCAPE '\'
|
||||
`JOIN pragma_table_info(m.name) c WHERE m.type = 'table' AND lower(c.name) IN ('secret', 'access_token', ` +
|
||||
`'refresh_token', 'id_token', 'api_key', 'apikey', 'password', 'token', 'credential', 'credentials')))`
|
||||
|
||||
// opencodeUnattended is the SQL condition that picks the tables of
|
||||
// opencode's database whose rows let something run in the VM without
|
||||
// asking, which an exported database brings from another VM, from
|
||||
// opencode v2.4.1's source: automation, each automation's trigger and the
|
||||
// shell command it runs on it, which opencode approved once, as it was
|
||||
// made, and never asks about again (core/src/automation/shell.ts);
|
||||
// permission, the requests you said always to allow in a project; job,
|
||||
// the subagents' jobs, which its service starts again when it starts
|
||||
// (core/src/session/execution/restart.ts); and session_inbox, the
|
||||
// messages queued for a session's next turn. Any table whose name starts
|
||||
// as theirs is picked too, so one a later opencode adds for them is.
|
||||
// What else runs without asking is a column (opencodeNulled,
|
||||
// opencodeAllowRules).
|
||||
const opencodeUnattended = `type = 'table' AND (name LIKE 'automation%' OR name LIKE 'permission%' OR name LIKE 'job%' ` +
|
||||
`OR name LIKE 'session_inbox%')`
|
||||
|
||||
// opencodeNulled is the SQL condition that picks the columns, of every
|
||||
// table (c, of m), that opencodeClean sets to NULL: time_suspended, which
|
||||
// marks a session whose turn opencode's service resumes on its own when it
|
||||
// starts (session_v2), and commands, a project's commands, whose start
|
||||
// command opencode runs with bash -lc for each worktree it makes
|
||||
// (core/src/worktree.ts). Names are compared in lower case, as SQLite
|
||||
// reads them.
|
||||
const opencodeNulled = `FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = 'table' ` +
|
||||
`AND lower(c.name) IN ('time_suspended', 'commands')`
|
||||
|
||||
// opencodeAllowRules is the SQL that keeps only the deny and ask rules of
|
||||
// the permission column of a table, a printf format that names the table
|
||||
// (%w) twice: opencode 2.4's session_v2 keeps each session's rules there,
|
||||
// a JSON array of {action, resource, effect}, and a session imported with
|
||||
// an allow rule would run what it allows without asking. A value that
|
||||
// isn't such an array becomes NULL, no rules, and so does a rule that
|
||||
// isn't an object with a text action. Each rule kept is written again
|
||||
// from the values sqlite3 read, so a key written twice, which sqlite3
|
||||
// reads first and opencode's JSON.parse last, can't keep an allow
|
||||
// effect behind a deny; a resource that isn't text becomes "*", every
|
||||
// resource, as opencode's Permission.Rule needs one. opencodeAllowLeft
|
||||
// counts the rows whose value is still anything else, a rule that isn't
|
||||
// in the form written again included. Each reads JSON only where CASE
|
||||
// has found it valid, as sqlite3's AND and OR may read both sides and
|
||||
// fail on what isn't JSON.
|
||||
const (
|
||||
opencodeAllowRules = `UPDATE "%w" SET permission = NULL WHERE permission IS NOT NULL AND ` +
|
||||
`CASE WHEN json_valid(permission) THEN json_type(permission) IS NOT 'array' ELSE 1 END; ` +
|
||||
`UPDATE "%w" SET permission = (SELECT json_group_array(json_object('action', json_extract(r.value, '$.action'), ` +
|
||||
`'resource', CASE WHEN json_type(r.value, '$.resource') = 'text' THEN json_extract(r.value, '$.resource') ELSE '*' END, ` +
|
||||
`'effect', json_extract(r.value, '$.effect'))) FROM json_each(permission) AS r ` +
|
||||
`WHERE CASE WHEN r.type = 'object' THEN json_type(r.value, '$.action') = 'text' ` +
|
||||
`AND json_extract(r.value, '$.effect') IN ('deny', 'ask') ELSE 0 END) WHERE permission IS NOT NULL;`
|
||||
opencodeAllowLeft = `SELECT count(*) FROM "%w" WHERE permission IS NOT NULL AND CASE WHEN NOT json_valid(permission) THEN 1 ` +
|
||||
`WHEN json_type(permission) IS NOT 'array' THEN 1 ELSE EXISTS (SELECT 1 FROM json_each(permission) AS r WHERE ` +
|
||||
`CASE WHEN r.type = 'object' THEN coalesce(json_extract(r.value, '$.effect') IN ('deny', 'ask'), 0) = 0 ` +
|
||||
`OR json_type(r.value, '$.action') IS NOT 'text' OR r.value IS NOT json_object('action', json_extract(r.value, '$.action'), ` +
|
||||
`'resource', CASE WHEN json_type(r.value, '$.resource') = 'text' THEN json_extract(r.value, '$.resource') ELSE '*' END, ` +
|
||||
`'effect', json_extract(r.value, '$.effect')) ELSE 1 END) END;`
|
||||
// opencodeRuleTables picks the tables with a permission column, its
|
||||
// name in any case, as SQLite reads it.
|
||||
opencodeRuleTables = `FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = 'table' AND lower(c.name) = 'permission'`
|
||||
)
|
||||
|
||||
// opencodeHidden is the SQL that counts the columns of the database's
|
||||
// tables that pragma_table_info doesn't list, a generated column's or a
|
||||
// virtual table's, which opencodeClean's steps would miss, so a copy with
|
||||
// any fails its check. opencode's own tables have none.
|
||||
const opencodeHidden = `SELECT count(*) FROM sqlite_master m JOIN pragma_table_xinfo(m.name) c WHERE m.type = 'table' AND c.hidden != 0;`
|
||||
|
||||
// opencodeAuthImport is opencode 2's migration that imports auth.json
|
||||
// into its credential table, once. opencodeClean takes its record out,
|
||||
// so the opencode that next opens the copy imports the logins devvm's
|
||||
@@ -81,16 +147,22 @@ const opencodeWellknown = `key LIKE 'wellknown:config:%'`
|
||||
|
||||
// opencodeClean is the shell function devvm_opencode_clean DB, which
|
||||
// makes clean.db in the current folder: a copy of opencode's database
|
||||
// DB without its logins. sqlite3 copies it with VACUUM INTO, which reads
|
||||
// DB without its logins, nor anything that would run without asking in
|
||||
// the VM that gets it. sqlite3 copies it with VACUUM INTO, which reads
|
||||
// the database with what its -wal file holds, as one snapshot; in the
|
||||
// copy it drops every trigger, empties the tables opencodeLogins picks,
|
||||
// deletes the kv rows opencodeWellknown picks and takes
|
||||
// opencodeAuthImport's record out, then turns WAL off and rebuilds the
|
||||
// file (secure_delete and VACUUM), so no page of it keeps a deleted row.
|
||||
// It fails when the VM has no sqlite3, when any step fails, when the
|
||||
// copy has fewer tables than DB or none, or unless each count of rows
|
||||
// left (the triggers, each table it emptied, kv's rows it deleted)
|
||||
// prints 0, so a sqlite3 that runs nothing and prints nothing fails too;
|
||||
// copy it drops every trigger and view, empties the tables opencodeLogins
|
||||
// and opencodeUnattended pick, sets the columns opencodeNulled picks to
|
||||
// NULL, keeps only the deny and ask rules of each permission column
|
||||
// (opencodeAllowRules), deletes the kv rows opencodeWellknown picks and
|
||||
// takes opencodeAuthImport's record out, then turns WAL off and rebuilds
|
||||
// the file (secure_delete and VACUUM), so no page of it keeps a deleted
|
||||
// row. It fails when the VM has no sqlite3, or one without JSON, when any
|
||||
// step fails, when the copy has fewer tables than DB or none, or unless
|
||||
// each count left (the triggers and views, the generated columns
|
||||
// (opencodeHidden), each table it emptied, each column it set to NULL,
|
||||
// each permission column's rules that aren't deny or ask, kv's rows it
|
||||
// deleted) prints 0, so a sqlite3 that runs nothing and prints nothing
|
||||
// fails too;
|
||||
// the caller then leaves the database out. The schema's own functions stay off
|
||||
// (trusted_schema), as an imported database is the export's: each
|
||||
// sqlite3 gets that pragma first in its own input, never in -cmd, as
|
||||
@@ -99,13 +171,22 @@ const opencodeWellknown = `key LIKE 'wellknown:config:%'`
|
||||
func opencodeClean() string {
|
||||
// opencodeWellknown in an SQL string literal, its quotes doubled.
|
||||
wellknown := strings.ReplaceAll(opencodeWellknown, "'", "''")
|
||||
allowRules, allowLeft := strings.ReplaceAll(opencodeAllowRules, "'", "''"), strings.ReplaceAll(opencodeAllowLeft, "'", "''")
|
||||
gen := `SELECT printf('DROP TRIGGER IF EXISTS "%w";', name) FROM sqlite_master WHERE type = 'trigger';` + "\n" +
|
||||
`SELECT printf('DROP VIEW IF EXISTS "%w";', name) FROM sqlite_master WHERE type = 'view';` + "\n" +
|
||||
`SELECT printf('DELETE FROM "%w";', name) FROM sqlite_master WHERE ` + opencodeLogins + ";\n" +
|
||||
`SELECT printf('DELETE FROM "%w";', name) FROM sqlite_master WHERE ` + opencodeUnattended + ";\n" +
|
||||
`SELECT printf('UPDATE "%w" SET "%w" = NULL;', m.name, c.name) ` + opencodeNulled + ";\n" +
|
||||
`SELECT printf('` + allowRules + `', m.name, m.name) ` + opencodeRuleTables + ";\n" +
|
||||
`SELECT 'DELETE FROM migration WHERE id = ''` + opencodeAuthImport + `'';' FROM sqlite_master ` +
|
||||
`WHERE type = 'table' AND name = 'migration';` + "\n" +
|
||||
`SELECT 'DELETE FROM kv WHERE ` + wellknown + `;' FROM sqlite_master WHERE type = 'table' AND name = 'kv';`
|
||||
check := `SELECT 'SELECT count(*) FROM sqlite_master WHERE type = ''trigger'';';` + "\n" +
|
||||
check := `SELECT 'SELECT count(*) FROM sqlite_master WHERE type IN (''trigger'', ''view'');';` + "\n" +
|
||||
`SELECT '` + strings.ReplaceAll(opencodeHidden, "'", "''") + `';` + "\n" +
|
||||
`SELECT printf('SELECT count(*) FROM "%w";', name) FROM sqlite_master WHERE ` + opencodeLogins + ";\n" +
|
||||
`SELECT printf('SELECT count(*) FROM "%w";', name) FROM sqlite_master WHERE ` + opencodeUnattended + ";\n" +
|
||||
`SELECT printf('SELECT count(*) FROM "%w" WHERE "%w" IS NOT NULL;', m.name, c.name) ` + opencodeNulled + ";\n" +
|
||||
`SELECT printf('` + allowLeft + `', m.name) ` + opencodeRuleTables + ";\n" +
|
||||
`SELECT 'SELECT count(*) FROM kv WHERE ` + wellknown + `;' FROM sqlite_master WHERE type = 'table' AND name = 'kv';`
|
||||
const untrusted = "PRAGMA trusted_schema = OFF;"
|
||||
tables := shell.Quote("SELECT count(*) FROM sqlite_master WHERE type = 'table';")
|
||||
@@ -282,7 +363,8 @@ func historyImport() string {
|
||||
`find "$t/x" -type l -print0 | while IFS= read -r -d '' l; do`,
|
||||
` case $(readlink "$l") in /* | .. | ../* | */.. | */../*) echo "devvm: left out the link $l" >&2; rm -f "$l" ;; esac`,
|
||||
"done",
|
||||
`for p in ` + shell.QuoteJoin(importSkips()) + `; do rm -rf "$t/x/$p"; done`,
|
||||
"# shellcheck disable=SC2231 # each is a path or a pattern (agents.Def's HistoryOwn), which the loop expands",
|
||||
`for p in ` + shell.QuoteJoin(importSkips()) + `; do for f in "$t/x/"$p; do rm -rf "$f"; done; done`,
|
||||
opencodeClean(),
|
||||
`o="$t/x/"` + shell.Quote(opencodeData),
|
||||
`for f in "$o"/` + strings.Join(opencodeDBs[1:], ` "$o"/`) + `; do rm -rf "$f"; done`,
|
||||
|
||||
@@ -176,11 +176,18 @@ func TestHistoryImportScript(t *testing.T) {
|
||||
if !slices.IsSorted(skips) || len(slices.Compact(slices.Clone(skips))) != len(skips) {
|
||||
t.Errorf("skips %q aren't sorted once each", skips)
|
||||
}
|
||||
// The clean-up after unpacking expands each one unquoted, as a pattern, so each is only of a
|
||||
// path's plain characters and *: no space, ? or [ that would split it or match more.
|
||||
for _, p := range skips {
|
||||
if strings.Trim(p, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._/-*") != "" {
|
||||
t.Errorf("skip %q isn't a plain path or pattern", p)
|
||||
}
|
||||
}
|
||||
s := historyImport()
|
||||
for _, want := range []string{
|
||||
`tar -tzf "$t/export" --absolute-names --quoting-style=escape`, "grep -vqE '^(\\.claude|\\.claude\\.json|\\.codex|",
|
||||
`grep -qE '(^|/)(\.\.?)?/|(^|/)\.\.?$'`, "echo " + historyUnsafe + "; exit 1",
|
||||
`; do rm -rf "$t/x/$p"; done`,
|
||||
`; do for f in "$t/x/"$p; do rm -rf "$f"; done; done`,
|
||||
`tar -xzf "$t/export" -C "$t/x" '--no-same-owner' '--no-same-permissions' '--anchored' '--exclude=`,
|
||||
"'--exclude=.claude.json' ", `find "$t/x" -type l`, "/* | .. | ../* | */.. | */../*) ",
|
||||
"for p in '.claude' '.claude.json' '.codex' '.local/share/opencode' '.local/state/opencode' '.pi/agent/sessions'",
|
||||
@@ -306,7 +313,9 @@ func TestHistoryImportRuns(t *testing.T) {
|
||||
".claude/link->/etc", ".claude/projects/up->../../.bashrc", ".claude/projects/in->p.jsonl", ".codex/",
|
||||
".codex/sessions/s", ".codex/auth.json", ".local/share/opencode/auth.json", ".local/state/opencode/x",
|
||||
opencodeState+"/machine/", opencodeHomeKey, opencodeState+"/service.json", opencodeState+"/pty/d/service.json",
|
||||
opencodeState+"/service.json.pty-handoff",
|
||||
opencodeState+"/service.json.pty-handoff", opencodeState+"/service-local.json", opencodeState+"/service.json.0a1b.tmp",
|
||||
opencodeState+"/service.json.pty-handoff.0a1b.tmp", opencodeState+"/service-local.json.pty-handoff",
|
||||
opencodeData+"/snapshot/p/h/config", opencodeData+"/repos/r/config", opencodeData+"/worktree/w/.git",
|
||||
".pi/agent/sessions/", ".pi/agent/sessions/--p--/s.jsonl")
|
||||
if out, err := runImport(t, home, export); err != nil {
|
||||
t.Fatalf("%q, %v", out, err)
|
||||
@@ -315,8 +324,11 @@ func TestHistoryImportRuns(t *testing.T) {
|
||||
".claude/projects/p.jsonl": true, ".codex/sessions/s": true, ".local/state/opencode/x": true, ".claude/projects/in": true,
|
||||
".pi/agent/sessions/--p--/s.jsonl": true, ".pi/agent/auth.json": true,
|
||||
opencodeHomeKey: false, opencodeState + "/machine": false, opencodeState + "/service.json": false, opencodeState + "/pty": false,
|
||||
opencodeState + "/service.json.pty-handoff": false,
|
||||
".claude/.credentials.json": false, ".claude/settings.json": false, ".claude/skills": false, ".claude.json": false,
|
||||
opencodeState + "/service.json.pty-handoff": false, opencodeState + "/service-local.json": false,
|
||||
opencodeState + "/service.json.0a1b.tmp": false, opencodeState + "/service.json.pty-handoff.0a1b.tmp": false,
|
||||
opencodeState + "/service-local.json.pty-handoff": false,
|
||||
opencodeData + "/snapshot": false, opencodeData + "/repos": false, opencodeData + "/worktree": false,
|
||||
".claude/.credentials.json": false, ".claude/settings.json": false, ".claude/skills": false, ".claude.json": false,
|
||||
".codex/auth.json": false, ".local/share/opencode/auth.json": false, ".claude/link": false, ".claude/projects/up": false,
|
||||
} {
|
||||
if _, err := os.Lstat(filepath.Join(home, p)); (err == nil) != want {
|
||||
@@ -375,7 +387,9 @@ func TestHistoryImportRuns(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
cmd := exec.CommandContext(t.Context(), "bash", "-c", historyExport()) //nolint:gosec // devvm's own export script
|
||||
argv, in := onInput(historyExport(), nil)
|
||||
cmd := exec.CommandContext(t.Context(), argv[0], argv[1:]...) //nolint:gosec // devvm's own command, its script on its input
|
||||
cmd.Stdin = in
|
||||
cmd.Env = []string{"HOME=" + from, "PATH=" + os.Getenv("PATH")}
|
||||
export, err := cmd.Output()
|
||||
if err != nil {
|
||||
@@ -473,10 +487,11 @@ func TestHistoryImportV010(t *testing.T) {
|
||||
// VM's user does, and returns what it printed.
|
||||
func runImport(t *testing.T, home string, export []byte) (string, error) {
|
||||
t.Helper()
|
||||
cmd := exec.CommandContext(t.Context(), "bash", "-c", historyImport()) //nolint:gosec // devvm's own import script
|
||||
argv, in := onInput(historyImport(), bytes.NewReader(export))
|
||||
cmd := exec.CommandContext(t.Context(), argv[0], argv[1:]...) //nolint:gosec // devvm's own command, its script on its input
|
||||
cmd.Env = []string{"HOME=" + home, "PATH=" + os.Getenv("PATH")}
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stdin, cmd.Stderr = bytes.NewReader(export), &stderr
|
||||
cmd.Stdin, cmd.Stderr = in, &stderr
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
t.Logf("tar's stderr: %s", stderr.String())
|
||||
|
||||
@@ -387,7 +387,8 @@ func (e Lifecycle) export(ctx context.Context, t *target, file string, failed er
|
||||
run, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
w := &bounded{to: out, max: cmp.Or(e.HistoryMax, historyMax), cancel: cancel}
|
||||
err = t.exec(run, []string{"bash", "-c", historyExport()}, backend.ExecOpts{Stdout: w, Stderr: e.vmLog()})
|
||||
argv, in := onInput(historyExport(), nil)
|
||||
err = t.exec(run, argv, backend.ExecOpts{Stdin: in, Stdout: w, Stderr: e.vmLog()})
|
||||
if cerr := out.Close(); err == nil {
|
||||
err = cerr
|
||||
}
|
||||
@@ -453,7 +454,8 @@ func importHistory(ctx context.Context, e *Env, t *target, file string) error {
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
out := &bounded{max: len(historyUnsafe) + 1}
|
||||
err = t.exec(ctx, []string{"bash", "-c", historyImport()}, backend.ExecOpts{Stdin: f, Stdout: out, Stderr: e.vmLog()})
|
||||
argv, in := onInput(historyImport(), f)
|
||||
err = t.exec(ctx, argv, backend.ExecOpts{Stdin: in, Stdout: out, Stderr: e.vmLog()})
|
||||
switch {
|
||||
case err == nil:
|
||||
case ctx.Err() != nil:
|
||||
|
||||
@@ -4,9 +4,12 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -18,6 +21,95 @@ import (
|
||||
"github.com/devvmhq/devvm/internal/vmname"
|
||||
)
|
||||
|
||||
// inputScript is the script a fake Exec got on its input (onInput) and
|
||||
// the rest of that input, or "" for any other command. It reads that
|
||||
// input.
|
||||
func inputScript(argv []string, o backend.ExecOpts) (script string, rest []byte) {
|
||||
if !slices.Equal(argv, []string{"bash", "-c", onInputCmd}) || o.Stdin == nil {
|
||||
return "", nil
|
||||
}
|
||||
b, _ := io.ReadAll(o.Stdin)
|
||||
n, after, _ := strings.Cut(string(b), "\n")
|
||||
size, err := strconv.Atoi(n)
|
||||
if err != nil || size > len(after) {
|
||||
return "", nil
|
||||
}
|
||||
return after[:size], []byte(after[size:])
|
||||
}
|
||||
|
||||
// exportScript is the export of agents' history that a fake Exec got on
|
||||
// its input, or "" for any other command. It reads that input.
|
||||
func exportScript(argv []string, o backend.ExecOpts) string {
|
||||
if s, _ := inputScript(argv, o); strings.Contains(s, "tar -czf") {
|
||||
return s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// The export's and the import's scripts go on the VM's bash's input,
|
||||
// never in its arguments, which ssh's shared connection on macOS fails to
|
||||
// pass at their length; the import's export follows its script.
|
||||
func TestHistoryScriptsOnInput(t *testing.T) {
|
||||
e, f, _ := upEnv(t, allNative())
|
||||
existingVM(t, e, Options{Agents: &[]string{"claude"}, Network: "open"})
|
||||
var scripts []string
|
||||
var rest []byte
|
||||
f.ExecFunc = func(_ vmname.VM, argv []string, o backend.ExecOpts) error {
|
||||
if s, r := inputScript(argv, o); s != "" {
|
||||
scripts, rest = append(scripts, s), r
|
||||
}
|
||||
for _, a := range argv {
|
||||
if len(a) > 4096 {
|
||||
t.Errorf("an argument of %d bytes: %.80q", len(a), a)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
file := filepath.Join(t.TempDir(), "h.tar.gz")
|
||||
if err := (Lifecycle{e}).Export(t.Context(), file); err != nil {
|
||||
t.Fatal(msg.NamesOf(err))
|
||||
}
|
||||
if err := os.WriteFile(file, []byte("the export"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := (Lifecycle{e}).Import(t.Context(), file); err != nil {
|
||||
t.Fatal(msg.NamesOf(err))
|
||||
}
|
||||
want := []string{strings.TrimRight(historyExport(), "\n"), strings.TrimRight(historyImport(), "\n")}
|
||||
if !slices.Equal(scripts, want) || string(rest) != "the export" {
|
||||
t.Errorf("the scripts on the input: %d, rest %q", len(scripts), rest)
|
||||
}
|
||||
}
|
||||
|
||||
// onInput's command runs its script, with the rest of its input as the
|
||||
// script's, only when it read the whole script: an input cut short, even
|
||||
// to a whole command, runs nothing.
|
||||
func TestOnInputCutShort(t *testing.T) {
|
||||
script := "mkdir ran\ncat > rest\n"
|
||||
argv, in := onInput(script, strings.NewReader("the rest"))
|
||||
b, err := io.ReadAll(in)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
full := string(b)
|
||||
for _, n := range []int{len(full), 1, len(full) / 2, strings.Index(full, "cat")} {
|
||||
dir := t.TempDir()
|
||||
cmd := exec.CommandContext(t.Context(), argv[0], argv[1:]...) //nolint:gosec // devvm's own command, its script on its input
|
||||
cmd.Dir, cmd.Stdin = dir, strings.NewReader(full[:n])
|
||||
err := cmd.Run()
|
||||
_, ran := os.Stat(filepath.Join(dir, "ran"))
|
||||
if n == len(full) {
|
||||
if err != nil || ran != nil || readFile(t, filepath.Join(dir, "rest")) != "the rest" {
|
||||
t.Errorf("whole: %v, ran %v", err, ran)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err == nil || ran == nil {
|
||||
t.Errorf("cut at %d of %d: %v, it ran", n, len(full), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rm asks first in a terminal and refuses without one, unless --force;
|
||||
// --no-export deletes without the export.
|
||||
func TestRmConfirms(t *testing.T) {
|
||||
@@ -35,8 +127,8 @@ func TestRmConfirms(t *testing.T) {
|
||||
t.Fatal("deleted when declined")
|
||||
}
|
||||
exported := false
|
||||
f.ExecFunc = func(_ vmname.VM, argv []string, _ backend.ExecOpts) error {
|
||||
exported = exported || (len(argv) == 3 && strings.Contains(argv[2], "tar -czf"))
|
||||
f.ExecFunc = func(_ vmname.VM, argv []string, o backend.ExecOpts) error {
|
||||
exported = exported || exportScript(argv, o) != ""
|
||||
return nil
|
||||
}
|
||||
if err := lc.Rm(t.Context(), RmOptions{Force: true, NoExport: true}); err != nil {
|
||||
@@ -55,8 +147,8 @@ func TestRm(t *testing.T) {
|
||||
lc := Lifecycle{e}
|
||||
st := existingVM(t, e, Options{Agents: &[]string{"claude"}, Network: "open"})
|
||||
vm := st.Name().String()
|
||||
f.ExecFunc = func(_ vmname.VM, argv []string, _ backend.ExecOpts) error {
|
||||
if len(argv) == 3 && strings.Contains(argv[2], "tar -czf") {
|
||||
f.ExecFunc = func(_ vmname.VM, argv []string, o backend.ExecOpts) error {
|
||||
if exportScript(argv, o) != "" {
|
||||
return errors.New("tar failed")
|
||||
}
|
||||
return nil
|
||||
@@ -72,8 +164,8 @@ func TestRm(t *testing.T) {
|
||||
}
|
||||
var script string
|
||||
f.ExecFunc = func(_ vmname.VM, argv []string, o backend.ExecOpts) error {
|
||||
if len(argv) == 3 && strings.Contains(argv[2], "tar -czf") {
|
||||
script = argv[2]
|
||||
if s := exportScript(argv, o); s != "" {
|
||||
script = s
|
||||
_, err := o.Stdout.Write([]byte("tarball"))
|
||||
return err
|
||||
}
|
||||
@@ -130,7 +222,7 @@ func TestRm(t *testing.T) {
|
||||
// streamForever is a VM's export that never ends: it writes until a
|
||||
// write fails, its stderr too, as a VM's root can.
|
||||
func streamForever(argv []string, o backend.ExecOpts) error {
|
||||
if len(argv) != 3 || !strings.Contains(argv[2], "tar -czf") {
|
||||
if exportScript(argv, o) == "" {
|
||||
return nil
|
||||
}
|
||||
chunk := []byte(strings.Repeat("x", 64<<10))
|
||||
@@ -317,7 +409,7 @@ func TestExport(t *testing.T) {
|
||||
vm := existingVM(t, e, Options{Network: "open"}).Name().String()
|
||||
tarball := "tarball"
|
||||
f.ExecFunc = func(_ vmname.VM, argv []string, o backend.ExecOpts) error {
|
||||
if len(argv) == 3 && strings.Contains(argv[2], "tar -czf") {
|
||||
if exportScript(argv, o) != "" {
|
||||
if tarball == "" {
|
||||
_, _ = o.Stdout.Write([]byte("partial"))
|
||||
return errors.New("tar failed")
|
||||
@@ -410,7 +502,7 @@ func TestExportStartsAsLaunch(t *testing.T) {
|
||||
switch {
|
||||
case argv[0] == "curl" && !direct:
|
||||
return errors.New("curl: (7) Failed to connect")
|
||||
case len(argv) == 3 && strings.Contains(argv[2], "tar -czf"):
|
||||
case exportScript(argv, o) != "":
|
||||
_, err := o.Stdout.Write([]byte("tarball"))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
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.
|
||||
const onInputCmd = `IFS= read -r n && s=$(dd bs=1 count="$n" 2>/dev/null) && [ "$(printf %s "$s" | wc -c)" -eq "$n" ] && exec bash -c "$s" bash`
|
||||
|
||||
// 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)
|
||||
}
|
||||
+131
-11
@@ -304,6 +304,21 @@ func plantSchemaRows(t *testing.T, db string, emptied, kept []string) []string {
|
||||
continue
|
||||
}
|
||||
v := "devvm-planted-" + table + "-" + c[0]
|
||||
if c[0] == "commands" {
|
||||
// A project's commands, its start command among them, which the copy
|
||||
// sets to NULL.
|
||||
values = append(values, "'"+v+"'")
|
||||
continue
|
||||
}
|
||||
if slices.Contains(kept, table) && c[0] == "permission" {
|
||||
// A kept table's permission rules, as session_v2 holds a session's: its
|
||||
// allow rule goes, its deny and ask rules stay.
|
||||
deny, ask := "devvm-kept-"+table+"-deny", "devvm-kept-"+table+"-ask"
|
||||
keptValues = append(keptValues, deny, ask)
|
||||
values = append(values, `'[{"action":"`+v+`","resource":"*","effect":"allow"},{"action":"`+deny+`","resource":"*","effect":"deny"},`+
|
||||
`{"action":"`+ask+`","resource":"*","effect":"ask"}]'`)
|
||||
continue
|
||||
}
|
||||
if slices.Contains(kept, table) {
|
||||
v = "devvm-kept-" + table + "-" + c[0]
|
||||
keptValues = append(keptValues, v)
|
||||
@@ -326,17 +341,26 @@ func plantSchemaRows(t *testing.T, db string, emptied, kept []string) []string {
|
||||
// fetched, and every other table's row, the session's among them, is
|
||||
// kept. machine, each paired machine's public key, which lets it log in
|
||||
// to the VM's home, is emptied as the VM's own pairings; the home's
|
||||
// private key is a file of its own (opencodeHomeKey).
|
||||
// private key is a file of its own (opencodeHomeKey). What would run
|
||||
// without asking in the VM that imports it goes: automation, whose shell
|
||||
// actions run unattended, permission, the requests you said always to
|
||||
// allow, job, the subagents' jobs its service starts again, and
|
||||
// session_inbox, a session's queued messages, are emptied
|
||||
// (opencodeUnattended); a session's permission rules lose their allow
|
||||
// rules, a suspended session no longer resumes on its own, and a project
|
||||
// loses its commands (opencodeNulled).
|
||||
func TestOpencodeCleanSchema(t *testing.T) {
|
||||
needSqlite(t)
|
||||
schema, err := os.ReadFile(opencodeFixture)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
emptied := []string{"account", "account_state", "control_account", "credential", "machine"}
|
||||
emptied := []string{
|
||||
"account", "account_state", "automation", "control_account", "credential", "job", "machine", "permission", "session_inbox",
|
||||
}
|
||||
kept := []string{
|
||||
"automation", "blob", "blob_ref", "event", "event_sequence", "instruction_blob", "instruction_entry",
|
||||
"instruction_state", "job", "permission", "project", "project_directory", "session_inbox",
|
||||
"blob", "blob_ref", "event", "event_sequence", "instruction_blob", "instruction_entry",
|
||||
"instruction_state", "project", "project_directory",
|
||||
"session_message", "session_part", "session_v2", "workspace", "worktree",
|
||||
}
|
||||
dir := t.TempDir()
|
||||
@@ -365,6 +389,92 @@ func TestOpencodeCleanSchema(t *testing.T) {
|
||||
"20261030054400_job\nwellknown:manifest:https://devvm-kept-org.example wellknown:sources\n" {
|
||||
t.Errorf("migrations and kv keys: %q", got)
|
||||
}
|
||||
// The session, which plantSchemaRows suspended (time_suspended 1), stays, but no longer
|
||||
// resumes on its own, and the project stays without its commands.
|
||||
if got := sqlite(t, copied, "SELECT count(*), count(time_suspended) FROM session_v2;\nSELECT count(*), count(commands) FROM project;\n"); got != "1|0\n1|0\n" {
|
||||
t.Errorf("sessions suspended and projects with commands: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// opencodeClean's copy keeps only the deny and ask rules of a session's
|
||||
// permission rules, in their order, each written again from what sqlite3
|
||||
// read: an allow rule goes, and so does a rule without an effect, without
|
||||
// a text action or that isn't an object, a key written twice keeps its
|
||||
// first value, a missing resource or one that isn't text becomes "*", any
|
||||
// other key goes, and a
|
||||
// value that isn't a JSON array of rules, such as opencode 1's table of
|
||||
// patterns, becomes no rules at all. A column named in another case is
|
||||
// read as SQLite reads it, and a later opencode's tables of automations,
|
||||
// saved permissions or jobs are emptied too.
|
||||
func TestOpencodeCleanSessionRules(t *testing.T) {
|
||||
needSqlite(t)
|
||||
dir := t.TempDir()
|
||||
db := filepath.Join(dir, "opencode.db")
|
||||
sqlite(t, db, "CREATE TABLE session_v2 (id text PRIMARY KEY, permission text);\n"+
|
||||
"CREATE TABLE other (id text PRIMARY KEY, PERMISSION text, Time_Suspended integer);\n"+
|
||||
"CREATE TABLE automation_run (id text PRIMARY KEY, command text);\n"+
|
||||
"CREATE TABLE permission_saved (id text PRIMARY KEY, resource text);\n"+
|
||||
"CREATE TABLE job_next (id text PRIMARY KEY);\n"+
|
||||
"INSERT INTO automation_run VALUES ('r', 'devvm-planted-run');\n"+
|
||||
"INSERT INTO permission_saved VALUES ('p', 'devvm-planted-saved');\n"+
|
||||
"INSERT INTO job_next VALUES ('j');\n"+
|
||||
`INSERT INTO other VALUES ('upper', '[{"action":"*","resource":"*","effect":"allow"}]', 5);`+"\n"+
|
||||
`INSERT INTO session_v2 VALUES ('mixed', '[{"action":"read","resource":"*","effect":"deny"},{"action":"bash","resource":"*","effect":"allow"},`+
|
||||
`{"action":"edit","effect":"ask"},{"action":"web"},"allow",{"action":"x","effect":"ALLOW"}]'), `+
|
||||
`('allow', '[{"action":"*","resource":"*","effect":"allow"}]'), ('table', '{"bash":"allow"}'), ('text', 'allow'), `+
|
||||
`('twice', '[{"action":"*","resource":"*","effect":"deny","effect":"allow"},{"action":1,"effect":"deny"},`+
|
||||
`{"action":"bash","resource":{"x":1},"effect":"ask","extra":"allow"}]'), `+
|
||||
`('none', NULL), ('empty', '[]');`+"\n")
|
||||
if err := runOpencodeClean(t, db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
copied := filepath.Join(dir, "clean.db")
|
||||
got := sqlite(t, copied, "SELECT id || ' ' || coalesce(permission, 'NULL') FROM session_v2 ORDER BY id;\n"+
|
||||
"SELECT coalesce(PERMISSION, 'NULL') || ' ' || coalesce(time_suspended, 'NULL') FROM other;\n"+
|
||||
"SELECT count(*) FROM automation_run;\nSELECT count(*) FROM permission_saved;\nSELECT count(*) FROM job_next;\n")
|
||||
// A key written twice is read first, as sqlite3 reads it, and written once, so opencode's
|
||||
// JSON.parse, which reads the last, finds the same effect.
|
||||
want := "allow []\nempty []\n" +
|
||||
`mixed [{"action":"read","resource":"*","effect":"deny"},{"action":"edit","resource":"*","effect":"ask"}]` + "\n" +
|
||||
"none NULL\ntable NULL\ntext NULL\n" +
|
||||
`twice [{"action":"*","resource":"*","effect":"deny"},{"action":"bash","resource":"*","effect":"ask"}]` + "\n" +
|
||||
"[] NULL\n0\n0\n0\n"
|
||||
if got != want {
|
||||
t.Errorf("the copy's rules:\n%s\nwant:\n%s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// opencodeClean makes no copy of a database that could hide rows from its
|
||||
// steps: a view in an emptied table's name over a table renamed out of
|
||||
// its reach is dropped and counted, and a generated permission column,
|
||||
// which pragma_table_info doesn't list, fails the check.
|
||||
func TestOpencodeCleanHidden(t *testing.T) {
|
||||
needSqlite(t)
|
||||
for name, schema := range map[string]string{
|
||||
"view": "CREATE TABLE zz (id text PRIMARY KEY, command text);\nINSERT INTO zz VALUES ('a', 'devvm-planted');\n" +
|
||||
"CREATE VIEW automation AS SELECT * FROM zz;\n",
|
||||
"generated": `CREATE TABLE session_v2 (id text PRIMARY KEY, permission text GENERATED ALWAYS AS ('[{"action":"*","effect":"allow"}]'));` +
|
||||
"\nINSERT INTO session_v2 (id) VALUES ('s');\n",
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
db := filepath.Join(dir, "opencode.db")
|
||||
sqlite(t, db, schema)
|
||||
err := runOpencodeClean(t, db)
|
||||
if name == "view" {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := sqlite(t, filepath.Join(dir, "clean.db"), "SELECT count(*) FROM sqlite_master WHERE type = 'view';\n"); got != "0\n" {
|
||||
t.Errorf("views left: %q", got)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err == nil {
|
||||
t.Error("a copy with a generated permission column passed its check")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// exportNames reads a gzipped tar stream: each member's name and, for a
|
||||
@@ -398,7 +508,7 @@ func exportNames(t *testing.T, export []byte) map[string][]byte {
|
||||
func pathWithout(t *testing.T, with bool) string {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
cmds := []string{"bash", "cat", "find", "grep", "gzip", "ls", "mkdir", "mktemp", "mv", "readlink", "rm", "tar"}
|
||||
cmds := []string{"bash", "cat", "dd", "find", "grep", "gzip", "ls", "mkdir", "mktemp", "mv", "readlink", "rm", "tar", "wc"}
|
||||
if with {
|
||||
cmds = append(cmds, "sqlite3")
|
||||
}
|
||||
@@ -433,7 +543,10 @@ func TestHistoryExportRuns(t *testing.T) {
|
||||
".claude/projects/p.jsonl", ".claude/.credentials.json", opencodeData + "/auth.json",
|
||||
opencodeData + "/mcp-auth.json", opencodeData + "/storage/s.json", ".local/state/opencode/kv.json",
|
||||
opencodeHomeKey, opencodeState + "/service.json", opencodeState + "/pty/d/service.json",
|
||||
opencodeState + "/service.json.pty-handoff",
|
||||
opencodeState + "/service.json.pty-handoff", opencodeState + "/service-local.json",
|
||||
opencodeState + "/service.json.0a1b.tmp", opencodeState + "/service.json.pty-handoff.0a1b.tmp",
|
||||
opencodeState + "/service-local.json.pty-handoff", opencodeState + "/services.json",
|
||||
opencodeData + "/snapshot/p/h/config", opencodeData + "/repos/r/config", opencodeData + "/worktree/w/.git",
|
||||
piSessions + "/--p--/s.jsonl", piDir + "/auth.json", piDir + "/settings.json",
|
||||
} {
|
||||
if err := state.WriteFile(filepath.Join(home, f), []byte(f)); err != nil {
|
||||
@@ -446,7 +559,10 @@ func TestHistoryExportRuns(t *testing.T) {
|
||||
} else if err := state.WriteFile(db, []byte(plantedKey)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.CommandContext(t.Context(), "bash", "-c", historyExport()) //nolint:gosec // devvm's own export script
|
||||
// As the VM runs it: on bash's input.
|
||||
argv, in := onInput(historyExport(), nil)
|
||||
cmd := exec.CommandContext(t.Context(), argv[0], argv[1:]...) //nolint:gosec // devvm's own command, its script on its input
|
||||
cmd.Stdin = in
|
||||
cmd.Env = []string{"HOME=" + home, "PATH=" + pathWithout(t, with)}
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
@@ -461,8 +577,11 @@ func TestHistoryExportRuns(t *testing.T) {
|
||||
opencodeData + "/opencode.db": with, opencodeData + "/opencode.db-wal": false, opencodeData + "/opencode.db-shm": false,
|
||||
piSessions + "/--p--/s.jsonl": true, piDir + "/auth.json": false, piDir + "/settings.json": false,
|
||||
opencodeHomeKey: false, opencodeState + "/machine/": false, opencodeState + "/service.json": false,
|
||||
opencodeState + "/service.json.pty-handoff": false,
|
||||
opencodeState + "/pty/d/service.json": false,
|
||||
opencodeState + "/service.json.pty-handoff": false, opencodeState + "/service-local.json": false,
|
||||
opencodeState + "/service.json.0a1b.tmp": false, opencodeState + "/service.json.pty-handoff.0a1b.tmp": false,
|
||||
opencodeState + "/service-local.json.pty-handoff": false, opencodeState + "/services.json": true,
|
||||
opencodeData + "/snapshot/p/h/config": false, opencodeData + "/repos/r/config": false, opencodeData + "/worktree/w/.git": false,
|
||||
opencodeState + "/pty/d/service.json": false,
|
||||
} {
|
||||
if _, ok := got[f]; ok != want {
|
||||
t.Errorf("%s: in the export %v, want %v", f, ok, want)
|
||||
@@ -539,9 +658,10 @@ func TestHistoryImportCleansOpencode(t *testing.T) {
|
||||
files[db] = data
|
||||
}
|
||||
home := t.TempDir()
|
||||
cmd := exec.CommandContext(t.Context(), "bash", "-c", historyImport()) //nolint:gosec // devvm's own import script
|
||||
argv, in := onInput(historyImport(), bytes.NewReader(tarGz(t, []string{db, wal, opencodeData + "/storage/s.json"}, files)))
|
||||
cmd := exec.CommandContext(t.Context(), argv[0], argv[1:]...) //nolint:gosec // devvm's own command, its script on its input
|
||||
cmd.Env = []string{"HOME=" + home, "PATH=" + pathWithout(t, with)}
|
||||
cmd.Stdin = bytes.NewReader(tarGz(t, []string{db, wal, opencodeData + "/storage/s.json"}, files))
|
||||
cmd.Stdin = in
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("%v: %s", err, out)
|
||||
}
|
||||
|
||||
@@ -381,8 +381,9 @@ func TestAddLayersAsks(t *testing.T) {
|
||||
if c.Method != "Exec" {
|
||||
continue
|
||||
}
|
||||
if argv, _ := c.Args[1].([]string); len(argv) == 3 && (argv[2] == homeOut || argv[2] == homeIn || strings.Contains(argv[2], "tar -czf")) {
|
||||
t.Errorf("--clean-home --no-export ran %q", argv[2])
|
||||
argv, _ := c.Args[1].([]string)
|
||||
if len(argv) == 3 && (argv[2] == homeOut || argv[2] == homeIn || argv[2] == onInputCmd) {
|
||||
t.Errorf("--clean-home --no-export ran %q", argv)
|
||||
}
|
||||
}
|
||||
said = nil
|
||||
|
||||
+24
-7
@@ -161,8 +161,8 @@ listed .pi/agent/extensions/e.ts true pi .pi/agent/extensions true true
|
||||
listed .pi/agent/sessions/s false false false
|
||||
listed .pi/agent/sessions/s true false false
|
||||
history paths .claude .claude.json .codex .local/share/opencode .local/state/opencode .pi/agent/sessions .cursor/chats
|
||||
history excludes .claude/.credentials.json .codex/auth.json .local/share/opencode/auth.json .local/share/opencode/account.json .local/share/opencode/mcp-auth.json .local/share/opencode/bin .local/state/opencode/machine .local/state/opencode/service.json .local/state/opencode/service.json.pty-handoff .local/state/opencode/pty
|
||||
import skips .claude.json .claude/.credentials.json .claude/CLAUDE.md .claude/agents .claude/commands .claude/output-styles .claude/plugins .claude/plugins-seed .claude/settings.json .claude/skills .codex/AGENTS.md .codex/auth.json .codex/config.toml .codex/prompts .codex/skills .cursor/cli-config.json .cursor/commands .cursor/mcp.json .cursor/rules .local/share/opencode/account.json .local/share/opencode/auth.json .local/share/opencode/bin .local/share/opencode/mcp-auth.json .local/state/opencode/machine .local/state/opencode/pty .local/state/opencode/service.json .local/state/opencode/service.json.pty-handoff .pi/agent/AGENTS.md .pi/agent/APPEND_SYSTEM.md .pi/agent/SYSTEM.md .pi/agent/extensions .pi/agent/keybindings.json .pi/agent/mcp.json .pi/agent/models.json .pi/agent/prompts .pi/agent/settings.json .pi/agent/skills .pi/agent/themes
|
||||
history excludes .claude/.credentials.json .codex/auth.json .local/share/opencode/auth.json .local/share/opencode/account.json .local/share/opencode/mcp-auth.json .local/share/opencode/bin .local/state/opencode/machine .local/state/opencode/service.json .local/state/opencode/service-*.json .local/state/opencode/service.json.* .local/state/opencode/service-*.json.* .local/state/opencode/pty .local/share/opencode/snapshot .local/share/opencode/repos .local/share/opencode/worktree
|
||||
import skips .claude.json .claude/.credentials.json .claude/CLAUDE.md .claude/agents .claude/commands .claude/output-styles .claude/plugins .claude/plugins-seed .claude/settings.json .claude/skills .codex/AGENTS.md .codex/auth.json .codex/config.toml .codex/prompts .codex/skills .cursor/cli-config.json .cursor/commands .cursor/mcp.json .cursor/rules .local/share/opencode/account.json .local/share/opencode/auth.json .local/share/opencode/bin .local/share/opencode/mcp-auth.json .local/share/opencode/repos .local/share/opencode/snapshot .local/share/opencode/worktree .local/state/opencode/machine .local/state/opencode/pty .local/state/opencode/service-*.json .local/state/opencode/service-*.json.* .local/state/opencode/service.json .local/state/opencode/service.json.* .pi/agent/AGENTS.md .pi/agent/APPEND_SYSTEM.md .pi/agent/SYSTEM.md .pi/agent/extensions .pi/agent/keybindings.json .pi/agent/mcp.json .pi/agent/models.json .pi/agent/prompts .pi/agent/settings.json .pi/agent/skills .pi/agent/themes
|
||||
save script, every agent
|
||||
set -o pipefail
|
||||
cd ~ || exit 1
|
||||
@@ -195,12 +195,20 @@ devvm_opencode_clean() {
|
||||
case $t in '' | 0 | *[!0-9]*) return 1 ;; esac
|
||||
[ "$(sqlite3 -bail clean.db 'PRAGMA trusted_schema = OFF;' 'SELECT count(*) FROM sqlite_master WHERE type = '\''table'\'';')" = "$t" ] &&
|
||||
s=$(sqlite3 -bail clean.db 'PRAGMA trusted_schema = OFF;' 'SELECT printf('\''DROP TRIGGER IF EXISTS "%w";'\'', name) FROM sqlite_master WHERE type = '\''trigger'\'';
|
||||
SELECT printf('\''DROP VIEW IF EXISTS "%w";'\'', name) FROM sqlite_master WHERE type = '\''view'\'';
|
||||
SELECT printf('\''DELETE FROM "%w";'\'', name) FROM sqlite_master WHERE type = '\''table'\'' AND name NOT LIKE '\''sqlite\_%'\'' ESCAPE '\''\'\'' AND (name = '\''machine'\'' OR name LIKE '\''%credential%'\'' OR name LIKE '\''%account%'\'' OR name LIKE '\''%auth%'\'' OR name LIKE '\''%secret%'\'' OR name LIKE '\''%token%'\'' OR name LIKE '\''%share%'\'' OR name IN (SELECT m.name FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) IN ('\''secret'\'', '\''access_token'\'', '\''refresh_token'\'', '\''id_token'\'', '\''api_key'\'', '\''apikey'\'', '\''password'\'', '\''token'\'', '\''credential'\'', '\''credentials'\'')));
|
||||
SELECT printf('\''DELETE FROM "%w";'\'', name) FROM sqlite_master WHERE type = '\''table'\'' AND (name LIKE '\''automation%'\'' OR name LIKE '\''permission%'\'' OR name LIKE '\''job%'\'' OR name LIKE '\''session_inbox%'\'');
|
||||
SELECT printf('\''UPDATE "%w" SET "%w" = NULL;'\'', m.name, c.name) FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) IN ('\''time_suspended'\'', '\''commands'\'');
|
||||
SELECT printf('\''UPDATE "%w" SET permission = NULL WHERE permission IS NOT NULL AND CASE WHEN json_valid(permission) THEN json_type(permission) IS NOT '\'''\''array'\'''\'' ELSE 1 END; UPDATE "%w" SET permission = (SELECT json_group_array(json_object('\'''\''action'\'''\'', json_extract(r.value, '\'''\''$.action'\'''\''), '\'''\''resource'\'''\'', CASE WHEN json_type(r.value, '\'''\''$.resource'\'''\'') = '\'''\''text'\'''\'' THEN json_extract(r.value, '\'''\''$.resource'\'''\'') ELSE '\'''\''*'\'''\'' END, '\'''\''effect'\'''\'', json_extract(r.value, '\'''\''$.effect'\'''\''))) FROM json_each(permission) AS r WHERE CASE WHEN r.type = '\'''\''object'\'''\'' THEN json_type(r.value, '\'''\''$.action'\'''\'') = '\'''\''text'\'''\'' AND json_extract(r.value, '\'''\''$.effect'\'''\'') IN ('\'''\''deny'\'''\'', '\'''\''ask'\'''\'') ELSE 0 END) WHERE permission IS NOT NULL;'\'', m.name, m.name) FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) = '\''permission'\'';
|
||||
SELECT '\''DELETE FROM migration WHERE id = '\'''\''20260805200742_import_legacy_credentials'\'''\'';'\'' FROM sqlite_master WHERE type = '\''table'\'' AND name = '\''migration'\'';
|
||||
SELECT '\''DELETE FROM kv WHERE key LIKE '\'''\''wellknown:config:%'\'''\'';'\'' FROM sqlite_master WHERE type = '\''table'\'' AND name = '\''kv'\'';') &&
|
||||
printf 'PRAGMA trusted_schema = OFF;\nPRAGMA journal_mode = DELETE;\nPRAGMA secure_delete = ON;\n%s\nVACUUM;\n' "$s" | sqlite3 -bail clean.db >/dev/null &&
|
||||
c=$(sqlite3 -bail clean.db 'PRAGMA trusted_schema = OFF;' 'SELECT '\''SELECT count(*) FROM sqlite_master WHERE type = '\'''\''trigger'\'''\'';'\'';
|
||||
c=$(sqlite3 -bail clean.db 'PRAGMA trusted_schema = OFF;' 'SELECT '\''SELECT count(*) FROM sqlite_master WHERE type IN ('\'''\''trigger'\'''\'', '\'''\''view'\'''\'');'\'';
|
||||
SELECT '\''SELECT count(*) FROM sqlite_master m JOIN pragma_table_xinfo(m.name) c WHERE m.type = '\'''\''table'\'''\'' AND c.hidden != 0;'\'';
|
||||
SELECT printf('\''SELECT count(*) FROM "%w";'\'', name) FROM sqlite_master WHERE type = '\''table'\'' AND name NOT LIKE '\''sqlite\_%'\'' ESCAPE '\''\'\'' AND (name = '\''machine'\'' OR name LIKE '\''%credential%'\'' OR name LIKE '\''%account%'\'' OR name LIKE '\''%auth%'\'' OR name LIKE '\''%secret%'\'' OR name LIKE '\''%token%'\'' OR name LIKE '\''%share%'\'' OR name IN (SELECT m.name FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) IN ('\''secret'\'', '\''access_token'\'', '\''refresh_token'\'', '\''id_token'\'', '\''api_key'\'', '\''apikey'\'', '\''password'\'', '\''token'\'', '\''credential'\'', '\''credentials'\'')));
|
||||
SELECT printf('\''SELECT count(*) FROM "%w";'\'', name) FROM sqlite_master WHERE type = '\''table'\'' AND (name LIKE '\''automation%'\'' OR name LIKE '\''permission%'\'' OR name LIKE '\''job%'\'' OR name LIKE '\''session_inbox%'\'');
|
||||
SELECT printf('\''SELECT count(*) FROM "%w" WHERE "%w" IS NOT NULL;'\'', m.name, c.name) FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) IN ('\''time_suspended'\'', '\''commands'\'');
|
||||
SELECT printf('\''SELECT count(*) FROM "%w" WHERE permission IS NOT NULL AND CASE WHEN NOT json_valid(permission) THEN 1 WHEN json_type(permission) IS NOT '\'''\''array'\'''\'' THEN 1 ELSE EXISTS (SELECT 1 FROM json_each(permission) AS r WHERE CASE WHEN r.type = '\'''\''object'\'''\'' THEN coalesce(json_extract(r.value, '\'''\''$.effect'\'''\'') IN ('\'''\''deny'\'''\'', '\'''\''ask'\'''\''), 0) = 0 OR json_type(r.value, '\'''\''$.action'\'''\'') IS NOT '\'''\''text'\'''\'' OR r.value IS NOT json_object('\'''\''action'\'''\'', json_extract(r.value, '\'''\''$.action'\'''\''), '\'''\''resource'\'''\'', CASE WHEN json_type(r.value, '\'''\''$.resource'\'''\'') = '\'''\''text'\'''\'' THEN json_extract(r.value, '\'''\''$.resource'\'''\'') ELSE '\'''\''*'\'''\'' END, '\'''\''effect'\'''\'', json_extract(r.value, '\'''\''$.effect'\'''\'')) ELSE 1 END) END;'\'', m.name) FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) = '\''permission'\'';
|
||||
SELECT '\''SELECT count(*) FROM kv WHERE key LIKE '\'''\''wellknown:config:%'\'''\'';'\'' FROM sqlite_master WHERE type = '\''table'\'' AND name = '\''kv'\'';') && [ -n "$c" ] &&
|
||||
left=$(printf 'PRAGMA trusted_schema = OFF;\n%s\n' "$c" | sqlite3 -bail clean.db) && [ -n "$left" ] &&
|
||||
[ "$(printf '%s\n' "$left" | grep -cx 0)" = "$(printf '%s\n' "$c" | grep -c '')" ] &&
|
||||
@@ -220,18 +228,19 @@ for db in "$HOME"/'.local/share/opencode'/opencode*.db; do
|
||||
:
|
||||
done
|
||||
[ "${#add[@]}" -eq 0 ] || add=(-C "$t" "${add[@]}")
|
||||
cd ~ && ls -d .claude .claude.json .codex .local/share/opencode .local/state/opencode .pi/agent/sessions .cursor/chats 2>/dev/null | tar -czf - '--exclude=.claude/.credentials.json' '--exclude=.codex/auth.json' '--exclude=.local/share/opencode/auth.json' '--exclude=.local/share/opencode/account.json' '--exclude=.local/share/opencode/mcp-auth.json' '--exclude=.local/share/opencode/bin' '--exclude=.local/state/opencode/machine' '--exclude=.local/state/opencode/service.json' '--exclude=.local/state/opencode/service.json.pty-handoff' '--exclude=.local/state/opencode/pty' '--exclude=.claude/plugins' '--no-wildcards-match-slash' '--exclude=.local/share/opencode/opencode*.db' '--exclude=.local/share/opencode/opencode*.db-wal' '--exclude=.local/share/opencode/opencode*.db-shm' '--exclude=.local/share/opencode/opencode*.db-journal' '--transform=flags=r;s,^devvm-clean/,.local/share/opencode/,' -T - ${add[@]+"${add[@]}"}
|
||||
cd ~ && ls -d .claude .claude.json .codex .local/share/opencode .local/state/opencode .pi/agent/sessions .cursor/chats 2>/dev/null | tar -czf - '--exclude=.claude/.credentials.json' '--exclude=.codex/auth.json' '--exclude=.local/share/opencode/auth.json' '--exclude=.local/share/opencode/account.json' '--exclude=.local/share/opencode/mcp-auth.json' '--exclude=.local/share/opencode/bin' '--exclude=.local/state/opencode/machine' '--exclude=.local/state/opencode/service.json' '--exclude=.local/state/opencode/service-*.json' '--exclude=.local/state/opencode/service.json.*' '--exclude=.local/state/opencode/service-*.json.*' '--exclude=.local/state/opencode/pty' '--exclude=.local/share/opencode/snapshot' '--exclude=.local/share/opencode/repos' '--exclude=.local/share/opencode/worktree' '--exclude=.claude/plugins' '--no-wildcards-match-slash' '--exclude=.local/share/opencode/opencode*.db' '--exclude=.local/share/opencode/opencode*.db-wal' '--exclude=.local/share/opencode/opencode*.db-shm' '--exclude=.local/share/opencode/opencode*.db-journal' '--transform=flags=r;s,^devvm-clean/,.local/share/opencode/,' -T - ${add[@]+"${add[@]}"}
|
||||
import script
|
||||
set -o pipefail
|
||||
mkdir -p ~/.cache && t=$(mktemp -d ~/.cache/devvm-import.XXXXXX) || exit 1
|
||||
trap 'rm -rf "$t"' EXIT
|
||||
cat > "$t/export" && tar -tzf "$t/export" --absolute-names --quoting-style=escape > "$t/names" || exit 1
|
||||
if grep -vE '(^|/)\._[^/]*$' "$t/names" | grep -vqE '^(\.claude|\.claude\.json|\.codex|\.local/share/opencode|\.local/state/opencode|\.pi/agent/sessions|\.cursor/chats)(/|$)' || grep -qE '(^|/)(\.\.?)?/|(^|/)\.\.?$' "$t/names"; then echo devvm-history-unsafe; exit 1; fi
|
||||
mkdir "$t/x" && tar -xzf "$t/export" -C "$t/x" '--no-same-owner' '--no-same-permissions' '--anchored' '--exclude=.claude.json' '--exclude=.claude/.credentials.json' '--exclude=.claude/CLAUDE.md' '--exclude=.claude/agents' '--exclude=.claude/commands' '--exclude=.claude/output-styles' '--exclude=.claude/plugins' '--exclude=.claude/plugins-seed' '--exclude=.claude/settings.json' '--exclude=.claude/skills' '--exclude=.codex/AGENTS.md' '--exclude=.codex/auth.json' '--exclude=.codex/config.toml' '--exclude=.codex/prompts' '--exclude=.codex/skills' '--exclude=.cursor/cli-config.json' '--exclude=.cursor/commands' '--exclude=.cursor/mcp.json' '--exclude=.cursor/rules' '--exclude=.local/share/opencode/account.json' '--exclude=.local/share/opencode/auth.json' '--exclude=.local/share/opencode/bin' '--exclude=.local/share/opencode/mcp-auth.json' '--exclude=.local/state/opencode/machine' '--exclude=.local/state/opencode/pty' '--exclude=.local/state/opencode/service.json' '--exclude=.local/state/opencode/service.json.pty-handoff' '--exclude=.pi/agent/AGENTS.md' '--exclude=.pi/agent/APPEND_SYSTEM.md' '--exclude=.pi/agent/SYSTEM.md' '--exclude=.pi/agent/extensions' '--exclude=.pi/agent/keybindings.json' '--exclude=.pi/agent/mcp.json' '--exclude=.pi/agent/models.json' '--exclude=.pi/agent/prompts' '--exclude=.pi/agent/settings.json' '--exclude=.pi/agent/skills' '--exclude=.pi/agent/themes' '--exclude=._*' '--exclude=*/._*' || exit 1
|
||||
mkdir "$t/x" && tar -xzf "$t/export" -C "$t/x" '--no-same-owner' '--no-same-permissions' '--anchored' '--exclude=.claude.json' '--exclude=.claude/.credentials.json' '--exclude=.claude/CLAUDE.md' '--exclude=.claude/agents' '--exclude=.claude/commands' '--exclude=.claude/output-styles' '--exclude=.claude/plugins' '--exclude=.claude/plugins-seed' '--exclude=.claude/settings.json' '--exclude=.claude/skills' '--exclude=.codex/AGENTS.md' '--exclude=.codex/auth.json' '--exclude=.codex/config.toml' '--exclude=.codex/prompts' '--exclude=.codex/skills' '--exclude=.cursor/cli-config.json' '--exclude=.cursor/commands' '--exclude=.cursor/mcp.json' '--exclude=.cursor/rules' '--exclude=.local/share/opencode/account.json' '--exclude=.local/share/opencode/auth.json' '--exclude=.local/share/opencode/bin' '--exclude=.local/share/opencode/mcp-auth.json' '--exclude=.local/share/opencode/repos' '--exclude=.local/share/opencode/snapshot' '--exclude=.local/share/opencode/worktree' '--exclude=.local/state/opencode/machine' '--exclude=.local/state/opencode/pty' '--exclude=.local/state/opencode/service-*.json' '--exclude=.local/state/opencode/service-*.json.*' '--exclude=.local/state/opencode/service.json' '--exclude=.local/state/opencode/service.json.*' '--exclude=.pi/agent/AGENTS.md' '--exclude=.pi/agent/APPEND_SYSTEM.md' '--exclude=.pi/agent/SYSTEM.md' '--exclude=.pi/agent/extensions' '--exclude=.pi/agent/keybindings.json' '--exclude=.pi/agent/mcp.json' '--exclude=.pi/agent/models.json' '--exclude=.pi/agent/prompts' '--exclude=.pi/agent/settings.json' '--exclude=.pi/agent/skills' '--exclude=.pi/agent/themes' '--exclude=._*' '--exclude=*/._*' || exit 1
|
||||
find "$t/x" -type l -print0 | while IFS= read -r -d '' l; do
|
||||
case $(readlink "$l") in /* | .. | ../* | */.. | */../*) echo "devvm: left out the link $l" >&2; rm -f "$l" ;; esac
|
||||
done
|
||||
for p in '.claude.json' '.claude/.credentials.json' '.claude/CLAUDE.md' '.claude/agents' '.claude/commands' '.claude/output-styles' '.claude/plugins' '.claude/plugins-seed' '.claude/settings.json' '.claude/skills' '.codex/AGENTS.md' '.codex/auth.json' '.codex/config.toml' '.codex/prompts' '.codex/skills' '.cursor/cli-config.json' '.cursor/commands' '.cursor/mcp.json' '.cursor/rules' '.local/share/opencode/account.json' '.local/share/opencode/auth.json' '.local/share/opencode/bin' '.local/share/opencode/mcp-auth.json' '.local/state/opencode/machine' '.local/state/opencode/pty' '.local/state/opencode/service.json' '.local/state/opencode/service.json.pty-handoff' '.pi/agent/AGENTS.md' '.pi/agent/APPEND_SYSTEM.md' '.pi/agent/SYSTEM.md' '.pi/agent/extensions' '.pi/agent/keybindings.json' '.pi/agent/mcp.json' '.pi/agent/models.json' '.pi/agent/prompts' '.pi/agent/settings.json' '.pi/agent/skills' '.pi/agent/themes'; do rm -rf "$t/x/$p"; done
|
||||
# shellcheck disable=SC2231 # each is a path or a pattern (agents.Def's HistoryOwn), which the loop expands
|
||||
for p in '.claude.json' '.claude/.credentials.json' '.claude/CLAUDE.md' '.claude/agents' '.claude/commands' '.claude/output-styles' '.claude/plugins' '.claude/plugins-seed' '.claude/settings.json' '.claude/skills' '.codex/AGENTS.md' '.codex/auth.json' '.codex/config.toml' '.codex/prompts' '.codex/skills' '.cursor/cli-config.json' '.cursor/commands' '.cursor/mcp.json' '.cursor/rules' '.local/share/opencode/account.json' '.local/share/opencode/auth.json' '.local/share/opencode/bin' '.local/share/opencode/mcp-auth.json' '.local/share/opencode/repos' '.local/share/opencode/snapshot' '.local/share/opencode/worktree' '.local/state/opencode/machine' '.local/state/opencode/pty' '.local/state/opencode/service-*.json' '.local/state/opencode/service-*.json.*' '.local/state/opencode/service.json' '.local/state/opencode/service.json.*' '.pi/agent/AGENTS.md' '.pi/agent/APPEND_SYSTEM.md' '.pi/agent/SYSTEM.md' '.pi/agent/extensions' '.pi/agent/keybindings.json' '.pi/agent/mcp.json' '.pi/agent/models.json' '.pi/agent/prompts' '.pi/agent/settings.json' '.pi/agent/skills' '.pi/agent/themes'; do for f in "$t/x/"$p; do rm -rf "$f"; done; done
|
||||
devvm_opencode_clean() {
|
||||
local t s c left
|
||||
rm -f clean.db clean.db-journal clean.db-wal clean.db-shm &&
|
||||
@@ -239,12 +248,20 @@ devvm_opencode_clean() {
|
||||
case $t in '' | 0 | *[!0-9]*) return 1 ;; esac
|
||||
[ "$(sqlite3 -bail clean.db 'PRAGMA trusted_schema = OFF;' 'SELECT count(*) FROM sqlite_master WHERE type = '\''table'\'';')" = "$t" ] &&
|
||||
s=$(sqlite3 -bail clean.db 'PRAGMA trusted_schema = OFF;' 'SELECT printf('\''DROP TRIGGER IF EXISTS "%w";'\'', name) FROM sqlite_master WHERE type = '\''trigger'\'';
|
||||
SELECT printf('\''DROP VIEW IF EXISTS "%w";'\'', name) FROM sqlite_master WHERE type = '\''view'\'';
|
||||
SELECT printf('\''DELETE FROM "%w";'\'', name) FROM sqlite_master WHERE type = '\''table'\'' AND name NOT LIKE '\''sqlite\_%'\'' ESCAPE '\''\'\'' AND (name = '\''machine'\'' OR name LIKE '\''%credential%'\'' OR name LIKE '\''%account%'\'' OR name LIKE '\''%auth%'\'' OR name LIKE '\''%secret%'\'' OR name LIKE '\''%token%'\'' OR name LIKE '\''%share%'\'' OR name IN (SELECT m.name FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) IN ('\''secret'\'', '\''access_token'\'', '\''refresh_token'\'', '\''id_token'\'', '\''api_key'\'', '\''apikey'\'', '\''password'\'', '\''token'\'', '\''credential'\'', '\''credentials'\'')));
|
||||
SELECT printf('\''DELETE FROM "%w";'\'', name) FROM sqlite_master WHERE type = '\''table'\'' AND (name LIKE '\''automation%'\'' OR name LIKE '\''permission%'\'' OR name LIKE '\''job%'\'' OR name LIKE '\''session_inbox%'\'');
|
||||
SELECT printf('\''UPDATE "%w" SET "%w" = NULL;'\'', m.name, c.name) FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) IN ('\''time_suspended'\'', '\''commands'\'');
|
||||
SELECT printf('\''UPDATE "%w" SET permission = NULL WHERE permission IS NOT NULL AND CASE WHEN json_valid(permission) THEN json_type(permission) IS NOT '\'''\''array'\'''\'' ELSE 1 END; UPDATE "%w" SET permission = (SELECT json_group_array(json_object('\'''\''action'\'''\'', json_extract(r.value, '\'''\''$.action'\'''\''), '\'''\''resource'\'''\'', CASE WHEN json_type(r.value, '\'''\''$.resource'\'''\'') = '\'''\''text'\'''\'' THEN json_extract(r.value, '\'''\''$.resource'\'''\'') ELSE '\'''\''*'\'''\'' END, '\'''\''effect'\'''\'', json_extract(r.value, '\'''\''$.effect'\'''\''))) FROM json_each(permission) AS r WHERE CASE WHEN r.type = '\'''\''object'\'''\'' THEN json_type(r.value, '\'''\''$.action'\'''\'') = '\'''\''text'\'''\'' AND json_extract(r.value, '\'''\''$.effect'\'''\'') IN ('\'''\''deny'\'''\'', '\'''\''ask'\'''\'') ELSE 0 END) WHERE permission IS NOT NULL;'\'', m.name, m.name) FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) = '\''permission'\'';
|
||||
SELECT '\''DELETE FROM migration WHERE id = '\'''\''20260805200742_import_legacy_credentials'\'''\'';'\'' FROM sqlite_master WHERE type = '\''table'\'' AND name = '\''migration'\'';
|
||||
SELECT '\''DELETE FROM kv WHERE key LIKE '\'''\''wellknown:config:%'\'''\'';'\'' FROM sqlite_master WHERE type = '\''table'\'' AND name = '\''kv'\'';') &&
|
||||
printf 'PRAGMA trusted_schema = OFF;\nPRAGMA journal_mode = DELETE;\nPRAGMA secure_delete = ON;\n%s\nVACUUM;\n' "$s" | sqlite3 -bail clean.db >/dev/null &&
|
||||
c=$(sqlite3 -bail clean.db 'PRAGMA trusted_schema = OFF;' 'SELECT '\''SELECT count(*) FROM sqlite_master WHERE type = '\'''\''trigger'\'''\'';'\'';
|
||||
c=$(sqlite3 -bail clean.db 'PRAGMA trusted_schema = OFF;' 'SELECT '\''SELECT count(*) FROM sqlite_master WHERE type IN ('\'''\''trigger'\'''\'', '\'''\''view'\'''\'');'\'';
|
||||
SELECT '\''SELECT count(*) FROM sqlite_master m JOIN pragma_table_xinfo(m.name) c WHERE m.type = '\'''\''table'\'''\'' AND c.hidden != 0;'\'';
|
||||
SELECT printf('\''SELECT count(*) FROM "%w";'\'', name) FROM sqlite_master WHERE type = '\''table'\'' AND name NOT LIKE '\''sqlite\_%'\'' ESCAPE '\''\'\'' AND (name = '\''machine'\'' OR name LIKE '\''%credential%'\'' OR name LIKE '\''%account%'\'' OR name LIKE '\''%auth%'\'' OR name LIKE '\''%secret%'\'' OR name LIKE '\''%token%'\'' OR name LIKE '\''%share%'\'' OR name IN (SELECT m.name FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) IN ('\''secret'\'', '\''access_token'\'', '\''refresh_token'\'', '\''id_token'\'', '\''api_key'\'', '\''apikey'\'', '\''password'\'', '\''token'\'', '\''credential'\'', '\''credentials'\'')));
|
||||
SELECT printf('\''SELECT count(*) FROM "%w";'\'', name) FROM sqlite_master WHERE type = '\''table'\'' AND (name LIKE '\''automation%'\'' OR name LIKE '\''permission%'\'' OR name LIKE '\''job%'\'' OR name LIKE '\''session_inbox%'\'');
|
||||
SELECT printf('\''SELECT count(*) FROM "%w" WHERE "%w" IS NOT NULL;'\'', m.name, c.name) FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) IN ('\''time_suspended'\'', '\''commands'\'');
|
||||
SELECT printf('\''SELECT count(*) FROM "%w" WHERE permission IS NOT NULL AND CASE WHEN NOT json_valid(permission) THEN 1 WHEN json_type(permission) IS NOT '\'''\''array'\'''\'' THEN 1 ELSE EXISTS (SELECT 1 FROM json_each(permission) AS r WHERE CASE WHEN r.type = '\'''\''object'\'''\'' THEN coalesce(json_extract(r.value, '\'''\''$.effect'\'''\'') IN ('\'''\''deny'\'''\'', '\'''\''ask'\'''\''), 0) = 0 OR json_type(r.value, '\'''\''$.action'\'''\'') IS NOT '\'''\''text'\'''\'' OR r.value IS NOT json_object('\'''\''action'\'''\'', json_extract(r.value, '\'''\''$.action'\'''\''), '\'''\''resource'\'''\'', CASE WHEN json_type(r.value, '\'''\''$.resource'\'''\'') = '\'''\''text'\'''\'' THEN json_extract(r.value, '\'''\''$.resource'\'''\'') ELSE '\'''\''*'\'''\'' END, '\'''\''effect'\'''\'', json_extract(r.value, '\'''\''$.effect'\'''\'')) ELSE 1 END) END;'\'', m.name) FROM sqlite_master m JOIN pragma_table_info(m.name) c WHERE m.type = '\''table'\'' AND lower(c.name) = '\''permission'\'';
|
||||
SELECT '\''SELECT count(*) FROM kv WHERE key LIKE '\'''\''wellknown:config:%'\'''\'';'\'' FROM sqlite_master WHERE type = '\''table'\'' AND name = '\''kv'\'';') && [ -n "$c" ] &&
|
||||
left=$(printf 'PRAGMA trusted_schema = OFF;\n%s\n' "$c" | sqlite3 -bail clean.db) && [ -n "$left" ] &&
|
||||
[ "$(printf '%s\n' "$left" | grep -cx 0)" = "$(printf '%s\n' "$c" | grep -c '')" ] &&
|
||||
|
||||
+3
-2
@@ -142,8 +142,9 @@ exec devvm rm --force
|
||||
stdout '^==> exported file=\S*/data/devvm/exports/devvm-agent-[0-9a-f]{14}-[0-9]{8}-[0-9]{6}\.tar\.gz vm=devvm-agent-[0-9a-f]{14}$'
|
||||
stdout '^==> deleted vm=devvm-agent-[0-9a-f]{14}$'
|
||||
stub_calls
|
||||
stdout 'exec ''bash'' ''-c'' ''devvm_opencode_clean\(\) \{$'
|
||||
stdout '^ *cd ~ && ls -d \.claude \.claude\.json .*--exclude=\.claude/\.credentials\.json.* -T - '
|
||||
stdout 'exec ''bash'' ''-c'' ''IFS= read -r n '
|
||||
grep '^devvm_opencode_clean\(\) \{$' $STUB_DIR/history-export.sh
|
||||
grep '^cd ~ && ls -d \.claude \.claude\.json .*--exclude=\.claude/\.credentials\.json.* -T - ' $STUB_DIR/history-export.sh
|
||||
! exists $AGENT_dir
|
||||
cd $WORK/net
|
||||
exec devvm rm --force --no-export
|
||||
|
||||
Vendored
+4
-2
@@ -23,8 +23,10 @@ exec devvm history export
|
||||
stdout '^==> starting what=devvm-web-[0-9a-f]{14}$'
|
||||
stdout '^==> exported file=\S*/data/devvm/exports/devvm-web-[0-9a-f]{14}-[0-9]{8}-[0-9]{6}\.tar\.gz vm=devvm-web-[0-9a-f]{14}$'
|
||||
stub_calls
|
||||
stdout 'exec ''bash'' ''-c'' ''devvm_opencode_clean\(\) \{$'
|
||||
stdout '^ *cd ~ && ls -d \.claude \.claude\.json .*--exclude=\.claude/\.credentials\.json.* -T - '
|
||||
# The export's script goes on bash's input, never in its arguments.
|
||||
stdout 'exec ''bash'' ''-c'' ''IFS= read -r n '
|
||||
grep '^devvm_opencode_clean\(\) \{$' $STUB_DIR/history-export.sh
|
||||
grep '^cd ~ && ls -d \.claude \.claude\.json .*--exclude=\.claude/\.credentials\.json.* -T - ' $STUB_DIR/history-export.sh
|
||||
exec sh -c 'ls "$EXPORTS"/*.tar.gz | wc -l'
|
||||
stdout '^ *1$'
|
||||
|
||||
|
||||
Vendored
+16
-13
@@ -26,18 +26,21 @@ exec devvm history import
|
||||
stdout '^==> imported file=\S*/data/devvm/exports/devvm-agent-[0-9a-f]{14}-[0-9]{8}-[0-9]{6}\.tar\.gz vm=devvm-agent-[0-9a-f]{14}$'
|
||||
exec sh -c 'cmp "$STUB_DIR/history-in.tgz" "$EXPORTS"/*.tar.gz'
|
||||
stub_calls
|
||||
stdout 'tar -tzf "\$t/export" --absolute-names --quoting-style=escape'
|
||||
stdout 'devvm-history-unsafe'
|
||||
stdout 'tar -xzf "\$t/export" -C "\$t/x" .*--no-same-owner.*--no-same-permissions.*--anchored'
|
||||
stdout 'find "\$t/x" -type l'
|
||||
stdout 'tar --extract --file=- --directory ~ --skip-old-files .*--no-same-owner.*--no-same-permissions'
|
||||
stdout '--exclude=\.claude/\.credentials\.json'
|
||||
stdout '--exclude=\.claude\.json'
|
||||
stdout '--exclude=\.codex/auth\.json'
|
||||
stdout '--exclude=\.local/share/opencode/auth\.json'
|
||||
stdout '--exclude=\.claude/settings\.json'
|
||||
stdout '--exclude=\.claude/skills'
|
||||
! stdout 'tar (-xzf|--extract) .*(--absolute-names|-P\b)'
|
||||
# The import's script goes on the VM's input, before the export, never in its arguments.
|
||||
stdout 'exec ''bash'' ''-c'' ''IFS= read -r n '
|
||||
! stdout 'quoting-style'
|
||||
grep 'tar -tzf "\$t/export" --absolute-names --quoting-style=escape' $STUB_DIR/history-import.sh
|
||||
grep 'devvm-history-unsafe' $STUB_DIR/history-import.sh
|
||||
grep 'tar -xzf "\$t/export" -C "\$t/x" .*--no-same-owner.*--no-same-permissions.*--anchored' $STUB_DIR/history-import.sh
|
||||
grep 'find "\$t/x" -type l' $STUB_DIR/history-import.sh
|
||||
grep 'tar --extract --file=- --directory ~ --skip-old-files .*--no-same-owner.*--no-same-permissions' $STUB_DIR/history-import.sh
|
||||
grep '--exclude=\.claude/\.credentials\.json' $STUB_DIR/history-import.sh
|
||||
grep '--exclude=\.claude\.json' $STUB_DIR/history-import.sh
|
||||
grep '--exclude=\.codex/auth\.json' $STUB_DIR/history-import.sh
|
||||
grep '--exclude=\.local/share/opencode/auth\.json' $STUB_DIR/history-import.sh
|
||||
grep '--exclude=\.claude/settings\.json' $STUB_DIR/history-import.sh
|
||||
grep '--exclude=\.claude/skills' $STUB_DIR/history-import.sh
|
||||
! grep 'tar (-xzf|--extract) .*(--absolute-names|-P\b)' $STUB_DIR/history-import.sh
|
||||
|
||||
# A file of your own, relative to here; one that isn't there fails before
|
||||
# anything runs in the VM.
|
||||
@@ -50,7 +53,7 @@ stub_reset
|
||||
! exec devvm history import nope.tar.gz
|
||||
stderr '^devvm: import_failed reason=.*nope\.tar\.gz.*$'
|
||||
stub_calls
|
||||
! stdout quoting-style
|
||||
! stdout 'IFS= read -r n '
|
||||
|
||||
# The VM's tar finds a path outside the agents' history: nothing imported.
|
||||
# Its tar failing otherwise is a failed import.
|
||||
|
||||
Vendored
+1
-1
@@ -63,7 +63,7 @@ stdout '==> creating_from image=docker vm=devvm-web-[0-9a-f]{14}$'
|
||||
stdout '==> remade image=docker vm=devvm-web-[0-9a-f]{14}$'
|
||||
stdout '^==> building_image image=docker '
|
||||
stub_calls
|
||||
stdout 'tar -czf - \S*--exclude.*\n(.*\n)*.*tar -czf - --one-file-system.*\n(.*\n)*limactl stop devvm-web-[0-9a-f]{14}\n(.*\n)*limactl rename --tty=false devvm-web-[0-9a-f]{14} devvm-[0-9a-f]{14}-old\n'
|
||||
stdout 'exec ''bash'' ''-c'' ''IFS= read -r n .*\n(.*\n)*.*tar -czf - --one-file-system.*\n(.*\n)*limactl stop devvm-web-[0-9a-f]{14}\n(.*\n)*limactl rename --tty=false devvm-web-[0-9a-f]{14} devvm-[0-9a-f]{14}-old\n'
|
||||
stdout 'limactl rename --tty=false devvm-web-[0-9a-f]{14} devvm-[0-9a-f]{14}-old\n(.*\n)*limactl clone --tty=false devvm-img-[0-9a-f]+ devvm-web-[0-9a-f]{14} .*\n(.*\n)*limactl start --tty=false devvm-web-[0-9a-f]{14}\n(.*\n)*.*tar -xzf - --skip-old-files.*\n(.*\n)*limactl delete -f devvm-[0-9a-f]{14}-old\n(.*\n)*limactl shell --workdir /\S*/web devvm-web-[0-9a-f]{14}\n'
|
||||
vm_state $WEB_dir/vm.json
|
||||
stdout '^image=docker$'
|
||||
|
||||
Vendored
+3
-2
@@ -108,8 +108,9 @@ exec devvm rm $WEB --force
|
||||
stdout '^==> exported file=\S*/data/devvm/exports/devvm-web-[0-9a-f]{14}-[0-9]{8}-[0-9]{6}\.tar\.gz vm=devvm-web-[0-9a-f]{14}$'
|
||||
stdout '^==> deleted vm=devvm-web-[0-9a-f]{14}$'
|
||||
stub_calls
|
||||
stdout 'exec ''bash'' ''-c'' ''devvm_opencode_clean\(\) \{$'
|
||||
stdout '^ *cd ~ && ls -d \.claude '
|
||||
stdout 'exec ''bash'' ''-c'' ''IFS= read -r n '
|
||||
grep '^devvm_opencode_clean\(\) \{$' $STUB_DIR/history-export.sh
|
||||
grep '^cd ~ && ls -d \.claude ' $STUB_DIR/history-export.sh
|
||||
! stdout 'limactl start'
|
||||
! exists $WEB_dir
|
||||
! exists $WORK/web
|
||||
|
||||
Reference in new issue
Block a user