# Shared Non-Credential Codex State Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use /ship (recommended) or /executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

Audience: AI coding agents first.

**Goal:** Share every Codex state element across `cdx` profiles except credentials.

**Architecture:** Dynamically migrate and link non-credential top-level paths into `~/.codex`. Route all SQLite-backed state to the same canonical home through `CODEX_SQLITE_HOME`; keep selected account `auth.json` isolated under its account `CODEX_HOME`.

**Tech Stack:** Python 3, pathlib, pytest

---

## Wave Plan

| Wave | Tasks | Files touched | Safe to parallelize? |
|------|-------|---------------|----------------------|
| 1 | Task 1 | `tests/test_account_registry.py`, `tests/test_cdx.py`, `account_registry.py`, `cdx.py` | single task |

Scheduler: `sequential`.

### Task 1: Share All Non-Credential State

**Wave:** 1
**Blocks:** -
**Blocked by:** -

**Files:**
- Modify: `account_registry.py` - dynamic migration and linking
- Modify: `cdx.py` - shared SQLite environment
- Test: `tests/test_account_registry.py`
- Test: `tests/test_cdx.py`

**Contract:**
- `AccountRegistry.sync_all_shared_links() -> None`
- Credential names: `auth.json` and names beginning with `auth.`
- SQLite names: files matching `*.sqlite`, `*.sqlite-wal`, or `*.sqlite-shm`; runtime shared by `CODEX_SQLITE_HOME` instead of file migration.
- Every other top-level path resolves to its counterpart under `legacy_codex_home` after synchronization.
- `history.jsonl` and `session_index.jsonl` merge without duplicate lines.
- Differing `.log` files append; generated `.tmp`, `tmp`, and `cache` conflicts prefer canonical state.
- Unknown different-content conflicts raise without overwriting either file.
- `cdx.main(argv)` sets selected `CODEX_HOME` and canonical `CODEX_SQLITE_HOME`.

**Acceptance:**
- Run: `pytest tests/test_cdx.py tests/test_account_registry.py -q`
- Expected: PASS for dynamic sharing, credential isolation, SQLite routing, JSONL merge, idempotency, and conflict protection.

- [ ] Write failing broad-state and SQLite-routing tests.
- [ ] Run them and confirm expected failures.
- [ ] Replace sharing whitelist with dynamic non-credential discovery.
- [ ] Add chronological JSONL migration.
- [ ] Route SQLite state to canonical home.
- [ ] Run focused and full test suites.
- [ ] Commit only changed implementation, test, spec, and plan files.
