token-pilot 0.8.1 → 0.8.3
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/CHANGELOG.md +11 -0
- package/dist/ast-index/client.d.ts +1 -0
- package/dist/ast-index/client.js +20 -4
- package/dist/handlers/code-audit.js +2 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ All notable changes to Token Pilot will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.8.3] - 2026-03-08
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **code_audit pattern search — root cause fix** — `ast-index agrep` does not support `--limit` flag. Token Pilot was passing `--limit 50` which caused the command to fail silently, returning 0 results across v0.8.0–v0.8.2. Removed the flag; results are now limited via `.slice()` after parsing.
|
|
12
|
+
|
|
13
|
+
## [0.8.2] - 2026-03-08
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- **code_audit pattern search** — inject `node_modules/.bin` into PATH so `ast-index agrep` can find `sg` (ast-grep) when it's installed as optional dependency but not in system PATH.
|
|
17
|
+
- **code_audit annotations** — strip `@` prefix from annotation names (`@Injectable` → `Injectable`). ast-index expects names without `@`.
|
|
18
|
+
|
|
8
19
|
## [0.8.1] - 2026-03-08
|
|
9
20
|
|
|
10
21
|
### Added
|
|
@@ -12,6 +12,7 @@ export declare class AstIndexClient {
|
|
|
12
12
|
private configBinaryPath;
|
|
13
13
|
private autoInstall;
|
|
14
14
|
private astGrepAvailable;
|
|
15
|
+
private astGrepBinDir;
|
|
15
16
|
constructor(projectRoot: string, timeout?: number, options?: {
|
|
16
17
|
binaryPath?: string | null;
|
|
17
18
|
autoInstall?: boolean;
|
package/dist/ast-index/client.js
CHANGED
|
@@ -17,6 +17,7 @@ export class AstIndexClient {
|
|
|
17
17
|
configBinaryPath;
|
|
18
18
|
autoInstall;
|
|
19
19
|
astGrepAvailable = null;
|
|
20
|
+
astGrepBinDir = null;
|
|
20
21
|
constructor(projectRoot, timeout = 5000, options) {
|
|
21
22
|
this.projectRoot = projectRoot;
|
|
22
23
|
this.timeout = timeout;
|
|
@@ -647,14 +648,24 @@ export class AstIndexClient {
|
|
|
647
648
|
async checkAstGrep() {
|
|
648
649
|
if (this.astGrepAvailable !== null)
|
|
649
650
|
return this.astGrepAvailable;
|
|
651
|
+
// Try system PATH first
|
|
650
652
|
try {
|
|
651
653
|
await execFileAsync('sg', ['--version'], { timeout: 3000 });
|
|
652
654
|
this.astGrepAvailable = true;
|
|
655
|
+
return true;
|
|
653
656
|
}
|
|
654
|
-
catch {
|
|
655
|
-
|
|
657
|
+
catch { /* not in PATH */ }
|
|
658
|
+
// Try node_modules/.bin/sg (from optionalDependencies or source installs)
|
|
659
|
+
try {
|
|
660
|
+
const localBinDir = new URL('../../node_modules/.bin', import.meta.url).pathname;
|
|
661
|
+
await execFileAsync(localBinDir + '/sg', ['--version'], { timeout: 3000 });
|
|
662
|
+
this.astGrepBinDir = localBinDir;
|
|
663
|
+
this.astGrepAvailable = true;
|
|
664
|
+
return true;
|
|
656
665
|
}
|
|
657
|
-
|
|
666
|
+
catch { /* not found locally either */ }
|
|
667
|
+
this.astGrepAvailable = false;
|
|
668
|
+
return false;
|
|
658
669
|
}
|
|
659
670
|
/** Structural pattern search via ast-grep. Requires ast-grep (sg) installed. */
|
|
660
671
|
async agrep(pattern, options) {
|
|
@@ -671,7 +682,6 @@ export class AstIndexClient {
|
|
|
671
682
|
const args = ['agrep', pattern];
|
|
672
683
|
if (options?.lang)
|
|
673
684
|
args.push('--lang', options.lang);
|
|
674
|
-
args.push('--limit', String(limit));
|
|
675
685
|
try {
|
|
676
686
|
const result = await this.exec(args, 15000);
|
|
677
687
|
return this.parseAgrepText(result).slice(0, limit);
|
|
@@ -836,10 +846,16 @@ export class AstIndexClient {
|
|
|
836
846
|
if (!this.binaryPath) {
|
|
837
847
|
throw new Error('ast-index not initialized. Call init() first.');
|
|
838
848
|
}
|
|
849
|
+
// If ast-grep was found in node_modules/.bin, inject it into PATH
|
|
850
|
+
// so ast-index can find sg when running agrep
|
|
851
|
+
const env = this.astGrepBinDir
|
|
852
|
+
? { ...process.env, PATH: `${this.astGrepBinDir}:${process.env.PATH ?? ''}` }
|
|
853
|
+
: undefined;
|
|
839
854
|
const { stdout, stderr } = await execFileAsync(this.binaryPath, args, {
|
|
840
855
|
timeout: timeoutMs ?? this.timeout,
|
|
841
856
|
maxBuffer: 10 * 1024 * 1024, // 10MB
|
|
842
857
|
cwd: this.projectRoot,
|
|
858
|
+
...(env && { env }),
|
|
843
859
|
});
|
|
844
860
|
if (stderr) {
|
|
845
861
|
console.error(`[token-pilot] ast-index stderr (${args[0]}): ${stderr.trim()}`);
|
|
@@ -17,7 +17,8 @@ export async function handleCodeAudit(args, projectRoot, astIndex) {
|
|
|
17
17
|
case 'deprecated':
|
|
18
18
|
return handleDeprecated(limit, projectRoot, astIndex);
|
|
19
19
|
case 'annotations':
|
|
20
|
-
|
|
20
|
+
// Strip @ prefix — ast-index expects "Injectable" not "@Injectable"
|
|
21
|
+
return handleAnnotations(args.name.replace(/^@/, ''), limit, projectRoot, astIndex);
|
|
21
22
|
case 'all':
|
|
22
23
|
return handleAll(limit, projectRoot, astIndex);
|
|
23
24
|
default:
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "token-pilot",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "Save 80% tokens when AI reads code — MCP server for token-efficient code navigation, AST-aware structural reading instead of dumping full files into context window",
|
|
3
|
+
"version": "0.8.3",
|
|
4
|
+
"description": "Save 60-80% tokens when AI reads code — MCP server for token-efficient code navigation, AST-aware structural reading instead of dumping full files into context window",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"bin": {
|