@easbot/codebase 0.3.29 → 0.3.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.en.md +55 -1
  2. package/README.md +55 -1
  3. package/dist/chunks/cache-CSRIBDNY.cjs +1 -0
  4. package/dist/chunks/cache-EZ3VLUUC.mjs +1 -0
  5. package/dist/chunks/chunk-3DAM6EZN.cjs +203 -0
  6. package/dist/chunks/chunk-43WAI4Z7.mjs +1 -0
  7. package/dist/chunks/chunk-47LKNS74.mjs +1 -0
  8. package/dist/chunks/chunk-6NYX22KV.cjs +48 -0
  9. package/dist/chunks/{chunk-YJK7F6NJ.cjs → chunk-AARBEAIB.cjs} +22 -22
  10. package/dist/chunks/chunk-D5NDNAKA.cjs +1 -0
  11. package/dist/chunks/chunk-ECMVXJH2.mjs +1 -0
  12. package/dist/chunks/chunk-EH2QTB6S.cjs +37 -0
  13. package/dist/chunks/chunk-ESA2CL57.mjs +37 -0
  14. package/dist/chunks/chunk-ETCTXAXR.mjs +1 -0
  15. package/dist/chunks/{chunk-4XKCGYFF.mjs → chunk-EU2I2AMK.mjs} +22 -22
  16. package/dist/chunks/chunk-FZNMPXUO.mjs +62 -0
  17. package/dist/chunks/chunk-H4VZF3ZQ.mjs +1 -0
  18. package/dist/chunks/chunk-J7Z3MIR7.cjs +1 -0
  19. package/dist/chunks/chunk-KTSR5VPT.mjs +1 -0
  20. package/dist/chunks/chunk-OUJNWRIY.mjs +48 -0
  21. package/dist/chunks/chunk-QZMJ5EUF.mjs +203 -0
  22. package/dist/chunks/chunk-R32346OA.cjs +1 -0
  23. package/dist/chunks/chunk-VXLUR7M5.cjs +62 -0
  24. package/dist/chunks/chunk-VZCOLSBF.cjs +1 -0
  25. package/dist/chunks/chunk-W5SMGCKO.cjs +1 -0
  26. package/dist/chunks/chunk-Y7JDLK56.cjs +1 -0
  27. package/dist/chunks/cli-handler-7HKSS3UW.mjs +1 -0
  28. package/dist/chunks/cli-handler-OU2TC2SB.cjs +1 -0
  29. package/dist/chunks/code-base-OBQSRCQ3.mjs +1 -0
  30. package/dist/chunks/code-base-WZ3L5IE5.cjs +1 -0
  31. package/dist/chunks/database-manager-T43UZZ45.cjs +1 -0
  32. package/dist/chunks/database-manager-ZC46AHSS.mjs +1 -0
  33. package/dist/chunks/file-watcher-GUS2OVZU.cjs +1 -0
  34. package/dist/chunks/file-watcher-RAO72GUL.mjs +1 -0
  35. package/dist/chunks/{interfaces-S7TJGWWS.mjs → interfaces-UUDPRWI6.mjs} +1 -1
  36. package/dist/chunks/interfaces-YGSG2MI4.cjs +1 -0
  37. package/dist/chunks/llm-NWYEBR5K.mjs +1 -0
  38. package/dist/chunks/llm-UYBJKQ3S.cjs +1 -0
  39. package/dist/chunks/{stdio-server-DFKFFRSM.cjs → stdio-server-37QG6AO2.cjs} +2 -2
  40. package/dist/chunks/stdio-server-QAEXVFSI.mjs +30 -0
  41. package/dist/cli.cjs +1 -1
  42. package/dist/cli.mjs +1 -1
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.d.cts +149 -41
  45. package/dist/index.d.ts +149 -41
  46. package/dist/index.mjs +1 -1
  47. package/package.json +10 -11
  48. package/dist/chunks/chunk-23YR2LAM.cjs +0 -1
  49. package/dist/chunks/chunk-2YMB6W5S.mjs +0 -1
  50. package/dist/chunks/chunk-3RVRPGJC.mjs +0 -1
  51. package/dist/chunks/chunk-3UGOMK4F.cjs +0 -62
  52. package/dist/chunks/chunk-5M2N7JFP.cjs +0 -1
  53. package/dist/chunks/chunk-A4YJ5ZVE.cjs +0 -203
  54. package/dist/chunks/chunk-J7AIRI5N.mjs +0 -203
  55. package/dist/chunks/chunk-LLO6DDXU.mjs +0 -48
  56. package/dist/chunks/chunk-LQVKXVBS.mjs +0 -51
  57. package/dist/chunks/chunk-LZLPJAB6.mjs +0 -62
  58. package/dist/chunks/chunk-M2YU5LAI.cjs +0 -1
  59. package/dist/chunks/chunk-MZHDSOD7.mjs +0 -1
  60. package/dist/chunks/chunk-OGTQ7MWV.cjs +0 -51
  61. package/dist/chunks/chunk-V6PHJ4DG.cjs +0 -48
  62. package/dist/chunks/cli-handler-B7WPIZRE.cjs +0 -1
  63. package/dist/chunks/cli-handler-EJX27R4Q.mjs +0 -1
  64. package/dist/chunks/code-base-FSOSU46G.mjs +0 -1
  65. package/dist/chunks/code-base-OWYMNEQG.cjs +0 -1
  66. package/dist/chunks/database-manager-7D7NDXJK.mjs +0 -1
  67. package/dist/chunks/database-manager-X4DMAUWC.cjs +0 -1
  68. package/dist/chunks/file-watcher-E2JROVI7.cjs +0 -1
  69. package/dist/chunks/file-watcher-KSLBUUPP.mjs +0 -1
  70. package/dist/chunks/interfaces-URUTHSR2.cjs +0 -1
  71. package/dist/chunks/llm-R2ZLKZDO.cjs +0 -1
  72. package/dist/chunks/llm-U57HNTZO.mjs +0 -1
  73. package/dist/chunks/stdio-server-NV5YAXJD.mjs +0 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easbot/codebase",
3
- "version": "0.3.29",
3
+ "version": "0.3.36",
4
4
  "description": "Code Knowledge Graph SDK for EASBot - Property Graph model for code indexing and querying with Tree-sitter parsing, FTS hybrid search, and incremental updates",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -71,15 +71,14 @@
71
71
  "tree-sitter-scala": "^0.24.0",
72
72
  "tree-sitter-typescript": "^0.23.2",
73
73
  "web-tree-sitter": "^0.26.12",
74
- "xdg-basedir": "^5.1.0",
75
- "zod": "^4.4.3",
76
- "@easbot/database": "0.3.29",
77
- "@easbot/llm": "0.3.29",
78
- "@easbot/mcp": "0.3.29",
79
- "@easbot/local-model-sdk": "0.3.29",
80
- "@easbot/terminal": "0.3.29",
81
- "@easbot/types": "0.3.29",
82
- "@easbot/utils": "0.3.29"
74
+ "zod": "^4.6.7",
75
+ "@easbot/database": "0.3.36",
76
+ "@easbot/llm": "0.3.36",
77
+ "@easbot/mcp": "0.3.36",
78
+ "@easbot/local-model-sdk": "0.3.36",
79
+ "@easbot/terminal": "0.3.36",
80
+ "@easbot/types": "0.3.36",
81
+ "@easbot/utils": "0.3.36"
83
82
  },
