Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:3641397194 wq Gpt6 Astra detectDirectory

From Leeroopedia
Knowledge Sources
Domains Desktop_App, Configuration_Management, Security
Last Updated 2026-10-26 12:00 GMT

Overview

Concrete tool for resolving AI model client config directories across platforms with symlink and hardlink guards, provided by the ColdBrew Zero desktop library.

Description

The detectDirectory function resolves the on-disk configuration directory for a given AI model client ("seat"). It checks environment variable overrides first, then falls back to platform-specific default locations, validating every candidate path against symlinks, junctions, and hardlinks via `guardPath` before returning.

Each of the 11 supported seats (codex, claude, grok, deepseek, glm53, gemini, doubao, workbuddy, cursor, mimo, kimi) has a different resolution strategy. Seats with non-trivial resolution (cursor, mimo, kimi, workbuddy, doubao, deepseek) delegate to specialized resolvers that apply additional seat-specific safety rules.

Usage

  • One-click install: called by `scanAll` to detect all seat config directories before offering install buttons.
  • Install/verify/uninstall: called by `selectOne` to resolve the target directory for a specific seat.
  • Testing: the `{env, home, platform}` parameters are injectable, allowing deterministic tests without modifying the real environment.

Code Reference

Source Location

  • Repository: ColdBrew Zero
  • File: desktop/src/lib/detect-directory.js

Signature

function detectDirectory(
  seat,
  { env = process.env, home = os.homedir(), platform = process.platform } = {}
) -> { root: string, source: string, layout: string, exists: boolean }

function platformDataHome(
  { env = process.env, home = os.homedir(), platform = process.platform } = {}
) -> string

Import

const { detectDirectory, platformDataHome } = require('./detect-directory');

I/O Contract

Inputs

Name Type Required Description
seat string Yes One of: codex, claude, grok, deepseek, glm53, gemini, doubao, workbuddy, cursor, mimo, kimi
env object No Process.env override (default: process.env)
home string No OS homedir override (default: os.homedir())
platform string No Process.platform override (default: process.platform)

Outputs

Name Type Description
root string Absolute resolved config directory path
source string Origin description (e.g., "CURSOR_HOME", "Cursor 用户目录")
layout string Directory layout: 'default', 'deepseek-harness', or 'zcode'
exists boolean Whether the directory exists on disk

Usage Examples

Detect All Seats

const { detectDirectory } = require('./detect-directory');
const { PACK_IDS } = require('./seat-runtime');

// Detect config directories for all 11 seats
for (const seat of PACK_IDS) {
  try {
    const found = detectDirectory(seat);
    console.log(`${seat}: ${found.root} (exists: ${found.exists}, layout: ${found.layout})`);
  } catch (error) {
    console.log(`${seat}: ${error.message}`);
  }
}

Test with Injected Environment

const { detectDirectory } = require('./detect-directory');

// Override env and platform for testing
const found = detectDirectory('codex', {
  env: { CODEX_HOME: '/tmp/test-codex' },
  home: '/tmp/fake-home',
  platform: 'linux'
});
// found.root === '/tmp/test-codex'
// found.source === 'CODEX_HOME'

Resolve DeepSeek with Harness Layout

const { detectDirectory } = require('./detect-directory');

const found = detectDirectory('deepseek', {
  env: { DSH_HOME: '/home/user/.dsh' }
});
// found.layout === 'deepseek-harness'
// found.root === resolved path from deepseekHarnessHome

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment