get_session_diff
Compare session snapshots to view file changes and modifications within a project, helping track development progress and identify updates.
Instructions
Get diff summary for a session including file changes and snapshot info
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_name | Yes | Project folder name | |
| session_id | Yes | Session ID |
Implementation Reference
- src/mcp/index.ts:161-166 (handler)The MCP tool handler function for 'get_session_diff'. It extracts parameters, calls the session helper, and formats the result as MCP content.async ({ project_name, session_id }) => { const result = await Effect.runPromise(session.getSessionDiffSummary(project_name, session_id)) return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], } }
- src/mcp/index.ts:157-160 (schema)Zod input schema defining parameters for the get_session_diff tool: project_name and session_id.{ project_name: z.string().describe('Project folder name'), session_id: z.string().describe('Session ID'), },
- src/mcp/index.ts:154-167 (registration)Registration of the 'get_session_diff' tool using server.tool, including name, description, schema, and handler.server.tool( 'get_session_diff', 'Get diff summary for a session including file changes and snapshot info', { project_name: z.string().describe('Project folder name'), session_id: z.string().describe('Session ID'), }, async ({ project_name, session_id }) => { const result = await Effect.runPromise(session.getSessionDiffSummary(project_name, session_id)) return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], } } )
- src/lib/session.ts:453-510 (helper)Main helper function that implements the logic for getSessionDiffSummary: reads session messages, extracts title from first human message, scans file-history-snapshot messages for unique file backups/changes, counts snapshots.export const getSessionDiffSummary = (projectName: string, sessionId: string) => Effect.gen(function* () { const messages = yield* readSession(projectName, sessionId) // Extract title const title = pipe( messages, A.findFirst((m) => m.type === 'human'), O.map((m) => { const msg = m.message as { content?: string } | undefined const content = msg?.content ?? '' return content.slice(0, 50) + (content.length > 50 ? '...' : '') }), O.getOrElse(() => 'Untitled') ) const changes: FileDiffSummary['changes'] = [] const seenFiles = new Set<string>() let snapshotCount = 0 for (const msg of messages) { if (msg.type === 'file-history-snapshot') { snapshotCount++ const snapshot = msg as { type: string snapshot?: { trackedFileBackups?: Record<string, { content?: string }> } } const backups = snapshot.snapshot?.trackedFileBackups if (backups && typeof backups === 'object') { for (const [filePath, backup] of Object.entries(backups)) { if (!seenFiles.has(filePath)) { seenFiles.add(filePath) const backupData = backup as { content?: string } | undefined const content = backupData?.content ?? '' changes.push({ path: filePath, action: 'modified', hasBackup: content.length > 0, backupPreview: content.slice(0, 100) + (content.length > 100 ? '...' : ''), }) } } } } } return { sessionId, projectName, title, changes, totalFiles: changes.length, snapshotCount, } satisfies FileDiffSummary })
- src/lib/session.ts:439-451 (schema)TypeScript interface defining the structure of the session diff summary output.export interface FileDiffSummary { sessionId: string projectName: string title: string changes: Array<{ path: string action: 'created' | 'modified' | 'deleted' hasBackup: boolean backupPreview?: string }> totalFiles: number snapshotCount: number }