1- import { FileSystemUtils } from '../../../utils/file-system.js' ;
2- import { SlashCommandConfigurator } from './base.js' ;
3- import { SlashCommandId , TemplateManager } from '../../templates/index.js' ;
4- import { OPENSPEC_MARKERS } from '../../config.js' ;
1+ import { TomlSlashCommandConfigurator } from './toml-base.js' ;
2+ import { SlashCommandId } from '../../templates/index.js' ;
53
64const FILE_PATHS : Record < SlashCommandId , string > = {
75 proposal : '.gemini/commands/openspec/proposal.toml' ,
@@ -15,69 +13,15 @@ const DESCRIPTIONS: Record<SlashCommandId, string> = {
1513 archive : 'Archive a deployed OpenSpec change and update specs.'
1614} ;
1715
18- export class GeminiSlashCommandConfigurator extends SlashCommandConfigurator {
16+ export class GeminiSlashCommandConfigurator extends TomlSlashCommandConfigurator {
1917 readonly toolId = 'gemini' ;
2018 readonly isAvailable = true ;
2119
2220 protected getRelativePath ( id : SlashCommandId ) : string {
2321 return FILE_PATHS [ id ] ;
2422 }
2523
26- protected getFrontmatter ( _id : SlashCommandId ) : string | undefined {
27- // TOML doesn't use separate frontmatter - it's all in one structure
28- return undefined ;
29- }
30-
31- // Override to generate TOML format with markers inside the prompt field
32- async generateAll ( projectPath : string , _openspecDir : string ) : Promise < string [ ] > {
33- const createdOrUpdated : string [ ] = [ ] ;
34-
35- for ( const target of this . getTargets ( ) ) {
36- const body = this . getBody ( target . id ) ;
37- const filePath = FileSystemUtils . joinPath ( projectPath , target . path ) ;
38-
39- if ( await FileSystemUtils . fileExists ( filePath ) ) {
40- await this . updateBody ( filePath , body ) ;
41- } else {
42- const tomlContent = this . generateTOML ( target . id , body ) ;
43- await FileSystemUtils . writeFile ( filePath , tomlContent ) ;
44- }
45-
46- createdOrUpdated . push ( target . path ) ;
47- }
48-
49- return createdOrUpdated ;
50- }
51-
52- private generateTOML ( id : SlashCommandId , body : string ) : string {
53- const description = DESCRIPTIONS [ id ] ;
54-
55- // TOML format with triple-quoted string for multi-line prompt
56- // Markers are inside the prompt value
57- return `description = "${ description } "
58-
59- prompt = """
60- ${ OPENSPEC_MARKERS . start }
61- ${ body }
62- ${ OPENSPEC_MARKERS . end }
63- """
64- ` ;
65- }
66-
67- // Override updateBody to handle TOML format
68- protected async updateBody ( filePath : string , body : string ) : Promise < void > {
69- const content = await FileSystemUtils . readFile ( filePath ) ;
70- const startIndex = content . indexOf ( OPENSPEC_MARKERS . start ) ;
71- const endIndex = content . indexOf ( OPENSPEC_MARKERS . end ) ;
72-
73- if ( startIndex === - 1 || endIndex === - 1 || endIndex <= startIndex ) {
74- throw new Error ( `Missing OpenSpec markers in ${ filePath } ` ) ;
75- }
76-
77- const before = content . slice ( 0 , startIndex + OPENSPEC_MARKERS . start . length ) ;
78- const after = content . slice ( endIndex ) ;
79- const updatedContent = `${ before } \n${ body } \n${ after } ` ;
80-
81- await FileSystemUtils . writeFile ( filePath , updatedContent ) ;
24+ protected getDescription ( id : SlashCommandId ) : string {
25+ return DESCRIPTIONS [ id ] ;
8226 }
8327}
0 commit comments