@xenosystem/agent-sdk 0.8.12
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/LICENSE +15 -0
- package/README.md +511 -0
- package/dist/agents/index.cjs +17 -0
- package/dist/agents/index.d.cts +244 -0
- package/dist/agents/index.d.ts +244 -0
- package/dist/agents/index.js +17 -0
- package/dist/agents/metafile-cjs.json +1 -0
- package/dist/agents/metafile-esm.json +1 -0
- package/dist/artifacts/browser.cjs +1 -0
- package/dist/artifacts/browser.d.cts +8 -0
- package/dist/artifacts/browser.d.ts +8 -0
- package/dist/artifacts/browser.js +1 -0
- package/dist/artifacts/diff-artifact-C2tQZWcs.d.cts +354 -0
- package/dist/artifacts/diff-artifact-C2tQZWcs.d.ts +354 -0
- package/dist/artifacts/index.cjs +10 -0
- package/dist/artifacts/index.d.cts +588 -0
- package/dist/artifacts/index.d.ts +588 -0
- package/dist/artifacts/index.js +10 -0
- package/dist/artifacts/metafile-cjs.json +1 -0
- package/dist/artifacts/metafile-esm.json +1 -0
- package/dist/automation/index.cjs +438 -0
- package/dist/automation/index.d.cts +878 -0
- package/dist/automation/index.d.ts +878 -0
- package/dist/automation/index.js +438 -0
- package/dist/automation/metafile-cjs.json +1 -0
- package/dist/automation/metafile-esm.json +1 -0
- package/dist/control-plane/index.cjs +7 -0
- package/dist/control-plane/index.d.cts +403 -0
- package/dist/control-plane/index.d.ts +403 -0
- package/dist/control-plane/index.js +7 -0
- package/dist/control-plane/metafile-cjs.json +1 -0
- package/dist/control-plane/metafile-esm.json +1 -0
- package/dist/control-room/index.cjs +1 -0
- package/dist/control-room/index.d.cts +216 -0
- package/dist/control-room/index.d.ts +216 -0
- package/dist/control-room/index.js +1 -0
- package/dist/control-room/metafile-cjs.json +1 -0
- package/dist/control-room/metafile-esm.json +1 -0
- package/dist/electron/index.cjs +1476 -0
- package/dist/electron/index.d.cts +1583 -0
- package/dist/electron/index.d.ts +1583 -0
- package/dist/electron/index.js +1476 -0
- package/dist/electron/metafile-cjs.json +1 -0
- package/dist/electron/metafile-esm.json +1 -0
- package/dist/governance/index.cjs +33 -0
- package/dist/governance/index.d.cts +397 -0
- package/dist/governance/index.d.ts +397 -0
- package/dist/governance/index.js +33 -0
- package/dist/governance/metafile-cjs.json +1 -0
- package/dist/governance/metafile-esm.json +1 -0
- package/dist/hooks/index.cjs +9 -0
- package/dist/hooks/index.d.cts +198 -0
- package/dist/hooks/index.d.ts +198 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/metafile-cjs.json +1 -0
- package/dist/hooks/metafile-esm.json +1 -0
- package/dist/hosted/index.cjs +1 -0
- package/dist/hosted/index.d.cts +490 -0
- package/dist/hosted/index.d.ts +490 -0
- package/dist/hosted/index.js +1 -0
- package/dist/hosted/metafile-cjs.json +1 -0
- package/dist/hosted/metafile-esm.json +1 -0
- package/dist/index.cjs +2161 -0
- package/dist/index.d.cts +12259 -0
- package/dist/index.d.ts +12259 -0
- package/dist/index.js +2161 -0
- package/dist/intelligence/index.cjs +10 -0
- package/dist/intelligence/index.d.cts +220 -0
- package/dist/intelligence/index.d.ts +220 -0
- package/dist/intelligence/index.js +10 -0
- package/dist/intelligence/metafile-cjs.json +1 -0
- package/dist/intelligence/metafile-esm.json +1 -0
- package/dist/mcp/index.cjs +28 -0
- package/dist/mcp/index.d.cts +960 -0
- package/dist/mcp/index.d.ts +960 -0
- package/dist/mcp/index.js +28 -0
- package/dist/mcp/metafile-cjs.json +1 -0
- package/dist/mcp/metafile-esm.json +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/oracle/index.cjs +1 -0
- package/dist/oracle/index.d.cts +310 -0
- package/dist/oracle/index.d.ts +310 -0
- package/dist/oracle/index.js +1 -0
- package/dist/oracle/metafile-cjs.json +1 -0
- package/dist/oracle/metafile-esm.json +1 -0
- package/dist/providers/index.cjs +11 -0
- package/dist/providers/index.d.cts +462 -0
- package/dist/providers/index.d.ts +462 -0
- package/dist/providers/index.js +11 -0
- package/dist/providers/metafile-cjs.json +1 -0
- package/dist/providers/metafile-esm.json +1 -0
- package/dist/recipes/index.cjs +2 -0
- package/dist/recipes/index.d.cts +86 -0
- package/dist/recipes/index.d.ts +86 -0
- package/dist/recipes/index.js +2 -0
- package/dist/recipes/metafile-cjs.json +1 -0
- package/dist/recipes/metafile-esm.json +1 -0
- package/dist/research/index.cjs +3 -0
- package/dist/research/index.d.cts +285 -0
- package/dist/research/index.d.ts +285 -0
- package/dist/research/index.js +3 -0
- package/dist/research/metafile-cjs.json +1 -0
- package/dist/research/metafile-esm.json +1 -0
- package/dist/session/index.cjs +56 -0
- package/dist/session/index.d.cts +523 -0
- package/dist/session/index.d.ts +523 -0
- package/dist/session/index.js +56 -0
- package/dist/session/metafile-cjs.json +1 -0
- package/dist/session/metafile-esm.json +1 -0
- package/dist/sharing/index.cjs +4 -0
- package/dist/sharing/index.d.cts +272 -0
- package/dist/sharing/index.d.ts +272 -0
- package/dist/sharing/index.js +4 -0
- package/dist/sharing/metafile-cjs.json +1 -0
- package/dist/sharing/metafile-esm.json +1 -0
- package/dist/skills/index.cjs +6 -0
- package/dist/skills/index.d.cts +277 -0
- package/dist/skills/index.d.ts +277 -0
- package/dist/skills/index.js +6 -0
- package/dist/skills/metafile-cjs.json +1 -0
- package/dist/skills/metafile-esm.json +1 -0
- package/dist/soul/index.cjs +32 -0
- package/dist/soul/index.d.cts +138 -0
- package/dist/soul/index.d.ts +138 -0
- package/dist/soul/index.js +32 -0
- package/dist/soul/metafile-cjs.json +1 -0
- package/dist/soul/metafile-esm.json +1 -0
- package/dist/terminal/index.cjs +4 -0
- package/dist/terminal/index.d.cts +55 -0
- package/dist/terminal/index.d.ts +55 -0
- package/dist/terminal/index.js +4 -0
- package/dist/terminal/metafile-cjs.json +1 -0
- package/dist/terminal/metafile-esm.json +1 -0
- package/dist/ui/index.cjs +35 -0
- package/dist/ui/index.d.cts +298 -0
- package/dist/ui/index.d.ts +298 -0
- package/dist/ui/index.js +35 -0
- package/dist/ui/metafile-cjs.json +1 -0
- package/dist/ui/metafile-esm.json +1 -0
- package/dist/utils/index.cjs +23 -0
- package/dist/utils/index.d.cts +245 -0
- package/dist/utils/index.d.ts +245 -0
- package/dist/utils/index.js +23 -0
- package/dist/utils/metafile-cjs.json +1 -0
- package/dist/utils/metafile-esm.json +1 -0
- package/native/mxc/LICENSE.microsoft-mxc-sdk.md +21 -0
- package/native/mxc/README.md +25 -0
- package/native/mxc/bin/arm64/lxc-exec +0 -0
- package/native/mxc/bin/arm64/mxc-exec-mac +0 -0
- package/native/mxc/bin/arm64/wxc-exec.exe +0 -0
- package/native/mxc/bin/arm64/wxc-host-prep.exe +0 -0
- package/native/mxc/bin/x64/lxc-exec +0 -0
- package/native/mxc/bin/x64/wxc-exec.exe +0 -0
- package/native/mxc/bin/x64/wxc-host-prep.exe +0 -0
- package/native/mxc/package.json +58 -0
- package/ownership/CLEAN_ROOM_CONTRIBUTOR_GUIDE.md +63 -0
- package/ownership/audit.mjs +727 -0
- package/ownership/evidence/PROPRIETARY-COMMAND-1/implementation-record.md +77 -0
- package/ownership/evidence/PROPRIETARY-COMMAND-1/provenance-review.md +51 -0
- package/ownership/evidence/PROPRIETARY-MEDIA-1/implementation-record.md +131 -0
- package/ownership/evidence/PROPRIETARY-MEDIA-1/provenance-review.md +50 -0
- package/ownership/evidence/PROPRIETARY-PTY-1/implementation-record.md +86 -0
- package/ownership/evidence/PROPRIETARY-PTY-1/provenance-review.md +52 -0
- package/ownership/evidence/PROPRIETARY-RUNTIME-1/implementation-record.md +68 -0
- package/ownership/evidence/PROPRIETARY-RUNTIME-1/provenance-review.md +32 -0
- package/ownership/evidence/PROPRIETARY-TOOLCHAIN-1/implementation-record.md +53 -0
- package/ownership/evidence/PROPRIETARY-TOOLCHAIN-1/provenance-review.md +32 -0
- package/ownership/evidence/PROPRIETARY-UI-1/implementation-record.md +96 -0
- package/ownership/evidence/PROPRIETARY-UI-1/provenance-review.md +46 -0
- package/ownership/ownership-policy.json +232 -0
- package/ownership/ownership-policy.schema.json +192 -0
- package/ownership/templates/clean-room-implementation-record.md +70 -0
- package/ownership/templates/provenance-review.md +51 -0
- package/package.json +209 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";var j=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var re=(e,t)=>{for(var n in t)j(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ne(t))!oe.call(e,s)&&s!==n&&j(e,s,{get:()=>t[s],enumerable:!(o=te(t,s))||o.enumerable});return e};var ie=e=>se(j({},"__esModule",{value:!0}),e);var Ne={};re(Ne,{XENO_REPOSITORY_INDEX_SCHEMA_VERSION:()=>A,XenoRepositoryIndexFileStore:()=>K,buildXenoRepositoryIndex:()=>G,buildXenoRepositoryIndexWithEmbeddings:()=>le,detectRepositoryDocumentKind:()=>U,detectRepositoryLanguage:()=>T,inspectXenoRepositoryFreshness:()=>fe,inspectXenoRepositorySymbol:()=>ge,searchXenoRepositoryIndex:()=>he,validateXenoRepositoryIndex:()=>k});module.exports=ie(Ne);var A="xeno.repository-index.v1";var L=require("node:crypto");var ae=120,ce=24e3,pe=4096,de=64,ue={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"},me=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(Ce).sort(He),o=P(t.createdAt??t.updatedAt??new Date().toISOString(),"createdAt"),s=P(t.updatedAt??o,"updatedAt"),a=F(t.chunkLines??ae,20,1e3,"chunkLines"),i=F(t.maxChunkChars??ce,1e3,256e3,"maxChunkChars"),r=[],d=[],p=[],l=new Map;for(let c of n){let h=Q(c.content),w=R(h),x=S("file",`${c.workspaceId}:${f(c.path)}`),y=c.language?.trim().toLowerCase()||T(c.path),v=c.kind??U(c.path,y),_=ye(x,h,a,i),N=Re(h,y).map(g=>({symbolId:S("symbol",`${x}:${g.kind}:${g.name}:${g.line}`),fileId:x,workspaceId:c.workspaceId,path:f(c.path),name:g.name,qualifiedName:`${f(c.path)}#${g.name}`,kind:g.kind,language:y,startLine:g.line,endLine:g.line,exported:g.exported,...g.signature?{signature:g.signature}:{}})),ee={fileId:x,workspaceId:c.workspaceId,root:c.root,path:f(c.path),language:y,kind:v,size:c.size,mtimeMs:c.mtimeMs,contentHash:w,lineCount:De(h),chunks:_,symbolIds:N.map(g=>g.symbolId),...c.git?{git:B(c.git)}:{}};r.push(ee),d.push(...N),l.set(x,we(h,y));for(let g of N)p.push(C("defines",x,g.symbolId,g.path,g.startLine,`Defines ${g.kind} ${g.name}`,1))}let I=xe(r);for(let c of r)for(let h of l.get(c.fileId)??[]){let w=Ie(c,h.specifier,I);w&&p.push(C("imports",c.fileId,w.fileId,c.path,h.line,`Imports ${h.specifier}`,.98))}p.push(...ke(r)),p.push(...Xe(r));let u=Ae(n),m=Se(p),H={workspaces:new Set(r.map(c=>c.workspaceId)).size,files:r.length,chunks:r.reduce((c,h)=>c+h.chunks.length,0),symbols:d.length,relationships:m.length,embeddedChunks:r.reduce((c,h)=>c+h.chunks.filter(w=>w.embedding).length,0),sourceBytes:r.reduce((c,h)=>c+h.size,0)},X=[...new Map(n.map(c=>[c.workspaceId,c])).values()].map(c=>({workspaceId:c.workspaceId,root:c.root,...c.git?{git:B(c.git)}:{},indexedAt:s})).sort((c,h)=>c.workspaceId.localeCompare(h.workspaceId)),E={schemaVersion:A,indexId:t.indexId?.trim()||`repo_index_${(0,L.randomUUID)()}`,revision:F(t.revision??1,1,Number.MAX_SAFE_INTEGER,"revision"),createdAt:o,updatedAt:s,sourceFingerprint:u,producer:{id:t.producer?.id?.trim()||"xeno-agent-sdk",...t.producer?.version?{version:t.producer.version.trim()}:{}},workspaces:X,files:r,symbols:d,relationships:m,stats:H};return{...E,indexHash:R($(E))}}async function le(e,t,n={}){if(!t.id.trim()||!t.model.trim())throw new Error("Repository embedding provider identity is required");let o=G(e,n),s=await Promise.all(o.files.map(async d=>({...d,chunks:await Promise.all(d.chunks.map(async p=>{let l=V(await t.embed({workspaceId:d.workspaceId,path:d.path,startLine:p.startLine,endLine:p.endLine,content:p.content,contentHash:p.contentHash}));if(l.contentHash!==p.contentHash)throw new Error(`Repository embedding content hash mismatch for ${d.path}:${p.startLine}`);if(l.model!==t.model)throw new Error(`Repository embedding model mismatch for ${d.path}:${p.startLine}`);return{...p,embedding:l}}))}))),a={...o,files:s,stats:{...o.stats,embeddedChunks:s.reduce((d,p)=>d+p.chunks.filter(l=>l.embedding).length,0)}},{indexHash:i,...r}=a;return{...a,indexHash:R($(r))}}function he(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 o=t.mode??"hybrid",s=t.queryEmbedding?V(t.queryEmbedding):void 0,a=[...new Set(W(n))].slice(0,de),i=ze(e.symbols,u=>u.fileId),r=$e(e.files),d=Math.max(1,e.stats.chunks),p=[],l=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 m of u.chunks){l+=1;let H=a.filter(y=>(m.terms[y]??0)>0),X=o==="semantic"?0:Ee(m,a,r,d),E=!!(s&&m.embedding&&s.model===m.embedding.model&&s.dimensions===m.embedding.dimensions),c=o==="lexical"||!E?0:ve(s?.vector,m.embedding?.vector),h=(i.get(u.fileId)??[]).filter(y=>{let v=y.name.toLowerCase();return a.some(_=>v===_||v.includes(_))}),w=h.length*1.5,x=o==="lexical"?X+w:o==="semantic"?c+w:X*.65+c*6*.35+w;x<=0||p.push({resultId:m.chunkId,workspaceId:u.workspaceId,path:u.path,kind:u.kind,language:u.language,startLine:m.startLine,endLine:m.endLine,snippet:_e(m.content,a),score:O(x),lexicalScore:O(X),semanticScore:O(c),matchedTerms:H,symbolIds:h.map(y=>y.symbolId),provenance:{indexId:e.indexId,indexRevision:e.revision,indexHash:e.indexHash,sourceFingerprint:e.sourceFingerprint,contentHash:m.contentHash,...u.git?{git:u.git}:{}}})}let I=F(t.limit??20,1,100,"limit");return p.sort((u,m)=>m.score-u.score||u.path.localeCompare(m.path)||u.startLine-m.startLine),{query:{...t,query:n,mode:o},results:p.slice(0,I),totalCandidates:l,semanticAvailable:!!(s&&e.files.some(u=>u.chunks.some(m=>m.embedding?.model===s.model&&m.embedding.dimensions===s.dimensions))),index:{indexId:e.indexId,revision:e.revision,indexHash:e.indexHash,updatedAt:e.updatedAt}}}function ge(e,t){k(e);let n=e.symbols.find(r=>r.symbolId===t||r.qualifiedName===t),o=n?.symbolId??t,s=e.relationships.filter(r=>r.toId===o||n&&r.toId===n.fileId),a=e.relationships.filter(r=>r.fromId===o||n&&r.fromId===n.fileId),i=new Set([...s.map(r=>r.fromId),...a.map(r=>r.toId)]);return{...n?{symbol:n}:{},incoming:s,outgoing:a,relatedSymbols:e.symbols.filter(r=>i.has(r.symbolId)),relatedFiles:e.files.filter(r=>i.has(r.fileId)||r.fileId===n?.fileId)}}function fe(e,t,n=new Date().toISOString()){k(e);let o=new Map(e.files.map(p=>[`${p.workspaceId}:${p.path}`,p])),s=new Map(t.map(p=>[`${p.workspaceId}:${f(p.path)}`,p])),a=[],i=[],r=[];for(let[p,l]of s){let I=o.get(p);I?(l.contentHash?l.contentHash!==I.contentHash:l.size!==I.size||l.mtimeMs!==I.mtimeMs)&&i.push(l.path):a.push(l.path)}for(let[p,l]of o)s.has(p)||r.push(l.path);let d=Fe(t);return{state:a.length||i.length||r.length?"stale":"fresh",checkedAt:P(n,"checkedAt"),added:a.sort(),changed:i.sort(),removed:r.sort(),sourceFingerprint:d,indexedSourceFingerprint:e.sourceFingerprint}}function k(e){if(e.schemaVersion!==A)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),J(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 o=new Set([...t,...n]);for(let i of e.relationships)if(!o.has(i.fromId)||!o.has(i.toId))throw new Error(`Repository relationship ${i.relationshipId} is dangling`);let{indexHash:s,...a}=e;if(R($(a))!==e.indexHash)throw new Error("Repository index hash mismatch");return e}function T(e){let t=f(e).split("/").pop()??"",n=t.includes(".")?t.split(".").pop()?.toLowerCase()??"":"";return ue[n]??"text"}function U(e,t=T(e)){let n=f(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 ye(e,t,n,o){let s=t.split(`
|
|
2
|
+
`),a=[],i=0;for(;i<s.length;){let r=Math.min(s.length,i+n);for(;r>i+1&&s.slice(i,r).join(`
|
|
3
|
+
`).length>o;)r-=1;let d=s.slice(i,r).join(`
|
|
4
|
+
`),p=R(d);a.push({chunkId:S("chunk",`${e}:${i+1}:${r}:${p}`),startLine:i+1,endLine:Math.max(i+1,r),content:d,contentHash:p,terms:Le(d)}),i=r}return a.length?a:[{chunkId:S("chunk",`${e}:1:1:${R("")}`),startLine:1,endLine:1,content:"",contentHash:R(""),terms:{}}]}function Re(e,t){let n=[],o=e.split(`
|
|
5
|
+
`),s=be(t);return o.forEach((a,i)=>{for(let r of s){let d=r.expression.exec(a);if(d?.groups?.name){n.push({name:d.groups.name,kind:r.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 be(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 we(e,t){let n=[];return e.split(`
|
|
6
|
+
`).forEach((o,s)=>{let a=t==="python"?/^\s*(?:from\s+(?<from>[.\w]+)\s+import|import\s+(?<plain>[.\w]+))/u.exec(o):/(?:\bfrom\s*|\brequire\s*\(\s*|\bimport\s*\(\s*)["'](?<module>[^"']+)["']/u.exec(o),i=a?.groups?.module??a?.groups?.from??a?.groups?.plain;i&&n.push({specifier:i,line:s+1})}),n.slice(0,2e4)}function xe(e){let t=new Map;for(let n of e){let o=`${n.workspaceId}:${M(n.path)}`;t.set(o,n),t.set(`${n.workspaceId}:${n.path}`,n),t.set(`${n.workspaceId}:${M(n.path)}/index`,n)}return t}function Ie(e,t,n){if(!t.startsWith("."))return;let s=[...e.path.split("/").slice(0,-1),...t.replace(/\\/gu,"/").split("/")],a=[];for(let r of s)!r||r==="."||(r===".."?a.pop():a.push(r));let i=a.join("/");return n.get(`${e.workspaceId}:${i}`)??n.get(`${e.workspaceId}:${M(i)}`)??n.get(`${e.workspaceId}:${i}/index`)}function ke(e){let t=[],n=new Map;for(let o of e.filter(s=>s.kind==="source")){let s=Z(o.path),a=`${o.workspaceId}:${s}`;n.set(a,[...n.get(a)??[],o])}for(let o of e.filter(s=>s.kind==="test")){let s=n.get(`${o.workspaceId}:${Z(o.path)}`)??[];for(let a of s.slice(0,8))t.push(C("tests",o.fileId,a.fileId,o.path,void 0,`Test ownership inferred for ${a.path}`,.8))}return t}function Xe(e){let t=[],n=e.filter(o=>o.kind!=="documentation");for(let o of e.filter(s=>s.kind==="documentation")){let s=o.chunks.map(a=>a.content).join(`
|
|
7
|
+
`).toLowerCase();for(let a of n){let i=a.path.toLowerCase(),r=i.split("/").pop()??i;if(!(!s.includes(i)&&(r.length<5||!s.includes(r)))&&(t.push(C("documents",o.fileId,a.fileId,o.path,void 0,`Documentation references ${a.path}`,.85)),t.length>=5e4))return t}}return t}function C(e,t,n,o,s,a,i){return{relationshipId:S("relationship",`${e}:${t}:${n}:${s??0}`),kind:e,fromId:t,toId:n,confidence:i,evidence:{path:o,...s?{line:s}:{},summary:a}}}function Se(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 o of n.chunks)for(let s of Object.keys(o.terms))t.set(s,(t.get(s)??0)+1);return t}function Ee(e,t,n,o){let s=Object.values(e.terms).reduce((i,r)=>i+r,0),a=0;for(let i of t){let r=e.terms[i]??0;if(!r)continue;let d=n.get(i)??0,p=Math.log(1+(o-d+.5)/(d+.5));a+=p*(r*2.2/(r+1.2*(.25+.75*s/350)))}return a}function ve(e,t){if(!e||!t||e.length===0||e.length!==t.length)return 0;let n=0,o=0,s=0;for(let a=0;a<e.length;a+=1){let i=e[a]??0,r=t[a]??0;n+=i*r,o+=i*i,s+=r*r}return o&&s?n/Math.sqrt(o*s):0}function _e(e,t){let n=e.replace(/\s+/gu," ").trim();if(n.length<=600)return n;let o=n.toLowerCase(),s=t.map(d=>o.indexOf(d)).filter(d=>d>=0),a=s.length?Math.min(...s):0,i=Math.max(0,a-180),r=Math.min(n.length,i+600);return`${i?"\u2026":""}${n.slice(i,r)}${r<n.length?"\u2026":""}`}function Ae(e){return R($(e.map(t=>({workspaceId:t.workspaceId,root:t.root,path:f(t.path),size:t.size,mtimeMs:t.mtimeMs,contentHash:R(Q(t.content)),git:t.git}))))}function Fe(e){return R($([...e].map(t=>({workspaceId:t.workspaceId,path:f(t.path),size:t.size,mtimeMs:t.mtimeMs,contentHash:t.contentHash})).sort((t,n)=>`${t.workspaceId}:${t.path}`.localeCompare(`${n.workspaceId}:${n.path}`))))}function Ce(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(J(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:f(e.path)}}function V(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 B(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>typeof t=="string"&&t.trim()).map(([t,n])=>[t,String(n).trim()]))}function W(e){return(e.normalize("NFKC").toLowerCase().match(/[\p{L}\p{N}_$.-]{2,}/gu)??[]).flatMap(t=>Me(t)).filter(t=>t.length>=2&&!me.has(t))}function Me(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 Le(e){let t=new Map;for(let n of W(e))if(t.set(n,(t.get(n)??0)+1),t.size>=pe)break;return Object.fromEntries([...t.entries()].sort(([n],[o])=>n.localeCompare(o)))}function ze(e,t){let n=new Map;for(let o of e)n.set(t(o),[...n.get(t(o))??[],o]);return n}function Z(e){return M(f(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 J(e){let t=f(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 f(e){return e.replace(/\\/gu,"/").replace(/^\.\//u,"").replace(/\/{2,}/gu,"/")}function Q(e){return e.replace(/\r\n?/gu,`
|
|
8
|
+
`)}function De(e){return e?e.split(`
|
|
9
|
+
`).length:1}function He(e,t){return`${e.workspaceId}:${e.path}`.localeCompare(`${t.workspaceId}:${t.path}`)}function S(e,t){return`${e}_${R(t).slice(0,24)}`}function R(e){return(0,L.createHash)("sha256").update(e,"utf8").digest("hex")}function $(e){return JSON.stringify(q(e))}function q(e){return Array.isArray(e)?e.map(q):!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,q(n)]))}function F(e,t,n,o){if(!Number.isInteger(e)||e<t||e>n)throw new Error(`${o} 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 Y=require("node:crypto"),b=require("node:fs/promises"),D=require("node:path");var z=512*1024*1024,K=class{path;constructor(t){this.path=(0,D.resolve)(t)}async exists(){try{return(await(0,b.stat)(this.path)).isFile()}catch{return!1}}async load(){let t=await(0,b.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,b.readFile)(this.path,"utf8"))}catch(o){throw new Error(`Repository index is invalid JSON: ${o instanceof Error?o.message:String(o)}`)}return k(n)}async save(t){k(t);let n=`${JSON.stringify(t)}
|
|
10
|
+
`;if(Buffer.byteLength(n,"utf8")>z)throw new Error(`Repository index exceeds ${z} bytes`);await(0,b.mkdir)((0,D.dirname)(this.path),{recursive:!0,mode:448});let o=`${this.path}.${process.pid}.${(0,Y.randomUUID)()}.tmp`;await(0,b.writeFile)(o,n,{encoding:"utf8",mode:384,flag:"wx"}),await(0,b.rename)(o,this.path)}};0&&(module.exports={XENO_REPOSITORY_INDEX_SCHEMA_VERSION,XenoRepositoryIndexFileStore,buildXenoRepositoryIndex,buildXenoRepositoryIndexWithEmbeddings,detectRepositoryDocumentKind,detectRepositoryLanguage,inspectXenoRepositoryFreshness,inspectXenoRepositorySymbol,searchXenoRepositoryIndex,validateXenoRepositoryIndex});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
declare const XENO_REPOSITORY_INDEX_SCHEMA_VERSION: "xeno.repository-index.v1";
|
|
2
|
+
type XenoRepositoryDocumentKind = "source" | "test" | "documentation" | "configuration" | "asset" | "other";
|
|
3
|
+
type XenoRepositorySymbolKind = "class" | "interface" | "type" | "enum" | "function" | "method" | "variable" | "module" | "heading" | "unknown";
|
|
4
|
+
type XenoRepositoryRelationshipKind = "imports" | "exports" | "defines" | "references" | "tests" | "documents";
|
|
5
|
+
interface XenoRepositoryGitProvenance {
|
|
6
|
+
head?: string;
|
|
7
|
+
branch?: string;
|
|
8
|
+
remote?: string;
|
|
9
|
+
lastCommit?: string;
|
|
10
|
+
lastCommitAt?: string;
|
|
11
|
+
}
|
|
12
|
+
interface XenoRepositorySourceDocument {
|
|
13
|
+
workspaceId: string;
|
|
14
|
+
root: string;
|
|
15
|
+
path: string;
|
|
16
|
+
content: string;
|
|
17
|
+
size: number;
|
|
18
|
+
mtimeMs: number;
|
|
19
|
+
language?: string;
|
|
20
|
+
kind?: XenoRepositoryDocumentKind;
|
|
21
|
+
git?: XenoRepositoryGitProvenance;
|
|
22
|
+
}
|
|
23
|
+
interface XenoRepositoryEmbedding {
|
|
24
|
+
model: string;
|
|
25
|
+
dimensions: number;
|
|
26
|
+
vector: number[];
|
|
27
|
+
contentHash: string;
|
|
28
|
+
generatedAt: string;
|
|
29
|
+
}
|
|
30
|
+
interface XenoRepositoryChunk {
|
|
31
|
+
chunkId: string;
|
|
32
|
+
startLine: number;
|
|
33
|
+
endLine: number;
|
|
34
|
+
content: string;
|
|
35
|
+
contentHash: string;
|
|
36
|
+
terms: Record<string, number>;
|
|
37
|
+
embedding?: XenoRepositoryEmbedding;
|
|
38
|
+
}
|
|
39
|
+
interface XenoRepositoryFileRecord {
|
|
40
|
+
fileId: string;
|
|
41
|
+
workspaceId: string;
|
|
42
|
+
root: string;
|
|
43
|
+
path: string;
|
|
44
|
+
language: string;
|
|
45
|
+
kind: XenoRepositoryDocumentKind;
|
|
46
|
+
size: number;
|
|
47
|
+
mtimeMs: number;
|
|
48
|
+
contentHash: string;
|
|
49
|
+
lineCount: number;
|
|
50
|
+
chunks: XenoRepositoryChunk[];
|
|
51
|
+
symbolIds: string[];
|
|
52
|
+
git?: XenoRepositoryGitProvenance;
|
|
53
|
+
}
|
|
54
|
+
interface XenoRepositorySymbol {
|
|
55
|
+
symbolId: string;
|
|
56
|
+
fileId: string;
|
|
57
|
+
workspaceId: string;
|
|
58
|
+
path: string;
|
|
59
|
+
name: string;
|
|
60
|
+
qualifiedName: string;
|
|
61
|
+
kind: XenoRepositorySymbolKind;
|
|
62
|
+
language: string;
|
|
63
|
+
startLine: number;
|
|
64
|
+
endLine: number;
|
|
65
|
+
exported: boolean;
|
|
66
|
+
signature?: string;
|
|
67
|
+
}
|
|
68
|
+
interface XenoRepositoryRelationship {
|
|
69
|
+
relationshipId: string;
|
|
70
|
+
kind: XenoRepositoryRelationshipKind;
|
|
71
|
+
fromId: string;
|
|
72
|
+
toId: string;
|
|
73
|
+
confidence: number;
|
|
74
|
+
evidence: {
|
|
75
|
+
path: string;
|
|
76
|
+
line?: number;
|
|
77
|
+
summary: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
interface XenoRepositoryIndexStats {
|
|
81
|
+
workspaces: number;
|
|
82
|
+
files: number;
|
|
83
|
+
chunks: number;
|
|
84
|
+
symbols: number;
|
|
85
|
+
relationships: number;
|
|
86
|
+
embeddedChunks: number;
|
|
87
|
+
sourceBytes: number;
|
|
88
|
+
}
|
|
89
|
+
interface XenoRepositoryIndexSnapshot {
|
|
90
|
+
schemaVersion: typeof XENO_REPOSITORY_INDEX_SCHEMA_VERSION;
|
|
91
|
+
indexId: string;
|
|
92
|
+
revision: number;
|
|
93
|
+
createdAt: string;
|
|
94
|
+
updatedAt: string;
|
|
95
|
+
sourceFingerprint: string;
|
|
96
|
+
indexHash: string;
|
|
97
|
+
producer: {
|
|
98
|
+
id: string;
|
|
99
|
+
version?: string;
|
|
100
|
+
};
|
|
101
|
+
workspaces: Array<{
|
|
102
|
+
workspaceId: string;
|
|
103
|
+
root: string;
|
|
104
|
+
git?: XenoRepositoryGitProvenance;
|
|
105
|
+
indexedAt: string;
|
|
106
|
+
}>;
|
|
107
|
+
files: XenoRepositoryFileRecord[];
|
|
108
|
+
symbols: XenoRepositorySymbol[];
|
|
109
|
+
relationships: XenoRepositoryRelationship[];
|
|
110
|
+
stats: XenoRepositoryIndexStats;
|
|
111
|
+
}
|
|
112
|
+
interface XenoRepositoryIndexBuildOptions {
|
|
113
|
+
indexId?: string;
|
|
114
|
+
revision?: number;
|
|
115
|
+
createdAt?: string;
|
|
116
|
+
updatedAt?: string;
|
|
117
|
+
producer?: {
|
|
118
|
+
id: string;
|
|
119
|
+
version?: string;
|
|
120
|
+
};
|
|
121
|
+
chunkLines?: number;
|
|
122
|
+
maxChunkChars?: number;
|
|
123
|
+
}
|
|
124
|
+
interface XenoRepositoryEmbeddingRequest {
|
|
125
|
+
workspaceId: string;
|
|
126
|
+
path: string;
|
|
127
|
+
startLine: number;
|
|
128
|
+
endLine: number;
|
|
129
|
+
content: string;
|
|
130
|
+
contentHash: string;
|
|
131
|
+
}
|
|
132
|
+
interface XenoRepositoryEmbeddingProvider {
|
|
133
|
+
id: string;
|
|
134
|
+
model: string;
|
|
135
|
+
embed(request: XenoRepositoryEmbeddingRequest): Promise<XenoRepositoryEmbedding>;
|
|
136
|
+
}
|
|
137
|
+
type XenoRepositorySearchMode = "lexical" | "semantic" | "hybrid";
|
|
138
|
+
interface XenoRepositorySearchQuery {
|
|
139
|
+
query: string;
|
|
140
|
+
mode?: XenoRepositorySearchMode;
|
|
141
|
+
workspaceIds?: string[];
|
|
142
|
+
kinds?: XenoRepositoryDocumentKind[];
|
|
143
|
+
languages?: string[];
|
|
144
|
+
limit?: number;
|
|
145
|
+
queryEmbedding?: XenoRepositoryEmbedding;
|
|
146
|
+
}
|
|
147
|
+
interface XenoRepositorySearchResult {
|
|
148
|
+
resultId: string;
|
|
149
|
+
workspaceId: string;
|
|
150
|
+
path: string;
|
|
151
|
+
kind: XenoRepositoryDocumentKind;
|
|
152
|
+
language: string;
|
|
153
|
+
startLine: number;
|
|
154
|
+
endLine: number;
|
|
155
|
+
snippet: string;
|
|
156
|
+
score: number;
|
|
157
|
+
lexicalScore: number;
|
|
158
|
+
semanticScore: number;
|
|
159
|
+
matchedTerms: string[];
|
|
160
|
+
symbolIds: string[];
|
|
161
|
+
provenance: {
|
|
162
|
+
indexId: string;
|
|
163
|
+
indexRevision: number;
|
|
164
|
+
indexHash: string;
|
|
165
|
+
sourceFingerprint: string;
|
|
166
|
+
contentHash: string;
|
|
167
|
+
git?: XenoRepositoryGitProvenance;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
interface XenoRepositorySearchResponse {
|
|
171
|
+
query: XenoRepositorySearchQuery;
|
|
172
|
+
results: XenoRepositorySearchResult[];
|
|
173
|
+
totalCandidates: number;
|
|
174
|
+
semanticAvailable: boolean;
|
|
175
|
+
index: {
|
|
176
|
+
indexId: string;
|
|
177
|
+
revision: number;
|
|
178
|
+
indexHash: string;
|
|
179
|
+
updatedAt: string;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
interface XenoRepositoryFreshnessInput {
|
|
183
|
+
workspaceId: string;
|
|
184
|
+
path: string;
|
|
185
|
+
size: number;
|
|
186
|
+
mtimeMs: number;
|
|
187
|
+
contentHash?: string;
|
|
188
|
+
}
|
|
189
|
+
interface XenoRepositoryFreshnessReport {
|
|
190
|
+
state: "fresh" | "stale" | "missing";
|
|
191
|
+
checkedAt: string;
|
|
192
|
+
added: string[];
|
|
193
|
+
changed: string[];
|
|
194
|
+
removed: string[];
|
|
195
|
+
sourceFingerprint: string;
|
|
196
|
+
indexedSourceFingerprint: string;
|
|
197
|
+
}
|
|
198
|
+
interface XenoRepositorySymbolGraph {
|
|
199
|
+
symbol?: XenoRepositorySymbol;
|
|
200
|
+
incoming: XenoRepositoryRelationship[];
|
|
201
|
+
outgoing: XenoRepositoryRelationship[];
|
|
202
|
+
relatedSymbols: XenoRepositorySymbol[];
|
|
203
|
+
relatedFiles: XenoRepositoryFileRecord[];
|
|
204
|
+
}
|
|
205
|
+
declare function buildXenoRepositoryIndex(sourceDocuments: readonly XenoRepositorySourceDocument[], options?: XenoRepositoryIndexBuildOptions): XenoRepositoryIndexSnapshot;
|
|
206
|
+
declare function buildXenoRepositoryIndexWithEmbeddings(sourceDocuments: readonly XenoRepositorySourceDocument[], provider: XenoRepositoryEmbeddingProvider, options?: XenoRepositoryIndexBuildOptions): Promise<XenoRepositoryIndexSnapshot>;
|
|
207
|
+
declare function searchXenoRepositoryIndex(snapshot: XenoRepositoryIndexSnapshot, input: XenoRepositorySearchQuery): XenoRepositorySearchResponse;
|
|
208
|
+
declare function inspectXenoRepositorySymbol(snapshot: XenoRepositoryIndexSnapshot, symbolOrFileId: string): XenoRepositorySymbolGraph;
|
|
209
|
+
declare function inspectXenoRepositoryFreshness(snapshot: XenoRepositoryIndexSnapshot, current: readonly XenoRepositoryFreshnessInput[], checkedAt?: string): XenoRepositoryFreshnessReport;
|
|
210
|
+
declare function validateXenoRepositoryIndex(snapshot: XenoRepositoryIndexSnapshot): XenoRepositoryIndexSnapshot;
|
|
211
|
+
declare function detectRepositoryLanguage(path: string): string;
|
|
212
|
+
declare function detectRepositoryDocumentKind(path: string, language?: string): XenoRepositoryDocumentKind;
|
|
213
|
+
declare class XenoRepositoryIndexFileStore {
|
|
214
|
+
readonly path: string;
|
|
215
|
+
constructor(path: string);
|
|
216
|
+
exists(): Promise<boolean>;
|
|
217
|
+
load(): Promise<XenoRepositoryIndexSnapshot>;
|
|
218
|
+
save(snapshot: XenoRepositoryIndexSnapshot): Promise<void>;
|
|
219
|
+
}
|
|
220
|
+
export { XENO_REPOSITORY_INDEX_SCHEMA_VERSION, type XenoRepositoryChunk, type XenoRepositoryDocumentKind, type XenoRepositoryEmbedding, type XenoRepositoryEmbeddingProvider, type XenoRepositoryEmbeddingRequest, type XenoRepositoryFileRecord, type XenoRepositoryFreshnessInput, type XenoRepositoryFreshnessReport, type XenoRepositoryGitProvenance, type XenoRepositoryIndexBuildOptions, XenoRepositoryIndexFileStore, type XenoRepositoryIndexSnapshot, type XenoRepositoryIndexStats, type XenoRepositoryRelationship, type XenoRepositoryRelationshipKind, type XenoRepositorySearchMode, type XenoRepositorySearchQuery, type XenoRepositorySearchResponse, type XenoRepositorySearchResult, type XenoRepositorySourceDocument, type XenoRepositorySymbol, type XenoRepositorySymbolGraph, type XenoRepositorySymbolKind, buildXenoRepositoryIndex, buildXenoRepositoryIndexWithEmbeddings, detectRepositoryDocumentKind, detectRepositoryLanguage, inspectXenoRepositoryFreshness, inspectXenoRepositorySymbol, searchXenoRepositoryIndex, validateXenoRepositoryIndex };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
declare const XENO_REPOSITORY_INDEX_SCHEMA_VERSION: "xeno.repository-index.v1";
|
|
2
|
+
type XenoRepositoryDocumentKind = "source" | "test" | "documentation" | "configuration" | "asset" | "other";
|
|
3
|
+
type XenoRepositorySymbolKind = "class" | "interface" | "type" | "enum" | "function" | "method" | "variable" | "module" | "heading" | "unknown";
|
|
4
|
+
type XenoRepositoryRelationshipKind = "imports" | "exports" | "defines" | "references" | "tests" | "documents";
|
|
5
|
+
interface XenoRepositoryGitProvenance {
|
|
6
|
+
head?: string;
|
|
7
|
+
branch?: string;
|
|
8
|
+
remote?: string;
|
|
9
|
+
lastCommit?: string;
|
|
10
|
+
lastCommitAt?: string;
|
|
11
|
+
}
|
|
12
|
+
interface XenoRepositorySourceDocument {
|
|
13
|
+
workspaceId: string;
|
|
14
|
+
root: string;
|
|
15
|
+
path: string;
|
|
16
|
+
content: string;
|
|
17
|
+
size: number;
|
|
18
|
+
mtimeMs: number;
|
|
19
|
+
language?: string;
|
|
20
|
+
kind?: XenoRepositoryDocumentKind;
|
|
21
|
+
git?: XenoRepositoryGitProvenance;
|
|
22
|
+
}
|
|
23
|
+
interface XenoRepositoryEmbedding {
|
|
24
|
+
model: string;
|
|
25
|
+
dimensions: number;
|
|
26
|
+
vector: number[];
|
|
27
|
+
contentHash: string;
|
|
28
|
+
generatedAt: string;
|
|
29
|
+
}
|
|
30
|
+
interface XenoRepositoryChunk {
|
|
31
|
+
chunkId: string;
|
|
32
|
+
startLine: number;
|
|
33
|
+
endLine: number;
|
|
34
|
+
content: string;
|
|
35
|
+
contentHash: string;
|
|
36
|
+
terms: Record<string, number>;
|
|
37
|
+
embedding?: XenoRepositoryEmbedding;
|
|
38
|
+
}
|
|
39
|
+
interface XenoRepositoryFileRecord {
|
|
40
|
+
fileId: string;
|
|
41
|
+
workspaceId: string;
|
|
42
|
+
root: string;
|
|
43
|
+
path: string;
|
|
44
|
+
language: string;
|
|
45
|
+
kind: XenoRepositoryDocumentKind;
|
|
46
|
+
size: number;
|
|
47
|
+
mtimeMs: number;
|
|
48
|
+
contentHash: string;
|
|
49
|
+
lineCount: number;
|
|
50
|
+
chunks: XenoRepositoryChunk[];
|
|
51
|
+
symbolIds: string[];
|
|
52
|
+
git?: XenoRepositoryGitProvenance;
|
|
53
|
+
}
|
|
54
|
+
interface XenoRepositorySymbol {
|
|
55
|
+
symbolId: string;
|
|
56
|
+
fileId: string;
|
|
57
|
+
workspaceId: string;
|
|
58
|
+
path: string;
|
|
59
|
+
name: string;
|
|
60
|
+
qualifiedName: string;
|
|
61
|
+
kind: XenoRepositorySymbolKind;
|
|
62
|
+
language: string;
|
|
63
|
+
startLine: number;
|
|
64
|
+
endLine: number;
|
|
65
|
+
exported: boolean;
|
|
66
|
+
signature?: string;
|
|
67
|
+
}
|
|
68
|
+
interface XenoRepositoryRelationship {
|
|
69
|
+
relationshipId: string;
|
|
70
|
+
kind: XenoRepositoryRelationshipKind;
|
|
71
|
+
fromId: string;
|
|
72
|
+
toId: string;
|
|
73
|
+
confidence: number;
|
|
74
|
+
evidence: {
|
|
75
|
+
path: string;
|
|
76
|
+
line?: number;
|
|
77
|
+
summary: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
interface XenoRepositoryIndexStats {
|
|
81
|
+
workspaces: number;
|
|
82
|
+
files: number;
|
|
83
|
+
chunks: number;
|
|
84
|
+
symbols: number;
|
|
85
|
+
relationships: number;
|
|
86
|
+
embeddedChunks: number;
|
|
87
|
+
sourceBytes: number;
|
|
88
|
+
}
|
|
89
|
+
interface XenoRepositoryIndexSnapshot {
|
|
90
|
+
schemaVersion: typeof XENO_REPOSITORY_INDEX_SCHEMA_VERSION;
|
|
91
|
+
indexId: string;
|
|
92
|
+
revision: number;
|
|
93
|
+
createdAt: string;
|
|
94
|
+
updatedAt: string;
|
|
95
|
+
sourceFingerprint: string;
|
|
96
|
+
indexHash: string;
|
|
97
|
+
producer: {
|
|
98
|
+
id: string;
|
|
99
|
+
version?: string;
|
|
100
|
+
};
|
|
101
|
+
workspaces: Array<{
|
|
102
|
+
workspaceId: string;
|
|
103
|
+
root: string;
|
|
104
|
+
git?: XenoRepositoryGitProvenance;
|
|
105
|
+
indexedAt: string;
|
|
106
|
+
}>;
|
|
107
|
+
files: XenoRepositoryFileRecord[];
|
|
108
|
+
symbols: XenoRepositorySymbol[];
|
|
109
|
+
relationships: XenoRepositoryRelationship[];
|
|
110
|
+
stats: XenoRepositoryIndexStats;
|
|
111
|
+
}
|
|
112
|
+
interface XenoRepositoryIndexBuildOptions {
|
|
113
|
+
indexId?: string;
|
|
114
|
+
revision?: number;
|
|
115
|
+
createdAt?: string;
|
|
116
|
+
updatedAt?: string;
|
|
117
|
+
producer?: {
|
|
118
|
+
id: string;
|
|
119
|
+
version?: string;
|
|
120
|
+
};
|
|
121
|
+
chunkLines?: number;
|
|
122
|
+
maxChunkChars?: number;
|
|
123
|
+
}
|
|
124
|
+
interface XenoRepositoryEmbeddingRequest {
|
|
125
|
+
workspaceId: string;
|
|
126
|
+
path: string;
|
|
127
|
+
startLine: number;
|
|
128
|
+
endLine: number;
|
|
129
|
+
content: string;
|
|
130
|
+
contentHash: string;
|
|
131
|
+
}
|
|
132
|
+
interface XenoRepositoryEmbeddingProvider {
|
|
133
|
+
id: string;
|
|
134
|
+
model: string;
|
|
135
|
+
embed(request: XenoRepositoryEmbeddingRequest): Promise<XenoRepositoryEmbedding>;
|
|
136
|
+
}
|
|
137
|
+
type XenoRepositorySearchMode = "lexical" | "semantic" | "hybrid";
|
|
138
|
+
interface XenoRepositorySearchQuery {
|
|
139
|
+
query: string;
|
|
140
|
+
mode?: XenoRepositorySearchMode;
|
|
141
|
+
workspaceIds?: string[];
|
|
142
|
+
kinds?: XenoRepositoryDocumentKind[];
|
|
143
|
+
languages?: string[];
|
|
144
|
+
limit?: number;
|
|
145
|
+
queryEmbedding?: XenoRepositoryEmbedding;
|
|
146
|
+
}
|
|
147
|
+
interface XenoRepositorySearchResult {
|
|
148
|
+
resultId: string;
|
|
149
|
+
workspaceId: string;
|
|
150
|
+
path: string;
|
|
151
|
+
kind: XenoRepositoryDocumentKind;
|
|
152
|
+
language: string;
|
|
153
|
+
startLine: number;
|
|
154
|
+
endLine: number;
|
|
155
|
+
snippet: string;
|
|
156
|
+
score: number;
|
|
157
|
+
lexicalScore: number;
|
|
158
|
+
semanticScore: number;
|
|
159
|
+
matchedTerms: string[];
|
|
160
|
+
symbolIds: string[];
|
|
161
|
+
provenance: {
|
|
162
|
+
indexId: string;
|
|
163
|
+
indexRevision: number;
|
|
164
|
+
indexHash: string;
|
|
165
|
+
sourceFingerprint: string;
|
|
166
|
+
contentHash: string;
|
|
167
|
+
git?: XenoRepositoryGitProvenance;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
interface XenoRepositorySearchResponse {
|
|
171
|
+
query: XenoRepositorySearchQuery;
|
|
172
|
+
results: XenoRepositorySearchResult[];
|
|
173
|
+
totalCandidates: number;
|
|
174
|
+
semanticAvailable: boolean;
|
|
175
|
+
index: {
|
|
176
|
+
indexId: string;
|
|
177
|
+
revision: number;
|
|
178
|
+
indexHash: string;
|
|
179
|
+
updatedAt: string;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
interface XenoRepositoryFreshnessInput {
|
|
183
|
+
workspaceId: string;
|
|
184
|
+
path: string;
|
|
185
|
+
size: number;
|
|
186
|
+
mtimeMs: number;
|
|
187
|
+
contentHash?: string;
|
|
188
|
+
}
|
|
189
|
+
interface XenoRepositoryFreshnessReport {
|
|
190
|
+
state: "fresh" | "stale" | "missing";
|
|
191
|
+
checkedAt: string;
|
|
192
|
+
added: string[];
|
|
193
|
+
changed: string[];
|
|
194
|
+
removed: string[];
|
|
195
|
+
sourceFingerprint: string;
|
|
196
|
+
indexedSourceFingerprint: string;
|
|
197
|
+
}
|
|
198
|
+
interface XenoRepositorySymbolGraph {
|
|
199
|
+
symbol?: XenoRepositorySymbol;
|
|
200
|
+
incoming: XenoRepositoryRelationship[];
|
|
201
|
+
outgoing: XenoRepositoryRelationship[];
|
|
202
|
+
relatedSymbols: XenoRepositorySymbol[];
|
|
203
|
+
relatedFiles: XenoRepositoryFileRecord[];
|
|
204
|
+
}
|
|
205
|
+
declare function buildXenoRepositoryIndex(sourceDocuments: readonly XenoRepositorySourceDocument[], options?: XenoRepositoryIndexBuildOptions): XenoRepositoryIndexSnapshot;
|
|
206
|
+
declare function buildXenoRepositoryIndexWithEmbeddings(sourceDocuments: readonly XenoRepositorySourceDocument[], provider: XenoRepositoryEmbeddingProvider, options?: XenoRepositoryIndexBuildOptions): Promise<XenoRepositoryIndexSnapshot>;
|
|
207
|
+
declare function searchXenoRepositoryIndex(snapshot: XenoRepositoryIndexSnapshot, input: XenoRepositorySearchQuery): XenoRepositorySearchResponse;
|
|
208
|
+
declare function inspectXenoRepositorySymbol(snapshot: XenoRepositoryIndexSnapshot, symbolOrFileId: string): XenoRepositorySymbolGraph;
|
|
209
|
+
declare function inspectXenoRepositoryFreshness(snapshot: XenoRepositoryIndexSnapshot, current: readonly XenoRepositoryFreshnessInput[], checkedAt?: string): XenoRepositoryFreshnessReport;
|
|
210
|
+
declare function validateXenoRepositoryIndex(snapshot: XenoRepositoryIndexSnapshot): XenoRepositoryIndexSnapshot;
|
|
211
|
+
declare function detectRepositoryLanguage(path: string): string;
|
|
212
|
+
declare function detectRepositoryDocumentKind(path: string, language?: string): XenoRepositoryDocumentKind;
|
|
213
|
+
declare class XenoRepositoryIndexFileStore {
|
|
214
|
+
readonly path: string;
|
|
215
|
+
constructor(path: string);
|
|
216
|
+
exists(): Promise<boolean>;
|
|
217
|
+
load(): Promise<XenoRepositoryIndexSnapshot>;
|
|
218
|
+
save(snapshot: XenoRepositoryIndexSnapshot): Promise<void>;
|
|
219
|
+
}
|
|
220
|
+
export { XENO_REPOSITORY_INDEX_SCHEMA_VERSION, type XenoRepositoryChunk, type XenoRepositoryDocumentKind, type XenoRepositoryEmbedding, type XenoRepositoryEmbeddingProvider, type XenoRepositoryEmbeddingRequest, type XenoRepositoryFileRecord, type XenoRepositoryFreshnessInput, type XenoRepositoryFreshnessReport, type XenoRepositoryGitProvenance, type XenoRepositoryIndexBuildOptions, XenoRepositoryIndexFileStore, type XenoRepositoryIndexSnapshot, type XenoRepositoryIndexStats, type XenoRepositoryRelationship, type XenoRepositoryRelationshipKind, type XenoRepositorySearchMode, type XenoRepositorySearchQuery, type XenoRepositorySearchResponse, type XenoRepositorySearchResult, type XenoRepositorySourceDocument, type XenoRepositorySymbol, type XenoRepositorySymbolGraph, type XenoRepositorySymbolKind, buildXenoRepositoryIndex, buildXenoRepositoryIndexWithEmbeddings, detectRepositoryDocumentKind, detectRepositoryLanguage, inspectXenoRepositoryFreshness, inspectXenoRepositorySymbol, searchXenoRepositoryIndex, validateXenoRepositoryIndex };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var z="xeno.repository-index.v1";import{createHash as V,randomUUID as W}from"node:crypto";var J=120,Q=24e3,Y=4096,ee=64,te={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"},ne=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 oe(e,t={}){let n=e.map(we).sort(Se),o=N(t.createdAt??t.updatedAt??new Date().toISOString(),"createdAt"),i=N(t.updatedAt??o,"updatedAt"),a=_(t.chunkLines??J,20,1e3,"chunkLines"),s=_(t.maxChunkChars??Q,1e3,256e3,"maxChunkChars"),r=[],d=[],p=[],l=new Map;for(let c of n){let h=B(c.content),b=R(h),w=X("file",`${c.workspaceId}:${f(c.path)}`),y=c.language?.trim().toLowerCase()||q(c.path),E=c.kind??re(c.path,y),v=se(w,h,a,s),L=ie(h,y).map(g=>({symbolId:X("symbol",`${w}:${g.kind}:${g.name}:${g.line}`),fileId:w,workspaceId:c.workspaceId,path:f(c.path),name:g.name,qualifiedName:`${f(c.path)}#${g.name}`,kind:g.kind,language:y,startLine:g.line,endLine:g.line,exported:g.exported,...g.signature?{signature:g.signature}:{}})),U={fileId:w,workspaceId:c.workspaceId,root:c.root,path:f(c.path),language:y,kind:E,size:c.size,mtimeMs:c.mtimeMs,contentHash:b,lineCount:Xe(h),chunks:v,symbolIds:L.map(g=>g.symbolId),...c.git?{git:j(c.git)}:{}};r.push(U),d.push(...L),l.set(w,ce(h,y));for(let g of L)p.push(A("defines",w,g.symbolId,g.path,g.startLine,`Defines ${g.kind} ${g.name}`,1))}let x=pe(r);for(let c of r)for(let h of l.get(c.fileId)??[]){let b=de(c,h.specifier,x);b&&p.push(A("imports",c.fileId,b.fileId,c.path,h.line,`Imports ${h.specifier}`,.98))}p.push(...ue(r)),p.push(...me(r));let u=Re(n),m=le(p),M={workspaces:new Set(r.map(c=>c.workspaceId)).size,files:r.length,chunks:r.reduce((c,h)=>c+h.chunks.length,0),symbols:d.length,relationships:m.length,embeddedChunks:r.reduce((c,h)=>c+h.chunks.filter(b=>b.embedding).length,0),sourceBytes:r.reduce((c,h)=>c+h.size,0)},k=[...new Map(n.map(c=>[c.workspaceId,c])).values()].map(c=>({workspaceId:c.workspaceId,root:c.root,...c.git?{git:j(c.git)}:{},indexedAt:i})).sort((c,h)=>c.workspaceId.localeCompare(h.workspaceId)),$={schemaVersion:z,indexId:t.indexId?.trim()||`repo_index_${W()}`,revision:_(t.revision??1,1,Number.MAX_SAFE_INTEGER,"revision"),createdAt:o,updatedAt:i,sourceFingerprint:u,producer:{id:t.producer?.id?.trim()||"xeno-agent-sdk",...t.producer?.version?{version:t.producer.version.trim()}:{}},workspaces:k,files:r,symbols:d,relationships:m,stats:M};return{...$,indexHash:R(S($))}}async function He(e,t,n={}){if(!t.id.trim()||!t.model.trim())throw new Error("Repository embedding provider identity is required");let o=oe(e,n),i=await Promise.all(o.files.map(async d=>({...d,chunks:await Promise.all(d.chunks.map(async p=>{let l=P(await t.embed({workspaceId:d.workspaceId,path:d.path,startLine:p.startLine,endLine:p.endLine,content:p.content,contentHash:p.contentHash}));if(l.contentHash!==p.contentHash)throw new Error(`Repository embedding content hash mismatch for ${d.path}:${p.startLine}`);if(l.model!==t.model)throw new Error(`Repository embedding model mismatch for ${d.path}:${p.startLine}`);return{...p,embedding:l}}))}))),a={...o,files:i,stats:{...o.stats,embeddedChunks:i.reduce((d,p)=>d+p.chunks.filter(l=>l.embedding).length,0)}},{indexHash:s,...r}=a;return{...a,indexHash:R(S(r))}}function Ne(e,t){I(e);let n=t.query.trim();if(!n||n.length>8192)throw new Error("Repository search query must contain 1-8192 characters");let o=t.mode??"hybrid",i=t.queryEmbedding?P(t.queryEmbedding):void 0,a=[...new Set(T(n))].slice(0,ee),s=ke(e.symbols,u=>u.fileId),r=he(e.files),d=Math.max(1,e.stats.chunks),p=[],l=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 m of u.chunks){l+=1;let M=a.filter(y=>(m.terms[y]??0)>0),k=o==="semantic"?0:ge(m,a,r,d),$=!!(i&&m.embedding&&i.model===m.embedding.model&&i.dimensions===m.embedding.dimensions),c=o==="lexical"||!$?0:fe(i?.vector,m.embedding?.vector),h=(s.get(u.fileId)??[]).filter(y=>{let E=y.name.toLowerCase();return a.some(v=>E===v||E.includes(v))}),b=h.length*1.5,w=o==="lexical"?k+b:o==="semantic"?c+b:k*.65+c*6*.35+b;w<=0||p.push({resultId:m.chunkId,workspaceId:u.workspaceId,path:u.path,kind:u.kind,language:u.language,startLine:m.startLine,endLine:m.endLine,snippet:ye(m.content,a),score:D(w),lexicalScore:D(k),semanticScore:D(c),matchedTerms:M,symbolIds:h.map(y=>y.symbolId),provenance:{indexId:e.indexId,indexRevision:e.revision,indexHash:e.indexHash,sourceFingerprint:e.sourceFingerprint,contentHash:m.contentHash,...u.git?{git:u.git}:{}}})}let x=_(t.limit??20,1,100,"limit");return p.sort((u,m)=>m.score-u.score||u.path.localeCompare(m.path)||u.startLine-m.startLine),{query:{...t,query:n,mode:o},results:p.slice(0,x),totalCandidates:l,semanticAvailable:!!(i&&e.files.some(u=>u.chunks.some(m=>m.embedding?.model===i.model&&m.embedding.dimensions===i.dimensions))),index:{indexId:e.indexId,revision:e.revision,indexHash:e.indexHash,updatedAt:e.updatedAt}}}function je(e,t){I(e);let n=e.symbols.find(r=>r.symbolId===t||r.qualifiedName===t),o=n?.symbolId??t,i=e.relationships.filter(r=>r.toId===o||n&&r.toId===n.fileId),a=e.relationships.filter(r=>r.fromId===o||n&&r.fromId===n.fileId),s=new Set([...i.map(r=>r.fromId),...a.map(r=>r.toId)]);return{...n?{symbol:n}:{},incoming:i,outgoing:a,relatedSymbols:e.symbols.filter(r=>s.has(r.symbolId)),relatedFiles:e.files.filter(r=>s.has(r.fileId)||r.fileId===n?.fileId)}}function Oe(e,t,n=new Date().toISOString()){I(e);let o=new Map(e.files.map(p=>[`${p.workspaceId}:${p.path}`,p])),i=new Map(t.map(p=>[`${p.workspaceId}:${f(p.path)}`,p])),a=[],s=[],r=[];for(let[p,l]of i){let x=o.get(p);x?(l.contentHash?l.contentHash!==x.contentHash:l.size!==x.size||l.mtimeMs!==x.mtimeMs)&&s.push(l.path):a.push(l.path)}for(let[p,l]of o)i.has(p)||r.push(l.path);let d=be(t);return{state:a.length||s.length||r.length?"stale":"fresh",checkedAt:N(n,"checkedAt"),added:a.sort(),changed:s.sort(),removed:r.sort(),sourceFingerprint:d,indexedSourceFingerprint:e.sourceFingerprint}}function I(e){if(e.schemaVersion!==z)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 o=new Set([...t,...n]);for(let s of e.relationships)if(!o.has(s.fromId)||!o.has(s.toId))throw new Error(`Repository relationship ${s.relationshipId} is dangling`);let{indexHash:i,...a}=e;if(R(S(a))!==e.indexHash)throw new Error("Repository index hash mismatch");return e}function q(e){let t=f(e).split("/").pop()??"",n=t.includes(".")?t.split(".").pop()?.toLowerCase()??"":"";return te[n]??"text"}function re(e,t=q(e)){let n=f(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 se(e,t,n,o){let i=t.split(`
|
|
2
|
+
`),a=[],s=0;for(;s<i.length;){let r=Math.min(i.length,s+n);for(;r>s+1&&i.slice(s,r).join(`
|
|
3
|
+
`).length>o;)r-=1;let d=i.slice(s,r).join(`
|
|
4
|
+
`),p=R(d);a.push({chunkId:X("chunk",`${e}:${s+1}:${r}:${p}`),startLine:s+1,endLine:Math.max(s+1,r),content:d,contentHash:p,terms:Ie(d)}),s=r}return a.length?a:[{chunkId:X("chunk",`${e}:1:1:${R("")}`),startLine:1,endLine:1,content:"",contentHash:R(""),terms:{}}]}function ie(e,t){let n=[],o=e.split(`
|
|
5
|
+
`),i=ae(t);return o.forEach((a,s)=>{for(let r of i){let d=r.expression.exec(a);if(d?.groups?.name){n.push({name:d.groups.name,kind:r.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 ae(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 ce(e,t){let n=[];return e.split(`
|
|
6
|
+
`).forEach((o,i)=>{let a=t==="python"?/^\s*(?:from\s+(?<from>[.\w]+)\s+import|import\s+(?<plain>[.\w]+))/u.exec(o):/(?:\bfrom\s*|\brequire\s*\(\s*|\bimport\s*\(\s*)["'](?<module>[^"']+)["']/u.exec(o),s=a?.groups?.module??a?.groups?.from??a?.groups?.plain;s&&n.push({specifier:s,line:i+1})}),n.slice(0,2e4)}function pe(e){let t=new Map;for(let n of e){let o=`${n.workspaceId}:${F(n.path)}`;t.set(o,n),t.set(`${n.workspaceId}:${n.path}`,n),t.set(`${n.workspaceId}:${F(n.path)}/index`,n)}return t}function de(e,t,n){if(!t.startsWith("."))return;let i=[...e.path.split("/").slice(0,-1),...t.replace(/\\/gu,"/").split("/")],a=[];for(let r of i)!r||r==="."||(r===".."?a.pop():a.push(r));let s=a.join("/");return n.get(`${e.workspaceId}:${s}`)??n.get(`${e.workspaceId}:${F(s)}`)??n.get(`${e.workspaceId}:${s}/index`)}function ue(e){let t=[],n=new Map;for(let o of e.filter(i=>i.kind==="source")){let i=O(o.path),a=`${o.workspaceId}:${i}`;n.set(a,[...n.get(a)??[],o])}for(let o of e.filter(i=>i.kind==="test")){let i=n.get(`${o.workspaceId}:${O(o.path)}`)??[];for(let a of i.slice(0,8))t.push(A("tests",o.fileId,a.fileId,o.path,void 0,`Test ownership inferred for ${a.path}`,.8))}return t}function me(e){let t=[],n=e.filter(o=>o.kind!=="documentation");for(let o of e.filter(i=>i.kind==="documentation")){let i=o.chunks.map(a=>a.content).join(`
|
|
7
|
+
`).toLowerCase();for(let a of n){let s=a.path.toLowerCase(),r=s.split("/").pop()??s;if(!(!i.includes(s)&&(r.length<5||!i.includes(r)))&&(t.push(A("documents",o.fileId,a.fileId,o.path,void 0,`Documentation references ${a.path}`,.85)),t.length>=5e4))return t}}return t}function A(e,t,n,o,i,a,s){return{relationshipId:X("relationship",`${e}:${t}:${n}:${i??0}`),kind:e,fromId:t,toId:n,confidence:s,evidence:{path:o,...i?{line:i}:{},summary:a}}}function le(e){return[...new Map(e.map(t=>[t.relationshipId,t])).values()].sort((t,n)=>t.relationshipId.localeCompare(n.relationshipId))}function he(e){let t=new Map;for(let n of e)for(let o of n.chunks)for(let i of Object.keys(o.terms))t.set(i,(t.get(i)??0)+1);return t}function ge(e,t,n,o){let i=Object.values(e.terms).reduce((s,r)=>s+r,0),a=0;for(let s of t){let r=e.terms[s]??0;if(!r)continue;let d=n.get(s)??0,p=Math.log(1+(o-d+.5)/(d+.5));a+=p*(r*2.2/(r+1.2*(.25+.75*i/350)))}return a}function fe(e,t){if(!e||!t||e.length===0||e.length!==t.length)return 0;let n=0,o=0,i=0;for(let a=0;a<e.length;a+=1){let s=e[a]??0,r=t[a]??0;n+=s*r,o+=s*s,i+=r*r}return o&&i?n/Math.sqrt(o*i):0}function ye(e,t){let n=e.replace(/\s+/gu," ").trim();if(n.length<=600)return n;let o=n.toLowerCase(),i=t.map(d=>o.indexOf(d)).filter(d=>d>=0),a=i.length?Math.min(...i):0,s=Math.max(0,a-180),r=Math.min(n.length,s+600);return`${s?"\u2026":""}${n.slice(s,r)}${r<n.length?"\u2026":""}`}function Re(e){return R(S(e.map(t=>({workspaceId:t.workspaceId,root:t.root,path:f(t.path),size:t.size,mtimeMs:t.mtimeMs,contentHash:R(B(t.content)),git:t.git}))))}function be(e){return R(S([...e].map(t=>({workspaceId:t.workspaceId,path:f(t.path),size:t.size,mtimeMs:t.mtimeMs,contentHash:t.contentHash})).sort((t,n)=>`${t.workspaceId}:${t.path}`.localeCompare(`${n.workspaceId}:${n.path}`))))}function we(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:f(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 j(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>typeof t=="string"&&t.trim()).map(([t,n])=>[t,String(n).trim()]))}function T(e){return(e.normalize("NFKC").toLowerCase().match(/[\p{L}\p{N}_$.-]{2,}/gu)??[]).flatMap(t=>xe(t)).filter(t=>t.length>=2&&!ne.has(t))}function xe(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 Ie(e){let t=new Map;for(let n of T(e))if(t.set(n,(t.get(n)??0)+1),t.size>=Y)break;return Object.fromEntries([...t.entries()].sort(([n],[o])=>n.localeCompare(o)))}function ke(e,t){let n=new Map;for(let o of e)n.set(t(o),[...n.get(t(o))??[],o]);return n}function O(e){return F(f(e).split("/").pop()??e).replace(/\.(test|spec)$/u,"").replace(/[-_]?(tests?|specs?)$/u,"")}function F(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=f(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 f(e){return e.replace(/\\/gu,"/").replace(/^\.\//u,"").replace(/\/{2,}/gu,"/")}function B(e){return e.replace(/\r\n?/gu,`
|
|
8
|
+
`)}function Xe(e){return e?e.split(`
|
|
9
|
+
`).length:1}function Se(e,t){return`${e.workspaceId}:${e.path}`.localeCompare(`${t.workspaceId}:${t.path}`)}function X(e,t){return`${e}_${R(t).slice(0,24)}`}function R(e){return V("sha256").update(e,"utf8").digest("hex")}function S(e){return JSON.stringify(H(e))}function H(e){return Array.isArray(e)?e.map(H):!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,H(n)]))}function _(e,t,n,o){if(!Number.isInteger(e)||e<t||e>n)throw new Error(`${o} must be an integer between ${t} and ${n}`);return e}function N(e,t){if(!Number.isFinite(Date.parse(e)))throw new Error(`${t} must be an ISO timestamp`);return e}function D(e){return Math.round(e*1e6)/1e6}import{randomUUID as $e}from"node:crypto";import{mkdir as Ee,readFile as ve,rename as _e,stat as Z,writeFile as Ae}from"node:fs/promises";import{dirname as Fe,resolve as Ce}from"node:path";var C=512*1024*1024,G=class{path;constructor(t){this.path=Ce(t)}async exists(){try{return(await Z(this.path)).isFile()}catch{return!1}}async load(){let t=await Z(this.path);if(!t.isFile())throw new Error("Repository index path is not a regular file");if(t.size>C)throw new Error(`Repository index exceeds ${C} bytes`);let n;try{n=JSON.parse(await ve(this.path,"utf8"))}catch(o){throw new Error(`Repository index is invalid JSON: ${o instanceof Error?o.message:String(o)}`)}return I(n)}async save(t){I(t);let n=`${JSON.stringify(t)}
|
|
10
|
+
`;if(Buffer.byteLength(n,"utf8")>C)throw new Error(`Repository index exceeds ${C} bytes`);await Ee(Fe(this.path),{recursive:!0,mode:448});let o=`${this.path}.${process.pid}.${$e()}.tmp`;await Ae(o,n,{encoding:"utf8",mode:384,flag:"wx"}),await _e(o,this.path)}};export{z as XENO_REPOSITORY_INDEX_SCHEMA_VERSION,G as XenoRepositoryIndexFileStore,oe as buildXenoRepositoryIndex,He as buildXenoRepositoryIndexWithEmbeddings,re as detectRepositoryDocumentKind,q as detectRepositoryLanguage,Oe as inspectXenoRepositoryFreshness,je as inspectXenoRepositorySymbol,Ne as searchXenoRepositoryIndex,I as validateXenoRepositoryIndex};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/intelligence/types.ts":{"bytes":5600,"imports":[],"format":"esm"},"src/intelligence/repository-index.ts":{"bytes":34708,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/intelligence/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/intelligence/file-store.ts":{"bytes":1857,"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/intelligence/repository-index.ts","kind":"import-statement","original":"./repository-index.js"}],"format":"esm"},"src/intelligence/index.ts":{"bytes":103,"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}],"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":16434},"src/intelligence/file-store.ts":{"bytesInOutput":967}},"bytes":18591}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/intelligence/types.ts":{"bytes":5600,"imports":[],"format":"esm"},"src/intelligence/repository-index.ts":{"bytes":34708,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/intelligence/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/intelligence/file-store.ts":{"bytes":1857,"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/intelligence/repository-index.ts","kind":"import-statement","original":"./repository-index.js"}],"format":"esm"},"src/intelligence/index.ts":{"bytes":103,"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}],"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":16429},"src/intelligence/file-store.ts":{"bytesInOutput":982}},"bytes":17806}}}
|