tokless 0.5.0 → 0.5.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/README.en.md CHANGED
@@ -10,199 +10,89 @@
10
10
 
11
11
  [简体中文](./README.md) | English
12
12
 
13
- **Zero-dependency token optimizer for AI coding agents (Google Antigravity, Claude Code, Codex CLI, and extensible via `targets/`).**
13
+ > **Cut runaway prompt-cache snowballing and blind-read token bloat in half—without sacrificing a single line of debugging or coding quality.**
14
14
 
15
- `tokless` cuts runaway prompt-cache snowballing without sacrificing code quality by combining sub-100ms `[Lstart-Lend]` AST-like code skeleton navigation, native `PreToolUse` blind-read brakes, MCP-stripped subagents, and 0-token local session billing/compaction audits.
15
+ `tokless` is a **zero-dependency Node.js (`>=18`)** token optimizer and local billing inspector built for AI coding agents (one-command native setup for **Google Antigravity**, **Claude Code**, and **Codex CLI**, plus universal CLI/rules for Cursor, Windsurf, Cline, Roo Code, and others):
16
16
 
17
- In a controlled A/B bug-hunt and fix benchmark on a production Tauri + Rust + React desktop codebase, `tokless` reduced **total token throughput by 53.2% (-11.38M tokens)**, cut **cumulative Cache Read tokens by 53.8% (-11.23M tokens)**, and finished in **34.4% fewer model turns** while finding and fixing the exact same **7 deep concurrency/logic bugs** (*Note: this A/B benchmark was recorded on early `v0.1.0` with only the baseline skeletonizer and unsliced blind-read block; we have not yet re-run a full long-horizon comparison on newer releases, which add MCP-stripped lean subagents and refined line-range pass-through for even stronger theoretical savings*).
17
+ 1. **Stop Blind-Read Bloat (`tokless skeleton`)**: Semantic search (`@Codebase`) finds files, not line ranges—agents still lazily read entire 1,500-line files into context, compounding `Cache Read` costs on every subsequent turn. `tokless` extracts function/class/macro/typedef signatures with exact **`[Lstart-Lend]` line ranges** in milliseconds so agents read only the exact slice they need (**85%~97% exploration savings**).
18
+ 2. **Strip Idle MCP Base Tax (`tokless-coder` / `tokless-reviewer`)**: Lean roles with `inheritMcp: false` strip unused external MCP and tool schemas during pure coding or read-only review sessions.
19
+ 3. **Inspect Real Token Bills Offline (`tokless audit`)**: Dissect Top 5 costliest steps, Prefix Cache cliffs (including Orchestrator/dual-model switches and idle expirations), and project rule/MCP base overhead at **0 LLM tokens**.
18
20
 
19
21
  ---
20
22
 
21
- ## Quick Install (Zero Dependencies · Node.js `>=18`)
23
+ ## Real-World A/B Benchmark (Tauri + Rust + React Bug Hunt & Fix)
22
24
 
23
- ### Option 1: One-Line CLI Setup (Recommended)
24
-
25
- Auto-detects and installs into Google Antigravity, Claude Code (`~/.claude`), and Codex CLI (`~/.codex`). When invoked via `npx`, `tokless` automatically switches to file-copy mode so hooks never break after npm cache cleanup:
26
-
27
- ```bash
28
- npx tokless install
29
- ```
30
-
31
- Target specific hosts or cleanly uninstall anytime:
32
-
33
- ```bash
34
- npx tokless install --target agy # Google Antigravity only
35
- npx tokless install --target claude # Non-destructively merge into ~/.claude/settings.json + skills
36
- npx tokless install --target codex # Install ~/.codex/skills/code-skeleton
37
- npx tokless install --target all # Install across all supported hosts
38
- npx tokless uninstall --target all # Cleanly remove hooks/skills and restore original settings
39
- ```
40
-
41
- ### Option 2: Paste One Prompt to Your AI Agent
42
-
43
- Drop this directly into Antigravity or Claude Code and let the agent wire itself up:
44
-
45
- ```text
46
- Please run `npx tokless install` to enable tokless (or clone https://github.com/daoif/tokless and run `node install.js`), then verify that the read-guard hook and skills are active.
47
- ```
48
-
49
- ---
50
-
51
- ## Why `@Codebase` or `repomix` Alone Isn't Enough
52
-
53
- A common question from heavy AI coding users: *"My IDE already has `@Codebase` semantic search, or I use `repomix`. Why does my 5-hour / weekly quota still burn out so fast?"*
54
-
55
- - **`@Codebase` is a search engine; `tokless` is a blind-read brake.** Semantic search tells the agent *which file* looks relevant, but it does not stop the agent from lazily calling `read_file` / `Read` without line numbers and dumping a 1,500-line file straight into context.
56
- - **`repomix` is a full-repo packer for web chat.** Packing an entire repo is great for browser chat UIs without local file tools, but inside a multi-turn CLI/IDE agent loop it front-loads tens of thousands of tokens from turn 1.
57
- - **The Cache Read Snowball:** In multi-step agent loops, `Cumulative Cache Read ≈ Average Context Size × Model Turns`. Dumping 30K tokens of irrelevant code on step 3 across a 50-turn task charges you 47 times—over **1.4M wasted Cache Read tokens** from a single lazy read.
58
- - **Compaction Thresholds:** Generation-3 models commonly trigger forced context compaction around **256K tokens** (`CHECKPOINT: # Resuming from a compaction`, collapsing context into a lossy summary), while Generation-4 models have been observed running past 440K without compacting (widely estimated around **512K**). Regardless of where the ceiling sits, keeping per-turn context lean and cutting redundant turns directly determines how fast your quota drains.
59
-
60
- `tokless` works alongside `@Codebase`: once the agent knows which directory or file to inspect, `tokless` generates `[Lstart-Lend]` function/class maps in ~80ms with zero pre-indexing, and its `PreToolUse` hook blocks un-sliced reads over 200 lines (returning the file's skeleton inline so the agent immediately re-reads the exact line range).
61
-
62
- ---
63
-
64
- ## Real-World Benchmark (Tauri + Rust + React Bug Hunt & Fix)
65
-
66
- Two isolated Git worktrees from the same commit (`3908815`), running the exact same model (`Gemini 4 Hydrogen High`) and prompt:
25
+ Two isolated Git worktrees from commit `3908815`, running the exact same model and prompt across a production desktop codebase:
67
26
 
68
27
  | Metric | Baseline (Default Agent) | With `tokless` | Delta |
69
28
  | :--- | :--- | :--- | :--- |
70
29
  | **Total Tokens (`input + cache_read + output`)** | 21,410,381 | **10,029,592** | **-53.2% (-11.38M)** |
71
30
  | **Cumulative Cache Read Tokens** | 20,858,589 | **9,627,700** | **-53.8% (-11.23M)** |
72
- | **Cumulative Input Tokens** | 494,886 | **352,020** | **-28.9%** |
73
- | **Model Invocations (Turns)** | 64 | **42** | **-34.4%** |
74
- | **Total Execution Steps** | 220 | **150** | **-31.8%** |
75
- | **`read_file` Calls (Full Blind Reads)** | 79 (3 blind reads) | **51 (0 blind reads)** | **-35.4%** |
76
- | **Peak Context Watermark** | 439,830 tokens | **323,344 tokens** | **-26.5%** |
77
- | **Time to First Code Edit** | 227s (Step 115) | **196s (Step 81)** | **31s faster / -34 steps** |
31
+ | **Model Turns / Execution Steps** | 64 turns / 220 steps | **42 turns / 150 steps** | **-34.4% turns** |
32
+ | **`read_file` Calls (Unsliced Blind Reads)** | 79 (3 blind reads) | **51 (0 blind reads)** | **-35.4% reads** |
33
+ | **Peak Context Watermark** | 439,830 tokens | **323,344 tokens** | **-26.5% peak** |
78
34
  | **Real Bugs Found & Fixed (Build Verified)** | 7 | **7** | **Zero quality loss** |
79
35
 
80
- > **Version Note (`v0.1.0` Baseline)**: The Tauri + Rust + React A/B figures above were captured on early `v0.1.0` (which only included baseline syntax skeleton extraction and unsliced blind-read blocking) and have not yet been re-run end-to-end on the latest release. With MCP-stripped lean roles (`inheritMcp: false`) and refined line-slice pass-through introduced in subsequent versions, current theoretical end-to-end token savings are even higher. Full reports: [benchmarks/real-world-bugfix-case.md](./benchmarks/real-world-bugfix-case.md) and [benchmarks/static-skeleton-benchmark.md](./benchmarks/static-skeleton-benchmark.md).
36
+ > *Note: Recorded on the `v0.1.0` baseline (skeleton + blind-read block only); newer releases add MCP-stripped lean roles, deep C/C++ parsing, and refined line-range pass-through. Full reports: [real-world-bugfix-case.md](./benchmarks/real-world-bugfix-case.md) and [static-skeleton-benchmark.md](./benchmarks/static-skeleton-benchmark.md).*
81
37
 
82
38
  ---
83
39
 
84
- ## Four Core Capabilities & Platform Boundaries (v0.5.0)
85
-
86
- `tokless` draws a transparent line between **universal capabilities that work with every AI coding tool** and **host-specific hooks or log parsers**:
87
-
88
- | Host Agent | 1. `tokless skeleton` + `AGENTS.md` Rules | 2. `PreToolUse` Blind-Read Guard | 3. Lean Subagents (`inheritMcp: false`) | 4. `tokless audit` Inspector |
89
- | :--- | :---: | :---: | :---: | :---: |
90
- | **Platform Scope** | **100% Universal across all AI coding tools** | **Extensible hook (Native on Antigravity & Claude Code)** | **Antigravity Plugin Only** | **`audit project` Universal; `session / compare` Antigravity Only** |
91
- | **Google Antigravity** | Native Skill + CLI + `rules/AGENTS.md` | Native `hooks.json` (`read_file` / `view_file`) | `tokless-coder` / `tokless-reviewer` | Full (`project` + `session` / `compare`) |
92
- | **Claude Code** | `~/.claude/skills` + CLI | Merged `~/.claude/settings.json` (`Read`) | — | `audit project` (rules & MCP tax) |
93
- | **Codex CLI** | `~/.codex/skills` + CLI + `AGENTS.md` | — | — | `audit project` (rules density) |
94
- | **Other Agents** (Cursor / Windsurf / Cline / Roo Code / Trae / OpenCode, etc.) | `npm i -g tokless` + root `AGENTS.md` (Ready Today) | PRs welcome via `targets/` (see `claude-code.js`) | — | `audit project` (rules density) |
95
-
96
- ### 1. `tokless skeleton` (alias `repo-skeleton`) + `rules/AGENTS.md` — [100% Universal]
40
+ ## Quick Install
97
41
 
98
- Zero pre-indexing, pure Node.js standard library. Extracts class/function signatures and exact **`[Lstart-Lend]` line ranges** across `.js/.jsx/.ts/.tsx/.vue/.svelte/.py/.go/.rs/.java/.kt/.c/.cpp/.cs/.md` in milliseconds (lazy-loading only the scanned language parser), cutting exploration tokens by **85%~97%** when paired with [`rules/AGENTS.md`](./rules/AGENTS.md):
42
+ Auto-detects and installs skills, rules, and lean roles into Google Antigravity, Claude Code (`~/.claude`), and Codex CLI (`~/.codex`). **Omits `PreToolUse` child-process hooks by default** for zero read latency (automatically copies files when invoked via `npx`):
99
43
 
100
44
  ```bash
101
- npx tokless skeleton . --map
102
- npx tokless skeleton ./src --depth 2
103
- npx tokless skeleton ./src/App.tsx --json
45
+ npx tokless install
104
46
  ```
105
47
 
106
- ### 2. `PreToolUse` Blind-Read Brake (`scripts/read-guard-hook.js`) — [Extensible Hook · Native on Antigravity & Claude Code]
107
-
108
- Only intercepts blind full-file reads (`> 200` lines, configurable via `TOKLESS_READ_MAX_LINES`) and fake `1..EOF` slices, returning the file's `[Lstart-Lend]` skeleton inline. Once explicit line numbers are supplied, any function span—whether 50 or 500 lines—is allowed in a single read so agents never burn extra turns reading fragments.
109
-
110
- ### 3. MCP-Stripped Lean Subagents (`agents/`) — [Antigravity Plugin Only]
111
-
112
- Ships [`tokless-coder`](./agents/tokless-coder.md) and read-only [`tokless-reviewer`](./agents/tokless-reviewer.md) with `inheritMcp: false`, stripping unused external MCP schemas to eliminate thousands of idle base tokens on every coding/review turn.
113
-
114
- ### 4. `tokless audit` (alias `agy-audit`) — [`audit project` Universal · `session / compare` Antigravity Only]
115
-
116
- Offline 0-LLM-token inspector for rule bloat, MCP schema overhead, and Antigravity session transcripts:
48
+ Opt in to the `>800`-line unsliced blind-read guard, target specific hosts, or cleanly uninstall anytime:
117
49
 
118
50
  ```bash
119
- # [Universal] Audit AGENTS.md / SKILL.md bloat and workspace/global MCP schema base tax
120
- npx tokless audit project <project-dir>
121
-
122
- # [Antigravity Only] Dissect a session's Top 5 costliest steps, Prefix Cache cliffs, and compactions
123
- npx tokless audit session <session-id-prefix>
124
-
125
- # [Antigravity Only] Side-by-side A/B token bill comparison between two sessions
126
- npx tokless audit compare <before-id> <after-id>
51
+ npx tokless install --with-guard # Opt-in PreToolUse hook (returns skeleton only on unsliced reads >800 lines)
52
+ npx tokless install --target agy # Target agy, claude, codex, or all
53
+ npx tokless uninstall --target all # Cleanly remove and restore original host settings
127
54
  ```
128
55
 
129
- ---
130
-
131
- ## Where Each Target Installs & How to Use Day-to-Day
132
-
133
- ### 1. Built-in One-Command Targets (`npx tokless install`)
56
+ Or paste one prompt straight into your AI coding agent:
134
57
 
135
- - **Google Antigravity** (`--target agy`):
136
- - **Installed to**: `~/.gemini/config/plugins/agy-tokless/` (`plugin.json`, `hooks.json`, `rules/AGENTS.md`, `skills/`, `agents/`).
137
- - **How it triggers**: Active automatically in new sessions—`PreToolUse` blocks blind reads on large files, `code-skeleton` guides ranged reads, `tokless-coder` / `tokless-reviewer` run without MCP tax, and `token-audit` / `npx tokless audit session <id>` inspects session bills.
138
- - **Claude Code** (`--target claude`):
139
- - **Installed to**: Core runtime in `~/.claude/tokless/`, skill in `~/.claude/skills/code-skeleton/SKILL.md`, and non-destructively merged `PreToolUse` (`Read`) hook in `~/.claude/settings.json` (preserves your existing permissions and custom hooks; cleanly restored on uninstall).
140
- - **How it triggers**: Active automatically whenever you launch `claude`—un-sliced `Read` calls over 200 lines are intercepted with an inline `[Lstart-Lend]` map so Claude immediately re-reads the exact target lines.
141
- - **Codex CLI** (`--target codex`):
142
- - **Installed to**: `~/.codex/skills/code-skeleton/` (`SKILL.md` + bundled `tools/repo-skeleton`).
143
- - **How it triggers**: Codex discovers the `code-skeleton` skill automatically; copy [`rules/AGENTS.md`](./rules/AGENTS.md) into your repo root `AGENTS.md` for consistent proactive triggering.
144
-
145
- ### 2. Using `tokless` with Cursor, Windsurf, Cline, Roo Code, Trae, OpenCode & Others
58
+ ```text
59
+ Please run `npx tokless install` to enable tokless and confirm that the skills and lean-reading rules are active.
60
+ ```
146
61
 
147
- - **Use It Right Now (1-Minute Universal Setup)**:
148
- 1. Install the global CLI via `npm i -g tokless` (exposes `tokless skeleton` and `tokless audit project` globally);
149
- 2. Copy the lean-reading rules from [`rules/AGENTS.md`](./rules/AGENTS.md) into your repository's root `AGENTS.md` (or `.cursor/rules/`, `.windsurfrules`, `.clinerules`, etc.). Your agent can immediately run `tokless skeleton <path>` before reading large files, and you can run `tokless audit project .` anytime.
150
- - **Honest Note on Native Auto-Installers & Community Co-Creation**:
151
- Because maintainer bandwidth is currently focused on core accuracy, we haven't hand-wired global config paths and hook formats for a dozen different editors yet. **If you use another coding agent daily, you are warmly encouraged to ask your AI to build a target adapter modeled after [`targets/claude-code.js`](./targets/claude-code.js) and open a PR—we will review and publish it promptly, and we will also add more official built-in targets over time.**
62
+ > **Using Cursor, Windsurf, Cline, Roo Code, Trae, or OpenCode?**
63
+ > Run `npm i -g tokless` and copy [`rules/AGENTS.md`](./rules/AGENTS.md) into your repository root `AGENTS.md` (or editor rule file). See [Core Mechanics & Per-Host Setup](./docs/why-tokless.en.md) for details.
152
64
 
153
65
  ---
154
66
 
155
- ## Programmatic Node.js API
67
+ ## Core Capabilities & Everyday CLI
156
68
 
157
- `tokless` exports clean CommonJS modules (`tokless`, `tokless/skeleton`, `tokless/read-guard`, `tokless/audit`) for in-process agent harnesses and custom tooling with zero child-process overhead:
158
-
159
- ```js
160
- const {
161
- generateSkeleton,
162
- evaluateReadGuard,
163
- analyzeSession,
164
- auditProject,
165
- } = require('tokless');
166
-
167
- // Extract [Lstart-Lend] map for a file or directory
168
- const skel = generateSkeleton('./src', { maxDepth: 2 });
169
- console.log(skel.formatted);
69
+ | Host Agent | 1. `tokless skeleton` | 2. `PreToolUse` Guard (`--with-guard`) | 3. Lean Roles (`inheritMcp: false`) | 4. `tokless audit` Inspector |
70
+ | :--- | :---: | :---: | :---: | :---: |
71
+ | **Google Antigravity** | Native Skill + CLI + `rules/AGENTS.md` | Optional `hooks.json` (`>800`-line navigator) | `tokless-coder` / `tokless-reviewer` | Full (`project` + `list / session / compare`) |
72
+ | **Claude Code** | `~/.claude/skills` + CLI | Optional merged `~/.claude/settings.json` | — | `audit project` (rules & MCP cost) |
73
+ | **Codex CLI** | `~/.codex/skills` + CLI + `AGENTS.md` | — | — | `audit project` (rules cost) |
74
+ | **Other Coding Agents** | `npm i -g tokless` + root `AGENTS.md` | PRs welcome via `targets/` | — | `audit project` (rules cost) |
170
75
 
171
- // Evaluate Antigravity or Claude Code PreToolUse payloads in memory
172
- const verdict = evaluateReadGuard({
173
- tool_name: 'Read',
174
- tool_input: { file_path: './src/large-module.ts' },
175
- });
176
- // => { decision: 'deny' | 'allow', reason?: string, host: 'claude' | 'antigravity' }
76
+ ```bash
77
+ # 1. Code skeletons (lazy-loads JS/TS, Vue/Svelte, Python, Go, Rust, Java, Kotlin, C/C++, C#, Markdown)
78
+ npx tokless skeleton . --map # Fast repo file line/char overview
79
+ npx tokless skeleton ./src --depth 3 --exclude third_party # Directory [Lstart-Lend] signature map
80
+ npx tokless skeleton ./driver/hal_uart.c # Single file or large C/C++ header skeleton
81
+
82
+ # 2. Offline 0-LLM-token billing & base-tax audits
83
+ npx tokless audit project . # [Universal] Inspect Always-On rules, skills & MCP base costs
84
+ npx tokless audit list --source cli # [Antigravity] List recent sessions (cli / app / ide / all)
85
+ npx tokless audit session latest # [Antigravity] Dissect Top 5 costliest steps & cache cliffs
86
+ npx tokless audit compare latest~1 latest # [Antigravity] Side-by-side A/B session bill comparison
177
87
  ```
178
88
 
179
89
  ---
180
90
 
181
- ## Contributing Agent Targets & Language Parsers
182
-
183
- ### 1. Host Agent Installers (`targets/<agent>.js`)
184
-
185
- Host integrations live as self-contained adapters under [`targets/`](./targets/):
186
-
187
- - [`targets/antigravity.js`](./targets/antigravity.js) — Google Antigravity plugin, hooks, and lean subagents
188
- - [`targets/claude-code.js`](./targets/claude-code.js) — Claude Code `~/.claude/settings.json` non-destructive hook merge + skill (best reference template for new adapters)
189
- - [`targets/codex.js`](./targets/codex.js) — OpenAI Codex CLI skill installer
91
+ ## Documentation & Contributing
190
92
 
191
- Rather than guessing every editor's private config layout upfront, we prioritize clean community co-creation: if you use **Cursor, Windsurf, Cline, Roo Code, Trae, OpenCode, or GitHub Copilot**, point your AI at [`targets/claude-code.js`](./targets/claude-code.js), register the new adapter in [`targets/index.js`](./targets/index.js), and open a Pull Request. Verified PRs are merged and released right away, while official support for additional hosts will continue rolling out over time.
192
-
193
- ### 2. Language Skeleton Parsers & Regression Fixes (`tools/repo-skeleton/lib/langs/<lang>/`)
194
-
195
- Every supported language is treated on equal footing as a standalone module under [`tools/repo-skeleton/lib/langs/<lang>/index.js`](./tools/repo-skeleton/lib/langs/) backed by the shared lexer and balanced-delimiter engine in [`tools/repo-skeleton/lib/core/`](./tools/repo-skeleton/lib/core/). Each language directory manages all of its associated file extensions in one place (for example, `javascript/` handles `.js/.jsx/.mjs/.cjs/.ts/.tsx`, `c-family/` handles `.c/.h/.cpp/.hpp/.cc/.cs`, and `sfc/` handles `.vue/.svelte`), and `core/registry.js` lazy-loads a parser only when a matching file extension is actually scanned.
196
-
197
- When fixing a real-world syntax edge case or adding a new language:
198
-
199
- 1. Update or add the corresponding `tools/repo-skeleton/lib/langs/<lang>/index.js` (and register any new extensions in `tools/repo-skeleton/lib/core/registry.js`);
200
- 2. **Add a regression test reproducing the exact real-world case in `tests/langs/<lang>.test.js`** ([`tests/run-all.js`](./tests/run-all.js) automatically discovers all `tests/**/*.test.js` suites without editing `package.json`);
201
- 3. Run the full verification suite locally (cumulative language regressions, cross-platform checks, and the zero-personal-path leak gate) to ensure 100% zero breakage before opening a PR:
202
-
203
- ```bash
204
- npm test
205
- ```
93
+ - **[Why `@Codebase` / `repomix` Alone Isn't Enough & Per-Host Paths](./docs/why-tokless.en.md)**
94
+ - **[Programmatic Node.js API & Contributing Host/Language Adapters](./docs/contributing-and-api.en.md)**
95
+ - **[Repository Engineering Guide & Change-Sync Map (AGENTS.md)](./AGENTS.md)**
206
96
 
207
97
  ---
208
98
 
@@ -210,7 +100,7 @@ npm test
210
100
 
211
101
  Built from scratch on the Node.js standard library. Special thanks to:
212
102
 
213
- - **Contributors**: [@PXY000](https://github.com/PXY000) for cross-platform PowerShell skill templates, absolute Node binary resolution in hooks, path traversal guards, and regression tests; [@Mr-PolarBear](https://github.com/Mr-PolarBear) for Java nested classes, dotted/generic return types, anonymous field filtering, and JS top-level IIFE skeleton extraction fixes.
103
+ - **Contributors**: [@PXY000](https://github.com/PXY000) (cross-platform PowerShell skill templates, absolute Node resolution in hooks, path traversal guards & tests), [@Mr-PolarBear](https://github.com/Mr-PolarBear) (Java nested classes, dotted/generic return types, anonymous field filtering & JS top-level IIFE fixes), and [@Jefferyu](https://github.com/Jefferyu) (modular C/C++ embedded skeleton parser, multi-source Antigravity CLI audit & dual-model cache cliff attribution).
214
104
  - **Open-Source Inspiration**: [HoangP8/tokless](https://github.com/HoangP8/tokless), [ILoveMyJay/repocontext](https://github.com/ILoveMyJay/repocontext), [pdavis68/RepoMapper](https://github.com/pdavis68/RepoMapper), and [ooples/token-optimizer-mcp](https://github.com/ooples/token-optimizer-mcp).
215
105
 
216
106
  ## License
package/README.md CHANGED
@@ -10,244 +10,102 @@
10
10
 
11
11
  简体中文 | [English](./README.en.md)
12
12
 
13
- > **核心初心:在不损失一行代码排查与修复质量的前提下,把 AI 编程工具里无意义的盲读膨胀与滚雪球 Token 消耗砍到最低。**
13
+ > **在不损失一行代码排查与修复质量的前提下,把 AI 编程工具里无意义的大文件盲读膨胀与滚雪球 Token 消耗砍掉一半以上。**
14
14
 
15
- **面向主流 AI 编程 Agent(原生支持 Google Antigravity、Claude Code、Codex CLI,开放 `targets/` 插件架构扩展更多工具)的纯 Node.js 零依赖省流套件——毫秒级 `[L起-L止]` 语法骨架导航、原生 `PreToolUse` 防盲读硬刹车、剥离 MCP 空载税的净身角色与 0 Token 本地账单/缓存断层体检。**
15
+ `tokless` 是面向主流 AI 编程 Agent(原生一键挂载 **Google Antigravity**、**Claude Code**、**Codex CLI**,通用支持 Cursor / Windsurf / Cline / Roo Code 等)的 **纯 Node.js(`>=18`)零外部依赖** 省流与账单透视套件:
16
16
 
17
- 在真实跨语言生产工程(Tauri + Rust + React)的严格 A/B 盲测中,启用 `tokless` 后单次任务减少 **34.4% 模型往返轮次**、砍掉 **53.2% 总 Token 吞吐(净省 1,138 万 Token)**、滚雪球 Cache Read 净省 **53.8%(少烧 1,123 万 Token)**,7 个真实深层 Bug 检出与修复质量零折损(*注:该组盲测数据完成于早期 `v0.1.0` 版本,当时仅含基础语法骨架与无行号盲读拦截,尚未针对后续新增净身角色与优化行号放行机制的新版本重跑完整长任务对照,当前版本理论综合省流表现更强*)。
17
+ 1. **防盲读省探索(`tokless skeleton`)**:IDE 的 `@Codebase` 只管找到文件,不管怎么读;AI 拿到文件名后常把上千行源码整份塞进上下文,在多步循环中引发 `Cache Read` 复利滚雪球。`tokless` 毫秒级提取函数/类/宏/类型定义与 **`[L起-L止]` 行号骨架**,让 AI 只按行切片读取真正要改的几十行代码(探索期单文件省流 **85%~97%**)。
18
+ 2. **卸空载省底座(`tokless-coder` / `tokless-reviewer`)**:在纯写码/审码会话中剥离用不上的外部 MCP 与花哨工具 Schema,每步立省数千固定底座 Token。
19
+ 3. **查真账捉黑洞(`tokless audit`)**:0 模型 Token 离线解剖本地会话账单,一眼定位最烧钱的 Top 5 步骤、跨模型切换/闲置引起的 Prefix Cache 断层,以及项目规则与 MCP 空载开销。
18
20
 
19
21
  ---
20
22
 
21
- ## 一行命令极速启用(零界面 · 纯 Node.js `>=18` 零外部依赖)
23
+ ## 真实工程 A/B 实测效果(Tauri + Rust + React 全仓找 Bug 与修复)
22
24
 
23
- ### 方式一:终端一键挂载(推荐)
25
+ 同一生产级工程(Commit `3908815`)切出两个独立 Worktree,同一模型执行完全相同的深层 Bug 排查、修复与编译验证任务:
24
26
 
25
- 自动检测并挂载本机已安装的 Antigravity、Claude Code(`~/.claude`)与 Codex CLI(`~/.codex`),从 `npx` 临时目录运行时会自动切换为实体文件拷贝,杜绝缓存清理后软链悬空:
26
-
27
- ```bash
28
- npx tokless install
29
- ```
30
-
31
- 按需指定单个或全部目标宿主 / 一键干净卸载:
32
-
33
- ```bash
34
- npx tokless install --target agy # 仅挂载 Google Antigravity
35
- npx tokless install --target claude # 仅无损合并 Claude Code ~/.claude/settings.json 钩子与技能
36
- npx tokless install --target codex # 仅安装 Codex CLI ~/.codex/skills/code-skeleton
37
- npx tokless install --target all # 挂载全部已支持宿主
38
- npx tokless uninstall --target all # 一键卸载并还原原有宿主配置
39
- ```
40
-
41
- ### 方式二:复制一句话直接交给你的 AI 编程助手
42
-
43
- 不想自己切终端,直接把下面这句话发给 Antigravity 或 Claude Code 对话框即可:
44
-
45
- ```text
46
- 请运行 npx tokless install 帮我安装启用 tokless 省流套件(若网络受限可克隆 https://github.com/daoif/tokless 后运行 node install.js),装好后帮我确认钩子与技能已生效。
47
- ```
48
-
49
- ### 方式三:源码克隆本地安装(适合二次开发或离线环境)
50
-
51
- ```bash
52
- git clone https://github.com/daoif/tokless.git
53
- cd tokless
54
- node install.js
55
- ```
56
-
57
- ---
58
-
59
- ## 为什么你的周额度掉得这么快?有了 `@Codebase` 或 `repomix` 为什么还是拦不住?
60
-
61
- 很多重度 AI 编程玩家都有同一个困惑:**“IDE 明明自带了 `@Codebase` 语义索引,我也试过 `repomix`,为什么跑几个复杂需求,5 小时窗口和周额度还是见底了?”**
62
-
63
- 通过对数十份底层会话账单日志(`transcript_full.jsonl`)的逐帧解剖,吃光额度的元凶非常清晰:
64
-
65
- ### 1. `@Codebase` 是找线索的「搜索引擎」,`tokless` 是防偷懒的「省流刹车系统」
66
-
67
- | 工具类型 | 代表工具 | 核心职责 | 为什么单靠它省不了 Agent 循环里的额度? |
68
- | :--- | :--- | :--- | :--- |
69
- | **语义搜索引擎** | IDE 自带 `@Codebase` | 向量/关键词检索,帮 AI 找到“大概在哪个文件” | **只管找路,不管怎么读**。AI 拿到文件名后,下一步依然习惯性调用无行号的 `read_file` / `Read`,顺手把整份一两千行源码全量塞进上下文。 |
70
- | **全仓打包器** | `repomix` / `gitingest` | 把整个仓库压成单文件喂给网页聊天框 | 适合无本地工具权限的网页问答;若塞进本地 Agent 会话,相当于第 1 步直接背上几万 Token 包袱。 |
71
- | **省流导航与硬刹车** | **`tokless`** | **80ms 零索引出 `[L起-L止]` 骨架 + `PreToolUse` 硬拦盲读** | 当 AI 偷懒盲读 >200 行代码文件(或传 `1~文件末尾` 假切片)时,底层钩子当场拦截并直接甩回该文件的函数/类 `[L起-L止]` 行号骨架,逼它按行号精准切片读取。 |
72
-
73
- `tokless` 与 `@Codebase` 完全不冲突,而是天然互补:`@Codebase` 负责回答“去哪几个文件找”,`tokless` 负责在读取那一刻踩住刹车,只让真正要改的那几十行代码进入上下文。
74
-
75
- ### 2. 「Cache Read 滚雪球效应」与上下文自动压缩水位
76
-
77
- 在多步 Agent 循环中,真正烧光额度的往往不是单次 `Input`,而是每一步反复重读历史上下文的 **`Cache Read`**:
78
-
79
- $$\text{累计 Cache Read} \approx \text{平均上下文水位} \times \text{模型调用轮数}$$
80
-
81
- - **早一步塞进废话,步步交复利税**:如果第 3 步盲读塞进 3 万 Token 无关代码,整个任务跑了 50 轮,这 3 万 Token 就会在后续每一步被重复计费 47 次,单这一步就白烧 **140 万+ Cache Read Token**。
82
- - **远离隐式压缩失忆线**:在 Antigravity 等宿主中,三代模型常见在约 **256K** 上下文水位触发底层强制摘要压缩(`CHECKPOINT: # Resuming from a compaction`,将数十万上下文压成几千字摘要导致细节丢失与反复重读);四代模型实测跑上 440K 未触发压缩(社区普遍推测阈值约 **512K**)。但无论压缩上限在哪,**压低每步水位 + 减少探索轮数**都是同时保住代码记忆精度与周额度的核心解法。
83
-
84
- ---
85
-
86
- ## 真实工程 A/B 实测账单(Tauri + Rust + React 全仓找 Bug 与修复)
87
-
88
- 在同一个生产级桌面工程(Rust 后端 + TypeScript/React 前端)上,基于同一 Git Commit (`3908815`) 切出两个独立 Worktree,由同一模型(`Gemini 4 Hydrogen High`)执行完全相同的全仓深层 Bug 排查、修复与编译验证任务:
89
-
90
- | 对比维度 | 对照组 (原生常规模式) | 实验组 (启用 `tokless`) | 真实节省 / 提升 |
27
+ | 对比维度 | 对照组 (原生默认模式) | 实验组 (启用 `tokless`) | 真实节省 / 提升 |
91
28
  | :--- | :--- | :--- | :--- |
92
29
  | **总 Token 吞吐 (`input + cache_read + output`)** | 21,410,381 (2,141 万) | **10,029,592 (1,003 万)** | **净省 53.2% (-1,138 万 Tokens)** |
93
30
  | **累计 Cache Read(滚雪球缓存消耗)** | 20,858,589 (2,086 万) | **9,627,700 (963 万)** | **净省 53.8% (-1,123 万 Tokens)** |
94
- | **累计 Input Tokens(新增输入)** | 494,886 | **352,020** | **省 28.9%** |
95
- | **模型调用轮数(Planner Invocations)** | 64 次 | **42 次** | **少跑 34.4% 轮次** |
96
- | **总执行步数(Steps)** | 220 步 | **150 步** | **少走 31.8% 弯路** |
97
- | **`read_file` 调用次数(全量盲读次数)** | 79 次(含 3 次全量盲读) | **51 次(0 次盲读)** | **文件读取减少 35.4%** |
98
- | **峰值上下文水位(Peak Context)** | 439,830 Tokens | **323,344 Tokens** | **峰值降低 26.5%** |
99
- | **定位首个 Bug 开始改代码耗时** | 227 秒(第 115 步) | **196 秒(第 81 步)** | **提速 31 秒 / 少花 34 步** |
100
- | **检出并修复的真实硬核 Bug 数** | 7 个(全部编译通过) | **7 个(全部编译通过)** | **0 质量损耗(并发细节更深)** |
101
-
102
- > **实测版本与模型说明**:
103
- > 1. **测试版本背景(`v0.1.0` 基线)**:上表 A/B 盲测数据完成于早期的 `v0.1.0` 版本(当时仅包含基础语法骨架提取与无行号盲读拦截),目前尚未针对新版本重跑完整长任务对照;随着后续版本加入剥离外部 MCP 空载税的净身角色(`inheritMcp: false`)与优化后的行号切片放行机制,当前版本的理论综合省流表现更强。
104
- > 2. **压缩阈值参考**:本轮实测基于四代模型,对照组峰值达 439,830 Tokens 未触发自动压缩(若换作 256K 阈值的三代模型早已触发强制压缩失忆)。完整逐项对比见 [benchmarks/real-world-bugfix-case.md](./benchmarks/real-world-bugfix-case.md) 与静态骨架基准测试 [benchmarks/static-skeleton-benchmark.md](./benchmarks/static-skeleton-benchmark.md)。
31
+ | **模型调用轮数 / 总步数** | 64 轮 / 220 步 | **42 轮 / 150 步** | **少跑 34.4% 轮次** |
32
+ | **`read_file` 调用(无行号盲读)** | 79 次(3 次盲读) | **51 次(0 次盲读)** | **读取减少 35.4%** |
33
+ | **峰值上下文水位** | 439,830 Tokens | **323,344 Tokens** | **峰值降低 26.5%** |
34
+ | **检出并修复的真实硬核 Bug 数** | 7 个(全部编译通过) | **7 个(全部编译通过)** | **0 质量损耗** |
105
35
 
106
- ---
36
+ > *注:上表完成于早期 `v0.1.0` 基线(仅含基础骨架提取与盲读拦截),后续版本已新增 `inheritMcp: false` 净身角色、C/C++ 深度解析与更精细的行号放行机制。完整报告见 [真实 Bug 修复对照账单](./benchmarks/real-world-bugfix-case.md) 与 [静态骨架基准测试](./benchmarks/static-skeleton-benchmark.md)。*
107
37
 
108
- ## 四大核心能力与全平台支持边界(v0.5.0)
109
-
110
- `tokless` 把「跨所有 AI 编程工具通用的省流内核」与「特定客户端的深度钩子/日志解析」拆得清清楚楚,绝不混为一谈:
111
-
112
- | 宿主工具 | 1. `tokless skeleton` 语法骨架 + `AGENTS.md` 规范 | 2. `PreToolUse` 防盲读硬刹车 | 3. 净身子角色 (`inheritMcp: false`) | 4. `tokless audit` 体检仪 |
113
- | :--- | :---: | :---: | :---: | :---: |
114
- | **能力通用边界** | **100% 所有 AI 编程工具通用** | **可扩展钩子机制(已打通 Antigravity / Claude Code)** | **Antigravity 插件专用** | **`audit project` 跨端通用;`session / compare` 属 Antigravity 专用** |
115
- | **Google Antigravity** | 原生 Skill + CLI + `rules/AGENTS.md` | 原生 `hooks.json` (`read_file` / `view_file`) | `tokless-coder` / `tokless-reviewer` | 全功能支持(`project` + `session` / `compare`) |
116
- | **Claude Code** | `~/.claude/skills` + CLI | 无损合并 `~/.claude/settings.json` (`Read`) | — | 支持 `audit project` 规则与 MCP 税体检 |
117
- | **Codex CLI** | `~/.codex/skills` + CLI + `AGENTS.md` | — | — | 支持 `audit project` 规则体检 |
118
- | **其他工具**(Cursor / Windsurf / Cline / Roo Code / Trae / OpenCode 等) | `npm i -g tokless` + 项目根 `AGENTS.md` 立即可用 | 欢迎参考 `targets/claude-code.js` 共创适配 PR | — | 支持 `audit project` 规则体检 |
38
+ ---
119
39
 
120
- ### 1. `tokless skeleton`(兼容 `repo-skeleton`)+ `rules/AGENTS.md` 省流规范 —【100% 所有 AI 编程工具通用】
40
+ ## 一行命令极速启用
121
41
 
122
- 无需预建索引数据库,纯 Node.js 标准库毫秒级提取 `.js/.jsx/.ts/.tsx/.vue/.svelte/.py/.go/.rs/.java/.kt/.c/.cpp/.cs/.md` 等文件的类名、函数签名、接口与精确 **`[L起-L止]` 行号范围**(按需惰性加载对应语言解析器),配合 [`rules/AGENTS.md`](./rules/AGENTS.md) 中的两步精准读取规范,探索期单文件省流 **85%~97%**:
42
+ 自动检测并挂载本机已安装的 Antigravity、Claude Code(`~/.claude`)与 Codex CLI(`~/.codex`),默认纯增益安装技能、省流规则与净身角色(**默认不挂载 `PreToolUse` 子进程钩子**,零读文件延迟;`npx` 运行自动切换实体拷贝防软链悬空):
123
43
 
124
44
  ```bash
125
- # 快速生成全仓目录行数与字数鸟瞰地图(不展开函数签名)
126
- npx tokless skeleton . --map
127
-
128
- # 扫描整个源码目录(自动排除 node_modules/.git/dist/target 等),一步生成全局行号地图
129
- npx tokless skeleton ./src --depth 3
130
-
131
- # 提取单个大文件的函数签名与 [L起-L止] 行号(支持 --json 输出结构化数据)
132
- npx tokless skeleton ./src/App.tsx
45
+ npx tokless install
133
46
  ```
134
47
 
135
- ### 2. `PreToolUse` 防盲读硬刹车(`scripts/read-guard-hook.js`)—【可扩展钩子机制,目前已原生打通 Google Antigravity 与 Claude Code】
136
-
137
- 精准防盲读,绝不设死板跨度锁死:当 AI 不传起止行号盲读超过 200 行(可通过环境变量 `TOKLESS_READ_MAX_LINES` 调整)的代码文件,或传入 `1~文件末尾` 假切片糊弄时,钩子自动拦截并当场返回该文件的 `[L起-L止]` 语法骨架;一旦拿到明确行号,无论目标函数是 50 行还是 500 行均一次完整放行,避免拆成多轮碎片读取倒贴 Cache Read。
138
-
139
- ### 3. 剥离外部 MCP 空载底座税的净身子角色(`agents/`)—【Antigravity 插件专用】
140
-
141
- 内置 [`tokless-coder`](./agents/tokless-coder.md) 与只读 [`tokless-reviewer`](./agents/tokless-reviewer.md),默认声明 `inheritMcp: false` 卸除纯写代码/审代码时用不上的外部 MCP Schema,消除每一步固定背负的数千至数万空载底座税。
142
-
143
- ### 4. `tokless audit`(兼容 `agy-audit`)体检仪 —【`audit project` 跨端通用;`audit session / compare` 属 Antigravity 专用】
144
-
145
- 直接离线解析本地项目规则配置与 Antigravity 会话日志,不花 1 个模型 Token:
48
+ 按需启用超大文件盲读护栏、指定宿主或一键干净卸载:
146
49
 
147
50
  ```bash
148
- # [跨端通用] 诊断项目的 AGENTS.md / SKILL.md 肥胖度与全局/工作区 MCP 空载底座税
149
- npx tokless audit project <项目目录路径>
150
-
151
- # [Antigravity 专用] 解剖单个会话(支持短 ID 前缀):查 Top 5 烧钱步骤、Prefix Cache 断层与压缩节点
152
- npx tokless audit session <会话ID前缀>
153
-
154
- # [Antigravity 专用] 优化前后两个会话的 A/B 量化账单对比
155
- npx tokless audit compare <优化前ID> <优化后ID>
51
+ npx tokless install --with-guard # 可选启用 PreToolUse 护栏(仅对 >800 行无行号盲读返回骨架,传行号一律放行)
52
+ npx tokless install --target agy # 仅挂载 Google Antigravity(claude / codex / all 同理)
53
+ npx tokless uninstall --target all # 一键卸载并无损还原宿主原有配置
156
54
  ```
157
55
 
158
- ---
159
-
160
- ## 各工具安装位置与日常使用方法
161
-
162
- ### 1. 已内置一键挂载的三大工具(运行 `npx tokless install` 后分别装到了哪里、怎么触发)
163
-
164
- - **Google Antigravity**(`--target agy`):
165
- - **安装位置**:`~/.gemini/config/plugins/agy-tokless/`(挂载 `plugin.json`、`hooks.json`、`rules/AGENTS.md`、`skills/` 与 `agents/`)。
166
- - **日常触发**:装好后新开对话即自动生效——探索大文件时自动触发 `code-skeleton` 技能与 `PreToolUse` 防盲读拦截;派发纯编码或审查子任务时可指定 `tokless-coder` / `tokless-reviewer` 卸除 MCP 税;需要查账单时直接让 AI 调用 `token-audit` 技能或手动运行 `npx tokless audit session <ID>`。
167
- - **Claude Code**(`--target claude`):
168
- - **安装位置**:核心脚本存入 `~/.claude/tokless/`,技能写入 `~/.claude/skills/code-skeleton/SKILL.md`,并将 `Read` 防盲读钩子无损合并进 `~/.claude/settings.json`(保留你原有的权限与自定义钩子,卸载时精准剥离还原)。
169
- - **日常触发**:在任意项目启动 `claude` 后自动生效——当 Claude 试图不带 `offset/limit` 盲读超过 200 行的代码文件时,`PreToolUse` 钩子会自动拦下并把 `[L起-L止]` 骨架直接喂回给它,引导它按行号精读。
170
- - **Codex CLI**(`--target codex`):
171
- - **安装位置**:`~/.codex/skills/code-skeleton/`(含 `SKILL.md` 与零依赖 `tools/repo-skeleton` 脚本)。
172
- - **日常触发**:Codex 会自动发现并按需调用 `code-skeleton` 技能先看行号骨架再精读源码;建议同时将 [`rules/AGENTS.md`](./rules/AGENTS.md) 中的省流规范合入项目根目录的 `AGENTS.md` 以强化主动触发。
56
+ 不想切终端?直接把下面这句话发给你的 AI 编程助手即可:
173
57
 
174
- ### 2. 其他 AI 编程工具(Cursor、Windsurf、Cline、Roo Code、Trae、OpenCode 等)怎么用?
58
+ ```text
59
+ 请运行 npx tokless install 帮我安装启用 tokless 省流套件,装好后确认技能与省流规则已生效。
60
+ ```
175
61
 
176
- - **当下立即可用法(1 分钟接入核心省流能力)**:
177
- 1. 在终端运行 `npm i -g tokless` 安装全局 CLI(获得全局 `tokless skeleton` 与 `tokless audit project` 命令);
178
- 2. 将仓库内 [`rules/AGENTS.md`](./rules/AGENTS.md) 的省流读取规范复制到你项目根目录的 `AGENTS.md`(或对应编辑器的 `.cursor/rules/`、`.windsurfrules`、`.clinerules` 等规则文件)中。配置完成后,你的 AI 助手就会在读大文件前主动调用 `tokless skeleton <路径>` 拿 `[L起-L止]` 行号地图并按需精读,也能随时用 `tokless audit project .` 检查规则体积。
179
- - **关于官方一键挂载与共创适配的坦诚说明**:
180
- 由于作者近期精力有限,暂时还没法逐一去折腾十几个编辑器各自的专属全局目录与钩子格式。**如果你日常主力使用其他工具,非常欢迎直接让你的 AI 参考 [`targets/claude-code.js`](./targets/claude-code.js) 写一个对应的挂载适配并提交 PR——我们审核代码确认干净无误后会第一时间合并发版;后续作者空下来也会逐步跟进补充更多主流工具的官方一键支持。**
62
+ > **使用 Cursor、Windsurf、Cline、Roo Code、Trae、OpenCode 等其他工具?**
63
+ > 运行 `npm i -g tokless`,再把 [`rules/AGENTS.md`](./rules/AGENTS.md) 复制到项目根目录(或对应编辑器的规则文件)即可立享核心省流能力。各宿主具体安装目录详见 [原理与各工具挂载说明](./docs/why-tokless.md)。
181
64
 
182
65
  ---
183
66
 
184
- ## Node.js 编程接口(Programmatic API)
185
-
186
- `tokless` 同时导出零依赖标准 CommonJS 接口(支持 `tokless`、`tokless/skeleton`、`tokless/read-guard`、`tokless/audit` 子路径按需引入),方便其他 Agent 编排器或评测脚本在进程内直接调用,零子进程开销:
67
+ ## 四大核心能力与常用命令
187
68
 
188
- ```js
189
- const {
190
- generateSkeleton, // 自动识别文件或目录生成 [L起-L止] 骨架
191
- evaluateReadGuard, // 纯函数评估 Antigravity / Claude Code 读取请求是否盲读
192
- analyzeSession, // 解析单次会话账单、缓存断层与峰值水位
193
- auditProject, // 审计项目常驻规则体积与 MCP Schema 底座税
194
- } = require('tokless');
69
+ | 宿主工具 | 1. `tokless skeleton` 语法骨架 | 2. `PreToolUse` 盲读护栏(`--with-guard`) | 3. 净身角色 (`inheritMcp: false`) | 4. `tokless audit` 账单体检 |
70
+ | :--- | :---: | :---: | :---: | :---: |
71
+ | **Google Antigravity** | 原生 Skill + CLI + `rules/AGENTS.md` | 可选 `hooks.json` (`>800` 行无行号导航) | `tokless-coder` / `tokless-reviewer` | 全功能(`project` + `list / session / compare`) |
72
+ | **Claude Code** | `~/.claude/skills` + CLI | 可选无损合并 `~/.claude/settings.json` | — | 支持 `audit project` 规则与 MCP 账单 |
73
+ | **Codex CLI** | `~/.codex/skills` + CLI + `AGENTS.md` | — | — | 支持 `audit project` 规则账单 |
74
+ | **其他 AI 编程工具** | `npm i -g tokless` + 根 `AGENTS.md` | 欢迎参考 `targets/` 共创适配 | — | 支持 `audit project` 规则账单 |
195
75
 
196
- // 1. 提取目录或单文件骨架
197
- const skel = generateSkeleton('./src', { maxDepth: 2 });
198
- console.log(skel.formatted);
76
+ ### 日常高频 CLI 速查
199
77
 
200
- // 2. 进程内调用防盲读判定(支持 Antigravity 与 Claude Code 载荷格式)
201
- const verdict = evaluateReadGuard({
202
- tool_name: 'Read',
203
- tool_input: { file_path: './src/large-module.ts' },
204
- });
205
- // verdict => { decision: 'deny' | 'allow', reason?: string, host: 'claude' | 'antigravity' }
78
+ ```bash
79
+ # 1. 代码骨架提取(按需惰性加载 JS/TS、Vue/Svelte、Python、Go、Rust、Java、Kotlin、C/C++、C#、Markdown 解析器)
80
+ npx tokless skeleton . --map # 全仓文件行数与字数鸟瞰图
81
+ npx tokless skeleton ./src --depth 3 --exclude third_party # 目录级签名与 [L起-L止] 行号地图(自动排除常见构建产物)
82
+ npx tokless skeleton ./driver/hal_uart.c # 单文件或 C/C++ 大头文件函数/宏/typedef/结构体定位
83
+
84
+ # 2. 本地 0 Token 账单与底座透视
85
+ npx tokless audit project . # [通用] 透视项目常驻规则、Skill 与 MCP 工具底座 Token 开销
86
+ npx tokless audit list --source cli # [Antigravity] 列出最近会话(支持 cli / app / ide / all)
87
+ npx tokless audit session latest # [Antigravity] 解剖最新会话 Top 5 烧钱步与缓存断层/模型切换归因
88
+ npx tokless audit compare latest~1 latest # [Antigravity] 优化前后双会话 A/B 账单对比
206
89
  ```
207
90
 
208
91
  ---
209
92
 
210
- ## 社区共建:欢迎扩展更多 AI 编程工具与语言支持(Contributing)
211
-
212
- ### 1. 新增 AI 编程工具一键挂载(`targets/<agent>.js`)
213
-
214
- `tokless` 将各宿主的安装与卸载逻辑完全解耦在 [`targets/`](./targets/) 目录下,每个宿主只需一个独立的百行级适配器文件:
215
-
216
- - [`targets/antigravity.js`](./targets/antigravity.js) — Google Antigravity 插件、钩子与净身角色挂载
217
- - [`targets/claude-code.js`](./targets/claude-code.js) — Claude Code `~/.claude/settings.json` 无损合并与技能挂载(推荐新增适配时优先参考)
218
- - [`targets/codex.js`](./targets/codex.js) — OpenAI Codex CLI 技能挂载
219
-
220
- 因作者近期精力有限,暂未逐一折腾十几个编辑器的专属全局配置与钩子格式。非常欢迎使用 **Cursor、Windsurf、Cline、Roo Code、Trae、OpenCode、GitHub Copilot** 等工具的开发者,直接让自己的 AI 参考 [`targets/claude-code.js`](./targets/claude-code.js) 完成适配并在 [`targets/index.js`](./targets/index.js) 中注册后提交 Pull Request——我们审核无误后会立即合并发版;后续作者空下来也会逐步补充更多工具的官方一键支持。
93
+ ## 深入文档与扩展开发
221
94
 
222
- ### 2. 多语言骨架解析扩展与真实场景修复(`tools/repo-skeleton/lib/langs/<lang>/`)
223
-
224
- `tokless skeleton` 对所有支持语言一视同仁,统一采用「共享词法与括号平衡核心([`tools/repo-skeleton/lib/core/`](./tools/repo-skeleton/lib/core/))+ 按语言独立分目录([`tools/repo-skeleton/lib/langs/<lang>/index.js`](./tools/repo-skeleton/lib/langs/))」的模块化架构:每种语言在独立目录内统一管理关联文件后缀(如 `javascript/` 承接 `.js/.jsx/.mjs/.cjs/.ts/.tsx`、`c-family/` 承接 `.c/.h/.cpp/.hpp/.cc/.cs`、`sfc/` 承接 `.vue/.svelte` 等),仅在扫描到对应后缀时由 `core/registry.js` 按需惰性加载,互不耦合且保持毫秒级冷启动。
225
-
226
- 如果你在真实项目中遇到某门语言的语法边界漏检,或希望新增语言支持,请遵循以下稳健省心的共创约定:
227
-
228
- 1. 修改或新增对应的 `tools/repo-skeleton/lib/langs/<lang>/index.js`(若新增后缀,同步注册至 `tools/repo-skeleton/lib/core/registry.js` 的 `LANG_DIR_TO_EXTS`);
229
- 2. **必须在 `tests/langs/<lang>.test.js` 补上复现该真实场景的回归测试用例**([`tests/run-all.js`](./tests/run-all.js) 会自动递归发现 `tests/` 下全部 `*.test.js`,无需手改 `package.json` 测试列表);
230
- 3. 提交 PR 前在本地运行全套自检(包含全量语言累积回归测试、跨平台路径测试与 100% 零私人路径泄漏门禁),确保历史全量用例 100% 零破坏:
231
-
232
- ```bash
233
- npm test
234
- ```
95
+ - **[为什么 `@Codebase` / `repomix` 挡不住掉额度?原理与各宿主目录详解](./docs/why-tokless.md)**
96
+ - **[Node.js 编程接口(Programmatic API)与新增宿主/语言贡献指南](./docs/contributing-and-api.md)**
97
+ - **[仓库工程规范与变更联动地图(AGENTS.md)](./AGENTS.md)**
235
98
 
236
99
  ---
237
100
 
238
101
  ## 开源致谢(Acknowledgments)
239
102
 
240
- `tokless` 全部代码基于 Node.js 标准库从零独立实现,核心设计思路受益于以下优秀开源探索与社区贡献者,特此致谢:
103
+ `tokless` 基于 Node.js 标准库从零独立实现,特此感谢以下社区贡献者与开源灵感项目:
241
104
 
242
- - **社区贡献者**:感谢 [@PXY000](https://github.com/PXY000) 在跨平台 PowerShell 技能文档、钩子 Node 绝对路径解析、路径穿越防护与沙箱安全审计查找上的扎实修复与单测贡献;感谢 [@Mr-PolarBear](https://github.com/Mr-PolarBear) 在 Java 嵌套类、点号/泛型返回类型、匿名字段过滤与 JS 顶层 IIFE 骨架提取上的真实场景修复贡献。
243
- - **灵感致敬**:
244
- - [HoangP8/tokless](https://github.com/HoangP8/tokless):启发了项目命名及“指令规范 + 生命周期钩子”组合拦截上下文膨胀的思路;
245
- - [ILoveMyJay/repocontext](https://github.com/ILoveMyJay/repocontext) 与 [pdavis68/RepoMapper](https://github.com/pdavis68/RepoMapper):启发了“先拿带行号的紧凑语法骨架地图,再按行号精准切片读取”的探索期降耗策略;
246
- - [ooples/token-optimizer-mcp](https://github.com/ooples/token-optimizer-mcp):启发了针对工具返回体积与会话级 Token 账单做量化透视的思路。
105
+ - **社区贡献者**:感谢 [@PXY000](https://github.com/PXY000)(跨平台 PowerShell 技能模板、钩子 Node 绝对路径解析、路径安全防护与单测)、[@Mr-PolarBear](https://github.com/Mr-PolarBear)(Java 嵌套类/泛型返回类型/匿名字段过滤与 JS 顶层 IIFE 骨架提取修复)、[@Jefferyu](https://github.com/Jefferyu)(模块化 C/C++ 嵌入式语法骨架解析器、Antigravity 多源 CLI 审计与双模型切换缓存断层归因)。
106
+ - **灵感致敬**:[HoangP8/tokless](https://github.com/HoangP8/tokless)、[ILoveMyJay/repocontext](https://github.com/ILoveMyJay/repocontext)、[pdavis68/RepoMapper](https://github.com/pdavis68/RepoMapper) 与 [ooples/token-optimizer-mcp](https://github.com/ooples/token-optimizer-mcp)。
247
107
 
248
- 如果 `tokless` 切实帮你省下了宝贵的周额度,欢迎在右上角点一颗 **Star** 支持,或关注作者技术手记公众号 **【织歌AI笔记】** 交流实战经验。
249
-
250
- ---
108
+ 如果 `tokless` 切实帮你省下了周额度,欢迎点一颗 **Star** 支持,或关注作者技术手记公众号 **【织歌AI笔记】** 交流实战经验。
251
109
 
252
110
  ## License
253
111