(prompt?: string, options: ChatOptions = {})
| 544 | } |
| 545 | |
| 546 | export async function chat(prompt?: string, options: ChatOptions = {}) { |
| 547 | // Configure logger based on headless mode |
| 548 | configureLogger(options.headless ?? false); |
| 549 | |
| 550 | // Configure headless-aware logging system |
| 551 | logging.configureLogger({ headless: options.headless ?? false }); |
| 552 | |
| 553 | try { |
| 554 | // Record session start |
| 555 | telemetryService.recordSessionStart(); |
| 556 | |
| 557 | // Start active time tracking |
| 558 | telemetryService.startActiveTime(); |
| 559 | |
| 560 | // Critical routing: Explicit separation of headless and interactive modes |
| 561 | if (options.headless) { |
| 562 | // Headless path - no Ink, no TUI, works in TTY-less environments |
| 563 | logger.debug("Running in headless mode (TTY-less compatible)"); |
| 564 | await runHeadlessMode(prompt, options); |
| 565 | return; |
| 566 | } |
| 567 | |
| 568 | // Interactive path - requires TTY for Ink rendering |
| 569 | // If not in headless mode, use unified initialization with TUI |
| 570 | if (!options.headless) { |
| 571 | // Process flags for TUI mode |
| 572 | const { permissionOverrides } = processCommandFlags(options); |
| 573 | // Initialize services with onboarding handled internally |
| 574 | await initializeServices({ |
| 575 | options, |
| 576 | headless: false, |
| 577 | toolPermissionOverrides: permissionOverrides, |
| 578 | }); |
| 579 | |
| 580 | const agentFileState = await serviceContainer.get<AgentFileServiceState>( |
| 581 | SERVICE_NAMES.AGENT_FILE, |
| 582 | ); |
| 583 | |
| 584 | const initialPrompt = prependPrompt( |
| 585 | agentFileState?.agentFile?.prompt, |
| 586 | prompt, |
| 587 | ); |
| 588 | |
| 589 | // Start TUI with skipOnboarding since we already handled it |
| 590 | const tuiOptions: any = { |
| 591 | initialPrompt, |
| 592 | resume: options.resume, |
| 593 | fork: options.fork, |
| 594 | config: options.config, |
| 595 | org: options.org, |
| 596 | rule: options.rule, |
| 597 | prompt: options.prompt, |
| 598 | toolPermissionOverrides: permissionOverrides, |
| 599 | skipOnboarding: true, |
| 600 | }; |
| 601 | |
| 602 | // If we detected piped input, create a custom stdin for TUI |
| 603 | if ((options as any).hasPipedInput) { |
no test coverage detected