Repository navigation
feat(desktop): capture a Linux desktop application in use - #8874
earakely-scale wants to merge 15 commits into
Conversation
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]>
[Critical impact] The command reads existing home-directory data and saves selected file contents into a capture folder. Hold the merge until Findings
Fix with agent prompt### Issue 1
src/application/desktop/DesktopCaptureOutput.ts:64-65
If another process running as the same user creates `capture.json.partial` during the session, the exclusive write correctly fails with `EEXIST`. Failed-run cleanup then deletes that existing file without checking whether this run created it. Cleanup also removes this path after failures that happen before publication begins.
`DesktopContentStore` has the same problem: it sets `#writing` before exclusive creation succeeds, then removes that path on failure. This violates the lifecycle guide's directive to release only owned resources. Keep proof of ownership from the exclusive open and remove only the file this run created.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["CLI request and stdin"] --> B["Check host, app, windows, and output"]
B --> C["Record baseline and retain starting files"]
C --> D["Launch owned app"]
D --> E["Sample processes, windows, and open files"]
E -->|Checkpoint| F["Walk, compare, and retain changed files"]
F --> E
E -->|Session ends| G["Release owned processes"]
G --> H["Publish capture.json and check cleanup"]
H --> I["Return Evidence or cleanup failure"]
Reviews (14) · Last reviewed commit: "fix(desktop): look programs up in the la..." · Reviewed by Greptile |
…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]>
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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
- 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]>
| const partial = capturePartial(output); | ||
| return rm(partial, { force: true }).then( |
There was a problem hiding this comment.
If another process running as the same user creates capture.json.partial during the session, the exclusive write correctly fails with EEXIST. Failed-run cleanup then deletes that existing file without checking whether this run created it. Cleanup also removes this path after failures that happen before publication begins.
DesktopContentStore has the same problem: it sets #writing before exclusive creation succeeds, then removes that path on failure. This violates the lifecycle guide's directive to release only owned resources. Keep proof of ownership from the exclusive open and remove only the file this run created.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/application/desktop/DesktopCaptureOutput.ts
Line: 64-65
Comment:
**Cleanup deletes unowned files**
If another process running as the same user creates `capture.json.partial` during the session, the exclusive write correctly fails with `EEXIST`. Failed-run cleanup then deletes that existing file without checking whether this run created it. Cleanup also removes this path after failures that happen before publication begins.
`DesktopContentStore` has the same problem: it sets `#writing` before exclusive creation succeeds, then removes that path on failure. This violates the lifecycle guide's directive to release only owned resources. Keep proof of ownership from the exclusive open and remove only the file this run created.
**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Fixed in e087320: a CaptureFile owner marks the partial file as created only after its exclusive open succeeds, and discards only a file this run created and has not published (tests for EEXIST, failed rename, and publish).
xfwm4 leaves _NET_CLIENT_LIST unset while it manages no windows, so the capture refused an ordinary desktop with nothing open. Read _NET_SUPPORTED with the list: an unset list means no windows when the window manager supports it, and the capture is refused only when it does not. `xprop`'s "no such atom" output now reads as unset too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…application # Conflicts: # docs/index.md
- A zombie or dead process no longer keeps the session open. - Remove only the partial capture file this run created. - Keep the exact owners of handles and processes whose cleanup failed on the returned error, so a retry can release them; test the published capture's cleanup-failure branch with mixed outcomes and retries. - Release the application once even when the exit checkpoint fails. - A cancellation before the capture is written removes what it retained. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- An unreadable window list is unknown, not zero windows, and is named in the limitations. - Before ending the session, live run-token carriers no parent link reached are tracked; an unreadable process table leaves the exit unknown. - An env prefix's assignments find the program and name its XDG folders. - flatpak run options that take a value are skipped with it, -- is honoured and a /arch/branch suffix is dropped from the id. - State directories include the entry's full id. - Path options refuse empty values; roots count toward the entry limit. - A capture file whose close failed stays owned and is retried on discard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A program, or an empty or relative PATH entry, is resolved from the folder the program starts in, as the launch does, so `env PATH=. app` with the entry's Path still finds the app. 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]>
Summary
Adds
rea capture-desktop-application, the first step toward turning an application installed on someone's Linux desktop into an agent environment computer application. It launches the application on the user's X11 display, watches it while a person or a driver uses it, and writes a capture folder: Evidence incapture.jsonand the bytes of retained files incontent/<sha256>. Later steps (state view, export, verification, tasks) read this folder; this PR builds no environment.The overall plan is in
docs/specs/desktop-app-environments/README.md; this step's spec, plan and verification are indocs/specs/desktop-app-environments/capture/.Problem and expected behavior
Building a computer application environment for a real desktop application today means writing its class by hand: how to install it, how to launch it and recognise its window, and which files hold its state. REA can observe all of that. Native UI capture is macOS only and process capture is built for terminal programs, so nothing in REA could watch a Linux GUI application and the files it changes.
After this change, a capture records:
xpropwith titles, owner pid and type, the time the first application window appeared, a window match (class and instance), and files the application held open.Change and scope
stopor end of input ends it; empty, duplicate and reserved checkpoint names are refused), likeenvironment-serve. No MCP tool or catalog change.DISPLAYorxprop, a window manager without EWMH_NET_CLIENT_LISTsupport, a non-empty output folder, and an application that already has a window open are refused before anything is launched or written./or a directory containing the home is never walked or retained as an argument. A capture that fails beforecapture.jsonis written removes the content it retained.src/domain/desktop/, host adapters in a newsrc/desktop/root (added to the adapters test project), and orchestration and Evidence insrc/application/desktop/. It reusesreadLinuxProcessStat/readLinuxChildren,execFileOutputandreadElectronFuseImage.stop, end of input, the time limit or an error, REA sends SIGTERM to that group and to every process carrying the run token, then SIGKILL after five seconds. Incomplete cleanup is reported with its facts. A process found only as the owner of a matching window is never signalled.Contract and boundary impact
capture_desktop_application; no existing producer or consumer changes.mcp-catalog:checkpasses).xprop(x11-utils) only;REA_XPROP_COMMANDoverrides the binary.rea-desktopv1, operationcapture_desktop_application, predicaterea.desktop-application-capture,confidence: observed,authority: controlled-replay; parameters carry only counts and the launch kind.capture-desktop-application(ignored, regenerated by CI).Expected effects:
Evidence and regression coverage
Execlines,xprop, dpkg and apt-cache output, package paths and walk diffs; adapter tests for the home walk, content store and inventory; service tests for every refusal; and three Linux captures of a fake application with a stubxprop(checkpoint with before and after content, application exiting on its own, refusal while already open).xdotool(details inverification.md). The saved~/Documents/groceries.txtwas recorded as created with retained contentGroceries: milk, eggs, coffee; the first window appeared after 527 ms; the window match isMousepad/mousepad;~/.config/Mousepad/accels.scmis marked as a state directory. A second run with Mousepad already open was refused and wrote nothing.For evidence-bearing changes:
Validation performed
npm run typecheck,lint,lint:typed,format:check,knip,knip:production,jscpd,docs:check,mcp-catalog:check,verify:test-discovery,verify:architecture-guards,scan:todos: passed; no lint diagnostics in the new files.npx vitest run --project domain --project services --project adapters(macOS): 21,581 passed, 29 skipped, 5 failed. The same 5 fail on maind7df9df33here (zstd, Inspector cancellation,setupEnvironment).npx vitest run --project cli-boundary(macOS): 1,499 passed, 5 skipped, 39 failed. 38 fail identically on main here (client profiles, setup, doctor, version report);closedStdoutpassed 3 of 3 when rerun alone.b79c71084,9612ef91f): Mousepad exits with code 0 on SIGTERM, and theexitcheckpoint now records its 3 shutdown writes; the package records originUbuntu.Compatibility, safety, and release
Author readiness
Human owner: @earakely-scale
Before merge
type(scope): outcome.🤖 Generated with Claude Code