auto_save_context
Automatically save and compress AI development context including progress, decisions, and code snippets to maintain session continuity and prevent data loss.
Instructions
commit|checkpoint|backup|compress|auto-save - Auto-save and compress context
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| urgency | Yes | Urgency level | |
| contextType | Yes | Type of context to save | |
| sessionId | No | Current session identifier | |
| summary | No | Brief summary of current context | |
| fullContext | No | Full context to compress and save | |
| compress | No | Enable smart compression (default: true) |
Implementation Reference
- Main handler function implementing auto_save_context tool: saves context with optional compression using MemoryManager and ContextCompressor.export async function autoSaveContext(args: { urgency: string; contextType: string; sessionId?: string; summary?: string; fullContext?: string; compress?: boolean; }): Promise<ToolResult> { const { urgency, contextType, sessionId, summary, fullContext, compress = true } = args; try { const memoryManager = MemoryManager.getInstance(); let contextToSave = summary || ''; let compressionStats = null; // Apply smart compression if full context provided and compression enabled if (fullContext && compress) { const targetTokens = urgency === 'critical' ? 8000 : urgency === 'high' ? 7000 : 4000; const compressionResult = ContextCompressor.compress(fullContext, targetTokens); contextToSave = compressionResult.compressed; compressionStats = { originalTokens: ContextCompressor.estimateTokens(fullContext), compressedTokens: ContextCompressor.estimateTokens(compressionResult.compressed), ratio: Math.round(compressionResult.compressionRatio * 100), removed: compressionResult.removedSections.length }; } else if (fullContext) { contextToSave = fullContext; } const contextData = { timestamp: new Date().toISOString(), urgency, contextType, sessionId, summary, context: contextToSave, compressed: compress && !!fullContext, compressionStats }; const priority = urgency === 'high' || urgency === 'critical' ? 2 : urgency === 'medium' ? 1 : 0; const contextKey = sessionId ? `context:session_${sessionId}_${Date.now()}` : `context:${Date.now()}`; memoryManager.save(contextKey, JSON.stringify(contextData), 'context', priority); let resultText = `✓ Context saved: ${contextType} (${urgency})`; if (sessionId) resultText += `\nSession: ${sessionId}`; if (compressionStats) { resultText += `\nCompressed: ${compressionStats.originalTokens} → ${compressionStats.compressedTokens} tokens (${compressionStats.ratio}%)`; resultText += `\nRemoved: ${compressionStats.removed} low-priority sections`; } if (summary) resultText += `\n${summary}`; return { content: [{ type: 'text', text: resultText }] }; } catch (error) { return { content: [{ type: 'text', text: `✗ Error: ${error instanceof Error ? error.message : 'Unknown error'}` }] }; } }
- ToolDefinition schema for auto_save_context including input schema and metadata.export const autoSaveContextDefinition: ToolDefinition = { name: 'auto_save_context', description: 'commit|checkpoint|backup|compress|auto-save - Auto-save and compress context', inputSchema: { type: 'object', properties: { urgency: { type: 'string', description: 'Urgency level', enum: ['low', 'medium', 'high', 'critical'] }, contextType: { type: 'string', description: 'Type of context to save', enum: ['progress', 'decisions', 'code-snippets', 'debugging', 'planning'] }, sessionId: { type: 'string', description: 'Current session identifier' }, summary: { type: 'string', description: 'Brief summary of current context' }, fullContext: { type: 'string', description: 'Full context to compress and save' }, compress: { type: 'boolean', description: 'Enable smart compression (default: true)' } }, required: ['urgency', 'contextType'] }, annotations: { title: 'Auto-Save Context', audience: ['user', 'assistant'] } };
- src/index.ts:648-649 (registration)Tool handler dispatch/registration in the main executeToolCall switch statement.case 'auto_save_context': return await autoSaveContext(args as any) as CallToolResult;
- src/index.ts:131-131 (registration)Inclusion of autoSaveContextDefinition in the tools array for schema registration.autoSaveContextDefinition,
- src/index.ts:59-59 (registration)Import statement bringing in the handler and definition.import { autoSaveContext, autoSaveContextDefinition } from './tools/memory/autoSaveContext.js';