mycoder
Version:
A command line tool using agent that can do arbitrary tasks, including coding tasks
108 lines • 3.28 kB
JavaScript
import { loadConfig as loadC12Config, watchConfig } from 'c12';
// Default configuration
const defaultConfig = {
logLevel: 'log',
// GitHub integration
githubMode: true,
// Browser settings
headless: true,
userSession: false,
pageFilter: 'none',
// Model settings
provider: 'anthropic',
maxTokens: 4096,
temperature: 0.7,
// Custom settings
customPrompt: '',
profile: false,
tokenCache: true,
userPrompt: true,
upgradeCheck: true,
tokenUsage: false,
interactive: false,
// MCP configuration
mcp: {
servers: [],
defaultResources: [],
},
};
export const getConfigFromArgv = (argv) => {
return {
logLevel: argv.logLevel,
tokenCache: argv.tokenCache,
provider: argv.provider,
model: argv.model,
maxTokens: argv.maxTokens,
temperature: argv.temperature,
profile: argv.profile,
githubMode: argv.githubMode,
userSession: argv.userSession,
pageFilter: argv.pageFilter,
headless: argv.headless,
ollamaBaseUrl: argv.ollamaBaseUrl,
userPrompt: argv.userPrompt,
upgradeCheck: argv.upgradeCheck,
tokenUsage: argv.tokenUsage,
interactive: argv.interactive,
};
};
/**
* Validates custom commands configuration
* @param config The configuration object
* @throws Error if any command configuration is invalid
*/
function validateCustomCommands(config) {
if (!config.commands)
return;
Object.entries(config.commands).forEach(([name, command]) => {
// Validate name (should be valid command name)
if (!/^[a-z][\w-]*$/.test(name)) {
throw new Error(`Invalid command name: ${name}. Command names should start with a letter and contain only letters, numbers, hyphens, and underscores.`);
}
// Validate execute property
if (typeof command.execute !== 'function') {
throw new Error(`Invalid execute property for command ${name}. Should be a function.`);
}
});
}
/**
* Load configuration using c12
* @returns Merged configuration with default values
*/
export async function loadConfig(cliOptions = {}) {
const { config } = await loadC12Config({
name: 'mycoder',
defaults: defaultConfig,
overrides: cliOptions,
globalRc: true,
});
// Convert to Config type and validate custom commands
const typedConfig = config;
validateCustomCommands(typedConfig);
return typedConfig;
}
/**
* Watch configuration for changes
* @param cliOptions CLI options to override configuration
* @param onUpdate Callback when configuration is updated
*/
export async function watchConfigForChanges(cliOptions = {}, onUpdate) {
const { config, watchingFiles, unwatch } = await watchConfig({
name: 'mycoder',
defaults: defaultConfig,
overrides: cliOptions,
onUpdate: ({ newConfig }) => {
const typedConfig = newConfig;
validateCustomCommands(typedConfig);
if (onUpdate) {
onUpdate(typedConfig);
}
},
});
return {
config: config,
watchingFiles,
unwatch,
};
}
//# sourceMappingURL=config.js.map