Skip to content

feat(desktop): export a captured application as an agentenv computer app - #8877

Closed
earakely-scale wants to merge 67 commits into
morluto:mainfrom
earakely-scale:feat/desktop-application-export
Closed

earakely-scale wants to merge 67 commits into
morluto:mainfrom
earakely-scale:feat/desktop-application-export

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #8875, which is stacked on #8874. This branch contains both. Review only 79d722502, 076291af9, 610a61fb0, 652cca203, b45681024, 2a813c484, 81430bd32, 770ae4115, f99b33660, 925b69530, cf2629390, add83e531 and db322822c, plus the merge 72328aef8, which adapts the export to #8875's review fixes (Evidence output, the shared command owner, digest-checked seed reads). The other merges only bring the earlier PRs in. Once they merge, the diff shrinks to these.

Summary

Adds rea export-desktop-application <capture-folder> <directory>, the third step toward turning a captured Linux desktop application into an agent environment. It writes an agentenv bundle with one computer_app environment for the captured application. The environment:

  • installs the app from the distribution archive on the ubuntu-24.04 base with the reference driver;
  • launches it at boot and is ready when its window appears;
  • is seeded with the user's state from before the capture;
  • serves that state through data/add, data/get and data/reset.

The spec, plan and verification are in docs/specs/desktop-app-environments/export/.

Problem and expected behavior

