// src/prompts/skyrampPrompt.ts
import { z } from "zod";
import { logger } from "../utils/logger.js";
import { SESSION_STORAGE_FILENAME } from "../types/TestTypes.js";
export function registerStartTraceCollectionPrompt(mcpServer) {
    logger.info("registering start trace collection prompt");
    mcpServer.registerPrompt("skyramp_trace_prompt", {
        description: "Skyramp trace collection prompt",
        argsSchema: {
            outputDir: z
                .string()
                .optional()
                .describe("Workspace directory where the session file will be saved. Pass the configured testDirectory from .skyramp/workspace.yml so the prompt can show the resolved save path instead of an abstract <outputDir> placeholder."),
        },
    }, (args) => {
        const outputDir = args?.outputDir;
        const sessionPathDisplay = outputDir
            ? `${outputDir.replace(/\/$/, "")}/${SESSION_STORAGE_FILENAME}`
            : `<outputDir>/${SESSION_STORAGE_FILENAME}`;
        return {
            messages: [
                {
                    role: "user",
                    content: {
                        type: "text",
                        text: `
**MANUAL Trace Collection (Docker-based):**
This is for MANUAL recording where the USER interacts with the browser themselves. Use this ONLY when the user explicitly requests "manual recording", "record myself", "I will interact", or "Docker trace". For AI-driven recording (where the agent drives the browser), use the browser_* tools and skyramp_export_zip instead.

* You can start a Skyramp trace session to capture network traffic from an active terminal window and for activity within a browser.
* Once you start a Skyramp trace session, you can stop it any time. Once stopped, a new session will be required to start a new trace collection.
* Please refer to the Skyramp documentation at https://www.skyramp.dev/docs/concepts/trace-collection for more details on trace collection.
* Once you have all the data call the stop trace collection tool to save the captured data.
* Always ask user if they want to enable playwright for trace collection.

**Playwright Configuration Options:**
When playwright is enabled for trace collection, you can optionally configure:

1. **Browser** (browser):
   - Choose which browser to use for trace collection
   - Supported browsers:
     * 'chromium' - Chrome/Chromium browser (default)
     * 'firefox' - Mozilla Firefox browser
     * 'webkit' - Safari/WebKit browser
   - Use firefox or webkit when you need to test cross-browser compatibility or specific browser behaviors

2. **Device** (device):
   - Device to emulate for mobile/tablet testing
   - Supported devices include:
     * 'iPhone 13' - Apple iPhone 13
     * 'iPhone 13 Pro' - Apple iPhone 13 Pro
     * 'Pixel 5' - Google Pixel 5
     * 'Galaxy S9+' - Samsung Galaxy S9 Plus
     * 'iPad Pro 11' - Apple iPad Pro
     * And many more Playwright device profiles
   - Leave empty (default) for desktop/no device emulation
   - Use specific device names when testing mobile-responsive applications or generating mobile UI tests

3. **LOAD existing session** (\`playwrightStoragePath\`):
   - Path to an existing playwright session storage file containing authentication data (cookies, localStorage, sessionStorage, etc.)
   - MUST be an absolute path like /path/to/storage.json
   - Use this when the user wants to REUSE a previously captured session so the recording starts already-authenticated (no login needed).
   - The session file should have been created in a prior \`skyramp_start_trace_collection\` run that captured the login flow (see option 5 below).

4. **Playwright Viewport Size** (playwrightViewportSize):
   - Defines the browser window size for trace collection
   - Supported formats:
     * 'hd' - 1280x720
     * 'full-hd' - 1920x1080
     * '2k' - 2560x1440
     * Custom: 'width,height' (e.g., '1920,1080')

5. **SAVE new session** (\`playwrightSaveStoragePath\`) — distinct from option 3, which LOADS an existing session; this option CAPTURES a fresh one:
   - Defaults to saving the session at \`${sessionPathDisplay}\` — do NOT set this argument unless the user requests a custom filename or absolute path.
   - When the goal is to capture an authenticated session for re-use, the recording workflow is strict:
     1. Start the trace collection.
     2. Have the user log in once.
     3. STOP IMMEDIATELY after login completes — any further interactions will pollute the trace.
   - Re-use the saved file by passing it as \`playwrightStoragePath\` (option 3) on later \`skyramp_start_trace_collection\` runs (skips login). Generated tests that reference \`storageState\` will also auto-mount it when run via \`skyramp_execute_test\`.
   - Example user prompts: "save my session", "store login session for future tests", "record auth state", "with session storage".

**Example usage prompt for trace collection:**
* To start a trace collection session using agent, run the following command:
  Generate trace with default settings and include realworld.demo.com:8080

**Example usage prompt for trace collection for playwright trace:**
* To start a playwright trace collection session using agent, run the following command:
  Start playwright trace collection with default settings.

**Example usage prompt for trace collection with device emulation:**
* To start a trace collection session with mobile device emulation:
  Start trace collection with iPhone 13 device
  Collect trace using Pixel 5 device emulation
  Start playwright trace with iPad Pro device

**Example usage prompt for trace collection with playwright storage and viewport:**
* Start playwright trace collection with storage path /Users/dev/session-storage.json and viewport size full-hd

**Example usage prompt for trace collection with specific browser:**
* Start trace collection with Firefox browser
* Collect UI traces using webkit browser
* Start playwright trace collection with chromium browser (default)

**CRITICAL: NEVER SHOW THE CLI COMMANDS.**
`,
                    },
                },
            ],
        };
    });
}
