save_data
Save your current lines, loops, vibes, and contexts to persistent storage with an optional custom filename.
Instructions
Save current lines, loops, vibes, and contexts to persistent storage
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | No | Optional custom filename (without extension) |
Implementation Reference
- index.js:1074-1121 (handler)Main handler for save_data tool - serializes lines, loops, vibes, and contexts to a JSON file in the data directory
async saveData(args) { if (!this.persistenceEnabled) { return { content: [ { type: 'text', text: `❌ Data persistence is disabled. Set LLV_PERSISTENCE=true to enable.`, }, ], }; } try { await this.ensureDataDir(); const filename = args.filename || 'llv-session'; const filepath = join(this.dataDir, `${filename}.json`); const data = { timestamp: new Date().toISOString(), lines: this.mapToObj(this.lines), loops: this.mapToObj(this.loops), vibes: this.mapToObj(this.vibes), contexts: this.mapToObj(this.contexts), version: '1.0.0', }; await fs.writeFile(filepath, JSON.stringify(data, null, 2)); return { content: [ { type: 'text', text: `💾 Data saved successfully!\n\nFile: ${filepath}\nLines: ${this.lines.size}\nLoops: ${this.loops.size}\nVibes: ${this.vibes.size}\nContexts: ${this.contexts.size}\n\nTimestamp: ${data.timestamp}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `❌ Failed to save data: ${error.message}`, }, ], }; } } - index.js:293-305 (schema)Schema definition for save_data tool with optional filename parameter
{ name: 'save_data', description: 'Save current lines, loops, vibes, and contexts to persistent storage', inputSchema: { type: 'object', properties: { filename: { type: 'string', description: 'Optional custom filename (without extension)', }, }, }, }, - index.js:351-358 (registration)Registration of save_data in CallToolRequestSchema switch-case handler
case 'save_data': return this.saveData(args); case 'load_data': return this.loadDataTool(args); default: throw new Error(`Unknown tool: ${name}`); } }); - index.js:1058-1064 (helper)Helper method that creates the data directory if it doesn't exist
async ensureDataDir() { try { await fs.mkdir(this.dataDir, { recursive: true }); } catch (error) { console.error('Failed to create data directory:', error); } } - index.js:1066-1072 (helper)Helper method converting Map to plain object for JSON serialization
mapToObj(map) { return Object.fromEntries(map); } objToMap(obj) { return new Map(Object.entries(obj || {})); }