import{createRequire as s}from"module";import{execFileSync as n}from"child_process";import{join as o}from"path";import{existsSync as a}from"fs";var c=s(import.meta.url);function l(){if(process.env.MCP_MEMORY_PATH)return process.env.MCP_MEMORY_PATH;try{return c.resolve("@zibby/ui-memory/mcp-server")}catch{return null}}var d={id:"memory",serverName:"memory",allowedTools:["mcp__memory__*"],envKeys:[],description:"Zibby Memory MCP Server (test history, selectors, page model)",async middleware(){try{let{createMemoryMiddleware:e}=await import("@zibby/ui-memory");return e()}catch{return null}},promptFragment:`BEFORE executing browser actions:
- Review any test memory/history above. Prefer selectors proven to work.
- If a previous run failed, avoid the same approach.
- After setup/login completes, navigate directly to the target page instead of clicking through menus.

DURING execution \u2014 when a selector fails and you switch to a fallback:
- Call memory_save_insight IMMEDIATELY with category: selector_tip
- Include: which stableId/selector failed, which fallback worked, and the page URL.

AFTER completing the test, you MUST call memory_save_insight at least once:
- Save any useful finding: reliable selectors, timing quirks, navigation patterns, workarounds.
- Category: selector_tip | timing | navigation | workaround | flaky | general
- Be specific \u2014 future runs will read your insights.`,resolve(){let e=l();if(!e)return console.warn("[memory] @zibby/ui-memory not found \u2014 memory tools disabled for this run"),null;let t=o(process.cwd(),".zibby","memory");if(!a(o(t,".dolt")))return console.warn("[memory] DB/dolt unavailable \u2014 memory tools disabled for this run"),null;try{let r=n("dolt",["sql","-q","SELECT COUNT(*) AS cnt FROM test_runs","-r","json"],{cwd:t,encoding:"utf-8",timeout:5e3}),i=JSON.parse(r.trim()).rows||[];if(!i[0]||i[0].cnt===0)return console.log("[memory] Database empty \u2014 memory tools activate after first completed run"),null}catch(r){return console.warn(`[memory] DB/dolt unavailable \u2014 memory tools disabled for this run (${r.message})`),null}return{command:"node",args:[e,"--db-path",t],description:this.description}},tools:[{name:"memory_get_test_history",description:"Query recent test runs with pass/fail results and timing",input_schema:{type:"object",properties:{specPath:{type:"string",description:"Filter by spec path (substring match)"},limit:{type:"number",description:"Max results (default 10)"}}}},{name:"memory_get_selectors",description:"Query known selectors for a page with stability metrics",input_schema:{type:"object",properties:{pageUrl:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_page_model",description:"Query page structure \u2014 elements, roles, selectors",input_schema:{type:"object",properties:{url:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_navigation",description:"Query known page-to-page transitions",input_schema:{type:"object",properties:{fromUrl:{type:"string",description:"Filter by source URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_save_insight",description:"Save a useful observation for future runs (selector tips, timing, workarounds)",input_schema:{type:"object",properties:{category:{type:"string",enum:["selector_tip","timing","navigation","workaround","flaky","general"],description:"Type of insight"},content:{type:"string",description:"The insight text \u2014 be specific and actionable"},specPath:{type:"string",description:"Related spec path"},sessionId:{type:"string",description:"Current session ID"}},required:["category","content"]}}]};export{d as memorySkill};
