Skip to content

feat(desktop): pick seed and end by checkpoint, and keep the capture host out of bundles - #9037

Merged
morluto merged 153 commits into
morluto:mainfrom
earakely-scale:feat/desktop-capture-for-building
Nov 6, 2026
Merged

morluto merged 153 commits into
morluto:mainfrom
earakely-scale:feat/desktop-capture-for-building

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Contributor

Stacked on #8994 (which contains #8988) and #8992. This branch contains them. Review only e6942cf34, and bdc45a5e2, e90c382a0 and 9a2695143, which fix the review findings. Once they merge, the diff shrinks to these. It is about 540 net new source lines, 715 of tests and 320 of docs.

Summary

This makes REA's capture-to-export pipeline fit a build where Claude drives the app inside an agentenv computer: it makes the starting document in the app, marks it, makes the edit and marks that. It is the first of four PRs for "a bundle from a request". It adds no MCP tools.

Problem and expected behavior

  1. The seed was always the capture's start. Export, task validation and the task draft took the baseline as the seed and the last version as the end. A document the user made during the capture, before the edit, was therefore never seeded.
    After this change, --seed-checkpoint seed --end-checkpoint end seeds the files as they were at seed, validates the task as failing there and passing at end, and drafts the diff between them. The defaults stay the baseline and the last version.
  2. apt's lists were assumed at /var/lib/apt/lists. Inside an agentenv computer there are no system lists; a user-space apt-get update under APT_CONFIG writes them elsewhere, so capture found no sources and export refused.
    After this change, capture reads the lists folder and the trusted keys from apt-config, falling back to the defaults.
  3. The launched app inherited AGENTENV_*, including the computer's control token. After this change those variables are dropped from its environment.
  4. Bundles carried the capture host. Geany's seed held pref_template_mail=ada@e81232be457d, and every bundle shipped CAPTURED_HOME="/home/ada".
    After this change, capture records the host name and user. Export rewrites them in seeds and refuses checks that name them.

Change and scope

  • Checkpoints: versionAt and StateEnds (desktopState.ts) and selectStateEnds (DesktopStateVersions.ts). They refuse an unknown or ambiguous name and an end before the seed. They are threaded through planExport, DesktopTaskExport, draftTaskFiles and DesktopTaskDraft. The export result gains checkpoints: {seed, end}.
  • apt: one apt-config shell call for Dir::State::Lists, Dir::Etc::TrustedParts and Dir::Etc::Trusted, each with its default as fallback.
  • Launch environment: applicationEnvironment drops every AGENTENV_ variable.
  • Host identity (hostIdentity.ts; bundle writing moves to DesktopExportFiles.ts):
    • Replacements: user@host becomes user@localhost, the host name standing alone becomes localhost, and the captured home becomes /home/user wherever a whole path segment ends after it.
    • Untouched: the user name standing alone, and the host name inside a longer name or domain, so a host named ubuntu leaves ports.ubuntu.com alone.
    • What ships: the bundle ships SEED_HOME = "/home/user", which the computer respells at boot.
    • Reporting: scrubbed_files and unscrubbed_files (binary or SQLite seeds that still hold the name) are in the result and the README. A check naming user@host or the host name is refused.
  • Review fixes (bdc45a5e2, e90c382a0):
    • Shipped seed: task validation checks the seed as the bundle ships it, after the scrub.
    • Format-aware scrub: JSON strings and XML text and attribute values are scrubbed as decoded values, keeping syntax valid and finding escaped identities (seedScrub.ts). JSON member names are never rewritten, and the JSON walk's stack does not grow with string length.
    • Leftover search: one search covers every shipped file's name and contents, the generated module and dconf keys included.
    • localhost: user@localhost is replaced even when the host is named localhost.
  • Second review fixes (9a2695143):
    • dconf: only decoded GVariant string values are scrubbed; keys, groups, bytestrings, dictionary keys and object paths ship as captured and are reported.
    • Task identity: the host search reads a check's string values, not its field names or default ids.
    • Selected ends: the text-file refusal reads only the shipped seed and the end.
    • UTF-16 seeds: the decoded text's format picks the scrubber, keeping the byte-order mark.
  • Docs: the capture, state, tasks and export guides, and a new capture-for-building spec folder.

Contract and boundary impact

  • Semantic owner and earliest changed stage: capture_desktop_application (host identity, apt locations, launch environment), then export, task export and the draft.
  • Contribution scope fit and linked maintainer decision: same approved desktop-environments work as feat(desktop): capture a Linux desktop application in use #8874.
  • CLI and MCP/tool-catalog contract: new optional --seed-checkpoint and --end-checkpoint on export-desktop-application and describe-desktop-application-task. No MCP change.
  • Provider, bridge, target-format, or platform compatibility: the exported module's home constant is renamed SEED_HOME; the Python parity tests cover it.
  • Evidence, artifact, provenance, or reconstruction contract: captures gain optional host.hostname and host.user; older captures still parse and export, with a limitation.
  • Target selection, authority, upstream behavior, and cleanup details: one more apt-config call per capture.
  • Generated metadata: none.

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

