@@ -256,10 +256,9 @@ async function registerIpcHandlers(): Promise<void> {
256256 }
257257
258258 // Append to description if sensible
259+ // MOVED TO projectGuidelines
259260 if ( context . guidelines ) {
260- data . description =
261- ( data . description || '' ) +
262- `\n\n[Imported Guidelines]\n${ context . guidelines } ` ;
261+ ( data as any ) . projectGuidelines = context . guidelines ;
263262 }
264263 }
265264 } catch ( scanErr ) {
@@ -466,14 +465,9 @@ async function registerIpcHandlers(): Promise<void> {
466465 } ;
467466 }
468467
469- // Append guidelines to description if present
468+ // Update projectGuidelines if present
470469 if ( context . guidelines ) {
471- // Check if guidelines are not already in description to avoid duplication
472- if ( ! project . description ?. includes ( '[Imported Guidelines]' ) ) {
473- updateData . description =
474- ( project . description || '' ) +
475- `\n\n[Imported Guidelines]\n${ context . guidelines } ` ;
476- }
470+ updateData . projectGuidelines = context . guidelines ;
477471 }
478472
479473 if ( Object . keys ( updateData ) . length > 0 ) {
@@ -510,6 +504,135 @@ async function registerIpcHandlers(): Promise<void> {
510504 }
511505 } ) ;
512506
507+ // Detect existing agent context for project recovery
508+ ipcMain . handle ( 'projects:detect-context' , async ( _event , projectId : number ) => {
509+ try {
510+ const project = await projectRepo . findById ( projectId ) ;
511+ if ( ! project || ! project . baseDevFolder ) {
512+ return { hasContext : false } ;
513+ }
514+
515+ const folder = project . baseDevFolder ;
516+ const fs = await import ( 'fs/promises' ) ;
517+ const path = await import ( 'path' ) ;
518+
519+ // Helper to check if path exists
520+ const exists = async ( p : string ) => {
521+ try {
522+ await fs . access ( p ) ;
523+ return true ;
524+ } catch {
525+ return false ;
526+ }
527+ } ;
528+
529+ // Helper to read file safely
530+ const readFileSafe = async ( p : string ) : Promise < string | null > => {
531+ try {
532+ return await fs . readFile ( p , 'utf-8' ) ;
533+ } catch {
534+ return null ;
535+ }
536+ } ;
537+
538+ // Detect various context files
539+ const hasClaudeMd = await exists ( path . join ( folder , 'CLAUDE.md' ) ) ;
540+ const hasGeminiDir = await exists ( path . join ( folder , '.gemini' ) ) ;
541+ const hasCodexDir = await exists ( path . join ( folder , '.codex' ) ) ;
542+ const hasGit = await exists ( path . join ( folder , '.git' ) ) ;
543+ const hasGeminiMd = await exists ( path . join ( folder , 'GEMINI.md' ) ) ;
544+ const hasAgentsMd = await exists ( path . join ( folder , 'AGENTS.md' ) ) ;
545+ const hasTaskMd = await exists ( path . join ( folder , 'task.md' ) ) ;
546+ const hasPlanMd = await exists ( path . join ( folder , 'implementation_plan.md' ) ) ;
547+ const hasReadme = await exists ( path . join ( folder , 'README.md' ) ) ;
548+
549+ // Read Claude CLAUDE.md content
550+ const claudeMdContent = hasClaudeMd
551+ ? await readFileSafe ( path . join ( folder , 'CLAUDE.md' ) )
552+ : null ;
553+
554+ // Read Gemini GEMINI.md content
555+ const geminiMdContent = hasGeminiMd
556+ ? await readFileSafe ( path . join ( folder , 'GEMINI.md' ) )
557+ : null ;
558+
559+ // Read Codex AGENTS.md content (OpenAI Codex uses AGENTS.md)
560+ const agentsMdContent = hasAgentsMd
561+ ? await readFileSafe ( path . join ( folder , 'AGENTS.md' ) )
562+ : null ;
563+
564+ // Read task.md for Gemini CLI progress context
565+ const taskMdContent = hasTaskMd
566+ ? await readFileSafe ( path . join ( folder , 'task.md' ) )
567+ : null ;
568+
569+ // Read implementation_plan.md for Gemini CLI progress
570+ const planMdContent = hasPlanMd
571+ ? await readFileSafe ( path . join ( folder , 'implementation_plan.md' ) )
572+ : null ;
573+
574+ // Check .gemini/task.md as alternative location
575+ let geminiTaskMdContent : string | null = null ;
576+ if ( hasGeminiDir ) {
577+ geminiTaskMdContent = await readFileSafe ( path . join ( folder , '.gemini' , 'task.md' ) ) ;
578+ }
579+
580+ // Get recent git commits if git exists
581+ let recentCommits : string [ ] = [ ] ;
582+ if ( hasGit ) {
583+ try {
584+ const { exec } = await import ( 'child_process' ) ;
585+ const { promisify } = await import ( 'util' ) ;
586+ const execAsync = promisify ( exec ) ;
587+ const { stdout } = await execAsync ( 'git log --oneline -n 5' , { cwd : folder } ) ;
588+ recentCommits = stdout
589+ . trim ( )
590+ . split ( '\n' )
591+ . filter ( ( l : string ) => l ) ;
592+ } catch ( e ) {
593+ console . warn ( 'Could not get git history:' , e ) ;
594+ }
595+ }
596+
597+ const hasContext =
598+ hasClaudeMd ||
599+ hasGeminiDir ||
600+ hasCodexDir ||
601+ hasGeminiMd ||
602+ hasAgentsMd ||
603+ hasTaskMd ||
604+ hasPlanMd ;
605+
606+ return {
607+ hasContext,
608+ // Detection flags
609+ hasClaudeMd,
610+ hasGeminiDir,
611+ hasCodexDir,
612+ hasGit,
613+ hasGeminiMd,
614+ hasAgentsMd,
615+ hasTaskMd,
616+ hasPlanMd,
617+ hasReadme,
618+ // Content
619+ claudeMdContent,
620+ geminiMdContent,
621+ agentsMdContent,
622+ taskMdContent,
623+ planMdContent,
624+ geminiTaskMdContent,
625+ recentCommits,
626+ } ;
627+ } catch ( error ) {
628+ console . error ( 'Error detecting context:' , error ) ;
629+ return {
630+ hasContext : false ,
631+ error : error instanceof Error ? error . message : String ( error ) ,
632+ } ;
633+ }
634+ } ) ;
635+
513636 // ========================================
514637 // Task IPC Handlers
515638 // ========================================
0 commit comments