tokless 0.4.1 → 0.5.1

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.
@@ -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,
@@ -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> 目录扫描最大深度(默认: 2,自动排除 node_modules/.git/dist/build/exports/.next/target/__pycache__)
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 = 2;
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
- return { target, depth, json, help };
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);