Each new test failed on the parent and passes here; the Linux-only ones were checked the same way in an Ubuntu 24.04 container.

  • Checkpoints (DesktopCheckpointEnds.test.ts, a seedEndCapture fixture, and a CLI case):
    • the export seeds as at seed;
    • the task fails on the seed and passes at end;
    • a check true only after end is refused;
    • the defaults are unchanged, and the draft diffs seed to end;
    • the refusals.
  • apt: an adapter test for a quoted path, a failed call and a missing command, plus, on Linux, the real apt-config under APT_CONFIG.
  • Launch environment (Linux): no AGENTENV_*, other variables kept.
  • Host identity:
    • hostIdentity.test.ts: the Geany line, word and domain boundaries, UTF-16 in both byte orders, and a UTF-8 byte-order mark.
    • DesktopExportIdentity.test.ts: no bundle file but a binary database holds the host name, ada@ or /home/ada; dconf keys are scrubbed; host checks are refused.
  • Real Mousepad capture in an Ubuntu 24.04 container, as user ada, with no system apt lists:
    • the user-space lists were found;
    • the app had no AGENTENV_*;
    • the draft between seed and end showed only the edit;
    • the export seeded from user@localhost and no file held the host name or /home/ada;
    • agentenv 0.9.1431 accepted the class and planned a smoke deploy.

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

  • These passed with no lint diagnostics in this PR's files: npm run typecheck, format:check, build:cached then knip, jscpd, docs:check, docs:build, verify:test-discovery, verify:architecture-guards and verify:module-boundaries. lint and lint:typed fail only on main's tests/acceptance/webSourceLocationCli.test.ts.
  • Desktop tests with the Python boundary and desktop CLI tests: 456 passed and 20 skipped (Linux only) on macOS. In the Ubuntu 24.04 container: 485 passed and 3 skipped.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The draft keeps its baseline and final fields, which now hold the seed and end names.
  • Real Hopper/Ghidra, browser, or OS coverage: Ubuntu 24.04 (container), Mousepad.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: keeps the computer's control token out of the launched app, and the capture host's name and user out of shared bundles.

Known gaps:

  • A seed file whose name holds the host name is only reported, not renamed.
  • The launch command's working directory and arguments outside the home are kept as captured.
  • Not yet run inside a real agentenv computer; PR 3 of this milestone does that.

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 30 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]>
…cation-export

# Conflicts:
#	src/application/desktop/DesktopApplicationState.test.ts
#	src/application/desktop/DesktopApplicationState.ts
#	src/application/desktop/desktopCapture.fixture.ts
#	src/cli/desktopCaptureCommands.ts
- 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]>
…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
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]>
earakely-scale and others added 4 commits November 5, 2026 15:50
…lues for the host, and gate checks on the selected ends

- dconf: the host scrub ran over the whole key file, so on a host named
  `true` `wrap=true` became an invalid `wrap=localhost`. Only decoded GVariant
  string values are scrubbed now; keys, groups, bytestrings, dictionary keys
  and object paths ship as captured and are reported.
- Task identity: the host search read the serialized check, whose field
  names (`file`, `kind`) and default ids matched hosts of those names. It now
  reads the check's string values only.
- Value checks: the text-file refusal read every recorded version; it now
  reads only the shipped seed and the end.
- UTF-16 seeds: the plain scrubber renamed JSON keys and XML names; the
  decoded text's format now picks the scrubber, keeping the byte order mark.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and refuse oversized and deep text before building a view

- Pairing: an element with an identifier (name, id, xid, *:id) pairs only by
  it, so an unchanged id still names an edited element instead of a removal
  and an addition, and two objects of one type are never paired as a rename.
  Selectors keep the tag apart from each attribute condition and spell only
  the chosen one, so a long tag with many attributes no longer multiplies.
- Size: REA's detection and the exported reader decide JSON with a scanner
  that builds no value, and refuse a view over the parsed-view limit before
  building it, in files and zip entries alike.
- Deep text: the exported reader confirms the whole text is JSON before
  reporting a nesting depth error, as REA reads it.

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

# Conflicts:
#	docs/specs/desktop-app-environments/document-views/spec.md
earakely-scale added a commit to earakely-scale/rea that referenced this pull request Nov 5, 2026
Comment thread src/domain/desktop/viewPointer.ts Resolved
earakely-scale and others added 3 commits November 5, 2026 16:17
…ntified elements choose only their identifiers

Identity-first pairing also dropped an identified sibling's other
attributes from the counts that prove a selector names one member, so a
shared attribute such as `color` or `fill` could be chosen though it matched
two siblings: the diff reported present elements removed and drafts lost
their checks. Counting now covers every attribute of every sibling; only the
choice is limited to an identified element's tag and identifiers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
earakely-scale added a commit to earakely-scale/rea that referenced this pull request Nov 6, 2026
…rub XML without one piece per token

Choosing the scrubber for a decoded UTF-16 seed ran the full state
detection, which built the whole XML document (or JSON value), so a large
seed within the capture limit could exhaust memory at export. A syntax pass
now decides the format (the JSON token scan, and the XML parser's events
keeping only the open elements), and the XML scrubber copies out only the
spans it changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
earakely-scale added a commit to earakely-scale/rea that referenced this pull request Nov 6, 2026
earakely-scale added a commit to earakely-scale/rea that referenced this pull request Nov 6, 2026
@earakely-scale
earakely-scale marked this pull request as ready for review November 6, 2026 01:25
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-06T01:25:39.917721Z
We couldn’t complete this review. Comment @codex review to try again.
d78db23 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

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