Skip to content
Source
Sign inSign up
pingdotgg/t3code

Use xdg directories: Separate configuration, data, state, cache, and runtime storage #4437

Closedcolonelpanic8(GitHub profile, opens in a new tab)wants to merge 8 commits intomain fromrefs/pull/4437/headopened View on GitHub

What Changed

  • Introduce a shared five-root storage model for configuration, durable data, machine state, disposable caches, and runtime files.
  • Use platform-native defaults: XDG roots on Linux, Application Support and Library/Caches on macOS, and roaming/local application data on Windows.
  • Keep initialized ~/.t3 installations on the exact legacy layout. Selection checks real artifacts, so an empty or partially-created XDG directory cannot hide existing data.
  • Add independent T3CODE_CONFIG_DIR, T3CODE_DATA_DIR, T3CODE_STATE_DIR, T3CODE_CACHE_DIR, and T3CODE_RUNTIME_DIR overrides. T3CODE_HOME and --base-dir remain explicit legacy compatibility controls and conflict with granular overrides.
  • Add --storage-layout xdg|legacy to server and storage-aware subcommands so users can override automatic selection while incompatible explicit path controls still fail clearly.
  • Place settings and keybindings in config; worktrees and attachments in data; SQLite, identities, secrets, and logs in state; provider and desktop browser caches in cache; and live server discovery state in runtime.
  • Propagate the exact resolved roots through desktop bootstrap, WSL isolation, background services, and self-update.
  • Add Settings → Diagnostics → Storage Locations with the effective layout, all resolved paths, and copy controls.
  • Document the storage model and override behavior.

Why

The legacy tree mixes portable plaintext configuration, durable binary data, machine-local state, caches, and runtime files. That makes dotfile management difficult and made the earlier partial XDG implementation unsafe: an empty XDG startup could appear to replace a real legacy installation.

This change establishes the core storage contract first. It deliberately performs no migration: startup never copies, moves, deletes, or automatically switches existing data. A manual copy-based migration workflow can be designed separately once this contract is stable.

This supersedes #4419.

UI Changes

Settings diagnostics now shows whether the connected server is using the split or legacy layout and lists configuration, data, state, cache, runtime, database, settings, keybindings, worktree, and attachment paths.

The flow was verified against a disposable /tmp/t3code-test.* environment. The page correctly identified the explicit legacy layout, stated that no data was moved or copied, and copied a selected path.

Checklist

  • vp fmt --check for all 29 changed files
  • vp lint --deny-warnings for all changed TypeScript and TSX files
  • Typechecks for @t3tools/shared, @t3tools/contracts, t3, and @t3tools/desktop
  • 197 focused tests across shared path resolution, server configuration/services, desktop resolution/bootstrap, and server integration
  • Follow-up server typecheck, targeted lint/format checks, bundle build, and built CLI help verification for --storage-layout
  • Isolated web verification with test-t3-app
  • git diff --check

The full web typecheck still reports unrelated errors already present on the base revision in BranchToolbarBranchSelector, ModelPickerContent, PreviewAutomationHosts, and atom query helpers. The changed diagnostics UI passes lint and the integrated browser verification.


Note

High Risk Wrong layout selection or path mapping can point servers at empty split dirs or split primary/WSL storage; bootstrap-pinned roots and legacy artifact detection are critical to avoid data loss or duplicate env identity.

Overview Introduces a split vs legacy storage contract in @t3tools/shared/storagePaths, used by the server CLI, desktop app, bootstrap, and boot service. New installs default to platform-native five-root layouts (XDG on Linux, Application Support/Caches on macOS, roaming/local on Windows); existing ~/.t3 installs stay on the unified tree when real legacy artifacts are detected—no automatic migration.

