@@ -38,11 +38,15 @@ export class RalphStackMemoryBridge {
3838 private sessionManager : SessionManager ;
3939 private recoveryState ?: RecoveryState ;
4040 private readonly ralphDir = '.ralph' ;
41+ private readonly requiresDatabase : boolean ;
4142
42- constructor ( options ?: BridgeOptions ) {
43+ constructor ( options ?: BridgeOptions & { useStackMemory ?: boolean } ) {
4344 // Initialize configuration
4445 this . config = this . mergeConfig ( options ?. config ) ;
4546
47+ // Check if database/StackMemory features are required
48+ this . requiresDatabase = options ?. useStackMemory !== false ;
49+
4650 // Initialize managers
4751 this . state = {
4852 initialized : false ,
@@ -87,18 +91,26 @@ export class RalphStackMemoryBridge {
8791
8892 this . state . currentSession = session ;
8993
90- // Initialize frame manager with session database
91- if ( session . database && session . projectId ) {
92- this . frameManager = new FrameManager (
93- session . database ,
94- session . projectId ,
95- {
96- skipContextBridge : true ,
97- }
98- ) ;
94+ // Initialize frame manager with session database if required
95+ if ( this . requiresDatabase ) {
96+ if ( session . database && session . projectId ) {
97+ this . frameManager = new FrameManager (
98+ session . database ,
99+ session . projectId ,
100+ {
101+ skipContextBridge : true ,
102+ }
103+ ) ;
104+ } else {
105+ throw new Error (
106+ 'Session database not available for FrameManager initialization. ' +
107+ 'If StackMemory features are not needed, set useStackMemory: false in options'
108+ ) ;
109+ }
99110 } else {
100- throw new Error (
101- 'Session database not available for FrameManager initialization'
111+ // Database not required, skip frame manager initialization
112+ logger . info (
113+ 'Running without StackMemory database (useStackMemory: false)'
102114 ) ;
103115 }
104116
@@ -580,6 +592,21 @@ export class RalphStackMemoryBridge {
580592 * Create root frame for Ralph loop
581593 */
582594 private async createRootFrame ( state : RalphLoopState ) : Promise < Frame > {
595+ if ( ! this . requiresDatabase ) {
596+ // Return a mock frame when database is not required
597+ return {
598+ frame_id : `mock-${ state . loopId } ` ,
599+ type : 'task' as FrameType ,
600+ name : `ralph-${ state . loopId } ` ,
601+ inputs : {
602+ task : state . task ,
603+ criteria : state . criteria ,
604+ loopId : state . loopId ,
605+ } ,
606+ created_at : Date . now ( ) ,
607+ } as Frame ;
608+ }
609+
583610 if ( ! this . frameManager ) {
584611 throw new Error ( 'Frame manager not initialized' ) ;
585612 }
@@ -926,7 +953,8 @@ export class RalphStackMemoryBridge {
926953 * Save iteration frame to StackMemory
927954 */
928955 private async saveIterationFrame ( iteration : RalphIteration ) : Promise < void > {
929- if ( ! this . frameManager || ! this . state . activeLoop ) return ;
956+ if ( ! this . requiresDatabase || ! this . frameManager || ! this . state . activeLoop )
957+ return ;
930958
931959 const frame : Partial < Frame > = {
932960 type : 'subtask' as FrameType ,
0 commit comments