Skip to content

feat: multi-environment Codex provider targets (Windows + WSL)#5668

Open
M1kasali wants to merge 15 commits into
farion1231:mainfrom
M1kasali:feat/multi-environment-provider-targets
Open

feat: multi-environment Codex provider targets (Windows + WSL)#5668
M1kasali wants to merge 15 commits into
farion1231:mainfrom
M1kasali:feat/multi-environment-provider-targets

Conversation

@M1kasali

Copy link
Copy Markdown

Summary

Enable Windows CC Switch to manage Windows Codex and WSL2 Codex as separate Managed Targets without copying full config trees or merging cross-platform paths.

  • Managed Targets: discover/register WSL distros, isolate current Provider per environment, field-level projection only.
  • Stable custom route: managed third-party (and unified official) Providers share Codex’s stable session bucket so native history stays visible when switching channels.
  • Explicit history migrate/restore: per-Target ledger + backup; never auto-merge Windows ↔ WSL histories.
  • Session Manager Target-aware (M1): Codex sessions list/read/delete scoped to the selected Managed Target (Windows path, host-visible WSL path / UNC, or WSL argv reads with wsl: sources).
  • UI: environment selector shows Provider names; settings history controls are collapsed advanced actions; switch/history buttons respect pending state.

Non-goals (follow-ups)

  • Session provenance ledger (original channel after unify)
  • Multi-target linked switch / tray layered by environment
  • Target-aware proxy takeover
  • Claude / Gemini multi-environment parity
  • SSH / Dev Container / multi-user WSL beyond default user
  • Independent auto-update channel / forked installer identity (trial builds should avoid being overwritten by upstream auto-update until that is decided)

Safety notes

  • Register/discover is read-only; first write requires explicit “enable management”.
  • Normal Provider switch does not rewrite auth.json, sessions, or move history.
  • History rewrite is user-initiated only, with backups; partial failure is marked on the ledger and restore remains available.
  • Do not run migrate/restore against production history in CI; tests use temp dirs only.

Test plan

  • pnpm typecheck
  • Targeted Vitest (EnvironmentTargetsPanel, switch mutation)
  • cargo test --test target_history_migration --test managed_target_sessions
  • cargo clippy --all-targets -- -D warnings / cargo fmt --check
  • Manual (Windows host): discover Ubuntu WSL → enable management → switch Provider independently on Windows vs WSL
  • Manual: Session Manager selects each Target and lists only that environment’s sessions
  • Manual: history migrate/restore only on Managed Targets after confirming Codex processes are closed
  • Confirm auth.json / Local Fields unchanged across switches

Architecture references

  • docs/adr/0001-model-provider-management-as-environment-targets.md
  • docs/adr/0002-preserve-upstream-codex-unified-history-per-target.md
  • docs/handoff/windows-wsl-provider-customization-status-2026-07-23.md

M1kasali added 15 commits July 22, 2026 11:18
pnpm 11 requires explicit allowBuilds booleans. Approve esbuild postinstall
(needed by Vite/Vitest) and keep msw ignored, matching onlyBuiltDependencies.
Add ADR-0002 and research notes for stable custom session buckets, align the
design doc and CONTEXT with implemented history rewrite rules, and capture the
Windows/WSL RC handoff snapshot for the multi-environment slice.
Improve WSL path/hash handling for provider projection writes and keep
CREATE_NO_WINDOW coverage in inspection tests so UI actions do not flash
console windows on Windows hosts.
Stop generating per-provider cc_switch_* runtime keys. Managed third-party
providers and official unify injection share the stable custom model_provider
bucket so Codex native history stays visible across channel switches.
Introduce per-Target explicit migration into the custom session bucket with
backup ledgers for Windows and WSL, share the process-wide history op lock
with official unify, surface partial-failure status, and expose Tauri commands
for settings-driven migrate/restore.
Add settings APIs and Environment Targets history migrate/restore UX with
managed-only gating, distinct skip toasts, and confirm-disabled while pending.
Also disable Provider enable buttons during an in-flight switch to avoid
duplicate WSL writes.
Scope Session Manager to the selected Managed Target for Codex. Windows
targets use the host Codex home; WSL targets prefer a host-visible path
(or UNC on Windows) and fall back to argv-safe WSL reads with wsl: sources
for message load and delete. Query keys include targetId so UI state stays
isolated per environment.
Enrich the environment selector with current Provider display names, resolve
Provider IDs to names in the settings target cards, and collapse history
migrate/restore behind an advanced section to reduce accidental clicks.
@M1kasali
M1kasali requested a review from farion1231 as a code owner July 23, 2026 03:47
@github-actions github-actions Bot added documentation Improvements or additions to documentation dependencies Dependency updates frontend Frontend (React/TypeScript) backend Backend (Rust/Tauri) labels Jul 23, 2026
@allenxu09

Copy link
Copy Markdown
Collaborator

please remove the unnecessary documentation files

@farion1231

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ba6f0f45a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

created_at,
last_active_at,
source_path: Some(source_path_display.to_string()),
resume_command: Some(format!("codex resume {session_id}")),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Route WSL resume commands through their owning target

For metadata parsed from a WSL-backed session, this still exposes the generic codex resume <id> command. SessionManagerPage merely copies or launches that string and does not use targetId or the encoded WSL source, so running it from the Windows host targets the Windows Codex installation, where the WSL session is unavailable or an unrelated session with the same ID could be selected. Generate a target-aware command such as a wsl.exe -d ... -u ... invocation, or route resume through a backend command that resolves the recorded target.

Useful? React with 👍 / 👎.

Comment on lines +262 to +266
for linux_path in paths {
let Some(bytes) = self.read_file_bytes(distro, user, &linux_path)? else {
continue;
};
let Ok(text) = String::from_utf8(bytes) else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid loading every complete WSL history file during scans

When a WSL target is not host-mounted, every session-list refresh starts a separate wsl.exe process and reads each entire JSONL transcript into a Vec and then a String, although the parser only uses the first 10 and last 30 lines. Codex transcripts grow with the full conversation, so targets with many or large sessions incur memory proportional to all history and can leave the session page loading for a long time. Fetch bounded head/tail data inside WSL or stream only the metadata needed for the listing.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri) dependencies Dependency updates documentation Improvements or additions to documentation frontend Frontend (React/TypeScript)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants