(
tools: Array<{ cliName: string; workflow: string; description?: string; stateful: boolean }>,
options: { grouped?: boolean; verbose?: boolean } = {},
)
| 1 | export type OutputFormat = 'text' | 'json' | 'jsonl' | 'raw'; |
| 2 | |
| 3 | export function formatToolList( |
| 4 | tools: Array<{ cliName: string; workflow: string; description?: string; stateful: boolean }>, |
| 5 | options: { grouped?: boolean; verbose?: boolean } = {}, |
| 6 | ): string { |
| 7 | const lines: string[] = []; |
| 8 | |
| 9 | if (options.grouped) { |
| 10 | const byWorkflow = new Map<string, typeof tools>(); |
| 11 | for (const tool of tools) { |
| 12 | let group = byWorkflow.get(tool.workflow); |
| 13 | if (!group) { |
| 14 | group = []; |
| 15 | byWorkflow.set(tool.workflow, group); |
| 16 | } |
| 17 | group.push(tool); |
| 18 | } |
| 19 | |
| 20 | const sortedWorkflows = [...byWorkflow.keys()].sort(); |
| 21 | for (const workflow of sortedWorkflows) { |
| 22 | lines.push(`\n${workflow}:`); |
| 23 | const workflowTools = byWorkflow.get(workflow) ?? []; |
| 24 | const sortedTools = workflowTools.sort((a, b) => a.cliName.localeCompare(b.cliName)); |
| 25 | |
| 26 | for (const tool of sortedTools) { |
| 27 | const statefulMarker = tool.stateful ? ' [stateful]' : ''; |
| 28 | if (options.verbose && tool.description) { |
| 29 | lines.push(` ${tool.cliName}${statefulMarker}`); |
| 30 | lines.push(` ${tool.description}`); |
| 31 | } else { |
| 32 | const desc = tool.description ? ` - ${truncate(tool.description, 60)}` : ''; |
| 33 | lines.push(` ${tool.cliName}${statefulMarker}${desc}`); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } else { |
| 38 | const sortedTools = [...tools].sort((a, b) => { |
| 39 | const aFull = `${a.workflow} ${a.cliName}`; |
| 40 | const bFull = `${b.workflow} ${b.cliName}`; |
| 41 | return aFull.localeCompare(bFull); |
| 42 | }); |
| 43 | |
| 44 | for (const tool of sortedTools) { |
| 45 | const fullCommand = `${tool.workflow} ${tool.cliName}`; |
| 46 | const statefulMarker = tool.stateful ? ' [stateful]' : ''; |
| 47 | if (options.verbose && tool.description) { |
| 48 | lines.push(`${fullCommand}${statefulMarker}`); |
| 49 | lines.push(` ${tool.description}`); |
| 50 | } else { |
| 51 | const desc = tool.description ? ` - ${truncate(tool.description, 60)}` : ''; |
| 52 | lines.push(`${fullCommand}${statefulMarker}${desc}`); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return lines.join('\n'); |
| 58 | } |
| 59 | |
| 60 | function truncate(str: string, maxLength: number): string { |
no test coverage detected