/** * codebase-analyzer.ts * * Scans an existing project directory to detect its Playwright test patterns, * naming conventions, import styles, POM structure, and fixture usage. * * Output is injected into the code-generation prompt so generated code * matches the project's own style exactly instead of PlayGen defaults. * * When no existing tests are found, the analyzer returns a "new codebase" * profile with Playwright Pilot AI default settings (StepTracker, kebab-case * filenames, PascalCase class names, etc.). * * Key things detected: * - Test file directory (tests/, e2e/, test/, spec/) * - POM file directory (pages/, page-objects/, pageObjects/, etc.) * - Import style (vanilla @playwright/test vs. custom fixtures) * - Whether StepTracker and ELEMENT_CONTEXTS are used * - Whether a base page class is used and what it's called * - Naming conventions (kebab-case, camelCase, PascalCase, snake_case) * - Locator style (getByRole > getByLabel > CSS, XPath, etc.) * - Whether tests use test.describe blocks * * Role in the overall flow: * generate_test / video_to_test / preview_generation * → analyzeCodebase() → CodebaseProfile → code-generation prompt */ /** How tests in this project are structured. */ export type TestStyle = 'pwpilot' | 'fixture-based' | 'vanilla-playwright' | 'custom'; /** The file naming convention used by this project. */ export type NamingConvention = 'kebab-case' | 'camelCase' | 'PascalCase' | 'snake_case' | 'unknown'; /** A snippet of a file used for pattern detection. */ export interface FileSample { filePath: string; content: string; } /** * Complete profile of a Playwright project's conventions. * Used to make generated code look native to the project. */ export interface CodebaseProfile { /** True if no existing test or POM files were found. */ isNewCodebase: boolean; /** * Source language for all generated files. * 'javascript' — Node.js CommonJS (.js, require/module.exports, no type annotations) * 'typescript' — TypeScript (.ts, import/export, full type annotations) * * Defaults to 'javascript' for new codebases. * Detected from existing files for existing codebases. */ language: 'javascript' | 'typescript'; /** Relative path to where test specs are stored, e.g. "tests" or "e2e". */ testDirectory: string; /** Relative path to where Page Object files are stored, e.g. "pages". */ pomDirectory: string; /** Playwright config file name if found, e.g. "playwright.config.ts". */ configFile: string | null; /** How tests are written in this project. */ testStyle: TestStyle; /** Naming convention used for class names in POM files. */ namingConvention: NamingConvention; /** Naming convention used for file names. */ fileNamingConvention: NamingConvention; /** Import line for test runner, e.g. "import { test, expect } from '@playwright/test'". */ baseTestImport: string; /** Import line for page object base, e.g. "import { Page, Locator } from '@playwright/test'". */ basePageImport: string; /** True if the project uses custom fixture files. */ usesFixtures: boolean; /** Import line for the fixture file if one is found, e.g. "import { test } from '../fixtures/test'". */ fixtureImport: string | null; /** True if the project uses the PlayGen StepTracker helper. */ usesStepTracker: boolean; /** True if POM classes extend a common base class. */ usesPageObjectBase: boolean; /** Name of the base class if used, e.g. "BasePage". */ pageObjectBaseClass: string | null; /** First 60 lines of a representative test spec file, used as a style sample. */ existingTestFileSample: string | null; /** First 60 lines of a representative POM file, used as a style sample. */ existingPomFileSample: string | null; /** Assertion style seen in existing tests, e.g. "expect(locator).toBeVisible()". */ assertionStyle: string; /** Locator strategy priority seen in existing code, e.g. "getByRole > getByLabel > CSS". */ locatorStyle: string; /** True if existing tests use test.describe() blocks. */ usesDescribeBlock: boolean; /** Up to 10 discovered test spec file paths. */ discoveredTestFiles: string[]; /** Up to 10 discovered POM file paths. */ discoveredPomFiles: string[]; } /** * Scan a project directory and return a CodebaseProfile describing its conventions. * * If no test or POM files are found, returns a "new codebase" profile with * Playwright Pilot AI defaults. Otherwise, reads up to 3 samples each from test * and POM files and extracts all style information from them. * * @param cwd - Absolute or relative path to the project root to analyze. * @returns A CodebaseProfile with all detected settings. */ export declare function analyzeCodebase(cwd: string): Promise; /** * Returns a compact codebase adaptation note for injection into prompts. * * For new codebases: a single line summarising PlayGen defaults. * For existing codebases: key facts + up to 20 lines of a real code sample. * * Token budget: <100 tokens for new codebases, <200 tokens for existing. * * @param profile - The CodebaseProfile to summarise. * @returns A compact markdown string ready to append to a code-generation prompt. */ export declare function buildCodebaseAdaptationSection(profile: CodebaseProfile): string; //# sourceMappingURL=codebase-analyzer.d.ts.map