Principle:3641397194 wq Gpt6 Astra Seat Detection
| Knowledge Sources | |
|---|---|
| Domains | Desktop_App, Configuration_Management, Security |
| Last Updated | 2026-10-26 12:00 GMT |
Overview
A configuration resolution strategy that discovers AI model client config directories across platforms while guarding against path traversal via symlinks, junctions, and hardlinks.
Description
Seat Detection is the process of locating the on-disk configuration directory for a specific AI model client ("seat") — such as Codex, Claude, Grok, or Cursor — on Windows, macOS, and Linux. Each seat stores its configuration in a different location: some use environment variable overrides, some use platform data directories, and some require specialized home-directory resolvers.
The core problem this solves is safe path resolution. Config directories may legitimately not exist yet, but the resolution path must never cross a symlink, directory junction, or hardlink — those could redirect writes outside the user's intended directory. The detection layer validates every candidate path with a guard that walks the entire ancestor chain checking `lstat` for links before returning.
A secondary concern is override resolution: users can redirect a seat's config directory via environment variables (e.g., `CODEX_HOME`, `CLAUDE_CONFIG_DIR`). The detection layer checks environment variables first, then falls back to platform-specific default locations, always preferring an existing directory when multiple candidates are found.
Usage
Use this principle when you need to programmatically locate where an AI model client stores its configuration files before writing to or reading from that directory. It is the mandatory first step of any seat pack installation or verification flow, ensuring all subsequent file operations target a validated, link-free absolute path.
Theoretical Basis
The detection algorithm follows a prioritized candidate resolution:
- Environment override: check seat-specific env vars (e.g., `CODEX_HOME`, `CLAUDE_CONFIG_DIR`) — if set, use that path.
- Specialized resolver: for seats with non-trivial resolution (Cursor, Kimi, MiniMax, DeepSeek), delegate to a per-seat home resolver that applies seat-specific safety rules.
- Platform default: fall back to `~/.<seat-dir>` (e.g., `~/.codex`, `~/.claude`) or a platform data home directory.
- Existence preference: when multiple candidates exist, prefer the one that already exists on disk.
Every candidate path is validated by a path guard that:
- Resolves the path to an absolute path
- Walks every ancestor from the file to the filesystem root
- Checks `lstat` on each ancestor — if any is a symlink or junction, rejects the path
- Checks `nlink > 1` on files — if any is a hardlink, rejects the path
- Compares `realpathSync.native` against the literal path to detect canonical spelling changes
Pseudo-code Logic:
# Abstract algorithm (NOT real implementation)
def detect_directory(seat, env, home, platform):
candidates = []
# 1. Check environment overrides
for key in seat.env_keys:
if env.get(key):
candidates.append(validate(env[key], source=key))
# 2. Fall back to platform default
candidates.append(validate(path.join(home, seat.default_dir)))
# 3. Prefer existing candidate
return first_existing_or_first(candidates)
def validate(path, source):
path = resolve_absolute(path)
for ancestor in walk_to_root(path):
stat = lstat(ancestor)
if stat.is_symlink: raise PathGuardError
if stat.is_file and stat.nlink > 1: raise HardlinkError
return path
Practical Guide
- Always pass the full `{env, home, platform}` context for testability — the function accepts injectable overrides.
- The returned `{root, source, layout, exists}` tells you where the config lives and whether it already exists.
- The `layout` field matters: `deepseek-harness` and `zcode` use non-standard directory structures.
- Per-seat resolvers (cursor-home, kimi-home, mimo-home, deepseek-home) enforce additional seat-specific safety rules beyond the generic path guard.