Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ termly config set defaultAI aider
termly config get defaultAI
```

`defaultAI` is used by `termly start` when no `--ai` flag is given. If the
configured tool is unknown or not installed, Termly warns and falls back to
auto-detection instead of failing.

**Note:** Server URL is determined by environment and cannot be changed via config.

### Cleanup
Expand Down
41 changes: 41 additions & 0 deletions lib/ai-tools/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const inquirer = require('inquirer');
const chalk = require('chalk');
const { detectInstalledTools, isToolInstalled } = require('./detector');
const { getToolByKey } = require('./registry');
const { getDefaultAI } = require('../config/manager');
const logger = require('../utils/logger');

// Select AI tool based on options
Expand All @@ -12,6 +13,12 @@ async function selectAITool(options) {
return await selectManualTool(options.ai);
}

// Configured default (termly setup / termly config set defaultAI <tool>)
const configuredTool = await selectConfiguredDefault();
if (configuredTool) {
return configuredTool;
}

// No auto-detect mode
if (options.noAutoDetect) {
console.error(chalk.red('❌ Please specify AI tool with --ai flag'));
Expand All @@ -27,6 +34,40 @@ async function selectAITool(options) {
return await autoSelectTool();
}

// Configured default tool selection
//
// Unlike --ai, `defaultAI` is a stored preference that may have been set long
// ago, so a stale value must never kill `termly start`: warn and let the caller
// fall back to auto-detection.
async function selectConfiguredDefault() {
const defaultAI = getDefaultAI();

if (!defaultAI) {
return null;
}

logger.debug(`Configured defaultAI: ${defaultAI}`);

const tool = getToolByKey(defaultAI);

if (!tool) {
logger.warn(`Configured default AI "${defaultAI}" is unknown - falling back to auto-detection`);
console.log(chalk.dim(' Change it with: termly config set defaultAI <tool>'));
return null;
}

const result = await isToolInstalled(tool.key);

if (!result.installed) {
logger.warn(`Configured default AI ${tool.displayName} is not installed - falling back to auto-detection`);
console.log(chalk.dim(' Change it with: termly config set defaultAI <tool>'));
return null;
}

console.log(chalk.green(`Using ${result.tool.displayName} v${result.tool.version} (configured default)`));
return result.tool;
}

// Manual tool selection
async function selectManualTool(toolName) {
const tool = getToolByKey(toolName);
Expand Down