|
|
|
${c}`}var db=new Set([".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".pyw",".go",".rs",".rb",".java",".cs",".cpp",".cc",".cxx",".c",".h",".hpp",".hh",".swift",".kt",".kts",".php",".vue",".svelte",".ex",".exs",".lua",".scala",".sc",".sh",".bash",".zsh",".hs",".zig",".css",".scss",".toml",".yml",".yaml",".sql",".md",".mdx"]),oj=new Set(["node_modules",".git","dist","build",".next","__pycache__",".venv","venv","env",".env","target","vendor",".cache",".turbo","coverage",".nyc_output",".claude",".smart-file-read"]),ij=512*1024;async function*pb(e,t,r=20,n){if(r<=0)return;let o;try{o=await(0,Cn.readdir)(e,{withFileTypes:!0})}catch{return}for(let i of o){if(i.name.startsWith(".")&&i.name!=="."||oj.has(i.name))continue;let a=(0,Ri.join)(e,i.name);if(i.isDirectory())yield*pb(a,t,r-1,n);else if(i.isFile()){let s=i.name.slice(i.name.lastIndexOf("."));(db.has(s)||n&&n.has(s))&&(yield a)}}}async function aj(e){try{let t=await(0,Cn.stat)(e);if(t.size>ij||t.size===0)return null;let r=await(0,Cn.readFile)(e,"utf-8");return r.slice(0,1e3).includes("\0")?null:r}catch{return null}}async function fb(e,t,r={}){let n=r.maxResults||20,o=t.toLowerCase(),i=o.split(/[\s_\-./]+/).filter(x=>x.length>0),a=r.projectRoot||e,s=Ni(a),c=new Set;for(let x of Object.values(s.grammars))for(let b of x.extensions)db.has(b)||c.add(b);let u=[];for await(let x of pb(e,e,20,c.size>0?c:void 0)){if(r.filePattern&&!(0,Ri.relative)(e,x).toLowerCase().includes(r.filePattern.toLowerCase()))continue;let b=await aj(x);b&&u.push({absolutePath:x,relativePath:(0,Ri.relative)(e,x),content:b})}let l=cb(u,a),d=[],p=[],f=0;for(let[x,b]of l){f+=sj(b);let T=tc(x.toLowerCase(),i)>0,Ve=[],We=(Zn,qr)=>{for(let ye of Zn){let rr=0,mt="",Ln=tc(ye.name.toLowerCase(),i);Ln>0&&(rr+=Ln*3,mt="name match"),ye.signature.toLowerCase().includes(o)&&(rr+=2,mt=mt?`${mt} + signature`:"signature match"),ye.jsdoc&&ye.jsdoc.toLowerCase().includes(o)&&(rr+=1,mt=mt?`${mt} + jsdoc`:"jsdoc match"),rr>0&&(T=!0,Ve.push({filePath:x,symbolName:qr?`${qr}.${ye.name}`:ye.name,kind:ye.kind,signature:ye.signature,jsdoc:ye.jsdoc,lineStart:ye.lineStart,lineEnd:ye.lineEnd,matchReason:mt})),ye.children&&We(ye.children,ye.name)}};We(b.symbols),T&&(d.push(b),p.push(...Ve))}p.sort((x,b)=>{let N=tc(x.symbolName.toLowerCase(),i);return tc(b.symbolName.toLowerCase(),i)-N});let h=p.slice(0,n),g=new Set(h.map(x=>x.filePath)),y=d.filter(x=>g.has(x.filePath)).slice(0,n),S=y.reduce((x,b)=>x+b.foldedTokenEstimate,0);return{foldedFiles:y,matchingSymbols:h,totalFilesScanned:u.length,totalSymbolsFound:f,tokenEstimate:S}}function tc(e,t){let r=0;for(let n of t)if(e===n)r+=10;else if(e.includes(n))r+=5;else{let o=0,i=0;for(let a of n){let s=e.indexOf(a,o);s!==-1&&(i++,o=s+1)}i===n.length&&(r+=1)}return r}function sj(e){let t=e.symbols.length;for(let r of e.symbols)r.children&&(t+=r.children.length);return t}function mb(e,t){let r=[];if(r.push(`\u{1F50D} Smart Search: "${t}"`),r.push(` Scanned ${e.totalFilesScanned} files, found ${e.totalSymbolsFound} symbols`),r.push(` ${e.matchingSymbols.length} matches across ${e.foldedFiles.length} files (~${e.tokenEstimate} tokens for folded view)`),r.push(""),e.matchingSymbols.length===0)return r.push(" No matching symbols found."),r.join(`
|
|
|
|
${c}`}var db=new Set([".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".pyw",".go",".rs",".rb",".java",".cs",".cpp",".cc",".cxx",".c",".h",".hpp",".hh",".swift",".kt",".kts",".php",".vue",".svelte",".ex",".exs",".lua",".scala",".sc",".sh",".bash",".zsh",".hs",".zig",".css",".scss",".toml",".yml",".yaml",".sql",".md",".mdx"]),oj=new Set(["node_modules",".git","dist","build",".next","__pycache__",".venv","venv","env",".env","target","vendor",".cache",".turbo","coverage",".nyc_output",".claude",".smart-file-read"]),ij=512*1024;async function*pb(e,t,r=20,n){if(r<=0)return;let o;try{o=await(0,Cn.readdir)(e,{withFileTypes:!0})}catch{return}for(let i of o){if(i.name.startsWith(".")&&i.name!=="."||oj.has(i.name))continue;let a=(0,Ri.join)(e,i.name);if(i.isDirectory())yield*pb(a,t,r-1,n);else if(i.isFile()){let s=i.name.slice(i.name.lastIndexOf("."));(db.has(s)||n&&n.has(s))&&(yield a)}}}async function aj(e){try{let t=await(0,Cn.stat)(e);if(t.size>ij||t.size===0)return null;let r=await(0,Cn.readFile)(e,"utf-8");return r.slice(0,1e3).includes("\0")?null:r}catch{return null}}async function fb(e,t,r={}){let n=r.maxResults||20,o=t.toLowerCase(),i=o.split(/[\s_\-./]+/).filter(x=>x.length>0),a=r.projectRoot||e,s=Ni(a),c=new Set;for(let x of Object.values(s.grammars))for(let b of x.extensions)db.has(b)||c.add(b);let u=[];for await(let x of pb(e,e,20,c.size>0?c:void 0)){if(r.filePattern&&!(0,Ri.relative)(e,x).toLowerCase().includes(r.filePattern.toLowerCase()))continue;let b=await aj(x);b&&u.push({absolutePath:x,relativePath:(0,Ri.relative)(e,x),content:b})}let l=cb(u,a),d=[],p=[],f=0;for(let[x,b]of l){f+=sj(b);let T=tc(x.toLowerCase(),i)>0,Ve=[],We=(Zn,qr)=>{for(let ye of Zn){let rr=0,mt="",Ln=tc(ye.name.toLowerCase(),i);Ln>0&&(rr+=Ln*3,mt="name match"),ye.signature.toLowerCase().includes(o)&&(rr+=2,mt=mt?`${mt} + signature`:"signature match"),ye.jsdoc&&ye.jsdoc.toLowerCase().includes(o)&&(rr+=1,mt=mt?`${mt} + jsdoc`:"jsdoc match"),rr>0&&(T=!0,Ve.push({filePath:x,symbolName:qr?`${qr}.${ye.name}`:ye.name,kind:ye.kind,signature:ye.signature,jsdoc:ye.jsdoc,lineStart:ye.lineStart,lineEnd:ye.lineEnd,matchReason:mt})),ye.children&&We(ye.children,ye.name)}};We(b.symbols),T&&(d.push(b),p.push(...Ve))}p.sort((x,b)=>{let N=tc(x.symbolName.toLowerCase(),i);return tc(b.symbolName.toLowerCase(),i)-N});let h=p.slice(0,n),g=new Set(h.map(x=>x.filePath)),y=d.filter(x=>g.has(x.filePath)).slice(0,n),S=y.reduce((x,b)=>x+b.foldedTokenEstimate,0);return{foldedFiles:y,matchingSymbols:h,totalFilesScanned:u.length,totalSymbolsFound:f,tokenEstimate:S}}function tc(e,t){let r=0;for(let n of t)if(e===n)r+=10;else if(e.includes(n))r+=5;else{let o=0,i=0;for(let a of n){let s=e.indexOf(a,o);s!==-1&&(i++,o=s+1)}i===n.length&&(r+=1)}return r}function sj(e){let t=e.symbols.length;for(let r of e.symbols)r.children&&(t+=r.children.length);return t}function mb(e,t){let r=[];if(r.push(`\u{1F50D} Smart Search: "${t}"`),r.push(` Scanned ${e.totalFilesScanned} files, found ${e.totalSymbolsFound} symbols`),r.push(` ${e.matchingSymbols.length} matches across ${e.foldedFiles.length} files (~${e.tokenEstimate} tokens for folded view)`),r.push(""),e.matchingSymbols.length===0)return r.push(" No matching symbols found."),r.join(`
|
|
|
|
`)}var hm=require("node:fs/promises"),vb=require("node:fs"),Fr=require("node:path"),_b=require("node:url"),vj={},cj="12.2.0";console.log=(...e)=>{w.error("CONSOLE","Intercepted console output (MCP protocol protection)",void 0,{args:e})};var yb=!1,$b=(()=>{if(typeof __dirname<"u")return __dirname;try{return(0,Fr.dirname)((0,_b.fileURLToPath)(vj.url))}catch{return yb=!0,process.cwd()}})(),gm=(0,Fr.resolve)($b,"worker-service.cjs");function uj(){yb&&((0,vb.existsSync)(gm)||w.error("SYSTEM","mcp-server: dirname resolution failed (both __dirname and import.meta.url are unavailable). Fell back to process.cwd() and the resolved WORKER_SCRIPT_PATH does not exist. This is the actual problem \u2014 the worker bundle is fine, but mcp-server cannot locate it. Worker auto-start will fail until the dirname-resolution path is fixed.",{workerScriptPath:gm,mcpServerDir:$b}))}var hb={search:"/api/search",timeline:"/api/timeline"};async function mm(e,t){w.debug("SYSTEM","\u2192 Worker API",void 0,{endpoint:e,params:t});try{let r=new URLSearchParams;for(let[a,s]of Object.entries(t))s!=null&&r.append(a,String(s));let n=`${e}?${r}`,o=await Ys(n);if(!o.ok){let a=await o.text();throw new Error(`Worker API error (${o.status}): ${a}`)}let i=await o.json();return w.debug("SYSTEM","\u2190 Worker API success",void 0,{endpoint:e}),i}catch(r){return w.error("SYSTEM","\u2190 Worker API error",{endpoint:e},r),{content:[{type:"text",text:`Error calling Worker API: ${r instanceof Error?r.message:String(r)}`}],isError:!0}}}async function Un(e,t){w.debug("HTTP","Worker API request (POST)",void 0,{endpoint:e});try{let r=await Ys(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){let o=await r.text();throw new Error(`Worker API error (${r.status}): ${o}`)}let n=await r.json();return w.debug("HTTP","Worker API success (POST)",void 0,{endpoint:e}),{content:[{type:"text",text:JSON.stringify(n,null,2)}]}}catch(r){return w.error("HTTP","Worker API error (POST)",{endpoint:e},r),{content:[{type:"text",text:`Error calling Worker API: ${r instanceof Error?r.message:String(r)}`}],isError:!0}}}async function lj(){try{return(await Ys("/api/health")).ok}catch(e){return w.debug("SYSTEM","Worker health check failed",{},e),!1}}async function dj(){if(await lj())return!0;w.warn("SYSTEM","Worker not available, attempting auto-start for MCP client"),uj();try{let e=Bf(),t=await B$(e,gm);return t||w.error("SYSTEM","Worker auto-start returned false \u2014 MCP tools that require the worker (search, timeline, get_observations) will fail until the worker is running. Check earlier log lines for the specific failure reason (Bun not found, missing worker bundle, port conflict, etc.)."),t}catch(e){return w.error("SYSTEM","Worker auto-start threw \u2014 MCP tools that require the worker (search, timeline, get_observations) will fail until the worker is running.",void 0,e),!1}}var bb=[{name:"__IMPORTANT",description:`3-LAYER WORKFLOW (ALWAYS FOLLOW):
|
|
|
|
`)}var hm=require("node:fs/promises"),vb=require("node:fs"),Fr=require("node:path"),_b=require("node:url"),vj={},cj="12.2.1";console.log=(...e)=>{w.error("CONSOLE","Intercepted console output (MCP protocol protection)",void 0,{args:e})};var yb=!1,$b=(()=>{if(typeof __dirname<"u")return __dirname;try{return(0,Fr.dirname)((0,_b.fileURLToPath)(vj.url))}catch{return yb=!0,process.cwd()}})(),gm=(0,Fr.resolve)($b,"worker-service.cjs");function uj(){yb&&((0,vb.existsSync)(gm)||w.error("SYSTEM","mcp-server: dirname resolution failed (both __dirname and import.meta.url are unavailable). Fell back to process.cwd() and the resolved WORKER_SCRIPT_PATH does not exist. This is the actual problem \u2014 the worker bundle is fine, but mcp-server cannot locate it. Worker auto-start will fail until the dirname-resolution path is fixed.",{workerScriptPath:gm,mcpServerDir:$b}))}var hb={search:"/api/search",timeline:"/api/timeline"};async function mm(e,t){w.debug("SYSTEM","\u2192 Worker API",void 0,{endpoint:e,params:t});try{let r=new URLSearchParams;for(let[a,s]of Object.entries(t))s!=null&&r.append(a,String(s));let n=`${e}?${r}`,o=await Ys(n);if(!o.ok){let a=await o.text();throw new Error(`Worker API error (${o.status}): ${a}`)}let i=await o.json();return w.debug("SYSTEM","\u2190 Worker API success",void 0,{endpoint:e}),i}catch(r){return w.error("SYSTEM","\u2190 Worker API error",{endpoint:e},r),{content:[{type:"text",text:`Error calling Worker API: ${r instanceof Error?r.message:String(r)}`}],isError:!0}}}async function Un(e,t){w.debug("HTTP","Worker API request (POST)",void 0,{endpoint:e});try{let r=await Ys(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){let o=await r.text();throw new Error(`Worker API error (${r.status}): ${o}`)}let n=await r.json();return w.debug("HTTP","Worker API success (POST)",void 0,{endpoint:e}),{content:[{type:"text",text:JSON.stringify(n,null,2)}]}}catch(r){return w.error("HTTP","Worker API error (POST)",{endpoint:e},r),{content:[{type:"text",text:`Error calling Worker API: ${r instanceof Error?r.message:String(r)}`}],isError:!0}}}async function lj(){try{return(await Ys("/api/health")).ok}catch(e){return w.debug("SYSTEM","Worker health check failed",{},e),!1}}async function dj(){if(await lj())return!0;w.warn("SYSTEM","Worker not available, attempting auto-start for MCP client"),uj();try{let e=Bf(),t=await B$(e,gm);return t||w.error("SYSTEM","Worker auto-start returned false \u2014 MCP tools that require the worker (search, timeline, get_observations) will fail until the worker is running. Check earlier log lines for the specific failure reason (Bun not found, missing worker bundle, port conflict, etc.)."),t}catch(e){return w.error("SYSTEM","Worker auto-start threw \u2014 MCP tools that require the worker (search, timeline, get_observations) will fail until the worker is running.",void 0,e),!1}}var bb=[{name:"__IMPORTANT",description:`3-LAYER WORKFLOW (ALWAYS FOLLOW):
|