diff --git a/src/context.ts b/src/context.ts index c60d40e..71b8a6f 100644 --- a/src/context.ts +++ b/src/context.ts @@ -148,13 +148,17 @@ export class Context { } private async _logSessionEntry(toolName: string, params: Record, snapshotFile?: string) { - if (!this.config.saveSession || !this._sessionFile) + if (!this.config.saveSession) return; // Ensure session file is initialized before proceeding if (this._sessionFileInitialized) await this._sessionFileInitialized; + // After initialization, session file should always be defined when saveSession is true + if (!this._sessionFile) + throw new Error('Session file not initialized despite saveSession being enabled'); + const entry = [ `- ${toolName}:`, ' params:',