@xenosystem/agent-sdk 0.10.36 → 0.10.37
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.
- package/dist/agents/index.cjs +9 -9
- package/dist/agents/index.d.cts +4 -1
- package/dist/agents/index.d.ts +4 -1
- package/dist/agents/index.js +16 -16
- package/dist/agents/metafile-cjs.json +1 -1
- package/dist/agents/metafile-esm.json +1 -1
- package/dist/artifacts/index.cjs +1 -1
- package/dist/artifacts/index.js +1 -1
- package/dist/artifacts/metafile-cjs.json +1 -1
- package/dist/artifacts/metafile-esm.json +1 -1
- package/dist/automation/index.cjs +35 -24
- package/dist/automation/index.d.cts +194 -12
- package/dist/automation/index.d.ts +194 -12
- package/dist/automation/index.js +35 -24
- package/dist/automation/metafile-cjs.json +1 -1
- package/dist/automation/metafile-esm.json +1 -1
- package/dist/control-plane/index.cjs +8 -8
- package/dist/control-plane/index.js +8 -8
- package/dist/control-plane/metafile-cjs.json +1 -1
- package/dist/control-plane/metafile-esm.json +1 -1
- package/dist/coordination/index.cjs +2 -2
- package/dist/coordination/index.js +2 -2
- package/dist/coordination/metafile-cjs.json +1 -1
- package/dist/coordination/metafile-esm.json +1 -1
- package/dist/electron/index.cjs +239 -227
- package/dist/electron/index.d.cts +158 -1
- package/dist/electron/index.d.ts +158 -1
- package/dist/electron/index.js +239 -227
- package/dist/electron/metafile-cjs.json +1 -1
- package/dist/electron/metafile-esm.json +1 -1
- package/dist/hosted/metafile-cjs.json +1 -1
- package/dist/hosted/metafile-esm.json +1 -1
- package/dist/index.cjs +399 -388
- package/dist/index.d.cts +323 -172
- package/dist/index.d.ts +323 -172
- package/dist/index.js +401 -390
- package/dist/intelligence/index.cjs +4 -4
- package/dist/intelligence/index.js +4 -4
- package/dist/intelligence/metafile-cjs.json +1 -1
- package/dist/intelligence/metafile-esm.json +1 -1
- package/dist/mcp/index.cjs +20 -20
- package/dist/mcp/index.d.cts +146 -0
- package/dist/mcp/index.d.ts +146 -0
- package/dist/mcp/index.js +17 -17
- package/dist/mcp/metafile-cjs.json +1 -1
- package/dist/mcp/metafile-esm.json +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/providers/index.cjs +10 -10
- package/dist/providers/index.d.cts +49 -5
- package/dist/providers/index.d.ts +49 -5
- package/dist/providers/index.js +10 -10
- package/dist/providers/metafile-cjs.json +1 -1
- package/dist/providers/metafile-esm.json +1 -1
- package/dist/recipes/metafile-cjs.json +1 -1
- package/dist/recipes/metafile-esm.json +1 -1
- package/dist/research/metafile-cjs.json +1 -1
- package/dist/research/metafile-esm.json +1 -1
- package/dist/session/index.cjs +24 -24
- package/dist/session/index.js +16 -16
- package/dist/session/metafile-cjs.json +1 -1
- package/dist/session/metafile-esm.json +1 -1
- package/dist/sharing/index.cjs +1 -1
- package/dist/sharing/index.js +3 -3
- package/dist/sharing/metafile-cjs.json +1 -1
- package/dist/sharing/metafile-esm.json +1 -1
- package/dist/skills/index.d.cts +6 -0
- package/dist/skills/index.d.ts +6 -0
- package/dist/utils/index.cjs +24 -24
- package/dist/utils/index.d.cts +14 -2
- package/dist/utils/index.d.ts +14 -2
- package/dist/utils/index.js +24 -24
- package/dist/utils/metafile-cjs.json +1 -1
- package/dist/utils/metafile-esm.json +1 -1
- package/ownership/evidence/PROPRIETARY-PTY-1/implementation-record.md +1 -1
- package/ownership/ownership-policy.json +12 -1
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var oe=Object.create;var _=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var pe=(e,t)=>{for(var n in t)_(e,n,{get:t[n],enumerable:!0})},W=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ie(t))!ce.call(e,o)&&o!==n&&_(e,o,{get:()=>t[o],enumerable:!(r=se(t,o))||r.enumerable});return e};var de=(e,t,n)=>(n=e!=null?oe(ae(e)):{},W(t||!e||!e.__esModule?_(n,"default",{value:e,enumerable:!0}):n,e)),ue=e=>W(_({},"__esModule",{value:!0}),e);var Ke={};pe(Ke,{XENO_REPOSITORY_INDEX_SCHEMA_VERSION:()=>C,XenoRepositoryIndexFileStore:()=>K,buildXenoRepositoryIndex:()=>G,buildXenoRepositoryIndexWithEmbeddings:()=>
|
|
1
|
+
"use strict";var oe=Object.create;var _=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var pe=(e,t)=>{for(var n in t)_(e,n,{get:t[n],enumerable:!0})},W=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ie(t))!ce.call(e,o)&&o!==n&&_(e,o,{get:()=>t[o],enumerable:!(r=se(t,o))||r.enumerable});return e};var de=(e,t,n)=>(n=e!=null?oe(ae(e)):{},W(t||!e||!e.__esModule?_(n,"default",{value:e,enumerable:!0}):n,e)),ue=e=>W(_({},"__esModule",{value:!0}),e);var Ke={};pe(Ke,{XENO_REPOSITORY_INDEX_SCHEMA_VERSION:()=>C,XenoRepositoryIndexFileStore:()=>K,buildXenoRepositoryIndex:()=>G,buildXenoRepositoryIndexWithEmbeddings:()=>be,detectRepositoryDocumentKind:()=>J,detectRepositoryLanguage:()=>q,inspectXenoRepositoryFreshness:()=>we,inspectXenoRepositorySymbol:()=>Re,searchXenoRepositoryIndex:()=>xe,validateXenoRepositoryIndex:()=>X});module.exports=ue(Ke);var C="xeno.repository-index.v1";var D=require("node:crypto");var le=120,me=24e3,fe=4096,he=64,ge={c:"c",cc:"cpp",cjs:"javascript",cpp:"cpp",cs:"csharp",css:"css",cxx:"cpp",go:"go",h:"c",hpp:"cpp",html:"html",java:"java",js:"javascript",json:"json",jsx:"javascriptreact",kt:"kotlin",kts:"kotlin",md:"markdown",mdx:"markdown",mjs:"javascript",php:"php",py:"python",rb:"ruby",rs:"rust",sh:"shell",sql:"sql",svelte:"svelte",swift:"swift",toml:"toml",ts:"typescript",tsx:"typescriptreact",vue:"vue",yaml:"yaml",yml:"yaml"},ye=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","if","in","is","it","of","on","or","that","the","this","to","was","were","will","with","true","false","null","const","let","var","return","export","import","function","class","interface","type","public","private"]);function G(e,t={}){let n=e.map(ze).sort(je),r=P(t.createdAt??t.updatedAt??new Date().toISOString(),"createdAt"),o=P(t.updatedAt??r,"updatedAt"),a=A(t.chunkLines??le,20,1e3,"chunkLines"),i=A(t.maxChunkChars??me,1e3,256e3,"maxChunkChars"),s=[],d=[],p=[],m=new Map;for(let c of n){let f=ee(c.content),x=b(f),w=S("file",`${c.workspaceId}:${g(c.path)}`),y=c.language?.trim().toLowerCase()||q(c.path),F=c.kind??J(c.path,y),L=Ie(w,f,a,i),H=ke(f,y).map(h=>({symbolId:S("symbol",`${w}:${h.kind}:${h.name}:${h.line}`),fileId:w,workspaceId:c.workspaceId,path:g(c.path),name:h.name,qualifiedName:`${g(c.path)}#${h.name}`,kind:h.kind,language:y,startLine:h.line,endLine:h.line,exported:h.exported,...h.signature?{signature:h.signature}:{}})),re={fileId:w,workspaceId:c.workspaceId,root:c.root,path:g(c.path),language:y,kind:F,size:c.size,mtimeMs:c.mtimeMs,contentHash:x,lineCount:Oe(f),chunks:L,symbolIds:H.map(h=>h.symbolId),...c.git?{git:Z(c.git)}:{}};s.push(re),d.push(...H),m.set(w,Ee(f,y));for(let h of H)p.push(N("defines",w,h.symbolId,h.path,h.startLine,`Defines ${h.kind} ${h.name}`,1))}let k=Se(s);for(let c of s)for(let f of m.get(c.fileId)??[]){let x=$e(c,f.specifier,k);x&&p.push(N("imports",c.fileId,x.fileId,c.path,f.line,`Imports ${f.specifier}`,.98))}p.push(...ve(s)),p.push(...Fe(s));let u=Me(n),l=Le(p),B={workspaces:new Set(s.map(c=>c.workspaceId)).size,files:s.length,chunks:s.reduce((c,f)=>c+f.chunks.length,0),symbols:d.length,relationships:l.length,embeddedChunks:s.reduce((c,f)=>c+f.chunks.filter(x=>x.embedding).length,0),sourceBytes:s.reduce((c,f)=>c+f.size,0)},E=[...new Map(n.map(c=>[c.workspaceId,c])).values()].map(c=>({workspaceId:c.workspaceId,root:c.root,...c.git?{git:Z(c.git)}:{},indexedAt:o})).sort((c,f)=>c.workspaceId.localeCompare(f.workspaceId)),v={schemaVersion:C,indexId:t.indexId?.trim()||`repo_index_${(0,D.randomUUID)()}`,revision:A(t.revision??1,1,Number.MAX_SAFE_INTEGER,"revision"),createdAt:r,updatedAt:o,sourceFingerprint:u,producer:{id:t.producer?.id?.trim()||"xeno-agent-sdk",...t.producer?.version?{version:t.producer.version.trim()}:{}},workspaces:E,files:s,symbols:d,relationships:l,stats:B};return{...v,indexHash:b($(v))}}async function be(e,t,n={}){if(!t.id.trim()||!t.model.trim())throw new Error("Repository embedding provider identity is required");let r=G(e,n),o=await Promise.all(r.files.map(async d=>({...d,chunks:await Promise.all(d.chunks.map(async p=>{let m=Y(await t.embed({workspaceId:d.workspaceId,path:d.path,startLine:p.startLine,endLine:p.endLine,content:p.content,contentHash:p.contentHash}));if(m.contentHash!==p.contentHash)throw new Error(`Repository embedding content hash mismatch for ${d.path}:${p.startLine}`);if(m.model!==t.model)throw new Error(`Repository embedding model mismatch for ${d.path}:${p.startLine}`);return{...p,embedding:m}}))}))),a={...r,files:o,stats:{...r.stats,embeddedChunks:o.reduce((d,p)=>d+p.chunks.filter(m=>m.embedding).length,0)}},{indexHash:i,...s}=a;return{...a,indexHash:b($(s))}}function xe(e,t){X(e);let n=t.query.trim();if(!n||n.length>8192)throw new Error("Repository search query must contain 1-8192 characters");let r=t.mode??"hybrid",o=t.queryEmbedding?Y(t.queryEmbedding):void 0,a=[...new Set(V(n))].slice(0,he),i=He(e.symbols,u=>u.fileId),s=_e(e.files),d=Math.max(1,e.stats.chunks),p=[],m=0;for(let u of e.files)if(!(t.workspaceIds?.length&&!t.workspaceIds.includes(u.workspaceId))&&!(t.kinds?.length&&!t.kinds.includes(u.kind))&&!(t.languages?.length&&!t.languages.includes(u.language)))for(let l of u.chunks){m+=1;let B=a.filter(y=>(l.terms[y]??0)>0),E=r==="semantic"?0:Ce(l,a,s,d),v=!!(o&&l.embedding&&o.model===l.embedding.model&&o.dimensions===l.embedding.dimensions),c=r==="lexical"||!v?0:Ae(o?.vector,l.embedding?.vector),f=(i.get(u.fileId)??[]).filter(y=>{let F=y.name.toLowerCase();return a.some(L=>F===L||F.includes(L))}),x=f.length*1.5,w=r==="lexical"?E+x:r==="semantic"?c+x:E*.65+c*6*.35+x;w<=0||p.push({resultId:l.chunkId,workspaceId:u.workspaceId,path:u.path,kind:u.kind,language:u.language,startLine:l.startLine,endLine:l.endLine,snippet:Ne(l.content,a),score:O(w),lexicalScore:O(E),semanticScore:O(c),matchedTerms:B,symbolIds:f.map(y=>y.symbolId),provenance:{indexId:e.indexId,indexRevision:e.revision,indexHash:e.indexHash,sourceFingerprint:e.sourceFingerprint,contentHash:l.contentHash,...u.git?{git:u.git}:{}}})}let k=A(t.limit??20,1,100,"limit");return p.sort((u,l)=>l.score-u.score||u.path.localeCompare(l.path)||u.startLine-l.startLine),{query:{...t,query:n,mode:r},results:p.slice(0,k),totalCandidates:m,semanticAvailable:!!(o&&e.files.some(u=>u.chunks.some(l=>l.embedding?.model===o.model&&l.embedding.dimensions===o.dimensions))),index:{indexId:e.indexId,revision:e.revision,indexHash:e.indexHash,updatedAt:e.updatedAt}}}function Re(e,t){X(e);let n=e.symbols.find(s=>s.symbolId===t||s.qualifiedName===t),r=n?.symbolId??t,o=e.relationships.filter(s=>s.toId===r||n&&s.toId===n.fileId),a=e.relationships.filter(s=>s.fromId===r||n&&s.fromId===n.fileId),i=new Set([...o.map(s=>s.fromId),...a.map(s=>s.toId)]);return{...n?{symbol:n}:{},incoming:o,outgoing:a,relatedSymbols:e.symbols.filter(s=>i.has(s.symbolId)),relatedFiles:e.files.filter(s=>i.has(s.fileId)||s.fileId===n?.fileId)}}function we(e,t,n=new Date().toISOString()){X(e);let r=new Map(e.files.map(p=>[`${p.workspaceId}:${p.path}`,p])),o=new Map(t.map(p=>[`${p.workspaceId}:${g(p.path)}`,p])),a=[],i=[],s=[];for(let[p,m]of o){let k=r.get(p);k?(m.contentHash?m.contentHash!==k.contentHash:m.size!==k.size||m.mtimeMs!==k.mtimeMs)&&i.push(m.path):a.push(m.path)}for(let[p,m]of r)o.has(p)||s.push(m.path);let d=De(t);return{state:a.length||i.length||s.length?"stale":"fresh",checkedAt:P(n,"checkedAt"),added:a.sort(),changed:i.sort(),removed:s.sort(),sourceFingerprint:d,indexedSourceFingerprint:e.sourceFingerprint}}function X(e){if(e.schemaVersion!==C)throw new Error("Unsupported repository index schema");if(!e.indexId||!Number.isInteger(e.revision)||e.revision<1)throw new Error("Repository index identity is invalid");let t=new Set;for(let i of e.files){if(t.has(i.fileId))throw new Error(`Duplicate repository file ID: ${i.fileId}`);t.add(i.fileId),Q(i.path)}let n=new Set;for(let i of e.symbols){if(!t.has(i.fileId))throw new Error(`Repository symbol references unknown file: ${i.symbolId}`);if(n.has(i.symbolId))throw new Error(`Duplicate repository symbol ID: ${i.symbolId}`);n.add(i.symbolId)}let r=new Set([...t,...n]);for(let i of e.relationships)if(!r.has(i.fromId)||!r.has(i.toId))throw new Error(`Repository relationship ${i.relationshipId} is dangling`);let{indexHash:o,...a}=e;if(b($(a))!==e.indexHash)throw new Error("Repository index hash mismatch");return e}function q(e){let t=g(e).split("/").pop()??"",n=t.includes(".")?t.split(".").pop()?.toLowerCase()??"":"";return ge[n]??"text"}function J(e,t=q(e)){let n=g(e).toLowerCase();return/(^|\/)(test|tests|spec|specs|__tests__)(\/|$)|\.(test|spec)\.[^/]+$/u.test(n)?"test":t==="markdown"||/(^|\/)(docs?|documentation)(\/|$)/u.test(n)?"documentation":["json","yaml","toml"].includes(t)||/(^|\/)(\.github|config)(\/|$)/u.test(n)?"configuration":["typescript","typescriptreact","javascript","javascriptreact","python","go","rust","java","csharp","c","cpp","ruby","php","swift","kotlin","shell","sql"].includes(t)?"source":/\.(png|jpe?g|gif|webp|svg|ico|woff2?|ttf|mp[34]|wav)$/u.test(n)?"asset":"other"}function Ie(e,t,n,r){let o=t.split(`
|
|
2
2
|
`),a=[],i=0;for(;i<o.length;){let s=Math.min(o.length,i+n);for(;s>i+1&&o.slice(i,s).join(`
|
|
3
3
|
`).length>r;)s-=1;let d=o.slice(i,s).join(`
|
|
4
|
-
`),p=
|
|
4
|
+
`),p=b(d);a.push({chunkId:S("chunk",`${e}:${i+1}:${s}:${p}`),startLine:i+1,endLine:Math.max(i+1,s),content:d,contentHash:p,terms:Be(d)}),i=s}return a.length?a:[{chunkId:S("chunk",`${e}:1:1:${b("")}`),startLine:1,endLine:1,content:"",contentHash:b(""),terms:{}}]}function ke(e,t){let n=[],r=e.split(`
|
|
5
5
|
`),o=Xe(t);return r.forEach((a,i)=>{for(let s of o){let d=s.expression.exec(a);if(d?.groups?.name){n.push({name:d.groups.name,kind:s.kind,line:i+1,exported:/\b(export|public|pub)\b/u.test(a),signature:a.trim().slice(0,1e3)});break}}}),n.slice(0,2e4)}function Xe(e){return e==="markdown"?[{kind:"heading",expression:/^#{1,6}\s+(?<name>.+?)\s*$/u}]:e==="python"?[{kind:"class",expression:/^\s*class\s+(?<name>[A-Za-z_][\w]*)/u},{kind:"function",expression:/^\s*(?:async\s+)?def\s+(?<name>[A-Za-z_][\w]*)/u}]:e==="go"?[{kind:"function",expression:/^\s*func\s+(?:\([^)]*\)\s*)?(?<name>[A-Za-z_][\w]*)/u},{kind:"type",expression:/^\s*type\s+(?<name>[A-Za-z_][\w]*)/u}]:e==="rust"?[{kind:"function",expression:/^\s*(?:pub(?:\([^)]*\))?\s+)?(?:async\s+)?fn\s+(?<name>[A-Za-z_][\w]*)/u},{kind:"class",expression:/^\s*(?:pub(?:\([^)]*\))?\s+)?struct\s+(?<name>[A-Za-z_][\w]*)/u},{kind:"enum",expression:/^\s*(?:pub(?:\([^)]*\))?\s+)?enum\s+(?<name>[A-Za-z_][\w]*)/u},{kind:"interface",expression:/^\s*(?:pub(?:\([^)]*\))?\s+)?trait\s+(?<name>[A-Za-z_][\w]*)/u}]:[{kind:"class",expression:/^\s*(?:export\s+)?(?:default\s+)?(?:abstract\s+)?class\s+(?<name>[A-Za-z_$][\w$]*)/u},{kind:"interface",expression:/^\s*(?:export\s+)?interface\s+(?<name>[A-Za-z_$][\w$]*)/u},{kind:"type",expression:/^\s*(?:export\s+)?type\s+(?<name>[A-Za-z_$][\w$]*)/u},{kind:"enum",expression:/^\s*(?:export\s+)?(?:const\s+)?enum\s+(?<name>[A-Za-z_$][\w$]*)/u},{kind:"function",expression:/^\s*(?:export\s+)?(?:default\s+)?(?:async\s+)?function\s*\*?\s*(?<name>[A-Za-z_$][\w$]*)/u},{kind:"variable",expression:/^\s*(?:export\s+)?(?:const|let|var)\s+(?<name>[A-Za-z_$][\w$]*)/u}]}function Ee(e,t){let n=[];return e.split(`
|
|
6
6
|
`).forEach((r,o)=>{let a=t==="python"?/^\s*(?:from\s+(?<from>[.\w]+)\s+import|import\s+(?<plain>[.\w]+))/u.exec(r):/(?:\bfrom\s*|\brequire\s*\(\s*|\bimport\s*\(\s*)["'](?<module>[^"']+)["']/u.exec(r),i=a?.groups?.module??a?.groups?.from??a?.groups?.plain;i&&n.push({specifier:i,line:o+1})}),n.slice(0,2e4)}function Se(e){let t=new Map;for(let n of e){let r=`${n.workspaceId}:${M(n.path)}`;t.set(r,n),t.set(`${n.workspaceId}:${n.path}`,n),t.set(`${n.workspaceId}:${M(n.path)}/index`,n)}return t}function $e(e,t,n){if(!t.startsWith("."))return;let o=[...e.path.split("/").slice(0,-1),...t.replace(/\\/gu,"/").split("/")],a=[];for(let s of o)!s||s==="."||(s===".."?a.pop():a.push(s));let i=a.join("/");return n.get(`${e.workspaceId}:${i}`)??n.get(`${e.workspaceId}:${M(i)}`)??n.get(`${e.workspaceId}:${i}/index`)}function ve(e){let t=[],n=new Map;for(let r of e.filter(o=>o.kind==="source")){let o=U(r.path),a=`${r.workspaceId}:${o}`;n.set(a,[...n.get(a)??[],r])}for(let r of e.filter(o=>o.kind==="test")){let o=n.get(`${r.workspaceId}:${U(r.path)}`)??[];for(let a of o.slice(0,8))t.push(N("tests",r.fileId,a.fileId,r.path,void 0,`Test ownership inferred for ${a.path}`,.8))}return t}function Fe(e){let t=[],n=e.filter(r=>r.kind!=="documentation");for(let r of e.filter(o=>o.kind==="documentation")){let o=r.chunks.map(a=>a.content).join(`
|
|
7
|
-
`).toLowerCase();for(let a of n){let i=a.path.toLowerCase(),s=i.split("/").pop()??i;if(!(!o.includes(i)&&(s.length<5||!o.includes(s)))&&(t.push(N("documents",r.fileId,a.fileId,r.path,void 0,`Documentation references ${a.path}`,.85)),t.length>=5e4))return t}}return t}function N(e,t,n,r,o,a,i){return{relationshipId:S("relationship",`${e}:${t}:${n}:${o??0}`),kind:e,fromId:t,toId:n,confidence:i,evidence:{path:r,...o?{line:o}:{},summary:a}}}function Le(e){return[...new Map(e.map(t=>[t.relationshipId,t])).values()].sort((t,n)=>t.relationshipId.localeCompare(n.relationshipId))}function _e(e){let t=new Map;for(let n of e)for(let r of n.chunks)for(let o of Object.keys(r.terms))t.set(o,(t.get(o)??0)+1);return t}function Ce(e,t,n,r){let o=Object.values(e.terms).reduce((i,s)=>i+s,0),a=0;for(let i of t){let s=e.terms[i]??0;if(!s)continue;let d=n.get(i)??0,p=Math.log(1+(r-d+.5)/(d+.5));a+=p*(s*2.2/(s+1.2*(.25+.75*o/350)))}return a}function Ae(e,t){if(!e||!t||e.length===0||e.length!==t.length)return 0;let n=0,r=0,o=0;for(let a=0;a<e.length;a+=1){let i=e[a]??0,s=t[a]??0;n+=i*s,r+=i*i,o+=s*s}return r&&o?n/Math.sqrt(r*o):0}function Ne(e,t){let n=e.replace(/\s+/gu," ").trim();if(n.length<=600)return n;let r=n.toLowerCase(),o=t.map(d=>r.indexOf(d)).filter(d=>d>=0),a=o.length?Math.min(...o):0,i=Math.max(0,a-180),s=Math.min(n.length,i+600);return`${i?"\u2026":""}${n.slice(i,s)}${s<n.length?"\u2026":""}`}function Me(e){return
|
|
7
|
+
`).toLowerCase();for(let a of n){let i=a.path.toLowerCase(),s=i.split("/").pop()??i;if(!(!o.includes(i)&&(s.length<5||!o.includes(s)))&&(t.push(N("documents",r.fileId,a.fileId,r.path,void 0,`Documentation references ${a.path}`,.85)),t.length>=5e4))return t}}return t}function N(e,t,n,r,o,a,i){return{relationshipId:S("relationship",`${e}:${t}:${n}:${o??0}`),kind:e,fromId:t,toId:n,confidence:i,evidence:{path:r,...o?{line:o}:{},summary:a}}}function Le(e){return[...new Map(e.map(t=>[t.relationshipId,t])).values()].sort((t,n)=>t.relationshipId.localeCompare(n.relationshipId))}function _e(e){let t=new Map;for(let n of e)for(let r of n.chunks)for(let o of Object.keys(r.terms))t.set(o,(t.get(o)??0)+1);return t}function Ce(e,t,n,r){let o=Object.values(e.terms).reduce((i,s)=>i+s,0),a=0;for(let i of t){let s=e.terms[i]??0;if(!s)continue;let d=n.get(i)??0,p=Math.log(1+(r-d+.5)/(d+.5));a+=p*(s*2.2/(s+1.2*(.25+.75*o/350)))}return a}function Ae(e,t){if(!e||!t||e.length===0||e.length!==t.length)return 0;let n=0,r=0,o=0;for(let a=0;a<e.length;a+=1){let i=e[a]??0,s=t[a]??0;n+=i*s,r+=i*i,o+=s*s}return r&&o?n/Math.sqrt(r*o):0}function Ne(e,t){let n=e.replace(/\s+/gu," ").trim();if(n.length<=600)return n;let r=n.toLowerCase(),o=t.map(d=>r.indexOf(d)).filter(d=>d>=0),a=o.length?Math.min(...o):0,i=Math.max(0,a-180),s=Math.min(n.length,i+600);return`${i?"\u2026":""}${n.slice(i,s)}${s<n.length?"\u2026":""}`}function Me(e){return b($(e.map(t=>({workspaceId:t.workspaceId,root:t.root,path:g(t.path),size:t.size,mtimeMs:t.mtimeMs,contentHash:b(ee(t.content)),git:t.git}))))}function De(e){return b($([...e].map(t=>({workspaceId:t.workspaceId,path:g(t.path),size:t.size,mtimeMs:t.mtimeMs,contentHash:t.contentHash})).sort((t,n)=>`${t.workspaceId}:${t.path}`.localeCompare(`${n.workspaceId}:${n.path}`))))}function ze(e){if(!e.workspaceId.trim())throw new Error("Repository source workspaceId is required");if(!e.root.trim())throw new Error("Repository source root is required");if(Q(e.path),!Number.isFinite(e.size)||e.size<0)throw new Error(`Repository source size is invalid: ${e.path}`);if(!Number.isFinite(e.mtimeMs)||e.mtimeMs<0)throw new Error(`Repository source mtimeMs is invalid: ${e.path}`);if(Buffer.byteLength(e.content,"utf8")>4*1024*1024)throw new Error(`Repository source exceeds 4 MiB: ${e.path}`);return{...e,workspaceId:e.workspaceId.trim(),root:e.root.trim(),path:g(e.path)}}function Y(e){if(!e.model.trim()||!Number.isInteger(e.dimensions)||e.dimensions<1||e.dimensions>65536)throw new Error("Repository embedding metadata is invalid");if(e.vector.length!==e.dimensions||e.vector.some(t=>!Number.isFinite(t)))throw new Error("Repository embedding vector is invalid");return{...e,model:e.model.trim(),vector:[...e.vector]}}function Z(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>typeof t=="string"&&t.trim()).map(([t,n])=>[t,String(n).trim()]))}function V(e){return(e.normalize("NFKC").toLowerCase().match(/[\p{L}\p{N}_$.-]{2,}/gu)??[]).flatMap(t=>Te(t)).filter(t=>t.length>=2&&!ye.has(t))}function Te(e){let n=e.replace(/([a-z0-9])([A-Z])/gu,"$1 $2").replace(/[.$/_-]+/gu," ").toLowerCase().split(/\s+/u).filter(Boolean);return n.length>1?[e.toLowerCase(),...n]:n}function Be(e){let t=new Map;for(let n of V(e))if(t.set(n,(t.get(n)??0)+1),t.size>=fe)break;return Object.fromEntries([...t.entries()].sort(([n],[r])=>n.localeCompare(r)))}function He(e,t){let n=new Map;for(let r of e)n.set(t(r),[...n.get(t(r))??[],r]);return n}function U(e){return M(g(e).split("/").pop()??e).replace(/\.(test|spec)$/u,"").replace(/[-_]?(tests?|specs?)$/u,"")}function M(e){return e.replace(/\.(d\.)?(c|m)?(js|ts)x?$|\.(py|go|rs|java|cs|cpp|cxx|cc|c|h|hpp|rb|php|swift|kt|kts|md|mdx)$/u,"")}function Q(e){let t=g(e);if(!t||t.startsWith("/")||/^[A-Za-z]:\//u.test(t)||t.split("/").includes(".."))throw new Error(`Repository path must be relative and confined: ${e}`);return t}function g(e){return e.replace(/\\/gu,"/").replace(/^\.\//u,"").replace(/\/{2,}/gu,"/")}function ee(e){return e.replace(/\r\n?/gu,`
|
|
8
8
|
`)}function Oe(e){return e?e.split(`
|
|
9
|
-
`).length:1}function je(e,t){return`${e.workspaceId}:${e.path}`.localeCompare(`${t.workspaceId}:${t.path}`)}function S(e,t){return`${e}_${
|
|
9
|
+
`).length:1}function je(e,t){return`${e.workspaceId}:${e.path}`.localeCompare(`${t.workspaceId}:${t.path}`)}function S(e,t){return`${e}_${b(t).slice(0,24)}`}function b(e){return(0,D.createHash)("sha256").update(e,"utf8").digest("hex")}function $(e){return JSON.stringify(j(e))}function j(e){return Array.isArray(e)?e.map(j):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>[t,j(n)]))}function A(e,t,n,r){if(!Number.isInteger(e)||e<t||e>n)throw new Error(`${r} must be an integer between ${t} and ${n}`);return e}function P(e,t){if(!Number.isFinite(Date.parse(e)))throw new Error(`${t} must be an ISO timestamp`);return e}function O(e){return Math.round(e*1e6)/1e6}var ne=require("node:crypto"),I=require("node:fs/promises"),T=require("node:path");var R=de(require("node:fs/promises"),1);var Pe=new Set(["EACCES","EBUSY","EPERM"]),qe=[10,20,40,80,160,320,640];async function te(e,t){for(let n=0;;n+=1)try{await R.rename(e,t);return}catch(r){let o=r.code,a=qe[n];if(process.platform!=="win32"||!o||!Pe.has(o)||a===void 0)throw r;await new Promise(i=>setTimeout(i,a))}}var z=512*1024*1024,K=class{path;constructor(t){this.path=(0,T.resolve)(t)}async exists(){try{return(await(0,I.stat)(this.path)).isFile()}catch{return!1}}async load(){let t=await(0,I.stat)(this.path);if(!t.isFile())throw new Error("Repository index path is not a regular file");if(t.size>z)throw new Error(`Repository index exceeds ${z} bytes`);let n;try{n=JSON.parse(await(0,I.readFile)(this.path,"utf8"))}catch(r){throw new Error(`Repository index is invalid JSON: ${r instanceof Error?r.message:String(r)}`)}return X(n)}async save(t){X(t);let n=`${JSON.stringify(t)}
|
|
10
10
|
`;if(Buffer.byteLength(n,"utf8")>z)throw new Error(`Repository index exceeds ${z} bytes`);await(0,I.mkdir)((0,T.dirname)(this.path),{recursive:!0,mode:448});let r=`${this.path}.${process.pid}.${(0,ne.randomUUID)()}.tmp`;await(0,I.writeFile)(r,n,{encoding:"utf8",mode:384,flag:"wx"}),await te(r,this.path)}};0&&(module.exports={XENO_REPOSITORY_INDEX_SCHEMA_VERSION,XenoRepositoryIndexFileStore,buildXenoRepositoryIndex,buildXenoRepositoryIndexWithEmbeddings,detectRepositoryDocumentKind,detectRepositoryLanguage,inspectXenoRepositoryFreshness,inspectXenoRepositorySymbol,searchXenoRepositoryIndex,validateXenoRepositoryIndex});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var D="xeno.repository-index.v1";import{createHash as Y,randomUUID as V}from"node:crypto";var Q=120,ee=24e3,te=4096,ne=64,re={c:"c",cc:"cpp",cjs:"javascript",cpp:"cpp",cs:"csharp",css:"css",cxx:"cpp",go:"go",h:"c",hpp:"cpp",html:"html",java:"java",js:"javascript",json:"json",jsx:"javascriptreact",kt:"kotlin",kts:"kotlin",md:"markdown",mdx:"markdown",mjs:"javascript",php:"php",py:"python",rb:"ruby",rs:"rust",sh:"shell",sql:"sql",svelte:"svelte",swift:"swift",toml:"toml",ts:"typescript",tsx:"typescriptreact",vue:"vue",yaml:"yaml",yml:"yaml"},oe=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","if","in","is","it","of","on","or","that","the","this","to","was","were","will","with","true","false","null","const","let","var","return","export","import","function","class","interface","type","public","private"]);function se(e,t={}){let n=e.map(Ie).sort($e),r=B(t.createdAt??t.updatedAt??new Date().toISOString(),"createdAt"),i=B(t.updatedAt??r,"updatedAt"),a=L(t.chunkLines??Q,20,1e3,"chunkLines"),s=L(t.maxChunkChars??ee,1e3,256e3,"maxChunkChars"),o=[],d=[],p=[],m=new Map;for(let c of n){let f=W(c.content),b
|
|
1
|
+
var D="xeno.repository-index.v1";import{createHash as Y,randomUUID as V}from"node:crypto";var Q=120,ee=24e3,te=4096,ne=64,re={c:"c",cc:"cpp",cjs:"javascript",cpp:"cpp",cs:"csharp",css:"css",cxx:"cpp",go:"go",h:"c",hpp:"cpp",html:"html",java:"java",js:"javascript",json:"json",jsx:"javascriptreact",kt:"kotlin",kts:"kotlin",md:"markdown",mdx:"markdown",mjs:"javascript",php:"php",py:"python",rb:"ruby",rs:"rust",sh:"shell",sql:"sql",svelte:"svelte",swift:"swift",toml:"toml",ts:"typescript",tsx:"typescriptreact",vue:"vue",yaml:"yaml",yml:"yaml"},oe=new Set(["a","an","and","are","as","at","be","by","for","from","has","have","if","in","is","it","of","on","or","that","the","this","to","was","were","will","with","true","false","null","const","let","var","return","export","import","function","class","interface","type","public","private"]);function se(e,t={}){let n=e.map(Ie).sort($e),r=B(t.createdAt??t.updatedAt??new Date().toISOString(),"createdAt"),i=B(t.updatedAt??r,"updatedAt"),a=L(t.chunkLines??Q,20,1e3,"chunkLines"),s=L(t.maxChunkChars??ee,1e3,256e3,"maxChunkChars"),o=[],d=[],p=[],m=new Map;for(let c of n){let f=W(c.content),x=b(f),w=E("file",`${c.workspaceId}:${g(c.path)}`),y=c.language?.trim().toLowerCase()||j(c.path),v=c.kind??ie(c.path,y),F=ae(w,f,a,s),M=ce(f,y).map(h=>({symbolId:E("symbol",`${w}:${h.kind}:${h.name}:${h.line}`),fileId:w,workspaceId:c.workspaceId,path:g(c.path),name:h.name,qualifiedName:`${g(c.path)}#${h.name}`,kind:h.kind,language:y,startLine:h.line,endLine:h.line,exported:h.exported,...h.signature?{signature:h.signature}:{}})),J={fileId:w,workspaceId:c.workspaceId,root:c.root,path:g(c.path),language:y,kind:v,size:c.size,mtimeMs:c.mtimeMs,contentHash:x,lineCount:Se(f),chunks:F,symbolIds:M.map(h=>h.symbolId),...c.git?{git:H(c.git)}:{}};o.push(J),d.push(...M),m.set(w,de(f,y));for(let h of M)p.push(_("defines",w,h.symbolId,h.path,h.startLine,`Defines ${h.kind} ${h.name}`,1))}let I=ue(o);for(let c of o)for(let f of m.get(c.fileId)??[]){let x=le(c,f.specifier,I);x&&p.push(_("imports",c.fileId,x.fileId,c.path,f.line,`Imports ${f.specifier}`,.98))}p.push(...me(o)),p.push(...fe(o));let u=Re(n),l=he(p),N={workspaces:new Set(o.map(c=>c.workspaceId)).size,files:o.length,chunks:o.reduce((c,f)=>c+f.chunks.length,0),symbols:d.length,relationships:l.length,embeddedChunks:o.reduce((c,f)=>c+f.chunks.filter(x=>x.embedding).length,0),sourceBytes:o.reduce((c,f)=>c+f.size,0)},X=[...new Map(n.map(c=>[c.workspaceId,c])).values()].map(c=>({workspaceId:c.workspaceId,root:c.root,...c.git?{git:H(c.git)}:{},indexedAt:i})).sort((c,f)=>c.workspaceId.localeCompare(f.workspaceId)),$={schemaVersion:D,indexId:t.indexId?.trim()||`repo_index_${V()}`,revision:L(t.revision??1,1,Number.MAX_SAFE_INTEGER,"revision"),createdAt:r,updatedAt:i,sourceFingerprint:u,producer:{id:t.producer?.id?.trim()||"xeno-agent-sdk",...t.producer?.version?{version:t.producer.version.trim()}:{}},workspaces:X,files:o,symbols:d,relationships:l,stats:N};return{...$,indexHash:b(S($))}}async function He(e,t,n={}){if(!t.id.trim()||!t.model.trim())throw new Error("Repository embedding provider identity is required");let r=se(e,n),i=await Promise.all(r.files.map(async d=>({...d,chunks:await Promise.all(d.chunks.map(async p=>{let m=P(await t.embed({workspaceId:d.workspaceId,path:d.path,startLine:p.startLine,endLine:p.endLine,content:p.content,contentHash:p.contentHash}));if(m.contentHash!==p.contentHash)throw new Error(`Repository embedding content hash mismatch for ${d.path}:${p.startLine}`);if(m.model!==t.model)throw new Error(`Repository embedding model mismatch for ${d.path}:${p.startLine}`);return{...p,embedding:m}}))}))),a={...r,files:i,stats:{...r.stats,embeddedChunks:i.reduce((d,p)=>d+p.chunks.filter(m=>m.embedding).length,0)}},{indexHash:s,...o}=a;return{...a,indexHash:b(S(o))}}function Oe(e,t){k(e);let n=t.query.trim();if(!n||n.length>8192)throw new Error("Repository search query must contain 1-8192 characters");let r=t.mode??"hybrid",i=t.queryEmbedding?P(t.queryEmbedding):void 0,a=[...new Set(q(n))].slice(0,ne),s=Ee(e.symbols,u=>u.fileId),o=ge(e.files),d=Math.max(1,e.stats.chunks),p=[],m=0;for(let u of e.files)if(!(t.workspaceIds?.length&&!t.workspaceIds.includes(u.workspaceId))&&!(t.kinds?.length&&!t.kinds.includes(u.kind))&&!(t.languages?.length&&!t.languages.includes(u.language)))for(let l of u.chunks){m+=1;let N=a.filter(y=>(l.terms[y]??0)>0),X=r==="semantic"?0:ye(l,a,o,d),$=!!(i&&l.embedding&&i.model===l.embedding.model&&i.dimensions===l.embedding.dimensions),c=r==="lexical"||!$?0:be(i?.vector,l.embedding?.vector),f=(s.get(u.fileId)??[]).filter(y=>{let v=y.name.toLowerCase();return a.some(F=>v===F||v.includes(F))}),x=f.length*1.5,w=r==="lexical"?X+x:r==="semantic"?c+x:X*.65+c*6*.35+x;w<=0||p.push({resultId:l.chunkId,workspaceId:u.workspaceId,path:u.path,kind:u.kind,language:u.language,startLine:l.startLine,endLine:l.endLine,snippet:xe(l.content,a),score:z(w),lexicalScore:z(X),semanticScore:z(c),matchedTerms:N,symbolIds:f.map(y=>y.symbolId),provenance:{indexId:e.indexId,indexRevision:e.revision,indexHash:e.indexHash,sourceFingerprint:e.sourceFingerprint,contentHash:l.contentHash,...u.git?{git:u.git}:{}}})}let I=L(t.limit??20,1,100,"limit");return p.sort((u,l)=>l.score-u.score||u.path.localeCompare(l.path)||u.startLine-l.startLine),{query:{...t,query:n,mode:r},results:p.slice(0,I),totalCandidates:m,semanticAvailable:!!(i&&e.files.some(u=>u.chunks.some(l=>l.embedding?.model===i.model&&l.embedding.dimensions===i.dimensions))),index:{indexId:e.indexId,revision:e.revision,indexHash:e.indexHash,updatedAt:e.updatedAt}}}function je(e,t){k(e);let n=e.symbols.find(o=>o.symbolId===t||o.qualifiedName===t),r=n?.symbolId??t,i=e.relationships.filter(o=>o.toId===r||n&&o.toId===n.fileId),a=e.relationships.filter(o=>o.fromId===r||n&&o.fromId===n.fileId),s=new Set([...i.map(o=>o.fromId),...a.map(o=>o.toId)]);return{...n?{symbol:n}:{},incoming:i,outgoing:a,relatedSymbols:e.symbols.filter(o=>s.has(o.symbolId)),relatedFiles:e.files.filter(o=>s.has(o.fileId)||o.fileId===n?.fileId)}}function Pe(e,t,n=new Date().toISOString()){k(e);let r=new Map(e.files.map(p=>[`${p.workspaceId}:${p.path}`,p])),i=new Map(t.map(p=>[`${p.workspaceId}:${g(p.path)}`,p])),a=[],s=[],o=[];for(let[p,m]of i){let I=r.get(p);I?(m.contentHash?m.contentHash!==I.contentHash:m.size!==I.size||m.mtimeMs!==I.mtimeMs)&&s.push(m.path):a.push(m.path)}for(let[p,m]of r)i.has(p)||o.push(m.path);let d=we(t);return{state:a.length||s.length||o.length?"stale":"fresh",checkedAt:B(n,"checkedAt"),added:a.sort(),changed:s.sort(),removed:o.sort(),sourceFingerprint:d,indexedSourceFingerprint:e.sourceFingerprint}}function k(e){if(e.schemaVersion!==D)throw new Error("Unsupported repository index schema");if(!e.indexId||!Number.isInteger(e.revision)||e.revision<1)throw new Error("Repository index identity is invalid");let t=new Set;for(let s of e.files){if(t.has(s.fileId))throw new Error(`Duplicate repository file ID: ${s.fileId}`);t.add(s.fileId),K(s.path)}let n=new Set;for(let s of e.symbols){if(!t.has(s.fileId))throw new Error(`Repository symbol references unknown file: ${s.symbolId}`);if(n.has(s.symbolId))throw new Error(`Duplicate repository symbol ID: ${s.symbolId}`);n.add(s.symbolId)}let r=new Set([...t,...n]);for(let s of e.relationships)if(!r.has(s.fromId)||!r.has(s.toId))throw new Error(`Repository relationship ${s.relationshipId} is dangling`);let{indexHash:i,...a}=e;if(b(S(a))!==e.indexHash)throw new Error("Repository index hash mismatch");return e}function j(e){let t=g(e).split("/").pop()??"",n=t.includes(".")?t.split(".").pop()?.toLowerCase()??"":"";return re[n]??"text"}function ie(e,t=j(e)){let n=g(e).toLowerCase();return/(^|\/)(test|tests|spec|specs|__tests__)(\/|$)|\.(test|spec)\.[^/]+$/u.test(n)?"test":t==="markdown"||/(^|\/)(docs?|documentation)(\/|$)/u.test(n)?"documentation":["json","yaml","toml"].includes(t)||/(^|\/)(\.github|config)(\/|$)/u.test(n)?"configuration":["typescript","typescriptreact","javascript","javascriptreact","python","go","rust","java","csharp","c","cpp","ruby","php","swift","kotlin","shell","sql"].includes(t)?"source":/\.(png|jpe?g|gif|webp|svg|ico|woff2?|ttf|mp[34]|wav)$/u.test(n)?"asset":"other"}function ae(e,t,n,r){let i=t.split(`
|
|
2
2
|
`),a=[],s=0;for(;s<i.length;){let o=Math.min(i.length,s+n);for(;o>s+1&&i.slice(s,o).join(`
|
|
3
3
|
`).length>r;)o-=1;let d=i.slice(s,o).join(`
|
|
4
|
-
`),p=
|
|
4
|
+
`),p=b(d);a.push({chunkId:E("chunk",`${e}:${s+1}:${o}:${p}`),startLine:s+1,endLine:Math.max(s+1,o),content:d,contentHash:p,terms:Xe(d)}),s=o}return a.length?a:[{chunkId:E("chunk",`${e}:1:1:${b("")}`),startLine:1,endLine:1,content:"",contentHash:b(""),terms:{}}]}function ce(e,t){let n=[],r=e.split(`
|
|
5
5
|
`),i=pe(t);return r.forEach((a,s)=>{for(let o of i){let d=o.expression.exec(a);if(d?.groups?.name){n.push({name:d.groups.name,kind:o.kind,line:s+1,exported:/\b(export|public|pub)\b/u.test(a),signature:a.trim().slice(0,1e3)});break}}}),n.slice(0,2e4)}function pe(e){return e==="markdown"?[{kind:"heading",expression:/^#{1,6}\s+(?<name>.+?)\s*$/u}]:e==="python"?[{kind:"class",expression:/^\s*class\s+(?<name>[A-Za-z_][\w]*)/u},{kind:"function",expression:/^\s*(?:async\s+)?def\s+(?<name>[A-Za-z_][\w]*)/u}]:e==="go"?[{kind:"function",expression:/^\s*func\s+(?:\([^)]*\)\s*)?(?<name>[A-Za-z_][\w]*)/u},{kind:"type",expression:/^\s*type\s+(?<name>[A-Za-z_][\w]*)/u}]:e==="rust"?[{kind:"function",expression:/^\s*(?:pub(?:\([^)]*\))?\s+)?(?:async\s+)?fn\s+(?<name>[A-Za-z_][\w]*)/u},{kind:"class",expression:/^\s*(?:pub(?:\([^)]*\))?\s+)?struct\s+(?<name>[A-Za-z_][\w]*)/u},{kind:"enum",expression:/^\s*(?:pub(?:\([^)]*\))?\s+)?enum\s+(?<name>[A-Za-z_][\w]*)/u},{kind:"interface",expression:/^\s*(?:pub(?:\([^)]*\))?\s+)?trait\s+(?<name>[A-Za-z_][\w]*)/u}]:[{kind:"class",expression:/^\s*(?:export\s+)?(?:default\s+)?(?:abstract\s+)?class\s+(?<name>[A-Za-z_$][\w$]*)/u},{kind:"interface",expression:/^\s*(?:export\s+)?interface\s+(?<name>[A-Za-z_$][\w$]*)/u},{kind:"type",expression:/^\s*(?:export\s+)?type\s+(?<name>[A-Za-z_$][\w$]*)/u},{kind:"enum",expression:/^\s*(?:export\s+)?(?:const\s+)?enum\s+(?<name>[A-Za-z_$][\w$]*)/u},{kind:"function",expression:/^\s*(?:export\s+)?(?:default\s+)?(?:async\s+)?function\s*\*?\s*(?<name>[A-Za-z_$][\w$]*)/u},{kind:"variable",expression:/^\s*(?:export\s+)?(?:const|let|var)\s+(?<name>[A-Za-z_$][\w$]*)/u}]}function de(e,t){let n=[];return e.split(`
|
|
6
6
|
`).forEach((r,i)=>{let a=t==="python"?/^\s*(?:from\s+(?<from>[.\w]+)\s+import|import\s+(?<plain>[.\w]+))/u.exec(r):/(?:\bfrom\s*|\brequire\s*\(\s*|\bimport\s*\(\s*)["'](?<module>[^"']+)["']/u.exec(r),s=a?.groups?.module??a?.groups?.from??a?.groups?.plain;s&&n.push({specifier:s,line:i+1})}),n.slice(0,2e4)}function ue(e){let t=new Map;for(let n of e){let r=`${n.workspaceId}:${C(n.path)}`;t.set(r,n),t.set(`${n.workspaceId}:${n.path}`,n),t.set(`${n.workspaceId}:${C(n.path)}/index`,n)}return t}function le(e,t,n){if(!t.startsWith("."))return;let i=[...e.path.split("/").slice(0,-1),...t.replace(/\\/gu,"/").split("/")],a=[];for(let o of i)!o||o==="."||(o===".."?a.pop():a.push(o));let s=a.join("/");return n.get(`${e.workspaceId}:${s}`)??n.get(`${e.workspaceId}:${C(s)}`)??n.get(`${e.workspaceId}:${s}/index`)}function me(e){let t=[],n=new Map;for(let r of e.filter(i=>i.kind==="source")){let i=O(r.path),a=`${r.workspaceId}:${i}`;n.set(a,[...n.get(a)??[],r])}for(let r of e.filter(i=>i.kind==="test")){let i=n.get(`${r.workspaceId}:${O(r.path)}`)??[];for(let a of i.slice(0,8))t.push(_("tests",r.fileId,a.fileId,r.path,void 0,`Test ownership inferred for ${a.path}`,.8))}return t}function fe(e){let t=[],n=e.filter(r=>r.kind!=="documentation");for(let r of e.filter(i=>i.kind==="documentation")){let i=r.chunks.map(a=>a.content).join(`
|
|
7
|
-
`).toLowerCase();for(let a of n){let s=a.path.toLowerCase(),o=s.split("/").pop()??s;if(!(!i.includes(s)&&(o.length<5||!i.includes(o)))&&(t.push(_("documents",r.fileId,a.fileId,r.path,void 0,`Documentation references ${a.path}`,.85)),t.length>=5e4))return t}}return t}function _(e,t,n,r,i,a,s){return{relationshipId:E("relationship",`${e}:${t}:${n}:${i??0}`),kind:e,fromId:t,toId:n,confidence:s,evidence:{path:r,...i?{line:i}:{},summary:a}}}function he(e){return[...new Map(e.map(t=>[t.relationshipId,t])).values()].sort((t,n)=>t.relationshipId.localeCompare(n.relationshipId))}function ge(e){let t=new Map;for(let n of e)for(let r of n.chunks)for(let i of Object.keys(r.terms))t.set(i,(t.get(i)??0)+1);return t}function ye(e,t,n,r){let i=Object.values(e.terms).reduce((s,o)=>s+o,0),a=0;for(let s of t){let o=e.terms[s]??0;if(!o)continue;let d=n.get(s)??0,p=Math.log(1+(r-d+.5)/(d+.5));a+=p*(o*2.2/(o+1.2*(.25+.75*i/350)))}return a}function
|
|
7
|
+
`).toLowerCase();for(let a of n){let s=a.path.toLowerCase(),o=s.split("/").pop()??s;if(!(!i.includes(s)&&(o.length<5||!i.includes(o)))&&(t.push(_("documents",r.fileId,a.fileId,r.path,void 0,`Documentation references ${a.path}`,.85)),t.length>=5e4))return t}}return t}function _(e,t,n,r,i,a,s){return{relationshipId:E("relationship",`${e}:${t}:${n}:${i??0}`),kind:e,fromId:t,toId:n,confidence:s,evidence:{path:r,...i?{line:i}:{},summary:a}}}function he(e){return[...new Map(e.map(t=>[t.relationshipId,t])).values()].sort((t,n)=>t.relationshipId.localeCompare(n.relationshipId))}function ge(e){let t=new Map;for(let n of e)for(let r of n.chunks)for(let i of Object.keys(r.terms))t.set(i,(t.get(i)??0)+1);return t}function ye(e,t,n,r){let i=Object.values(e.terms).reduce((s,o)=>s+o,0),a=0;for(let s of t){let o=e.terms[s]??0;if(!o)continue;let d=n.get(s)??0,p=Math.log(1+(r-d+.5)/(d+.5));a+=p*(o*2.2/(o+1.2*(.25+.75*i/350)))}return a}function be(e,t){if(!e||!t||e.length===0||e.length!==t.length)return 0;let n=0,r=0,i=0;for(let a=0;a<e.length;a+=1){let s=e[a]??0,o=t[a]??0;n+=s*o,r+=s*s,i+=o*o}return r&&i?n/Math.sqrt(r*i):0}function xe(e,t){let n=e.replace(/\s+/gu," ").trim();if(n.length<=600)return n;let r=n.toLowerCase(),i=t.map(d=>r.indexOf(d)).filter(d=>d>=0),a=i.length?Math.min(...i):0,s=Math.max(0,a-180),o=Math.min(n.length,s+600);return`${s?"\u2026":""}${n.slice(s,o)}${o<n.length?"\u2026":""}`}function Re(e){return b(S(e.map(t=>({workspaceId:t.workspaceId,root:t.root,path:g(t.path),size:t.size,mtimeMs:t.mtimeMs,contentHash:b(W(t.content)),git:t.git}))))}function we(e){return b(S([...e].map(t=>({workspaceId:t.workspaceId,path:g(t.path),size:t.size,mtimeMs:t.mtimeMs,contentHash:t.contentHash})).sort((t,n)=>`${t.workspaceId}:${t.path}`.localeCompare(`${n.workspaceId}:${n.path}`))))}function Ie(e){if(!e.workspaceId.trim())throw new Error("Repository source workspaceId is required");if(!e.root.trim())throw new Error("Repository source root is required");if(K(e.path),!Number.isFinite(e.size)||e.size<0)throw new Error(`Repository source size is invalid: ${e.path}`);if(!Number.isFinite(e.mtimeMs)||e.mtimeMs<0)throw new Error(`Repository source mtimeMs is invalid: ${e.path}`);if(Buffer.byteLength(e.content,"utf8")>4*1024*1024)throw new Error(`Repository source exceeds 4 MiB: ${e.path}`);return{...e,workspaceId:e.workspaceId.trim(),root:e.root.trim(),path:g(e.path)}}function P(e){if(!e.model.trim()||!Number.isInteger(e.dimensions)||e.dimensions<1||e.dimensions>65536)throw new Error("Repository embedding metadata is invalid");if(e.vector.length!==e.dimensions||e.vector.some(t=>!Number.isFinite(t)))throw new Error("Repository embedding vector is invalid");return{...e,model:e.model.trim(),vector:[...e.vector]}}function H(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>typeof t=="string"&&t.trim()).map(([t,n])=>[t,String(n).trim()]))}function q(e){return(e.normalize("NFKC").toLowerCase().match(/[\p{L}\p{N}_$.-]{2,}/gu)??[]).flatMap(t=>ke(t)).filter(t=>t.length>=2&&!oe.has(t))}function ke(e){let n=e.replace(/([a-z0-9])([A-Z])/gu,"$1 $2").replace(/[.$/_-]+/gu," ").toLowerCase().split(/\s+/u).filter(Boolean);return n.length>1?[e.toLowerCase(),...n]:n}function Xe(e){let t=new Map;for(let n of q(e))if(t.set(n,(t.get(n)??0)+1),t.size>=te)break;return Object.fromEntries([...t.entries()].sort(([n],[r])=>n.localeCompare(r)))}function Ee(e,t){let n=new Map;for(let r of e)n.set(t(r),[...n.get(t(r))??[],r]);return n}function O(e){return C(g(e).split("/").pop()??e).replace(/\.(test|spec)$/u,"").replace(/[-_]?(tests?|specs?)$/u,"")}function C(e){return e.replace(/\.(d\.)?(c|m)?(js|ts)x?$|\.(py|go|rs|java|cs|cpp|cxx|cc|c|h|hpp|rb|php|swift|kt|kts|md|mdx)$/u,"")}function K(e){let t=g(e);if(!t||t.startsWith("/")||/^[A-Za-z]:\//u.test(t)||t.split("/").includes(".."))throw new Error(`Repository path must be relative and confined: ${e}`);return t}function g(e){return e.replace(/\\/gu,"/").replace(/^\.\//u,"").replace(/\/{2,}/gu,"/")}function W(e){return e.replace(/\r\n?/gu,`
|
|
8
8
|
`)}function Se(e){return e?e.split(`
|
|
9
|
-
`).length:1}function $e(e,t){return`${e.workspaceId}:${e.path}`.localeCompare(`${t.workspaceId}:${t.path}`)}function E(e,t){return`${e}_${
|
|
9
|
+
`).length:1}function $e(e,t){return`${e.workspaceId}:${e.path}`.localeCompare(`${t.workspaceId}:${t.path}`)}function E(e,t){return`${e}_${b(t).slice(0,24)}`}function b(e){return Y("sha256").update(e,"utf8").digest("hex")}function S(e){return JSON.stringify(T(e))}function T(e){return Array.isArray(e)?e.map(T):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>[t,T(n)]))}function L(e,t,n,r){if(!Number.isInteger(e)||e<t||e>n)throw new Error(`${r} must be an integer between ${t} and ${n}`);return e}function B(e,t){if(!Number.isFinite(Date.parse(e)))throw new Error(`${t} must be an ISO timestamp`);return e}function z(e){return Math.round(e*1e6)/1e6}import{randomUUID as Le}from"node:crypto";import{mkdir as _e,readFile as Ce,stat as U,writeFile as Ae}from"node:fs/promises";import{dirname as Ne,resolve as Me}from"node:path";import*as R from"node:fs/promises";var ve=new Set(["EACCES","EBUSY","EPERM"]),Fe=[10,20,40,80,160,320,640];async function Z(e,t){for(let n=0;;n+=1)try{await R.rename(e,t);return}catch(r){let i=r.code,a=Fe[n];if(process.platform!=="win32"||!i||!ve.has(i)||a===void 0)throw r;await new Promise(s=>setTimeout(s,a))}}var A=512*1024*1024,G=class{path;constructor(t){this.path=Me(t)}async exists(){try{return(await U(this.path)).isFile()}catch{return!1}}async load(){let t=await U(this.path);if(!t.isFile())throw new Error("Repository index path is not a regular file");if(t.size>A)throw new Error(`Repository index exceeds ${A} bytes`);let n;try{n=JSON.parse(await Ce(this.path,"utf8"))}catch(r){throw new Error(`Repository index is invalid JSON: ${r instanceof Error?r.message:String(r)}`)}return k(n)}async save(t){k(t);let n=`${JSON.stringify(t)}
|
|
10
10
|
`;if(Buffer.byteLength(n,"utf8")>A)throw new Error(`Repository index exceeds ${A} bytes`);await _e(Ne(this.path),{recursive:!0,mode:448});let r=`${this.path}.${process.pid}.${Le()}.tmp`;await Ae(r,n,{encoding:"utf8",mode:384,flag:"wx"}),await Z(r,this.path)}};export{D as XENO_REPOSITORY_INDEX_SCHEMA_VERSION,G as XenoRepositoryIndexFileStore,se as buildXenoRepositoryIndex,He as buildXenoRepositoryIndexWithEmbeddings,ie as detectRepositoryDocumentKind,j as detectRepositoryLanguage,Pe as inspectXenoRepositoryFreshness,je as inspectXenoRepositorySymbol,Oe as searchXenoRepositoryIndex,k as validateXenoRepositoryIndex};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/intelligence/types.ts":{"bytes":5352,"imports":[],"format":"esm"},"src/intelligence/repository-index.ts":{"bytes":33925,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/intelligence/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/fs.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/intelligence/types.ts":{"bytes":5352,"imports":[],"format":"esm"},"src/intelligence/repository-index.ts":{"bytes":33925,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/intelligence/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/fs.ts":{"bytes":13746,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/intelligence/file-store.ts":{"bytes":1879,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/intelligence/repository-index.ts","kind":"import-statement","original":"./repository-index.js"}],"format":"esm"},"src/intelligence/index.ts":{"bytes":100,"imports":[{"path":"src/intelligence/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/intelligence/repository-index.ts","kind":"import-statement","original":"./repository-index.js"},{"path":"src/intelligence/file-store.ts","kind":"import-statement","original":"./file-store.js"}],"format":"esm"}},"outputs":{"dist/intelligence/index.cjs":{"imports":[{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs/promises","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:fs/promises","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/intelligence/index.ts","inputs":{"src/intelligence/index.ts":{"bytesInOutput":402},"src/intelligence/types.ts":{"bytesInOutput":33},"src/intelligence/repository-index.ts":{"bytesInOutput":16437},"src/intelligence/file-store.ts":{"bytesInOutput":960},"src/utils/fs.ts":{"bytesInOutput":319}},"bytes":19054}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/intelligence/types.ts":{"bytes":5352,"imports":[],"format":"esm"},"src/intelligence/repository-index.ts":{"bytes":33925,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/intelligence/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/fs.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/intelligence/types.ts":{"bytes":5352,"imports":[],"format":"esm"},"src/intelligence/repository-index.ts":{"bytes":33925,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/intelligence/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/utils/fs.ts":{"bytes":13746,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/intelligence/file-store.ts":{"bytes":1879,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/fs.ts","kind":"import-statement","original":"../utils/fs.js"},{"path":"src/intelligence/repository-index.ts","kind":"import-statement","original":"./repository-index.js"}],"format":"esm"},"src/intelligence/index.ts":{"bytes":100,"imports":[{"path":"src/intelligence/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/intelligence/repository-index.ts","kind":"import-statement","original":"./repository-index.js"},{"path":"src/intelligence/file-store.ts","kind":"import-statement","original":"./file-store.js"}],"format":"esm"}},"outputs":{"dist/intelligence/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true}],"exports":["XENO_REPOSITORY_INDEX_SCHEMA_VERSION","XenoRepositoryIndexFileStore","buildXenoRepositoryIndex","buildXenoRepositoryIndexWithEmbeddings","detectRepositoryDocumentKind","detectRepositoryLanguage","inspectXenoRepositoryFreshness","inspectXenoRepositorySymbol","searchXenoRepositoryIndex","validateXenoRepositoryIndex"],"entryPoint":"src/intelligence/index.ts","inputs":{"src/intelligence/types.ts":{"bytesInOutput":33},"src/intelligence/index.ts":{"bytesInOutput":0},"src/intelligence/repository-index.ts":{"bytesInOutput":16433},"src/intelligence/file-store.ts":{"bytesInOutput":968},"src/utils/fs.ts":{"bytesInOutput":313}},"bytes":18109}}}
|