UNPKG

claude-code-company

Version:

Multi-agent tmux coordination system for Claude Code with perfect Unicode support

101 lines (89 loc) 2.58 kB
const fs = require('fs'); const path = require('path'); const os = require('os'); // 設定ファイルのパス const CONFIG_DIR = path.join('/tmp', '.claude-code-company'); const SESSION_CONFIG_FILE = path.join(CONFIG_DIR, 'session-config.json'); // 設定ディレクトリの作成 function ensureConfigDir() { if (!fs.existsSync(CONFIG_DIR)) { fs.mkdirSync(CONFIG_DIR, { recursive: true }); } } // セッション設定の保存 function saveSessionConfig(config) { ensureConfigDir(); try { fs.writeFileSync(SESSION_CONFIG_FILE, JSON.stringify(config, null, 2)); return true; } catch (error) { console.error(`Failed to save session config: ${error.message}`); return false; } } // セッション設定の読み込み function loadSessionConfig() { try { if (fs.existsSync(SESSION_CONFIG_FILE)) { const data = fs.readFileSync(SESSION_CONFIG_FILE, 'utf8'); return JSON.parse(data); } } catch (error) { console.error(`Failed to load session config: ${error.message}`); } return null; } // セッション設定のクリア function clearSessionConfig() { try { if (fs.existsSync(SESSION_CONFIG_FILE)) { fs.unlinkSync(SESSION_CONFIG_FILE); return true; } } catch (error) { console.error(`Failed to clear session config: ${error.message}`); } return false; } // 現在のセッション情報を取得 function getCurrentSession() { const config = loadSessionConfig(); if (config && config.sessions && config.sessions.length > 0) { // 最新のセッションを返す return config.sessions[config.sessions.length - 1]; } return null; } // セッション情報を追加 function addSession(sessionInfo) { let config = loadSessionConfig() || { sessions: [] }; // 同じプロジェクトパスのセッションがあれば更新 const existingIndex = config.sessions.findIndex( s => s.projectPath === sessionInfo.projectPath ); if (existingIndex >= 0) { config.sessions[existingIndex] = { ...sessionInfo, updatedAt: new Date().toISOString() }; } else { config.sessions.push({ ...sessionInfo, createdAt: new Date().toISOString() }); } // 古いセッションを削除(最大10個まで保持) if (config.sessions.length > 10) { config.sessions = config.sessions.slice(-10); } return saveSessionConfig(config); } module.exports = { saveSessionConfig, loadSessionConfig, clearSessionConfig, getCurrentSession, addSession, CONFIG_DIR, SESSION_CONFIG_FILE };