()
| 388 | * argv (both null) contexts. |
| 389 | */ |
| 390 | export function buildCommandTree(): CommandNode { |
| 391 | // Help printers are imported lazily to avoid pulling braintrust into |
| 392 | // quiet commands like `config path`. |
| 393 | const help = async () => import("./commands/help.js"); |
| 394 | |
| 395 | const runNode: CommandNode = { |
| 396 | name: "run", |
| 397 | summary: "Run evals", |
| 398 | printHelp: async () => (await help()).printRunHelp(), |
| 399 | handler: async (args, ctx) => { |
| 400 | const { parseRunArgs, resolveRunOptions } = await import( |
| 401 | "./commands/parse.js" |
| 402 | ); |
| 403 | const { readConfig } = await import("./commands/config.js"); |
| 404 | const { runCommand } = await import("./commands/run.js"); |
| 405 | |
| 406 | const flags = parseRunArgs(args); |
| 407 | const configFile = readConfig(ctx.entryDir); |
| 408 | const resolved = resolveRunOptions( |
| 409 | flags, |
| 410 | configFile.defaults, |
| 411 | process.env, |
| 412 | configFile.core, |
| 413 | ); |
| 414 | |
| 415 | // Argv mode (no abortRef): handle --legacy here, mirroring cli.ts. |
| 416 | if (ctx.abortRef === null) { |
| 417 | if (flags.legacy) { |
| 418 | const { runLegacy } = await import("./commands/legacy.js"); |
| 419 | const { discoverTasks } = await import("../framework/discovery.js"); |
| 420 | const { getRuntimeTasksRoot } = await import("../runtimePaths.js"); |
| 421 | const registry = await discoverTasks(getRuntimeTasksRoot(), false); |
| 422 | await runLegacy(resolved, flags, registry); |
| 423 | return; |
| 424 | } |
| 425 | await runCommand(resolved); |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | // REPL mode: pass abort signal so Esc can cancel. |
| 430 | const registry = await ctx.getRegistry(); |
| 431 | ctx.abortRef.current = new AbortController(); |
| 432 | try { |
| 433 | await runCommand(resolved, registry, ctx.abortRef.current.signal); |
| 434 | } finally { |
| 435 | ctx.abortRef.current = null; |
| 436 | } |
| 437 | }, |
| 438 | }; |
| 439 | |
| 440 | const listNode: CommandNode = { |
| 441 | name: "list", |
| 442 | summary: "List tasks and categories", |
| 443 | printHelp: async () => (await help()).printListHelp(), |
| 444 | handler: async (args, ctx) => { |
| 445 | const { printList } = await import("./commands/list.js"); |
| 446 | const detailed = args.includes("--detailed") || args.includes("-d"); |
| 447 | const tierFilter = args.find((a) => !a.startsWith("-")); |
no test coverage detected