hataraku
Version:
An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.
150 lines • 5.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigLoader = void 0;
const agent_manager_1 = require("./agent-manager");
const ProfileManager_1 = require("./ProfileManager");
const TaskManager_1 = require("./TaskManager");
const ToolManager_1 = require("./ToolManager");
/**
* Configuration Loader class
* Handles loading all configuration types and resolving effective configuration based on overrides
*/
class ConfigLoader {
profileManager;
toolManager;
agentManager;
taskManager;
constructor() {
this.profileManager = new ProfileManager_1.ProfileManager();
this.toolManager = new ToolManager_1.ToolManager();
this.agentManager = new agent_manager_1.AgentManager();
this.taskManager = new TaskManager_1.TaskManager();
}
/**
* Load all configurations
* @returns Object containing all configurations
*/
async loadConfig() {
const [profiles, activeProfile, tools, agents, tasks] = await Promise.all([
this.profileManager.listProfiles(),
this.profileManager.getActiveProfile().then(profile => profile.name),
this.toolManager.listTools(),
this.agentManager.listAgents(),
this.taskManager.listTasks()
]);
return {
profiles,
activeProfile,
tools,
agents,
tasks
};
}
/**
* Get effective configuration based on CLI options
* @param cliOptions CLI options for overrides
* @returns Effective configuration for execution
*/
async getEffectiveConfig(cliOptions) {
// 1. Get active profile (or specified profile)
const profileName = cliOptions.profile || (await this.profileManager.getActiveProfile()).name;
const profile = await this.profileManager.getProfile(profileName);
// 2. Apply CLI overrides to profile
const effectiveProfile = {
...profile,
provider: cliOptions.provider || profile.provider,
model: cliOptions.model || profile.model,
tools: cliOptions.tools || profile.tools,
options: {
...profile.options,
stream: cliOptions.stream !== undefined ? cliOptions.stream : profile.options?.stream,
sound: cliOptions.sound !== undefined ? cliOptions.sound : profile.options?.sound,
verbose: cliOptions.verbose !== undefined ? cliOptions.verbose : profile.options?.verbose
}
};
// 3. Resolve agent if specified
let agent;
const agentName = cliOptions.agent || profile.agent;
if (agentName) {
try {
agent = await this.agentManager.getAgent(agentName);
}
catch (error) {
// Agent not found, will use default model configuration
}
}
// 4. Resolve tools
let tools = [];
if (effectiveProfile.tools && effectiveProfile.tools.length > 0) {
tools = effectiveProfile.tools;
}
// 5. Return effective configuration
return {
profile: effectiveProfile,
agent,
tools
};
}
/**
* Get environment variables from a tool configuration
* @param tools Tool configuration names
* @returns Environment variables
*/
async resolveEnvironmentVariables(tools) {
const env = {};
for (const toolName of tools) {
try {
const toolConfig = await this.toolManager.getTool(toolName);
for (const server of toolConfig.mcpServers) {
if (server.env) {
for (const [key, value] of Object.entries(server.env)) {
// Handle environment variable interpolation (${VAR_NAME})
const interpolatedValue = this.interpolateEnvVar(value);
if (interpolatedValue !== undefined) {
env[key] = interpolatedValue;
}
}
}
}
}
catch (error) {
// Skip if tool doesn't exist
}
}
return env;
}
/**
* Interpolate environment variables in a string
* @param value String with potential environment variable references
* @returns Interpolated string or undefined if interpolation fails
*/
interpolateEnvVar(value) {
// If the value is a direct environment variable reference (${VAR_NAME})
if (value.startsWith('${') && value.endsWith('}')) {
const envName = value.substring(2, value.length - 1);
return process.env[envName];
}
// Return the value as-is if it doesn't need interpolation
return value;
}
/**
* Get a task configuration by name
* @param name Task name
* @returns Task configuration
*/
async getTask(name) {
return this.taskManager.getTask(name);
}
/**
* Initialize all configuration managers with default configurations
*/
async initializeDefaults() {
await Promise.all([
this.toolManager.initializeDefaults(),
this.agentManager.initializeDefaults(),
this.taskManager.initializeDefaults()
]);
}
}
exports.ConfigLoader = ConfigLoader;
//# sourceMappingURL=config-loader.js.map