/**
 * Copyright (c) Microsoft Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { traceOpen } from './traceOpen';
import { closeTrace } from './traceUtils';
import { traceActions } from './traceActions';
import { traceAction } from './traceActions';
import { traceRequests } from './traceRequests';
import { traceRequest } from './traceRequests';
import { traceConsole } from './traceConsole';
import { traceErrors } from './traceErrors';
import { traceSnapshot } from './traceSnapshot';
import { traceScreenshot } from './traceScreenshot';
import { traceAttachments } from './traceAttachments';
import { traceAttachment } from './traceAttachments';
import { installSkill } from './installSkill';
export function addTraceCommands(program, logErrorAndExit) {
    const traceCommand = program
        .command('trace')
        .description('inspect trace files from the command line');
    traceCommand
        .command('open <trace>')
        .description('extract trace file for inspection')
        .action(async (trace) => {
        traceOpen(trace).catch(logErrorAndExit);
    });
    traceCommand
        .command('close')
        .description('remove extracted trace data')
        .action(async () => {
        closeTrace().catch(logErrorAndExit);
    });
    traceCommand
        .command('actions')
        .description('list actions in the trace')
        .option('--grep <pattern>', 'filter actions by title pattern')
        .option('--errors-only', 'only show failed actions')
        .action(async (options) => {
        traceActions(options).catch(logErrorAndExit);
    });
    traceCommand
        .command('action <action-id>')
        .description('show details of a specific action')
        .action(async (actionId) => {
        traceAction(actionId).catch(logErrorAndExit);
    });
    traceCommand
        .command('requests')
        .description('show network requests')
        .option('--grep <pattern>', 'filter by URL pattern')
        .option('--method <method>', 'filter by HTTP method')
        .option('--status <code>', 'filter by status code')
        .option('--failed', 'only show failed requests (status >= 400)')
        .action(async (options) => {
        traceRequests(options).catch(logErrorAndExit);
    });
    traceCommand
        .command('request <request-id>')
        .description('show details of a specific network request')
        .action(async (requestId) => {
        traceRequest(requestId).catch(logErrorAndExit);
    });
    traceCommand
        .command('console')
        .description('show console messages')
        .option('--errors-only', 'only show errors')
        .option('--warnings', 'show errors and warnings')
        .option('--browser', 'only browser console messages')
        .option('--stdio', 'only stdout/stderr')
        .action(async (options) => {
        traceConsole(options).catch(logErrorAndExit);
    });
    traceCommand
        .command('errors')
        .description('show errors with stack traces')
        .action(async () => {
        traceErrors().catch(logErrorAndExit);
    });
    traceCommand
        .command('snapshot <action-id>')
        .description('run a playwright-cli command against a DOM snapshot')
        .option('--name <name>', 'snapshot phase: before, input, or after')
        .option('--serve', 'serve snapshot on localhost and keep running')
        .allowUnknownOption(true)
        .allowExcessArguments(true)
        .action(async (actionId, options, cmd) => {
        try {
            // Collect everything after '--' as the browser command.
            const browserArgs = cmd.args.slice(1);
            await traceSnapshot(actionId, { ...options, browserArgs });
        }
        catch (e) {
            logErrorAndExit(e);
        }
    });
    traceCommand
        .command('screenshot <action-id>')
        .description('save screencast screenshot for an action')
        .option('-o, --output <path>', 'output file path')
        .action(async (actionId, options) => {
        traceScreenshot(actionId, options).catch(logErrorAndExit);
    });
    traceCommand
        .command('attachments')
        .description('list trace attachments')
        .action(async () => {
        traceAttachments().catch(logErrorAndExit);
    });
    traceCommand
        .command('attachment <attachment-id>')
        .description('extract a trace attachment by its number')
        .option('-o, --output <path>', 'output file path')
        .action(async (attachmentId, options) => {
        traceAttachment(attachmentId, options).catch(logErrorAndExit);
    });
    traceCommand
        .command('install-skill')
        .description('install SKILL.md for LLM integration')
        .action(async () => {
        installSkill().catch(logErrorAndExit);
    });
}
//# sourceMappingURL=traceCli.js.map