Skip to content

fix(desktop): record the desktop entry's package and app profiles in any case - #8992

Closed
earakely-scale wants to merge 118 commits into
morluto:mainfrom
earakely-scale:fix/desktop-entry-package-and-profiles
Closed

earakely-scale wants to merge 118 commits into
morluto:mainfrom
earakely-scale:fix/desktop-entry-package-and-profiles

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Contributor

Builds on the desktop stack merged as #8954. The diff against main is this PR alone, four commits: bd0af1a32 (fix(desktop): record the desktop entry's package and app profiles in any case), and 0a25c8f7e, 782859348 and 82e7c78cc, which fix the review findings.

Summary

These are two capture fixes found by running five Linux apps end to end (Inkscape, Geany, KiCad, LibreOffice Writer, GIMP):

  • Writer's package: REA recorded the package that owns the launched program instead of the one that owns the desktop entry, so Writer's exported computer never installed Writer.
  • GIMP's profile: REA didn't recognise GIMP's profile folder as its state, so the profile was neither seeded nor reset.

Problem and expected behavior

  1. Package: --desktop-entry libreoffice-writer launches /usr/bin/libreoffice, which belongs to libreoffice-common. REA recorded that package, which doesn't depend on libreoffice-writer, so the computer booted without Writer: no window with class 'libreoffice-writer'. After this change, REA records libreoffice-writer, the owner of the entry file, and Writer boots.
  2. Profile: GIMP 2.10 keeps its profile in ~/.config/GIMP/2.10. State folders were matched to the app's names in their own spelling and in lowercase, never GIMP, so the profile got role unrelated. After this change, ~/.config/GIMP is a state folder and the profile is seeded and reset.

Change and scope

  • Package (src/desktop/DebianPackageInventory.ts):
    • When the launch comes from a desktop entry, REA asks dpkg who owns the entry file and its resolved path. That package becomes package.name.
    • When the program's package differs, it is kept in a new optional executable_package.
    • --executable launches, entries no package owns (e.g. in ~/.local/share/applications), and flatpak, snap and AppImage detection are unchanged.
    • Version, sources, the vendor-repository check and --package-file matching all key off package.name, so they follow it.
  • State folders (src/desktop/ApplicationStateDirectories.ts, split out of LinuxApplicationInventory.ts):
    • Direct children of the four XDG folders and the home's dot-entries count when their whole name equals a candidate name, ignoring letter case.
    • stateRoles.ts gives the same rule to a folder created during the capture.
    • GIMPshop, MyGIMP and nested matches are excluded.
  • Review fixes (0a25c8f7e):
    • The program's package is installed too. When it differs from the entry's, the capture checks it by the library packages' rule: some version must come from the Ubuntu 24.04 archive or a declared vendor repository. If not, it records why in executable_package_reason. The export installs the package right after the app's, or refuses with that reason. Example: vim-common owns vim.desktop but doesn't depend on vim.
    • State folders keep their spelling. The export owns a state folder in the letter case the app wrote it (stateDirectoryOf, shared with the roles), so data/get and data/reset cover .config/GIMP, not just .config/GIMP/2.10.
    • Approval follows the kept repositories (782859348). Each repository records the packages only it supplies (supplies). When the export leaves a repository out (its key dropped by the content budget, an architecture restriction or a conflicting key), it drops the library packages only that repository supplied, with a limitation, and refuses when the program's package is one of them. The install limitations move to appExportInstallLimitations.ts.
    • Unpackaged programs refuse export (82e7c78cc). When a package owns the entry but none owns the program it runs, such as ~/.local/bin/notes first on PATH, the capture records why, and export refuses instead of installing a package that doesn't bring that program.
    • Failed lookups stay unknown. A dpkg-query -S that fails or exits 2 or higher leaves the package unknown, with a limitation, instead of reading as "no owner".
  • Docs: the capture, state and export guides and the capture, state-view and export specs.