Today a computer app environment means writing its ComputerAppEnvironment class by hand. After this change, a capture plus its state view (#8875) yields a bundle that agentenv's own declaration reader accepts. The bundle contains:

  • envs/<name>/env.toml
  • envs/<name>/<name>.py
  • envs/<name>/SKILL.md
  • envs/<name>/seed/
  • tasks/smoke.json
  • README.md

The generated class declares:

  • the apt package;
  • the captured launch command, with arguments under the captured home respelled under $HOME; when an argument is relative, it tries the captured working directory first and still starts if that folder is missing;
  • an exact window-class match with a window ready check;
  • paths from the state roles;
  • data hooks.

Declaring any hook switches off agentenv's default data plane, so the hooks call agentenv's own helpers:

  • On start: seed the home once per boot, then keep_initial.
  • add and reset: call the same-named helpers.
  • get: returns the files plus a DataPart with a typed JSON view of each (SQLite rows, JSON, XML, key-file groups, text lines). Each view is read the way the state view reads it, within its row, line and XML node limits, and says whether it was truncated.

This follows the decision recorded in the design: exact files for reset and load, plus a typed view on get.

Change and scope

  • CLI only. It reads the capture and its state view, writes through the shared SafeOutputTree, and runs nothing.
  • Pure renderers live in src/domain/desktop/appExport.ts, and the planner and writer in src/application/desktop/DesktopApplicationExport.ts.
  • The desktop CLI commands now import their services lazily, so registering the command catalog loads none of them (cliStartupImports).
  • Refused:
    • applications not installed from the Ubuntu 24.04 archive or a mirror of it (apt must report the source's origin as Ubuntu; PPAs and other repositories are refused), since the computer installs by name;
    • captures without an application window;
    • non-portable environment names.
  • Not included: booting the bundle in a computer (next step, with its recording), tasks beyond a deploy smoke task, version pinning, other package kinds, seed redaction.

Contract and boundary impact

  • Semantic owner and earliest changed stage: new producer export_desktop_application; it consumes capture_desktop_application Evidence and the inspect_desktop_application_state view.
  • Contribution scope fit and linked maintainer decision: writes a bundle from captured data; it runs nothing. Same approved desktop-environments work as feat(desktop): capture a Linux desktop application in use #8874 (approved by morluto with the author; not yet recorded on GitHub).
  • CLI and MCP/tool-catalog contract: one new CLI command; MCP catalog unchanged.
  • Provider, bridge, target-format, or platform compatibility:
  • Evidence, artifact, provenance, or reconstruction contract: the README and module docstring name the capture's Evidence id. The command returns Evidence (rea.desktop-application-export, confidence: derived) listing paths, seed files and written files.
  • Target selection, authority, upstream behavior, and cleanup details: none beyond writing the output directory.
  • Generated metadata: the product catalog gains export-desktop-application.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added:
    • names (including Python's reserved names), owned paths (including files directly in the home), the launch command (including a non-home working directory), env.toml, and the class with hooks, without them, and with dconf only;
    • home-path respelling limited to text seeds;
    • the service writing a bundle from a synthetic capture;
    • refusal of an application with no archive source or only a PPA, and acceptance of a mirror.
  • Mousepad end to end (Ubuntu 24.04 container). Mousepad was captured editing ~/Documents/todo.txt, then exported.
    • agentenv-framework 0.9.1431, installed from PyPI:
      • python -m agentenv_protocol.computer._declare . mousepad_app.py Mousepad exited 0 (the module is <name>_app.py, so it cannot shadow another module). It declared apt mousepad, window class Mousepad with a ready check, paths .config/Mousepad and Documents, the skill, and data/add, data/get and data/reset.
      • agent-env run <bundle> --dry-run planned envs/mousepad and tasks/smoke.json on ubuntu-24.04 with the reference driver.
    • The generated helpers, run on real files:
      • seeding a fresh home wrote Documents/todo.txt with buy bread;
      • the typed get view of the edited file was ["buy bread", "buy milk"];
      • the dconf loader, run on its own: a fresh home got the captured keys, an existing database kept its other groups with the captured keys winning, and a missing dconf printed one warning.
  • Remaining proof gaps:
    • The bundle was not booted in a computer, and the seed-before-launch ordering is unproven there. That is the next PR, with a recording.
    • SafeOutputTree refused a macOS bind-mounted folder as the bundle directory, because its directory identity is unstable there. The e2e wrote the bundle inside the container instead.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run typecheck, lint, lint:typed, format:check, knip, jscpd, docs:check, verify:test-discovery, verify:architecture-guards, scan:todos: passed.
  • Desktop domain, service and adapter tests: 141 passed on macOS, and 150 on Linux in the container (capture, state and export together).
  • CLI boundary (tool coverage, startup imports, input schemas): 30 passed.
  • The Mousepad export end to end, as above, rerun on 652cca203.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Ubuntu 24.04, Mousepad 0.6.1, agentenv-framework 0.9.1431.
  • Package or release metadata impact: one new CLI command in the product catalog.
  • Security, privacy, process, or containment review:
    • The seed is the user's real data, and the README says to keep the bundle local.
    • Nothing is published.
    • Only files the state view read as text have the captured home path respelled; others are copied byte for byte.
    • A file that existed before the capture but was not retained is listed in unseeded_files and the README.

Author readiness

Human owner: @earakely-scale

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

earakely-scale and others added 11 commits November 3, 2026 22:37
Add `capture-desktop-application`, a CLI-only, Linux and X11 capture that
launches an installed desktop application, watches it while it is used and
writes capture Evidence plus SHA-256 addressed content:

- inventory: desktop entry, launch command, executable, package and its
  apt sources (or snap, flatpak, AppImage), Electron markers and candidate
  state directories;
- session: the launched process tree, client windows from xprop with the
  first application window time and a window match, and files held open;
- state: a stat walk of the home directory before launch, at checkpoints
  read from stdin, at stop and after exit, with created, modified, deleted
  and retyped paths and the content of changed files and state directories.

It refuses non-Linux hosts, missing DISPLAY or xprop, a non-empty output
folder and an application whose window is already open, and signals only
processes it started.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cancelled captures

- Launch through the owned provider path with a run token; release with
  SIGTERM, then the token-verified group cleanup, after every session.
  Processes without the token are never signalled; each records whether it
  carries it, and the session records whether cleanup was verified.
- Report creations and deletions only where a walk listed the nearest
  existing directory; count the rest as unconfirmed.
- Retain a file only when it is still the walked version, through owned
  no-follow reads; charge the budget only for new content; create files
  exclusively in a private output folder owned by the caller.
- Walk content roots outside the home directory, compare paths in their
  physical spelling, and run executables from the caller's directory.
- Refuse when the window list cannot be read, re-evaluate window ownership
  each sample, handle one queued request per sample with a bounded stdin
  queue, and write the capture with end reason `cancelled` on interruption.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Allow a capture cancelled before any requested checkpoint to hold only the
  baseline.
- Retry an incomplete stop once; if cleanup is still unverified, write the
  capture and fail with the run token and process group as cleanup
  resources.
- Classify path changes after a walk (ENOTDIR and other selected-file
  errors) as changed_since_walk instead of failing the capture.
- Treat a non-directory ancestor as proof that nothing existed beneath it.
- Report a before digest only for the file version it was read from.
- Derive stderr_truncated from stderr's own byte counts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content reads pass retainFailedClose, so a handle whose close fails stays
owned by the content store; the capture retries those closes after it is
written and fails with the output folder as the cleanup resource if one
still cannot be closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add inspect-desktop-application-state, a CLI command that reads a capture
folder into the application's state: every retained or changed file with
its role and reasons, a typed JSON view of each version (SQLite through the
shared worker, dconf through a private dconf dump, JSON, XML, key files,
text) and the kinds of change between versions (lines, values, keys, rows).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When both the launched processes and a retained file's handle remain
unresolved after the capture is written, one cleanup error now lists both
reasons and both resource sets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add export-desktop-application, which writes an agentenv bundle with one
computer_app environment from a capture folder and its state view: the
apt package, a boot launch matched on the captured window class with a
window ready check, owned paths from the state roles, a seed of the
baseline files, data hooks that call agentenv's add/get/reset helpers
with a typed JSON view on get, a skill, a README and a deploy smoke task.
The desktop CLI commands now load their services lazily.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Read key files, XML attributes, dconf groups and SQLite tables into
  dictionaries without inherited properties, so captured keys such as
  __proto__ stay data.
- Version databases with their write-ahead log as of each checkpoint, and
  stage only digest-verified bytes for the SQLite and dconf readers.
- Detect the format per version, report format changes, keep JSON null and
  empty containers as values, keep XML text and preserved whitespace, and
  mark truncated views (including XML depth) and comparisons of them.
- Number versions and changes by checkpoint index, decide baseline
  presence from the captured type, and keep tagged SQLite integers, text
  bytes and blobs distinct.
- Carry the capture's limitations and omitted content forward, match state
  directories by their home path, index changes once per capture, keep
  failed handle closes owned, and finish the CLI through the shared owner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: apex

[High impact] The PR adds a local CLI workflow that launches desktop apps and copies captured user files into an export bundle.

The prior cleanup finding still needs to be fully addressed before merging.

Findings

  1. P2 Capture loses cleanup owners ▶
Fix with agent prompt
### Issue 1
src/application/desktop/DesktopApplicationCapture.ts:307-318
Cancelling during baseline retention skips `discardFailedCapture`, leaving copied files without `capture.json` and skipping `store.close()`. On the normal path, a repeated close failure becomes only `false`. The returned error keeps a folder name but loses the exact `OwnedFileHandle` needed to retry cleanup.

This violates `AGENTS.md`'s requirement to retain ownership when cleanup fails. Give the store one cleanup scope that runs on every exit and preserves failed owners, as `withRetainedContent` does. This repository requirement must be satisfied before merging.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds export-desktop-application to write an agentenv bundle from capture Evidence and retained baseline files.

  • The capture command records a Linux desktop app and its file changes at checkpoints.
  • The state command labels captured files and shows their contents in typed views.
  • The export command turns a capture into an agentenv computer-app bundle.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  C["Capture Evidence and retained files"] --> S["Read typed state views"]
  C --> P["Plan package, launch and seed"]
  S --> P
  P --> W["Write through SafeOutputTree"]
  W --> B["Agentenv computer app bundle"]
Loading

Reviews (15) · Last reviewed commit: "fix(desktop): start a relative program f..." · Reviewed by Greptile

Comment thread src/domain/desktop/appExport.ts Resolved
Comment thread src/domain/desktop/appExport.ts Resolved
Comment thread src/domain/desktop/appExport.ts Resolved
Comment thread src/domain/desktop/appExport.ts Resolved
Comment thread src/domain/desktop/appExport.ts Resolved
Comment thread src/domain/desktop/appExport.ts Resolved
…cation-export

# Conflicts:
#	src/application/desktop/DesktopApplicationState.test.ts
#	src/application/desktop/DesktopApplicationState.ts
#	src/application/desktop/desktopCapture.fixture.ts
#	src/cli/desktopCaptureCommands.ts
Comment thread src/domain/desktop/stateChanges.ts Resolved
earakely-scale and others added 6 commits November 4, 2026 00:31
- Read coverage flags only from formats whose readers write them, so JSON
  fields named truncated stay data.
- Fail a SQLite version whose write-ahead log existed but was not retained
  or does not match its digest, instead of reading the database alone.
- Close retained content on every exit, including cancellation, and report
  a close that still fails together with the primary failure.
- Finish the CLI with the canonical operation name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cation-export

# Conflicts:
#	src/cli/desktopCaptureCommands.ts
- Refuse packages not from the Ubuntu 24.04 archive, since the computer
  installs by name from that archive.
- Start the launch command in the captured working directory.
- Respell the home path only in files the state view read as text.
- Report files that were not retained instead of dropping them silently.
- Load captured dconf keys for apps that own no files.
- Keep home-level files as owned paths; rename reserved Python class names.
- Mark truncated SQLite and text views in the class's get view, and read
  file types the way the state view does.
- Release the output tree through a resource scope, and read seeds through
  an owner closed on every exit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…L values

- Stage database bytes in a private runtime root released through a
  resource scope, so a failed removal keeps its owner and is reported with
  the read's outcome.
- Report cleanup facts and owners from desktop failures instead of
  wrapping them as a plain adapter error.
- Record the state directories as walked, in their physical spelling, and
  match roles against both spellings, so files in a symlinked state
  directory are not mistaken for selected documents.
- Keep whitespace-only XML leaf values; drop only formatting between
  elements.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep whitespace-only leaf values and xml:space="preserve" text in the
generated get view; drop only formatting between elements.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/domain/desktop/appExport.ts Resolved
Comment thread src/domain/desktop/appExport.ts Resolved
earakely-scale and others added 8 commits November 4, 2026 01:04
…captures

- Release retained-content handles whose close failed through a resource
  scope on every exit; a release that fails again reports the exact handle
  owners. A read that finished keeps its bytes when only its close failed.
- Accept captures written before state directories were recorded, and say
  in the state view's limitations that symlinked state directories may be
  misclassed for them.
- Compute each XML element's whitespace context once instead of scanning
  siblings for every text run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Try the captured working directory only when an argument is relative,
  and start the app even when that folder is missing.
- Cut the generated XML view at REA's node and depth limits, and keep one
  unreadable file from failing data/get.
- Accept Ubuntu 24.04 mirrors, not only the canonical hosts; PPAs and
  other repositories are still refused.
- Read seeds through the retained-content owner's new signature.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Stage a retained -journal beside its database so the SQLite worker
  accepts an inactive journal and refuses a hot one; a -wal or -journal
  that existed but was not retained (including one omitted at the
  baseline) makes the version unreadable.
- Keep tables that read when another fails, and let cancellation and
  unfinished cleanup propagate instead of becoming view errors.
- Read text as a key file only when every line parses as one.
- Rank a file named in a window title or selected by the caller as a
  document even when the application holds it open; match titles on
  file-name boundaries; leave the display name out of dconf matching.
- Bound JSON and key file views (4 MiB, 500 levels, exact numbers) and
  report too-large, missing and altered retained content separately.
- Add no version or change while a database stays absent.
- Read staged databases in place instead of copying them again.
- Give Evidence the same limitations as the result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Load captured dconf keys without D-Bus: install dconf-cli, compile the
  existing and captured key files into the user database, and warn on
  failure instead of stopping the server.
- Start relative-argument launches in the captured working directory,
  the home included, since the framework launches from the app folder;
  respell the home itself and option values under it.
- Read views in a thread, skip files over 64 MiB, align the generated
  readers with the state view's, and close SQLite connections.
- Never own the home or a shared base folder; map a symlinked state
  directory's files back to their home spelling.
- Report omitted files and unretained opened folders.
- Name the module so it cannot shadow another, and keep the class off
  the module's own names; derive names the bundle check accepts.
- Write seeds as they are read, and remove an unpublished bundle on
  failure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Ask the launch process group and token carriers to exit before
  killing them, on errors too; report incomplete cleanup with its facts.
- Count descendants of the launch as started by the capture even when
  their environment cannot be read; treat a reused pid as a new process.
- Follow symlinked desktop entries; name a flatpak's state after its
  application id; match flatpak windows by name only.
- Stop on end of input; refuse empty, duplicate and reserved checkpoint
  names; require whitespace after the checkpoint keyword.
- Stay on each walk root's device, and never walk or retain `/` or a
  directory containing the home; say so in the limitations.
- Refuse a window manager that does not publish _NET_CLIENT_LIST.
- Remove retained content when a capture fails before it is written.
- Skip reading a file larger than the remaining content budget.
- Record apt's archive origin for each package source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lication-state

# Conflicts:
#	docs/desktop-application-capture.md
#	src/cli/desktopCaptureCommands.ts
Comment thread src/domain/desktop/appExportPython.ts Resolved
earakely-scale and others added 11 commits November 4, 2026 20:06
The CLI alias check reads `-wal` and `-journal` in help text as short flags,
so the help names the write-ahead log and rollback journal instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Program paths and PATH entries are joined rather than resolved, so `..` after
a symbolic link means what it means to the launch. The lookup moves to its own
module.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The exported reader only needs to know whether any number was inexact, so it
keeps a boolean instead of every rejected spelling.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…into feat/desktop-application-state

# Conflicts:
#	src/application/desktop/DesktopCaptureRefusals.ts
…or env

Empty and `.` segments are dropped from a looked-up program path, which keeps
`/snap/bin/` entries recognisable as snaps, while `..` is still left for the
kernel. Relative and empty PATH entries are searched only in the PATH an `env`
prefix sets, which travels with the exported launch; the host's own PATH does
not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The capture records the paths every walk left out, and the state view treats
a log as absent only under content roots the baseline walked completely and
outside those exclusions, so an excluded or unvisited log leaves the database
unread rather than read without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The exported reader marks an inexact number instead of flagging it during the
parse, then looks for marks in the parsed value, so a number a later duplicate
key overwrote no longer refuses the file, as in REA.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/desktop/ProgramLookup.ts Resolved
Comment thread src/desktop/ProgramLookup.ts Resolved
Comment thread src/domain/desktop/appExportPython.ts Resolved
earakely-scale and others added 7 commits November 4, 2026 21:20
When the current read cannot observe a carrier's process group, the carrier
is signalled on its own instead of letting an older process-table row grant
a group-wide SIGTERM.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…relative finds

The lookup searches PATH as the launch does, an empty entry meaning the
launch folder, so inspection and launch name the same program. A program found
only through a relative or empty entry of the host's own PATH is refused,
since the exported computer would not have it; an env prefix's PATH travels
with the command.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each walk counts the paths it could not stat and the directories on another
device it did not enter, and the checkpoint records it as `unchecked_paths`.
The state view treats a log as absent only when the baseline left nothing
unchecked, so a log whose stat failed stays unknown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The check for marked numbers walks the parsed value with an iterator per
nesting level instead of copying each container's children; a million-entry
array went from about 15.7 MiB to 8.1 MiB of peak traced memory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An exported launch whose program path is relative, such as `./app` from an
entry's Path, now changes to the captured working directory first, as it
already did for relative arguments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Thanks @earakely-scale! Every commit from this PR landed in main via the stacked #8954 (squash 970969c), so I'm closing this one as merged there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants