跳到正文
DEV Community· AmanullaShaikh·· 8 天前AI 評分56

Apex Agents 開源 CLI 工具以 Babel AST 壓縮 JS/TS 函式主體

I built a CLI harness that strips JS/TS function bodies with Babel AST to save 80% context tokens

AI 導讀

AmanullaShaikh 開源 Apex Agents,這個 CLI 工具透過 Babel AST 將 TypeScript、JSX 和 JavaScript 函式主體替換為 {},保留類型、泛型、參數及匯出內容。

正文

Cover image for I built a CLI harness that strips JS/TS function bodies with Babel AST to save 80% context tokens

AmanullaShaikh

While working on large Next.js and TypeScript repositories, I noticed AI coding agents (Cursor, Claude Code) constantly burning through context limits. They were reading 500-line implementation files when all they really needed were the types, interfaces, and exported signatures.

To solve this mechanically, I engineered and open-sourced Apex Agents.

How It Works:

  1. Babel AST Compactor (npx apex-agents compact):
    Parses TypeScript, JSX, and JavaScript using @babel/parser and replaces function bodies with {} while preserving all types, generics, parameters, and exports. In our tests, an ~13k token codebase compacted down to ~1.4k tokens (88.5% reduction) into an APEX_CONTEXT.md file.

  2. Pre-Commit Anti-Cheat & Secret Guard (.git/hooks/pre-commit):
    Diff auditor physically prevents AI agents from modifying or skipping tests to fake a "pass", and halts any accidental commit containing high-entropy API keys.

  3. 38 Specialist Personas (.cursor/rules):
    Injects domain-specific engineering rules directly into .cursor/rules for database performance, React 19 architecture, and Lighthouse optimization.

  4. Native MCP Server:
    Built-in JSON-RPC stdio server ready to plug into Claude Desktop or Cursor MCP settings.

Try it in any repo:

bash:
npx apex-agents init

GitHub: github.com/AmanullaShaikh/apex-agents
NPM: npmjs.com/package/apex-agents

Feedback and pull requests are welcome!

來源:DEV Community · dev.to