@better-vibe/repo-slice 1.0.1 → 1.1.0
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/README.md +24 -11
- package/dist/cli.js +137 -64
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -59,11 +59,11 @@ repo-slice pack --from-diff HEAD~3..HEAD
|
|
|
59
59
|
# Parse error logs and bundle relevant code
|
|
60
60
|
repo-slice pack --from-log build-errors.txt
|
|
61
61
|
|
|
62
|
-
# Output as
|
|
63
|
-
repo-slice pack --entry src/app.ts --format
|
|
62
|
+
# Output as Markdown instead of JSON (default)
|
|
63
|
+
repo-slice pack --entry src/app.ts --format md
|
|
64
64
|
|
|
65
65
|
# Save to file
|
|
66
|
-
repo-slice pack --entry src/api.ts --out context.
|
|
66
|
+
repo-slice pack --entry src/api.ts --out context.json
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
## Commands
|
|
@@ -114,24 +114,37 @@ Extract a context bundle from the repository.
|
|
|
114
114
|
|
|
115
115
|
| Option | Description |
|
|
116
116
|
|--------|-------------|
|
|
117
|
-
| `--format <md
|
|
117
|
+
| `--format <json\|md>` | Output format (default: json) |
|
|
118
118
|
| `--out <path>` | Write to file instead of stdout |
|
|
119
119
|
| `--reason` | Include selection reasons in output |
|
|
120
120
|
| `--redact` | Redact secrets (API keys, etc.) |
|
|
121
121
|
| `--no-timestamp` | Omit timestamp for reproducible output |
|
|
122
122
|
| `--debug` | Enable debug logging |
|
|
123
123
|
|
|
124
|
-
### `repo-slice workspaces`
|
|
124
|
+
### `repo-slice workspaces [options]`
|
|
125
125
|
|
|
126
126
|
List detected workspaces in the repository.
|
|
127
127
|
|
|
128
128
|
```bash
|
|
129
129
|
$ repo-slice workspaces
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
[
|
|
131
|
+
{
|
|
132
|
+
"name": "packages/web",
|
|
133
|
+
"kind": "node",
|
|
134
|
+
"root": "/path/to/repo/packages/web"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"name": "packages/api",
|
|
138
|
+
"kind": "node",
|
|
139
|
+
"root": "/path/to/repo/packages/api"
|
|
140
|
+
}
|
|
141
|
+
]
|
|
133
142
|
```
|
|
134
143
|
|
|
144
|
+
| Option | Description |
|
|
145
|
+
|--------|-------------|
|
|
146
|
+
| `--format <json\|text>` | Output format (default: json) |
|
|
147
|
+
|
|
135
148
|
### `repo-slice version`
|
|
136
149
|
|
|
137
150
|
Print the version number.
|
|
@@ -200,10 +213,10 @@ Then disambiguate:
|
|
|
200
213
|
repo-slice pack --symbol "src/config/app.ts:Config"
|
|
201
214
|
```
|
|
202
215
|
|
|
203
|
-
### JSON Output for Tooling
|
|
216
|
+
### JSON Output for Tooling (default)
|
|
204
217
|
|
|
205
218
|
```bash
|
|
206
|
-
repo-slice pack --entry src/api.ts
|
|
219
|
+
repo-slice pack --entry src/api.ts | jq '.items[].filePath'
|
|
207
220
|
```
|
|
208
221
|
|
|
209
222
|
### Monorepo Usage
|
|
@@ -270,7 +283,7 @@ Create `.repo-slicerc.json` at your repository root or workspace root:
|
|
|
270
283
|
|
|
271
284
|
## Output Formats
|
|
272
285
|
|
|
273
|
-
### Markdown
|
|
286
|
+
### Markdown
|
|
274
287
|
|
|
275
288
|
```markdown
|
|
276
289
|
# repo-slice bundle
|
package/dist/cli.js
CHANGED
|
@@ -1,75 +1,78 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var vf=Object.defineProperty;var h=(r,n)=>{for(var f in n)vf(r,f,{get:n[f],enumerable:!0,configurable:!0,set:(m)=>n[f]=()=>m})};var J=(r,n)=>()=>(r&&(n=r(r=0)),n);var Or={};h(Or,{versionCommand:()=>lf});import{readFile as hf,access as pf}from"node:fs/promises";import{fileURLToPath as sf}from"node:url";import{dirname as of,join as $n}from"node:path";async function lf(){let r=sf(import.meta.url),n=of(r),f=$n(n,"..","package.json");try{await pf(f)}catch{f=$n(n,"..","..","package.json")}let m=await hf(f,"utf8"),t=JSON.parse(m);process.stdout.write(`${t.version??"0.0.0"}
|
|
3
|
+
`)}var Dr=()=>{};import{readFile as un,stat as df}from"node:fs/promises";async function Q(r){try{return await df(r),!0}catch{return!1}}async function nr(r){let n=await un(r,"utf8");return JSON.parse(n)}async function S(r){return un(r,"utf8")}var D=()=>{};import{relative as af,resolve as ef,sep as rm}from"node:path";function k(r){return ef(r)}function B(r){return r.split(rm).join("/")}function V(r,n){let f=af(n,r);return f===""||!f.startsWith("..")&&!f.startsWith("../")&&!f.startsWith("..\\")}var _=()=>{};import{dirname as nm,join as fm}from"node:path";async function p(r){let n=k(r);while(!0){if(await Q(fm(n,".git")))return n;let f=nm(n);if(f===n)return k(r);n=f}}var $r=J(()=>{D();_()});import{basename as yn,join as zr}from"node:path";import mm from"fast-glob";import tm from"yaml";import{readFile as $m}from"node:fs/promises";async function xn(r){let n=k(r),f=new Map,m=zr(n,"package.json"),t=[],u;if(await Q(m)){if(u=await nr(m),u.workspaces){if(Array.isArray(u.workspaces))t.push(...u.workspaces);else if(Array.isArray(u.workspaces.packages))t.push(...u.workspaces.packages)}f.set(n,{id:".",name:u.name??yn(n),root:n,kind:"node"})}let $=zr(n,"pnpm-workspace.yaml");if(await Q($)){let x=await $m($,"utf8"),w=tm.parse(x);if(Array.isArray(w?.packages))t.push(...w.packages)}if(t.length===0)return Array.from(f.values());let y=await mm(t,{cwd:n,onlyDirectories:!0,absolute:!0,dot:!1,followSymbolicLinks:!1});for(let x of y.sort()){let w=zr(x,"package.json");if(!await Q(w))continue;let E={id:".",name:(await nr(w)).name??yn(x),root:k(x),kind:"node"};f.set(E.root,E)}return Array.from(f.values())}var wn=J(()=>{D();_()});import{basename as Gn,join as En}from"node:path";import um from"fast-glob";async function Wn(r,n=ym){let f=k(r),m=new Map;for(let u of Ln)if(await Q(En(f,u))){m.set(f,{id:".",name:Gn(f),root:f,kind:"python"});break}let t=await um(n,{cwd:f,onlyDirectories:!0,absolute:!0,dot:!1,followSymbolicLinks:!1});for(let u of t.sort())for(let $ of Ln)if(await Q(En(u,$))){let y=k(u);m.set(y,{id:".",name:Gn(u),root:y,kind:"python"});break}return Array.from(m.values())}var Ln,ym;var Kn=J(()=>{D();_();Ln=["pyproject.toml","requirements.txt"],ym=["apps/*","packages/*","services/*"]});import{basename as xm,relative as wm}from"node:path";async function s(r){let n=k(r),f=await xn(n),m=await Wn(n),t=new Map,u=(y,x)=>{let w=t.get(y.root);if(!w){t.set(y.root,{...y,kind:x});return}if(w.kind!==x)w.kind="mixed"};for(let y of f)u(y,"node");for(let y of m)u(y,"python");return Array.from(t.values()).map((y)=>{let x=wm(n,y.root),w=x===""?".":B(x);return{...y,id:w,name:y.name||xm(y.root)}}).sort((y,x)=>y.root.localeCompare(x.root))}var ur=J(()=>{wn();Kn();_()});import{basename as Cu,resolve as Gm}from"node:path";async function yr(r){let{workspaces:n,cwd:f,workspaceFlag:m,allWorkspaces:t}=r;if(t)return{mode:"all",workspaces:n};if(!m||m==="auto"){let y=Em(n,f);if(y)return{mode:"nearest",workspaces:[y]};let x=n[0];if(x)return{mode:"nearest",workspaces:[x],note:"No workspace contains cwd; falling back to first workspace"};return{mode:"nearest",workspaces:[]}}let u=n.find((y)=>y.name===m);if(u)return{mode:"explicit",workspaces:[u]};let $=k(Gm(f,m));if(await Q($)){let y=z(n,$);if(y)return{mode:"explicit",workspaces:[y]}}throw Error(`Workspace not found: ${m}`)}function Em(r,n){let f=k(n),m;for(let t of r)if(V(f,t.root)){if(!m||t.root.length>m.root.length)m=t}return m}function z(r,n){let f=k(n),m;for(let t of r)if(V(f,t.root)){if(!m||t.root.length>m.root.length)m=t}return m}var xr=J(()=>{_();D()});import{join as kn}from"node:path";async function b(r,n){let f=kn(r,".repo-slicerc.json"),m=n?kn(n,".repo-slicerc.json"):void 0,t=await An(f)??{},u=m&&m!==f?await An(m)??{}:{};return{config:Un(Un(Lm,t),u),sources:{repoConfigPath:await Q(f)?f:void 0,workspaceConfigPath:m&&await Q(m)?m:void 0}}}function Un(r,n){return{...r,...n,ignore:n.ignore??r.ignore,includeTests:n.includeTests??r.includeTests,workspaces:{...r.workspaces,...n.workspaces,pythonImportRoots:n.workspaces?.pythonImportRoots??r.workspaces.pythonImportRoots},redact:{...r.redact,...n.redact,patterns:n.redact?.patterns??r.redact.patterns}}}async function An(r){if(!await Q(r))return;try{return await nr(r)}catch(n){throw Error(`Failed to parse config: ${r}`)}}var Lm;var Hr=J(()=>{D();Lm={budgetChars:28000,depth:2,includeTests:"auto",ignore:["**/dist/**","**/.next/**","**/build/**","**/*.snap"],workspaces:{mode:"auto",pythonImportRoots:["src","."]},redact:{enabled:!1,patterns:["BEGIN PRIVATE KEY","AWS_SECRET_ACCESS_KEY","API_KEY=","SECRET_KEY="]}}});import{join as wr,relative as Wm}from"node:path";import Km from"ignore";async function i(r){let n=Km();if(n.add("node_modules/"),r.extraIgnorePatterns?.length)n.add(r.extraIgnorePatterns);if(await Gr(n,wr(r.repoRoot,".gitignore")),await Gr(n,wr(r.repoRoot,".repo-sliceignore")),r.workspaceRoot&&r.workspaceRoot!==r.repoRoot)await Gr(n,wr(r.workspaceRoot,".gitignore")),await Gr(n,wr(r.workspaceRoot,".repo-sliceignore"));return{ignores:(f)=>{let m=B(Wm(r.repoRoot,f));return n.ignores(m)}}}async function Gr(r,n){if(!await Q(n))return;let f=await S(n);r.add(f.split(/\r?\n/))}var qr=J(()=>{D();_()});function km(r){return r.split(/\r?\n/)}function Um(r,n){let f=km(r),m=Math.max(1,n.startLine),t=Math.min(f.length,n.endLine);return f.slice(m-1,t).join(`
|
|
4
|
+
`)}async function o(r,n){let f=await S(r);return Um(f,n)}var Er=J(()=>{D()});import Z from"typescript";function In(r,n,f){let m=[],t=r.getTypeChecker(),u=f?.files?new Set(f.files.map((y)=>k(y))):null,$=f?.symbolFilter?new Set(f.symbolFilter):null;for(let y of r.getSourceFiles()){let x=k(y.fileName);if(!V(x,n))continue;if(u&&!u.has(x))continue;let w=(G,E)=>{let W=Am(G,E);if(Z.isCallExpression(G)||Z.isNewExpression(G)){let U=Im(G,y,t,x,W);if(U){if(!$||$.has(U.calleeSymbol))m.push(U)}}G.forEachChild((U)=>w(U,W))};w(y)}return m}function Am(r,n){if(Z.isFunctionDeclaration(r)&&r.name)return r.name.text;if(Z.isMethodDeclaration(r)&&Z.isIdentifier(r.name)){let f=r.parent;if(Z.isClassDeclaration(f)&&f.name)return`${f.name.text}.${r.name.text}`;return r.name.text}if(Z.isArrowFunction(r)||Z.isFunctionExpression(r)){let f=r.parent;if(Z.isVariableDeclaration(f)&&Z.isIdentifier(f.name))return f.name.text;if(Z.isPropertyAssignment(f)&&Z.isIdentifier(f.name))return f.name.text}if(Z.isConstructorDeclaration(r)){let f=r.parent;if(Z.isClassDeclaration(f)&&f.name)return`${f.name.text}.constructor`}return n}function Im(r,n,f,m,t){let u=r.expression,$,y=1,x=!1;if(Z.isIdentifier(u)){if($=Tm(u,f),!$)$=u.text,y=0.8}else if(Z.isPropertyAccessExpression(u)){if($=Jm(u,f),!$)$=Tn(u),y=0.6,x=!0}else if(Z.isElementAccessExpression(u))$="[dynamic]",y=0.3,x=!0;else return null;if(!$)return null;let w=Ym(n,r.getStart(),r.getEnd());return{callerFile:m,callerSymbol:t,calleeSymbol:$,range:w,confidence:y,isDynamic:x}}function Tm(r,n){try{let f=n.getSymbolAtLocation(r);if(!f)return;let m=f.getDeclarations();if(!m||m.length===0)return;let t=m[0],u=t.getSourceFile();if(Z.isFunctionDeclaration(t)&&t.name)return`${Lr(u.fileName)}#${t.name.text}`;if(Z.isVariableDeclaration(t)&&Z.isIdentifier(t.name)){if(t.initializer&&(Z.isFunctionExpression(t.initializer)||Z.isArrowFunction(t.initializer)))return`${Lr(u.fileName)}#${t.name.text}`}if(Z.isClassDeclaration(t)&&t.name)return`${Lr(u.fileName)}#${t.name.text}`;return r.text}catch{return}}function Jm(r,n){try{let f=n.getSymbolAtLocation(r);if(!f)return;let m=f.getDeclarations();if(!m||m.length===0)return;let t=m[0];if(Z.isMethodDeclaration(t)&&Z.isIdentifier(t.name)){let x=t.parent;if(Z.isClassDeclaration(x)&&x.name){let w=t.getSourceFile();return`${Lr(w.fileName)}#${x.name.text}.${t.name.text}`}}let u=n.getTypeAtLocation(r.expression),$=n.typeToString(u),y=r.name.text;if($&&$!=="any"&&!$.includes("typeof"))return`${$}.${y}`;return Tn(r)}catch{return}}function Tn(r){let n=[],f=r;while(Z.isPropertyAccessExpression(f))n.unshift(f.name.text),f=f.expression;if(Z.isIdentifier(f))n.unshift(f.text);else n.unshift("[expr]");return n.join(".")}function Lr(r){let f=k(r).split("/"),m=f.findIndex((t)=>t==="src");if(m>=0)return f.slice(m).join("/");return f.slice(-2).join("/")}function Ym(r,n,f){let m=r.getLineAndCharacterOfPosition(n),t=r.getLineAndCharacterOfPosition(f);return{startLine:m.line+1,endLine:t.line+1}}var Jn=J(()=>{_()});import P from"typescript";import{join as Yn}from"node:path";import{mkdir as Zm,readFile as Sr,writeFile as Qm}from"node:fs/promises";import{createHash as Bm}from"node:crypto";async function Bn(r){try{let n=await Sr(r);return Bm("sha256").update(n).digest("hex")}catch{return null}}async function Xm(r){let n=Yn(r,Qn);if(!await Q(n))return null;try{let f=await Sr(n,"utf8"),m=JSON.parse(f);if(m.version!==Zn)return null;return m}catch{return null}}async function Cm(r,n){await Zm(r,{recursive:!0});let f=Yn(r,Qn);await Qm(f,JSON.stringify(n,null,2))}async function _m(r,n){let f=[],m=[],t=[],u=[],$=new Set(r.fileList),y=new Set(n);for(let x of n)if(!$.has(x))m.push(x);for(let x of r.fileList)if(!y.has(x))t.push(x);for(let x of n){if(!$.has(x))continue;let w=await Bn(x),G=r.fileHashes[x];if(w!==G)f.push(x);else u.push(x)}return{changed:f,added:m,removed:t,unchanged:u}}async function Om(r){let n={},f=50;for(let m=0;m<r.length;m+=50){let t=r.slice(m,m+50),u=await Promise.all(t.map(async($)=>({file:$,hash:await Bn($)})));for(let{file:$,hash:y}of u)if(y)n[$]=y}return n}async function Xn(r,n,f){let m=await Xm(f),t=m?await _m(m,n):{changed:[],added:n,removed:[],unchanged:[]},u=t.changed.length+t.added.length,$=t.unchanged.length,y={allowJs:!0,jsx:P.JsxEmit.Preserve,target:P.ScriptTarget.ES2020,module:P.ModuleKind.NodeNext,moduleResolution:P.ModuleResolutionKind.NodeNext,skipLibCheck:!0,skipDefaultLibCheck:!0},x=P.createCompilerHost(y,!0),w=x.getSourceFile,G=new Map;for(let L of t.unchanged)if(m?.fileHashes[L])try{let X=await Sr(L,"utf8")}catch{}let E=P.createProgram(n,y,x),W={getScriptFileNames:()=>n,getScriptVersion:(L)=>{let I=k(L);if(t.unchanged.includes(I))return"0";return Date.now().toString()},getScriptSnapshot:(L)=>{let I=P.sys.readFile(L);if(I===void 0)return;return P.ScriptSnapshot.fromString(I)},getCurrentDirectory:()=>r,getCompilationSettings:()=>y,getDefaultLibFileName:(L)=>P.getDefaultLibFilePath(L),fileExists:P.sys.fileExists,readFile:P.sys.readFile,readDirectory:P.sys.readDirectory,directoryExists:P.sys.directoryExists,getDirectories:P.sys.getDirectories},U=P.createLanguageService(W),K=await Om(n),A={version:Zn,workspaceRoot:r,fileList:n,fileHashes:K,compilerOptions:y,timestamp:Date.now()};return await Cm(f,A),{program:E,languageService:U,compilerOptions:y,isIncremental:m!==null&&u<n.length,stats:{totalFiles:n.length,changedFiles:u,reusedFiles:$}}}var Zn="1",Qn="ts-service-state.json";var Cn=J(()=>{D();_()});var _n={};h(_n,{buildTsAdapter:()=>Hm});import T from"typescript";import{join as Wr}from"node:path";import Dm from"fast-glob";async function Hm(r){let{workspace:n,ignoreMatcher:f}=r,m=r.files??await qm(n.root,f);if(m.length===0)return null;let t,u,$,y=!1,x={totalFiles:0,changedFiles:0,reusedFiles:0};if(r.enableIncremental&&r.cacheDir){let E=await Xn(n.root,m,r.cacheDir);t=E.program,u=E.languageService,$=E.compilerOptions,y=E.isIncremental,x=E.stats}else{let E=await Sm(n.root,m);t=E.program,u=E.languageService,$=E.compilerOptions}let w=r.cachedImportGraph??Pm(t,$,n.root),G=r.cachedCallExpressions;return{lang:"ts",workspace:n,files:m,importGraph:w,findSymbolDefinitions:(E)=>Promise.resolve(jm(t,$,n.root,E)),findSymbolReferences:(E,W)=>Rm(u,E,W),extractSnippet:(E,W)=>o(E,W),findCallExpressions:async(E)=>{if(G&&!E)return G;if(!G)G=In(t,n.root,E);return G},metadata:{ts:{callExpressions:G,isIncremental:y,incrementalStats:x}}}}async function qm(r,n){return(await Dm(["**/*.ts","**/*.tsx","**/*.js","**/*.jsx"],{cwd:r,absolute:!0,dot:!1,followSymbolicLinks:!1})).map((t)=>k(t)).filter((t)=>!n.ignores(t)).sort()}async function Sm(r,n){let f=await Q(Wr(r,"tsconfig.json"))?Wr(r,"tsconfig.json"):await Q(Wr(r,"tsconfig.base.json"))?Wr(r,"tsconfig.base.json"):void 0,m={allowJs:!0,jsx:T.JsxEmit.Preserve,target:T.ScriptTarget.ES2020,module:T.ModuleKind.NodeNext,moduleResolution:T.ModuleResolutionKind.NodeNext},t=n;if(f){let w=T.readConfigFile(f,T.sys.readFile);if(w.error)throw Error(T.formatDiagnosticsWithColorAndContext([w.error],{getCurrentDirectory:T.sys.getCurrentDirectory,getCanonicalFileName:(E)=>E,getNewLine:()=>`
|
|
5
|
+
`}));let G=T.parseJsonConfigFileContent(w.config,T.sys,r);m={...G.options,allowJs:!0},t=G.fileNames.map((E)=>k(E)).filter((E)=>V(E,r))}let u=T.createCompilerHost(m,!0),$=T.createProgram(t,m,u),y={getScriptFileNames:()=>t,getScriptVersion:()=>"0",getScriptSnapshot:(w)=>{let G=T.sys.readFile(w);if(G===void 0)return;return T.ScriptSnapshot.fromString(G)},getCurrentDirectory:()=>r,getCompilationSettings:()=>m,getDefaultLibFileName:(w)=>T.getDefaultLibFilePath(w),fileExists:T.sys.fileExists,readFile:T.sys.readFile,readDirectory:T.sys.readDirectory,directoryExists:T.sys.directoryExists,getDirectories:T.sys.getDirectories},x=T.createLanguageService(y);return{program:$,languageService:x,compilerOptions:m}}function Pm(r,n,f){let m=new Map,t=T.createCompilerHost(n,!0);for(let u of r.getSourceFiles()){let $=k(u.fileName);if(!V($,f))continue;if(!zm.some((w)=>$.endsWith(w)))continue;if(!m.has($))m.set($,new Map);let y=m.get($),x=Vm(u);for(let w of x){if(!w.startsWith(".")&&!w.startsWith("/"))continue;let G=T.resolveModuleName(w,$,n,t);if(G.resolvedModule){let E=k(G.resolvedModule.resolvedFileName);if(V(E,f))y.set(E,"imports")}}}return m}function Vm(r){let n=[],f=new Set,m=(u)=>{if(!f.has(u))f.add(u),n.push(u)};for(let u of r.statements){let $;if(T.isImportDeclaration(u)&&u.moduleSpecifier){if(T.isStringLiteral(u.moduleSpecifier))$=u.moduleSpecifier.text}else if(T.isExportDeclaration(u)&&u.moduleSpecifier){if(T.isStringLiteral(u.moduleSpecifier))$=u.moduleSpecifier.text}if($)m($)}let t=(u)=>{if(T.isCallExpression(u)&&u.expression.kind===T.SyntaxKind.ImportKeyword){let[$]=u.arguments;if($&&T.isStringLiteral($))m($.text)}T.forEachChild(u,t)};return T.forEachChild(r,t),n}function jm(r,n,f,m){let t=[],u=r.getTypeChecker();for(let $ of r.getSourceFiles()){let y=k($.fileName);if(!V(y,f))continue;let x=(w)=>{if(T.isFunctionDeclaration(w)&&w.name){if(w.name.text===m){let G=fr($,w.getStart(),w.getEnd());t.push({filePath:y,range:G,kind:"definition",lang:"ts",symbolName:m})}}else if(T.isClassDeclaration(w)&&w.name){if(w.name.text===m){let G=fr($,w.getStart(),w.getEnd());t.push({filePath:y,range:G,kind:"definition",lang:"ts",symbolName:m})}}else if(T.isInterfaceDeclaration(w)&&w.name){if(w.name.text===m){let G=fr($,w.getStart(),w.getEnd());t.push({filePath:y,range:G,kind:"definition",lang:"ts",symbolName:m})}}else if(T.isTypeAliasDeclaration(w)&&w.name){if(w.name.text===m){let G=fr($,w.getStart(),w.getEnd());t.push({filePath:y,range:G,kind:"definition",lang:"ts",symbolName:m})}}else if(T.isVariableStatement(w)){for(let G of w.declarationList.declarations)if(T.isIdentifier(G.name)&&G.name.text===m){let E=fr($,w.getStart(),w.getEnd());t.push({filePath:y,range:E,kind:"definition",lang:"ts",symbolName:m})}}w.forEachChild(x)};x($)}return t}async function Rm(r,n,f){let m=n.filePath,t=r.getReferencesAtPosition(m,Nm(m,n.range.startLine));if(!t)return[];let u=[],$=new Set(f?.anchorFiles?.map((x)=>k(x))??[]);for(let x of t){let w=k(x.fileName);if(w===m&&x.isDefinition)continue;let G=r.getProgram()?.getSourceFile(w);if(!G)continue;let E=cm(G,x.textSpan);u.push({filePath:w,range:E,kind:"reference",lang:"ts"})}let y=f?.limit??10;return u.slice(0,y)}function Nm(r,n){return(n-1)*50}function fr(r,n,f){let m=r.getLineAndCharacterOfPosition(n),t=r.getLineAndCharacterOfPosition(f);return{startLine:m.line+1,endLine:t.line+1}}function cm(r,n){let f=r.getLineAndCharacterOfPosition(n.start),m=r.getLineAndCharacterOfPosition(n.start+n.length);return{startLine:f.line+1,endLine:m.line+1}}var zm;var On=J(()=>{D();Er();_();Jn();Cn();zm=[".ts",".tsx",".js",".jsx",".d.ts"]});import bm from"tree-sitter";import Fm from"tree-sitter-python";import{relative as mr}from"node:path";async function Dn(r,n){let f=new bm;f.setLanguage(Fm);let m=[],t=n?.files?new Set(n.files.map(($)=>k($))):null,u=n?.symbolFilter?new Set(n.symbolFilter):null;for(let[$,y]of r.fileContents.entries()){if(t&&!t.has($))continue;let w=f.parse(y).rootNode.descendantsOfType(["call"]);for(let G of w){let E=await Mm(G,$,r);if(E){if(!u||u.has(E.calleeSymbol))m.push(E)}}}return m}async function Mm(r,n,f){let m=r.childForFieldName("function");if(!m)return null;let t,u=0.7,$=!1,y=gm(r);if(m.type==="identifier"){t=m.text;let w=hm(m.text,n,f);if(w)t=w,u=0.9}else if(m.type==="attribute"){let w=m.childForFieldName("object"),G=m.childForFieldName("attribute");if(G)if(w?.type==="identifier"){let E=pm(w.text,G.text,n,f);if(E)t=E,u=0.8;else t=`${w.text}.${G.text}`,u=0.5,$=!0}else if(w?.type==="call")t=`[call].${G.text}`,u=0.3,$=!0;else if(w?.type==="attribute")t=`${im(w)}.${G.text}`,u=0.4,$=!0;else t=`[expr].${G.text}`,u=0.2,$=!0}else if(m.type==="subscript")t="[subscript]",u=0.1,$=!0;else return null;if(!t)return null;let x=om(r);return{callerFile:n,callerSymbol:y,calleeSymbol:t,range:x,confidence:u,isDynamic:$}}function gm(r){let n=r.parent;while(n){if(n.type==="function_definition"){let f=n.childForFieldName("name");if(f){let m=vm(n);if(m)return`${m}.${f.text}`;return f.text}}n=n.parent}return}function vm(r){let n=r.parent;while(n){if(n.type==="class_definition"){let f=n.childForFieldName("name");if(f)return f.text}n=n.parent}return}function hm(r,n,f){let m=f.definitions.get(n);if(m){let t=m.find((u)=>u.name===r);if(t){let u=B(mr(f.workspaceRoot,n));if(t.className)return`${u}#${t.className}.${t.name}`;return`${u}#${t.name}`}}for(let[t,u]of f.moduleMap.entries()){let $=f.definitions.get(u);if($){let y=$.find((x)=>x.name===r);if(y)return`${B(mr(f.workspaceRoot,u))}#${y.name}`}}return}function pm(r,n,f,m){if(r==="self"||r==="cls"){let u=sm(f,m);if(u)return`${B(mr(m.workspaceRoot,f))}#${u}.${n}`}let t=m.definitions.get(f);if(t){if(t.find(($)=>$.kind==="class"&&$.name===r))return`${B(mr(m.workspaceRoot,f))}#${r}.${n}`}for(let[,u]of m.moduleMap.entries()){let $=m.definitions.get(u);if($){if($.find((x)=>x.kind==="class"&&x.name===r))return`${B(mr(m.workspaceRoot,u))}#${r}.${n}`}}return}function sm(r,n){return}function im(r){let n=[],f=r;while(f)if(f.type==="attribute"){let m=f.childForFieldName("attribute");if(m)n.unshift(m.text);f=f.childForFieldName("object")}else if(f.type==="identifier"){n.unshift(f.text);break}else{n.unshift("[expr]");break}return n.join(".")}function om(r){return{startLine:r.startPosition.row+1,endLine:r.endPosition.row+1}}var zn=J(()=>{_()});var Vn={};h(Vn,{buildPythonAdapter:()=>em});import qn from"tree-sitter";import Sn from"tree-sitter-python";import lm from"fast-glob";import{join as dm,relative as am}from"node:path";async function em(r){let{workspace:n,ignoreMatcher:f,pythonImportRoots:m}=r,t=r.files??await rt(n.root,f);if(t.length===0)return null;let u=await nt(n,t,m,r.cachedModuleMap,r.cachedDefinitions,r.cachedImportGraph),$=r.cachedCallExpressions;return{lang:"py",workspace:n,files:u.files,importGraph:u.importGraph,findSymbolDefinitions:(y)=>Promise.resolve(wt(u,y)),findSymbolReferences:(y,x)=>{return Et(u,y,x)},extractSnippet:(y,x)=>o(y,x),findCallExpressions:async(y)=>{if($&&!y)return $;let x=new Map;for(let[w,G]of u.parsedFiles.entries())x.set(w,G.text);return $=await Dn({workspaceRoot:n.root,fileContents:x,definitions:u.definitions,moduleMap:u.moduleMap},y),$},metadata:{py:{moduleMap:u.moduleMap,definitions:u.definitions,callExpressions:$}}}}async function rt(r,n){return(await lm(["**/*.py"],{cwd:r,absolute:!0,dot:!1,followSymbolicLinks:!1})).map((m)=>k(m)).filter((m)=>!n.ignores(m)).sort()}async function nt(r,n,f,m,t,u){let $=new qn;$.setLanguage(Sn);let y=m??new Map,x=new Map,w=t??new Map,G=new Map,E=new Map,W=50;for(let K=0;K<n.length;K+=W){let A=n.slice(K,K+W);await Promise.all(A.map(async(L)=>{let I=x.get(L);if(!I){if(I=ft(r.root,L,f),I){if(!y.has(I))y.set(I,L);x.set(L,I)}}let X=await S(L),O=$.parse(X),Y;if(t?.has(L))Y=t.get(L);else Y=mt(O.rootNode),w.set(L,Y);for(let H of Y){let C=E.get(H.name);if(C)C.add(L);else E.set(H.name,new Set([L]))}Pn(O.rootNode,E,L),G.set(L,{filePath:L,text:X,tree:O,definitions:Y})}))}let U=u??await $t(r,n,x,y,G);for(let K of G.values())K.tree=void 0;return{workspace:r,files:n,moduleMap:y,fileModules:x,definitions:w,parsedFiles:G,nameIndex:E,importGraph:U}}function Pn(r,n,f){if(r.type==="identifier"){let m=r.text,t=n.get(m);if(t)t.add(f);else n.set(m,new Set([f]))}if(r.type==="attribute"){let m=r.childForFieldName("attribute");if(m){let t=m.text,u=n.get(t);if(u)u.add(f);else n.set(t,new Set([f]))}}for(let m of r.namedChildren)Pn(m,n,f)}function ft(r,n,f){let m=k(n);for(let t of f){let u=k(dm(r,t));if(!V(m,u))continue;let $=am(u,m);$=$.replace(/\.py$/,"");let y=B($).split("/");if(y[y.length-1]==="__init__")y.pop();let x=y.filter(Boolean).join(".");if(x)return x}return}function mt(r){let n=[],f=(m,t)=>{if(m.type==="decorated_definition"){let u=m.namedChildren.find(($)=>["function_definition","class_definition"].includes($.type));if(u){let $=Pr(u,m,t);if($)n.push($);if(u.type==="class_definition"&&$){let y={name:$.name,kind:"class",range:$.range,className:$.name,classRange:$.range},x=u.childForFieldName("body");if(x)for(let w of x.namedChildren)f(w,y)}}return}if(m.type==="class_definition"){let u=Pr(m,m,t);if(u){n.push(u);let $={name:u.name,kind:"class",range:u.range,className:u.name,classRange:u.range},y=m.childForFieldName("body");if(y)for(let x of y.namedChildren)f(x,$)}return}if(m.type==="function_definition"){if(m.parent?.type==="decorated_definition")return;let u=Pr(m,m,t);if(u)n.push(u);return}for(let u of m.namedChildren)f(u,t)};return f(r),n}function Pr(r,n,f){let m=r.childForFieldName("name");if(!m)return null;let t=tt(n);if(f&&r.type==="function_definition")return{name:m.text,kind:"method",range:t,className:f.name,classRange:f.range};if(r.type==="class_definition")return{name:m.text,kind:"class",range:t};return{name:m.text,kind:"function",range:t}}function tt(r){return{startLine:r.startPosition.row+1,endLine:r.endPosition.row+1}}async function $t(r,n,f,m,t){let u=new Map,$=(y,x,w)=>{let G=u.get(y);if(!G)G=new Map,u.set(y,G);let E=G.get(x);if(!E||E==="imports-dynamic"&&w==="imports")G.set(x,w)};for(let y of n){if(!u.has(y))u.set(y,new Map);let x=t.get(y);if(!x)continue;let{tree:w,text:G}=x,E=f.get(y),W=w.rootNode.descendantsOfType(["import_statement","import_from_statement"]);for(let K of W){let A=ut(K,E);for(let L of A){let I=Hn(L,m);if(!I)continue;if(!V(I,r.root))continue;$(y,I,"imports")}}let U=w.rootNode.descendantsOfType(["call"]);for(let K of U){let A=K.childForFieldName("function");if(!A)continue;let L=!1,I=null;if(A.type==="attribute"){let X=A.childForFieldName("object"),O=A.childForFieldName("attribute");if(X?.type==="identifier"&&X.text==="importlib"&&O?.text==="import_module"){L=!0;let Y=K.childForFieldName("arguments");if(Y&&Y.namedChildren.length>0)I=Y.namedChildren[0]}}if(A.type==="identifier"&&A.text==="__import__"){L=!0;let X=K.childForFieldName("arguments");if(X&&X.namedChildren.length>0)I=X.namedChildren[0]}if(L&&I&&I.type==="string"){let O=I.text.match(/^["'](.+)["']$/);if(O){let Y=O[1],H=Hn(Y,m);if(H&&V(H,r.root))$(y,H,"imports-dynamic")}}}}return u}function ut(r,n){if(r.type==="import_statement")return r.namedChildren.filter((f)=>f.type==="dotted_name").map((f)=>f.text);if(r.type==="import_from_statement"){let f="",m=0;for(let x of r.namedChildren){if(x.type==="dotted_name")f=x.text;if(x.type==="relative_import")m=x.text.length}let t=yt(n,m),u=t?f?`${t}.${f}`:t:f,$=r.namedChildren.filter((x)=>x.type==="import_list").flatMap((x)=>x.namedChildren.filter((w)=>w.type==="dotted_name"||w.type==="identifier").map((w)=>w.text)),y=[u].filter(Boolean);for(let x of $)if(u)y.push(`${u}.${x}`);return y}return[]}function yt(r,n){if(!r||n<=0)return r;let f=r.split(".");if(f.length<n)return;return f.slice(0,f.length-n).join(".")}function Hn(r,n){if(n.has(r))return n.get(r);let f=r.split(".");while(f.length>1){f.pop();let m=f.join(".");if(n.has(m))return n.get(m)}return}function xt(r,n){let f,m=n;if(n.includes(":")){let[y,x]=n.split(":",2);f=y,m=x}else{let y=n.split(".");for(let x=y.length-1;x>=1;x-=1){let w=y.slice(0,x).join(".");if(r.has(w)){f=w,m=y.slice(x).join(".");break}}}let t=m.split("."),u,$;if(t.length>=2)u=t[0],$=t.slice(1).join(".");return{moduleHint:f,symbolQuery:m,className:u,memberName:$}}function wt(r,n){let{moduleHint:f,symbolQuery:m,className:t,memberName:u}=xt(r.moduleMap,n),$=[],y=f?[r.moduleMap.get(f)].filter(Boolean):r.files;for(let x of y){let w=r.definitions.get(x)??[];for(let G of w){if(t&&u){if(G.kind==="method"&&G.className===t&&G.name===u){if($.push({filePath:x,range:G.range,kind:"definition",lang:"py",symbolName:`${t}.${u}`}),G.classRange)$.push({filePath:x,range:Gt(G.classRange,3),kind:"context",lang:"py",symbolName:G.className})}continue}if(G.name===m)$.push({filePath:x,range:G.range,kind:"definition",lang:"py",symbolName:G.name})}}return $}function Gt(r,n){return{startLine:r.startLine,endLine:Math.min(r.endLine,r.startLine+n-1)}}async function Et(r,n,f){let m=n.symbolName?.split(".").slice(-1)[0]??n.symbolName??"";if(!m)return[];let t=r.nameIndex.get(m);if(!t||t.size===0)return[];let u=[],$=new qn;$.setLanguage(Sn);for(let w of t){let G=r.parsedFiles.get(w);if(!G)continue;let{text:E}=G,W=E.split(/\r?\n/),U=new Set,A=$.parse(E).rootNode.descendantsOfType(["identifier","attribute"]);for(let L of A)if(L.type==="identifier"&&L.text===m)U.add(L.startPosition.row+1);else if(L.type==="attribute"){let I=L.childForFieldName("attribute")??L.namedChildren[L.namedChildren.length-1];if(I?.text===m)U.add(I.startPosition.row+1)}if(U.size===0)continue;for(let L of U)u.push({filePath:w,range:{startLine:Math.max(1,L-2),endLine:Math.min(W.length,L+2)},kind:"reference",lang:"py"})}let y=Lt(u,f?.anchorFiles??[],n.filePath),x=f?.limit??10;return y.slice(0,x)}function Lt(r,n,f){let m=new Set(n.map((u)=>k(u))),t=k(f);return r.map((u)=>{let $=k(u.filePath),y=0;if($===t)y+=60;if(m.has($))y+=30;return{ref:u,score:y}}).sort((u,$)=>{if(u.score!==$.score)return $.score-u.score;if(u.ref.filePath!==$.ref.filePath)return u.ref.filePath.localeCompare($.ref.filePath);return u.ref.range.startLine-$.ref.range.startLine}).map((u)=>u.ref)}var jn=J(()=>{D();Er();_();zn()});async function Kr(r){let n=[];if(r.files?.tsFiles&&r.files.tsFiles.length>0){let{buildTsAdapter:f}=await Promise.resolve().then(() => (On(),_n)),m=await f({workspace:r.workspace,ignoreMatcher:r.ignoreMatcher,files:r.files.tsFiles,cachedImportGraph:r.cache?.tsImportGraph,cachedCallExpressions:r.cache?.tsCallExpressions,enableIncremental:r.enableIncremental,cacheDir:r.cacheDir});if(m)n.push(m)}if(r.files?.pyFiles&&r.files.pyFiles.length>0){let{buildPythonAdapter:f}=await Promise.resolve().then(() => (jn(),Vn)),m=await f({workspace:r.workspace,ignoreMatcher:r.ignoreMatcher,pythonImportRoots:r.pythonImportRoots,files:r.files.pyFiles,cachedModuleMap:r.cache?.pyModuleMap,cachedDefinitions:r.cache?.pyDefinitions,cachedImportGraph:r.cache?.pyImportGraph,cachedCallExpressions:r.cache?.pyCallExpressions});if(m)n.push(m)}return n}function R(r){if(r.toLowerCase().endsWith(".py"))return"py";return"ts"}import{stat as Wt}from"node:fs/promises";async function F(r){try{return(await Wt(r)).size}catch{return 0}}function M(r){return Math.max(1,r.endLine-r.startLine+1)*80}function Vr(r){if(r.kind==="snippet"&&r.range)return`${r.filePath}:${r.range.startLine}-${r.range.endLine}`;return`${r.filePath}:file`}function kr(r,n){let f=Vr(n),m=r.get(f);if(!m){r.set(f,{...n,id:f});return}m.score=Math.max(m.score,n.score),m.reasons=Array.from(new Set([...m.reasons,...n.reasons])),m.anchor=m.anchor||n.anchor}function Rn(r){return r.sort((n,f)=>{if(n.score!==f.score)return f.score-n.score;if(n.kind!==f.kind)return n.kind==="snippet"?-1:1;if(n.filePath!==f.filePath)return n.filePath.localeCompare(f.filePath);if(n.range&&f.range)return n.range.startLine-f.range.startLine;if(n.range)return-1;if(f.range)return 1;return 0})}function Ur(r){let n=Math.min(200,Math.floor(r.estimatedChars/1000)*10);return{...r,score:r.score-n}}var Ar=()=>{};import{execFile as Kt}from"node:child_process";import{promisify as kt}from"node:util";import{join as Ut}from"node:path";async function l(r,n){let{stdout:f}=await At("git",["diff",n,"-U3","--no-color"],{cwd:r});return It(f,r)}function It(r,n){let f=[],m=null;for(let t of r.split(/\r?\n/)){if(t.startsWith("+++ ")){let u=t.replace("+++ ","").trim();if(u==="/dev/null"){m=null;continue}let $=u.startsWith("b/")?u.slice(2):u;m=k(Ut(n,$));continue}if(t.startsWith("@@")&&m){let u=t.match(/\+(\d+)(?:,(\d+))?/);if(!u)continue;let $=Number(u[1]),y=u[2]?Number(u[2]):1,x=y===0?$:$+y-1;f.push({filePath:m,range:{startLine:$,endLine:x}})}}return f}var At;var Ir=J(()=>{_();At=kt(Kt)});import{join as Tt,isAbsolute as Jt}from"node:path";function d(r,n){let f=[],m=new Set,t=(u,$)=>{let y=Ot(u,n),x=`${y}:${$}`;if(!m.has(x))m.add(x),f.push({filePath:y,range:{startLine:Math.max(1,$-3),endLine:$+3}})};for(let u of r.split(/\r?\n/)){let $=u.match(Bt);if($){t($[1],Number($[3]));continue}let y=u.match(Xt);if(y){let U=y[3]?Number(y[3]):1;t(y[1],U);continue}let x=u.match(Ct);if(x){t(x[1],Number(x[2]));continue}let w=u.match(_t);if(w){t(w[1],Number(w[2]));continue}let G=u.match(Qt);if(G){t(G[1],Number(G[2]));continue}let E=u.match(Yt);if(E){t(E[1],Number(E[3]));continue}let W=u.match(Zt);if(W)t(W[1],Number(W[2]))}return f}function Ot(r,n){if(Jt(r))return k(r);return k(Tt(n,r))}var Yt,Zt,Qt,Bt,Xt,Ct,_t;var Tr=J(()=>{_();Yt=/([A-Za-z0-9_\-./\\]+?\.(tsx|ts|jsx|js)):(\d+)(?::(\d+))?/,Zt=/([A-Za-z0-9_\-./\\]+?\.py):(\d+)(?::(\d+))?/,Qt=/File "([^"]+\.py)", line (\d+)/,Bt=/at .+? \(([^)]+?\.(tsx|ts|jsx|js)):(\d+):(\d+)\)/,Xt=/(?:FAIL|PASS|❯|›)\s+([A-Za-z0-9_\-./\\]+?\.(tsx|ts|jsx|js))(?::(\d+))?/,Ct=/([A-Za-z0-9_\-./\\]+?\.py):(\d+):\s*(?:error|warning|note):/,_t=/([A-Za-z0-9_\-./\\]+?\.py):(\d+):(\d+)\s*-\s*(?:error|warning|information):/});import{resolve as Dt,isAbsolute as zt}from"node:path";async function a(r){let n=[],f=new Set,m=[],t=[];for(let u of r.entries){let $=k(zt(u)?u:Dt(r.cwd,u)),y=z(r.workspaces,$);if(!y)continue;let x=await F($);n.push({id:"",kind:"file",lang:R($),workspaceId:y.id,workspaceRoot:y.root,filePath:$,score:Nn,reasons:["entry file"],estimatedChars:x,anchor:!0}),f.add($)}for(let u of r.symbols){let $=await Pt(r.adapters,u);if($.length===0){m.push(u);continue}if($.length>1)t.push({query:u,definitions:$.map((y)=>({filePath:y.filePath,range:y.range}))});for(let y of $){let x=z(r.workspaces,y.filePath);if(!x)continue;if(n.push({id:"",kind:"snippet",lang:y.lang,workspaceId:x.id,workspaceRoot:x.root,filePath:y.filePath,range:y.range,score:y.kind==="context"?cn:Ht,reasons:[`defines-symbol ${u}`],estimatedChars:M(y.range),anchor:!0}),f.add(y.filePath),y.kind!=="definition")continue;let w=await Vt(r.adapters,y,f);for(let G of w){let E=z(r.workspaces,G.filePath);if(!E)continue;n.push({id:"",kind:"snippet",lang:G.lang,workspaceId:E.id,workspaceRoot:E.root,filePath:G.filePath,range:G.range,score:cn,reasons:[`references ${u}`],estimatedChars:M(G.range)}),f.add(G.filePath)}}}if(r.fromDiff){let u=r.diffHunks??await l(r.repoRoot,r.fromDiff),$=new Set;for(let y of u){let x=z(r.workspaces,y.filePath);if(!x)continue;n.push({id:"",kind:"snippet",lang:R(y.filePath),workspaceId:x.id,workspaceRoot:x.root,filePath:y.filePath,range:y.range,score:St,reasons:["diff hunk"],estimatedChars:M(y.range),anchor:!0}),f.add(y.filePath),$.add(y.filePath)}for(let y of $){let x=z(r.workspaces,y);if(!x)continue;let w=await F(y);n.push({id:"",kind:"file",lang:R(y),workspaceId:x.id,workspaceRoot:x.root,filePath:y,score:Nn,reasons:["diff file"],estimatedChars:w})}}if(r.fromLog){let u=r.logAnchors??d(await S(r.fromLog),r.repoRoot);for(let $ of u){let y=z(r.workspaces,$.filePath);if(!y)continue;n.push({id:"",kind:"snippet",lang:R($.filePath),workspaceId:y.id,workspaceRoot:y.root,filePath:$.filePath,range:$.range,score:qt,reasons:["diagnostic"],estimatedChars:M($.range),anchor:!0}),f.add($.filePath)}}return{candidates:n,anchorFiles:f,unresolvedSymbols:m,ambiguousSymbols:t}}async function Pt(r,n){let f=[];for(let m of r){let t=await m.findSymbolDefinitions(n);f.push(...t)}return f}async function Vt(r,n,f){let m=r.find((u)=>u.lang===n.lang&&n.filePath.startsWith(u.workspace.root));if(!m)return[];return await m.findSymbolReferences(n,{limit:10,anchorFiles:Array.from(f)})}var Nn=800,Ht=1000,cn=700,qt=950,St=850;var jr=J(()=>{D();_();Ar();xr();Ir();Tr()});import{dirname as jt,join as bn,basename as Rt,extname as Nt}from"node:path";import ct from"fast-glob";async function Fn(r){let n=[],f=new Map;for(let t of r.adapters)for(let u of t.files)f.set(u,t);for(let t of r.anchorFiles){let u=f.get(t);if(!u)continue;let $=u.importGraph,y=new Set([t]),x=[{file:t,distance:0}];while(x.length>0){let G=x.shift();if(!G)break;let E=G.distance+1;if(E>r.depth)continue;let W=$.get(G.file);if(!W)continue;let U=Array.from(W.keys()).sort();for(let K of U){if(y.has(K))continue;y.add(K),x.push({file:K,distance:E});let A=await F(K),I=W.get(K)==="imports-dynamic";n.push({id:"",kind:"file",lang:R(K),workspaceId:u.workspace.id,workspaceRoot:u.workspace.root,filePath:K,score:bt[E]??Ft,reasons:[I?`dynamic-import-distance ${E}`:`import-distance ${E}`],estimatedChars:A})}}let w=await ht(t);if(w){let G=await F(w);n.push({id:"",kind:"file",lang:R(w),workspaceId:u.workspace.id,workspaceRoot:u.workspace.root,filePath:w,score:Mt,reasons:["barrel file"],estimatedChars:G})}if(r.includeTests!=="false"){if(r.includeTests==="true"||/[\\/](src|lib)[\\/]/.test(t)){let E=r.ignoreMatchers.get(u.workspace.id)??r.ignoreMatchers.values().next().value,W=await pt(u.workspace.root,t,E);for(let U of W){let K=await F(U);n.push({id:"",kind:"file",lang:R(U),workspaceId:u.workspace.id,workspaceRoot:u.workspace.root,filePath:U,score:vt,reasons:["related test"],estimatedChars:K})}}}}let m=await st(r.workspaces);for(let t of m){let u=await F(t.filePath);n.push({id:"",kind:"file",lang:R(t.filePath),workspaceId:t.workspace.id,workspaceRoot:t.workspace.root,filePath:t.filePath,score:gt,reasons:["config booster"],estimatedChars:u})}return n}async function ht(r){let n=jt(r),f=["index.ts","index.tsx","index.js","index.jsx"];for(let m of f){let t=bn(n,m);if(await Q(t))return t}return null}async function pt(r,n,f){let m=Rt(n,Nt(n)),t=[`**/${m}.test.*`,`**/${m}.spec.*`,`**/test_${m}.*`];return(await ct(t,{cwd:r,absolute:!0,dot:!1,followSymbolicLinks:!1})).map(($)=>k($)).filter(($)=>!f.ignores($)).sort()}async function st(r){let n=["next.config.js","next.config.mjs","next.config.ts","next-env.d.ts","vite.config.ts","vite.config.js","svelte.config.js","remix.config.js"],f=[];for(let m of r)for(let t of n){let u=bn(m.root,t);if(await Q(u))f.push({workspace:m,filePath:u})}return f}var bt,Ft=50,Mt=120,gt=110,vt=100;var Mn=J(()=>{Ar();D();_();bt={1:250,2:150}});async function ot(r,n,f){let m=[];for(let t=0;t<r.length;t+=n){let u=r.slice(t,t+n),$=await Promise.all(u.map((y)=>f(y)));m.push(...$)}return m}async function lt(r){try{let n="";if(r.kind==="file")n=await S(r.filePath);else if(r.range)n=await o(r.filePath,r.range);let f=n.length,m=Math.ceil(f/4);return{success:!0,content:n,length:f,tokenEstimate:m}}catch{return{success:!1,error:"failed to read file"}}}async function gn(r){let{candidates:n,budgetChars:f,budgetTokens:m}=r,t=[],u=[],$=0,y=0,x=await ot(n,it,lt);for(let w=0;w<n.length;w++){let G=n[w],E=x[w];if(!E.success){u.push({id:G.id,filePath:G.filePath,kind:G.kind,range:G.range,reason:`${G.reasons.join("; ")}; ${E.error}`,score:G.score,estimatedChars:G.estimatedChars});continue}let{content:W,length:U,tokenEstimate:K}=E,A=$+U>f,L=m!==void 0&&y+K>m;if(A||L){u.push({id:G.id,filePath:G.filePath,kind:G.kind,range:G.range,reason:G.reasons.join("; "),score:G.score,estimatedChars:G.estimatedChars});continue}t.push({kind:G.kind,lang:G.lang,workspaceRoot:G.workspaceRoot,filePath:G.filePath,range:G.range,reasons:G.reasons,content:W}),$+=U,y+=K}return{items:t,omitted:u,usedChars:$,usedTokens:m!==void 0?y:void 0}}var it=10;var vn=J(()=>{Er();D()});import{relative as dt}from"node:path";function hn(r){let{meta:n,items:f,omitted:m,includeReasons:t}=r,u=[];if(u.push("# repo-slice bundle"),u.push(""),u.push(`- command: ${n.command}`),u.push(`- scope: ${n.scope.mode} (${n.scope.workspaces.join(", ")})`),u.push(`- budget: ${n.budget.usedChars}/${n.budget.chars} chars`),n.budget.tokens!==void 0&&n.budget.usedTokens!==void 0)u.push(`- tokens: ${n.budget.usedTokens}/${n.budget.tokens}`);if(n.note)u.push(`- note: ${n.note}`);if(n.generatedAt)u.push(`- generatedAt: ${n.generatedAt}`);if(u.push(""),u.push("## Index"),f.length===0)u.push("- (empty)");else for(let $ of f){let y=Jr(n.repoRoot,$.filePath),x=$.kind==="snippet"&&$.range?`:${$.range.startLine}-${$.range.endLine}`:"",w=t&&$.reasons.length?` (reasons: ${$.reasons.join(", ")})`:"";u.push(`- ${$.kind} ${y}${x}${w}`)}u.push(""),u.push("## Content");for(let $ of f){let y=Jr(n.repoRoot,$.filePath),x=$.kind==="snippet"&&$.range?`lines ${$.range.startLine}-${$.range.endLine}`:"full file";if(u.push(`### ${$.kind} ${y} (${x})`),u.push(`workspace: ${Jr(n.repoRoot,$.workspaceRoot)}`),t&&$.reasons.length)u.push(`reasons: ${$.reasons.join(", ")}`);u.push(""),u.push(`\`\`\`${at($.filePath)}`),u.push($.content),u.push("```"),u.push("")}if(t&&m.length>0){u.push("## Omitted (budget)");for(let $ of m){let y=Jr(n.repoRoot,$.filePath),x=$.kind==="snippet"&&$.range?`:${$.range.startLine}-${$.range.endLine}`:"";u.push(`- ${$.kind} ${y}${x} (score ${$.score}, est ${$.estimatedChars} chars) - ${$.reason}`)}u.push("")}return u.join(`
|
|
6
|
+
`)}function Jr(r,n){return B(dt(r,n))||"."}function at(r){let n=r.toLowerCase();if(n.endsWith(".tsx"))return"tsx";if(n.endsWith(".ts"))return"ts";if(n.endsWith(".jsx"))return"jsx";if(n.endsWith(".js"))return"js";if(n.endsWith(".py"))return"py";return"text"}var pn=J(()=>{_()});import{relative as et}from"node:path";function sn(r){let{meta:n,items:f,omitted:m}=r,t={meta:{...n,scope:{...n.scope,workspaces:n.scope.workspaces.map((u)=>u)}},items:f.map((u)=>({kind:u.kind,lang:u.lang,workspaceRoot:Rr(n.repoRoot,u.workspaceRoot),filePath:Rr(n.repoRoot,u.filePath),range:u.range,reasons:u.reasons,content:u.content})),omitted:m.map((u)=>({filePath:Rr(n.repoRoot,u.filePath),kind:u.kind,range:u.range,reason:u.reason,score:u.score,estimatedChars:u.estimatedChars}))};return JSON.stringify(t,null,2)}function Rr(r,n){return B(et(r,n))||"."}var on=J(()=>{_()});function ln(r,n){let f=r;for(let m of n){let t=r$(m);f=f.replace(t,"[REDACTED]")}return f}function r$(r){try{return new RegExp(r,"g")}catch{return new RegExp(n$(r),"g")}}function n$(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Yr(r){return{debug:(n)=>{if(!r)return;process.stderr.write(`[debug] ${n}
|
|
7
|
+
`)}}}import{createHash as f$}from"node:crypto";function Zr(r){return f$("sha1").update(r).digest("hex")}var Nr=()=>{};import{pack as m$,unpack as t$}from"msgpackr";function an(r){let n=m$(r),f=Buffer.alloc(cr);return $$.copy(f,0),f[4]=dn,f.writeUInt32LE(0,5),f.writeUInt32LE(n.length,9),f.writeUInt32LE(0,13),Buffer.concat([f,Buffer.from(n)])}function en(r){if(r.length<cr)return null;if(r.slice(0,4).toString()!=="RSCB")return null;if(r[4]!==dn)return null;let m=r.readUInt32LE(9),t=r.slice(cr);if(t.length!==m)console.warn("Cache size mismatch - possible corruption");try{return t$(t)}catch(u){return console.warn("Failed to unpack binary cache:",u),null}}function rf(r){if(typeof r==="string")return!1;if(r.length<4)return!1;return r.slice(0,4).toString()==="RSCB"}var $$,dn=1,cr=17;var nf=J(()=>{$$=Buffer.from("RSCB")});import{join as u$}from"node:path";import{readFile as y$,writeFile as ff,mkdir as x$,stat as w$}from"node:fs/promises";function tf(r){mf=r}async function $f(r){let n=yf(r.repoRoot,r.workspaceRoot,r.configHash,r.version);if(!await Q(n))return null;try{let f=await y$(n);if(rf(f)){let u=en(f);if(!u)return null;if(u.version!==r.version)return null;if(u.configHash!==r.configHash)return null;if(u.workspaceRoot!==r.workspaceRoot)return null;return u}let m=f.toString("utf8"),t=JSON.parse(m);if(t.version!==r.version)return null;if(t.configHash!==r.configHash)return null;if(t.workspaceRoot!==r.workspaceRoot)return null;return t}catch{return null}}async function uf(r){let n=yf(r.repoRoot,r.workspaceRoot,r.configHash,r.version),f=n.replace(/\/[^\/]+$/,"");if(await x$(f,{recursive:!0}),mf)await ff(n,JSON.stringify(r.cache,null,2),"utf8");else{let m=an(r.cache);await ff(n,m)}}function G$(r,n,f){return Zr(`${r}|${n}|${f}`)}function yf(r,n,f,m){let t=G$(n,f,m);return u$(r,".repo-slice","cache",t,"cache.bin")}function xf(r,n){if(r.files.length!==n.length)return!1;let f=new Map;for(let m of r.files)f.set(m.path,m);for(let m of n){let t=f.get(m.path);if(!t)return!1;if(t.mtimeMs!==m.mtimeMs)return!1;if(t.size!==m.size)return!1}return!0}function br(r){let n={};for(let[f,m]of r.entries()){let t={},u=Array.from(m.entries()).sort(($,y)=>$[0].localeCompare(y[0]));for(let[$,y]of u)t[$]=y;n[f]=t}return n}function Fr(r){let n=new Map;for(let[f,m]of Object.entries(r)){let t=new Map;if(Array.isArray(m))for(let u of m)t.set(u,"imports");else for(let[u,$]of Object.entries(m))t.set(u,$);n.set(f,t)}return n}async function wf(r){let f=[];for(let m=0;m<r.length;m+=50){let t=r.slice(m,m+50),u=await Promise.all(t.map(async($)=>{try{let y=await w$($);return{path:$,mtimeMs:y.mtimeMs,size:y.size}}catch{return null}}));f.push(...u.filter(($)=>$!==null))}return f}function Mr(r){return r.map((n)=>({callerFile:n.callerFile,callerSymbol:n.callerSymbol,calleeSymbol:n.calleeSymbol,range:n.range,confidence:n.confidence,isDynamic:n.isDynamic}))}function gr(r){return r.map((n)=>({callerFile:n.callerFile,callerSymbol:n.callerSymbol,calleeSymbol:n.calleeSymbol,range:n.range,confidence:n.confidence,isDynamic:n.isDynamic}))}var mf=!1;var Gf=J(()=>{D();Nr();nf()});import Ef from"fast-glob";import{resolve as vr,join as Wf}from"node:path";import{writeFile as E$}from"node:fs/promises";async function Kf(r){tf(r.debugCache??!1);let n=process.cwd(),f=await p(n),m=await s(f),{config:t}=await b(f),u=r.allWorkspaces??t.workspaces.mode==="all",$=r.workspace??t.workspaces.mode,y=await yr({workspaces:m,cwd:n,workspaceFlag:$==="all"?void 0:$,allWorkspaces:u}),x=y.mode;if(y.workspaces.length===0)throw Error("No workspaces detected");let w=y.workspaces[0],{config:G}=await b(f,w?.root),E=hr(G,r),W=r.includeTests??E.includeTests,U=r.budgetChars??E.budgetChars,K=r.budgetTokens,A=r.format??"json",L=Boolean(r.reason),I=r.redact===!0||E.redact.enabled,X=Yr(Boolean(r.debug)),O=r.fromDiff?await l(f,r.fromDiff):void 0,Y=r.fromLog?vr(n,r.fromLog):void 0,H=Y?d(await S(Y),f):void 0,C=L$({allWorkspaces:m,baseWorkspaces:y.workspaces,cwd:n,entries:r.entries,diffHunks:O,logAnchors:H}),e=await Lf({repoRoot:f,workspaces:C,args:r,logger:X}),v=K$(e,y.workspaces),N=await a({repoRoot:f,cwd:n,workspaces:C,adapters:v,entries:r.entries,symbols:r.symbols,fromDiff:r.fromDiff,fromLog:Y??r.fromLog,diffHunks:O,logAnchors:H});if(N.unresolvedSymbols.length>0&&r.fallbackAll&&!r.allWorkspaces)X.debug("Symbol not found in scope; retrying across all workspaces"),C=m,x="all",e=await Lf({repoRoot:f,workspaces:C,args:r,logger:X}),v=e,N=await a({repoRoot:f,cwd:n,workspaces:C,adapters:v,entries:r.entries,symbols:r.symbols,fromDiff:r.fromDiff,fromLog:Y??r.fromLog,diffHunks:O,logAnchors:H});if(N.unresolvedSymbols.length>0)process.stderr.write(`Symbol(s) not found: ${N.unresolvedSymbols.join(", ")}
|
|
8
|
+
`),process.stderr.write(`Try --all-workspaces or --fallback-all
|
|
9
|
+
`),process.exit(2);if(r.symbolStrict&&N.ambiguousSymbols.length>0){process.stderr.write(`Ambiguous symbol(s) found (--symbol-strict enabled):
|
|
10
|
+
`);for(let q of N.ambiguousSymbols){process.stderr.write(` ${q.query}:
|
|
11
|
+
`);for(let tn of q.definitions){let gf=tn.filePath.replace(f+"/","");process.stderr.write(` - ${gf}:${tn.range.startLine}
|
|
12
|
+
`)}}process.stderr.write(`Use file-hint syntax (e.g., path/to/file.ts:SymbolName) to disambiguate.
|
|
13
|
+
`),process.exit(2)}let c=new Map;for(let q of N.candidates)kr(c,Ur(q));let tr=await W$({repoRoot:f,workspaces:C,args:r}),Xr=await Fn({adapters:e,workspaces:C,anchorFiles:N.anchorFiles,depth:r.depth??E.depth,includeTests:W,ignoreMatchers:tr});for(let q of Xr)kr(c,Ur(q));k$(c,U);let Mf=Rn(Array.from(c.values())),rr=await gn({candidates:Mf,budgetChars:U,budgetTokens:K}),Cr=L?rr.items:rr.items.map((q)=>({...q,reasons:[]})),nn=L?rr.omitted:[];if(I)for(let q of Cr)q.content=ln(q.content,E.redact.patterns);let fn={repoRoot:f,generatedAt:r.noTimestamp?void 0:new Date().toISOString(),command:`repo-slice ${process.argv.slice(2).join(" ")}`,scope:{mode:x,workspaces:C.map((q)=>q.id)},budget:{chars:U,usedChars:rr.usedChars,tokens:K,usedTokens:rr.usedTokens},note:L?y.note:void 0},mn=A==="json"?sn({meta:fn,items:Cr,omitted:nn}):hn({meta:fn,items:Cr,omitted:nn,includeReasons:L});if(r.out){let q=vr(n,r.out);await E$(q,mn,"utf8")}else process.stdout.write(mn+`
|
|
14
|
+
`)}function hr(r,n){return{...r,budgetChars:n.budgetChars??r.budgetChars,depth:n.depth??r.depth,includeTests:n.includeTests??r.includeTests,redact:{...r.redact,enabled:n.redact===!0?!0:r.redact.enabled}}}function L$(r){let n=new Map;for(let f of r.baseWorkspaces)n.set(f.root,f);for(let f of r.entries){let m=vr(r.cwd,f),t=z(r.allWorkspaces,m);if(t)n.set(t.root,t)}for(let f of r.diffHunks??[]){let m=z(r.allWorkspaces,f.filePath);if(m)n.set(m.root,m)}for(let f of r.logAnchors??[]){let m=z(r.allWorkspaces,f.filePath);if(m)n.set(m.root,m)}return Array.from(n.values()).sort((f,m)=>f.root.localeCompare(m.root))}async function Lf(r){let n=await I$(r.repoRoot),f=await Promise.all(r.workspaces.map(async(m)=>{let{config:t}=await b(r.repoRoot,m.root),u=hr(t,r.args);r.logger.debug(`Indexing workspace ${m.root}`);let $=await i({repoRoot:r.repoRoot,workspaceRoot:m.root,extraIgnorePatterns:u.ignore}),y=await U$(m.root,$),x=[...y.tsFiles,...y.pyFiles].sort(),w=await wf(x),G=A$(u),E=await $f({repoRoot:r.repoRoot,workspaceRoot:m.root,configHash:G,version:n}),U=(E?xf(E,w):!1)?T$(E):void 0,K=Wf(r.repoRoot,".repo-slice","cache",G,"ts-service"),A=await Kr({workspace:m,ignoreMatcher:$,pythonImportRoots:u.workspaces.pythonImportRoots,files:y,cache:U,enableIncremental:!0,cacheDir:K});return{adapters:A,cache:{workspace:m,cache:E,version:n,configHash:G,stats:w,adapters:A}}}));return await Promise.all(f.map(({cache:m})=>uf({repoRoot:r.repoRoot,workspaceRoot:m.workspace.root,configHash:m.configHash,version:m.version,cache:J$(m)}))),f.flatMap((m)=>m.adapters)}async function W$(r){let n=await Promise.all(r.workspaces.map(async(m)=>{let{config:t}=await b(r.repoRoot,m.root),u=hr(t,r.args),$=await i({repoRoot:r.repoRoot,workspaceRoot:m.root,extraIgnorePatterns:u.ignore});return{id:m.id,matcher:$}})),f=new Map;for(let{id:m,matcher:t}of n)f.set(m,t);return f}function K$(r,n){let f=new Set(n.map((m)=>m.root));return r.filter((m)=>f.has(m.workspace.root))}function k$(r,n){for(let m of r.values()){if(m.kind!=="file"||!m.anchor)continue;if(m.estimatedChars<=n/2)continue;let t={id:"",kind:"snippet",lang:m.lang,workspaceId:m.workspaceId,workspaceRoot:m.workspaceRoot,filePath:m.filePath,range:{startLine:1,endLine:80},score:m.score-200,reasons:[...m.reasons,"header snippet"],estimatedChars:M({startLine:1,endLine:80})};kr(r,Ur(t))}for(let m of r.values())m.id=Vr(m)}async function U$(r,n){let f=await Ef(["**/*.ts","**/*.tsx","**/*.js","**/*.jsx"],{cwd:r,absolute:!0,dot:!1,followSymbolicLinks:!1}),m=await Ef(["**/*.py"],{cwd:r,absolute:!0,dot:!1,followSymbolicLinks:!1});return{tsFiles:f.map((t)=>k(t)).filter((t)=>!n.ignores(t)).sort(),pyFiles:m.map((t)=>k(t)).filter((t)=>!n.ignores(t)).sort()}}function A$(r){return Zr(JSON.stringify({ignore:r.ignore,pythonImportRoots:r.workspaces.pythonImportRoots}))}async function I$(r){let n=await S(Wf(r,"package.json"));try{return JSON.parse(n).version??"0.0.0"}catch{return"0.0.0"}}function T$(r){return{tsImportGraph:r.ts?Fr(r.ts.importGraph):void 0,tsCallExpressions:r.ts?.callExpressions?gr(r.ts.callExpressions):void 0,pyModuleMap:r.py?new Map(Object.entries(r.py.moduleMap)):void 0,pyDefinitions:r.py?new Map(Object.entries(r.py.definitions)):void 0,pyImportGraph:r.py?Fr(r.py.importGraph):void 0,pyCallExpressions:r.py?.callExpressions?gr(r.py.callExpressions):void 0}}function J$(r){let n=r.adapters.find((u)=>u.lang==="ts"),f=r.adapters.find((u)=>u.lang==="py"),m=f?.metadata?.py,t=n?.metadata?.ts;return{version:r.version,workspaceRoot:r.workspace.root,configHash:r.configHash,files:r.stats,ts:n?{importGraph:br(n.importGraph),callExpressions:t?.callExpressions?Mr(t.callExpressions):void 0}:void 0,py:f&&m?{moduleMap:Object.fromEntries(m.moduleMap.entries()),definitions:Object.fromEntries(m.definitions.entries()),importGraph:br(f.importGraph),callExpressions:m?.callExpressions?Mr(m.callExpressions):void 0}:void 0}}var kf=J(()=>{$r();ur();xr();Hr();qr();jr();Ir();Tr();Ar();Mn();vn();pn();on();D();_();Gf();Nr()});var Uf={};h(Uf,{packCommand:()=>Y$});async function Y$(r){let n;try{n=Z$(r)}catch(m){let t=m instanceof Error?m.message:String(m);process.stderr.write(`${t}
|
|
15
|
+
`),process.stderr.write(sr()+`
|
|
16
|
+
`),process.exit(3);return}if(n.help)process.stdout.write(sr()+`
|
|
17
|
+
`),process.exit(0);let{args:f}=n;if(f.entries.length===0&&f.symbols.length===0&&!f.fromDiff&&!f.fromLog){process.stderr.write(`Error: No anchors specified.
|
|
18
|
+
`),process.stderr.write(`Use --entry, --symbol, --from-diff, or --from-log to specify what to include.
|
|
19
|
+
|
|
20
|
+
`),process.stderr.write(sr()+`
|
|
21
|
+
`),process.exit(3);return}await Kf(f)}function Z$(r){let n={entries:[],symbols:[]},f=!1,m=(t,u)=>{let $=r[t+1];if(!$||$.startsWith("--"))throw Error(`Missing value for ${u}`);return $};for(let t=0;t<r.length;t+=1){let u=r[t];if(u==="--help"||u==="-h"){f=!0;continue}if(!u.startsWith("--"))throw Error(`Unexpected argument: ${u}`);let[$,y]=u.split("=",2);switch($){case"--entry":if(n.entries.push(y??m(t,$)),!y)t+=1;break;case"--symbol":if(n.symbols.push(y??m(t,$)),!y)t+=1;break;case"--symbol-strict":n.symbolStrict=!0;break;case"--from-diff":if(n.fromDiff=y??m(t,$),!y)t+=1;break;case"--from-log":if(n.fromLog=y??m(t,$),!y)t+=1;break;case"--workspace":if(n.workspace=y??m(t,$),!y)t+=1;break;case"--all-workspaces":n.allWorkspaces=!0;break;case"--fallback-all":n.fallbackAll=!0;break;case"--depth":if(n.depth=pr(y??m(t,$),$),!y)t+=1;break;case"--budget-chars":if(n.budgetChars=pr(y??m(t,$),$),!y)t+=1;break;case"--budget-tokens":if(n.budgetTokens=pr(y??m(t,$),$),!y)t+=1;break;case"--include-tests":{let x=y??m(t,$);if(!y)t+=1;if(!["auto","true","false"].includes(x))throw Error(`Invalid include-tests value: ${x}`);n.includeTests=x;break}case"--format":{let x=y??m(t,$);if(!y)t+=1;if(!["md","json"].includes(x))throw Error(`Invalid format: ${x}`);n.format=x;break}case"--out":if(n.out=y??m(t,$),!y)t+=1;break;case"--reason":n.reason=!0;break;case"--redact":n.redact=!0;break;case"--debug":n.debug=!0;break;case"--debug-cache":n.debugCache=!0;break;case"--no-timestamp":n.noTimestamp=!0;break;default:throw Error(`Unknown flag: ${$}`)}}return{help:f,args:n}}function pr(r,n){let f=Number(r);if(!Number.isFinite(f)||f<0||!Number.isInteger(f))throw Error(`Invalid number for ${n}: ${r}`);return f}function sr(){return`repo-slice pack - create a bundle from a codebase
|
|
3
22
|
|
|
4
23
|
Usage:
|
|
5
24
|
repo-slice pack [options]
|
|
6
|
-
repo-slice graph [options]
|
|
7
|
-
repo-slice workspaces
|
|
8
|
-
repo-slice version
|
|
9
25
|
|
|
10
|
-
|
|
11
|
-
--entry <
|
|
12
|
-
--symbol <
|
|
13
|
-
--symbol-strict
|
|
14
|
-
--from-diff <
|
|
15
|
-
--from-log <path>
|
|
16
|
-
--workspace <auto|name|path>
|
|
17
|
-
--all-workspaces
|
|
18
|
-
--fallback-all
|
|
19
|
-
--depth <n>
|
|
20
|
-
--budget-chars <n>
|
|
21
|
-
--budget-tokens <n>
|
|
22
|
-
--include-tests <auto|true|false>
|
|
23
|
-
--format <md|json>
|
|
24
|
-
--out <path>
|
|
25
|
-
--reason
|
|
26
|
-
--redact
|
|
27
|
-
--debug
|
|
28
|
-
--no-timestamp
|
|
26
|
+
Anchor options:
|
|
27
|
+
--entry <file> Entry file(s) to include
|
|
28
|
+
--symbol <name> Symbol(s) to anchor on
|
|
29
|
+
--symbol-strict Only include files that define the symbol
|
|
30
|
+
--from-diff <rev> Include files changed since git revision
|
|
31
|
+
--from-log <path> Parse error log for file paths
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
--
|
|
32
|
-
--
|
|
33
|
-
--
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
--
|
|
37
|
-
--
|
|
38
|
-
--
|
|
39
|
-
--include-tests <auto
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
--
|
|
43
|
-
--
|
|
44
|
-
--
|
|
45
|
-
--
|
|
46
|
-
--no-timestamp
|
|
33
|
+
Scope options:
|
|
34
|
+
--workspace <dir> Target workspace directory
|
|
35
|
+
--all-workspaces Include all detected workspaces
|
|
36
|
+
--fallback-all Fallback to all workspaces if none detected
|
|
37
|
+
|
|
38
|
+
Expansion options:
|
|
39
|
+
--depth <n> Import traversal depth (default: 2)
|
|
40
|
+
--budget-chars <n> Character budget (default: 28000)
|
|
41
|
+
--budget-tokens <n> Token budget (optional)
|
|
42
|
+
--include-tests <mode> Test inclusion: auto, true, false (default: auto)
|
|
43
|
+
|
|
44
|
+
Output options:
|
|
45
|
+
--format <json|md> Output format (default: json)
|
|
46
|
+
--out <path> Write to file instead of stdout
|
|
47
|
+
--reason Include reason annotations
|
|
48
|
+
--redact Redact sensitive patterns
|
|
49
|
+
--no-timestamp Exclude timestamp from output
|
|
50
|
+
|
|
51
|
+
Debug options:
|
|
52
|
+
--debug Enable verbose logging
|
|
53
|
+
--debug-cache Use JSON cache format (human readable)
|
|
54
|
+
--help, -h Show this help message
|
|
47
55
|
|
|
48
56
|
Exit codes:
|
|
49
57
|
0 success
|
|
50
58
|
1 runtime error
|
|
51
|
-
2 anchor resolution failure
|
|
52
59
|
3 invalid CLI usage
|
|
53
|
-
`}import{
|
|
54
|
-
`)}
|
|
55
|
-
`}));let w=G.parseJsonConfigFileContent(i.config,G.sys,n);f={...w.options,allowJs:!0},c=w.fileNames.map((x)=>I(x)).filter((x)=>Q(x,n))}let u=G.createCompilerHost(f,!0),m=G.createProgram(c,f,u),s={getScriptFileNames:()=>c,getScriptVersion:()=>"0",getScriptSnapshot:(i)=>{let w=G.sys.readFile(i);if(w===void 0)return;return G.ScriptSnapshot.fromString(w)},getCurrentDirectory:()=>n,getCompilationSettings:()=>f,getDefaultLibFileName:(i)=>G.getDefaultLibFilePath(i),fileExists:G.sys.fileExists,readFile:G.sys.readFile,readDirectory:G.sys.readDirectory,directoryExists:G.sys.directoryExists,getDirectories:G.sys.getDirectories},$=G.createLanguageService(s);return{program:m,languageService:$,compilerOptions:f}}function nf(n,r,t){let f=new Map,c=G.createCompilerHost(r,!0),u=new Set(n.getSourceFiles().map((i)=>i.fileName)),m=(i,w,x)=>{let E=f.get(i);if(!E)E=new Map,f.set(i,E);let k=E.get(w);if(!k||k==="imports-dynamic"&&x==="imports")E.set(w,x)},s=(i,w)=>{let x=G.resolveModuleName(i,w,r,c).resolvedModule?.resolvedFileName??rf(w,i);if(!x)return;let E=I(x);if(!Q(E,t))return;if(!u.has(E)&&!On(E))return;return E},$=(i)=>{if(G.isStringLiteral(i))return i.text;if(G.isNoSubstitutionTemplateLiteral(i))return i.text;return};for(let i of n.getSourceFiles()){let w=I(i.fileName);if(!Q(w,t))continue;if(!f.has(w))f.set(w,new Map);let x=(E)=>{if(G.isImportDeclaration(E)||G.isExportDeclaration(E)){let k=E.moduleSpecifier;if(k){let y=$(k);if(y){let L=s(y,w);if(L)m(w,L,"imports")}}}if(G.isImportEqualsDeclaration(E)){let k=E.moduleReference;if(G.isExternalModuleReference(k)&&k.expression){let y=$(k.expression);if(y){let L=s(y,w);if(L)m(w,L,"imports-dynamic")}}}if(G.isCallExpression(E)){let k=E.expression;if(k.kind===G.SyntaxKind.ImportKeyword){let y=E.arguments[0];if(y){let L=$(y);if(L){let T=s(L,w);if(T)m(w,T,"imports-dynamic")}}}if(G.isIdentifier(k)&&k.text==="require"){let y=E.arguments[0];if(y){let L=$(y);if(L){let T=s(L,w);if(T)m(w,T,"imports-dynamic")}}}}if(G.isImportTypeNode(E)){let k=E.argument;if(G.isLiteralTypeNode(k)&&k.literal){let y=$(k.literal);if(y){let L=s(y,w);if(L)m(w,L,"imports")}}}G.forEachChild(E,x)};x(i)}return f}function rf(n,r){if(!r.startsWith("."))return;let t=I(j(Zn(n),r));for(let f of Gr){let c=t.endsWith(f)?t:`${t}${f}`;if(On(c))return c}for(let f of Gr){let c=j(t,`index${f}`);if(On(c))return c}return}function On(n){return G.sys.fileExists(n)}function tf(n,r,t,f){let{fileHint:c,symbolQuery:u,className:m,memberName:s,isDefault:$}=cf(f),i=[],w=ff(n,t,c);for(let x of w){if(m&&s){let E=uf(x,m,s);i.push(...E);continue}if($)i.push(...sf(x));i.push(...$f(x,u))}return i}function ff(n,r,t){let f=n.getSourceFiles().filter((u)=>Q(u.fileName,r));if(!t)return f;let c=I(j(r,t));return f.filter((u)=>I(u.fileName)===c)}function cf(n){let r,t=n;if(n.includes(":")){let[s,$]=n.split(":",2);if(mf(s))r=s,t=$}let f=t.split("."),c=t==="default",u,m;if(f.length>=2)u=f.slice(0,-1).join("."),m=f[f.length-1];return{fileHint:r,symbolQuery:t,className:u,memberName:m,isDefault:c}}function mf(n){return n.includes("/")||n.includes("\\")||n.endsWith(".ts")||n.endsWith(".tsx")||n.endsWith(".js")||n.endsWith(".jsx")}function uf(n,r,t){let f=[],c=(u)=>{if(G.isClassDeclaration(u)&&u.name?.text===r){for(let m of u.members)if((G.isMethodDeclaration(m)||G.isPropertyDeclaration(m)||G.isGetAccessor(m)||G.isSetAccessor(m))&&m.name&&G.isIdentifier(m.name)&&m.name.text===t){let s=tn(n,u.getStart(),m.getEnd());f.push({filePath:n.fileName,range:s,kind:"definition",lang:"ts",symbolPosition:m.name.getStart(),symbolName:`${r}.${t}`})}}u.forEachChild(c)};return c(n),f}function sf(n){let r=[];return n.forEachChild((t)=>{if(G.isExportAssignment(t))r.push({filePath:n.fileName,range:tn(n,t.getStart(),t.getEnd()),kind:"definition",lang:"ts",symbolPosition:t.getStart(),symbolName:"default"});if((G.isClassDeclaration(t)||G.isFunctionDeclaration(t))&&t.modifiers?.some((f)=>f.kind===G.SyntaxKind.DefaultKeyword))r.push({filePath:n.fileName,range:tn(n,t.getStart(),t.getEnd()),kind:"definition",lang:"ts",symbolPosition:t.name?.getStart(),symbolName:t.name?.text??"default"})}),r}function $f(n,r){let t=[];return n.forEachChild((f)=>{if((G.isFunctionDeclaration(f)||G.isClassDeclaration(f)||G.isInterfaceDeclaration(f)||G.isTypeAliasDeclaration(f)||G.isEnumDeclaration(f))&&f.name?.text===r)t.push({filePath:n.fileName,range:tn(n,f.getStart(),f.getEnd()),kind:"definition",lang:"ts",symbolPosition:f.name?.getStart(),symbolName:r});if(G.isVariableStatement(f)){for(let c of f.declarationList.declarations)if(G.isIdentifier(c.name)&&c.name.text===r)t.push({filePath:n.fileName,range:tn(n,f.getStart(),f.getEnd()),kind:"definition",lang:"ts",symbolPosition:c.name.getStart(),symbolName:r})}}),t}function tn(n,r,t){let f=n.getLineAndCharacterOfPosition(r).line+1,c=n.getLineAndCharacterOfPosition(t).line+1;return{startLine:f,endLine:c}}async function xf(n,r,t){let f=r.filePath,c=r.symbolPosition??0,u=n.findReferences(f,c)??[],m=[];for(let i of u)for(let w of i.references){if(w.isDefinition)continue;let x=wf(w.fileName,w.textSpan);m.push({filePath:w.fileName,range:x,kind:"reference",lang:"ts"})}let s=Ef(m,t?.anchorFiles??[]),$=t?.limit??10;return s.slice(0,$)}function wf(n,r){let t=G.sys.readFile(n)??"",f=G.createSourceFile(n,t,G.ScriptTarget.ES2020,!0),c=f.getLineAndCharacterOfPosition(r.start).line+1,u=f.getLineAndCharacterOfPosition(r.start+r.length).line+1,m=2;return{startLine:Math.max(1,c-2),endLine:Math.max(c,u+2)}}function Ef(n,r){let t=new Set(r.map((c)=>I(c))),f=new Set(r.map((c)=>Zn(I(c))));return n.map((c)=>{let u=I(c.filePath),m=0;if(t.has(u))m+=50;if(f.has(Zn(u)))m+=20;return{ref:c,score:m}}).sort((c,u)=>{if(c.score!==u.score)return u.score-c.score;if(c.ref.filePath!==u.ref.filePath)return c.ref.filePath.localeCompare(u.ref.filePath);return c.ref.range.startLine-u.ref.range.startLine}).map((c)=>c.ref)}var Gr;var Lr=C(()=>{Y();yn();B();kr();Gr=[".ts",".tsx",".js",".jsx",".d.ts"]});import yf from"tree-sitter";import kf from"tree-sitter-python";import{relative as fn}from"node:path";async function Cr(n,r){let t=new yf;t.setLanguage(kf);let f=[],c=r?.files?new Set(r.files.map((m)=>I(m))):null,u=r?.symbolFilter?new Set(r.symbolFilter):null;for(let[m,s]of n.fileContents.entries()){if(c&&!c.has(m))continue;let i=t.parse(s).rootNode.descendantsOfType(["call"]);for(let w of i){let x=await Gf(w,m,n);if(x){if(!u||u.has(x.calleeSymbol))f.push(x)}}}return f}async function Gf(n,r,t){let f=n.childForFieldName("function");if(!f)return null;let c,u=0.7,m=!1,s=If(n);if(f.type==="identifier"){c=f.text;let i=Cf(f.text,r,t);if(i)c=i,u=0.9}else if(f.type==="attribute"){let i=f.childForFieldName("object"),w=f.childForFieldName("attribute");if(w)if(i?.type==="identifier"){let x=Tf(i.text,w.text,r,t);if(x)c=x,u=0.8;else c=`${i.text}.${w.text}`,u=0.5,m=!0}else if(i?.type==="call")c=`[call].${w.text}`,u=0.3,m=!0;else if(i?.type==="attribute")c=`${Af(i)}.${w.text}`,u=0.4,m=!0;else c=`[expr].${w.text}`,u=0.2,m=!0}else if(f.type==="subscript")c="[subscript]",u=0.1,m=!0;else return null;if(!c)return null;let $=Wf(n);return{callerFile:r,callerSymbol:s,calleeSymbol:c,range:$,confidence:u,isDynamic:m}}function If(n){let r=n.parent;while(r){if(r.type==="function_definition"){let t=r.childForFieldName("name");if(t){let f=Lf(r);if(f)return`${f}.${t.text}`;return t.text}}r=r.parent}return}function Lf(n){let r=n.parent;while(r){if(r.type==="class_definition"){let t=r.childForFieldName("name");if(t)return t.text}r=r.parent}return}function Cf(n,r,t){let f=t.definitions.get(r);if(f){let c=f.find((u)=>u.name===n);if(c){let u=A(fn(t.workspaceRoot,r));if(c.className)return`${u}#${c.className}.${c.name}`;return`${u}#${c.name}`}}for(let[c,u]of t.moduleMap.entries()){let m=t.definitions.get(u);if(m){let s=m.find(($)=>$.name===n);if(s)return`${A(fn(t.workspaceRoot,u))}#${s.name}`}}return}function Tf(n,r,t,f){if(n==="self"||n==="cls"){let u=hf(t,f);if(u)return`${A(fn(f.workspaceRoot,t))}#${u}.${r}`}let c=f.definitions.get(t);if(c){if(c.find((m)=>m.kind==="class"&&m.name===n))return`${A(fn(f.workspaceRoot,t))}#${n}.${r}`}for(let[,u]of f.moduleMap.entries()){let m=f.definitions.get(u);if(m){if(m.find(($)=>$.kind==="class"&&$.name===n))return`${A(fn(f.workspaceRoot,u))}#${n}.${r}`}}return}function hf(n,r){return}function Af(n){let r=[],t=n;while(t)if(t.type==="attribute"){let f=t.childForFieldName("attribute");if(f)r.unshift(f.text);t=t.childForFieldName("object")}else if(t.type==="identifier"){r.unshift(t.text);break}else{r.unshift("[expr]");break}return r.join(".")}function Wf(n){return{startLine:n.startPosition.row+1,endLine:n.endPosition.row+1}}var Tr=C(()=>{B()});var Sr={};b(Sr,{buildPythonAdapter:()=>Uf});import Ar from"tree-sitter";import Wr from"tree-sitter-python";import Sf from"fast-glob";import{join as Kf,relative as Bf}from"node:path";async function Uf(n){let{workspace:r,ignoreMatcher:t,pythonImportRoots:f}=n,c=n.files??await _f(r.root,t);if(c.length===0)return null;let u=await Yf(r,c,f,n.cachedModuleMap,n.cachedDefinitions,n.cachedImportGraph);return{lang:"py",workspace:r,files:u.files,importGraph:u.importGraph,findSymbolDefinitions:(m)=>Promise.resolve(Pf(u,m)),findSymbolReferences:(m,s)=>{let $=new Ar;return $.setLanguage(Wr),qf(u,m,s,$)},extractSnippet:(m,s)=>l(m,s),findCallExpressions:async(m)=>Cr({workspaceRoot:r.root,fileContents:u.fileContents,definitions:u.definitions,moduleMap:u.moduleMap},m),metadata:{py:{moduleMap:u.moduleMap,definitions:u.definitions}}}}async function _f(n,r){return(await Sf(["**/*.py"],{cwd:n,absolute:!0,dot:!1,followSymbolicLinks:!1})).map((f)=>I(f)).filter((f)=>!r.ignores(f)).sort()}async function Yf(n,r,t,f,c,u){let m=new Ar;m.setLanguage(Wr);let s=f??new Map,$=new Map,i=c??new Map,w=new Map;for(let E of r){let k=$.get(E);if(!k){if(k=Jf(n.root,E,t),k){if(!s.has(k))s.set(k,E);$.set(E,k)}}let y=await D(E);if(w.set(E,y),!i.has(E)){let L=m.parse(y),T=Zf(L.rootNode);i.set(E,T)}}let x=u??await Df(n,r,w,$,s,m);return{workspace:n,files:r,moduleMap:s,fileModules:$,definitions:i,fileContents:w,importGraph:x}}function Jf(n,r,t){let f=I(r);for(let c of t){let u=I(Kf(n,c));if(!Q(f,u))continue;let m=Bf(u,f);m=m.replace(/\.py$/,"");let s=A(m).split("/");if(s[s.length-1]==="__init__")s.pop();let $=s.filter(Boolean).join(".");if($)return $}return}function Zf(n){let r=[],t=(f,c)=>{if(f.type==="decorated_definition"){let u=f.namedChildren.find((m)=>["function_definition","class_definition"].includes(m.type));if(u){let m=Dn(u,f,c);if(m)r.push(m);if(u.type==="class_definition"&&m){let s={name:m.name,kind:"class",range:m.range,className:m.name,classRange:m.range},$=u.childForFieldName("body");if($)for(let i of $.namedChildren)t(i,s)}}return}if(f.type==="class_definition"){let u=Dn(f,f,c);if(u){r.push(u);let m={name:u.name,kind:"class",range:u.range,className:u.name,classRange:u.range},s=f.childForFieldName("body");if(s)for(let $ of s.namedChildren)t($,m)}return}if(f.type==="function_definition"){if(f.parent?.type==="decorated_definition")return;let u=Dn(f,f,c);if(u)r.push(u);return}for(let u of f.namedChildren)t(u,c)};return t(n),r}function Dn(n,r,t){let f=n.childForFieldName("name");if(!f)return null;let c=Of(r);if(t&&n.type==="function_definition")return{name:f.text,kind:"method",range:c,className:t.name,classRange:t.range};if(n.type==="class_definition")return{name:f.text,kind:"class",range:c};return{name:f.text,kind:"function",range:c}}function Of(n){return{startLine:n.startPosition.row+1,endLine:n.endPosition.row+1}}async function Df(n,r,t,f,c,u){let m=new Map,s=($,i,w)=>{let x=m.get($);if(!x)x=new Map,m.set($,x);let E=x.get(i);if(!E||E==="imports-dynamic"&&w==="imports")x.set(i,w)};for(let $ of r){if(!m.has($))m.set($,new Map);let i=t.get($)??"",w=u.parse(i),x=f.get($),E=w.rootNode.descendantsOfType(["import_statement","import_from_statement"]);for(let y of E){let L=Xf(y,x);for(let T of L){let S=hr(T,c);if(!S)continue;if(!Q(S,n.root))continue;s($,S,"imports")}}let k=w.rootNode.descendantsOfType(["call"]);for(let y of k){let L=y.childForFieldName("function");if(!L)continue;let T=!1,S=null;if(L.type==="attribute"){let _=L.childForFieldName("object"),X=L.childForFieldName("attribute");if(_?.type==="identifier"&&_.text==="importlib"&&X?.text==="import_module"){T=!0;let K=y.childForFieldName("arguments");if(K&&K.namedChildren.length>0)S=K.namedChildren[0]}}if(L.type==="identifier"&&L.text==="__import__"){T=!0;let _=y.childForFieldName("arguments");if(_&&_.namedChildren.length>0)S=_.namedChildren[0]}if(T&&S&&S.type==="string"){let X=S.text.match(/^["'](.+)["']$/);if(X){let K=X[1],P=hr(K,c);if(P&&Q(P,n.root))s($,P,"imports-dynamic")}}}}return m}function Xf(n,r){if(n.type==="import_statement")return n.namedChildren.filter((t)=>t.type==="dotted_name").map((t)=>t.text);if(n.type==="import_from_statement"){let t="",f=0;for(let $ of n.namedChildren){if($.type==="dotted_name")t=$.text;if($.type==="relative_import")f=$.text.length}let c=Qf(r,f),u=c?t?`${c}.${t}`:c:t,m=n.namedChildren.filter(($)=>$.type==="import_list").flatMap(($)=>$.namedChildren.filter((i)=>i.type==="dotted_name"||i.type==="identifier").map((i)=>i.text)),s=[u].filter(Boolean);for(let $ of m)if(u)s.push(`${u}.${$}`);return s}return[]}function Qf(n,r){if(!n||r<=0)return n;let t=n.split(".");if(t.length<r)return;return t.slice(0,t.length-r).join(".")}function hr(n,r){if(r.has(n))return r.get(n);let t=n.split(".");while(t.length>1){t.pop();let f=t.join(".");if(r.has(f))return r.get(f)}return}function zf(n,r){let t,f=r;if(r.includes(":")){let[s,$]=r.split(":",2);t=s,f=$}else{let s=r.split(".");for(let $=s.length-1;$>=1;$-=1){let i=s.slice(0,$).join(".");if(n.has(i)){t=i,f=s.slice($).join(".");break}}}let c=f.split("."),u,m;if(c.length>=2)u=c[0],m=c.slice(1).join(".");return{moduleHint:t,symbolQuery:f,className:u,memberName:m}}function Pf(n,r){let{moduleHint:t,symbolQuery:f,className:c,memberName:u}=zf(n.moduleMap,r),m=[],s=t?[n.moduleMap.get(t)].filter(Boolean):n.files;for(let $ of s){let i=n.definitions.get($)??[];for(let w of i){if(c&&u){if(w.kind==="method"&&w.className===c&&w.name===u){if(m.push({filePath:$,range:w.range,kind:"definition",lang:"py",symbolName:`${c}.${u}`}),w.classRange)m.push({filePath:$,range:Hf(w.classRange,3),kind:"context",lang:"py",symbolName:w.className})}continue}if(w.name===f)m.push({filePath:$,range:w.range,kind:"definition",lang:"py",symbolName:w.name})}}return m}function Hf(n,r){return{startLine:n.startLine,endLine:Math.min(n.endLine,n.startLine+r-1)}}async function qf(n,r,t,f){let c=r.symbolName?.split(".").slice(-1)[0]??r.symbolName??"";if(!c)return[];let u=[];for(let $ of n.files){let i=n.fileContents.get($)??"",w=f.parse(i),x=i.split(/\r?\n/),E=new Set,k=w.rootNode.descendantsOfType(["identifier","attribute"]);for(let y of k)if(y.type==="identifier"&&y.text===c)E.add(y.startPosition.row+1);else if(y.type==="attribute"){let L=y.childForFieldName("attribute")??y.namedChildren[y.namedChildren.length-1];if(L?.text===c)E.add(L.startPosition.row+1)}if(E.size===0)continue;for(let y of E)u.push({filePath:$,range:{startLine:Math.max(1,y-2),endLine:Math.min(x.length,y+2)},kind:"reference",lang:"py"})}let m=gf(u,t?.anchorFiles??[],r.filePath),s=t?.limit??10;return m.slice(0,s)}function gf(n,r,t){let f=new Set(r.map((u)=>I(u))),c=I(t);return n.map((u)=>{let m=I(u.filePath),s=0;if(m===c)s+=60;if(f.has(m))s+=30;return{ref:u,score:s}}).sort((u,m)=>{if(u.score!==m.score)return m.score-u.score;if(u.ref.filePath!==m.ref.filePath)return u.ref.filePath.localeCompare(m.ref.filePath);return u.ref.range.startLine-m.ref.range.startLine}).map((u)=>u.ref)}var Kr=C(()=>{Y();yn();B();Tr()});async function Gn(n){let r=[];if(n.files?.tsFiles&&n.files.tsFiles.length>0){let{buildTsAdapter:t}=await Promise.resolve().then(() => (Lr(),Ir)),f=await t({workspace:n.workspace,ignoreMatcher:n.ignoreMatcher,files:n.files.tsFiles,cachedImportGraph:n.cache?.tsImportGraph});if(f)r.push(f)}if(n.files?.pyFiles&&n.files.pyFiles.length>0){let{buildPythonAdapter:t}=await Promise.resolve().then(() => (Kr(),Sr)),f=await t({workspace:n.workspace,ignoreMatcher:n.ignoreMatcher,pythonImportRoots:n.pythonImportRoots,files:n.files.pyFiles,cachedModuleMap:n.cache?.pyModuleMap,cachedDefinitions:n.cache?.pyDefinitions,cachedImportGraph:n.cache?.pyImportGraph});if(f)r.push(f)}return r}function z(n){if(n.toLowerCase().endsWith(".py"))return"py";return"ts"}import{stat as Vf}from"node:fs/promises";async function V(n){try{return(await Vf(n)).size}catch{return 0}}function R(n){return Math.max(1,n.endLine-n.startLine+1)*80}function Xn(n){if(n.kind==="snippet"&&n.range)return`${n.filePath}:${n.range.startLine}-${n.range.endLine}`;return`${n.filePath}:file`}function In(n,r){let t=Xn(r),f=n.get(t);if(!f){n.set(t,{...r,id:t});return}f.score=Math.max(f.score,r.score),f.reasons=Array.from(new Set([...f.reasons,...r.reasons])),f.anchor=f.anchor||r.anchor}function Br(n){return n.sort((r,t)=>{if(r.score!==t.score)return t.score-r.score;if(r.kind!==t.kind)return r.kind==="snippet"?-1:1;if(r.filePath!==t.filePath)return r.filePath.localeCompare(t.filePath);if(r.range&&t.range)return r.range.startLine-t.range.startLine;if(r.range)return-1;if(t.range)return 1;return 0})}function Ln(n){let r=Math.min(200,Math.floor(n.estimatedChars/1000)*10);return{...n,score:n.score-r}}var Cn=()=>{};import{execFile as jf}from"node:child_process";import{promisify as Rf}from"node:util";import{join as pf}from"node:path";async function e(n,r){let{stdout:t}=await bf("git",["diff",r,"-U3","--no-color"],{cwd:n});return Mf(t,n)}function Mf(n,r){let t=[],f=null;for(let c of n.split(/\r?\n/)){if(c.startsWith("+++ ")){let u=c.replace("+++ ","").trim();if(u==="/dev/null"){f=null;continue}let m=u.startsWith("b/")?u.slice(2):u;f=I(pf(r,m));continue}if(c.startsWith("@@")&&f){let u=c.match(/\+(\d+)(?:,(\d+))?/);if(!u)continue;let m=Number(u[1]),s=u[2]?Number(u[2]):1,$=s===0?m:m+s-1;t.push({filePath:f,range:{startLine:m,endLine:$}})}}return t}var bf;var Tn=C(()=>{B();bf=Rf(jf)});import{join as Ff,isAbsolute as vf}from"node:path";function o(n,r){let t=[],f=new Set,c=(u,m)=>{let s=rc(u,r),$=`${s}:${m}`;if(!f.has($))f.add($),t.push({filePath:s,range:{startLine:Math.max(1,m-3),endLine:m+3}})};for(let u of n.split(/\r?\n/)){let m=u.match(of);if(m){c(m[1],Number(m[3]));continue}let s=u.match(df);if(s){let k=s[3]?Number(s[3]):1;c(s[1],k);continue}let $=u.match(af);if($){c($[1],Number($[2]));continue}let i=u.match(nc);if(i){c(i[1],Number(i[2]));continue}let w=u.match(ef);if(w){c(w[1],Number(w[2]));continue}let x=u.match(Nf);if(x){c(x[1],Number(x[3]));continue}let E=u.match(lf);if(E)c(E[1],Number(E[2]))}return t}function rc(n,r){if(vf(n))return I(n);return I(Ff(r,n))}var Nf,lf,ef,of,df,af,nc;var hn=C(()=>{B();Nf=/([A-Za-z0-9_\-./\\]+?\.(tsx|ts|jsx|js)):(\d+)(?::(\d+))?/,lf=/([A-Za-z0-9_\-./\\]+?\.py):(\d+)(?::(\d+))?/,ef=/File "([^"]+\.py)", line (\d+)/,of=/at .+? \(([^)]+?\.(tsx|ts|jsx|js)):(\d+):(\d+)\)/,df=/(?:FAIL|PASS|❯|›)\s+([A-Za-z0-9_\-./\\]+?\.(tsx|ts|jsx|js))(?::(\d+))?/,af=/([A-Za-z0-9_\-./\\]+?\.py):(\d+):\s*(?:error|warning|note):/,nc=/([A-Za-z0-9_\-./\\]+?\.py):(\d+):(\d+)\s*-\s*(?:error|warning|information):/});import{resolve as tc,isAbsolute as fc}from"node:path";async function d(n){let r=[],t=new Set,f=[],c=[];for(let u of n.entries){let m=I(fc(u)?u:tc(n.cwd,u)),s=J(n.workspaces,m);if(!s)continue;let $=await V(m);r.push({id:"",kind:"file",lang:z(m),workspaceId:s.id,workspaceRoot:s.root,filePath:m,score:Ur,reasons:["entry file"],estimatedChars:$,anchor:!0}),t.add(m)}for(let u of n.symbols){let m=await sc(n.adapters,u);if(m.length===0){f.push(u);continue}if(m.length>1)c.push({query:u,definitions:m.map((s)=>({filePath:s.filePath,range:s.range}))});for(let s of m){let $=J(n.workspaces,s.filePath);if(!$)continue;if(r.push({id:"",kind:"snippet",lang:s.lang,workspaceId:$.id,workspaceRoot:$.root,filePath:s.filePath,range:s.range,score:s.kind==="context"?_r:cc,reasons:[`defines-symbol ${u}`],estimatedChars:R(s.range),anchor:!0}),t.add(s.filePath),s.kind!=="definition")continue;let i=await $c(n.adapters,s,t);for(let w of i){let x=J(n.workspaces,w.filePath);if(!x)continue;r.push({id:"",kind:"snippet",lang:w.lang,workspaceId:x.id,workspaceRoot:x.root,filePath:w.filePath,range:w.range,score:_r,reasons:[`references ${u}`],estimatedChars:R(w.range)}),t.add(w.filePath)}}}if(n.fromDiff){let u=n.diffHunks??await e(n.repoRoot,n.fromDiff),m=new Set;for(let s of u){let $=J(n.workspaces,s.filePath);if(!$)continue;r.push({id:"",kind:"snippet",lang:z(s.filePath),workspaceId:$.id,workspaceRoot:$.root,filePath:s.filePath,range:s.range,score:uc,reasons:["diff hunk"],estimatedChars:R(s.range),anchor:!0}),t.add(s.filePath),m.add(s.filePath)}for(let s of m){let $=J(n.workspaces,s);if(!$)continue;let i=await V(s);r.push({id:"",kind:"file",lang:z(s),workspaceId:$.id,workspaceRoot:$.root,filePath:s,score:Ur,reasons:["diff file"],estimatedChars:i})}}if(n.fromLog){let u=n.logAnchors??o(await D(n.fromLog),n.repoRoot);for(let m of u){let s=J(n.workspaces,m.filePath);if(!s)continue;r.push({id:"",kind:"snippet",lang:z(m.filePath),workspaceId:s.id,workspaceRoot:s.root,filePath:m.filePath,range:m.range,score:mc,reasons:["diagnostic"],estimatedChars:R(m.range),anchor:!0}),t.add(m.filePath)}}return{candidates:r,anchorFiles:t,unresolvedSymbols:f,ambiguousSymbols:c}}async function sc(n,r){let t=[];for(let f of n){let c=await f.findSymbolDefinitions(r);t.push(...c)}return t}async function $c(n,r,t){let f=n.find((u)=>u.lang===r.lang&&r.filePath.startsWith(u.workspace.root));if(!f)return[];return await f.findSymbolReferences(r,{limit:10,anchorFiles:Array.from(t)})}var Ur=800,cc=1000,_r=700,mc=950,uc=850;var Qn=C(()=>{Y();B();Cn();xn();Tn();hn()});import{dirname as ic,join as Yr,basename as xc,extname as wc}from"node:path";import Ec from"fast-glob";async function Jr(n){let r=[],t=new Map;for(let c of n.adapters)for(let u of c.files)t.set(u,c);for(let c of n.anchorFiles){let u=t.get(c);if(!u)continue;let m=u.importGraph,s=new Set([c]),$=[{file:c,distance:0}];while($.length>0){let w=$.shift();if(!w)break;let x=w.distance+1;if(x>n.depth)continue;let E=m.get(w.file);if(!E)continue;let k=Array.from(E.keys()).sort();for(let y of k){if(s.has(y))continue;s.add(y),$.push({file:y,distance:x});let L=await V(y),S=E.get(y)==="imports-dynamic";r.push({id:"",kind:"file",lang:z(y),workspaceId:u.workspace.id,workspaceRoot:u.workspace.root,filePath:y,score:yc[x]??kc,reasons:[S?`dynamic-import-distance ${x}`:`import-distance ${x}`],estimatedChars:L})}}let i=await Cc(c);if(i){let w=await V(i);r.push({id:"",kind:"file",lang:z(i),workspaceId:u.workspace.id,workspaceRoot:u.workspace.root,filePath:i,score:Gc,reasons:["barrel file"],estimatedChars:w})}if(n.includeTests!=="false"){if(n.includeTests==="true"||/[\\/](src|lib)[\\/]/.test(c)){let x=n.ignoreMatchers.get(u.workspace.id)??n.ignoreMatchers.values().next().value,E=await Tc(u.workspace.root,c,x);for(let k of E){let y=await V(k);r.push({id:"",kind:"file",lang:z(k),workspaceId:u.workspace.id,workspaceRoot:u.workspace.root,filePath:k,score:Lc,reasons:["related test"],estimatedChars:y})}}}}let f=await hc(n.workspaces);for(let c of f){let u=await V(c.filePath);r.push({id:"",kind:"file",lang:z(c.filePath),workspaceId:c.workspace.id,workspaceRoot:c.workspace.root,filePath:c.filePath,score:Ic,reasons:["config booster"],estimatedChars:u})}return r}async function Cc(n){let r=ic(n),t=["index.ts","index.tsx","index.js","index.jsx"];for(let f of t){let c=Yr(r,f);if(await W(c))return c}return null}async function Tc(n,r,t){let f=xc(r,wc(r)),c=[`**/${f}.test.*`,`**/${f}.spec.*`,`**/test_${f}.*`];return(await Ec(c,{cwd:n,absolute:!0,dot:!1,followSymbolicLinks:!1})).map((m)=>I(m)).filter((m)=>!t.ignores(m)).sort()}async function hc(n){let r=["next.config.js","next.config.mjs","next.config.ts","next-env.d.ts","vite.config.ts","vite.config.js","svelte.config.js","remix.config.js"],t=[];for(let f of n)for(let c of r){let u=Yr(f.root,c);if(await W(u))t.push({workspace:f,filePath:u})}return t}var yc,kc=50,Gc=120,Ic=110,Lc=100;var Zr=C(()=>{Cn();Y();B();yc={1:250,2:150}});async function Or(n){let{candidates:r,budgetChars:t,budgetTokens:f}=n,c=[],u=[],m=0,s=0;for(let $ of r){let i="";try{i=$.kind==="file"?await D($.filePath):$.range?await l($.filePath,$.range):""}catch{u.push({id:$.id,filePath:$.filePath,kind:$.kind,range:$.range,reason:`${$.reasons.join("; ")}; failed to read file`,score:$.score,estimatedChars:$.estimatedChars});continue}let w=i.length,x=Math.ceil(w/4),E=m+w>t,k=f!==void 0&&s+x>f;if(E||k){u.push({id:$.id,filePath:$.filePath,kind:$.kind,range:$.range,reason:$.reasons.join("; "),score:$.score,estimatedChars:$.estimatedChars});continue}c.push({kind:$.kind,lang:$.lang,workspaceRoot:$.workspaceRoot,filePath:$.filePath,range:$.range,reasons:$.reasons,content:i}),m+=w,s+=x}return{items:c,omitted:u,usedChars:m,usedTokens:f!==void 0?s:void 0}}var Dr=C(()=>{yn();Y()});import{relative as Ac}from"node:path";function Xr(n){let{meta:r,items:t,omitted:f,includeReasons:c}=n,u=[];if(u.push("# repo-slice bundle"),u.push(""),u.push(`- command: ${r.command}`),u.push(`- scope: ${r.scope.mode} (${r.scope.workspaces.join(", ")})`),u.push(`- budget: ${r.budget.usedChars}/${r.budget.chars} chars`),r.budget.tokens!==void 0&&r.budget.usedTokens!==void 0)u.push(`- tokens: ${r.budget.usedTokens}/${r.budget.tokens}`);if(r.note)u.push(`- note: ${r.note}`);if(r.generatedAt)u.push(`- generatedAt: ${r.generatedAt}`);if(u.push(""),u.push("## Index"),t.length===0)u.push("- (empty)");else for(let m of t){let s=An(r.repoRoot,m.filePath),$=m.kind==="snippet"&&m.range?`:${m.range.startLine}-${m.range.endLine}`:"",i=c&&m.reasons.length?` (reasons: ${m.reasons.join(", ")})`:"";u.push(`- ${m.kind} ${s}${$}${i}`)}u.push(""),u.push("## Content");for(let m of t){let s=An(r.repoRoot,m.filePath),$=m.kind==="snippet"&&m.range?`lines ${m.range.startLine}-${m.range.endLine}`:"full file";if(u.push(`### ${m.kind} ${s} (${$})`),u.push(`workspace: ${An(r.repoRoot,m.workspaceRoot)}`),c&&m.reasons.length)u.push(`reasons: ${m.reasons.join(", ")}`);u.push(""),u.push(`\`\`\`${Wc(m.filePath)}`),u.push(m.content),u.push("```"),u.push("")}if(c&&f.length>0){u.push("## Omitted (budget)");for(let m of f){let s=An(r.repoRoot,m.filePath),$=m.kind==="snippet"&&m.range?`:${m.range.startLine}-${m.range.endLine}`:"";u.push(`- ${m.kind} ${s}${$} (score ${m.score}, est ${m.estimatedChars} chars) - ${m.reason}`)}u.push("")}return u.join(`
|
|
56
|
-
`)}function An(n,r){return A(Ac(n,r))||"."}function Wc(n){let r=n.toLowerCase();if(r.endsWith(".tsx"))return"tsx";if(r.endsWith(".ts"))return"ts";if(r.endsWith(".jsx"))return"jsx";if(r.endsWith(".js"))return"js";if(r.endsWith(".py"))return"py";return"text"}var Qr=C(()=>{B()});import{relative as Sc}from"node:path";function zr(n){let{meta:r,items:t,omitted:f}=n,c={meta:{...r,scope:{...r.scope,workspaces:r.scope.workspaces.map((u)=>u)}},items:t.map((u)=>({kind:u.kind,lang:u.lang,workspaceRoot:zn(r.repoRoot,u.workspaceRoot),filePath:zn(r.repoRoot,u.filePath),range:u.range,reasons:u.reasons,content:u.content})),omitted:f.map((u)=>({filePath:zn(r.repoRoot,u.filePath),kind:u.kind,range:u.range,reason:u.reason,score:u.score,estimatedChars:u.estimatedChars}))};return JSON.stringify(c,null,2)}function zn(n,r){return A(Sc(n,r))||"."}var Pr=C(()=>{B()});function Hr(n,r){let t=n;for(let f of r){let c=Kc(f);t=t.replace(c,"[REDACTED]")}return t}function Kc(n){try{return new RegExp(n,"g")}catch{return new RegExp(Bc(n),"g")}}function Bc(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Wn(n){return{debug:(r)=>{if(!n)return;process.stderr.write(`[debug] ${r}
|
|
57
|
-
`)}}}import{createHash as Uc}from"node:crypto";function Sn(n){return Uc("sha1").update(n).digest("hex")}var Pn=()=>{};import{join as _c}from"node:path";import{readFile as Yc,writeFile as Jc,mkdir as Zc,stat as Oc}from"node:fs/promises";async function qr(n){let r=Vr(n.repoRoot,n.workspaceRoot,n.configHash,n.version);if(!await W(r))return null;try{let t=await Yc(r,"utf8"),f=JSON.parse(t);if(f.version!==n.version)return null;if(f.configHash!==n.configHash)return null;if(f.workspaceRoot!==n.workspaceRoot)return null;return f}catch{return null}}async function gr(n){let r=Vr(n.repoRoot,n.workspaceRoot,n.configHash,n.version),t=r.replace(/\/index\.json$/,"");await Zc(t,{recursive:!0}),await Jc(r,JSON.stringify(n.cache,null,2),"utf8")}function Dc(n,r,t){return Sn(`${n}|${r}|${t}`)}function Vr(n,r,t,f){let c=Dc(r,t,f);return _c(n,".repo-slice","cache",c,"index.json")}function jr(n,r){if(n.files.length!==r.length)return!1;let t=[...r].sort((c,u)=>c.path.localeCompare(u.path)),f=[...n.files].sort((c,u)=>c.path.localeCompare(u.path));for(let c=0;c<t.length;c+=1){let u=t[c],m=f[c];if(u.path!==m.path)return!1;if(u.mtimeMs!==m.mtimeMs)return!1;if(u.size!==m.size)return!1}return!0}function Hn(n){let r={};for(let[t,f]of n.entries()){let c={},u=Array.from(f.entries()).sort((m,s)=>m[0].localeCompare(s[0]));for(let[m,s]of u)c[m]=s;r[t]=c}return r}function qn(n){let r=new Map;for(let[t,f]of Object.entries(n)){let c=new Map;if(Array.isArray(f))for(let u of f)c.set(u,"imports");else for(let[u,m]of Object.entries(f))c.set(u,m);r.set(t,c)}return r}async function Rr(n){let r=[];for(let t of n)try{let f=await Oc(t);r.push({path:t,mtimeMs:f.mtimeMs,size:f.size})}catch{continue}return r}var pr=C(()=>{Y();Pn()});import br from"fast-glob";import{resolve as gn,join as Xc}from"node:path";import{writeFile as Qc}from"node:fs/promises";async function Fr(n){let r=process.cwd(),t=await F(r),f=await v(t),{config:c}=await g(t),u=n.allWorkspaces??c.workspaces.mode==="all",m=n.workspace??c.workspaces.mode,s=await $n({workspaces:f,cwd:r,workspaceFlag:m==="all"?void 0:m,allWorkspaces:u}),$=s.mode;if(s.workspaces.length===0)throw Error("No workspaces detected");let i=s.workspaces[0],{config:w}=await g(t,i?.root),x=Vn(w,n),E=n.includeTests??x.includeTests,k=n.budgetChars??x.budgetChars,y=n.budgetTokens,L=n.format??"md",T=Boolean(n.reason),S=n.redact===!0||x.redact.enabled,_=Wn(Boolean(n.debug)),X=n.fromDiff?await e(t,n.fromDiff):void 0,K=n.fromLog?gn(r,n.fromLog):void 0,P=K?o(await D(K),t):void 0,U=zc({allWorkspaces:f,baseWorkspaces:s.workspaces,cwd:r,entries:n.entries,diffHunks:X,logAnchors:P}),a=await Mr({repoRoot:t,workspaces:U,args:n,logger:_}),p=Hc(a,s.workspaces),H=await d({repoRoot:t,cwd:r,workspaces:U,adapters:p,entries:n.entries,symbols:n.symbols,fromDiff:n.fromDiff,fromLog:K??n.fromLog,diffHunks:X,logAnchors:P});if(H.unresolvedSymbols.length>0&&n.fallbackAll&&!n.allWorkspaces)_.debug("Symbol not found in scope; retrying across all workspaces"),U=f,$="all",a=await Mr({repoRoot:t,workspaces:U,args:n,logger:_}),p=a,H=await d({repoRoot:t,cwd:r,workspaces:U,adapters:p,entries:n.entries,symbols:n.symbols,fromDiff:n.fromDiff,fromLog:K??n.fromLog,diffHunks:X,logAnchors:P});if(H.unresolvedSymbols.length>0)process.stderr.write(`Symbol(s) not found: ${H.unresolvedSymbols.join(", ")}
|
|
58
|
-
`),process.stderr.write(`Try --all-workspaces or --fallback-all
|
|
59
|
-
`),process.exit(2);if(n.symbolStrict&&H.ambiguousSymbols.length>0){process.stderr.write(`Ambiguous symbol(s) found (--symbol-strict enabled):
|
|
60
|
-
`);for(let Z of H.ambiguousSymbols){process.stderr.write(` ${Z.query}:
|
|
61
|
-
`);for(let an of Z.definitions){let St=an.filePath.replace(t+"/","");process.stderr.write(` - ${St}:${an.range.startLine}
|
|
62
|
-
`)}}process.stderr.write(`Use file-hint syntax (e.g., path/to/file.ts:SymbolName) to disambiguate.
|
|
63
|
-
`),process.exit(2)}let q=new Map;for(let Z of H.candidates)In(q,Ln(Z));let mn=await Pc({repoRoot:t,workspaces:U,args:n}),Bn=await Jr({adapters:a,workspaces:U,anchorFiles:H.anchorFiles,depth:n.depth??x.depth,includeTests:E,ignoreMatchers:mn});for(let Z of Bn)In(q,Ln(Z));qc(q,k);let Wt=Br(Array.from(q.values())),nn=await Or({candidates:Wt,budgetChars:k,budgetTokens:y}),Un=T?nn.items:nn.items.map((Z)=>({...Z,reasons:[]})),en=T?nn.omitted:[];if(S)for(let Z of Un)Z.content=Hr(Z.content,x.redact.patterns);let on={repoRoot:t,generatedAt:n.noTimestamp?void 0:new Date().toISOString(),command:`repo-slice ${process.argv.slice(2).join(" ")}`,scope:{mode:$,workspaces:U.map((Z)=>Z.id)},budget:{chars:k,usedChars:nn.usedChars,tokens:y,usedTokens:nn.usedTokens},note:T?s.note:void 0},dn=L==="json"?zr({meta:on,items:Un,omitted:en}):Xr({meta:on,items:Un,omitted:en,includeReasons:T});if(n.out){let Z=gn(r,n.out);await Qc(Z,dn,"utf8")}else process.stdout.write(dn)}function Vn(n,r){return{...n,budgetChars:r.budgetChars??n.budgetChars,depth:r.depth??n.depth,includeTests:r.includeTests??n.includeTests,redact:{...n.redact,enabled:r.redact===!0?!0:n.redact.enabled}}}function zc(n){let r=new Map;for(let t of n.baseWorkspaces)r.set(t.root,t);for(let t of n.entries){let f=gn(n.cwd,t),c=J(n.allWorkspaces,f);if(c)r.set(c.root,c)}for(let t of n.diffHunks??[]){let f=J(n.allWorkspaces,t.filePath);if(f)r.set(f.root,f)}for(let t of n.logAnchors??[]){let f=J(n.allWorkspaces,t.filePath);if(f)r.set(f.root,f)}return Array.from(r.values()).sort((t,f)=>t.root.localeCompare(f.root))}async function Mr(n){let r=[],t=await jc(n.repoRoot);for(let f of n.workspaces){let{config:c}=await g(n.repoRoot,f.root),u=Vn(c,n.args);n.logger.debug(`Indexing workspace ${f.root}`);let m=await N({repoRoot:n.repoRoot,workspaceRoot:f.root,extraIgnorePatterns:u.ignore}),s=await gc(f.root,m),$=[...s.tsFiles,...s.pyFiles].sort(),i=await Rr($),w=Vc(u),x=await qr({repoRoot:n.repoRoot,workspaceRoot:f.root,configHash:w,version:t}),k=(x?jr(x,i):!1)?Rc(x):void 0,y=await Gn({workspace:f,ignoreMatcher:m,pythonImportRoots:u.workspaces.pythonImportRoots,files:s,cache:k});r.push(...y),await gr({repoRoot:n.repoRoot,workspaceRoot:f.root,configHash:w,version:t,cache:pc({cache:x,workspace:f,version:t,configHash:w,stats:i,adapters:y})})}return r.flat()}async function Pc(n){let r=new Map;for(let t of n.workspaces){let{config:f}=await g(n.repoRoot,t.root),c=Vn(f,n.args),u=await N({repoRoot:n.repoRoot,workspaceRoot:t.root,extraIgnorePatterns:c.ignore});r.set(t.id,u)}return r}function Hc(n,r){let t=new Set(r.map((f)=>f.root));return n.filter((f)=>t.has(f.workspace.root))}function qc(n,r){for(let f of n.values()){if(f.kind!=="file"||!f.anchor)continue;if(f.estimatedChars<=r/2)continue;let c={id:"",kind:"snippet",lang:f.lang,workspaceId:f.workspaceId,workspaceRoot:f.workspaceRoot,filePath:f.filePath,range:{startLine:1,endLine:80},score:f.score-200,reasons:[...f.reasons,"header snippet"],estimatedChars:R({startLine:1,endLine:80})};In(n,Ln(c))}for(let f of n.values())f.id=Xn(f)}async function gc(n,r){let t=await br(["**/*.ts","**/*.tsx","**/*.js","**/*.jsx"],{cwd:n,absolute:!0,dot:!1,followSymbolicLinks:!1}),f=await br(["**/*.py"],{cwd:n,absolute:!0,dot:!1,followSymbolicLinks:!1});return{tsFiles:t.map((c)=>I(c)).filter((c)=>!r.ignores(c)).sort(),pyFiles:f.map((c)=>I(c)).filter((c)=>!r.ignores(c)).sort()}}function Vc(n){return Sn(JSON.stringify({ignore:n.ignore,pythonImportRoots:n.workspaces.pythonImportRoots}))}async function jc(n){let r=await D(Xc(n,"package.json"));try{return JSON.parse(r).version??"0.0.0"}catch{return"0.0.0"}}function Rc(n){return{tsImportGraph:n.ts?qn(n.ts.importGraph):void 0,pyModuleMap:n.py?new Map(Object.entries(n.py.moduleMap)):void 0,pyDefinitions:n.py?new Map(Object.entries(n.py.definitions)):void 0,pyImportGraph:n.py?qn(n.py.importGraph):void 0}}function pc(n){let r=n.adapters.find((c)=>c.lang==="ts"),t=n.adapters.find((c)=>c.lang==="py"),f=t?.metadata?.py;return{version:n.version,workspaceRoot:n.workspace.root,configHash:n.configHash,files:n.stats,ts:r?{importGraph:Hn(r.importGraph)}:void 0,py:t&&f?{moduleMap:Object.fromEntries(f.moduleMap.entries()),definitions:Object.fromEntries(f.definitions.entries()),importGraph:Hn(t.importGraph)}:void 0}}var vr=C(()=>{un();sn();xn();Yn();Jn();Qn();Tn();hn();Cn();Zr();Dr();Qr();Pr();Y();B();pr();Pn()});var Nr={};b(Nr,{packCommand:()=>bc});async function bc(n){let r;try{r=Mc(n)}catch(t){let f=t instanceof Error?t.message:String(t);process.stderr.write(`${f}
|
|
64
|
-
`),process.stderr.write(M()),process.exit(3);return}if(r.help)process.stdout.write(M()),process.exit(0);await Fr(r.args)}function Mc(n){let r={entries:[],symbols:[]},t=!1,f=(c,u)=>{let m=n[c+1];if(!m||m.startsWith("--"))throw Error(`Missing value for ${u}`);return m};for(let c=0;c<n.length;c+=1){let u=n[c];if(u==="--help"||u==="-h"){t=!0;continue}if(!u.startsWith("--"))throw Error(`Unexpected argument: ${u}`);let[m,s]=u.split("=",2);switch(m){case"--entry":if(r.entries.push(s??f(c,m)),!s)c+=1;break;case"--symbol":if(r.symbols.push(s??f(c,m)),!s)c+=1;break;case"--symbol-strict":r.symbolStrict=!0;break;case"--from-diff":if(r.fromDiff=s??f(c,m),!s)c+=1;break;case"--from-log":if(r.fromLog=s??f(c,m),!s)c+=1;break;case"--workspace":if(r.workspace=s??f(c,m),!s)c+=1;break;case"--all-workspaces":r.allWorkspaces=!0;break;case"--fallback-all":r.fallbackAll=!0;break;case"--depth":if(r.depth=jn(s??f(c,m),m),!s)c+=1;break;case"--budget-chars":if(r.budgetChars=jn(s??f(c,m),m),!s)c+=1;break;case"--budget-tokens":if(r.budgetTokens=jn(s??f(c,m),m),!s)c+=1;break;case"--include-tests":{let $=s??f(c,m);if(!s)c+=1;if(!["auto","true","false"].includes($))throw Error(`Invalid include-tests value: ${$}`);r.includeTests=$;break}case"--format":{let $=s??f(c,m);if(!s)c+=1;if(!["md","json"].includes($))throw Error(`Invalid format: ${$}`);r.format=$;break}case"--out":if(r.out=s??f(c,m),!s)c+=1;break;case"--reason":r.reason=!0;break;case"--redact":r.redact=!0;break;case"--debug":r.debug=!0;break;case"--no-timestamp":r.noTimestamp=!0;break;default:throw Error(`Unknown flag: ${m}`)}}if(r.allWorkspaces&&r.workspace)throw Error("Cannot combine --all-workspaces with --workspace");return{help:t,args:r}}function jn(n,r){let t=Number(n);if(!Number.isFinite(t))throw Error(`Invalid number for ${r}: ${n}`);return t}var lr=C(()=>{vr()});import{relative as bn,basename as er,extname as Fc}from"node:path";import vc from"fast-glob";async function or(n){let r=new Map,t=[],f=new Map;for(let c of n.adapters)for(let u of c.files)f.set(u,c);for(let c of n.anchorFiles){let u=f.get(c);if(!u)continue;let m=u.importGraph,s=new Set([c]),$=[{file:c,distance:0}],i=pn({filePath:c,repoRoot:n.repoRoot,workspaceRoot:u.workspace.root,anchor:!0,external:!1});r.set(i.id,i);while($.length>0){let w=$.shift();if(!w)break;let x=w.distance+1;if(x>n.depth)continue;let E=m.get(w.file);if(!E)continue;let k=Array.from(E.entries()).sort((y,L)=>y[0].localeCompare(L[0]));for(let[y,L]of k){let T=Rn(w.file,n.repoRoot),S=Rn(y,n.repoRoot);if(!s.has(y)){s.add(y);let K=f.get(y),P=!K;if(!P||n.includeExternal){let U=pn({filePath:y,repoRoot:n.repoRoot,workspaceRoot:K?.workspace.root??n.repoRoot,anchor:!1,external:P});r.set(U.id,U),$.push({file:y,distance:x})}}let _=r.get(T),X=r.get(S);if(_&&X){let K=L==="imports-dynamic"?"imports-dynamic":"imports";t.push({from:T,to:S,type:K,confidence:L==="imports-dynamic"?0.9:1})}}}if(n.includeTests!=="false"){if(n.includeTests==="true"||/[\\/](src|lib)[\\/]/.test(c)){let x=n.ignoreMatchers.get(u.workspace.id)??n.ignoreMatchers.values().next().value,E=await Nc(u.workspace.root,c,x);for(let k of E){let y=pn({filePath:k,repoRoot:n.repoRoot,workspaceRoot:u.workspace.root,anchor:!1,external:!1});if(!r.has(y.id))r.set(y.id,y);let L=Rn(c,n.repoRoot);t.push({from:y.id,to:L,type:"tests",confidence:1})}}}}return{nodes:Array.from(r.values()),edges:t}}function Rn(n,r){let t=z(n),f=A(bn(r,n))||n;return`${t}:${f}`}function pn(n){let{filePath:r,repoRoot:t,workspaceRoot:f,anchor:c,external:u}=n,m=A(bn(t,r))||r,s=z(r);return{id:`${s}:${m}`,kind:"file",lang:s,name:er(r),filePath:m,workspaceRoot:A(bn(t,f))||".",anchor:c,external:u,confidence:1}}async function Nc(n,r,t){let f=er(r,Fc(r)),c=[`**/${f}.test.*`,`**/${f}.spec.*`,`**/test_${f}.*`],u=await vc(c,{cwd:n,absolute:!0,dot:!1,followSymbolicLinks:!1});return(t?u.filter((s)=>!t.ignores(s)):u).sort()}var dr=C(()=>{B()});function ar(n,r,t){let f=!1,c=0,u=0,m=n.filter((x)=>x.anchor),s=n.filter((x)=>!x.anchor);s.sort((x,E)=>{if(x.external!==E.external)return x.external?1:-1;return E.confidence-x.confidence||x.id.localeCompare(E.id)});let $;if(m.length>=t.maxNodes)$=m.slice(0,t.maxNodes),c=m.length-t.maxNodes+s.length,f=!0;else{let x=t.maxNodes-m.length,E=s.slice(0,x);if($=[...m,...E],c=s.length-E.length,c>0)f=!0}let i=new Set($.map((x)=>x.id)),w=r.filter((x)=>i.has(x.from)&&i.has(x.to));if(w.sort((x,E)=>{if(x.confidence!==E.confidence)return E.confidence-x.confidence;if(x.type!==E.type)return x.type.localeCompare(E.type);return x.from.localeCompare(E.from)||x.to.localeCompare(E.to)}),w.length>t.maxEdges)u=w.length-t.maxEdges,w=w.slice(0,t.maxEdges),f=!0;return{nodes:$,edges:w,truncated:f,truncatedNodes:c,truncatedEdges:u}}function nt(n,r,t){switch(t){case"none":return{nodes:n,edges:r};case"external":return lc(n,r);case"file":return ec(n,r);case"class":return oc(n,r);default:return{nodes:n,edges:r}}}function lc(n,r){let t=n.filter((x)=>x.external),f=n.filter((x)=>!x.external);if(t.length===0)return{nodes:n,edges:r};let c="__external__",u=new Set(t.map((x)=>x.id)),m={id:c,kind:"module",lang:"ts",name:"external",filePath:"__external__",workspaceRoot:".",anchor:!1,external:!0,confidence:1},s=[],$=new Set;for(let x of r){let E=u.has(x.from),k=u.has(x.to),y=x.from,L=x.to;if(E)y=c;if(k)L=c;if(y===c&&L===c)continue;let T=`${y}|${L}|${x.type}`;if(!$.has(T))$.add(T),s.push({...x,from:y,to:L})}return{nodes:s.some((x)=>x.from===c||x.to===c)?[...f,m]:f,edges:s}}function ec(n,r){let t=new Map,f=new Map;for(let m of n){let s=`${m.lang}:${m.filePath}`;if(f.set(m.id,s),!t.has(s))t.set(s,{id:s,kind:"file",lang:m.lang,name:m.filePath.split("/").pop()??m.filePath,filePath:m.filePath,workspaceRoot:m.workspaceRoot,anchor:m.anchor,external:m.external,confidence:m.confidence});else{let $=t.get(s);$.anchor=$.anchor||m.anchor,$.confidence=Math.max($.confidence,m.confidence)}}let c=[],u=new Set;for(let m of r){let s=f.get(m.from)??m.from,$=f.get(m.to)??m.to;if(s===$)continue;let i=`${s}|${$}|${m.type}`;if(!u.has(i))u.add(i),c.push({...m,from:s,to:$})}return{nodes:Array.from(t.values()),edges:c}}function oc(n,r){let t=new Map,f=new Map;for(let m of n){let s;if(m.kind==="method"||m.kind==="constructor"){let $=m.id.split("#");if($.length>=2){let w=$[1].split(".");if(w.length>=2)s=`${$[0]}#${w[0]}`;else s=m.id}else s=m.id}else if(m.kind==="class")s=m.id;else s=m.id;if(f.set(m.id,s),!t.has(s)){let $=s.includes("#")?s.split("#")[1]:m.name;t.set(s,{id:s,kind:m.kind==="method"||m.kind==="constructor"?"class":m.kind,lang:m.lang,name:$,filePath:m.filePath,range:m.range,workspaceRoot:m.workspaceRoot,anchor:m.anchor,external:m.external,confidence:m.confidence})}else{let $=t.get(s);$.anchor=$.anchor||m.anchor,$.confidence=Math.max($.confidence,m.confidence)}}let c=[],u=new Set;for(let m of r){let s=f.get(m.from)??m.from,$=f.get(m.to)??m.to;if(s===$)continue;let i=`${s}|${$}|${m.type}`;if(!u.has(i))u.add(i),c.push({...m,from:s,to:$})}return{nodes:Array.from(t.values()),edges:c}}import{relative as Kn}from"node:path";async function mt(n){let r=[],t=[];if(n.graphType==="imports"||n.graphType==="combined"){let u=await or({adapters:n.adapters,anchorFiles:n.anchorFiles,repoRoot:n.repoRoot,depth:n.depth,includeTests:n.includeTests,includeExternal:n.includeExternal,ignoreMatchers:n.ignoreMatchers});r=tt(r,u.nodes),t=ft(t,u.edges)}if(n.graphType==="calls"||n.graphType==="combined"){let u=await dc(n);r=tt(r,u.nodes),t=ft(t,u.edges)}let f=nt(r,t,n.collapse);r=f.nodes,t=f.edges,ct(r,t);let c=ar(r,t,{maxNodes:n.maxNodes,maxEdges:n.maxEdges});return ct(c.nodes,c.edges),{nodes:c.nodes,edges:c.edges,truncated:c.truncated,truncatedNodes:c.truncatedNodes,truncatedEdges:c.truncatedEdges}}async function dc(n){let r=new Map,t=[],f=Array.from(n.anchorFiles);for(let c of n.adapters){if(!c.findCallExpressions)continue;let u=await c.findCallExpressions({files:f.filter((m)=>m.startsWith(c.workspace.root))});for(let m of u){let s=ac(m.callerFile,m.callerSymbol,c.lang,n.repoRoot),$=nm(m.calleeSymbol,c.lang,n.repoRoot);if(!r.has(s))r.set(s,rt({id:s,filePath:m.callerFile,symbolName:m.callerSymbol,lang:c.lang,repoRoot:n.repoRoot,workspaceRoot:c.workspace.root,anchor:n.anchorFiles.has(m.callerFile),confidence:1}));if(!r.has($))r.set($,rt({id:$,filePath:rm(m.calleeSymbol),symbolName:tm(m.calleeSymbol),lang:c.lang,repoRoot:n.repoRoot,workspaceRoot:c.workspace.root,anchor:!1,confidence:m.confidence}));let i=m.isDynamic?"calls-dynamic":m.confidence<0.5?"calls-unknown":"calls";t.push({from:s,to:$,type:i,callsite:{filePath:A(Kn(n.repoRoot,m.callerFile)),range:m.range},confidence:m.confidence})}}return{nodes:Array.from(r.values()),edges:t}}function ac(n,r,t,f){let c=A(Kn(f,n));if(r)return`${t}:${c}#${r}`;return`${t}:${c}`}function nm(n,r,t){if(n.includes("#")){let f=n.split("#"),c=f[0],u=f.slice(1).join("#");if(c.includes("/"))return`${r}:${c}#${u}`}if(n.startsWith("/")||n.includes(":"))return`${r}:${n}`;return`${r}:[unresolved]#${n}`}function rm(n){if(n.includes("#")){let r=n.split("#")[0];if(r.includes("/"))return r}return"[unresolved]"}function tm(n){if(n.includes("#"))return n.split("#").slice(1).join("#");return n}function rt(n){let{id:r,filePath:t,symbolName:f,lang:c,repoRoot:u,workspaceRoot:m,anchor:s,confidence:$}=n,i=t.startsWith("/")?A(Kn(u,t)):t,w=m.startsWith("/")?A(Kn(u,m))||".":m,x="function";if(f){if(f.includes(".")){let E=f.split(".");if(E[E.length-1]==="constructor")x="constructor";else x="method"}}else x="file";return{id:r,kind:x,lang:c,name:f??i.split("/").pop()??i,filePath:i,workspaceRoot:w,anchor:s,external:t==="[unresolved]",confidence:$}}function tt(n,r){let t=new Map;for(let f of n)t.set(f.id,f);for(let f of r){let c=t.get(f.id);if(!c)t.set(f.id,f);else t.set(f.id,{...c,anchor:c.anchor||f.anchor,confidence:Math.max(c.confidence,f.confidence)})}return Array.from(t.values())}function ft(n,r){let t=new Set,f=[];for(let c of n){let u=`${c.from}|${c.to}|${c.type}`;if(!t.has(u))t.add(u),f.push(c)}for(let c of r){let u=`${c.from}|${c.to}|${c.type}`;if(!t.has(u))t.add(u),f.push(c)}return f}function ct(n,r){n.sort((t,f)=>t.id.localeCompare(f.id)),r.sort((t,f)=>{let c=t.from.localeCompare(f.from);if(c!==0)return c;let u=t.to.localeCompare(f.to);if(u!==0)return u;return t.type.localeCompare(f.type)})}var ut=C(()=>{dr();B()});function $t(n){let r=[];if(r.push("digraph G {"),r.push(" rankdir=LR;"),r.push(" node [shape=box];"),r.push(""),new Set(n.nodes.map((c)=>c.workspaceRoot)).size>1){let c=fm(n.nodes),u=0;for(let[m,s]of c.entries()){r.push(` subgraph cluster_${u} {`),r.push(` label="${it(m)}";`);for(let $ of s)r.push(` ${st($)}`);r.push(" }"),r.push(""),u++}}else for(let c of n.nodes)r.push(` ${st(c)}`);r.push("");for(let c of n.edges)r.push(` ${cm(c)}`);return r.push("}"),r.join(`
|
|
65
|
-
`)}function fm(n){let r=new Map;for(let t of n){let f=r.get(t.workspaceRoot);if(f)f.push(t);else r.set(t.workspaceRoot,[t])}return r}function st(n){let r=[`label="${it(n.name)}"`];if(n.anchor)r.push('style="filled"'),r.push('fillcolor="lightblue"');else if(n.external)r.push('style="dashed"'),r.push('color="gray"');if(n.kind==="class")r.push('shape="ellipse"');else if(n.kind==="function"||n.kind==="method")r.push('shape="diamond"');return`"${Mn(n.id)}" [${r.join(", ")}];`}function cm(n){let r=[];if(n.type==="imports-dynamic"||n.type==="calls-dynamic"||n.type==="calls-unknown")r.push('style="dashed"');if(n.type==="tests")r.push('color="green"'),r.push('label="tests"');if(n.type==="calls")r.push('color="blue"');if(n.confidence<0.8&&!r.some((f)=>f.includes("style")))r.push('style="dotted"');let t=r.length>0?` [${r.join(", ")}]`:"";return`"${Mn(n.from)}" -> "${Mn(n.to)}"${t};`}function Mn(n){return n.replace(/\\/g,"\\\\").replace(/"/g,"\\\"")}function it(n){return n.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n")}import xt from"fast-glob";import{resolve as Fn,relative as mm}from"node:path";import{writeFile as um}from"node:fs/promises";async function Et(n){let r=process.cwd(),t=await F(r),f=await v(t),{config:c}=await g(t),u=n.allWorkspaces??c.workspaces.mode==="all",m=n.workspace??c.workspaces.mode,s=await $n({workspaces:f,cwd:r,workspaceFlag:m==="all"?void 0:m,allWorkspaces:u}),$=s.mode;if(s.workspaces.length===0)throw Error("No workspaces detected");let i=s.workspaces[0],{config:w}=await g(t,i?.root),x=yt(w,n),E=n.includeTests??x.includeTests,k=Wn(Boolean(n.debug)),y=n.fromDiff?await e(t,n.fromDiff):void 0,L=n.fromLog?Fn(r,n.fromLog):void 0,T=L?o(await D(L),t):void 0,S=$m({allWorkspaces:f,baseWorkspaces:s.workspaces,cwd:r,entries:n.entries,diffHunks:y,logAnchors:T}),_=await wt({repoRoot:t,workspaces:S,args:n,logger:k}),X=xm(_,s.workspaces),K=await d({repoRoot:t,cwd:r,workspaces:S,adapters:X,entries:n.entries,symbols:n.symbols,fromDiff:n.fromDiff,fromLog:L??n.fromLog,diffHunks:y,logAnchors:T});if(K.unresolvedSymbols.length>0&&n.fallbackAll&&!n.allWorkspaces)k.debug("Symbol not found in scope; retrying across all workspaces"),S=f,$="all",_=await wt({repoRoot:t,workspaces:S,args:n,logger:k}),X=_,K=await d({repoRoot:t,cwd:r,workspaces:S,adapters:X,entries:n.entries,symbols:n.symbols,fromDiff:n.fromDiff,fromLog:L??n.fromLog,diffHunks:y,logAnchors:T});if(K.unresolvedSymbols.length>0)process.stderr.write(`Symbol(s) not found: ${K.unresolvedSymbols.join(", ")}
|
|
60
|
+
`}var Af=J(()=>{kf()});import{relative as lr,basename as If,extname as Q$}from"node:path";import B$ from"fast-glob";async function Tf(r){let n=new Map,f=[],m=new Map;for(let t of r.adapters)for(let u of t.files)m.set(u,t);for(let t of r.anchorFiles){let u=m.get(t);if(!u)continue;let $=u.importGraph,y=new Set([t]),x=[{file:t,distance:0}],w=or({filePath:t,repoRoot:r.repoRoot,workspaceRoot:u.workspace.root,anchor:!0,external:!1});n.set(w.id,w);while(x.length>0){let G=x.shift();if(!G)break;let E=G.distance+1;if(E>r.depth)continue;let W=$.get(G.file);if(!W)continue;let U=Array.from(W.entries()).sort((K,A)=>K[0].localeCompare(A[0]));for(let[K,A]of U){let L=ir(G.file,r.repoRoot),I=ir(K,r.repoRoot);if(!y.has(K)){y.add(K);let Y=m.get(K),H=!Y;if(!H||r.includeExternal){let C=or({filePath:K,repoRoot:r.repoRoot,workspaceRoot:Y?.workspace.root??r.repoRoot,anchor:!1,external:H});n.set(C.id,C),x.push({file:K,distance:E})}}let X=n.get(L),O=n.get(I);if(X&&O){let Y=A==="imports-dynamic"?"imports-dynamic":"imports";f.push({from:L,to:I,type:Y,confidence:A==="imports-dynamic"?0.9:1})}}}if(r.includeTests!=="false"){if(r.includeTests==="true"||/[\\/](src|lib)[\\/]/.test(t)){let E=r.ignoreMatchers.get(u.workspace.id)??r.ignoreMatchers.values().next().value,W=await X$(u.workspace.root,t,E);for(let U of W){let K=or({filePath:U,repoRoot:r.repoRoot,workspaceRoot:u.workspace.root,anchor:!1,external:!1});if(!n.has(K.id))n.set(K.id,K);let A=ir(t,r.repoRoot);f.push({from:K.id,to:A,type:"tests",confidence:1})}}}}return{nodes:Array.from(n.values()),edges:f}}function ir(r,n){let f=R(r),m=B(lr(n,r))||r;return`${f}:${m}`}function or(r){let{filePath:n,repoRoot:f,workspaceRoot:m,anchor:t,external:u}=r,$=B(lr(f,n))||n,y=R(n);return{id:`${y}:${$}`,kind:"file",lang:y,name:If(n),filePath:$,workspaceRoot:B(lr(f,m))||".",anchor:t,external:u,confidence:1}}async function X$(r,n,f){let m=If(n,Q$(n)),t=[`**/${m}.test.*`,`**/${m}.spec.*`,`**/test_${m}.*`],u=await B$(t,{cwd:r,absolute:!0,dot:!1,followSymbolicLinks:!1});return(f?u.filter((y)=>!f.ignores(y)):u).sort()}var Jf=J(()=>{_()});function Yf(r,n,f){let m=!1,t=0,u=0,$=r.filter((E)=>E.anchor),y=r.filter((E)=>!E.anchor);y.sort((E,W)=>{if(E.external!==W.external)return E.external?1:-1;return W.confidence-E.confidence||E.id.localeCompare(W.id)});let x;if($.length>=f.maxNodes)x=$.slice(0,f.maxNodes),t=$.length-f.maxNodes+y.length,m=!0;else{let E=f.maxNodes-$.length,W=y.slice(0,E);if(x=[...$,...W],t=y.length-W.length,t>0)m=!0}let w=new Set(x.map((E)=>E.id)),G=n.filter((E)=>w.has(E.from)&&w.has(E.to));if(G.sort((E,W)=>{if(E.confidence!==W.confidence)return W.confidence-E.confidence;if(E.type!==W.type)return E.type.localeCompare(W.type);return E.from.localeCompare(W.from)||E.to.localeCompare(W.to)}),G.length>f.maxEdges)u=G.length-f.maxEdges,G=G.slice(0,f.maxEdges),m=!0;return{nodes:x,edges:G,truncated:m,truncatedNodes:t,truncatedEdges:u}}function Zf(r,n,f){switch(f){case"none":return{nodes:r,edges:n};case"external":return C$(r,n);case"file":return _$(r,n);case"class":return O$(r,n);default:return{nodes:r,edges:n}}}function C$(r,n){let f=r.filter((E)=>E.external),m=r.filter((E)=>!E.external);if(f.length===0)return{nodes:r,edges:n};let t="__external__",u=new Set(f.map((E)=>E.id)),$={id:t,kind:"module",lang:"ts",name:"external",filePath:"__external__",workspaceRoot:".",anchor:!1,external:!0,confidence:1},y=[],x=new Set;for(let E of n){let W=u.has(E.from),U=u.has(E.to),K=E.from,A=E.to;if(W)K=t;if(U)A=t;if(K===t&&A===t)continue;let L=`${K}|${A}|${E.type}`;if(!x.has(L))x.add(L),y.push({...E,from:K,to:A})}return{nodes:y.some((E)=>E.from===t||E.to===t)?[...m,$]:m,edges:y}}function _$(r,n){let f=new Map,m=new Map;for(let $ of r){let y=`${$.lang}:${$.filePath}`;if(m.set($.id,y),!f.has(y))f.set(y,{id:y,kind:"file",lang:$.lang,name:$.filePath.split("/").pop()??$.filePath,filePath:$.filePath,workspaceRoot:$.workspaceRoot,anchor:$.anchor,external:$.external,confidence:$.confidence});else{let x=f.get(y);x.anchor=x.anchor||$.anchor,x.confidence=Math.max(x.confidence,$.confidence)}}let t=[],u=new Set;for(let $ of n){let y=m.get($.from)??$.from,x=m.get($.to)??$.to;if(y===x)continue;let w=`${y}|${x}|${$.type}`;if(!u.has(w))u.add(w),t.push({...$,from:y,to:x})}return{nodes:Array.from(f.values()),edges:t}}function O$(r,n){let f=new Map,m=new Map;for(let $ of r){let y;if($.kind==="method"||$.kind==="constructor"){let x=$.id.split("#");if(x.length>=2){let G=x[1].split(".");if(G.length>=2)y=`${x[0]}#${G[0]}`;else y=$.id}else y=$.id}else if($.kind==="class")y=$.id;else y=$.id;if(m.set($.id,y),!f.has(y)){let x=y.includes("#")?y.split("#")[1]:$.name;f.set(y,{id:y,kind:$.kind==="method"||$.kind==="constructor"?"class":$.kind,lang:$.lang,name:x,filePath:$.filePath,range:$.range,workspaceRoot:$.workspaceRoot,anchor:$.anchor,external:$.external,confidence:$.confidence})}else{let x=f.get(y);x.anchor=x.anchor||$.anchor,x.confidence=Math.max(x.confidence,$.confidence)}}let t=[],u=new Set;for(let $ of n){let y=m.get($.from)??$.from,x=m.get($.to)??$.to;if(y===x)continue;let w=`${y}|${x}|${$.type}`;if(!u.has(w))u.add(w),t.push({...$,from:y,to:x})}return{nodes:Array.from(f.values()),edges:t}}import{relative as Qr}from"node:path";async function _f(r){let n=[],f=[];if(r.graphType==="imports"||r.graphType==="combined"){let u=await Tf({adapters:r.adapters,anchorFiles:r.anchorFiles,repoRoot:r.repoRoot,depth:r.depth,includeTests:r.includeTests,includeExternal:r.includeExternal,ignoreMatchers:r.ignoreMatchers});n=Bf(n,u.nodes),f=Xf(f,u.edges)}if(r.graphType==="calls"||r.graphType==="combined"){let u=await D$(r);n=Bf(n,u.nodes),f=Xf(f,u.edges)}let m=Zf(n,f,r.collapse);n=m.nodes,f=m.edges,Cf(n,f);let t=Yf(n,f,{maxNodes:r.maxNodes,maxEdges:r.maxEdges});return Cf(t.nodes,t.edges),{nodes:t.nodes,edges:t.edges,truncated:t.truncated,truncatedNodes:t.truncatedNodes,truncatedEdges:t.truncatedEdges}}async function D$(r){let n=new Map,f=[],m=Array.from(r.anchorFiles);for(let t of r.adapters){if(!t.findCallExpressions)continue;let u=await t.findCallExpressions({files:m.filter(($)=>$.startsWith(t.workspace.root))});for(let $ of u){let y=z$($.callerFile,$.callerSymbol,t.lang,r.repoRoot),x=H$($.calleeSymbol,t.lang,r.repoRoot);if(!n.has(y))n.set(y,Qf({id:y,filePath:$.callerFile,symbolName:$.callerSymbol,lang:t.lang,repoRoot:r.repoRoot,workspaceRoot:t.workspace.root,anchor:r.anchorFiles.has($.callerFile),confidence:1}));if(!n.has(x))n.set(x,Qf({id:x,filePath:q$($.calleeSymbol),symbolName:S$($.calleeSymbol),lang:t.lang,repoRoot:r.repoRoot,workspaceRoot:t.workspace.root,anchor:!1,confidence:$.confidence}));let w=$.isDynamic?"calls-dynamic":$.confidence<0.5?"calls-unknown":"calls";f.push({from:y,to:x,type:w,callsite:{filePath:B(Qr(r.repoRoot,$.callerFile)),range:$.range},confidence:$.confidence})}}return{nodes:Array.from(n.values()),edges:f}}function z$(r,n,f,m){let t=B(Qr(m,r));if(n)return`${f}:${t}#${n}`;return`${f}:${t}`}function H$(r,n,f){if(r.includes("#")){let m=r.split("#"),t=m[0],u=m.slice(1).join("#");if(t.includes("/"))return`${n}:${t}#${u}`}if(r.startsWith("/")||r.includes(":"))return`${n}:${r}`;return`${n}:[unresolved]#${r}`}function q$(r){if(r.includes("#")){let n=r.split("#")[0];if(n.includes("/"))return n}return"[unresolved]"}function S$(r){if(r.includes("#"))return r.split("#").slice(1).join("#");return r}function Qf(r){let{id:n,filePath:f,symbolName:m,lang:t,repoRoot:u,workspaceRoot:$,anchor:y,confidence:x}=r,w=f.startsWith("/")?B(Qr(u,f)):f,G=$.startsWith("/")?B(Qr(u,$))||".":$,E="function";if(m){if(m.includes(".")){let W=m.split(".");if(W[W.length-1]==="constructor")E="constructor";else E="method"}}else E="file";return{id:n,kind:E,lang:t,name:m??w.split("/").pop()??w,filePath:w,workspaceRoot:G,anchor:y,external:f==="[unresolved]",confidence:x}}function Bf(r,n){let f=new Map;for(let m of r)f.set(m.id,m);for(let m of n){let t=f.get(m.id);if(!t)f.set(m.id,m);else f.set(m.id,{...t,anchor:t.anchor||m.anchor,confidence:Math.max(t.confidence,m.confidence)})}return Array.from(f.values())}function Xf(r,n){let f=new Set,m=[];for(let t of r){let u=`${t.from}|${t.to}|${t.type}`;if(!f.has(u))f.add(u),m.push(t)}for(let t of n){let u=`${t.from}|${t.to}|${t.type}`;if(!f.has(u))f.add(u),m.push(t)}return m}function Cf(r,n){r.sort((f,m)=>f.id.localeCompare(m.id)),n.sort((f,m)=>{let t=f.from.localeCompare(m.from);if(t!==0)return t;let u=f.to.localeCompare(m.to);if(u!==0)return u;return f.type.localeCompare(m.type)})}var Of=J(()=>{Jf();_()});function zf(r){let n=[];if(n.push("digraph G {"),n.push(" rankdir=LR;"),n.push(" node [shape=box];"),n.push(""),new Set(r.nodes.map((t)=>t.workspaceRoot)).size>1){let t=P$(r.nodes),u=0;for(let[$,y]of t.entries()){n.push(` subgraph cluster_${u} {`),n.push(` label="${Hf($)}";`);for(let x of y)n.push(` ${Df(x)}`);n.push(" }"),n.push(""),u++}}else for(let t of r.nodes)n.push(` ${Df(t)}`);n.push("");for(let t of r.edges)n.push(` ${V$(t)}`);return n.push("}"),n.join(`
|
|
61
|
+
`)}function P$(r){let n=new Map;for(let f of r){let m=n.get(f.workspaceRoot);if(m)m.push(f);else n.set(f.workspaceRoot,[f])}return n}function Df(r){let n=[`label="${Hf(r.name)}"`];if(r.anchor)n.push('style="filled"'),n.push('fillcolor="lightblue"');else if(r.external)n.push('style="dashed"'),n.push('color="gray"');if(r.kind==="class")n.push('shape="ellipse"');else if(r.kind==="function"||r.kind==="method")n.push('shape="diamond"');return`"${dr(r.id)}" [${n.join(", ")}];`}function V$(r){let n=[];if(r.type==="imports-dynamic"||r.type==="calls-dynamic"||r.type==="calls-unknown")n.push('style="dashed"');if(r.type==="tests")n.push('color="green"'),n.push('label="tests"');if(r.type==="calls")n.push('color="blue"');if(r.confidence<0.8&&!n.some((m)=>m.includes("style")))n.push('style="dotted"');let f=n.length>0?` [${n.join(", ")}]`:"";return`"${dr(r.from)}" -> "${dr(r.to)}"${f};`}function dr(r){return r.replace(/\\/g,"\\\\").replace(/"/g,"\\\"")}function Hf(r){return r.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n")}import qf from"fast-glob";import{resolve as ar,relative as j$}from"node:path";import{writeFile as R$}from"node:fs/promises";async function Pf(r){let n=process.cwd(),f=await p(n),m=await s(f),{config:t}=await b(f),u=r.allWorkspaces??t.workspaces.mode==="all",$=r.workspace??t.workspaces.mode,y=await yr({workspaces:m,cwd:n,workspaceFlag:$==="all"?void 0:$,allWorkspaces:u}),x=y.mode;if(y.workspaces.length===0)throw Error("No workspaces detected");let w=y.workspaces[0],{config:G}=await b(f,w?.root),E=Vf(G,r),W=r.includeTests??E.includeTests,U=Yr(Boolean(r.debug)),K=r.fromDiff?await l(f,r.fromDiff):void 0,A=r.fromLog?ar(n,r.fromLog):void 0,L=A?d(await S(A),f):void 0,I=c$({allWorkspaces:m,baseWorkspaces:y.workspaces,cwd:n,entries:r.entries,diffHunks:K,logAnchors:L}),X=await Sf({repoRoot:f,workspaces:I,args:r,logger:U}),O=F$(X,y.workspaces),Y=await a({repoRoot:f,cwd:n,workspaces:I,adapters:O,entries:r.entries,symbols:r.symbols,fromDiff:r.fromDiff,fromLog:A??r.fromLog,diffHunks:K,logAnchors:L});if(Y.unresolvedSymbols.length>0&&r.fallbackAll&&!r.allWorkspaces)U.debug("Symbol not found in scope; retrying across all workspaces"),I=m,x="all",X=await Sf({repoRoot:f,workspaces:I,args:r,logger:U}),O=X,Y=await a({repoRoot:f,cwd:n,workspaces:I,adapters:O,entries:r.entries,symbols:r.symbols,fromDiff:r.fromDiff,fromLog:A??r.fromLog,diffHunks:K,logAnchors:L});if(Y.unresolvedSymbols.length>0)process.stderr.write(`Symbol(s) not found: ${Y.unresolvedSymbols.join(", ")}
|
|
66
62
|
`),process.stderr.write(`Try --all-workspaces or --fallback-all
|
|
67
|
-
`),process.exit(2);if(
|
|
68
|
-
`);for(let
|
|
69
|
-
`);for(let
|
|
63
|
+
`),process.exit(2);if(r.symbolStrict&&Y.ambiguousSymbols.length>0){process.stderr.write(`Ambiguous symbol(s) found (--symbol-strict enabled):
|
|
64
|
+
`);for(let c of Y.ambiguousSymbols){process.stderr.write(` ${c.query}:
|
|
65
|
+
`);for(let tr of c.definitions){let Xr=tr.filePath.replace(f+"/","");process.stderr.write(` - ${Xr}:${tr.range.startLine}
|
|
70
66
|
`)}}process.stderr.write(`Use file-hint syntax (e.g., path/to/file.ts:SymbolName) to disambiguate.
|
|
71
|
-
`),process.exit(2)}let
|
|
72
|
-
`)
|
|
67
|
+
`),process.exit(2)}let H=await b$({repoRoot:f,workspaces:I,args:r}),C=await _f({adapters:X,anchorFiles:Y.anchorFiles,repoRoot:f,graphType:r.graphType,depth:r.depth,includeTests:W,includeExternal:r.includeExternal??!1,maxNodes:r.maxNodes,maxEdges:r.maxEdges,collapse:r.collapse,ignoreMatchers:H}),v={meta:{repoRoot:B(j$(n,f))||".",generatedAt:r.noTimestamp?void 0:new Date().toISOString(),command:`repo-slice ${process.argv.slice(2).join(" ")}`,scope:{mode:x,workspaces:I.map((c)=>c.id)},graphType:r.graphType,depth:r.depth,maxNodes:r.maxNodes,maxEdges:r.maxEdges,collapse:r.collapse,truncated:C.truncated,truncatedNodes:C.truncatedNodes>0?C.truncatedNodes:void 0,truncatedEdges:C.truncatedEdges>0?C.truncatedEdges:void 0},nodes:C.nodes,edges:C.edges},N=r.format==="json"?N$(v):zf(v);if(r.out){let c=ar(n,r.out);await R$(c,N,"utf8")}else process.stdout.write(N+`
|
|
68
|
+
`)}function N$(r){return JSON.stringify(r,null,2)}function Vf(r,n){return{...r,depth:n.depth??r.depth,includeTests:n.includeTests??r.includeTests}}function c$(r){let n=new Map;for(let f of r.baseWorkspaces)n.set(f.root,f);for(let f of r.entries){let m=ar(r.cwd,f),t=z(r.allWorkspaces,m);if(t)n.set(t.root,t)}for(let f of r.diffHunks??[]){let m=z(r.allWorkspaces,f.filePath);if(m)n.set(m.root,m)}for(let f of r.logAnchors??[]){let m=z(r.allWorkspaces,f.filePath);if(m)n.set(m.root,m)}return Array.from(n.values()).sort((f,m)=>f.root.localeCompare(m.root))}async function Sf(r){let n=[];for(let f of r.workspaces){let{config:m}=await b(r.repoRoot,f.root),t=Vf(m,r.args);r.logger.debug(`Indexing workspace ${f.root}`);let u=await i({repoRoot:r.repoRoot,workspaceRoot:f.root,extraIgnorePatterns:m.ignore}),$=await M$(f.root,u),y=await Kr({workspace:f,ignoreMatcher:u,pythonImportRoots:m.workspaces.pythonImportRoots,files:$});n.push(...y)}return n}async function b$(r){let n=new Map;for(let f of r.workspaces){let{config:m}=await b(r.repoRoot,f.root),t=await i({repoRoot:r.repoRoot,workspaceRoot:f.root,extraIgnorePatterns:m.ignore});n.set(f.id,t)}return n}function F$(r,n){let f=new Set(n.map((m)=>m.root));return r.filter((m)=>f.has(m.workspace.root))}async function M$(r,n){let f=await qf(["**/*.ts","**/*.tsx","**/*.js","**/*.jsx"],{cwd:r,absolute:!0,dot:!1,followSymbolicLinks:!1}),m=await qf(["**/*.py"],{cwd:r,absolute:!0,dot:!1,followSymbolicLinks:!1});return{tsFiles:f.map((t)=>k(t)).filter((t)=>!n.ignores(t)).sort(),pyFiles:m.map((t)=>k(t)).filter((t)=>!n.ignores(t)).sort()}}var jf=J(()=>{$r();ur();xr();Hr();qr();jr();Ir();Tr();Of();D();_()});var Rf={};h(Rf,{renderGraphHelp:()=>Br,graphCommand:()=>g$});async function g$(r){let n;try{n=v$(r)}catch(m){let t=m instanceof Error?m.message:String(m);process.stderr.write(`${t}
|
|
69
|
+
`),process.stderr.write(Br()+`
|
|
70
|
+
`),process.exit(3);return}if(n.help)process.stdout.write(Br()+`
|
|
71
|
+
`),process.exit(0);let{args:f}=n;if(f.entries.length===0&&f.symbols.length===0&&!f.fromDiff&&!f.fromLog){process.stderr.write(`Error: No anchors specified.
|
|
72
|
+
`),process.stderr.write(`Use --entry, --symbol, --from-diff, or --from-log to specify what to include.
|
|
73
|
+
|
|
74
|
+
`),process.stderr.write(Br()+`
|
|
75
|
+
`),process.exit(3);return}await Pf(f)}function v$(r){let n={entries:[],symbols:[],graphType:"imports",depth:2,maxNodes:500,maxEdges:2000,collapse:"external",format:"json"},f=!1,m=(t,u)=>{let $=r[t+1];if(!$||$.startsWith("--"))throw Error(`Missing value for ${u}`);return $};for(let t=0;t<r.length;t+=1){let u=r[t];if(u==="--help"||u==="-h"){f=!0;continue}if(!u.startsWith("--"))throw Error(`Unexpected argument: ${u}`);let[$,y]=u.split("=",2);switch($){case"--entry":if(n.entries.push(y??m(t,$)),!y)t+=1;break;case"--symbol":if(n.symbols.push(y??m(t,$)),!y)t+=1;break;case"--symbol-strict":n.symbolStrict=!0;break;case"--from-diff":if(n.fromDiff=y??m(t,$),!y)t+=1;break;case"--from-log":if(n.fromLog=y??m(t,$),!y)t+=1;break;case"--workspace":if(n.workspace=y??m(t,$),!y)t+=1;break;case"--all-workspaces":n.allWorkspaces=!0;break;case"--fallback-all":n.fallbackAll=!0;break;case"--graph-type":{let x=y??m(t,$);if(!y)t+=1;if(!["imports","calls","combined"].includes(x))throw Error(`Invalid graph-type: ${x}`);n.graphType=x;break}case"--depth":if(n.depth=er(y??m(t,$),$),!y)t+=1;break;case"--scope":{let x=y??m(t,$);if(!y)t+=1;if(!["symbol","file","workspace"].includes(x))throw Error(`Invalid scope: ${x}`);n.scope=x;break}case"--include-tests":{let x=y??m(t,$);if(!y)t+=1;if(!["auto","true","false"].includes(x))throw Error(`Invalid include-tests value: ${x}`);n.includeTests=x;break}case"--include-external":n.includeExternal=!0;break;case"--max-nodes":if(n.maxNodes=er(y??m(t,$),$),!y)t+=1;break;case"--max-edges":if(n.maxEdges=er(y??m(t,$),$),!y)t+=1;break;case"--collapse":{let x=y??m(t,$);if(!y)t+=1;if(!["none","external","file","class"].includes(x))throw Error(`Invalid collapse mode: ${x}`);n.collapse=x;break}case"--python-engine":{let x=y??m(t,$);if(!y)t+=1;if(!["treesitter","pyright"].includes(x))throw Error(`Invalid python-engine: ${x}`);n.pythonEngine=x;break}case"--format":{let x=y??m(t,$);if(!y)t+=1;if(!["json","dot"].includes(x))throw Error(`Invalid format: ${x}`);n.format=x;break}case"--out":if(n.out=y??m(t,$),!y)t+=1;break;case"--debug":n.debug=!0;break;case"--no-timestamp":n.noTimestamp=!0;break;default:throw Error(`Unknown flag: ${$}`)}}if(n.allWorkspaces&&n.workspace)throw Error("Cannot combine --all-workspaces with --workspace");return{help:f,args:n}}function er(r,n){let f=Number(r);if(!Number.isFinite(f))throw Error(`Invalid number for ${n}: ${r}`);return f}function Br(){return`repo-slice graph - generate dependency graphs from anchors
|
|
73
76
|
|
|
74
77
|
Usage:
|
|
75
78
|
repo-slice graph [options]
|
|
@@ -108,9 +111,79 @@ Exit codes:
|
|
|
108
111
|
1 runtime error
|
|
109
112
|
2 anchor resolution failure
|
|
110
113
|
3 invalid CLI usage
|
|
111
|
-
`}var
|
|
112
|
-
`)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`),process.
|
|
114
|
+
`}var Nf=J(()=>{jf()});var cf={};h(cf,{workspacesCommand:()=>h$});async function h$(r){let f=p$(r).format??"json",m=await p(process.cwd()),t=await s(m);if(f==="json"){let u=t.slice().sort(($,y)=>$.root.localeCompare(y.root)).map(($)=>({name:$.name,kind:$.kind,root:$.root}));process.stdout.write(JSON.stringify(u,null,2)+`
|
|
115
|
+
`)}else{let u=t.slice().sort(($,y)=>$.root.localeCompare(y.root)).map(($)=>`${$.name} ${$.kind} ${$.root}`);process.stdout.write(u.join(`
|
|
116
|
+
`)+(u.length?`
|
|
117
|
+
`:""))}}function p$(r){let n={};for(let f=0;f<r.length;f+=1){let m=r[f];if(m==="--help"||m==="-h")process.stdout.write(s$()+`
|
|
118
|
+
`),process.exit(0);if(!m.startsWith("--"))throw Error(`Unexpected argument: ${m}`);let[t,u]=m.split("=",2);switch(t){case"--format":{let $=u??r[f+1];if(!u)f+=1;if(!["json","text"].includes($))throw Error(`Invalid format: ${$}`);n.format=$;break}default:throw Error(`Unknown flag: ${t}`)}}return n}function s$(){return`repo-slice workspaces - list detected workspaces
|
|
119
|
+
|
|
120
|
+
Usage:
|
|
121
|
+
repo-slice workspaces [options]
|
|
122
|
+
|
|
123
|
+
Options:
|
|
124
|
+
--format <json|text> Output format (default: json)
|
|
125
|
+
--help, -h Show this help message
|
|
126
|
+
|
|
127
|
+
Exit codes:
|
|
128
|
+
0 success
|
|
129
|
+
1 runtime error
|
|
130
|
+
3 invalid CLI usage
|
|
131
|
+
`}var bf=J(()=>{$r();ur()});function _r(){return`repo-slice - deterministic repo context bundler
|
|
132
|
+
|
|
133
|
+
Usage:
|
|
134
|
+
repo-slice pack [options]
|
|
135
|
+
repo-slice graph [options]
|
|
136
|
+
repo-slice workspaces [options]
|
|
137
|
+
repo-slice version
|
|
138
|
+
|
|
139
|
+
Pack options:
|
|
140
|
+
--entry <path> Add entry file anchor (repeatable)
|
|
141
|
+
--symbol <query> Add symbol query anchor (repeatable)
|
|
142
|
+
--symbol-strict Fail if any symbol resolves to multiple definitions
|
|
143
|
+
--from-diff <revRange> Add changed files + hunks as anchors
|
|
144
|
+
--from-log <path> Parse logs into file/line anchors
|
|
145
|
+
--workspace <auto|name|path>
|
|
146
|
+
--all-workspaces
|
|
147
|
+
--fallback-all
|
|
148
|
+
--depth <n>
|
|
149
|
+
--budget-chars <n>
|
|
150
|
+
--budget-tokens <n>
|
|
151
|
+
--include-tests <auto|true|false>
|
|
152
|
+
--format <json|md> Output format (default: json)
|
|
153
|
+
--out <path>
|
|
154
|
+
--reason
|
|
155
|
+
--redact
|
|
156
|
+
--debug
|
|
157
|
+
--no-timestamp
|
|
158
|
+
|
|
159
|
+
Graph options:
|
|
160
|
+
--entry <path> Add entry file anchor (repeatable)
|
|
161
|
+
--symbol <query> Add symbol query anchor (repeatable)
|
|
162
|
+
--from-diff <revRange> Add changed files as anchors
|
|
163
|
+
--from-log <path> Parse logs into file/line anchors
|
|
164
|
+
--workspace <auto|name|path>
|
|
165
|
+
--all-workspaces
|
|
166
|
+
--graph-type <imports|calls|combined>
|
|
167
|
+
--depth <n>
|
|
168
|
+
--include-tests <auto|true|false>
|
|
169
|
+
--include-external
|
|
170
|
+
--max-nodes <n>
|
|
171
|
+
--max-edges <n>
|
|
172
|
+
--collapse <none|external|file|class>
|
|
173
|
+
--format <json|dot>
|
|
174
|
+
--out <path>
|
|
175
|
+
--no-timestamp
|
|
176
|
+
|
|
177
|
+
Workspaces options:
|
|
178
|
+
--format <json|text> Output format (default: json)
|
|
179
|
+
|
|
180
|
+
Exit codes:
|
|
181
|
+
0 success
|
|
182
|
+
1 runtime error
|
|
183
|
+
2 anchor resolution failure
|
|
184
|
+
3 invalid CLI usage
|
|
185
|
+
`}var Ff=process.argv.slice(2),g=Ff[0],rn=Ff.slice(1);async function i$(){if(!g||g==="--help"||g==="-h")process.stdout.write(_r()+`
|
|
186
|
+
`),process.exit(0);if(g==="--version"||g==="-v"){await(await Promise.resolve().then(() => (Dr(),Or))).versionCommand();return}switch(g){case"pack":await(await Promise.resolve().then(() => (Af(),Uf))).packCommand(rn);return;case"graph":await(await Promise.resolve().then(() => (Nf(),Rf))).graphCommand(rn);return;case"workspaces":await(await Promise.resolve().then(() => (bf(),cf))).workspacesCommand(rn);return;case"version":await(await Promise.resolve().then(() => (Dr(),Or))).versionCommand();return;default:process.stderr.write(`Unknown command: ${g}
|
|
187
|
+
`),process.stderr.write(_r()+`
|
|
188
|
+
`),process.exit(3)}}i$().catch((r)=>{let n=r instanceof Error?r.message:String(r);process.stderr.write(`${n}
|
|
116
189
|
`),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-vibe/repo-slice",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A deterministic CLI that extracts high-signal context bundles from repositories for AI-assisted coding workflows",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,6 +46,11 @@
|
|
|
46
46
|
"test": "bun test",
|
|
47
47
|
"test:unit": "bun test test/budget.test.ts test/output-md.test.ts test/output-json.test.ts test/workspaces.test.ts test/anchors-diff.test.ts test/anchors-log.test.ts",
|
|
48
48
|
"test:e2e": "bun test test/e2e.test.ts",
|
|
49
|
+
"bench": "bun run benchmarks/run.ts",
|
|
50
|
+
"bench:save": "bun run benchmarks/run.ts --save",
|
|
51
|
+
"bench:compare": "bun run benchmarks/run.ts --compare",
|
|
52
|
+
"bench:pack": "bun run benchmarks/run.ts --suite pack",
|
|
53
|
+
"bench:graph": "bun run benchmarks/run.ts --suite graph",
|
|
49
54
|
"changeset": "changeset",
|
|
50
55
|
"changeset:version": "changeset version",
|
|
51
56
|
"release": "bun run build && changeset publish",
|
|
@@ -55,6 +60,7 @@
|
|
|
55
60
|
"dependencies": {
|
|
56
61
|
"fast-glob": "^3.3.3",
|
|
57
62
|
"ignore": "^5.3.1",
|
|
63
|
+
"msgpackr": "^1.11.8",
|
|
58
64
|
"tree-sitter": "^0.21.1",
|
|
59
65
|
"tree-sitter-python": "^0.21.0",
|
|
60
66
|
"typescript": "^5.9.3",
|