tokless 0.4.0 → 0.5.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.en.md +20 -7
- package/README.md +23 -8
- package/bin/tokless.js +1 -1
- package/index.js +3 -0
- package/package.json +2 -2
- package/plugin.json +1 -1
- package/tools/repo-skeleton/cli.js +25 -7
- package/tools/repo-skeleton/lib/core/block-anchor.js +851 -0
- package/tools/repo-skeleton/lib/core/lexer.js +722 -0
- package/tools/repo-skeleton/lib/core/registry.js +64 -0
- package/tools/repo-skeleton/lib/langs/c-family/index.js +177 -0
- package/tools/repo-skeleton/lib/langs/go/index.js +108 -0
- package/tools/repo-skeleton/lib/langs/java/index.js +149 -0
- package/tools/repo-skeleton/lib/langs/javascript/index.js +288 -0
- package/tools/repo-skeleton/lib/langs/kotlin/index.js +167 -0
- package/tools/repo-skeleton/lib/langs/markdown/index.js +79 -0
- package/tools/repo-skeleton/lib/langs/python/index.js +208 -0
- package/tools/repo-skeleton/lib/langs/rust/index.js +115 -0
- package/tools/repo-skeleton/lib/langs/sfc/index.js +72 -0
- package/tools/repo-skeleton/lib/skeleton.js +144 -1309
package/README.en.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
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.
|
|
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
|
|
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*).
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -77,11 +77,11 @@ Two isolated Git worktrees from the same commit (`3908815`), running the exact s
|
|
|
77
77
|
| **Time to First Code Edit** | 227s (Step 115) | **196s (Step 81)** | **31s faster / -34 steps** |
|
|
78
78
|
| **Real Bugs Found & Fixed (Build Verified)** | 7 | **7** | **Zero quality loss** |
|
|
79
79
|
|
|
80
|
-
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).
|
|
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).
|
|
81
81
|
|
|
82
82
|
---
|
|
83
83
|
|
|
84
|
-
## Four Core Capabilities & Platform Boundaries (v0.
|
|
84
|
+
## Four Core Capabilities & Platform Boundaries (v0.5.0)
|
|
85
85
|
|
|
86
86
|
`tokless` draws a transparent line between **universal capabilities that work with every AI coding tool** and **host-specific hooks or log parsers**:
|
|
87
87
|
|
|
@@ -95,9 +95,10 @@ Full reports: [benchmarks/real-world-bugfix-case.md](./benchmarks/real-world-bug
|
|
|
95
95
|
|
|
96
96
|
### 1. `tokless skeleton` (alias `repo-skeleton`) + `rules/AGENTS.md` — [100% Universal]
|
|
97
97
|
|
|
98
|
-
Zero pre-indexing, pure Node.js standard library. Extracts class/function signatures and exact **`[Lstart-Lend]` line ranges** across `.js/.ts/.tsx/.py/.go/.rs/.java/.c/.cpp/.md` in milliseconds, cutting exploration tokens by **85%~97%** when paired with [`rules/AGENTS.md`](./rules/AGENTS.md):
|
|
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):
|
|
99
99
|
|
|
100
100
|
```bash
|
|
101
|
+
npx tokless skeleton . --map
|
|
101
102
|
npx tokless skeleton ./src --depth 2
|
|
102
103
|
npx tokless skeleton ./src/App.tsx --json
|
|
103
104
|
```
|
|
@@ -177,7 +178,9 @@ const verdict = evaluateReadGuard({
|
|
|
177
178
|
|
|
178
179
|
---
|
|
179
180
|
|
|
180
|
-
## Contributing
|
|
181
|
+
## Contributing Agent Targets & Language Parsers
|
|
182
|
+
|
|
183
|
+
### 1. Host Agent Installers (`targets/<agent>.js`)
|
|
181
184
|
|
|
182
185
|
Host integrations live as self-contained adapters under [`targets/`](./targets/):
|
|
183
186
|
|
|
@@ -185,7 +188,17 @@ Host integrations live as self-contained adapters under [`targets/`](./targets/)
|
|
|
185
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)
|
|
186
189
|
- [`targets/codex.js`](./targets/codex.js) — OpenAI Codex CLI skill installer
|
|
187
190
|
|
|
188
|
-
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
|
|
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:
|
|
189
202
|
|
|
190
203
|
```bash
|
|
191
204
|
npm test
|
|
@@ -197,7 +210,7 @@ npm test
|
|
|
197
210
|
|
|
198
211
|
Built from scratch on the Node.js standard library. Special thanks to:
|
|
199
212
|
|
|
200
|
-
- **Contributors**: [@PXY000](https://github.com/PXY000) for cross-platform PowerShell skill templates, absolute Node binary resolution in hooks, path traversal guards, and regression tests.
|
|
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.
|
|
201
214
|
- **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).
|
|
202
215
|
|
|
203
216
|
## License
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
**面向主流 AI 编程 Agent(原生支持 Google Antigravity、Claude Code、Codex CLI,开放 `targets/` 插件架构扩展更多工具)的纯 Node.js 零依赖省流套件——毫秒级 `[L起-L止]` 语法骨架导航、原生 `PreToolUse` 防盲读硬刹车、剥离 MCP 空载税的净身角色与 0 Token 本地账单/缓存断层体检。**
|
|
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
|
|
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` 版本,当时仅含基础语法骨架与无行号盲读拦截,尚未针对后续新增净身角色与优化行号放行机制的新版本重跑完整长任务对照,当前版本理论综合省流表现更强*)。
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -99,11 +99,13 @@ $$\text{累计 Cache Read} \approx \text{平均上下文水位} \times \text{模
|
|
|
99
99
|
| **定位首个 Bug 开始改代码耗时** | 227 秒(第 115 步) | **196 秒(第 81 步)** | **提速 31 秒 / 少花 34 步** |
|
|
100
100
|
| **检出并修复的真实硬核 Bug 数** | 7 个(全部编译通过) | **7 个(全部编译通过)** | **0 质量损耗(并发细节更深)** |
|
|
101
101
|
|
|
102
|
-
>
|
|
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)。
|
|
103
105
|
|
|
104
106
|
---
|
|
105
107
|
|
|
106
|
-
## 四大核心能力与全平台支持边界(v0.
|
|
108
|
+
## 四大核心能力与全平台支持边界(v0.5.0)
|
|
107
109
|
|
|
108
110
|
`tokless` 把「跨所有 AI 编程工具通用的省流内核」与「特定客户端的深度钩子/日志解析」拆得清清楚楚,绝不混为一谈:
|
|
109
111
|
|
|
@@ -117,9 +119,12 @@ $$\text{累计 Cache Read} \approx \text{平均上下文水位} \times \text{模
|
|
|
117
119
|
|
|
118
120
|
### 1. `tokless skeleton`(兼容 `repo-skeleton`)+ `rules/AGENTS.md` 省流规范 —【100% 所有 AI 编程工具通用】
|
|
119
121
|
|
|
120
|
-
无需预建索引数据库,纯 Node.js 标准库毫秒级提取 `.js/.ts/.tsx/.py/.go/.rs/.java/.c/.cpp/.md` 等文件的类名、函数签名、接口与精确 **`[L起-L止]`
|
|
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%**:
|
|
121
123
|
|
|
122
124
|
```bash
|
|
125
|
+
# 快速生成全仓目录行数与字数鸟瞰地图(不展开函数签名)
|
|
126
|
+
npx tokless skeleton . --map
|
|
127
|
+
|
|
123
128
|
# 扫描整个源码目录(自动排除 node_modules/.git/dist/target 等),一步生成全局行号地图
|
|
124
129
|
npx tokless skeleton ./src --depth 3
|
|
125
130
|
|
|
@@ -202,7 +207,9 @@ const verdict = evaluateReadGuard({
|
|
|
202
207
|
|
|
203
208
|
---
|
|
204
209
|
|
|
205
|
-
## 社区共建:欢迎扩展更多 AI
|
|
210
|
+
## 社区共建:欢迎扩展更多 AI 编程工具与语言支持(Contributing)
|
|
211
|
+
|
|
212
|
+
### 1. 新增 AI 编程工具一键挂载(`targets/<agent>.js`)
|
|
206
213
|
|
|
207
214
|
`tokless` 将各宿主的安装与卸载逻辑完全解耦在 [`targets/`](./targets/) 目录下,每个宿主只需一个独立的百行级适配器文件:
|
|
208
215
|
|
|
@@ -210,9 +217,17 @@ const verdict = evaluateReadGuard({
|
|
|
210
217
|
- [`targets/claude-code.js`](./targets/claude-code.js) — Claude Code `~/.claude/settings.json` 无损合并与技能挂载(推荐新增适配时优先参考)
|
|
211
218
|
- [`targets/codex.js`](./targets/codex.js) — OpenAI Codex CLI 技能挂载
|
|
212
219
|
|
|
213
|
-
因作者近期精力有限,暂未逐一折腾十几个编辑器的专属全局配置与钩子格式。非常欢迎使用 **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
|
|
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——我们审核无误后会立即合并发版;后续作者空下来也会逐步补充更多工具的官方一键支持。
|
|
221
|
+
|
|
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
|
+
如果你在真实项目中遇到某门语言的语法边界漏检,或希望新增语言支持,请遵循以下稳健省心的共创约定:
|
|
214
227
|
|
|
215
|
-
|
|
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% 零破坏:
|
|
216
231
|
|
|
217
232
|
```bash
|
|
218
233
|
npm test
|
|
@@ -224,7 +239,7 @@ npm test
|
|
|
224
239
|
|
|
225
240
|
`tokless` 全部代码基于 Node.js 标准库从零独立实现,核心设计思路受益于以下优秀开源探索与社区贡献者,特此致谢:
|
|
226
241
|
|
|
227
|
-
- **社区贡献者**:感谢 [@PXY000](https://github.com/PXY000) 在跨平台 PowerShell 技能文档、钩子 Node
|
|
242
|
+
- **社区贡献者**:感谢 [@PXY000](https://github.com/PXY000) 在跨平台 PowerShell 技能文档、钩子 Node 绝对路径解析、路径穿越防护与沙箱安全审计查找上的扎实修复与单测贡献;感谢 [@Mr-PolarBear](https://github.com/Mr-PolarBear) 在 Java 嵌套类、点号/泛型返回类型、匿名字段过滤与 JS 顶层 IIFE 骨架提取上的真实场景修复贡献。
|
|
228
243
|
- **灵感致敬**:
|
|
229
244
|
- [HoangP8/tokless](https://github.com/HoangP8/tokless):启发了项目命名及“指令规范 + 生命周期钩子”组合拦截上下文膨胀的思路;
|
|
230
245
|
- [ILoveMyJay/repocontext](https://github.com/ILoveMyJay/repocontext) 与 [pdavis68/RepoMapper](https://github.com/pdavis68/RepoMapper):启发了“先拿带行号的紧凑语法骨架地图,再按行号精准切片读取”的探索期降耗策略;
|
package/bin/tokless.js
CHANGED
|
@@ -14,7 +14,7 @@ function printHelp() {
|
|
|
14
14
|
Usage:
|
|
15
15
|
tokless install [--target agy|claude|codex|all] [--copy]
|
|
16
16
|
tokless uninstall [--target agy|claude|codex|all]
|
|
17
|
-
tokless skeleton <file-or-dir> [--depth <N>] [--json]
|
|
17
|
+
tokless skeleton <file-or-dir> [--depth <N>] [--map] [--json]
|
|
18
18
|
tokless audit <session|compare|project> [args...] [--json]
|
|
19
19
|
tokless --version | -v
|
|
20
20
|
tokless --help | -h
|
package/index.js
CHANGED
|
@@ -47,10 +47,13 @@ module.exports = {
|
|
|
47
47
|
readGuard,
|
|
48
48
|
IGNORED_DIRS: skeleton.IGNORED_DIRS,
|
|
49
49
|
SUPPORTED_EXTS: skeleton.SUPPORTED_EXTS,
|
|
50
|
+
scanFileLightweight: skeleton.scanFileLightweight,
|
|
50
51
|
generateFileSkeleton: skeleton.generateFileSkeleton,
|
|
51
52
|
scanDirectorySkeleton: skeleton.scanDirectorySkeleton,
|
|
52
53
|
formatSkeletonItems: skeleton.formatSkeletonItems,
|
|
53
54
|
formatDirectorySkeleton: skeleton.formatDirectorySkeleton,
|
|
55
|
+
formatDirectoryMap: skeleton.formatDirectoryMap,
|
|
56
|
+
generateRepoMap: skeleton.generateRepoMap,
|
|
54
57
|
generateSkeleton: skeleton.generateSkeleton,
|
|
55
58
|
estimateTokens: audit.estimateTokens,
|
|
56
59
|
analyzeSession: audit.analyzeSession,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Token optimizer, AST codebase skeletonizer, PreToolUse blind-read guard, lightweight role templates, and cache/compaction auditor for AI coding agents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"uninstall-plugin": "node ./install.js --uninstall",
|
|
40
40
|
"audit": "node ./tools/agy-audit/cli.js",
|
|
41
41
|
"skeleton": "node ./tools/repo-skeleton/cli.js",
|
|
42
|
-
"test": "node ./tests/
|
|
42
|
+
"test": "node ./tests/run-all.js",
|
|
43
43
|
"prepublishOnly": "npm test"
|
|
44
44
|
},
|
|
45
45
|
"repository": {
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-tokless",
|
|
3
3
|
"displayName": "AGY Tokless — Antigravity 省流护栏与账单透视套件",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "专为 AI 编程打造的省流护栏与账单审计插件:提供代码语法骨架提取(repo-skeleton)、大文件盲读拦截钩子(PreToolUse Hook)、轻量净身角色模板(agents)以及 Prefix Cache 断层与 MCP 底座税体检工具(agy-audit)。",
|
|
6
6
|
"disabled": false,
|
|
7
7
|
"suggestedPrompts": [
|
|
@@ -7,17 +7,20 @@ const {
|
|
|
7
7
|
generateFileSkeleton,
|
|
8
8
|
scanDirectorySkeleton,
|
|
9
9
|
formatDirectorySkeleton,
|
|
10
|
+
formatDirectoryMap,
|
|
11
|
+
generateRepoMap,
|
|
10
12
|
} = require('./lib/skeleton');
|
|
11
13
|
|
|
12
14
|
function printUsage() {
|
|
13
15
|
console.log(`repo-skeleton - 极速提取代码文件或目录的紧凑语法骨架与精确行号范围
|
|
14
16
|
|
|
15
17
|
用法:
|
|
16
|
-
node cli.js <文件路径> [--json]
|
|
17
|
-
node cli.js <目录路径> [--depth <深度, 默认 2>] [--json]
|
|
18
|
+
node cli.js <文件路径> [--map] [--json]
|
|
19
|
+
node cli.js <目录路径> [--depth <深度, 默认 2>] [--map] [--json]
|
|
18
20
|
|
|
19
21
|
选项:
|
|
20
|
-
--depth <N>
|
|
22
|
+
--depth <N> 目录扫描最大深度(常规默认: 2,--map 默认: 8;自动排除 node_modules/.git/dist/build/exports/.next/target/__pycache__)
|
|
23
|
+
--map 极简全仓文件体量地图模式(仅输出相对路径、总行数与总字数,不展开函数签名)
|
|
21
24
|
--json 输出结构化 JSON
|
|
22
25
|
-h, --help 显示帮助信息`);
|
|
23
26
|
}
|
|
@@ -25,7 +28,8 @@ function printUsage() {
|
|
|
25
28
|
function parseArgs(argv) {
|
|
26
29
|
const args = argv.slice(2);
|
|
27
30
|
let target = null;
|
|
28
|
-
let depth =
|
|
31
|
+
let depth = null;
|
|
32
|
+
let map = false;
|
|
29
33
|
let json = false;
|
|
30
34
|
let help = false;
|
|
31
35
|
|
|
@@ -35,6 +39,8 @@ function parseArgs(argv) {
|
|
|
35
39
|
help = true;
|
|
36
40
|
} else if (arg === '--json') {
|
|
37
41
|
json = true;
|
|
42
|
+
} else if (arg === '--map') {
|
|
43
|
+
map = true;
|
|
38
44
|
} else if (arg === '--depth') {
|
|
39
45
|
const next = args[i + 1];
|
|
40
46
|
if (next !== undefined && /^\d+$/.test(next)) {
|
|
@@ -51,11 +57,12 @@ function parseArgs(argv) {
|
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
|
|
60
|
+
const effectiveDepth = depth !== null ? depth : (map ? 8 : 2);
|
|
61
|
+
return { target, depth: effectiveDepth, map, json, help };
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
function main() {
|
|
58
|
-
const { target, depth, json, help } = parseArgs(process.argv);
|
|
65
|
+
const { target, depth, map, json, help } = parseArgs(process.argv);
|
|
59
66
|
|
|
60
67
|
if (help || !target) {
|
|
61
68
|
printUsage();
|
|
@@ -71,6 +78,16 @@ function main() {
|
|
|
71
78
|
const stat = fs.statSync(resolved);
|
|
72
79
|
const t0 = performance.now();
|
|
73
80
|
|
|
81
|
+
if (map) {
|
|
82
|
+
const result = generateRepoMap(resolved, { depth });
|
|
83
|
+
if (json) {
|
|
84
|
+
console.log(JSON.stringify(result, null, 2));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
console.log(result.text);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
74
91
|
if (stat.isFile()) {
|
|
75
92
|
const result = generateFileSkeleton(resolved, { includeHeader: false });
|
|
76
93
|
const elapsedMs = Number((performance.now() - t0).toFixed(2));
|
|
@@ -80,9 +97,10 @@ function main() {
|
|
|
80
97
|
return;
|
|
81
98
|
}
|
|
82
99
|
|
|
100
|
+
const charCount = result.charCount ?? result.rawChars ?? 0;
|
|
83
101
|
console.log(`文件: ${result.filePath}`);
|
|
84
102
|
console.log(
|
|
85
|
-
`统计: 总行数 ${result.totalLines} 行 | 全文估算 ${result.rawTokens} tokens → 骨架估算 ${result.skeletonTokens} tokens (节省 ${result.savedPercent}%, 耗时 ${elapsedMs}ms)`
|
|
103
|
+
`统计: 总行数 ${result.totalLines} 行 · ${charCount.toLocaleString('en-US')} 字 | 全文估算 ${result.rawTokens} tokens → 骨架估算 ${result.skeletonTokens} tokens (节省 ${result.savedPercent}%, 耗时 ${elapsedMs}ms)`
|
|
86
104
|
);
|
|
87
105
|
console.log('---');
|
|
88
106
|
console.log(result.formatted);
|