Contract and boundary impact

  • Semantic owner and earliest changed stage: capture_desktop_application, the inventory.
  • 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: unchanged.
  • Provider, bridge, target-format, or platform compatibility: unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: new optional executable_package and executable_package_reason; older captures still parse.
  • Target selection, authority, upstream behavior, and cleanup details: one more dpkg-query -S per capture, on the entry file.
  • 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

  • Package tests (DebianPackageInventory.test.ts, a fake dpkg host where libreoffice-writer owns the entry and libreoffice-common the program):

    • an entry launch records libreoffice-writer, with executable_package: libreoffice-common;
    • a --package-file holding libreoffice-writer is matched;
    • --executable launches and unowned entries keep the program's package.

    The first two fail on the parent.

  • State-folder tests:

    • LinuxApplicationInventory.test.ts: a GIMP layout records .config/GIMP and .Gimp and leaves out unrelated folders.
    • stateRoles.test.ts: .config/GIMP/2.10/sessionrc gets state_directory, while GIMPshop, a nested other/GIMP and .Config/gimp get nothing.

    Both fail on the parent.

  • Review-fix tests: 8 new tests in DebianPackageInventory.test.ts, appExportInstall.test.ts, appExport.test.ts and DesktopApplicationExport.test.ts. All 8 fail on bd0af1a32, while the 79 existing tests in those files pass there.

  • Linux: the first-round tests ran on Linux in the Ubuntu 24.04 e2e container (3 files, 31 tests, all passed) as well as on macOS, since macOS's filesystem ignores letter case.

  • Real apps: the five-app run that found these fixed Writer by patching its bundle to install libreoffice-writer. Re-capturing Writer and GIMP with this branch is the remaining check.

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 touched files: npm run typecheck, lint, lint:typed, format:check, build:cached then knip, jscpd, docs:check, docs:build, verify:test-discovery and verify:architecture-guards.
  • Desktop tests on macOS: 351 passed and 18 skipped with the review fixes. The first-round tests also pass on Linux; the review-fix tests ran on macOS.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. A capture may now record a different package name (the entry's), which is the intended fix.
  • Real Hopper/Ghidra, browser, or OS coverage: Ubuntu 24.04 package layouts for LibreOffice and GIMP.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only dpkg queries; no new paths are read beyond the XDG folders' and the home's direct children.

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 6 commits November 4, 2026 21:29
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]>
…any case

- A launch from a desktop entry records the package that owns the entry, so
  the export installs the app the entry starts (Writer, not only
  libreoffice-common); the program's own package is kept as
  executable_package when it differs.
- State folders match the app's names ignoring letter case, as direct
  children of the XDG folders and the home, so GIMP's ~/.config/GIMP profile
  is seeded and reset; roles follow the same rule.

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

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue remains.

Summary

Records the desktop entry’s package separately from the program’s package and finds application state folders regardless of letter case.

  • Desktop entries now install the package that provides the app.
  • App profiles now match state folders even when their letter case differs.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Capture[Capture desktop application] --> Owners[Find entry and program packages]
  Owners --> Sources[Record package sources and supplies]
  Sources --> Keys[Retain signing keys]
  Keys --> Export[Choose usable repositories]
  Export --> Check{Can the program be installed?}
  Check -->|Yes| Bundle[Write application bundle]
  Check -->|No| Refuse[Refuse with the recorded reason]
  Capture --> State[Find state folders ignoring letter case]
  State --> Shared[Use the same folder match for roles and export]
  Shared --> Bundle
Loading

Reviews (6) · Last reviewed commit: "Merge main into fix/desktop-entry-packag..." · Reviewed by Greptile

Comment thread src/desktop/DebianPackageInventory.ts Resolved
Comment thread src/domain/desktop/stateRoles.ts Resolved
Comment thread src/desktop/DebianPackageInventory.ts Resolved
…rs unknown

- When the desktop entry's package does not own the program it runs, the
  export installs the program's package too. The capture records why it
  cannot (executable_package_reason), and the export then refuses.
- The export owns a state folder in the letter case the app wrote it, as
  the state roles already did, so data/get and data/reset cover a profile
  folder the app created during the capture.
- A dpkg-query that fails or exits 2 or higher leaves the package unknown
  instead of reading as "no owner".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/domain/desktop/appExportInstall.ts Resolved
earakely-scale and others added 2 commits November 5, 2026 01:46
…port keeps

The capture approved library packages and the program's package against
every repository with a verified key, but the export can still leave a
repository out: its key dropped by the content budget, an architecture
restriction, or a conflicting key. Each repository now records the packages
only it supplies (`supplies`). The export drops stranded library packages
with a limitation, and refuses when the program's own package is stranded.
Captures without `supplies` behave as before.

The install limitations move to appExportInstallLimitations.ts to keep
appExportInstall.ts under the line limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every conflict was a file the squash re-added exactly as this branch's
stack base had it, so each keeps this branch's version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@earakely-scale
earakely-scale marked this pull request as ready for review November 5, 2026 16:08
Comment thread src/desktop/DebianPackageInventory.ts Resolved
…package owns

When a package owns the desktop entry but no package owns the program it
runs, such as one in ~/.local/bin first on PATH, the capture keeps the
entry's package and records why the program cannot be installed. Export
refuses instead of installing a package that does not bring that program.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
earakely-scale added a commit to earakely-scale/rea that referenced this pull request Nov 5, 2026

morluto commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Closing as superseded: the changes here landed on main through #9037 (c363f3e27b48).

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

Labels

area: build Build, CI, packaging, and publishing bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants