Commit graph

290 commits

Author SHA1 Message Date
ozymandiashh
6addfeb4be fix(app): key investigation chips by identity, not by their label
Chips were keyed by the string they display, which truncates a session
id to 12 characters and a project path to its last segment. Two sessions
whose ids share a prefix, or two projects with the same basename on the
same branch, produced one React key for two chips: React warned about
the duplicate and could reconcile or remove the wrong one.

filterChipKey returns the composite identity each dimension is already
normalized and removed by (provider + session id, project + branch), so
chips that read alike stay distinct to React while the display label is
left as short as it was.
2026-09-13 06:41:04 -07:00
ozymandiashh
62c7483aab fix(app): reset sessions pagination where the count is owned
The list reset its visible-row count to the first page whenever the
selection, the sort, the search or the data changed — but it wrote the
internal fallback state, and the app passes visibleCount as a controlled
prop so it can restore the depth from the nav history. The reset was
therefore dead: after Show more, changing the sort or removing a chip
left the reader 240 rows deep in a list that had just been reordered.

The owner now resets it in the same commit as the change it owns, so a
sort or selection change is one history entry rather than two, and no
reset can fire during a Back/Forward restore and discard the depth that
was just restored. The effect keeps serving the uncontrolled wiring and
says so.
2026-09-13 06:41:04 -07:00
ozymandiashh
3a70e9bcb7 fix(app): open the sessions behind a pull request row
The Pull requests section imported the PR selection builder and threaded
the drill-through callback through four component levels, but the row's
only handler was expand/collapse, so neither was ever invoked: every
other aggregate (day, model, category, project) reached the filtered
session list and the one report that names shipped work did not.

An expanded row now carries its own "View sessions for this pull request"
control above the work breakdown, matching the project entry in Spend. It
selects the PR by URL — the aggregation key of the by-PR report — and,
being a control of its own rather than the row, never toggles the
expansion it sits in. Rows with no per-turn detail get it too, and the
section renders no affordance at all when there is no destination wired.
2026-09-13 06:41:04 -07:00
iamtoruk
029843c13d Wire cohort samples to the real drill-through, scope and serve the new 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().
2026-09-12 14:02:01 -07:00
ozymandiashh
e78f4b9e70 Fix cohort accounting and exact project selection 2026-09-12 14:01:29 -07:00
ozymandiashh
9a383dca30 Add Compare cohorts mode with population disclosure, samples, and volume band
Desktop cohorts mode talks to the new cohort-json format through two
typed bridge channels (facets + report) with argv validation for models,
repeatable project patterns, and categories. The section keeps the
classic mode side by side; the cohorts view shows the population before
any metric (included observations, distinct sessions, excluded mixed-
model turns with their combined cost, unknown-cost count), an Inspect
samples list of the declared population through a minimal navigation
adapter (sampleNavigation.ts), cost median/P90/mean with a compact
histogram whose top bucket is open-ended, one-shot/retry rates over the
declared population, and token volume with input + cache-read labeled as
a context proxy. The volume band recomputes renderer-side over the
report's own observation list (cohortStats.ts mirrors the core
convention, pinned to the same test vector), excludes and counts
observations without a token measure, and never reads missing data as
small. CODEBURN_USER_DATA_DIR opts into an isolated Electron profile so
parallel dev runs get their own userData/serve.pid.
2026-09-12 14:01:29 -07:00
iamtoruk
b85c175a96 fix(compare-periods): real drill-through, project scope, clean date errors
Rebase fixes on top of #1296.

- App.tsx shipped a stub inspectRange calling a setCustomRange that no longer
  exists after #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 (#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.
2026-09-12 13:43:41 -07:00
ozymandiashh
fdc69ea235 Fix period comparison identities, daily deltas and detail cache 2026-09-12 13:43:24 -07:00
ozymandiashh
9a14f8d4b0 feat(desktop): Compare periods screen with contribution drill-down
New sidebar section 'periods' (Compare periods, shortcut 9) rendering
sections/PeriodCompare.tsx: preset last-7-complete-days vs prior 7 or two
custom calendars with a swap control; range meta shows both spans, the
duration delta and any overlap; totals, normalized per-day and per-100-calls
tables (denominators printed, zero denominators render as em dash); project
and model contribution lenses with New/Gone badges and click-to-inspect
session drill-down joined across A and B; coverage block for unpriced models
and aggregate-only carried history. A/B selection, lens and view persist in
localStorage so returning to the screen keeps the selection.

Navigation adapter until the goal-8 navigation lands: onInspectRange opens the
existing Sessions section scoped to the requested range via the app's
custom-range state; the Overview entry card links here. Renderer styling
follows the existing panel/table conventions.

Includes component tests (fixture report, New/Gone labels, per-100-calls
recomputation with zero-call sides, persistence across remounts, lens
switching) and user documentation at docs/compare-periods.md.
2026-09-12 13:43:24 -07:00
ozymandiashh
833d97fa1d feat(desktop): typed IPC channels for period comparison
Two bridge channels follow the existing envelope + argv-validation pattern:
codeburn:getPeriodCompare spawns compare-periods --format json with two
REQUIRED local YYYY-MM-DD range pairs (validated per range), and
codeburn:getPeriodCompareSessions spawns the sessions drill-down for one
project/model contribution key. Contribution keys ride the --key VALUE
position, so a dash-leading slug (Claude sanitizes /work/pricing to
-work-pricing) passes vContributionKey where vToken would wrongly reject it.
Preload and the renderer CodeburnBridge types mirror the two calls.
2026-09-12 13:43:24 -07:00
iamtoruk
dc8583fde8 Scope the By branch fetch by the app project filter
getBranchSpend was the only data fetch in createBridgeHandlers without
projectArgs(), so a project hidden by the Projects pane filter still showed
its branches in the Spend > By branch lens.

Extends the existing "scopes every fetch" test to cover the channel.
2026-09-12 13:25:15 -07:00
ozymandiashh
bb6a67b521 Restore the standard desktop development port 2026-09-12 13:09:00 -07:00
ozymandiashh
810d91169a Move desktop dev server to port 5720
The default 5173 collides with parallel CodeBurn worktree sessions sharing
one machine. strictPort stays on so a busy port fails loudly instead of
silently drifting; VITE_DEV_SERVER_URL follows the same port in the dev
script. Note the port does NOT isolate the Electron userData profile —
parallel sessions must still run the app one at a time.
2026-09-12 13:09:00 -07:00
ozymandiashh
28120c313f Add Spend By branch lens (renderer -> IPC -> branch-json report)
New getBranchSpend bridge channel (codeburn:getBranchSpend) spawning
'spend --format branch-json' with the same period/provider/range flags and
validation as the other first-click reports, plus background-priority
prefetch handling. The renderer keeps the typed contract in lib/types.ts.

BranchBreakdown panel: project picker (auto top project, explicit All
projects view labeled project/branch), expandable branch rows with token
components, worktree evidence and per-session contributions, a real session
inspect detail, and the coverage note (known / Unknown / no-branch-data,
identity-based distinct sessions). Reuses ListRow/Panel/Dropdown/stale-safe
usePolled memo keys; selection is derived so a refresh or a vanished project
falls back instead of mixing data.
2026-09-12 13:09:00 -07:00
torukmakto
989d953a78 Scope the drill-through fetch by the Projects filter and fix dead drill entries
Rebasing onto main put the new getSessionsContributions handler beside the
Projects-pane filter from #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.
2026-09-12 12:39:37 -07:00
ozymandiashh
756af7fcdf Fix drill-through provider, day and model attribution 2026-09-12 12:22:19 -07:00
ozymandiashh
d1dcc82ee5 Wire drill-through into the desktop app: entries, chips, contributions, drawer, history
Every report grows real entries: Overview day bars, expensive sessions
(provider+id matched), model names, task categories, Spend projects,
and PR cards. The Sessions destination renders the selection chips with
per-chip removal and Clear, fetches the contributions report once per
population (widened to cover the selected days so a day outside the top-bar
period still reconciles), computes every chip combination client-side over
the full population, and shows each row's contribution beside its full
cost. Row clicks open the side drawer (Escape closes, focus returns); the
top bar gains Back/Forward (Cmd+[ / Cmd+] on macOS, Alt+arrows elsewhere)
over the in-app history; the position survives a renderer restart. IPC
gains getSessionsContributions with the same argv validation as the plain
report.
2026-09-12 12:22:19 -07:00
ozymandiashh
f2491d17b2 Add the drill-through investigation state, selection math, and session drawer
InvestigationFilters is a normalized, serializable selection (days,
providers, projects, models, categories, PRs, project-scoped branches,
provider-scoped sessions) with OR within a dimension and AND across them.
Contribution math walks each row's segments and multiplies per-dimension
shares, so sums reconcile every dimension's aggregate exactly; rows without
segments are excluded and disclosed. NavState + the history stack back the
in-app Back/Forward (filters, sort, page depth, open drawer) and the
restart snapshot. The drawer shows metadata, full totals beside the
in-selection figures, and the per-model/category/branch/day/PR breakdowns
with an Escape-and-focus-return contract.
2026-09-12 12:22:19 -07:00
iamtoruk
4b9659bd78 fix(app): drop the instant-switch memo when the filter changes outside 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.
2026-09-12 06:01:23 -07:00
iamtoruk
a3f2b0b112 feat(app): search and cost order for the Projects pane
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.
2026-09-12 06:01:23 -07:00
iamtoruk
6d45db1e08 fix(app): re-read the project filter when it changes outside the window
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.
2026-09-12 05:50:41 -07:00
Mathieu Stanowski
435a5c8d95 test(app): move the project-match parity test to the CLI suite
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/.
2026-09-12 05:38:52 -07:00
Mathieu Stanowski
af10747e5d perf(app): serve the JSON report from the resident child
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.
2026-09-12 05:38:52 -07:00
Mathieu Stanowski
946fb75696 fix(app): stop reporting an export that wrote nothing as a success
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/.
2026-09-12 05:38:52 -07:00
Mathieu Stanowski
f76ee91526 fix(app): list projects for the whole history, not the visible period
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.
2026-09-12 05:38:52 -07:00
Mathieu Stanowski
1e34d36144 fix(app): fail closed when the project filter cannot be read
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.
2026-09-12 05:38:52 -07:00
Mathieu Stanowski
1b006ed2f7 fix(app): expand a leading ~ in a project pattern typed into the pane
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.
2026-09-12 05:38:52 -07:00
Mathieu Stanowski
6cac9d929c feat(app): add a Projects pane that scopes the desktop app to chosen 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.
2026-09-12 05:38:52 -07:00
Aditya Vikram Singh
18b3f6f948 fix(desktop): keep settings navigation from shrinking 2026-09-09 21:37:25 +05:30
Resham Joshi
159198be6c
Merge pull request #1271 from avs-io/codex/project-identity-session-counts
Some checks failed
CI / semgrep (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (22.13.0) (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
Tests / desktop (push) Waiting to run
macOS Menubar CI / test (push) Has been cancelled
Windows Menubar CI / check (ubuntu-latest) (push) Has been cancelled
Windows Menubar CI / check (windows-latest) (push) Has been cancelled
fix(usage): preserve project identity and qualify session counts
2026-09-08 09:27:57 +03:00
Aditya Vikram Singh
a8cfce0c9f
Merge pull request #1169 from ksp2000/feature/standardize-model-capability-tiers
feat: standardize model capability tiers
2026-09-08 10:07:27 +05:30
iamtoruk
df38e63849 fix(usage): fold Windows case in spend identity, qualify --json counts, drop scratch tests 2026-09-07 14:56:32 -07:00
Aditya Vikram Singh
0a7a281482 test(electron): stop chatty watchdog smoke racing Node boot
Independent default app npmtest killed the chatty optimize child at 614ms
because the 600ms idle timer started at spawn and the first progress byte
waited on Node boot plus setInterval. Emit the first stderr byte immediately
after boot, then ten 400ms ticks (result ticks 11) under a 2s silence budget.
Node boot still counts; the larger smoke window absorbs it. Work still
outlives a fixed total-runtime cap. Production already resets on every byte;
timeout constants unchanged.
2026-09-07 22:06:09 +05:30
Aditya Vikram Singh
f5fd47e83d fix(usage): preserve project identity and qualify incomplete session counts 2026-09-07 22:02:54 +05:30
iamtoruk
a0e0b9f866 chore: release 0.9.24 2026-09-04 02:05:03 -07:00
iamtoruk
02c3ab21dd chore: keep real people and machines out of a public repository
An audit of everything on main since v0.9.23 turned up five places where
real detail had been used where an invented value would have done. None of
them is a credential and none identifies a customer, but a public
repository is the wrong home for any of it.

perf/README.md cited an absolute path into a private audit workspace on a
contributor's own machine, naming their home directory, the workspace's
naming scheme and a run timestamp accurate to the second, as "evidence" no
reader can open. The number stays; the path goes, and the text now says
plainly that the artifact is not published. The same file described the
measurement corpus as the founder's 35 GB of session history, which is a
personal fact about one identifiable person, so it is now described by what
it is rather than by whose it is.

The remaining three are fixtures: a private product name as a working
directory, the maintainer's real operating-system username inside the very
tests that assert such a path is redacted, and their two machine names in
the sharing tests. Using the real values proved nothing the invented ones do
not, and the redaction tests read better when the string being scrubbed is
obviously synthetic.
2026-09-03 12:38:11 -07:00
iamtoruk
5f09d9735f fix(windows): make the cross-process lock test poll, not spin, so it passes on Windows
The rename retry landed, but its test kept the watcher reading in a
tight loop, and on real Windows that lost 8 runs in 12: a reader holding
the file open every instant is a race no bounded retry can win, because
an open handle blocks a rename until it closes. That is not a reader
either app has. The watcher now polls at 1ms, which still samples the
file thousands of times and still catches a lost update, while leaving
the writers room to rename. The locked path passes 15 of 15 on Windows,
and the unlocked path still reports a rolled-back write.

Also restores the lineage case the review asked for: a refresh where the
account id and refresh token are unchanged and only the id_token subject
moves, so the subject comparison is what discards the write. Both copies.
2026-09-03 11:28:01 -07:00
iamtoruk
96bf1984ff fix(windows): wait out a reader when replacing a preference file
The Windows CI leg failed on the cross-process test with EPERM from
renameSync. It is not a test artifact. Windows refuses a rename over a
file another process holds open rather than waiting, with
ERROR_ACCESS_DENIED or ERROR_SHARING_VIOLATION, and reads of these two
files are deliberately lock-free on both sides. So any tray or app read
that overlaps a writer's replace fails that write, and since this branch
made writers report a failure instead of swallowing it, the outcome is
exactly the lost update the lock exists to prevent, reached by another
route. The test's reader thread only made it visible by reading the way
both apps really do, continuously and without the lock.

The replace is now retried on that error class, ten attempts about 20ms
apart, on both sides: replace_file in settings.rs, used by settings patch
and by the dock's write_state_at, and renameOnto behind writeFileAtomic
in tray-settings.ts. The lock is already held at that point, so the wait
can only ever be on a reader, never on another writer, and a read of one
of these files is microseconds of open file. Once the budget is out the
original error is returned unchanged and the caller cleans up as before.
On POSIX, where a rename over an open file cannot fail this way, it
compiles out in Rust and short-circuits on process.platform in Node.

Reads stay lock-free, which is the right trade and the reason the files
can be read at all without coordination; both read paths now say what it
costs and where that cost is absorbed. The reader thread stays as it is,
and is now the regression test for the retry as well: it is what puts a
replace under a continuous reader.

The retry itself is covered on the Node side by faking the platform and
the rename, since a rename that fails this way cannot be produced on a
Mac: a reader waited out and the write landing, the budget running out
with the old file still whole, and an error a reader cannot cause not
being waited out at all. The Rust half is compiled out off Windows, so
CI is its only proof.
2026-09-03 11:10:33 -07:00
iamtoruk
a1b4b22f51 fix(windows): close three holes in the cross-process preference lock
writeDockEnabled still did its own read, mutate and atomic write of
windows-dock.json, outside the lock the rest of the module takes. It is
the Node side of the dock's enabled switch, reached from the desktop
app's Sidebar toggle, so a toggle there could still land between the
tray app's read and its rename and erase whatever it had just stored,
which in practice is the rail's placement. It now merges through
patchTrayFile, which takes the lock for the whole cycle; enabled is
already an accepted dock key, so nothing is dropped on the way.

Stale-lock recovery could hand out two owners at once. Both sides did
"if abandoned, unlink and retry", and nothing stood between the check
and the unlink: contender A could already have removed the stale lock
and created a fresh one of its own, and B's unlink then deleted A's
fresh lock, leaving both of them holding the file. Windows' share mode
hides this most of the time, because a lock a live holder still has open
will not unlink at all, but the same protocol runs on Linux and macOS,
where the unlink always succeeds. Removing an abandoned lock is now
itself arbitrated, by the same exclusive create the lock uses, on a
sibling <lock>.takeover file. Only its winner may unlink, and only after
re-checking staleness under that right, so a rival that reclaimed first
keeps the lock it now holds. A takeover file is dropped on every path
out, never held across the wait, and one left behind by a reclaimer that
died is freed by the same staleness rule as the lock itself.

The cross-process test asserted only each side's final value, so it
noticed a lost update only when the last writes happened to collide: on
a deliberately broken lock it passed about one run in three, which is
weak evidence for the property it exists to prove. Each side now writes
a counter that only rises, and a reader thread watches the file for the
whole run. A separate reader is the point: neither writer can see its
own counter rolled back, because in the unlocked cycle each carries the
other side's value forward itself, so what it reads back is never older
than what it last read. With the lock both counters only ever rise in
the file; without it one falls. It now fails on every unlocked run.

Also: a placement that cannot be saved is logged instead of discarded
silently, since losing the lock under contention is a new way for the
rail to revert at the next launch; and the Codex sameLogin comment now
states outright that a replacement document carrying none of the three
identifying fields reads as the same login and is written over, which is
the deliberate side to err on.
2026-09-03 10:28:05 -07:00
iamtoruk
615c94241b fix(windows): serialize tray and dock preference writes across processes
The desktop app and the tray app both read, merge and rename the same
preference files. The atomic rename stopped a torn file but not a lost
update: both read state A, each changed a different field, and the last
rename erased the other's change, so dock placement, enabled state,
provider choice or scale silently reverted.

One cross-process lock now covers the whole read-modify-write cycle,
designed once and implemented in both Rust and Node against the same
protocol: a sibling .lock file taken by exclusive create, carrying the
holder's pid and timestamp, taken over only when abandoned by a dead pid
or a stale mtime, and failing loudly rather than writing behind a live
holder. It follows the CLI's existing cache-refresh lock. All three
sites use it, including the dock's enabled, provider and placement
writes. A test drives real Node and Rust processes at the same file and
fails without the lock.
2026-09-03 07:59:42 -07:00
iamtoruk
7533e96fe3 fix(quota): discard a Codex refresh whose login changed under it
The refresh reread auth.json before writing the rotated tokens but only
checked it was still ChatGPT mode, not that it was still the same login.
A `codex login` account switch, or a second CodeBurn process refreshing
the same credential, landing while our refresh was in flight let the late
response splice one account's tokens into another's document: a new
account id over an old refresh token, or an older refresh token over a
newer one. Either signs the user out or binds them to the wrong account.

The login the grant belongs to is now captured before the grant and
compared against the reread document on account id, refresh token and
id-token subject. A demonstrated mismatch discards the write and says so.
An unreadable or key-sparse file is not a mismatch and still writes, so a
rotated token is never dropped. Both the CLI and the Electron copy.
2026-09-03 07:59:42 -07:00
iamtoruk
378062ebc2 Merge remote-tracking branch 'origin/main' into feat/windows-capacity-dock 2026-09-03 05:16:32 -07:00
iamtoruk
972e3b8a3d docs: stop three telemetry disclosures contradicting themselves
The onboarding screen, the privacy settings and the README each said the
daily report includes the names of the models, tools, skills and MCP
servers in use, and then in the next breath that it never includes
anything identifying. A server named after an employer is identifying,
so the second half was not true. All three now use the wording the tray
notice already had, which names what is withheld rather than claiming
more than the product does: never your prompts, your code, or your
project and file names.
2026-09-03 04:52:31 -07:00
iamtoruk
9640cdd9c7 fix(app): remember a pending restart across a desktop app restart
The reboot-pending flag lived in memory with a comment claiming the
restart it waits for also clears it. Quitting the desktop app and
opening it again cleared it too, and that is not the restart being
waited for, so the next launch started the old tray binary under the new
version's name, which is the confusion the flag exists to prevent.

It is saved as a timestamp now and read back by comparing it against
when Windows last booted, so only a real restart clears it. The test
that asserted the old behaviour crossed the boundary by restarting the
app; it now moves the boot time, and a second test covers restarting the
app without restarting Windows.
2026-09-03 04:52:31 -07:00
iamtoruk
ff2ba5c94a fix(app): typed IPC patches, the staged-msi flag, and honest consent copy
- Tray preference patches from the window were used with `in` before
  any type check; every patch handler now refuses anything that is not
  a plain object.
- The tray install passes `--staged-msi <path>` to the CLI instead of
  an environment variable.
- A timeout or a missing CLI no longer counts as a declined install,
  so it is retried at the next launch; only a cancelled prompt is
  remembered. After msiexec reports a pending restart the old binary is
  not launched, and the sidebar says a restart finishes the install.
- The telemetry opt-in event fired before the toggle was applied and
  could never be sent; it fires after a successful write.
- The ARM64 installer carries the x64-named tray, since the CLI accepts
  only that asset name; the distribution notes say so plainly.
- The README, the onboarding screen and the privacy settings say that
  the daily report includes the names of the models, tools, skills and
  MCP servers in use, and the renderer's fallback builder reports zero
  turns as zero.
2026-09-03 03:06:13 -07:00
iamtoruk
2b06a3a5e4 feat(app): send the CLI's telemetry snapshot and a few interaction events
The daily usage_snapshot event now carries the payload's
telemetrySnapshot verbatim, with the old renderer builder kept as the
fallback for an older CLI. Five name-only events join it: optimize_apply
with the fix kind, plan_set with the provider, export with the format,
compare_view with the two models, and settings_change with the setting
and its enum or boolean value.

The props sanitizer had allowed one level of arrays of flat objects and
would have stripped the snapshot's nested model and task rows; it walks
plain objects recursively now, five levels deep at most and a thousand
leaves per event, leaves still short strings, finite numbers and
booleans only. The README gains a Telemetry section listing every event
and field and how to turn it off.
2026-09-03 01:18:23 -07:00
iamtoruk
058bd57808 build(app): an ARM64 Windows installer that actually contains the program
7-Zip compresses ARM64 executables with its ARM64 branch filter by
default. The decoder inside the NSIS installer predates that filter, so
extraction dropped every .exe and .dll while the data files landed, and
the installer exited zero with no program in the directory. A new
package:win:arm64 script pins the BCJ filter through the electron-builder
override, and the distribution notes say why.
2026-09-03 00:01:35 -07:00
iamtoruk
7d4c86bc82 fix(app): seed launch at login again after reinstalling the tray
The Run value was seeded once per machine. Uninstalling the desktop app
removes the tray and, with it, the Run value; reinstalling put the tray
back but the seeded flag survived in the companion settings, so launch
at login was silently off afterwards. A tray app the current launch has
just installed now seeds the value as a first run does.
2026-09-03 00:01:34 -07:00
iamtoruk
f03a3133e2 build(app): allow a slow Electron start in the CLI staging smoke test 2026-09-03 00:01:34 -07:00
iamtoruk
9eafaefbfa fix(app): the desktop uninstaller really removes the tray it installed
Two faults in the uninstall hook, found by running it for the first time:

- NSIS has no doubled-quote escape, so the '' written for PowerShell's
  single quotes ended the NSIS string at the first one. The plugin got a
  truncated command PowerShell could not parse, and the hook silently
  did nothing: uninstalling the desktop app left the tray, its Run value
  and its marker behind. Each inner quote is now the NSIS escape.
- An upgrade runs the previous version's uninstaller first, with the
  updated flag, and the hook removed the tray there too, so every desktop
  upgrade uninstalled the tray and reinstalled it with an elevation
  prompt. The hook now leaves the tray alone during an upgrade.
2026-09-03 00:01:34 -07:00