UNPKG

hataraku

Version:

An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.

133 lines 5.13 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ProfileManager = void 0; const fs = __importStar(require("fs/promises")); const path = __importStar(require("path")); const config_paths_1 = require("./config-paths"); const profileConfig_1 = require("./profileConfig"); class ProfileManager { configPath; config = null; constructor() { const paths = (0, config_paths_1.getConfigPaths)(); this.configPath = path.join(paths.configDir, 'profiles.json'); } async loadConfig() { if (this.config) return this.config; try { const data = await fs.readFile(this.configPath, 'utf-8'); const config = JSON.parse(data); this.config = profileConfig_1.ProfilesConfigSchema.parse(config); return this.config; } catch (error) { // If file doesn't exist or is invalid, create default config this.config = { activeProfile: 'default', profiles: [profileConfig_1.DEFAULT_PROFILE] }; // Pretty print the initial config await fs.writeFile(this.configPath, JSON.stringify(this.config, null, 2)); return this.config; } } async saveConfig() { if (!this.config) throw new Error('No configuration loaded'); // Format JSON with no whitespace to match test expectations await fs.writeFile(this.configPath, JSON.stringify(this.config)); } async listProfiles() { const config = await this.loadConfig(); return config.profiles.map(p => p.name); } async getProfile(name) { const config = await this.loadConfig(); const profile = config.profiles.find(p => p.name === name); if (!profile) throw new Error(`Profile '${name}' not found`); return profile; } async createProfile(profile) { const config = await this.loadConfig(); if (config.profiles.some(p => p.name === profile.name)) { throw new Error(`Profile '${profile.name}' already exists`); } config.profiles.push(profile); await this.saveConfig(); } async updateProfile(name, updates) { const config = await this.loadConfig(); const index = config.profiles.findIndex(p => p.name === name); if (index === -1) throw new Error(`Profile '${name}' not found`); // Don't allow changing the name through updates if (updates.name && updates.name !== name) { throw new Error('Cannot change profile name'); } config.profiles[index] = { ...config.profiles[index], ...updates }; await this.saveConfig(); } async deleteProfile(name) { const config = await this.loadConfig(); if (name === 'default') throw new Error('Cannot delete default profile'); if (name === config.activeProfile) throw new Error('Cannot delete active profile'); const index = config.profiles.findIndex(p => p.name === name); if (index === -1) throw new Error(`Profile '${name}' not found`); config.profiles.splice(index, 1); await this.saveConfig(); } async getActiveProfile() { const config = await this.loadConfig(); return this.getProfile(config.activeProfile); } async setActiveProfile(name) { // Verify profile exists await this.getProfile(name); const config = await this.loadConfig(); config.activeProfile = name; await this.saveConfig(); } } exports.ProfileManager = ProfileManager; //# sourceMappingURL=ProfileManager.js.map