mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-06-03 19:25:19 +02:00
enable coding agents if they are available by default
This commit is contained in:
parent
e7c7d0e90f
commit
c213274723
1 changed files with 17 additions and 12 deletions
|
|
@ -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<CodeModeConfig>;
|
||||
|
|
@ -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<boolean> | null = null;
|
||||
|
||||
constructor() {
|
||||
this.ensureConfigFile();
|
||||
}
|
||||
|
||||
private async ensureConfigFile(): Promise<void> {
|
||||
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<boolean> {
|
||||
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<CodeModeConfig> {
|
||||
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() };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue