Skip to content

feat(app): add a Projects pane that scopes the desktop app to chosen projects - #1294

Closed
mathieustan wants to merge 7 commits into
getagentseal:mainfrom
mathieustan:feat/desktop-project-filter
Closed

mathieustan wants to merge 7 commits into
getagentseal:mainfrom
mathieustan:feat/desktop-project-filter

Conversation

@mathieustan

Copy link
Copy Markdown
Contributor

The desktop half of #1276, on top of the CLI half that merged as #1285.

What is in here

Settings gets a Projects pane: one switch per detected project, plus a
field for hiding a pattern that matches nothing detected yet. The filter
lives in ~/.config/codeburn/app-filter.json rather than renderer
storage, because the main process is where the CLI argv is assembled. No
file, or empty lists, means no filter, so nothing changes for anyone who
never opens the pane. CODEBURN_APP_FILTER overrides the path and an
empty value disables it outright, which is what the app test suite sets
so a real filter file cannot reach an assertion.

Two rules the pane is built around:

  • Its own list is fetched WITHOUT the filter, and over the whole
    history rather than the period on screen. Scoping it either way would
    hide the projects the checklist exists to switch back on.
  • Patterns go out as --project=<value>, never as two argv entries.
    A Claude project directory is encoded as -Users-me-Web-thing, and a
    leading dash in its own argv slot parses as a flag.

A row is one project as the parser sees it, which is one session's
starting cwd resolved by resolveCanonicalProjectPath. A linked
worktree folds back into its main repo; a subdirectory of a repo does
not, by that function's own rule, so a monorepo can show packages/api
as its own row beside the repo root. Hiding the repo path hides both:
a rooted pattern is anchored on a segment boundary, so it covers the
project and everything inside it.

Combined scope, as flagged in #1285

status --scope combined rejects --project/--exclude, because paired
devices report their usage unfiltered. The filter wins here: Combined is
unavailable while a project filter is set, and says why. Dropping the
filter instead would put the hidden projects back inside the combined
total, which is the one thing the pane exists to prevent. The offer from
#1285 still stands: if you would rather Combined stayed available and
simply ignored the filter, that is a one-line change.

buildOverviewArgs keeps the same rule as a guard, so a stale renderer
cannot produce the rejected argv either.

Five holes a local adversarial pass found, each closed with its test

The pane commit is the one I wrote; these are what a review pass against
it turned up before this PR opened. Each is its own commit.

  1. A failed filter read unhid every project. appFilterCache is
    module level and null on the first read of a launch, and statSync
    rejects EACCES the way it rejects ENOENT. An unreadable
    app-filter.json read back as an empty filter, so every fetch ran
    unfiltered and the renderer re-offered Combined, with no error
    anywhere. Only a missing file means "no filter" now; everything else
    fails closed into the panel's error state.

  2. The filter write skipped the atomic rename that saveConfig uses
    in the same directory, and for the same reason. Staged and renamed
    now, with the staged file cleaned up if the rename cannot land.

  3. The pane's list was bounded to the period on screen. A filter has
    no period, so an exclude for a project with no activity this period
    read as matches nothing detected next to a Remove button, under a
    footer saying Nothing is hidden. Lifetime now, and the period
    argument is gone from the channel.

  4. An all-hidden export reported success. export prints prose and
    exits 0 when every period is empty; the toast named a folder the CLI
    never created. Success reads the saved-path line instead.

  5. The list bypassed the resident serve child. report was in
    neither routing table, so the heaviest read in the app was also the
    only panel query that always paid a cold start. Routed, in its JSON
    form only.

Finding 5 is why this PR touches src/serve.ts and tests/ rather than
only app/: the routing table lives on both sides of the wire.

Tests

