Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Anything that changes what the dashboard, the admin or a widget can do gets a li

## Unreleased

### Added
- Add read-only Codex account quotas, token usage, selected local chats and observed turns. Enable account reads or select history sources in the admin screen privacy settings; both start off. History selection explains that titles and labels reach subscribed widgets. A chat opens only after exact-ID validation against the local desktop catalog. Account email is not sent to widgets. Removing a history source or disabling account reads also removes its cached fields if the next Codex read fails.

### Changed
- **Clock in the compact bar.** Show an accent-coloured clock icon beside the time, matching the weather icon.
- **The system tiles show useful Mac capacity.** Disk usage uses the APFS data volume and shows available space; memory shows available RAM and swap.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ What the installer checks, what a consent record is and how an update asks again
How to obtain each credential, what is stored where, and what is never logged:
**[docs/connections.md](docs/connections.md)**.

The optional [Codex provider](docs/codex.md) reads selected local account and chat data after an explicit opt-in. Its dashboard widgets are distributed separately.

## Backup

**/admin → Screen → Backup** downloads the whole dashboard — the configuration and the background
Expand Down
58 changes: 58 additions & 0 deletions docs/codex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Codex account, history and observed turns

The `codex` channel provides read-only account quotas, token usage and selected local chats. The `codex-live` channel reports observed turns and direct subagents for those selected chats. Both channels are disabled by default and require an installed Codex CLI. Widgets belong in the registry.

## Enable the data you want

In the admin's screen privacy settings, enable **Codex account usage** for account, quota and token reads. Select one or more **Codex history sources** for bounded local history reads. The available sources are `cli`, `vscode`, `exec`, `appServer`, `subAgent`, `subAgentReview`, `subAgentCompact`, `subAgentThreadSpawn`, `subAgentOther` and `unknown`. The broad `subAgent` selection includes its subtypes. An unknown source requires explicit selection.

These settings take effect on the next provider poll without a restart. An unconfigured subscribed channel keeps a 60-second polling cadence, so a new opt-in is picked up at its next scheduled poll. Turning account reads off clears the displayed account data. Removing every history source clears selected history and live observations. Older dashboard configurations migrate with both settings off. No widget installation grants consent to read Codex account data.

`buildApp` registers the provider beside the Claude providers and passes callbacks for `privacy.codexAccount` and `privacy.codexHistorySources`. Constructing the provider does not start a child process or read the desktop catalog. A subscribed channel starts reading only after its corresponding opt-in. The helper must be able to find `codex` on its inherited `PATH`; the provider does not scan other installations or edit Codex configuration.

## Read-only process boundary

The adapter discovers candidate methods from the installed CLI's generated `ClientRequest.json` schema and caches the capability result briefly. Schema presence alone does not establish account access; a runtime method-not-found response marks that method unsupported for that poll.

A separate stdio app-server child runs for each account or history poll and closes when the poll ends. It does not attach to the desktop daemon, its control socket or a proxy. Only these methods are permitted:

| Method | Fixed request constraints |
|---|---|
| `account/read` | `refreshToken: false` |
| `account/rateLimits/read` | `supportsLunaReserve: false`, `excludeResetCreditDetails: true` |
| `account/usage/read` | Empty parameters |
| `thread/list` | Explicit sources, `useStateDbOnly: true`, `archived: false`, `sortKey: updated_at`, limit 50 |

Initialization is adapter-owned. Conversation creation, resume, turns, login, logout and account-changing actions are refused before transport use. Server-initiated approval and external auth-token refresh requests are refused. Child arguments disable hooks and analytics. The child environment contains only process lookup, home, temporary-directory, locale and system-directory variables. Provider credentials and arbitrary parent variables are excluded. Stderr and protocol error text never enter snapshots or logs.

`refreshToken: false` forbids a requested refresh on `account/read`. This change does not prove that CLI startup has no incidental authentication side effects. The short-lived child avoids keeping a second app server beside the desktop app. Timeout or disconnect rejects pending reads; a stopped poll cannot publish its result.

The request constraints came from the installed CLI 0.159.2 schema. Earlier or later CLIs may change `experimentalApi`, `supportsLunaReserve` or `explicitGatewayOauth`, reject fields or lack methods. The provider reports `unsupported` or `offline` and does not retry with less restrictive requests. Durable errors back off for five minutes; only transient `offline` errors retry after 15 seconds.

## Snapshot and local chat opening

`CodexSnapshot` is exported by `server/src/providers/codex.ts`; the detailed types are in `server/src/codex/snapshot.ts`. Each account, quota, usage and history section carries data, update time, freshness and a fixed error reason. A failed refresh preserves last valid data as stale. Authentication rejection clears account data. A detected account or workspace identity change clears prior quota and usage data. No credential, workspace ID or account email is sent to a widget. `account.data` contains only authentication type and, for ChatGPT authentication, plan type. It is not a per-chat account binding.

History returns at most one page of 50 non-archived, non-ephemeral records. A cursor and `truncated` disclose an incomplete page. Rollout paths, working directories, prompt previews and turn bodies are excluded. Stored status and source do not prove live desktop activity.

A card's `codex/open` command accepts an exact thread UUID only from a loopback widget command. It requires a selected history record updated within 120 seconds and validates that ID against the desktop-owned local chat catalog before opening. The catalog check requires a local host and a non-removed record. The provider validates again immediately before using `/usr/bin/open` on `codex://threads/<id>`. It never guesses from a title, launches `codex resume` or sends a prompt. A user verified this deep link on their Mac, but it is not claimed as a stable public API. CLI terminal focus is unavailable because no process-to-terminal mapping has been demonstrated.

The local catalog validator uses one read-only SQLite query for an entire page and `PRAGMA query_only`. It currently reads `sqlite/codex-dev.db`. A missing database, changed schema, lock timeout or foreign ID fails closed. The desktop database schema is not a stable public API, so catalog changes may disable navigation while account and history reads continue.

## Observed turns and direct subagents

The `codex-live` provider polls selected history IDs every five seconds. One read-only SQLite query selects the parent records and non-archived direct children, up to 300 combined records. Journal reads are bounded to local session files and accept only regular files whose first record identifies the exact thread. Full working directories, rollout paths, prompts, reasoning and tool arguments are excluded from snapshots.

The reader examines at most 16 MiB on a cold file read and 512 KiB of new data on later reads, with at most four journal files open concurrently. It currently joins journals through `state_5.sqlite`. This versioned, undocumented schema may change in a Codex update; `codex-live` can then go quiet or report unknown observations while account and app-server history still work. It projects lifecycle state, last observed model and effort, branch, a working-directory basename, agent role and direct-child count. A missing start remains unknown. Inactivity for 90 seconds changes an unfinished observation to unknown; silence does not prove continued work. Saved desktop project names and IDs are deferred to a separate change, so the directory basename is only a label.

## Verification

From the cloned repository root:

```bash
pnpm --filter server exec vitest run test/codex-adapter.test.ts test/codex-provider.test.ts test/codex-local-chats.test.ts test/codex-observations.test.ts test/config-migration.test.ts --configLoader runner
pnpm typecheck
pnpm test
```

The tests use injected transports, clocks and disposable local databases. They do not authenticate a real account, prove that Codex startup never refreshes credentials, navigate the desktop app or verify the native dashboard. Those runtime checks remain separate.
3 changes: 2 additions & 1 deletion docs/writing-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ document.documentElement.style.setProperty('--h', Fremkit.size.px.height + 'px')

`system`, `processes`, `volume`, `spotify`, `mutedeck`, `clipboard`, `shortcuts`, `cleanshot`,
`network`, `battery`, `service-status`, `config`, `claude-sessions`, `claude-usage`,
`claude-account`, `dock`, `docker-local`, `local-models`, plus one per connection: `azure-devops:<connectionId>`,
`claude-account`, `codex`, `codex-live`, `dock`, `docker-local`, `local-models`,
plus one per connection: `azure-devops:<connectionId>`,
`bambu:<connectionId>`, `github:<connectionId>`, `synology:<connectionId>`,
and `calendar:<connectionId>` for an ICS connection.

Expand Down
9 changes: 9 additions & 0 deletions server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { ClaudeTracker } from './claude/tracker.js'
import { ClaudeUsage } from './claude/usage.js'
import { claudeRoutes } from './claude/routes.js'
import { createClaudeSessionsProvider, createClaudeUsageProvider, createClaudeAccountProvider } from './claude/providers.js'
import { createCodexProvider } from './providers/codex.js'
import { createLocalChatValidator } from './codex/local-chats.js'
import { createAttention } from './claude/attention.js'
import { DockState } from './dock/state.js'
import { dockRoutes } from './dock/routes.js'
Expand Down Expand Up @@ -153,6 +155,13 @@ export async function buildApp(opts: AppOptions): Promise<FastifyInstance> {
filePath: join(opts.dataDir, 'claude-account.json'),
enabled: () => store.get().privacy.claudeAccountUsage,
}))
const codex = createCodexProvider({
enabled: () => store.get().privacy.codexAccount || store.get().privacy.codexHistorySources.length > 0,
accountEnabled: () => store.get().privacy.codexAccount,
historySources: () => store.get().privacy.codexHistorySources,
}, { isLocalChat: createLocalChatValidator() })
registry.register(codex)
registry.register(codex.sessions)
registry.register(createDockProvider(dock))
// These two act on the user's behalf — opening an application, knocking on a host — so they
// resolve what to act on from the saved dashboard rather than from the widget's message.
Expand Down
Loading
Loading