From c213274723ec622ca1dcdc1cedbd66513e709322 Mon Sep 17 00:00:00 2001 From: Arjun <6592213+arkml@users.noreply.github.com> Date: Thu, 28 May 2026 22:33:32 +0530 Subject: [PATCH] enable coding agents if they are available by default --- apps/x/packages/core/src/code-mode/repo.ts | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/apps/x/packages/core/src/code-mode/repo.ts b/apps/x/packages/core/src/code-mode/repo.ts index dd318b34..78092db8 100644 --- a/apps/x/packages/core/src/code-mode/repo.ts +++ b/apps/x/packages/core/src/code-mode/repo.ts @@ -2,6 +2,7 @@ import fs from 'fs/promises'; import path from 'path'; import { WorkDir } from '../config/config.js'; import { CodeModeConfig } from './types.js'; +import { checkCodeModeAgentStatus } from './status.js'; export interface ICodeModeConfigRepo { getConfig(): Promise; @@ -10,27 +11,31 @@ export interface ICodeModeConfigRepo { export class FSCodeModeConfigRepo implements ICodeModeConfigRepo { private readonly configPath = path.join(WorkDir, 'config', 'code-mode.json'); - private readonly defaultConfig: CodeModeConfig = { enabled: false }; + private agentReadyPromise: Promise | null = null; - constructor() { - this.ensureConfigFile(); - } - - private async ensureConfigFile(): Promise { - try { - await fs.access(this.configPath); - } catch { - await fs.mkdir(path.dirname(this.configPath), { recursive: true }); - await fs.writeFile(this.configPath, JSON.stringify(this.defaultConfig, null, 2)); + // Reuse the existing agent check (Claude Code / Codex installed + signed in), + // cached for the process lifetime so we probe (shell + keychain) at most once + // per session rather than on every getConfig call. + private agentReady(): Promise { + if (!this.agentReadyPromise) { + this.agentReadyPromise = checkCodeModeAgentStatus() + .then((s) => + (s.claude.installed && s.claude.signedIn) + || (s.codex.installed && s.codex.signedIn)) + .catch(() => false); } + return this.agentReadyPromise; } async getConfig(): Promise { try { + // The file only exists once the user has explicitly toggled code mode + // in settings — always honor that choice. const content = await fs.readFile(this.configPath, 'utf8'); return CodeModeConfig.parse(JSON.parse(content)); } catch { - return this.defaultConfig; + // No explicit choice yet: enable automatically when a coding agent is ready. + return { enabled: await this.agentReady() }; } }