UNPKG

ai-expert

Version:

AI Expert CLI - Advanced management system for specialized Claude assistants

44 lines 1.36 kB
import { promises as fs } from 'fs'; import { tmpdir } from 'os'; import { join } from 'path'; import { spawn } from 'child_process'; import { v4 as uuidv4 } from 'uuid'; export async function edit(data) { const tmpFile = join(tmpdir(), `ai-expert-edit-${uuidv4()}.json`); try { // Write data to temp file await fs.writeFile(tmpFile, JSON.stringify(data, null, 2)); // Get editor const editor = process.env.EDITOR || 'nano'; // Open editor await new Promise((resolve, reject) => { const child = spawn(editor, [tmpFile], { stdio: 'inherit' }); child.on('exit', (code) => { if (code === 0) { resolve(); } else { reject(new Error(`Editor exited with code ${code}`)); } }); child.on('error', reject); }); // Read the edited content const content = await fs.readFile(tmpFile, 'utf-8'); const edited = JSON.parse(content); // Clean up await fs.unlink(tmpFile); return edited; } catch (error) { // Clean up on error try { await fs.unlink(tmpFile); } catch { } return null; } } //# sourceMappingURL=editor.js.map