84
83
  "devDependencies": {
85
84
  "@types/node": "^25.9.5",
@@ -87,7 +86,7 @@
87
86
  "dotenv": "^17.4.2",
88
87
  "tsup": "^8.5.1",
89
88
  "typescript": "^6.0.3",
90
- "vitest": "^4.1.10"
89
+ "vitest": "^5.0.5"
91
90
  },
92
91
  "engines": {
93
92
  "node": ">=22.22.2"
@@ -1 +0,0 @@
1
- 'use strict';var os=require('os'),utils=require('@easbot/utils'),xdgBasedir=require('xdg-basedir');var o=null,r=null;function I(t){o=t;}function h(){o=null;}function n(){if(o)return o;let t=utils.Filesystem.normalize(os.homedir()),i=xdgBasedir.xdgData??utils.Filesystem.join(t,".local","share");return {Path:{home:t,data:process.env.EASBOT_DATA_PATH?.trim()||utils.Filesystem.join(i,"easbot"),config:process.env.EASBOT_CONFIG_PATH?.trim()||(xdgBasedir.xdgConfig?utils.Filesystem.join(xdgBasedir.xdgConfig,"easbot"):utils.Filesystem.join(t,".config","easbot")),state:process.env.EASBOT_STATE_PATH?.trim()||(xdgBasedir.xdgState??utils.Filesystem.join(i,"easbot","state")),cache:process.env.EASBOT_CACHE_PATH?.trim()||(xdgBasedir.xdgCache?utils.Filesystem.join(xdgBasedir.xdgCache,"easbot"):utils.Filesystem.join(t,".cache","easbot")),log:process.env.EASBOT_LOG_PATH?.trim()||(xdgBasedir.xdgState??utils.Filesystem.join(i,"easbot","log")),bin:process.env.EASBOT_BIN_PATH?.trim()||utils.Filesystem.join(t,".local","bin")}}}function j(t){r=t;}function x(){r=null;}function g(){if(r)return r;let t=utils.Filesystem.normalize(process.cwd());return {directory:t,worktree:t}}function l(){return n().Path.home||utils.Filesystem.normalize(os.homedir())}function d(){let t=n().Path.data;return t||(xdgBasedir.xdgData??utils.Filesystem.join(l(),".local","share"))}function T(){let t=n().Path.config;return t||(xdgBasedir.xdgConfig??utils.Filesystem.join(l(),".config"))}function _(){let t=n().Path.state;return t||(xdgBasedir.xdgState??utils.Filesystem.join(d(),"state"))}function P(){let t=n().Path.cache;return t||(xdgBasedir.xdgCache??utils.Filesystem.join(l(),".cache"))}function v(){return utils.Filesystem.normalize(g().directory||process.cwd())}exports.a=I;exports.b=h;exports.c=n;exports.d=j;exports.e=x;exports.f=g;exports.g=l;exports.h=d;exports.i=T;exports.j=_;exports.k=P;exports.l=v;
@@ -1 +0,0 @@
1
- import i from'path';import {fileURLToPath}from'url';var m=Object.defineProperty;var r=(e,t,o)=>t in e?m(e,t,{enumerable:true,configurable:true,writable:true,value:o}):e[t]=o;var c=(e,t,o)=>r(e,typeof t!="symbol"?t+"":t,o);var a=()=>fileURLToPath(import.meta.url),p=()=>i.dirname(a()),_=p();export{c as a,_ as b};
@@ -1 +0,0 @@
1
- import {a}from'./chunk-2YMB6W5S.mjs';import {existsSync,readFileSync,promises}from'fs';import {isAbsolute,normalize,join}from'path';import {createRequire}from'module';import {Log,Ignore,errorMeta,NameErrors,PKG,Shell}from'@easbot/utils';var o=Log.create({service:"codebase-file-watcher"});function A(){return process.env.EASBOT_CACHE_PATH||join(process.cwd(),".easbot","cache")}var C=["node_modules/**",".git/**","dist/**","build/**","__pycache__/**","*.min.js","*.min.ts",".easbot/**",".codebase/**"],s=class s{constructor(){a(this,"wrapper",null);a(this,"error",null);}static get(){return s.instance||(s.instance=new s),s.instance}static clearCache(){s.instance&&(s.instance.wrapper=null,s.instance.error=null);}};a(s,"instance",null);var b=s;function R(){let r=process.platform==="linux"?`-${globalThis.EASBOT_LIBC||"glibc"}`:"";return `@parcel/watcher-${process.platform}-${process.arch}${r}`}async function T(){let r=b.get();if(r.wrapper)return r.wrapper;if(r.error)throw new NameErrors.OperationFailedError({message:r.error,operation:"parcel-watcher-binding-cache"});let e=R(),t=A(),i;try{await $(e,t)?i=join(t,"node_modules",e):(o.info("Parcel watcher binding not found, attempting to install",{binding:e,cachePath:t}),i=await q(e,t));}catch(u){let p=errorMeta(u).message,f=`binding "${e}" not found and auto-install failed. Run manually: pnpm install ${e}. Error: ${p}`;throw r.error=f,o.error("failed to install parcel watcher binding",{error:errorMeta(u),binding:e}),new NameErrors.OperationFailedError({message:f,operation:"parcel-watcher-binding-install"})}o.info("Loading Parcel watcher binding",{binding:e,modulePath:i});let{createWrapper:g}=await import('@parcel/watcher/wrapper.js'),l=createRequire(join(i,"package.json"))(e),c=g(l);return r.wrapper=c,c}async function $(r,e){try{return !!await PKG.resolve(r,void 0,{extraPaths:[e]})}catch{return false}}async function q(r,e){return o.info("Installing Parcel watcher binding",{binding:r,cachePath:e}),await Shell.install(r,"latest",e),join(e,"node_modules",r)}function P(){return process.platform==="darwin"?"fs-events":process.platform==="linux"?"inotify":process.platform==="win32"?"windows":"brute-force"}var v=class{constructor(e){a(this,"workspaceDir");a(this,"backendOpt");a(this,"ignorePatterns");a(this,"onLoadFailure");a(this,"ignoreInstance");a(this,"listeners",new Set);a(this,"unsubscribe",null);a(this,"disposed",false);a(this,"running",false);this.workspaceDir=isAbsolute(e.workspaceDir)?e.workspaceDir:normalize(e.workspaceDir),this.backendOpt=e.backend??"auto",this.ignorePatterns=e.ignorePatterns??[...C],this.onLoadFailure=e.onLoadFailure??"throw",this.ignoreInstance=Ignore.create().add(this.ignorePatterns);}getIgnoreInstance(){return this.ignoreInstance}getIgnorePatterns(){return this.ignorePatterns}getActiveBackend(){return this.backendOpt==="auto"?P():this.backendOpt}on(e){return this.listeners.add(e),()=>this.listeners.delete(e)}async start(){if(this.running)return;this.running=true;let e=this.backendOpt==="auto"?P():this.backendOpt;o.info("FileWatcher start",{workspaceDir:this.workspaceDir,backend:e});let t;try{t=await T();}catch(i){if(this.running=false,this.onLoadFailure==="warn")return;throw i}await this.subscribeWithParcel(t,e);}async stop(){if(this.unsubscribe){try{await this.unsubscribe();}catch(e){o.warn("parcel unsubscribe error",{error:errorMeta(e)});}this.unsubscribe=null;}this.running=false;}async dispose(){await this.stop(),this.disposed=true,this.listeners.clear();}isRunning(){return this.running}isDisposed(){return this.disposed}static clearParcelWrapperCache(){b.clearCache();}async subscribeWithParcel(e,t){if(this.disposed)throw new NameErrors.OperationFailedError({message:"FileWatcher disposed before subscribe",operation:"file-watcher-disposed"});let i=(a,l)=>{if(this.disposed)return;let c=this.workspaceDir.replace(/\\/g,"/").replace(/\/$/,""),u=l.replace(/\\/g,"/"),p=l;if(u.startsWith(c+"/")&&(p=u.slice(c.length+1)),this.ignoreInstance.ignores(p,a==="create"&&p.endsWith("/")))return;let f=a==="create"?"add":a==="delete"?"unlink":"change";for(let y of this.listeners)try{y(f,p);}catch(W){o.warn("listener threw",{error:errorMeta(W)});}},g=await e.subscribe(this.workspaceDir,(a,l)=>{if(a){o.error("parcel subscribe callback error",{error:errorMeta(a)});return}for(let c of l)i(c.type,c.path);},{ignore:[...this.ignorePatterns],backend:t});if(this.disposed){await g.unsubscribe().catch(()=>{});return}this.unsubscribe=async()=>{await g.unsubscribe().catch(a=>{o.warn("parcel unsubscribe error",{error:errorMeta(a)});});};}};function m(r){return join(r,".watcher.pid")}function z(r){let e=m(r);if(!existsSync(e))return null;try{let t=readFileSync(e,"utf-8").trim(),i=parseInt(t,10);return Number.isFinite(i)?i:null}catch{return null}}async function K(r,e){let t=m(r);await promises.writeFile(t,String(e),"utf-8");}async function U(r){let e=m(r);try{await promises.unlink(e);}catch{}}export{v as a,m as b,z as c,K as d,U as e};
@@ -1,62 +0,0 @@
1
- 'use strict';var chunkA4YJ5ZVE_cjs=require('./chunk-A4YJ5ZVE.cjs'),chunkYJK7F6NJ_cjs=require('./chunk-YJK7F6NJ.cjs'),utils=require('@easbot/utils'),types=require('@easbot/types'),fs=require('fs');var J=utils.Log.create({service:"codebase-service"}),N=utils.Filesystem.toUnixPath;function xe(e,t){let r={exact:1,qualified:.85,substring:.5}[e];return t?Math.min(1,r+.2):r}function Ne(e,t){if(!t)return false;if(e===t)return true;let r=e.split(/[/\\]/).pop()??"",o=t.split(/[/\\]/).pop()??"";return !!(r&&o&&r===o||t.includes("/")&&e.endsWith("/"+t))}async function T(e,t,r){if(r.nodeId){let i=e.getNode(r.nodeId);if(!i)throw new utils.ServiceError({code:"NOT_FOUND",message:`Node not found: nodeId=${r.nodeId}`,details:{name:r.nodeId}});return {node:i,candidates:[]}}if(!r.name)throw new utils.ServiceError({code:"NOT_FOUND",message:"Either name or nodeId is required",details:{...r}});let l=e.getDatabase().findNodesByName({name:r.name,file:r.file,kind:r.kind,limit:50});if(l.length===0)throw new utils.ServiceError({code:"NOT_FOUND",message:`Node not found: ${r.name}`,details:{name:r.name,candidates:[]}});let a=!!r.file,c=r.file?N(r.file):null,s=l.map(i=>{let m=c?Ne(N(i.node.file_path),c):false;return {node:i.node,score:xe(i.matchKind,m),matchKind:i.matchKind,inFile:m}});if(s.sort((i,m)=>m.score-i.score),s.length===1)return {node:s[0].node,candidates:s.map(i=>({node:i.node,score:i.score}))};let d=s[0].score,n=s.filter(i=>i.score===d);if(n.length===1)return {node:n[0].node,candidates:s.slice(0,10).map(i=>({node:i.node,score:i.score}))};if(a&&n.length>1){let i=n.filter(m=>m.inFile);if(i.length===1)return {node:i[0].node,candidates:s.slice(0,10).map(m=>({node:m.node,score:m.score}))}}throw new utils.ServiceError({code:"AMBIGUOUS",message:`Ambiguous name "${r.name}" \u2014 ${s.length} candidates`,details:{name:r.name,candidates:s.slice(0,10).map(i=>({node:i.node,score:i.score}))}})}async function P(e){let t=chunkA4YJ5ZVE_cjs.c(e.rootDir),r=new chunkA4YJ5ZVE_cjs.x({workspaceDir:e.workspaceDir,database:{path:t,walMode:true},embedding:types.DEFAULT_EMBEDDING_CONFIG,indexer:types.DEFAULT_INDEXER_CONFIG,parser:types.DEFAULT_PARSER_CONFIG,search:types.DEFAULT_SEARCH_CONFIG,sync:{onBoot:false,onSearch:false,onSessionStart:false,intervalMs:0}});return await r.initialize(),r}function U(e,t,r,o){let l=r.map(()=>"?").join(","),a=t.name.split("@")[0]??t.name,c=a.includes(".")?a.split(".").pop()??a:a,s=new Set([`${t.language}:*:*:${a}`]);c!==a&&s.add(`${t.language}:*:*:${c}`);let d=[];c!==a&&d.push(`${t.language}:*:*:%${c}`);let n=Array.from(s),i=n.map(()=>"?").join(","),u=d.length>0?"OR LOWER(target) LIKE LOWER(?)":"";n.length>1&&J.warn("queryIncomingEdgesWithWildcard: multi-variant wildcards (bare+namespaced)",{rootName:t.name,wildcards:n,hint:"\u540C\u540D\u540C namespace \u4E0D\u540C file \u7684\u65B9\u6CD5\u53EF\u80FD\u90FD\u88AB\u547D\u4E2D\uFF0CLLM \u63A8\u7406\u8BF7\u7528 file \u8FC7\u6EE4\u8F85\u4F50"});let g=`
2
- SELECT id, source, target, relation, created_at FROM edges
3
- WHERE relation IN (${l})
4
- AND source != target
5
- AND (
6
- target = ?
7
- OR target IN (${i})
8
- ${u}
9
- )
10
- GROUP BY id
11
- LIMIT ?
12
- `;return e.queryAll(g,[...r,t.id,...n,...d,o])}function Pe(e){return e==="class_declaration"||e==="class_definition"||e==="interface_declaration"||e==="struct_declaration"||e==="struct_specifier"||e==="record_declaration"}function Re(e,t,r,o,l){let c=e.queryAll("SELECT id FROM nodes WHERE file_path = ? AND start_line >= ? AND end_line <= ? AND ast_type IN ('method_definition', 'method_declaration') LIMIT 1000",[t.file_path,t.start_line,t.end_line]).map(n=>n.id),s=new Set,d=[];for(let n of r)n.id&&!s.has(n.id)&&(s.add(n.id),d.push(n));if(c.length>0){let n=o.map(()=>"?").join(","),i=c.map(()=>"?").join(","),m=`
13
- SELECT id, source, target, relation, created_at FROM edges
14
- WHERE relation IN (${n})
15
- AND source != target
16
- AND source IN (${i})
17
- GROUP BY id
18
- LIMIT ?
19
- `,u=e.queryAll(m,[...o,...c,l]);for(let g of u)g.id&&!s.has(g.id)&&(s.add(g.id),d.push(g));}return d.slice(0,l)}function Z(e,t,r,o){let a=`
20
- SELECT id, source, target, relation, created_at FROM edges
21
- WHERE relation IN (${r.map(()=>"?").join(",")})
22
- AND source != target
23
- AND source = ?
24
- LIMIT ?
25
- `;return e.queryAll(a,[...r,t.id,o])}function ee(e,t,r,o){let l=o==="in"?e.source:e.target;t.id;let c=r.getNodeById(l);if(!c&&l.includes(":*:")){let s=l.split(":").pop()??l,d=s.split("@")[0]??s;if(d&&d!==l){let n=r.findNodesByName({name:d}),i=t.file_path??"",m=i.split(/[/\\]/).pop()??"",u=i.split(/[/\\]/).filter(Boolean),g=n.find(p=>p.node.file_path?p.node.file_path===i:false)??n.find(p=>!p.node.file_path||!m?false:p.node.file_path.split(/[/\\]/).pop()===m)??n.find(p=>{if(!p.node.file_path)return false;let f=p.node.file_path.split(/[/\\]/).filter(Boolean);return u.length<2||f.length<2?false:u[0]===f[0]&&u[1]===f[1]})??null;g&&(c=g.node);}}if(!c){let s=l.split(":").pop()??l;return {id:l,name:s,astType:"unresolved",filePath:"(unresolved)",startLine:0,relation:e.relation}}return {id:c.id,name:c.name,astType:c.ast_type,filePath:N(c.file_path),startLine:c.start_line??0,relation:e.relation}}async function te(e,t){let r=Date.now(),c=await(await P(e)).getQuery().search(t.query??"",{maxResults:t.maxResults??10,language:t.language,filePath:t.file,astType:t.astType,includeEdges:true,enableFts:t.enableFts!==false,enableEmbedding:t.enableEmbedding!==false});if(t.kind){let n=t.kind.toLowerCase();c=c.filter(i=>i.ast_type.includes(n)||i.name.toLowerCase().includes(n));}if(t.file){let n=N(t.file);c=c.filter(i=>N(i.file_path).endsWith(n)||N(i.file_path).includes(n));}let s=t.maxEdgesPerNode??10,d=c.map(n=>({nodeId:n.id,name:n.name,kind:n.ast_type??"unknown",filePath:N(n.file_path),startLine:n.start_line,endLine:n.end_line,edges:(n.edges??[]).slice(0,s),source:"basic",score:0,snippet:(n.text??"").slice(0,200).replace(/\s+/g," ").trim()}));return {total:d.length,hits:d,durationMs:Date.now()-r,truncated:false}}async function Se(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t),c=[];if(t.includeEdges){let s=t.maxEdgesPerNode??10,d=["CALLS","IMPORTS","TYPE_REFERENCES","EXTENDS","IMPLEMENTS","HAS_METHOD","HAS_PROPERTY","METHOD_OVERRIDES"],n=U(l,a,d,s+1),i=Z(l,a,d,s+1),m=new Set,u=[];for(let g of [...n,...i])g.id&&!m.has(g.id)&&(m.add(g.id),u.push(g));c=u.slice(0,s);}return {node:a,edges:c}}var Ce=["CALLS","IMPORTS","TYPE_REFERENCES","EXTENDS","IMPLEMENTS","HAS_METHOD","HAS_PROPERTY","METHOD_OVERRIDES"];async function Ie(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t);if(!a)return {root:null,nodes:[],edges:[],truncated:false,totalNodes:0,totalEdges:0};let c=t.depth??2,s=t.maxNodes??100,d=t.direction??"both";t.maxEdgesPerNode??10;let i=new Map,m=[{nodeId:a.id,depth:0}];i.set(a.id,0);let u=[],g=false;for(;m.length>0;){let h=m.shift();if(h.depth>=c)continue;if(i.size>=s){g=true;break}let F=o.queryNeighbors(h.nodeId,{direction:d,relationTypes:t.relationTypes??Ce,limit:s-i.size+1});for(let y of F.edges){u.push(y);let I=y.source===h.nodeId?y.target:y.source;if(!i.has(I)&&(i.set(I,h.depth+1),m.push({nodeId:I,depth:h.depth+1}),i.size>=s)){g=true;break}}if(g)break}let p=new Set,f=[];for(let h of u)!h.id||p.has(h.id)||(p.add(h.id),f.push(h));let b=Array.from(i.keys()),E=b.length>0?l.queryNodes({ids:b}):[],C=new Map(E.map(h=>[h.id,h])),x=[];for(let[h,F]of i.entries()){let y=C.get(h);y&&x.push({node:y,depth:F});}return {root:a,nodes:x,edges:f,truncated:g,totalNodes:x.length,totalEdges:u.length}}var Le=["CALLS","IMPORTS","TYPE_REFERENCES"];async function Te(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t);if(!a)return {root:null,totalImpacted:0,buckets:[]};let c=t.depth??2,s=t.maxResults??10,d=t.relationTypes??Le,n=t.maxEdgesPerNode??10,i=new Set([a.id]),m=[],u=[a.id];for(let g=1;g<=c&&!(u.length===0||i.size-1>=s);g++){let p=U(l,a,d,n+1),f=[],b=new Set;for(let E of p)if(!i.has(E.source)&&!b.has(E.source)&&(b.add(E.source),i.add(E.source),f.push(E.source),i.size-1>=s))break;if(f.length>0){let E=f.slice(0,10),C=l.queryNodes({ids:E}),x=new Map(C.map(y=>[y.id,y])),h=new Map;for(let y of p)h.has(y.source)||h.set(y.source,y.relation);let F=E.map(y=>{let I=x.get(y);return {id:y,name:I?.name??"(unknown)",filePath:I?N(I.file_path):"(unknown)",relation:h.get(y)??"CALLS"}});m.push({depth:g,count:f.length,sample:F});}u=f;}return m.length===0&&J.warn("impact: no incoming edges found",{root:a.name,depth:c,relationTypes:d}),{root:a,totalImpacted:i.size-1,buckets:m}}var ne=["CALLS","IMPORTS","TYPE_REFERENCES","EXTENDS","IMPLEMENTS","METHOD_OVERRIDES"];async function $e(e,t){return re(e,t)}async function _e(e,t){return oe(e,t)}async function re(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t);if(!a)return {root:null,callers:[],truncated:false};let c=t.maxResults??10,s=t.maxEdgesPerNode??c,d=t.relationTypes??ne,n=U(l,a,d,s+1),i=[];for(let u of n){let g=ee(u,a,l,"in");g&&i.push(g);}let m=i.length>c;return {root:a,callers:m?i.slice(0,c):i,truncated:m}}async function oe(e,t){let r=await P(e),o=r.getQuery(),l=r.getDatabase(),{node:a}=await T(o,e,t);if(!a)return {root:null,callees:[],truncated:false};let c=t.maxResults??10,s=t.maxEdgesPerNode??c,d=t.relationTypes??ne,n=Z(l,a,d,s+1),i=Pe(a.ast_type)?Re(l,a,n,d,s+1):n,m=[];for(let g of i){let p=ee(g,a,l,"out");p&&m.push(p);}let u=m.length>c;return {root:a,callees:u?m.slice(0,c):m,truncated:u}}async function we(e,t){if(!t.query)throw new utils.ServiceError({code:"NOT_FOUND",message:"explore requires a non-empty query",details:{query:t.query}});let o=await P(e),l=o.getQuery(),a=o.getDatabase(),s=(await te(e,{query:t.query,file:t.file,kind:t.kind,intent:t.intent,maxResults:t.maxFiles??5,enableFts:true,enableEmbedding:true})).hits;if(t.file||t.kind)try{let u=await T(l,e,{name:t.query,file:t.file,kind:t.kind});if(u?.node){let g={nodeId:u.node.id,name:u.node.name,kind:u.node.ast_type,filePath:N(u.node.file_path),startLine:u.node.start_line,endLine:u.node.end_line,edges:[],source:"basic",score:0,snippet:(u.node.text??"").slice(0,200).replace(/\s+/g," ").trim()},p=s.filter(f=>f.nodeId!==g.nodeId);s=[g,...p];}}catch{}let d=new Map;for(let u of s){let g=N(u.filePath),p=d.get(g);p?p.push(u):d.set(g,[u]);}let n=t.maxSymbols??3,i=t.maxEdgesPerNode??10,m=[];for(let[u,g]of d){let p=g.slice(0,n),f=[];for(let b of p){let E=await re(e,{name:b.name,file:u,kind:t.kind,maxResults:i,maxEdgesPerNode:i}),C=await oe(e,{name:b.name,file:u,kind:t.kind,maxResults:i,maxEdgesPerNode:i});f.push({node:(()=>{let x={id:b.nodeId,name:b.name,ast_type:b.kind,language:"ts",file_path:b.filePath,start_line:b.startLine??0,end_line:b.endLine??0};try{let h=a.getNodeById(b.nodeId);return {...x,text:h?.text??""}}catch{return {...x,text:""}}})(),callers:E.callers,callees:C.callees});}m.push({file:u,symbols:f});}return {query:t.query,entryPoints:m,totalHits:s.length}}async function Fe(e,t){let o=await(await P(e)).getStatus();o.package="codebase",o.workspaceDir=e.workspaceDir;let l=chunkA4YJ5ZVE_cjs.b(e.workspaceDir),a=fs.existsSync(l),c=fs.existsSync(o.dbPath),s;if(c)try{s=fs.statSync(o.dbPath).size;}catch{}o.configPath=l,o.configExists=a,o.dbExists=c,o.dbSize=s,o.vectorEnabled=o.meta?.vector_enabled==="true"||o.meta?.vector_enabled==="1";let d=o.meta?.embeddingDims;d&&Number.isFinite(Number.parseInt(d,10))&&(o.embeddingDims=Number.parseInt(d,10));let n={initialized:false,capabilities:{embedding:false,graphLlm:false}};try{let{Llm:i}=await import('./llm-R2ZLKZDO.cjs');if(i.isInitialized()){n.initialized=!0;let m=i.capabilities();n.capabilities={embedding:m.embedding===!0,graphLlm:m.graphLlm===!0},n.embeddingModel=n.capabilities.embedding?"configured":void 0,n.graphModel=n.capabilities.graphLlm?"configured":void 0;}}catch{}o.llm=n;try{let{DatabaseManager:i}=await import('./database-manager-X4DMAUWC.cjs'),m=new i(o.dbPath);try{let{stats:u}=m.checkIntegrity();o.dbStats=u,o.ftsAvailable=m.isFtsAvailable();}finally{m.close();}}catch{}return o}async function Ae(e,t){return await(await P(e)).healthCheck()}var ke=utils.Log.create({service:"codebase-service-init"}),se=false;async function ve(){se||(se=true,ke.info("codebase service init"),await utils.ServiceErrorBus.init(),await chunkYJK7F6NJ_cjs.e());}var ie=utils.Filesystem.toUnixPath;function He(e){let t=e.text??"";if(!t)return false;let r=t.slice(0,80);return /\bexport\s/.test(r)||/\bpublic\s/.test(r)?true:(false)}function qe(e){let t=e.text??"";if(!t)return [];let r=t.slice(0,80),o=[];return /\basync\s/.test(r)&&o.push("async"),/\bstatic\s/.test(r)&&o.push("static"),/\babstract\s/.test(r)&&o.push("abstract"),/\breadonly\s/.test(r)&&o.push("readonly"),/\bconst\s/.test(r)&&o.push("const"),/\blet\s/.test(r)&&o.push("let"),o}function R(e){return {id:e.id,name:e.name,astType:e.ast_type,language:e.language,filePath:ie(e.file_path),startLine:e.start_line??0,endLine:e.end_line??0,isExported:He(e),modifiers:qe(e)}}function $(e,t){return {id:e.id,source:e.source,target:e.target,relation:e.relation,direction:t}}function z(e){return e.map(t=>({node:{id:t.nodeId,name:t.name,astType:t.kind,language:"typescript",filePath:ie(t.filePath),startLine:t.startLine??0,endLine:t.endLine??0,isExported:false,modifiers:[]},source:t.source,score:t.score,snippet:(t.snippet??"").slice(0,200),edges:(t.edges??[]).slice(0,10).map(r=>$({...r}))}))}function K(){return {id:"",name:"",astType:"",language:"",filePath:"",startLine:0,endLine:0,isExported:false,modifiers:[]}}var ze=utils.Log.create({service:"codebase-format-truncate"}),j="**`",Ke="**",le=24e3,de=25e3;async function D(e,t={}){let r=t.softLimit??le,o=t.hardCeiling??de,l=t.toolName??"codebase",a=t.writeToDisk!==false;if(e.length<=r)return {content:e,truncated:false};let c=e.slice(0,o),s=c.lastIndexOf(`
26
- ${j}`),d=c.lastIndexOf(`
27
- `),n;s>o*.5?n=s:d>0?n=d:n=-1;let i=n>0?c.slice(0,n):c,u=i+"\n\n... (output truncated to budget; the source above is complete and verbatim \u2014 treat it as already Read. For any area not covered, make ANOTHER `<tool>` targeting those names \u2014 do NOT Read these files.)";if(!a)return {content:u,truncated:true,outputPath:"",hint:"Use Grep/Read to inspect the truncated sections.",info:`... ${e.length-i.length}/${e.length} characters truncated ...`};try{let g=await utils.TruncateContent.truncate(e,{maxChars:i.length,direction:"head",label:`${l}-output`});return g.truncated?{content:u,truncated:!0,outputPath:g.outputPath,hint:utils.TruncateContent.formatHint(g),info:`... ${g.removedLength}/${g.originalLength} characters truncated ...`}:{content:u,truncated:!0,outputPath:"",hint:"Use Grep/Read to inspect the truncated sections.",info:`... ${e.length-i.length}/${e.length} characters truncated ...`}}catch(g){return ze.warn("TruncateContent.truncate failed, returning without disk hint",{error:utils.errorMeta(g)}),{content:u,truncated:true,outputPath:"",hint:"Use Grep/Read to inspect the truncated sections.",info:`... ${e.length-i.length}/${e.length} characters truncated ...`}}}function O(e,t={}){let r=t.softLimit??le,o=t.hardCeiling??de;if(e.length<=r)return {content:e,truncated:false};let l=e.slice(0,o),a=l.lastIndexOf(`
28
- ${j}`),c=l.lastIndexOf(`
29
- `),s;a>o*.5?s=a:c>0?s=c:s=-1;let d=s>0?l.slice(0,s):l;return {content:d+`
30
-
31
- ... (output truncated; tail dropped at section boundary)`,truncated:true,outputPath:"",hint:"",info:`... ${e.length-d.length}/${e.length} characters truncated ...`}}function je(e,t=Date.now()){let r=Math.max(0,Math.floor((t-e)/1e3));return r>60?">60s ago":`${r}s ago`}function k(e,t){if(!e||e.length===0)return null;let r=e.filter(l=>t.has(l.path));return r.length===0?null:`\u26A0\uFE0F Index may be stale for: ${r.map(l=>`${l.path} (edited ${je(l.lastEventAt)})`).join(", ")}
32
-
33
- `}function A(e,t,r={}){return (ce[e]??ce.default).replace(/<(\w+)>/g,(l,a)=>a==="tool"?t:r[a]??`<${a}>`)}var ce={search:`---
34
-
35
- > **Complete source for N files is included above \u2014 do NOT re-read them.**
36
- > If your question also needs files/symbols listed under "Not shown above" (or any area this call didn't cover), make ANOTHER \`<tool>\` targeting those names \u2014 it returns the same source with line numbers and is cheaper and more complete than reading.`,impact:"---\n\n> **Risk: <riskLevel>**. Before editing `<root>`, review d=1 first \u2014 those WILL BREAK.\n> Use `<tool>` to read full source of any direct caller.",context:"---\n\n> **Use `impact` for blast-radius analysis. Use `explore` to read source.**",default:`---
37
-
38
- > **Output truncated to budget; the content above is the source of truth.**
39
- > For more detail, call \`<tool>\` with refined parameters.`};async function v(e,t){let{pendingFiles:r,toolName:o,sync:l=false}=t;if(e.length===0)return _(o,"No matches found.","Try broader search terms, or use `explore` to read source.");let a=Ge(e),c=new Set(a.keys()),s=[];s.push(k(r,c)??"");let d="[[codebase-search-summary]]";s.push(d+`
40
- `);let n=e.length;s.push(`**Files with matches:** ${a.size}
41
- `);for(let[g,p]of a){let f=p.map(x=>x.node.name),b=f.slice(0,5).join(", "),E=f.length>5?`, +${f.length-5} more`:"";s.push(`**\`${g}\`** \u2014 ${b}${E}
42
- `);let C=p[0]?.node.language??"";s.push("```"+C);for(let x of p)s.push(`L${x.node.startLine} ${x.snippet}`);s.push("```\n");}s.push(A("search",o,{}));let i=s.join(`
43
- `),m=`Found ${n} symbol${n===1?"":"s"} across ${a.size} file${a.size===1?"":"s"}.`,u=i.replace(d,m);return w(u,t,l)}async function M(e,t,r){let{pendingFiles:o,toolName:l,sync:a=false}=r;if(t.length===0||t.every(n=>n.count===0))return _(l,`No incoming edges for \`${e.name}\`.`,"This symbol has no callers \u2014 safe to refactor.");let c=t.reduce((n,i)=>n+i.count,0),s=We(c),d=[];d.push(k(o,new Set([e.filePath]))??""),d.push(`**Impact for \`${e.name}\`** (root: ${e.filePath}:${e.startLine}, total impacted: ${c})
44
- `);for(let n of t){d.push(`- **d=${n.depth}** (${n.count} nodes) \u2014 ${n.riskLabel}`);for(let i of n.samples.slice(0,5))d.push(` - \`${i.name}\` ${i.file}:${i.line} [${i.relation}]`);n.samples.length>5&&d.push(` - ... and ${n.samples.length-5} more`);}return d.push(A("impact",l,{root:e.name,riskLevel:s})),w(d.join(`
45
- `),r,a)}function We(e){return e>=100?"CRITICAL":e>=50?"HIGH":e>=10?"MEDIUM":"LOW"}function W(e){return e===1?"WILL BREAK (direct callers)":e===2?"LIKELY AFFECTED (indirect)":"MAY NEED TESTING (transitive)"}async function G(e,t){let{root:r,incoming:o,outgoing:l,neighbors:a}=e,{pendingFiles:c,toolName:s,sync:d=false}=t;if(o.length===0&&l.length===0&&a.length===0)return _(s,`No relations found for \`${r.name}\`.`,"This is a leaf node.");let n=[];n.push(k(c,new Set([r.filePath]))??""),n.push(`**Context for \`${r.name}\`** (${r.astType}, ${r.language}, ${r.filePath}:${r.startLine})
46
- `),n.push(`**Incoming** (${o.length}):`);for(let i of o.slice(0,10))n.push(`- ${i.source} \u2192 [${i.relation}] \u2192 \`${r.name}\``);o.length>10&&n.push(`- ... and ${o.length-10} more`),n.push(""),n.push(`**Outgoing** (${l.length}):`);for(let i of l.slice(0,10))n.push(`- \`${r.name}\` \u2192 [${i.relation}] \u2192 ${i.target}`);if(l.length>10&&n.push(`- ... and ${l.length-10} more`),n.push(""),a.length>0){n.push(`**Neighbors** (${a.length}):`);for(let i of a.slice(0,20))n.push(`- [d=${i.depth}] \`${i.node.name}\` (${i.node.astType}) ${i.node.filePath}:${i.node.startLine}`);a.length>20&&n.push(`- ... and ${a.length-20} more`),n.push("");}return n.push(A("context",s,{})),w(n.join(`
47
- `),t,d)}async function H(e,t,r){let{pendingFiles:o,toolName:l,sync:a=false}=r;if(!e.id)return _(l,"Node not found.","Check the node ID or use `search` to find it.");let c=t.filter(n=>n.direction==="in"),s=t.filter(n=>n.direction==="out"),d=[];d.push(k(o,new Set([e.filePath]))??""),d.push(`**Node: \`${e.name}\`**
48
- `),d.push(`- ID: \`${e.id}\``),d.push(`- Kind: ${e.astType}`),d.push(`- Language: ${e.language}`),d.push(`- Location: ${e.filePath}:${e.startLine}-${e.endLine}`),d.push(`- Exported: ${e.isExported}`),e.modifiers.length>0&&d.push(`- Modifiers: ${e.modifiers.join(", ")}`),d.push(""),d.push(`**Edges** (incoming: ${c.length} / outgoing: ${s.length}):`);for(let n of c.slice(0,5))d.push(`- \u2190 [${n.relation}] ${n.source}`);for(let n of s.slice(0,5))d.push(`- \u2192 [${n.relation}] ${n.target}`);return t.length>10&&d.push(`- ... and ${t.length-10} more`),d.push(A("default",l,{})),w(d.join(`
49
- `),r,a)}async function q(e,t,r,o,l){let{toolName:a,sync:c=false}=l,s=r==="callers"?"Callers":"Callees",d="of",n=r==="callers"?"Use `node <name>` to read full source of any caller.":"Use `node <name>` to read full source of any callee.",i=t?.name??"?";if(e.length===0)return _(a,`**${s} ${d} \`${i}\`** (0)`,r==="callers"?"This symbol has no callers \u2014 safe to refactor.":"This symbol has no outgoing calls \u2014 leaf node.");let m=[];m.push(`**${s} ${d} \`${i}\`** (${e.length}${o?"+":""})
50
- `);for(let u of e.slice(0,10)){let g=u.filePath==="(unresolved)",p=g?u.filePath:`${u.filePath}:${u.startLine}`,f=g?" _(wildcard)_":"";m.push(`- [${u.relation}] \`${u.name}\` ${p}${f}`);}return e.length>10&&m.push(`- ... and ${e.length-10} more`),m.push(`
51
- ---
52
- > ${n}`),w(m.join(`
53
- `),l,c)}async function ue(e,t){let{entryPoints:r,totalHits:o,query:l}=e,{toolName:a,sync:c=false}=t;if(r.length===0)return _(a,`No matches for \`${l}\`.`,"Try broader search terms, or use `callers` / `callees` to traverse from a known symbol.");let s=[];s.push(`## Code Context
54
- `),s.push(`**Query:** ${l} `),s.push(`**Total hits:** ${o} `),s.push(`**Entry points:** ${r.length}
55
- `);for(let d of r){s.push(`**\`${d.file}\`** \u2014 ${d.symbols.length} symbol${d.symbols.length===1?"":"s"}
56
- `);for(let n of d.symbols){let i=(n.source??"").trim()||"(source not included)",m=n.node.language;if(s.push("```"+m),s.push(`L${n.node.startLine}-L${n.node.endLine} ${n.node.name} (${n.node.astType}${n.node.modifiers.length>0?`, ${n.node.modifiers.join(" ")}`:""})`),s.push(""),s.push(i),s.push("```\n"),n.callers.length>0){s.push(`**Callers of \`${n.node.name}\` (${n.callers.length}):**`);for(let u of n.callers.slice(0,5))s.push(`- [${u.relation}] \`${u.name}\` ${u.filePath}:${u.startLine}`);n.callers.length>5&&s.push(`- ... and ${n.callers.length-5} more`),s.push("");}if(n.callees.length>0){s.push(`**Callees of \`${n.node.name}\` (${n.callees.length}):**`);for(let u of n.callees.slice(0,5))s.push(`- [${u.relation}] \`${u.name}\` ${u.filePath}:${u.startLine}`);n.callees.length>5&&s.push(`- ... and ${n.callees.length-5} more`),s.push("");}}}return s.push(`---
57
- `),s.push(A("context",a,{})),w(s.join(`
58
- `),t,c)}function Ge(e){let t=new Map;for(let r of e){let o=r.node.filePath,l=t.get(o);l?l.push(r):t.set(o,[r]);}return t}function _(e,t,r){return `**${e}**
59
-
60
- ${t}
61
-
62
- > **Tip:** ${r}`}async function w(e,t,r){let o={softLimit:t.softLimit,hardCeiling:t.hardCeiling,toolName:t.toolName,writeToDisk:r?false:t.writeToDisk};return (r?O(e,o):await D(e,o)).content}var Ye=utils.Log.create({service:"codebase-format-render"});async function Ve(e,t){if(e.length===0)return v([],t);let r=z(e);return v(r,t)}async function Xe(e,t,r){if(t.length===0)return M(R(e),[],r);let o=[{depth:1,count:t.length,riskLabel:W(1),samples:t.slice(0,10).map(l=>({name:l.source.name,file:R(l.source).filePath,line:l.source.start_line??0,relation:l.relation}))}];return M(R(e),o,r)}async function Je(e,t,r,o,l){let a=R(e),c=t.map(n=>$(n,"in")),s=r.map(n=>$(n,"out")),d=o.map(n=>({node:R(n),depth:1}));return G({root:a,incoming:c,outgoing:s,neighbors:d},l)}async function Ze(e,t){return q(e.callers,e.root,"callers",e.truncated,t)}async function et(e,t){return q(e.callees,e.root,"callees",e.truncated,t)}async function tt(e,t){let{renderKnowledgeStatus:r}=await import('@easbot/terminal');return r({packageName:"codebase",rootDir:e.workspaceDir,configPath:e.configPath??"",configExists:typeof e.configExists=="boolean"?e.configExists:false,dbPath:e.dbPath,dbExists:typeof e.dbExists=="boolean"?e.dbExists:true,dbSize:e.dbSize,indexState:e.indexState,schemaVersion:(()=>{let o=e.meta?.schema_version;return o&&Number.isFinite(Number.parseInt(o,10))?Number.parseInt(o,10):void 0})(),extractionVersion:e.extractionVersion,lastSyncAt:e.lastSync,vectorEnabled:typeof e.vectorEnabled=="boolean"?e.vectorEnabled:false,embeddingDims:typeof e.embeddingDims=="number"?e.embeddingDims:void 0,llm:e.llm??{initialized:false,capabilities:{}},healthy:e.healthy,dbStats:e.dbStats,extras:(()=>{let o={};if(e.isStale===true&&(o.stale="yes \u2014 reindex recommended"),typeof e.ftsAvailable=="boolean"&&(o.fts_available=e.ftsAvailable?"yes":"no"),e.meta&&typeof e.meta=="object")for(let[l,a]of Object.entries(e.meta))a!=null&&(o[`meta/${l}`]=String(a));return Object.keys(o).length>0?o:void 0})()})}async function nt(e,t,r){if(!e)return H(K(),[],r);let o=R(e),l=t.map(a=>{let c=a.target===e.id?"in":"out";return $(a,c)});return H(o,l,r)}async function rt(e,t){let r={query:e.query,totalHits:e.totalHits,entryPoints:e.entryPoints.map(o=>({file:o.file,symbols:o.symbols.map(l=>({node:R(l.node),source:l.node.text??"",callers:l.callers.map(a=>({name:a.name,filePath:a.filePath,startLine:a.startLine,relation:a.relation})),callees:l.callees.map(a=>({name:a.name,filePath:a.filePath,startLine:a.startLine,relation:a.relation}))}))}))};return ue(r,t)}Ye.debug("format/render.ts loaded");exports.A=Je;exports.B=Ze;exports.C=et;exports.D=tt;exports.E=nt;exports.F=rt;exports.a=te;exports.b=Se;exports.c=Ie;exports.d=Te;exports.e=$e;exports.f=_e;exports.g=we;exports.h=Fe;exports.i=Ae;exports.j=ve;exports.k=R;exports.l=$;exports.m=z;exports.n=K;exports.o=j;exports.p=Ke;exports.q=D;exports.r=O;exports.s=v;exports.t=M;exports.u=W;exports.v=G;exports.w=H;exports.x=q;exports.y=Ve;exports.z=Xe;
@@ -1 +0,0 @@
1
- 'use strict';var chunkM2YU5LAI_cjs=require('./chunk-M2YU5LAI.cjs'),fs=require('fs'),path=require('path'),module$1=require('module'),utils=require('@easbot/utils');var o=utils.Log.create({service:"codebase-file-watcher"});function A(){return process.env.EASBOT_CACHE_PATH||path.join(process.cwd(),".easbot","cache")}var C=["node_modules/**",".git/**","dist/**","build/**","__pycache__/**","*.min.js","*.min.ts",".easbot/**",".codebase/**"],s=class s{constructor(){chunkM2YU5LAI_cjs.a(this,"wrapper",null);chunkM2YU5LAI_cjs.a(this,"error",null);}static get(){return s.instance||(s.instance=new s),s.instance}static clearCache(){s.instance&&(s.instance.wrapper=null,s.instance.error=null);}};chunkM2YU5LAI_cjs.a(s,"instance",null);var b=s;function R(){let r=process.platform==="linux"?`-${globalThis.EASBOT_LIBC||"glibc"}`:"";return `@parcel/watcher-${process.platform}-${process.arch}${r}`}async function T(){let r=b.get();if(r.wrapper)return r.wrapper;if(r.error)throw new utils.NameErrors.OperationFailedError({message:r.error,operation:"parcel-watcher-binding-cache"});let e=R(),t=A(),i;try{await $(e,t)?i=path.join(t,"node_modules",e):(o.info("Parcel watcher binding not found, attempting to install",{binding:e,cachePath:t}),i=await q(e,t));}catch(u){let p=utils.errorMeta(u).message,f=`binding "${e}" not found and auto-install failed. Run manually: pnpm install ${e}. Error: ${p}`;throw r.error=f,o.error("failed to install parcel watcher binding",{error:utils.errorMeta(u),binding:e}),new utils.NameErrors.OperationFailedError({message:f,operation:"parcel-watcher-binding-install"})}o.info("Loading Parcel watcher binding",{binding:e,modulePath:i});let{createWrapper:g}=await import('@parcel/watcher/wrapper.js'),l=module$1.createRequire(path.join(i,"package.json"))(e),c=g(l);return r.wrapper=c,c}async function $(r,e){try{return !!await utils.PKG.resolve(r,void 0,{extraPaths:[e]})}catch{return false}}async function q(r,e){return o.info("Installing Parcel watcher binding",{binding:r,cachePath:e}),await utils.Shell.install(r,"latest",e),path.join(e,"node_modules",r)}function P(){return process.platform==="darwin"?"fs-events":process.platform==="linux"?"inotify":process.platform==="win32"?"windows":"brute-force"}var v=class{constructor(e){chunkM2YU5LAI_cjs.a(this,"workspaceDir");chunkM2YU5LAI_cjs.a(this,"backendOpt");chunkM2YU5LAI_cjs.a(this,"ignorePatterns");chunkM2YU5LAI_cjs.a(this,"onLoadFailure");chunkM2YU5LAI_cjs.a(this,"ignoreInstance");chunkM2YU5LAI_cjs.a(this,"listeners",new Set);chunkM2YU5LAI_cjs.a(this,"unsubscribe",null);chunkM2YU5LAI_cjs.a(this,"disposed",false);chunkM2YU5LAI_cjs.a(this,"running",false);this.workspaceDir=path.isAbsolute(e.workspaceDir)?e.workspaceDir:path.normalize(e.workspaceDir),this.backendOpt=e.backend??"auto",this.ignorePatterns=e.ignorePatterns??[...C],this.onLoadFailure=e.onLoadFailure??"throw",this.ignoreInstance=utils.Ignore.create().add(this.ignorePatterns);}getIgnoreInstance(){return this.ignoreInstance}getIgnorePatterns(){return this.ignorePatterns}getActiveBackend(){return this.backendOpt==="auto"?P():this.backendOpt}on(e){return this.listeners.add(e),()=>this.listeners.delete(e)}async start(){if(this.running)return;this.running=true;let e=this.backendOpt==="auto"?P():this.backendOpt;o.info("FileWatcher start",{workspaceDir:this.workspaceDir,backend:e});let t;try{t=await T();}catch(i){if(this.running=false,this.onLoadFailure==="warn")return;throw i}await this.subscribeWithParcel(t,e);}async stop(){if(this.unsubscribe){try{await this.unsubscribe();}catch(e){o.warn("parcel unsubscribe error",{error:utils.errorMeta(e)});}this.unsubscribe=null;}this.running=false;}async dispose(){await this.stop(),this.disposed=true,this.listeners.clear();}isRunning(){return this.running}isDisposed(){return this.disposed}static clearParcelWrapperCache(){b.clearCache();}async subscribeWithParcel(e,t){if(this.disposed)throw new utils.NameErrors.OperationFailedError({message:"FileWatcher disposed before subscribe",operation:"file-watcher-disposed"});let i=(a,l)=>{if(this.disposed)return;let c=this.workspaceDir.replace(/\\/g,"/").replace(/\/$/,""),u=l.replace(/\\/g,"/"),p=l;if(u.startsWith(c+"/")&&(p=u.slice(c.length+1)),this.ignoreInstance.ignores(p,a==="create"&&p.endsWith("/")))return;let f=a==="create"?"add":a==="delete"?"unlink":"change";for(let y of this.listeners)try{y(f,p);}catch(W){o.warn("listener threw",{error:utils.errorMeta(W)});}},g=await e.subscribe(this.workspaceDir,(a,l)=>{if(a){o.error("parcel subscribe callback error",{error:utils.errorMeta(a)});return}for(let c of l)i(c.type,c.path);},{ignore:[...this.ignorePatterns],backend:t});if(this.disposed){await g.unsubscribe().catch(()=>{});return}this.unsubscribe=async()=>{await g.unsubscribe().catch(a=>{o.warn("parcel unsubscribe error",{error:utils.errorMeta(a)});});};}};function m(r){return path.join(r,".watcher.pid")}function H(r){let e=m(r);if(!fs.existsSync(e))return null;try{let t=fs.readFileSync(e,"utf-8").trim(),i=parseInt(t,10);return Number.isFinite(i)?i:null}catch{return null}}async function z(r,e){let t=m(r);await fs.promises.writeFile(t,String(e),"utf-8");}async function K(r){let e=m(r);try{await fs.promises.unlink(e);}catch{}}exports.a=v;exports.b=m;exports.c=H;exports.d=z;exports.e=K;