token-pilot 0.8.1 → 0.8.2

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 CHANGED
@@ -5,6 +5,12 @@ 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.2] - 2026-03-08
9
+
10
+ ### Fixed
11
+ - **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.
12
+ - **code_audit annotations** — strip `@` prefix from annotation names (`@Injectable` → `Injectable`). ast-index expects names without `@`.
13
+
8
14
  ## [0.8.1] - 2026-03-08
9
15
 
10
16
  ### 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;
@@ -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
- this.astGrepAvailable = false;
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
- return this.astGrepAvailable;
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) {
@@ -836,10 +847,16 @@ export class AstIndexClient {
836
847
  if (!this.binaryPath) {
837
848
  throw new Error('ast-index not initialized. Call init() first.');
838
849
  }
850
+ // If ast-grep was found in node_modules/.bin, inject it into PATH
851
+ // so ast-index can find sg when running agrep
852
+ const env = this.astGrepBinDir
853
+ ? { ...process.env, PATH: `${this.astGrepBinDir}:${process.env.PATH ?? ''}` }
854
+ : undefined;
839
855
  const { stdout, stderr } = await execFileAsync(this.binaryPath, args, {
840
856
  timeout: timeoutMs ?? this.timeout,
841
857
  maxBuffer: 10 * 1024 * 1024, // 10MB
842
858
  cwd: this.projectRoot,
859
+ ...(env && { env }),
843
860
  });
844
861
  if (stderr) {
845
862
  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
- return handleAnnotations(args.name, limit, projectRoot, astIndex);
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.1",
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.2",
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": {