15 added. I mutation-tested every one of them: each of the nine defects
above was put back one at a time, and the test that covers it fails
without its fix. Two of my first attempts at the atomic-write test passed
against the unfixed code (the old path never created a temp file, so
"no temp file is left behind" was true by accident); they are replaced by
one that asserts the live path is never a write target.

  • app/electron/main.test.ts: the two read-failure shapes, the fetch and
    the overview failing closed rather than spawning unfiltered, the
    channel reporting the failure instead of an empty filter, the staged
    write and its cleanup, both export outcomes, and the lifetime horizon.
  • app/renderer/sections/Settings.test.tsx: the list is asked for once,
    with no period, and survives a period change without refetching.
  • app/electron/cli.test.ts and tests/serve-stdio.test.ts: report
    rides the resident child, and its TUI form and --refresh are refused.
  • tests/cli-export-project-filter.test.ts: the real CLI, exercised in
    both directions, pinning the stdout contract the app now depends on.

CLI suite 3918 passing plus the serial lock suite, desktop suite 919
passing, tsc clean on both projects. Every intermediate commit is green
on its own, so the stack stays bisectable.

…projects

Screen-sharing or demoing the app exposed every project on the machine,
with no way to narrow it. Settings now has a Projects pane: one switch
per detected project, plus a field for hiding a pattern that matches
nothing detected yet.

The filter lives in ~/.config/codeburn/app-filter.json rather than
renderer storage, because the main process is where the CLI argv is
assembled. No file, or empty lists, means no filter, so the default is
unchanged for everyone who never opens the pane. CODEBURN_APP_FILTER
overrides the path and an empty value disables it, which is what the app
test suite sets so a real filter file cannot reach the assertions.

Details worth knowing:

- The pane's own project list is fetched WITHOUT the filter. Scoping it
  would hide the projects the checklist exists to switch back on.
- Patterns are passed as --project=<value>, never as two argv entries. A
  Claude project directory is encoded as "-Users-me-Web-thing", and a
  leading dash in its own argv slot parses as a flag.
- Combined scope and a project filter cannot both hold. The CLI rejects
  --scope combined next to --project/--exclude because paired devices
  report their usage unfiltered, and dropping the filter instead would
  put the hidden projects back inside the combined total, which is the
  one thing the pane exists to prevent. So the filter wins: Settings
  offers Local only while something is hidden (and says why), the
  renderer derives its effective scope from the filter so even the first
  poll of a filtered session is local, and buildOverviewArgs keeps the
  same rule as a guard for a stale caller.
- A read that fails on an existing file keeps the last known filter
  instead of falling back to the empty one. Unhiding every project on a
  torn write or a typo mid-edit is the one failure mode this pane cannot
  have. Only a missing file means "show everything" again.
- The pane's matcher lives in renderer/lib/projectMatch.ts, and
  projectMatch.test.ts pins it against the CLI's matchesProjectPattern
  over every pattern shape. A switch that disagrees with the argv it
  writes would lie about what is on screen.
- Writes are serialized: every write is computed from the filter on
  screen, so a second click before the first landed would be built from
  the pre-click value and drop it.
- export carries the filter too, since it writes project names into a
  file that gets shared. getPlans stays unfiltered, like combined scope:
  a plan is billed on every project, so scoping it would misreport the
  cycle.
A pattern typed into the Projects pane never passes through a shell, so
"~/work/app" reached the CLI as a literal tilde and matched nothing. It
is expanded in the main process now, on the way into app-filter.json and
on the way back out: the renderer has no home directory of its own, and a
tilde it cannot resolve would make its switches disagree with the argv
this process writes.

The file can also be hand-edited, so the expansion runs on read as well
as on write. projectMatch.test.ts covers the expanded shapes against the
CLI's matchesProjectPattern, which is what keeps the switch and the argv
on the same answer.
The Projects pane commit claimed that a failed read keeps the last known
filter instead of unhiding. That only held once a filter had already been
read in this process: appFilterCache is module level, so it is null on
the FIRST read of every launch, and both failure paths fell back to the
empty filter there. statSync also rejects EACCES and EIO exactly the way
it rejects ENOENT, so an unreadable file and a missing one produced the
same answer.

