* Parse a CLI flag string (e.g. "--prompt ", "--stream") into * a parameter name and inferred type.
(flag: string)
| 5 | * a parameter name and inferred type. |
| 6 | */ |
| 7 | function parseFlag(flag: string): { |
| 8 | name: string; |
| 9 | kebabName: string; |
| 10 | inferredType: string; |
| 11 | isArray: boolean; |
| 12 | } { |
| 13 | // e.g. "--prompt <text>" -> "prompt" |
| 14 | const match = flag.match(/^--([a-zA-Z0-9-]+)/); |
| 15 | const kebabName = match ? match[1]! : ''; |
| 16 | // camelCase to match internal API conventions |
| 17 | const name = kebabName.replace(/-([a-zA-Z0-9])/g, (_, c: string) => c.toUpperCase()); |
| 18 | |
| 19 | let inferredType = 'string'; |
| 20 | let isArray = false; |
| 21 | |
| 22 | if (!flag.includes('<') && !flag.includes('[')) { |
| 23 | // No parameter value — typically a boolean flag like --stream |
| 24 | inferredType = 'boolean'; |
| 25 | } else if (flag.includes('<n>') || flag.includes('<hz>') || flag.includes('<bps>') || flag.includes('<count>')) { |
| 26 | inferredType = 'number'; |
| 27 | } |
| 28 | |
| 29 | if (flag.toLowerCase().includes('repeatable')) { |
| 30 | isArray = true; |
| 31 | } |
| 32 | |
| 33 | return { name, kebabName, inferredType, isArray }; |
| 34 | } |
| 35 | |
| 36 | export function generateToolSchema(cmd: Command): Record<string, unknown> { |
| 37 | const toolName = `mmx_${cmd.name.replace(/ /g, '_')}`; |
no outgoing calls
no test coverage detected