Skip to content

Add opt-in Codex account and session provider - #14

Merged
fdussert merged 5 commits into
fdussert:mainfrom
FlorianBruniaux:codex/codex-readonly-provider
Oct 15, 2026
Merged

fdussert merged 5 commits into
fdussert:mainfrom
FlorianBruniaux:codex/codex-readonly-provider

Conversation

@FlorianBruniaux

@FlorianBruniaux FlorianBruniaux commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Adds an opt-in, read-only Codex provider for account quotas, token usage and selected local chat history. A separate codex-live channel projects observed turn state, model, elapsed time and direct subagents from bounded local records. Opening a chat requires its exact ID in the desktop catalog and validates it again before using the Codex deep link. The provider does not start a Codex child while disabled.

The admin privacy settings select account reads and history sources independently. The history setting explains that titles, model and folder or branch labels reach subscribed widgets, including marketplace widgets. Subagent source types are grouped under a disclosure. No account email, credential or conversation body is published. The source enum lives apart from process code so loading configuration cannot start a Codex child.

An unconfigured subscribed channel polls every 60 seconds so an opt-in is picked up promptly. docs/codex.md describes the versioned desktop SQLite schemas and the read-only process boundary. The branch is rebased on the account-email privacy setting in #25 and leaves that setting intact. The user verified the exact-chat deep link on their XENEON setup; this clean branch has not been installed there.

The account and sessions widgets are proposed separately to fremkit-sietch.

Checks

  • pnpm typecheck and pnpm build passed at 1d1a2c3.
  • Server tests: 1,454 passed with test/app.test.ts excluded locally because its external favicon request timed out in this environment. UI tests: 385 passed.
  • git diff --check passed.
  • Real-account authentication, incidental CLI credential refresh and native XENEON behavior remain unverified on this branch.

Latest review pass

Follow-up review: a disabled Codex account clears retained account data before a failed read, and removed history sources cannot be replayed or opened. Added regression tests for both cases and a split JSONL record. Local server and UI suites, typecheck and builds pass.

@fdussert fdussert left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this — it's a substantial piece of work, and a Codex provider does belong in core (local binary + credentials, widgets in the registry), so the overall direction is right. There is also a lot done well: the provider is fully inert when disabled, symlinks are refused, reads are bounded to sessions//archived_sessions/ with size limits, the child environment is allowlisted, stderr is never relayed, tokens never reach the snapshot, and the deep link is validated twice against the catalog. Before it can land, though, there are some larger changes I'd ask for:

Opt-in mechanism (server/src/codex/config.ts, server/src/index.ts)
Fremkit already has a pattern for opt-in account reads: privacy.claudeAccountUsage in server/src/config/schema.ts, with a migration, a test and a checkbox in ScreenInspector.vue, read on every poll via enabled: () => store.get().privacy.... Please follow it (e.g. privacy.codexAccount plus a history-sources setting) instead of a hand-written data/codex.json and env vars that need a restart, and register the provider in buildApp next to the Claude ones so it's covered by the app tests.

Second app-server and OAuth refresh (server/src/codex/adapter.ts, docs/codex.md)
Spawning a second long-lived codex app-server with the user's credentials is the part I'm most worried about. The docs say incidental token refresh "has not been measured". If refresh tokens are single-use, two processes refreshing concurrently can sign the user out of the desktop app or CLI — the same class of failure we had with Homey (see AGENTS.md). Could you either show that the app-server never refreshes with refreshToken: false, or avoid the long-lived child (one short-lived child per account poll)? Relying on experimentalApi, supportsLunaReserve and explicitGatewayOauth pinned to CLI 0.159.2 also needs a sentence on what happens when they change.

Email on the channel (server/src/providers/codex.ts)
Please drop email from account.data. A quota widget doesn't need it, and claude-account doesn't publish one; plan type and auth mode are enough.

Code style (server/src/codex/observations.ts, parts of providers/codex.ts, test/codex-provider.test.ts)
These files are effectively minified: chained statements, no spacing, any, a 600+ character SQL line. Please format them like the rest of the codebase (one statement per line, named helpers, SQL as a multi-line template). As it stands the security-relevant parts are hard to review properly.

