@@ -48,6 +48,9 @@ export class HindsightEmbedManager {
4848 env [ 'HINDSIGHT_EMBED_LLM_MODEL' ] = this . llmModel ;
4949 }
5050
51+ // Write env vars to ~/.hindsight/config.env for daemon persistence
52+ await this . writeConfigEnv ( env ) ;
53+
5154 // Start hindsight-embed daemon (it manages itself)
5255 const embedPackage = this . embedVersion ? `hindsight-embed@${ this . embedVersion } ` : 'hindsight-embed@latest' ;
5356 const startDaemon = spawn (
@@ -145,4 +148,64 @@ export class HindsightEmbedManager {
145148 isRunning ( ) : boolean {
146149 return this . process !== null ;
147150 }
151+
152+ private async writeConfigEnv ( env : NodeJS . ProcessEnv ) : Promise < void > {
153+ const hindsightDir = join ( homedir ( ) , '.hindsight' ) ;
154+ const embedConfigPath = join ( hindsightDir , 'embed' ) ;
155+
156+ // Ensure directory exists
157+ await fs . mkdir ( hindsightDir , { recursive : true } ) ;
158+
159+ // Read existing config to preserve extra settings
160+ let existingContent = '' ;
161+ let extraSettings : string [ ] = [ ] ;
162+ try {
163+ existingContent = await fs . readFile ( embedConfigPath , 'utf-8' ) ;
164+ // Extract non-LLM settings (like FORCE_CPU flags)
165+ const lines = existingContent . split ( '\n' ) ;
166+ for ( const line of lines ) {
167+ const trimmed = line . trim ( ) ;
168+ if ( trimmed && ! trimmed . startsWith ( '#' ) &&
169+ ! trimmed . startsWith ( 'HINDSIGHT_EMBED_LLM_' ) &&
170+ ! trimmed . startsWith ( 'HINDSIGHT_EMBED_BANK_ID' ) &&
171+ ! trimmed . startsWith ( 'HINDSIGHT_EMBED_DAEMON_IDLE_TIMEOUT' ) ) {
172+ extraSettings . push ( line ) ;
173+ }
174+ }
175+ } catch {
176+ // File doesn't exist yet, that's fine
177+ }
178+
179+ // Build config file with header
180+ const configLines : string [ ] = [
181+ '# Hindsight Embed Configuration' ,
182+ '# Generated by OpenClaw Hindsight plugin' ,
183+ '' ,
184+ ] ;
185+
186+ // Add LLM config
187+ if ( env . HINDSIGHT_EMBED_LLM_PROVIDER ) {
188+ configLines . push ( `HINDSIGHT_EMBED_LLM_PROVIDER=${ env . HINDSIGHT_EMBED_LLM_PROVIDER } ` ) ;
189+ }
190+ if ( env . HINDSIGHT_EMBED_LLM_MODEL ) {
191+ configLines . push ( `HINDSIGHT_EMBED_LLM_MODEL=${ env . HINDSIGHT_EMBED_LLM_MODEL } ` ) ;
192+ }
193+ if ( env . HINDSIGHT_EMBED_LLM_API_KEY ) {
194+ configLines . push ( `HINDSIGHT_EMBED_LLM_API_KEY=${ env . HINDSIGHT_EMBED_LLM_API_KEY } ` ) ;
195+ }
196+ if ( env . HINDSIGHT_EMBED_DAEMON_IDLE_TIMEOUT ) {
197+ configLines . push ( `HINDSIGHT_EMBED_DAEMON_IDLE_TIMEOUT=${ env . HINDSIGHT_EMBED_DAEMON_IDLE_TIMEOUT } ` ) ;
198+ }
199+
200+ // Add extra settings if they exist
201+ if ( extraSettings . length > 0 ) {
202+ configLines . push ( '' ) ;
203+ configLines . push ( '# Additional settings' ) ;
204+ configLines . push ( ...extraSettings ) ;
205+ }
206+
207+ // Write to file
208+ await fs . writeFile ( embedConfigPath , configLines . join ( '\n' ) + '\n' , 'utf-8' ) ;
209+ console . log ( `[Hindsight] Wrote config to ${ embedConfigPath } ` ) ;
210+ }
148211}
0 commit comments