Skip to content

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

Merged
iamtoruk merged 11 commits into
mainfrom
fix/projects-pane-followups
Sep 12, 2026
Merged

iamtoruk merged 11 commits into
mainfrom
fix/projects-pane-followups

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Supersedes #1294 by @mathieustan. Same commits, rebased onto current main, plus follow-ups on top.

Original work and design: @mathieustan.

Follow-ups in this branch:

  • Expand a leading ~ in a pattern typed into the pane, so ~/work/foo hides what the user meant.
  • Fail closed when the filter file cannot be read, instead of silently reporting unfiltered totals.
  • List projects for the whole history, not the visible period, so a dormant exclude stops reading as an orphan.
  • Slice the 365-day history in usage-aggregator by the filter, so the menubar history matches the app.
  • Re-read the filter on refresh and on every overview poll, so a hand edit of app-filter.json cannot leave a filtered local total under a "Combined" headline.
  • Drop the instant-switch memo when the filter changes outside the app: reportMemoKey carries no filter component, so a snapshot from the other scope could repaint until the next fetch.
  • Search box and cost-descending order in the pane. Real machines hit 2,759 rows here; a case-insensitive substring on name or path narrows them, with an "8 of 2,759" count beside the box.

Verified: app typecheck clean, 892 renderer/electron tests pass (27 failures are pre-existing localStorage-under-jsdom breakage in usePolled.test.ts and overviewSnapshot.test.ts, unrelated to this branch). Root tsc --noEmit clean, and the project-filter CLI and serve suites pass. Drove the built app to Settings > Projects and confirmed the count text and narrowing against a real 2,759-project list.

mathieustan and others added 11 commits September 12, 2026 05:38
…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/.
The headline is sliced to the requested projects (buildDurablePeriod runs
every historical cache day through sliceDayToProject) and today's days come
from the name-filtered parse, but `history.daily` was read straight out of
the day cache. Every surface built on it showed every project: the heatmap,
the streak, "N active days", month-to-date, the projected month, the daily
spend chart, the Spend punchcard and the daily-budget check.

On this machine, `status --format menubar-json --project=<one project>`
returned a $7.43 headline over a $2,993.61 month-to-date, and 137 of the
138 days in history.daily were byte-identical to the unfiltered run.

Same slice the headline already uses, so a cache day with no project split
contributes nothing here rather than everything, exactly as it does there.
The main process re-reads app-filter.json whenever the file changes, which
is what makes a hand edit land. The renderer only re-read it on its own
config mutations, so a filter that appeared any other way left
`projectFiltered` false: Settings kept offering Combined, the hero kept
saying "Combined · …", and buildOverviewArgs had already dropped
`--scope combined` because the filter was non-empty. The reading on screen
was a local, project-filtered total labelled as the combined one.

Re-read on a manual refresh and on every overview poll as well. It costs
one statSync the main process already memoizes by stat stamp.
The pane rendered one switch per detected project in whatever order the
report returned them: 2,762 rows on this machine, with nothing to type into
and the costliest buried at an arbitrary depth. Sort by lifetime cost
descending and narrow on a case-insensitive substring of the name or path,
with a "12 of 2,762" count beside the box once it narrows.

A substring pass over a few thousand rows is nothing, so no virtualisation.
The switches and the hide-a-pattern field are untouched, and the hidden
count still reads off the whole list, not the visible slice.
…e the app

reportMemoKey is section|period|provider|range|variant|boundary, with no
filter component, so an entry memoised before the filter changed is a valid
key for the other scope. A filter that appeared while the window was away
therefore repainted the unfiltered snapshot until the next fetch landed.

Clear the memo on the change only, where the re-read already compares the
observed flag against the persisted codeburn.projectFiltered: clearing on
every poll would throw the memo away wholesale for nothing.
@iamtoruk
iamtoruk merged commit ce59a3a into main Sep 12, 2026
20 checks passed
timothybrush pushed a commit to timothybrush/codeburn that referenced this pull request Sep 12, 2026
…ll entries

Rebasing onto main put the new getSessionsContributions handler beside the
Projects-pane filter from getagentseal#1307 without picking it up, so the drill-through
would have listed unfiltered sessions under a filtered headline.

- main.ts: add projectArgs() to the new handler, matching getSessions; the
  existing filter test now asserts the new channel too.
- usage-aggregator/day-aggregator: actually set categories[].rawCategory.
  menubar-json already declared and forwarded it, but no producer wrote it,
  so topActivities[].rawCategory was always undefined and the category
  drill entry was permanently disabled in both aggregation paths.
- Models.tsx: key the model drill off modelDisplayName. Contribution
  segments are keyed by canonical short name ("Fable 5"); the row's raw
  provider ids ("claude-fable-5") matched 0 of 19 segment keys on real data.
iamtoruk added a commit that referenced this pull request Sep 12, 2026
…w flags

Rebased on main, which since gained #1307, #1316 and #1319.

- Delete app/renderer/lib/sampleNavigation.ts. It was a placeholder for a
  registry that never landed: #1316 ships drill-through as an onInvestigate
  callback prop plus NavState. The sample rows now call it, threaded from
  App.tsx through Compare, and open the owning session for real.
- Give a CohortObservation the provider/project/session triple the sessions
  report keys rows by (inferSessionProvider, session.project || project.project),
  so a sample resolves to exactly one session row. Without it a cohort sample
  could not build sessionRowKey at all.
- Carry projectArgs() on both cohort spawns, per #1307. The saved project
  filter now scopes the facet query and the report; --project-id still narrows
  within it. Extended the scopes-every-fetch test to cover both.
- Allow --from, --to, --category and --project-id on compare in SERVE_OPTIONS.
  Verified over stdio: before, every cohort request but the bare facet query
  came back "command not served" and fell back to a spawn.
- Catch the invalid-date throw on compare like report does, instead of an
  unhandled UsageQueryError stack trace.
- Drop the unrelated CODEBURN_USER_DATA_DIR hunk in bootstrap().
ozymandiashh pushed a commit to ozymandiashh/codeburn that referenced this pull request Sep 12, 2026
…rrors

Rebase fixes on top of getagentseal#1296.

- App.tsx shipped a stub inspectRange calling a setCustomRange that no longer
  exists after getagentseal#1316. Replaced with the real navigation: commitNav to Sessions
  with the clicked side's range AND projectFilters/modelFilters for the
  contribution key, so the drill-through lands on the population the row
  describes instead of the whole range.
- getPeriodCompare and getPeriodCompareSessions carried no projectArgs(), so a
  saved project filter did not scope either fetch (getagentseal#1307). Added, and the
  "scopes every fetch" main-process test now covers both channels.
- compare-periods --format sessions ignored --project/--exclude, so a drill-down
  could surface a session from a hidden project. It now filters like the report.
- A bad --from-a/--to-a printed a raw stack trace: parseDateRangeFlags throws
  and the null check could never fire. Wrapped in the same try/catch every other
  date-flag command uses.
- Totals card now says inline how much daily history has no session detail
  behind it. On a machine with aged-off sources the detail-only total is far
  below report/status for the same range; the Coverage card alone was three
  cards away from the number it qualifies.
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