@@ -121,28 +121,35 @@ async function main() {
121121 console . log ( `📝 Found ${ stagedChanges . modified . length } staged modified/added MDX files` ) ;
122122 console . log ( `🗑️ Found ${ stagedChanges . deleted . length } staged deleted MDX files` ) ;
123123
124+ const args = new Set ( process . argv . slice ( 2 ) ) ;
125+ const onlyStaged = args . has ( '--only-staged' ) || ! args . has ( '--all' ) ;
126+ const repairMissing = args . has ( '--repair-missing' ) || args . has ( '--repair-missing=1' ) ;
127+ const aiEnabled = ! ! ( process . env . MY_BASE_URL && process . env . MY_API_KEY ) ;
128+
129+ console . log ( `⚙️ Options -> mode: ${ onlyStaged ? 'only-staged' : 'all' } , repair-missing: ${ repairMissing ? 'on' : 'off' } ` ) ;
130+ console . log ( `🤖 AI enabled: ${ aiEnabled ? 'yes' : 'no (will skip MD writes)' } ` ) ;
124131 if ( stagedChanges . deleted . length > 0 ) {
125132 console . log ( '🗑️ Deleting corresponding MD files for deleted MDX files...' ) ;
126133 deleteCorrespondingMdFiles ( stagedChanges . deleted ) ;
127134 }
128135
129136 console . log ( '🔍 Checking for MDX files without corresponding MD files...' ) ;
130- const missingMdFiles = findMdxFilesWithoutMd ( srcPagesPath , outputDir ) ;
137+ const missingMdFiles = repairMissing ? findMdxFilesWithoutMd ( srcPagesPath , outputDir ) : [ ] ;
131138
132139 let filesToProcess : string [ ] = [ ] ;
133-
134- if ( missingMdFiles . length > 0 ) {
135- console . log ( `📝 Found ${ missingMdFiles . length } MDX files without corresponding MD files` ) ;
136-
137- const missingMdFilesFullPaths = missingMdFiles . map ( relPath =>
138- `src/pages/${ relPath } `
139- ) ;
140-
141- const allFilesToProcess = [ ...new Set ( [ ...stagedChanges . modified , ...missingMdFilesFullPaths ] ) ] ;
142- filesToProcess = getAbsolutePaths ( allFilesToProcess , projectRoot ) ;
143- } else {
144- filesToProcess = getAbsolutePaths ( stagedChanges . modified , projectRoot ) ;
140+ const relPaths : string [ ] = [ ] ;
141+
142+ relPaths . push ( ...stagedChanges . modified ) ;
143+
144+ if ( repairMissing && missingMdFiles . length > 0 ) {
145+ console . log ( `📝 Found ${ missingMdFiles . length } MDX files without corresponding MD files (repair requested)` ) ;
146+ const missingMdFilesFullPaths = missingMdFiles . map ( relPath => `src/pages/${ relPath } ` ) ;
147+ for ( const p of missingMdFilesFullPaths ) {
148+ if ( ! relPaths . includes ( p ) ) relPaths . push ( p ) ;
149+ }
145150 }
151+
152+ filesToProcess = getAbsolutePaths ( relPaths , projectRoot ) ;
146153
147154 if ( filesToProcess . length === 0 && stagedChanges . deleted . length === 0 ) {
148155 console . log ( 'ℹ️ No MDX files to process' ) ;
@@ -185,24 +192,14 @@ async function main() {
185192 fs . mkdirSync ( outputFileDir , { recursive : true } ) ;
186193 }
187194
188- let aiProcessedContent : string | null = null ;
189- try {
190- console . log ( `🤖 Processing with AI: ${ displayPath } ` ) ;
191- const aiResult = await overviewByAI ( mdContent ) ;
192- if ( aiResult && aiResult . trim ( ) . length >= 50 ) {
193- aiProcessedContent = aiResult . trim ( ) ;
194- } else {
195- console . warn ( `⚠️ AI returned empty/short result for ${ displayPath } , skipping write` ) ;
196- }
197- } catch ( aiErr ) {
198- console . warn ( `⚠️ AI failed for ${ displayPath } , skipping write` , aiErr ) ;
199- }
200-
201- if ( ! aiProcessedContent ) {
202- console . warn ( `⏭️ Skipping MD write for ${ displayPath } due to AI unavailability` ) ;
195+ console . log ( `🤖 Processing with AI: ${ displayPath } ` ) ;
196+ const aiRes = await overviewByAI ( mdContent ) ;
197+ if ( aiRes . status !== 'SUCCESS' ) {
198+ console . warn ( `⏭️ Skipping MD write for ${ displayPath } due to AI status: ${ aiRes . status } ` ) ;
203199 skippedAiCount ++ ;
204200 continue ;
205201 }
202+ const aiProcessedContent = aiRes . text ;
206203
207204 let originalPath = relativePath . replace ( / \. m d x $ / , '' ) ;
208205 if ( originalPath . endsWith ( '/index' ) ) {
0 commit comments