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/bin/tokless.js CHANGED
@@ -9,19 +9,23 @@ const { parseCliArgs, runInstall, runUninstall } = require('../install');
9
9
  const REPO_ROOT = path.resolve(__dirname, '..');
10
10
 
11
11
  function printHelp() {
12
- console.log(`tokless v${pkg.version} - AST codebase skeletonizer, blind-read guard & session token auditor
12
+ console.log(`tokless v${pkg.version} - AST codebase skeletonizer, optional blind-read guard & session token auditor
13
13
 
14
14
  Usage:
15
- tokless install [--target agy|claude|codex|all] [--copy]
15
+ tokless install [--target agy|claude|codex|all] [--with-guard] [--copy]
16
16
  tokless uninstall [--target agy|claude|codex|all]
17
- tokless skeleton <file-or-dir> [--depth <N>] [--map] [--json]
18
- tokless audit <session|compare|project> [args...] [--json]
17
+ tokless skeleton <file-or-dir> [--depth <N>] [--exclude <dirs>] [--map] [--json]
18
+ tokless audit <list|session|compare|project> [args...] [--json]
19
19
  tokless --version | -v
20
20
  tokless --help | -h
21
21
 
22
+ Install Options:
23
+ --with-guard Opt-in PreToolUse hook (>800-line unsliced blind-read skeleton navigator; disabled by default)
24
+ --copy Copy files instead of linking (auto-enabled in _npx / node_modules)
25
+
22
26
  Targets:
23
27
  agy Antigravity (~/.gemini/config/plugins/agy-tokless)
24
- claude Claude Code (~/.claude/tokless + skills + settings.json PreToolUse Read hook)
28
+ claude Claude Code (~/.claude/tokless + skills; optional settings.json PreToolUse Read hook via --with-guard)
25
29
  codex Codex CLI (~/.codex/skills/code-skeleton)
26
30
  all Install/uninstall across all supported targets
27
31
  (omit) Auto-install Antigravity + any detected ~/.claude or ~/.codex host`);
@@ -62,6 +66,7 @@ function main() {
62
66
  sourceDir: REPO_ROOT,
63
67
  target: parsed.target,
64
68
  copy: parsed.copy,
69
+ withGuard: parsed.withGuard,
65
70
  mode: 'auto',
66
71
  });
67
72
  } catch (err) {
package/index.js CHANGED
@@ -56,12 +56,14 @@ module.exports = {
56
56
  generateRepoMap: skeleton.generateRepoMap,
57
57
  generateSkeleton: skeleton.generateSkeleton,
58
58
  estimateTokens: audit.estimateTokens,
59
+ listSessions: audit.listSessions,
59
60
  analyzeSession: audit.analyzeSession,
60
61
  compareSessions: audit.compareSessions,
61
62
  auditProject: audit.auditProject,
62
63
  auditMcpAndTools: audit.auditMcpAndTools,
63
64
  parseAgentMarkdown: audit.parseAgentMarkdown,
64
65
  formatSessionMarkdown: audit.formatSessionMarkdown,
66
+ formatSessionListMarkdown: audit.formatSessionListMarkdown,
65
67
  formatCompareMarkdown: audit.formatCompareMarkdown,
66
68
  formatProjectMarkdown: audit.formatProjectMarkdown,
67
69
  COMPACTION_THRESHOLD_256K: audit.COMPACTION_THRESHOLD_256K,
package/install.js CHANGED
@@ -8,6 +8,7 @@ const { shouldForceCopy, resolveHomeDir } = require('./targets/shared');
8
8
  function parseCliArgs(argv) {
9
9
  let target = null;
10
10
  let copy = false;
11
+ let withGuard = false;
11
12
  let uninstall = false;
12
13
  let help = false;
13
14
 
@@ -17,6 +18,8 @@ function parseCliArgs(argv) {
17
18
  help = true;
18
19
  } else if (arg === '--copy') {
19
20
  copy = true;
21
+ } else if (arg === '--with-guard') {
22
+ withGuard = true;
20
23
  } else if (arg === '--uninstall') {
21
24
  uninstall = true;
22
25
  } else if (arg === '--target' || arg === '-t') {
@@ -29,13 +32,14 @@ function parseCliArgs(argv) {
29
32
  }
30
33
  }
31
34
 
32
- return { target, copy, uninstall, help };
35
+ return { target, copy, withGuard, uninstall, help };
33
36
  }
34
37
 
35
38
  function runInstall(options = {}) {
36
39
  const sourceDir = options.sourceDir || __dirname;
37
40
  const homeDir = resolveHomeDir(options);
38
41
  const forceCopy = shouldForceCopy(sourceDir, Boolean(options.copy));
42
+ const withGuard = Boolean(options.withGuard);
39
43
  const mode = options.mode || 'antigravity-only';
40
44
  const adapters = resolveTargets(options.target, { homeDir, mode });
41
45
 
@@ -46,6 +50,7 @@ function runInstall(options = {}) {
46
50
  sourceDir,
47
51
  homeDir,
48
52
  copy: forceCopy,
53
+ withGuard,
49
54
  silent: options.silent,
50
55
  })
51
56
  );
@@ -71,9 +76,10 @@ function runUninstall(options = {}) {
71
76
  }
72
77
 
73
78
  function printHelp() {
74
- console.log(`Usage: node install.js [--target agy|claude|codex|all] [--copy] [--uninstall]
75
- (default) Install Antigravity plugin into ~/.gemini/config/plugins/agy-tokless
79
+ console.log(`Usage: node install.js [--target agy|claude|codex|all] [--with-guard] [--copy] [--uninstall]
80
+ (default) Install Antigravity plugin into ~/.gemini/config/plugins/agy-tokless (PreToolUse hook disabled by default)
76
81
  --target <hosts> Target host(s): agy, claude, codex, all (comma-separated supported)
82
+ --with-guard Opt-in PreToolUse hook to return syntax skeleton on unsliced blind reads >800 lines (disabled by default)
77
83
  --copy Copy all files instead of creating links (auto-enabled in _npx / node_modules)
78
84
  --uninstall Remove installed tokless plugin/hooks for the selected target(s)`);
79
85
  }
@@ -95,6 +101,7 @@ function main() {
95
101
  runInstall({
96
102
  target: parsed.target,
97
103
  copy: parsed.copy,
104
+ withGuard: parsed.withGuard,
98
105
  mode: 'antigravity-only',
99
106
  });
100
107
  } catch (err) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokless",
3
- "version": "0.5.0",
4
- "description": "Token optimizer, AST codebase skeletonizer, PreToolUse blind-read guard, lightweight role templates, and cache/compaction auditor for AI coding agents.",
3
+ "version": "0.5.2",
4
+ "description": "Token optimizer, AST codebase skeletonizer, optional PreToolUse blind-read guard, lightweight role templates, and cache/compaction auditor for AI coding agents.",
5
5
  "license": "MIT",
6
6
  "main": "./index.js",
7
7
  "bin": {
@@ -39,6 +39,8 @@
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
+ "bump": "node ./scripts/bump-version.js",
43
+ "version": "node ./scripts/bump-version.js --sync-from-pkg && git add plugin.json",
42
44
  "test": "node ./tests/run-all.js",
43
45
  "prepublishOnly": "npm test"
44
46
  },
package/plugin.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "agy-tokless",
3
3
  "displayName": "AGY Tokless — Antigravity 省流护栏与账单透视套件",
4
- "version": "0.5.0",
5
- "description": "专为 AI 编程打造的省流护栏与账单审计插件:提供代码语法骨架提取(repo-skeleton)、大文件盲读拦截钩子(PreToolUse Hook)、轻量净身角色模板(agents)以及 Prefix Cache 断层与 MCP 底座税体检工具(agy-audit)。",
4
+ "version": "0.5.2",
5
+ "description": "专为 AI 编程打造的省流导航与账单审计插件:提供代码语法骨架提取(repo-skeleton)、可选超大文件盲读骨架导航钩子(PreToolUse Hook,--with-guard 启用)、轻量净身角色模板(agents)以及 Prefix Cache 断层与 MCP 底座税体检工具(agy-audit)。",
6
6
  "disabled": false,
7
7
  "suggestedPrompts": [
8
8
  "使用 token-audit 检查最近会话的 Token 消耗黑洞、Prefix Cache 断层与当前项目的 MCP 底座空载税",
package/rules/AGENTS.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # AI 编程省流读取、净身角色与缓存保护规范 (tokless)
2
2
 
3
3
  ## 1. 先看代码骨架,再按行号精准读取 (`tokless skeleton` / `repo-skeleton`)
4
- - **严禁盲目全量读取大代码文件**:在未确定目标函数、类或逻辑块所在行号前,严禁不带起止行号(`StartLine`/`EndLine` 或 `offset`/`limit`)直接读取超过 200 行的源码文件,也严禁传入 `1~全文末尾` 的假切片糊弄全读。
4
+ - **拒绝无行号盲读与“伪精准”大区间硬读**:探索陌生模块或中大型代码文件(约 `>200` 行)前必须先提取语法骨架定位行号;严禁不抽骨架直接无行号盲读,或用 `StartLine=1, EndLine=800` 等泛大跨度区间伪装按行读取来跳过骨架导航(可选启用 `--with-guard` 读前护栏后,仅对 `>800` 行无行号盲读自动返回全文骨架辅助导航,凡传入显式行号参数一律放行)。
5
5
  - **两步精准定位法**:
6
6
  1. 探索陌生目录或大文件时,先用 `tokless skeleton`(兼容 `repo-skeleton`)提取语法签名与 `[L起-L止]` 行号(0 模型 Token,比盲读全文省 85%~97% 探索开销):
7
7
  - 全局 CLI(推荐): `tokless skeleton <目录或文件路径> --depth 2`
8
8
  - macOS / Linux: `node "$HOME/.gemini/config/plugins/agy-tokless/tools/repo-skeleton/cli.js" <目录或文件路径> --depth 2`
9
9
  - Windows (PowerShell): `node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\repo-skeleton\cli.js" <目录或文件路径> --depth 2`
10
- 2. 根据骨架中的 `[L起-L止]` 行号,调用 `read_file(Path, StartLine, EndLine)`(或 `Read(file_path, offset, limit)`)按需完整读取目标函数或逻辑块(无单次行数跨度硬限制,只要有明确目标区间即可一次读完)。
10
+ 2. 根据骨架中的 `[L起-L止]` 行号,调用 `read_file(Path, StartLine, EndLine)`(或 `Read(file_path, offset, limit)`)按需完整读取目标函数或逻辑块(针对骨架已定位的明确目标区间无单次跨度硬限制,可一次读完;未定位前禁止用 `1-800` 等满额区间批量扫读多个陌生文件)。
11
11
 
12
12
  ## 2. 轻量角色净身(卸除无关 MCP 与工具底座税)
13
13
  - 纯代码编写或只读代码审查会话优先启用 `inheritMcp: false` 及最小 `tools` 清单(如内置净身角色 `tokless-coder`、`tokless-reviewer`),剥离用不上的浏览器/外部 MCP Schema 每步固定底座税。
14
14
 
15
15
  ## 3. 本地账单透视、Prefix Cache 保护与控水位减轮次 (`tokless audit` / `agy-audit`)
16
- - **0 Token 账单与底座税体检**(支持 `session <ID>` 查缓存断层与 Top 5 膨胀步、`compare <前ID> <后ID>`、`project <项目目录>` 查规则肥胖度与 MCP 空载税):
17
- - 全局 CLI(推荐): `tokless audit <session|compare|project> <参数>`
18
- - macOS / Linux: `node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" <session|compare|project> <参数>`
19
- - Windows (PowerShell): `node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" <session|compare|project> <参数>`
16
+ - **0 Token 账单与底座税体检**(支持 `list` 列最近会话、`session <ID|latest>` 查缓存断层/模型切换归因与 Top 5 膨胀步、`compare <前ID> <后ID>`、`project <项目目录>` 查常驻规则与 MCP 底座账单):
17
+ - 全局 CLI(推荐): `tokless audit <list|session|compare|project> <参数>`
18
+ - macOS / Linux: `node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" <list|session|compare|project> <参数>`
19
+ - Windows (PowerShell): `node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" <list|session|compare|project> <参数>`
20
20
  - **严控终端输出与保护 Prefix Cache**:`run_command` 必须主动限制长日志输出规模;对话中途保持顶部规则稳定只追加,控制上下文水位与对话轮次以降低累计 `Cache Read` 滚雪球并避免触发历史自动压缩(三代模型常见约 256K,四代模型实测跑上 440K 未触发、推测约 512K)。
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ const REPO_ROOT = path.resolve(__dirname, '..');
8
+ const PKG_PATH = path.join(REPO_ROOT, 'package.json');
9
+ const PLUGIN_PATH = path.join(REPO_ROOT, 'plugin.json');
10
+ const SEMVER_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
11
+
12
+ function readJson(filePath) {
13
+ return JSON.parse(fs.readFileSync(filePath, 'utf8'));
14
+ }
15
+
16
+ function writeJson(filePath, obj) {
17
+ fs.writeFileSync(filePath, JSON.stringify(obj, null, 2) + '\n', 'utf8');
18
+ }
19
+
20
+ function bumpVersion(rawTarget, options = {}) {
21
+ const rootDir = options.rootDir || REPO_ROOT;
22
+ const pkgPath = path.join(rootDir, 'package.json');
23
+ const pluginPath = path.join(rootDir, 'plugin.json');
24
+
25
+ const pkg = readJson(pkgPath);
26
+ const plugin = readJson(pluginPath);
27
+
28
+ const normalized = options.syncFromPkg
29
+ ? String(pkg.version || '').trim()
30
+ : String(rawTarget || '').trim().replace(/^v/i, '');
31
+
32
+ if (!SEMVER_RE.test(normalized)) {
33
+ throw new Error(
34
+ `Invalid semver version "${rawTarget || ''}". Usage: npm run bump -- <major.minor.patch>`
35
+ );
36
+ }
37
+
38
+ const prevPkg = pkg.version;
39
+ const prevPlugin = plugin.version;
40
+
41
+ pkg.version = normalized;
42
+ plugin.version = normalized;
43
+
44
+ writeJson(pkgPath, pkg);
45
+ writeJson(pluginPath, plugin);
46
+
47
+ return {
48
+ version: normalized,
49
+ updated: [
50
+ { file: 'package.json', from: prevPkg, to: normalized },
51
+ { file: 'plugin.json', from: prevPlugin, to: normalized },
52
+ ],
53
+ };
54
+ }
55
+
56
+ function main() {
57
+ const args = process.argv.slice(2);
58
+ const syncFromPkg = args.includes('--sync-from-pkg');
59
+ const positional = args.find((a) => !a.startsWith('-'));
60
+
61
+ if (!syncFromPkg && !positional) {
62
+ console.error('Usage: npm run bump -- <version> (e.g. npm run bump -- 0.5.2)');
63
+ process.exit(1);
64
+ }
65
+
66
+ try {
67
+ const result = bumpVersion(positional, { syncFromPkg });
68
+ for (const item of result.updated) {
69
+ console.log(`[bump] ${item.file}: ${item.from} -> ${item.to}`);
70
+ }
71
+ } catch (err) {
72
+ console.error(`[bump] ${err.message}`);
73
+ process.exit(1);
74
+ }
75
+ }
76
+
77
+ if (require.main === module) {
78
+ main();
79
+ }
80
+
81
+ module.exports = { bumpVersion };
@@ -4,27 +4,17 @@
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
 
7
+ const { SUPPORTED_EXTS } = require('../tools/repo-skeleton/lib/core/registry');
8
+
7
9
  const READ_GUARD_SCRIPT_PATH = __filename;
8
10
  const HOOKS_CONFIG_PATH = path.resolve(__dirname, '../hooks.json');
9
11
  const PLUGIN_MANIFEST_PATH = path.resolve(__dirname, '../plugin.json');
12
+ const MAX_SKELETON_ITEMS = 120;
13
+ const MAX_FALLBACK_SEGMENTS = 20;
10
14
 
11
- const GUARDED_CODE_EXTS = new Set([
12
- '.js',
13
- '.mjs',
14
- '.cjs',
15
- '.ts',
16
- '.tsx',
17
- '.jsx',
18
- '.py',
19
- '.go',
20
- '.rs',
21
- '.java',
22
- '.c',
23
- '.cpp',
24
- '.cs',
25
- '.vue',
26
- '.svelte',
27
- ]);
15
+ const GUARDED_CODE_EXTS = new Set(
16
+ [...SUPPORTED_EXTS].filter((ext) => ext !== '.md' && ext !== '.mdx')
17
+ );
28
18
 
29
19
  function loadSkeletonGenerator() {
30
20
  const localLib = path.resolve(__dirname, '../tools/repo-skeleton/lib/skeleton.js');
@@ -39,9 +29,9 @@ function getMaxLinesThreshold(overrideVal) {
39
29
  }
40
30
  }
41
31
  const raw = process.env.TOKLESS_READ_MAX_LINES || process.env.AGY_READ_MAX_LINES;
42
- if (!raw) return 200;
32
+ if (!raw) return 800;
43
33
  const parsed = parseInt(raw, 10);
44
- return Number.isInteger(parsed) && parsed > 0 ? parsed : 200;
34
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : 800;
45
35
  }
46
36
 
47
37
  function parseLineArg(val) {
@@ -50,6 +40,56 @@ function parseLineArg(val) {
50
40
  return Number.isFinite(parsed) ? Math.floor(parsed) : null;
51
41
  }
52
42
 
43
+ function buildFallbackSegments(filePath, totalLines, maxLines) {
44
+ let lines = [];
45
+ try {
46
+ const content = fs.readFileSync(filePath, 'utf8');
47
+ lines = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n');
48
+ } catch (_) {
49
+ return `(未识别到显式函数/类签名,全文件共 ${totalLines} 行)`;
50
+ }
51
+
52
+ const step = Math.max(200, Math.min(maxLines, 400));
53
+ const out = [`(未识别到显式函数/类签名,按每段 ${step} 行提供首行定位预览:)`];
54
+ let segmentCount = 0;
55
+ for (let start = 1; start <= totalLines; start += step) {
56
+ if (segmentCount >= MAX_FALLBACK_SEGMENTS) {
57
+ out.push(`... (后段 [L${start}-L${totalLines}] 省略,请按区间继续分段读取)`);
58
+ break;
59
+ }
60
+ const end = Math.min(totalLines, start + step - 1);
61
+ let preview = '(空行/注释)';
62
+ for (let idx = start - 1; idx < end && idx < lines.length; idx++) {
63
+ const t = lines[idx].trim();
64
+ if (t) {
65
+ preview = t.length > 60 ? t.slice(0, 57) + '...' : t;
66
+ break;
67
+ }
68
+ }
69
+ out.push(`[L${start}-L${end}] ${preview}`);
70
+ segmentCount++;
71
+ }
72
+ return out.join('\n');
73
+ }
74
+
75
+ function formatBoundedSkeleton(skeleton, filePath, maxLines) {
76
+ if (!skeleton.items || skeleton.items.length === 0) {
77
+ return buildFallbackSegments(filePath, skeleton.totalLines, maxLines);
78
+ }
79
+ if (skeleton.items.length <= MAX_SKELETON_ITEMS) {
80
+ return skeleton.formatted;
81
+ }
82
+ const headLines = skeleton.items.slice(0, MAX_SKELETON_ITEMS).map((item) => {
83
+ const indent = ' '.repeat(item.depth || 0);
84
+ return `${indent}[L${item.startLine}-L${item.endLine}] ${item.signature}`;
85
+ });
86
+ const remaining = skeleton.items.length - MAX_SKELETON_ITEMS;
87
+ headLines.push(
88
+ `... (共 ${skeleton.items.length} 条声明,已截断显示前 ${MAX_SKELETON_ITEMS} 条,剩余 ${remaining} 条请运行 tokless skeleton CLI 或 grep 定位)`
89
+ );
90
+ return headLines.join('\n');
91
+ }
92
+
53
93
  function isClaudeCodePayload(payload, toolName) {
54
94
  if (!payload || typeof payload !== 'object') return false;
55
95
  if (toolName === 'Read') return true;
@@ -140,13 +180,15 @@ function evaluateReadGuard(payloadOrJson, options = {}) {
140
180
 
141
181
  const hasStart = startNum !== null;
142
182
  const hasEnd = endNum !== null;
143
- const maxLines = getMaxLinesThreshold(options.maxLines);
144
-
145
- // 陷阱: 严禁设 300 行死跨度硬拦截(会导致报错重试+拆轮倒贴数十万 Cache Read);正常局部行号切片直接放行,仅核查盲读与 1~EOF 假切片
146
- if (hasStart && startNum > 2) {
183
+ const byteOffsetVal = args.ByteOffset ?? args.byteOffset ?? args.byte_offset;
184
+ const hasByteOffset =
185
+ byteOffsetVal !== undefined && byteOffsetVal !== null && byteOffsetVal !== '';
186
+ // 陷阱: 凡传入了显式行号参数或字节偏移一律直接放行(禁设单次跨度上限或拦截 L1~EOF,避免报错重试+拆轮反噬数十万 Cache Read)
187
+ if (hasStart || hasEnd || hasByteOffset) {
147
188
  return { decision: 'allow', host };
148
189
  }
149
190
 
191
+ const maxLines = getMaxLinesThreshold(options.maxLines);
150
192
  const generateFileSkeleton = loadSkeletonGenerator();
151
193
  const skeleton = generateFileSkeleton(resolvedPath, { includeHeader: false });
152
194
 
@@ -157,29 +199,14 @@ function evaluateReadGuard(payloadOrJson, options = {}) {
157
199
  const rangeHint = isClaude
158
200
  ? '重新调用 Read 并传入目标区间的 offset 与 limit'
159
201
  : '重新调用 read_file 并传入目标区间的 StartLine 和 EndLine';
202
+ const skelBody = formatBoundedSkeleton(skeleton, resolvedPath, maxLines);
160
203
 
161
- if (!hasStart && !hasEnd) {
162
- const reason =
163
- `[tokless 省流护栏] 目标文件共 ${skeleton.totalLines} 行(超过 ${maxLines} 行全量读取阈值),已拦截盲目全量读取以保护上下文额度。\n` +
164
- `请根据下方该文件的语法骨架与 [L起-L止] 行号范围,${rangeHint}精准读取所需片段:\n\n` +
165
- `${skeleton.formatted}`;
166
-
167
- return { decision: 'deny', reason, host };
168
- }
169
-
170
- const effectiveStart = hasStart ? Math.max(1, startNum) : 1;
171
- const requestedEnd = hasEnd ? endNum : skeleton.totalLines;
172
-
173
- if (effectiveStart <= 2 && requestedEnd >= skeleton.totalLines - 2) {
174
- const reason =
175
- `[tokless 省流护栏] 目标文件共 ${skeleton.totalLines} 行,检测到 L${effectiveStart}-L${requestedEnd} 覆盖全文首尾的假切片全读,已拦截以保护上下文额度。\n` +
176
- `请根据下方该文件的语法骨架与 [L起-L止] 行号范围,${rangeHint}精准读取真实需要的函数或逻辑块:\n\n` +
177
- `${skeleton.formatted}`;
178
-
179
- return { decision: 'deny', reason, host };
180
- }
204
+ const reason =
205
+ `[tokless 省流护栏] 目标文件共 ${skeleton.totalLines} 行(超过 ${maxLines} 行无行号读取阈值),已返回语法骨架辅助定位。\n` +
206
+ `请根据下方该文件的语法骨架与 [L起-L止] 行号范围,${rangeHint}精准读取所需片段:\n\n` +
207
+ `${skelBody}`;
181
208
 
182
- return { decision: 'allow', host };
209
+ return { decision: 'deny', reason, host };
183
210
  } catch (_) {
184
211
  return { decision: 'allow', host: 'antigravity' };
185
212
  }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: code-skeleton
3
- description: 提取代码文件或目录的紧凑语法骨架(仅保留类名、函数签名、导出接口与精确 [L起-L止] 行号,剥离具体实现代码)。在探索代码库、排查 Bug 或读取超过 200 行的大文件前使用此技能快速定位行号,可减少 85%~97% 的探索期 Token 消耗。
3
+ description: 提取代码文件或目录的紧凑语法骨架(仅保留类名、函数签名、导出接口与精确 [L起-L止] 行号,剥离具体实现代码)。支持 C/C++ 大头文件与源码(.c/.h/.cpp/.hpp 的宏、typedef、struct、extern "C" 与条件编译平衡)。在探索代码库、排查 Bug 或读取中大型文件前使用此技能快速定位行号,可减少 85%~97% 的探索期 Token 消耗。
4
4
  ---
5
5
 
6
6
  # 代码骨架极速提取指南 (code-skeleton)
@@ -17,18 +17,18 @@ description: 提取代码文件或目录的紧凑语法骨架(仅保留类名
17
17
  # 1. 扫描源码目录(自动排除 node_modules/.git/dist/target 等,默认深度 2),一步拿到全局函数与行号地图
18
18
  node "$HOME/.gemini/config/plugins/agy-tokless/tools/repo-skeleton/cli.js" <目录路径> --depth 2
19
19
 
20
- # 2. 提取单个大文件的函数/类签名与起止行号
20
+ # 2. 提取单个大文件(含 C/C++ .c/.h/.cpp/.hpp)的函数/类/typedef/宏签名与起止行号
21
21
  node "$HOME/.gemini/config/plugins/agy-tokless/tools/repo-skeleton/cli.js" <文件路径>
22
22
  ```
23
23
 
24
24
  ### Windows (PowerShell)
25
25
 
26
26
  ```powershell
27
- # 1. 扫描源码目录(自动排除 node_modules/.git/dist/target 等,默认深度 2),一步拿到全局函数与行号地图
27
+ # 1. 扫描源码目录(自动排除 node_modules/.git/dist/target/Objects/cmake-build-* 等,默认深度 2;支持 --exclude 指定额外忽略目录)
28
28
  node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\repo-skeleton\cli.js" <目录路径> --depth 2
29
29
 
30
- # 2. 提取单个大文件的函数/类签名与起止行号
30
+ # 2. 提取单个大文件(含 C/C++ .c/.h/.cpp/.hpp)的函数/类/typedef/宏签名与起止行号
31
31
  node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\repo-skeleton\cli.js" <文件路径>
32
32
  ```
33
33
 
34
- 拿到目标函数的 `[L起-L止]` 行号后,直接调用 `read_file(Path, StartLine, EndLine)`(或 Claude Code `Read(file_path, offset, limit)`)按需完整读取对应代码段(无单次行数跨度限制,严禁不带行号盲读或传 `1~EOF` 假切片)。
34
+ 拿到目标函数的 `[L起-L止]` 行号后,直接调用 `read_file(Path, StartLine, EndLine)`(或 Claude Code `Read(file_path, offset, limit)`)按需完整读取对应代码段(针对骨架已定位的目标区间无单次跨度硬限制;但探索陌生中大型文件(`>200` 行)前必须先跑骨架,严禁直接传 `1-800` 等泛大跨度区间批量硬读代替骨架导航;若启用 `--with-guard` 护栏,仅对 `>800` 行无行号盲读返回全文骨架辅助导航)。
@@ -14,11 +14,14 @@ description: 审计与对比 Antigravity 会话的真实 Token 账单(Input /
14
14
  ### macOS / Linux (bash / zsh)
15
15
 
16
16
  ```bash
17
- # 1. 解剖单个会话(支持短 ID 前缀或日志路径),查看缓存断层、最慢步骤 Top 3、MCP 空载继承与 Top 5 烧钱步骤
18
- node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" session <会话ID或前缀>
17
+ # 0. 列出最近会话(兼容 antigravity / antigravity-cli / antigravity-ide,支持 --source cli|app|ide|all)
18
+ node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" list --source cli
19
+
20
+ # 1. 解剖单个会话(支持 latest、latest~1、短 ID 前缀或日志路径),查看缓存断层、模型切换型缓存断层归因、最慢步骤 Top 3、MCP 空载继承与 Top 5 烧钱步骤
21
+ node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" session latest
19
22
 
20
23
  # 2. 优化前后双会话 A/B 对比(对比总 Token、Cache Read 滚雪球、缓存命中率、盲读次数与节省比例)
21
- node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" compare <优化前会话ID> <优化后会话ID>
24
+ node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" compare latest~1 latest
22
25
 
23
26
  # 3. 诊断指定项目的常驻规则/Skill 肥胖度,以及全局/工作区 MCP 与工具底座空载税
24
27
  node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" project <项目目录路径>
@@ -27,11 +30,14 @@ node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" project <
27
30
  ### Windows (PowerShell)
28
31
 
29
32
  ```powershell
30
- # 1. 解剖单个会话(支持短 ID 前缀或日志路径),查看缓存断层、最慢步骤 Top 3、MCP 空载继承与 Top 5 烧钱步骤
31
- node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" session <会话ID或前缀>
33
+ # 0. 列出最近 agy CLI 会话
34
+ node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" list --source cli
35
+
36
+ # 1. 解剖单个会话(支持 latest、latest~1、短 ID 前缀或日志路径),查看缓存断层、模型切换型缓存断层归因、最慢步骤 Top 3、MCP 空载继承与 Top 5 烧钱步骤
37
+ node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" session latest
32
38
 
33
39
  # 2. 优化前后双会话 A/B 对比(对比总 Token、Cache Read 滚雪球、缓存命中率、盲读次数与节省比例)
34
- node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" compare <优化前会话ID> <优化后会话ID>
40
+ node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" compare latest~1 latest
35
41
 
36
42
  # 3. 诊断指定项目的常驻规则/Skill 肥胖度,以及全局/工作区 MCP 与工具底座空载税
37
43
  node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" project <项目目录路径>
@@ -51,6 +51,7 @@ function install(options = {}) {
51
51
  const sourceDir = options.sourceDir || path.resolve(__dirname, '..');
52
52
  const homeDir = resolveHomeDir(options);
53
53
  const forceCopy = shouldForceCopy(sourceDir, options.copy);
54
+ const withGuard = Boolean(options.withGuard);
54
55
  const manifestPath = path.join(sourceDir, 'plugin.json');
55
56
 
56
57
  if (!fs.existsSync(manifestPath)) {
@@ -67,6 +68,9 @@ function install(options = {}) {
67
68
 
68
69
  const copiedFiles = [];
69
70
  for (const fileName of ROOT_FILES) {
71
+ if (fileName === 'hooks.json' && !withGuard) {
72
+ continue;
73
+ }
70
74
  const srcFile = path.join(sourceDir, fileName);
71
75
  if (fs.existsSync(srcFile)) {
72
76
  const destFile = path.join(targetDir, fileName);
@@ -96,6 +100,9 @@ function install(options = {}) {
96
100
  console.log(`[tokless:antigravity] 已安装至 ${targetDir}`);
97
101
  console.log(` 插件源目录 : ${sourceDir}`);
98
102
  console.log(` 清单文件 : ${copiedFiles.join(', ')}`);
103
+ console.log(
104
+ ` 读前护栏 : ${withGuard ? '已启用 (--with-guard, >800 行无行号导航)' : '默认关闭 (需启用请加 --with-guard)'}`
105
+ );
99
106
  console.log(
100
107
  ` 模块挂载 : ${Object.entries(dirModes)
101
108
  .map(([k, v]) => `${k}[${v}]`)
@@ -107,6 +114,7 @@ function install(options = {}) {
107
114
  target: 'antigravity',
108
115
  targetDir,
109
116
  copiedFiles,
117
+ withGuard,
110
118
  dirModes,
111
119
  };
112
120
  }
@@ -139,6 +139,7 @@ function install(options = {}) {
139
139
  const sourceDir = options.sourceDir || path.resolve(__dirname, '..');
140
140
  const homeDir = resolveHomeDir(options);
141
141
  const forceCopy = shouldForceCopy(sourceDir, options.copy);
142
+ const withGuard = Boolean(options.withGuard);
142
143
 
143
144
  const claudeRoot = path.join(homeDir, '.claude');
144
145
  const coreDir = path.join(claudeRoot, 'tokless');
@@ -180,16 +181,28 @@ function install(options = {}) {
180
181
  );
181
182
  }
182
183
 
183
- const hookScriptPath = path.join(coreDir, 'scripts', 'read-guard-hook.js');
184
- const quotedNode = quoteCommandBinary(resolveNodeBinary());
185
- const hookCommand = `${quotedNode} ${JSON.stringify(hookScriptPath)}`;
186
- mergeClaudeSettings(settingsPath, hookCommand);
184
+ let hookCommand = null;
185
+ let cleanedStaleHook = false;
186
+ if (withGuard) {
187
+ const hookScriptPath = path.join(coreDir, 'scripts', 'read-guard-hook.js');
188
+ const quotedNode = quoteCommandBinary(resolveNodeBinary());
189
+ hookCommand = `${quotedNode} ${JSON.stringify(hookScriptPath)}`;
190
+ mergeClaudeSettings(settingsPath, hookCommand);
191
+ } else if (fs.existsSync(settingsPath)) {
192
+ cleanedStaleHook = unmergeClaudeSettings(settingsPath);
193
+ }
187
194
 
188
195
  if (!options.silent) {
189
196
  console.log('');
190
197
  console.log(`[tokless:claude] 已安装核心至 ${coreDir}`);
191
198
  console.log(` 技能目录 : ${skillDestDir}`);
192
- console.log(` 钩子配置 : ${settingsPath} (PreToolUse -> Read)`);
199
+ if (withGuard) {
200
+ console.log(` 钩子配置 : ${settingsPath} (已启用 PreToolUse -> Read, >800 行无行号导航)`);
201
+ } else if (cleanedStaleHook) {
202
+ console.log(` 钩子配置 : 已从 ${settingsPath} 自动移除旧 PreToolUse 钩子 (默认关闭,需启用请加 --with-guard)`);
203
+ } else {
204
+ console.log(` 钩子配置 : 默认关闭 (需启用 PreToolUse -> Read 请加 --with-guard)`);
205
+ }
193
206
  }
194
207
 
195
208
  return {
@@ -198,6 +211,8 @@ function install(options = {}) {
198
211
  skillDestDir,
199
212
  settingsPath,
200
213
  hookCommand,
214
+ withGuard,
215
+ cleanedStaleHook,
201
216
  dirModes,
202
217
  };
203
218
  }
@@ -236,7 +251,7 @@ function uninstall(options = {}) {
236
251
  module.exports = {
237
252
  id: 'claude',
238
253
  aliases: ['claude', 'claude-code'],
239
- label: 'Claude Code (~/.claude/tokless + PreToolUse Read hook)',
254
+ label: 'Claude Code (~/.claude/tokless + skills; optional PreToolUse Read hook)',
240
255
  mergeClaudeSettings,
241
256
  unmergeClaudeSettings,
242
257
  detect,