Server: resolveServerConfig picks roots from env, --base-dir, --storage-layout xdg|legacy, and desktop bootstrap storageRoots; maps settings/keybindings to config, DB/secrets/logs to state, attachments/worktrees to data, caches separately, runtime files with symlink/owner checks on Linux split layouts. Desktop: DesktopEnvironment mirrors the same selection; split layout sets Electron userData/cache under state/cache; WSL backend strips Windows storage env vars so Linux does not share a DB via /mnt/c. UI/docs: Diagnostics shows effective storage paths; contracts expose storage on server config and bootstrap payload.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 8d7270e82ccb610903290cafbfd0ccd177af5a0b. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Separate configuration, data, state, cache, and runtime storage into XDG-compliant directories

  • Introduces split (XDG/platform-native) vs legacy (unified T3CODE_HOME) storage layouts across server, desktop, and shared packages, with automatic selection based on whether legacy artifacts exist on disk.
  • Adds --storage-layout xdg|legacy CLI flag and T3CODE_CONFIG_DIR, T3CODE_DATA_DIR, T3CODE_STATE_DIR, T3CODE_CACHE_DIR, T3CODE_RUNTIME_DIR environment variables to override individual directories.
  • Adds storagePaths.ts in @t3tools/shared with platform-aware helpers for resolving, overriding, and selecting storage roots across Windows/macOS/Linux.
  • On non-Windows with split layout, the runtime directory is created with mode 0700, validated for ownership and symlink safety, and rejected if checks fail.
  • The generated systemd unit now sets Environment= lines for the active layout and uses UnsetEnvironment= to clear variables from the opposite layout.
  • A new Storage Locations section in Settings → Diagnostics displays the active layout and all resolved paths with copy-to-clipboard support.
  • Risk: Existing installations that lack legacy artifacts on disk will automatically migrate to split layout on next startup, changing the locations of settings.json, keybindings.json, attachments, and the provider status cache.
Macroscope summarized 8d7270e.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: fed5be41-0b94-441c-8ef2-accbcb1b5945

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR introduces a significant new feature: XDG-compliant storage directory separation. It adds new CLI flags (--storage-layout), environment variables for granular directory control, new contracts/schemas, and changes how storage paths are resolved for new installations. The cross-cutting nature and new capability warrant human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Effect Service Conventions: one finding on error modeling in apps/server/src/cli/config.ts.

      Posted via Macroscope — Effect Service Conventions
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High

      https://github.com/pingdotgg/t3code/blob/c99d68fa599ebdf65937986e3a760d0aecf93657/apps/desktop/src/backend/DesktopBackendConfiguration.ts#L512

      WINDOWS_STORAGE_ENV_NAMES.has(key) performs a case-sensitive membership check, but Windows environment-variable names are case-insensitive. If the desktop is launched with a differently-cased override such as t3code_home, Windows still resolves it as T3CODE_HOME, but the filter loop at lines 513–515 doesn't strip the lowercase key. The WSL backend then inherits the Windows storage path via /mnt/c, causing both backends to share the same database and environment identity — the exact collision this filter exists to prevent. Consider normalizing key (and the WSLENV entry names parsed in mergeWslEnv) to a consistent case before the membership checks.

      No longer relevant as of 66f6046d22826e565d39fb8eb33d4da68b20276f

    6. Effect service review: one error-modeling convention issue found in apps/server/src/cli/config.ts. See the inline comment.

      Posted via Macroscope — Effect Service Conventions
    7. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ee717d877a5b9e10506a0817ed9b019306efaac2. Configure [here](https://www.cursor.com/dashboard/bugbot).
    8. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium cloud/bootService.ts:112

      When storageRoots is set, the unit emits the granular T3CODE_*_DIR variables but never clears an inherited T3CODE_HOME, so both are present at runtime — a combination the server rejects with StorageDirectoryConfigurationConflictError, causing the service to crash-loop on every restart. The reverse happens when storageRoots is unset: the unit sets T3CODE_HOME but never clears inherited granular variables. Add UnsetEnvironment= entries for whichever storage variables this plan does not emit.

      ✅ Resolved in b067ac4ff068d1cabd87655603f8da7c316eb5fc

    9. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      Closing this PR after an automated pass over open pull requests. Adds an unsolicited product feature or cross-system architecture change that exceeds the contribution policy.

Sign in to join this conversation.