tokless 0.5.1 → 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 +47 -158
- package/README.md +54 -197
- package/bin/tokless.js +2 -2
- package/index.js +2 -0
- package/package.json +3 -1
- package/plugin.json +1 -1
- package/rules/AGENTS.md +6 -6
- package/scripts/bump-version.js +81 -0
- package/scripts/read-guard-hook.js +64 -20
- package/skills/code-skeleton/SKILL.md +5 -5
- package/skills/token-audit/SKILL.md +12 -6
- package/tools/agy-audit/cli.js +78 -24
- package/tools/agy-audit/lib/analyzer.js +133 -14
- package/tools/agy-audit/lib/compare.js +5 -3
- package/tools/agy-audit/lib/formatter.js +85 -28
- package/tools/agy-audit/lib/paths.js +381 -88
- package/tools/agy-audit/lib/project.js +88 -79
- package/tools/repo-skeleton/cli.js +24 -9
- package/tools/repo-skeleton/lib/core/registry.js +15 -1
- package/tools/repo-skeleton/lib/langs/c-family/c-cpp-parser.js +1133 -0
- package/tools/repo-skeleton/lib/langs/c-family/index.js +42 -77
- package/tools/repo-skeleton/lib/skeleton.js +23 -1
|
@@ -5,10 +5,27 @@ const os = require('os');
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const { estimateTokens } = require('./analyzer');
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
8
|
+
const CONFIG_DIR_NAMES = ['.agents', '.agent', '_agents', '_agent'];
|
|
9
|
+
|
|
10
|
+
function parseFrontmatterTrigger(content) {
|
|
11
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
12
|
+
if (!match) return null;
|
|
13
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
14
|
+
const m = line.match(/^\s*trigger\s*:\s*['"]?([A-Za-z0-9_-]+)['"]?\s*$/i);
|
|
15
|
+
if (m) return m[1].toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function canonicalDocKey(filePath) {
|
|
21
|
+
try {
|
|
22
|
+
const rp = fs.realpathSync(filePath);
|
|
23
|
+
return process.platform === 'win32' ? rp.toLowerCase() : rp;
|
|
24
|
+
} catch (_) {
|
|
25
|
+
const resolved = path.resolve(filePath);
|
|
26
|
+
return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
12
29
|
|
|
13
30
|
// Baseline per-step schema token estimates
|
|
14
31
|
const DEFAULT_BUILTIN_TOOLS_EST_TOKENS = 4200;
|
|
@@ -210,14 +227,34 @@ function auditMcpAndTools(rootDir, options = {}) {
|
|
|
210
227
|
}
|
|
211
228
|
}
|
|
212
229
|
|
|
213
|
-
// 3. Workspace MCP configs (.mcp.json, .agents/mcp_config.json
|
|
214
|
-
const workspaceMcpCandidates = [
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
230
|
+
// 3. Workspace MCP configs (.mcp.json, .agents/.agent/_agents/_agent mcp_config.json & workspace plugins, plugin root)
|
|
231
|
+
const workspaceMcpCandidates = [{ p: path.join(rootDir, '.mcp.json'), label: '.mcp.json' }];
|
|
232
|
+
const agentDirs = [];
|
|
233
|
+
for (const cfgName of CONFIG_DIR_NAMES) {
|
|
234
|
+
const cfgDir = path.join(rootDir, cfgName);
|
|
235
|
+
if (!fs.existsSync(cfgDir) || !fs.statSync(cfgDir).isDirectory()) continue;
|
|
236
|
+
workspaceMcpCandidates.push({
|
|
237
|
+
p: path.join(cfgDir, 'mcp_config.json'),
|
|
238
|
+
label: `${cfgName}/mcp_config.json`,
|
|
239
|
+
});
|
|
240
|
+
agentDirs.push(path.join(cfgDir, 'agents'));
|
|
241
|
+
|
|
242
|
+
const wsPluginsDir = path.join(cfgDir, 'plugins');
|
|
243
|
+
if (fs.existsSync(wsPluginsDir) && fs.statSync(wsPluginsDir).isDirectory()) {
|
|
244
|
+
for (const pEntry of fs.readdirSync(wsPluginsDir, { withFileTypes: true })) {
|
|
245
|
+
if (!pEntry.isDirectory()) continue;
|
|
246
|
+
const pRoot = path.join(wsPluginsDir, pEntry.name);
|
|
247
|
+
workspaceMcpCandidates.push({
|
|
248
|
+
p: path.join(pRoot, 'mcp_config.json'),
|
|
249
|
+
label: `${cfgName}/plugins/${pEntry.name}/mcp_config.json`,
|
|
250
|
+
});
|
|
251
|
+
agentDirs.push(path.join(pRoot, 'agents'));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
219
255
|
if (fs.existsSync(path.join(rootDir, 'plugin.json'))) {
|
|
220
256
|
workspaceMcpCandidates.push({ p: path.join(rootDir, 'mcp_config.json'), label: 'mcp_config.json' });
|
|
257
|
+
agentDirs.push(path.join(rootDir, 'agents'));
|
|
221
258
|
}
|
|
222
259
|
for (const item of workspaceMcpCandidates) {
|
|
223
260
|
collectMcpServersFromFile(item.p, 'workspace', item.label, mcpServers);
|
|
@@ -228,14 +265,7 @@ function auditMcpAndTools(rootDir, options = {}) {
|
|
|
228
265
|
const defaultToolAndMcpPerStep = DEFAULT_BUILTIN_TOOLS_EST_TOKENS + activeMcpEstTokensPerStep;
|
|
229
266
|
const est30StepSnowballTokens = defaultToolAndMcpPerStep * 30;
|
|
230
267
|
|
|
231
|
-
// 4. Scan project agent definitions (.agents
|
|
232
|
-
const agentDirs = [
|
|
233
|
-
path.join(rootDir, '.agents', 'agents'),
|
|
234
|
-
path.join(rootDir, '.agent', 'agents')
|
|
235
|
-
];
|
|
236
|
-
if (fs.existsSync(path.join(rootDir, 'plugin.json'))) {
|
|
237
|
-
agentDirs.push(path.join(rootDir, 'agents'));
|
|
238
|
-
}
|
|
268
|
+
// 4. Scan project agent definitions (.agents/.agent/_agents/_agent/agents/*.md and plugin agents/*.md)
|
|
239
269
|
|
|
240
270
|
const agents = [];
|
|
241
271
|
const seenAgentPaths = new Set();
|
|
@@ -334,58 +364,28 @@ function inspectDocFile(filePath, rootDir, category, loadMode) {
|
|
|
334
364
|
const estTokens = estimateTokens(chars);
|
|
335
365
|
const relPath = path.relative(rootDir, filePath).replace(/\\/g, '/');
|
|
336
366
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const suggestions = [];
|
|
345
|
-
if (exceedsLineLimit) {
|
|
346
|
-
if (isAlwaysOn) {
|
|
347
|
-
suggestions.push(
|
|
348
|
-
`行数超标 (${lines} 行 > ${lineLimit} 行上限):将命令模板、操作步骤与长示例下沉到 .agents/skills/*/SKILL.md(改为按需加载),常驻规则仅保留硬性边界与目录分工,压至 80 行以内。`
|
|
349
|
-
);
|
|
350
|
-
} else {
|
|
351
|
-
suggestions.push(
|
|
352
|
-
`行数超标 (${lines} 行 > ${lineLimit} 行上限):将长篇参考表、模板代码拆分到同级 references/ 或 scripts/ 目录,SKILL.md 主体只保留触发条件与核心步骤(控制在 100 行以内)。`
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (highDensity) {
|
|
357
|
-
if (isAlwaysOn) {
|
|
358
|
-
suggestions.push(
|
|
359
|
-
`高密度体积偏大 (${bytes} 字节 / 约 ${estTokens} Token,每轮对话必扣):建议删减长段落背景描述与内联示例,精简为短句清单,将常驻成本压到 2,000 字节 (~600 Token) 以内。`
|
|
360
|
-
);
|
|
361
|
-
} else {
|
|
362
|
-
suggestions.push(
|
|
363
|
-
`单次触发体积偏大 (${bytes} 字节 / 约 ${estTokens} Token):建议精简冗长散文描述,将大段规范/示例外置到 references/*.md 按需读取。`
|
|
364
|
-
);
|
|
367
|
+
let effectiveLoadMode = loadMode;
|
|
368
|
+
let effectiveCategory = category;
|
|
369
|
+
if (category === 'rule') {
|
|
370
|
+
const trigger = parseFrontmatterTrigger(content);
|
|
371
|
+
if (trigger === 'model_decision' || trigger === 'glob') {
|
|
372
|
+
effectiveLoadMode = 'Progressive Disclosure';
|
|
373
|
+
effectiveCategory = `rule (${trigger})`;
|
|
365
374
|
}
|
|
366
375
|
}
|
|
367
376
|
|
|
368
|
-
|
|
369
|
-
if (exceedsLineLimit) {
|
|
370
|
-
status = 'BLOAT';
|
|
371
|
-
} else if (highDensity) {
|
|
372
|
-
status = 'DENSE';
|
|
373
|
-
}
|
|
377
|
+
const isAlwaysOn = effectiveLoadMode === 'Always-On';
|
|
374
378
|
|
|
375
379
|
return {
|
|
376
380
|
relativePath: relPath,
|
|
377
381
|
absolutePath: filePath,
|
|
378
|
-
category,
|
|
379
|
-
loadMode,
|
|
380
|
-
lineLimit,
|
|
382
|
+
category: effectiveCategory,
|
|
383
|
+
loadMode: effectiveLoadMode,
|
|
381
384
|
lines,
|
|
382
385
|
chars,
|
|
383
386
|
bytes,
|
|
384
387
|
estTokens,
|
|
385
|
-
|
|
386
|
-
highDensity,
|
|
387
|
-
status,
|
|
388
|
-
suggestions
|
|
388
|
+
est30StepTokens: isAlwaysOn ? estTokens * 30 : null
|
|
389
389
|
};
|
|
390
390
|
}
|
|
391
391
|
|
|
@@ -402,8 +402,9 @@ function auditProject(dirPath, options = {}) {
|
|
|
402
402
|
const seenDocPaths = new Set();
|
|
403
403
|
const pushDoc = (filePath, category, loadMode) => {
|
|
404
404
|
const resolved = path.resolve(filePath);
|
|
405
|
-
|
|
406
|
-
seenDocPaths.
|
|
405
|
+
const key = canonicalDocKey(resolved);
|
|
406
|
+
if (seenDocPaths.has(key)) return;
|
|
407
|
+
seenDocPaths.add(key);
|
|
407
408
|
files.push(inspectDocFile(resolved, rootDir, category, loadMode));
|
|
408
409
|
};
|
|
409
410
|
|
|
@@ -418,11 +419,30 @@ function auditProject(dirPath, options = {}) {
|
|
|
418
419
|
pushDoc(geminiPath, 'GEMINI.md', 'Always-On');
|
|
419
420
|
}
|
|
420
421
|
|
|
421
|
-
// 2. .agents/rules
|
|
422
|
-
const rulesDirs = [
|
|
422
|
+
// 2 & 3. .agents / .agent / _agents / _agent rules, skills, and workspace plugins (plus root plugin layout)
|
|
423
|
+
const rulesDirs = [];
|
|
424
|
+
const skillsDirs = [];
|
|
425
|
+
for (const cfgName of CONFIG_DIR_NAMES) {
|
|
426
|
+
const cfgDir = path.join(rootDir, cfgName);
|
|
427
|
+
if (!fs.existsSync(cfgDir) || !fs.statSync(cfgDir).isDirectory()) continue;
|
|
428
|
+
rulesDirs.push(path.join(cfgDir, 'rules'));
|
|
429
|
+
skillsDirs.push(path.join(cfgDir, 'skills'));
|
|
430
|
+
|
|
431
|
+
const pluginsDir = path.join(cfgDir, 'plugins');
|
|
432
|
+
if (fs.existsSync(pluginsDir) && fs.statSync(pluginsDir).isDirectory()) {
|
|
433
|
+
for (const pEntry of fs.readdirSync(pluginsDir, { withFileTypes: true })) {
|
|
434
|
+
if (!pEntry.isDirectory()) continue;
|
|
435
|
+
const pRoot = path.join(pluginsDir, pEntry.name);
|
|
436
|
+
rulesDirs.push(path.join(pRoot, 'rules'));
|
|
437
|
+
skillsDirs.push(path.join(pRoot, 'skills'));
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
423
441
|
if (fs.existsSync(path.join(rootDir, 'plugin.json'))) {
|
|
424
442
|
rulesDirs.push(path.join(rootDir, 'rules'));
|
|
443
|
+
skillsDirs.push(path.join(rootDir, 'skills'));
|
|
425
444
|
}
|
|
445
|
+
|
|
426
446
|
for (const rulesDir of rulesDirs) {
|
|
427
447
|
if (fs.existsSync(rulesDir) && fs.statSync(rulesDir).isDirectory()) {
|
|
428
448
|
for (const entry of fs.readdirSync(rulesDir, { withFileTypes: true })) {
|
|
@@ -433,11 +453,6 @@ function auditProject(dirPath, options = {}) {
|
|
|
433
453
|
}
|
|
434
454
|
}
|
|
435
455
|
|
|
436
|
-
// 3. .agents/skills/*/SKILL.md (and plugin skills/*/SKILL.md if plugin.json exists)
|
|
437
|
-
const skillsDirs = [path.join(rootDir, '.agents', 'skills')];
|
|
438
|
-
if (fs.existsSync(path.join(rootDir, 'plugin.json'))) {
|
|
439
|
-
skillsDirs.push(path.join(rootDir, 'skills'));
|
|
440
|
-
}
|
|
441
456
|
for (const skillsDir of skillsDirs) {
|
|
442
457
|
if (fs.existsSync(skillsDir) && fs.statSync(skillsDir).isDirectory()) {
|
|
443
458
|
for (const entry of fs.readdirSync(skillsDir, { withFileTypes: true })) {
|
|
@@ -462,30 +477,24 @@ function auditProject(dirPath, options = {}) {
|
|
|
462
477
|
estTokens: arr.reduce((s, f) => s + f.estTokens, 0)
|
|
463
478
|
});
|
|
464
479
|
|
|
465
|
-
const flaggedFiles = files.filter(f => f.exceedsLineLimit || f.highDensity);
|
|
466
480
|
const mcpAndToolTax = auditMcpAndTools(rootDir, options);
|
|
481
|
+
const alwaysOnSummary = sum(alwaysOnFiles);
|
|
467
482
|
|
|
468
483
|
return {
|
|
469
484
|
projectDir: rootDir,
|
|
470
485
|
projectName: path.basename(rootDir),
|
|
471
|
-
thresholds: {
|
|
472
|
-
alwaysOnLineLimit: ALWAYS_ON_LINE_LIMIT,
|
|
473
|
-
skillLineLimit: SKILL_LINE_LIMIT,
|
|
474
|
-
alwaysOnByteAdvisory: ALWAYS_ON_BYTE_ADVISORY,
|
|
475
|
-
skillByteAdvisory: SKILL_BYTE_ADVISORY
|
|
476
|
-
},
|
|
477
486
|
summary: {
|
|
478
487
|
totalFiles: files.length,
|
|
479
|
-
alwaysOn:
|
|
488
|
+
alwaysOn: {
|
|
489
|
+
...alwaysOnSummary,
|
|
490
|
+
est30StepTokens: alwaysOnSummary.estTokens * 30
|
|
491
|
+
},
|
|
480
492
|
progressiveDisclosure: sum(skillFiles),
|
|
481
|
-
lineViolations: files.filter(f => f.exceedsLineLimit).length,
|
|
482
|
-
densityWarnings: files.filter(f => !f.exceedsLineLimit && f.highDensity).length,
|
|
483
493
|
enabledMcpCount: mcpAndToolTax.enabledMcpCount,
|
|
484
494
|
defaultToolAndMcpPerStepTokens: mcpAndToolTax.defaultSessionEstTokensPerStep,
|
|
485
495
|
agentRoleCount: mcpAndToolTax.agents.length
|
|
486
496
|
},
|
|
487
497
|
files,
|
|
488
|
-
flaggedFiles,
|
|
489
498
|
mcpAndToolTax
|
|
490
499
|
};
|
|
491
500
|
}
|
|
@@ -16,13 +16,14 @@ function printUsage() {
|
|
|
16
16
|
|
|
17
17
|
用法:
|
|
18
18
|
node cli.js <文件路径> [--map] [--json]
|
|
19
|
-
node cli.js <目录路径> [--depth <深度, 默认 2>] [--map] [--json]
|
|
19
|
+
node cli.js <目录路径> [--depth <深度, 默认 2>] [--exclude <dir1,dir2>] [--map] [--json]
|
|
20
20
|
|
|
21
21
|
选项:
|
|
22
|
-
--depth <N>
|
|
23
|
-
--
|
|
24
|
-
--
|
|
25
|
-
|
|
22
|
+
--depth <N> 目录扫描最大深度(常规默认: 2,--map 默认: 8;自动排除 node_modules/.git/dist/build/exports/.next/target/__pycache__/Objects/Listings/.cache/.clangd/cmake-build-*)
|
|
23
|
+
--exclude <dirs> 额外排除的目录名(逗号分隔,可重复传入)
|
|
24
|
+
--map 极简全仓文件体量地图模式(仅输出相对路径、总行数与总字数,不展开函数签名)
|
|
25
|
+
--json 输出结构化 JSON
|
|
26
|
+
-h, --help 显示帮助信息`);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
function parseArgs(argv) {
|
|
@@ -32,6 +33,7 @@ function parseArgs(argv) {
|
|
|
32
33
|
let map = false;
|
|
33
34
|
let json = false;
|
|
34
35
|
let help = false;
|
|
36
|
+
const exclude = [];
|
|
35
37
|
|
|
36
38
|
for (let i = 0; i < args.length; i++) {
|
|
37
39
|
const arg = args[i];
|
|
@@ -52,17 +54,30 @@ function parseArgs(argv) {
|
|
|
52
54
|
if (/^\d+$/.test(val)) {
|
|
53
55
|
depth = parseInt(val, 10);
|
|
54
56
|
}
|
|
57
|
+
} else if (arg === '--exclude') {
|
|
58
|
+
const next = args[i + 1];
|
|
59
|
+
if (next !== undefined) {
|
|
60
|
+
for (const p of next.split(',')) {
|
|
61
|
+
if (p.trim()) exclude.push(p.trim());
|
|
62
|
+
}
|
|
63
|
+
i++;
|
|
64
|
+
}
|
|
65
|
+
} else if (arg.startsWith('--exclude=')) {
|
|
66
|
+
const val = arg.slice('--exclude='.length);
|
|
67
|
+
for (const p of val.split(',')) {
|
|
68
|
+
if (p.trim()) exclude.push(p.trim());
|
|
69
|
+
}
|
|
55
70
|
} else if (!arg.startsWith('-') && !target) {
|
|
56
71
|
target = arg;
|
|
57
72
|
}
|
|
58
73
|
}
|
|
59
74
|
|
|
60
75
|
const effectiveDepth = depth !== null ? depth : (map ? 8 : 2);
|
|
61
|
-
return { target, depth: effectiveDepth, map, json, help };
|
|
76
|
+
return { target, depth: effectiveDepth, map, json, help, exclude };
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
function main() {
|
|
65
|
-
const { target, depth, map, json, help } = parseArgs(process.argv);
|
|
80
|
+
const { target, depth, map, json, help, exclude } = parseArgs(process.argv);
|
|
66
81
|
|
|
67
82
|
if (help || !target) {
|
|
68
83
|
printUsage();
|
|
@@ -79,7 +94,7 @@ function main() {
|
|
|
79
94
|
const t0 = performance.now();
|
|
80
95
|
|
|
81
96
|
if (map) {
|
|
82
|
-
const result = generateRepoMap(resolved, { depth });
|
|
97
|
+
const result = generateRepoMap(resolved, { depth, exclude });
|
|
83
98
|
if (json) {
|
|
84
99
|
console.log(JSON.stringify(result, null, 2));
|
|
85
100
|
return;
|
|
@@ -108,7 +123,7 @@ function main() {
|
|
|
108
123
|
}
|
|
109
124
|
|
|
110
125
|
if (stat.isDirectory()) {
|
|
111
|
-
const result = scanDirectorySkeleton(resolved, { depth });
|
|
126
|
+
const result = scanDirectorySkeleton(resolved, { depth, exclude });
|
|
112
127
|
const elapsedMs = Number((performance.now() - t0).toFixed(2));
|
|
113
128
|
|
|
114
129
|
if (json) {
|
|
@@ -6,7 +6,21 @@ const LANG_DIR_TO_EXTS = Object.freeze({
|
|
|
6
6
|
javascript: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'],
|
|
7
7
|
sfc: ['.vue', '.svelte'],
|
|
8
8
|
java: ['.java'],
|
|
9
|
-
'c-family': [
|
|
9
|
+
'c-family': [
|
|
10
|
+
'.c',
|
|
11
|
+
'.h',
|
|
12
|
+
'.cpp',
|
|
13
|
+
'.hpp',
|
|
14
|
+
'.cc',
|
|
15
|
+
'.cxx',
|
|
16
|
+
'.c++',
|
|
17
|
+
'.hh',
|
|
18
|
+
'.hxx',
|
|
19
|
+
'.h++',
|
|
20
|
+
'.inl',
|
|
21
|
+
'.inc',
|
|
22
|
+
'.cs',
|
|
23
|
+
],
|
|
10
24
|
kotlin: ['.kt', '.kts'],
|
|
11
25
|
go: ['.go'],
|
|
12
26
|
rust: ['.rs'],
|