/** * Weavetab — intelligence/patternCompiler.ts * * Compiles raw browser session trails (action sequences) into persistent, * reusable site workflow patterns stored under ~/.weavetab-system/memory/sites/. * * Design invariants: * - One file per origin (sanitized hostname). Never creates per-path or per-run files. * - Pattern names are caller-supplied (snake_case). Duplicate calls for the same * name on the same origin UPDATE the existing pattern rather than creating a new file. * - Volatile / unstable selectors (auto-generated classes, nth-child paths) are * stripped and replaced with semantic anchors where possible. * - Never reads or writes to ~/.weavetab/ (user config space). */ export interface WorkflowStep { /** MCP tool name, e.g. "browser_click", "browser_fill", "browser_navigate" */ tool: string; /** Primary selector or URL target */ target?: string; /** Optional value (text typed, option selected, etc.) */ value?: string; /** Any extra args forwarded verbatim to browser_burst replay */ extra?: Record; } export interface WorkflowPattern { /** Caller-assigned name in snake_case, e.g. "login_flow", "pr_review" */ name: string; /** Compiled, stable steps ready for browser_burst replay */ steps: WorkflowStep[]; /** Optional CSS selector / URL fragment that confirms success */ success_indicator?: string; /** URL path or pattern where this workflow starts, e.g. "/pull/:id/files" */ entry?: string; /** Exponentially-weighted moving average of duration in ms */ avg_duration_ms?: number; /** 0.0 – 1.0 reliability. Degrades on failures, climbs on successes. */ reliability: number; /** Consecutive failure counter — 3 strikes triggers re-learn flag */ strikes: number; /** ISO timestamp of last successful verified run */ last_verified: string; /** Total times this pattern was executed */ total_executions: number; /** Times the pattern completed without errors */ successful_executions: number; } export interface SiteQuirks { cookie_banner?: { selector: string; action: string; appears: "first_visit" | "always" | "random"; }; rate_limit?: { threshold?: string; recovery?: string; }; modal_popups?: Array<{ trigger?: string; dismiss_selector: string; }>; [key: string]: unknown; } export interface SiteProfile { /** Full origin, e.g. "https://github.com" */ origin: string; /** Detected JS framework: react, vue, angular, next, nuxt, svelte, etc. */ framework?: string; /** True if the site uses Shadow DOM components */ shadowDom?: boolean; /** How often this site presents CAPTCHA challenges */ captcha_frequency?: "none" | "rare" | "moderate" | "frequent"; /** Known site-level quirks to handle automatically */ quirks: SiteQuirks; /** Named, compiled workflow patterns indexed by name */ patterns: Record; /** ISO timestamp of last profile write */ updatedAt: string; /** How many times this origin has been visited in automated sessions */ visitCount: number; } export declare function clearSiteProfileCache(): void; /** * Load a site profile from disk. Returns null if the site has never been profiled. * Hits in-process cache first — no redundant disk reads within a session. */ export declare function getSiteProfile(origin: string): Promise; /** * Persist a site profile. Always deep-merges into existing data on disk — never * blindly overwrites — so concurrent tool calls don't clobber each other. */ export declare function saveSiteProfile(profile: SiteProfile): Promise; /** * Learn or update a named workflow pattern for a given origin. * - Duplicate name = merge/update, never duplicate file. * - Volatile selectors in steps are dropped to keep patterns stable. * - Anti-spam: skips disk write when content is identical to existing. */ export declare function learnPattern(origin: string, name: string, incoming: Partial): Promise; /** * Record the outcome of executing a named pattern. * Updates reliability via EWMA (α=0.15) and tracks consecutive strikes. * 3 strikes → reliability will naturally fall below 0.4, agent should re-explore. */ export declare function recordPatternExecution(origin: string, patternName: string, success: boolean, durationMs?: number): Promise; /** * Record or update a site quirk (cookie banner, rate limit, modal popup, etc.) * Only writes if the stored data differs from incoming — prevents spam writes. */ export declare function recordQuirk(origin: string, quirkKey: string, quirkData: unknown): Promise; /** * Returns the reliability score (0–1) of a named pattern, or -1 if unknown. */ export declare function getPatternReliability(origin: string, patternName: string): Promise; /** * Formats a compact site profile hint string for agent system prompt injection. * Called at session start when navigating to a known origin. */ export declare function formatSiteProfileHint(profile: SiteProfile): string;