A malformed or unreadable app-filter.json therefore made projectArgs()
return [], and every CLI fetch ran unfiltered: the hidden projects
painted, getProjectFilter reported an empty filter so the renderer
cleared its filtered state and re-offered Combined scope, and nothing
surfaced an error.

Only ENOENT means "no filter" now. Every other errno, and a parse failure
with nothing cached, throws. The handlers already wrap argv construction,
so a fetch fails closed into the panel's error state rather than
rendering a wider set of projects than the user asked for.

Writes are staged through a randomized temp file and renamed, the rule
saveConfig already follows in src/config.ts for the same directory: a
writeFileSync straight over the live path can be interrupted, and a
truncated filter is an unreadable filter.
getUnfilteredProjects passed the period on screen, and the CLI builds
that list from the days the period covers. A project filter has no
period: it scopes every screen and every horizon at once. So an exclude
pattern for a project with no activity in the current period rendered as
"matches nothing detected" next to a Remove button, while the footer read
"Nothing is hidden." Clicking Remove there unhid the project on every
screen, from a control that had just called the pattern dead.

The list is lifetime now, and the period argument is gone from the
channel rather than left for a caller to get wrong. `all` is capped at
six months, so lifetime is the only horizon that can answer for the whole
filter.

The pane's memo key goes through reportMemoKey like every other pane, and
the fetch is off the poll interval: it is the heaviest read in the app, a
toggle cannot change an unfiltered list, and the only thing that can is a
project appearing, which the next open picks up.
codeburn export prints "No usage data found." and exits 0 when every
period came back empty, writing no file and no folder. That path was
unreachable from the app until the export started carrying the project
filter; an exclude list covering every detected project now empties all
three periods of the export window. runAction read the exit code, so the
Export pane toasted "Exported to <folder>" for a folder the CLI never
created.

Success reads the saved-path line the CLI prints only after a write, and
a run that wrote nothing comes back as a failed action whose message
names both causes. A CLI test pins both halves of that contract, since
the app cannot import from src/.
The Projects pane's list is `report --format json`, the heaviest read in
the app, and report was in neither routing table: not in SERVE_ROUTED on
the client, not in SERVE_OPTIONS on the server. Every open of the pane
paid a fresh node boot plus the full session-cache parse the resident
child exists to avoid, at interactive priority, holding one of the two
run slots for its whole duration and stalling the panels polling behind
it.

report is servable in its JSON form only: on every other format it is the
interactive dashboard, which cannot run in a child whose stdout is the
wire. allowed() refuses those and the client falls back to a one-shot
spawn, which is where a dashboard belongs. --refresh only paces that
dashboard, so it stays off the served surface.
The desktop CI job runs `npm ci` inside app/ only, so an app-side test
that imports src/parser.ts cannot resolve the CLI's own dependencies: the
typecheck failed on chalk and strip-ansi before the suite even ran. A
local run hides it, because the repo root's node_modules sits one
directory up and resolves fine from there.

The test needs both halves by definition, so it moves to the suite that
has both, and projectMatch.ts names its new home. Nothing under app/
reaches into src/ any more: `tsc --listFiles` on the desktop project now
resolves no file outside app/.
@iamtoruk

Copy link
Copy Markdown
Member

Landed as #1307 (ce59a3a) with all your commits and authorship intact, rebased onto current main, plus four follow-ups found while driving the built app against a real corpus: the 365-day history and month-to-date are now sliced by the same project filter as the headline (they were unfiltered under a filtered headline), the renderer re-reads the filter when it changes outside the window so the Combined label cannot sit over a local filtered query, the pane gets a search box and cost ordering (2,759 rows here), and the instant-switch memo is dropped when the filter changes externally. Every argv shape, the fail-closed read, and the local-only scope decision verified live. We could not push to your fork, hence the superseding PR. Thank you, this was careful work.

@iamtoruk iamtoruk closed this Sep 12, 2026
@mathieustan
mathieustan deleted the feat/desktop-project-filter branch September 13, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants