11import { readFileSync } from 'fs'
2- import markdownToAnsiFactory from 'markdown-to-ansi'
32import { join } from 'path'
43
54import { assetsAI } from '../consts'
@@ -11,13 +10,19 @@ import { logger } from './logger'
1110 *
1211 * @returns Formatted guidance text with ANSI codes, or empty string if file doesn't exist
1312 */
14- function getGuidance ( ) : string {
13+ async function getGuidance ( ) : Promise < string > {
1514 const guidancePath = join ( assetsAI , 'guidance.md' )
1615
1716 try {
1817 const guidanceTemplate = readFileSync ( guidancePath , 'utf-8' )
1918
20- // markdown-to-ansi exports a factory function that returns a converter function
19+ /*
20+ * Dynamic import is used because markdown-to-ansi is an ES module.
21+ * When compiled to CommonJS, static imports would be transformed to require(),
22+ * which doesn't work for ES modules in Node.js 18 and below.
23+ */
24+ const markdownToAnsiModule = await import ( 'markdown-to-ansi' )
25+ const markdownToAnsiFactory = markdownToAnsiModule . default ?? markdownToAnsiModule
2126 const converter = markdownToAnsiFactory ( )
2227 // Convert markdown to ANSI-formatted terminal text (supports bold, italic, code, etc.)
2328
@@ -39,7 +44,7 @@ function getGuidance(): string {
3944 * Used for missing parameter errors to provide helpful guidance to users and AI assistants.
4045 */
4146export class GuidanceError extends Error {
42- public readonly guidance : string
47+ public readonly guidance : Promise < string >
4348
4449 constructor ( message : string ) {
4550 super ( message )
0 commit comments