Scope (server/src/codex/projects.ts)
Project grouping (.codex-global-state.json up to 8 MB, legacy project-id migration maps) serves a codex-sessions widget that doesn't exist yet. Could it move to a follow-up PR? A first version with quotas, usage, history and the validated open is much easier to land, and each undocumented Codex file we read is one more thing that can break silently on a Codex update.

Process cost (server/src/codex/observations.ts, server/src/providers/codex.ts)
codex-live spawns two or three sqlite3 processes every 5 s, and each history refresh validates threads one by one, up to 50 sequential sqlite3 runs. Please validate the whole page with one IN (...) query and cache or merge the capability check — a dashboard runs all day. A PRAGMA query_only next to -readonly wouldn't hurt either.

Retry cadence (server/src/providers/codex.ts)
intervalMs drops to 15 s on any error, including unsupported and unconfigured. With no binary on PATH that reruns codex app-server generate-json-schema every 15 s, and an API-key account polls account/read every 15 s forever. Please keep the fast retry for transient errors (offline) and back off for durable ones.

open binary
Please call /usr/bin/open by absolute path, like /usr/bin/sqlite3 elsewhere in this PR.

Docs, changelog, commits
Please add codex and codex-live to the channel list in docs/writing-widgets.md, double-check the learn.chatgpt.com links, and drop the hardware brand mention. The CHANGELOG line should tell a Fremkit user what they get and how to turn it on. Splitting the commit (adapter / account + history provider / live observations) would also match the "small commits" rule in AGENTS.md.

I know that's a long list for a first contribution of this size — happy to discuss any of it, and thanks again for the care that clearly went into the security side.

@fdussert

Copy link
Copy Markdown
Owner

A follow-up on the email point of my review, to give you a clearer rule (the same one applies to the Claude account in #19):

Fremkit will get a single privacy setting, privacy.showAccountEmail, off by default, with a checkbox in the Screen inspector next to the existing account-usage one. We'll add it on our side in a separate PR. The rule for every account provider will be:

  • When the setting is off, the provider does not publish the email at all. The check happens on the server, not in the widget, because any widget subscribed to the channel (including a marketplace one) receives what is published.
  • When it is on, the email can be published alongside the account data.
  • Plan type and auth mode don't depend on it and can always be published.

So for this PR: please leave email out of account.data for now. Once the setting lands, publishing it behind store.get().privacy.showAccountEmail (read on each poll, like claudeAccountUsage) is welcome, either here after a rebase or as a small follow-up. Sorry for the moving target, and thanks again!

@fdussert

Copy link
Copy Markdown
Owner

Thanks a lot for this rework — it's a substantial rewrite, and it addresses almost everything from the first round. The opt-in now goes through privacy.codexAccount / privacy.codexHistorySources, with a migration test and the admin checkboxes, and it's registered in buildApp. The app-server child is short-lived per poll, the email stays out of account.data, project grouping moved out, there's one IN (...) validation query with PRAGMA query_only, the capability cache is in, the retry backs off for durable errors, /usr/bin/open is absolute, the docs and CHANGELOG are updated, and the commits are split. Typecheck and the full test suite are green here.

A few remaining items before merging:

  1. Formatting, part two. observations.ts reads well now, thank you. adapter.ts (e.g. L105, L114, L121, L143), snapshot.ts (one-line schemas), providers/codex.ts (L10, L85–88, L120, L130, L152), test/codex-provider.test.ts and test/codex-observations.test.ts L30–31 (minified, with any) still need the same treatment: one statement per line, schemas spread over several lines.
  2. Interval while disabled. When the provider is off it publishes unconfigured, and intervalMs then returns 300 s. A widget that is already subscribed can wait up to five minutes after the user ticks the box, while the docs say the setting applies on the next poll. Could unconfigured keep the normal 60 s cadence?
  3. Privacy hint for history sources. Enabling a source publishes chat titles (often derived from the first prompt), branch names, a folder name and the model to any widget subscribed to codex / codex-live, including marketplace ones. Please add a hint under the source checkboxes that says so, like the Claude usage hint does. Ten checkboxes is also a lot; consider grouping the subagent subtypes behind "Subagents".
  4. Layering. config/schema.ts imports HistorySourceSchema from codex/adapter.ts, which pulls child_process into the config schema. Moving the enum to snapshot.ts or a small codex/sources.ts would keep the config free of the adapter.
  5. Undocumented files. state_5.sqlite carries a version in its name, and sqlite/codex-dev.db belongs to the desktop app. Both fail closed, which is right; a sentence in docs/codex.md saying codex-live / navigation will go quiet on a Codex schema bump would help the next person debugging it.
  6. Refresh (non-blocking). Since the provider now starts a child every minute, could you leave it running for a few hours with account reads on and check that ~/.codex/auth.json (mtime / last_refresh) only changes when the desktop app or CLI refreshes on its own? A sentence with that result in the docs would close the Homey-class question.
  7. Rebase. The branch now conflicts with main (Fix sandboxed widget startup in WebKit #10, Expand Mac system metrics and uptime tiles #16 and Add local Docker and model observation channels #17 landed today).

Heads-up: we're about to land privacy.showAccountEmail (with a withAccountEmail(email, show) helper in server/src/privacy.ts). It touches the same privacy literals, so expect small textual conflicts in schema.ts, migrate.ts, types.ts, ScreenInspector.vue and four UI tests on rebase. After that, publishing the email behind the setting is welcome.

Thanks again — this is close.

@FlorianBruniaux
FlorianBruniaux force-pushed the codex/codex-readonly-provider branch from ab69ee2 to 0329ebd Compare October 15, 2026 16:02
@FlorianBruniaux
FlorianBruniaux force-pushed the codex/codex-readonly-provider branch from a23903b to 3685fdd Compare October 15, 2026 16:20
fdussert added a commit that referenced this pull request Oct 15, 2026
The Codex provider in #14 publishes the account under account.data, and
gateAccountEmail only looks at the top level of what it is given, so
gating the whole snapshot would leave a nested address in place. The
helper stays a single-level one, which keeps it obvious; the contract
now says to apply it to the object that carries email, on the fresh,
error and stale paths alike, with a nested example and a test that also
shows gating the outer object changes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fdussert added a commit that referenced this pull request Oct 15, 2026
They compared the whole privacy section with toEqual, so the first
branch to add a key there (#14, #22) would break them with no git
conflict to say why. toMatchObject checks the two keys this setting is
about and nothing else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@fdussert fdussert left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, Florian — every point from the last round is addressed: the 60 s cadence while disabled, the privacy hint and grouped subagent sources, codex/sources.ts so the config no longer pulls in the adapter, the notes on versioned Codex files, and much more readable code. Typecheck and the full suite pass here. Approving. One note on order: #25 (privacy.showAccountEmail) lands first, so this will need a small rebase on the privacy literals; I'll merge right after.

FlorianBruniaux and others added 4 commits October 15, 2026 18:55
Constrain app-server methods, isolate the child environment, cache schema discovery, and validate local desktop chat IDs in one SQLite query.

Co-Authored-By: Claude <noreply@anthropic.com>
Use one read-only SQLite query per poll and bounded verified journal reads. Keep working state explicit when observations become stale.

Co-Authored-By: Claude <noreply@anthropic.com>
Expose live privacy controls beside Claude, keep account email private, close each app-server child after its poll, and document the unsupported/runtime boundaries.

Co-Authored-By: Claude <noreply@anthropic.com>
Keep unconfigured polling responsive, separate source schema from transport, clarify history exposure, document versioned databases, and improve readability.

Co-Authored-By: Claude <noreply@anthropic.com>
@FlorianBruniaux
FlorianBruniaux force-pushed the codex/codex-readonly-provider branch from 3685fdd to 1d1a2c3 Compare October 15, 2026 16:55
Co-Authored-By: Claude <noreply@anthropic.com>
@fdussert
fdussert merged commit c9b4a1c into fdussert:main Oct 15, 2026
1 check passed
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