tokless 0.0.0-stage → 0.4.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.
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: token-audit
3
+ description: 审计与对比 Antigravity 会话的真实 Token 账单(Input / Output / Cache Read)、检测 Prefix Cache 断层与自动压缩节点(CHECKPOINT)、揪出单次会话最烧额度的 Top 5 步骤,或诊断项目的 AGENTS.md / SKILL.md 肥胖度与 MCP 空载底座税。
4
+ ---
5
+
6
+ # Antigravity 账单透视、缓存断层与底座税审计指南 (token-audit)
7
+
8
+ 无需消耗任何模型 Token,直接通过本地脚本解析 Antigravity 底层会话日志(`transcript_full.jsonl` / `transcript.jsonl`)与项目/全局 MCP 配置,并自动区分不同代际模型的上下文自动压缩水位(三代模型常见约 256K,四代模型推测约 512K)。
9
+
10
+ ## 常用命令
11
+
12
+ > 注:若已全局安装 `tokless` 包,可直接运行 `tokless audit <session|compare|project> ...`(兼容 `agy-audit`)。Antigravity 仅向 Hook / MCP 进程注入 `PLUGIN_ROOT`,不会注入到常规 `run_command` 终端中,未全局安装 CLI 时请直接使用下方插件路径:
13
+
14
+ ### macOS / Linux (bash / zsh)
15
+
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或前缀>
19
+
20
+ # 2. 优化前后双会话 A/B 对比(对比总 Token、Cache Read 滚雪球、缓存命中率、盲读次数与节省比例)
21
+ node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" compare <优化前会话ID> <优化后会话ID>
22
+
23
+ # 3. 诊断指定项目的常驻规则/Skill 肥胖度,以及全局/工作区 MCP 与工具底座空载税
24
+ node "$HOME/.gemini/config/plugins/agy-tokless/tools/agy-audit/cli.js" project <项目目录路径>
25
+ ```
26
+
27
+ ### Windows (PowerShell)
28
+
29
+ ```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或前缀>
32
+
33
+ # 2. 优化前后双会话 A/B 对比(对比总 Token、Cache Read 滚雪球、缓存命中率、盲读次数与节省比例)
34
+ node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" compare <优化前会话ID> <优化后会话ID>
35
+
36
+ # 3. 诊断指定项目的常驻规则/Skill 肥胖度,以及全局/工作区 MCP 与工具底座空载税
37
+ node "$env:USERPROFILE\.gemini\config\plugins\agy-tokless\tools\agy-audit\cli.js" project <项目目录路径>
38
+ ```
@@ -0,0 +1,150 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const {
6
+ resolveHomeDir,
7
+ shouldForceCopy,
8
+ removePathSafe,
9
+ linkOrCopyDir,
10
+ resolveNodeBinary,
11
+ quoteCommandBinary,
12
+ } = require('./shared');
13
+
14
+ const PLUGIN_NAME = 'agy-tokless';
15
+ const ROOT_FILES = ['plugin.json', 'hooks.json', 'package.json', 'index.js', 'README.md', 'LICENSE'];
16
+ const LINK_DIRS = ['rules', 'skills', 'agents', 'scripts', 'tools', 'lib'];
17
+
18
+ function installHooksJson(srcFile, destFile) {
19
+ try {
20
+ const parsed = JSON.parse(fs.readFileSync(srcFile, 'utf8'));
21
+ const quotedNode = quoteCommandBinary(resolveNodeBinary());
22
+ for (const hookCfg of Object.values(parsed)) {
23
+ if (!hookCfg || typeof hookCfg !== 'object') continue;
24
+ for (const groups of Object.values(hookCfg)) {
25
+ if (!Array.isArray(groups)) continue;
26
+ for (const group of groups) {
27
+ const handlers = Array.isArray(group && group.hooks) ? group.hooks : [group];
28
+ for (const handler of handlers) {
29
+ if (handler && typeof handler.command === 'string' && /^node\s+/.test(handler.command)) {
30
+ handler.command = handler.command.replace(/^node(?=\s+)/, quotedNode);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ fs.writeFileSync(destFile, JSON.stringify(parsed, null, 2) + '\n', 'utf8');
37
+ } catch (_) {
38
+ fs.copyFileSync(srcFile, destFile);
39
+ }
40
+ }
41
+
42
+ function detect(options = {}) {
43
+ const homeDir = resolveHomeDir(options);
44
+ return (
45
+ fs.existsSync(path.join(homeDir, '.gemini')) ||
46
+ fs.existsSync(path.join(homeDir, '.gemini', 'config'))
47
+ );
48
+ }
49
+
50
+ function install(options = {}) {
51
+ const sourceDir = options.sourceDir || path.resolve(__dirname, '..');
52
+ const homeDir = resolveHomeDir(options);
53
+ const forceCopy = shouldForceCopy(sourceDir, options.copy);
54
+ const manifestPath = path.join(sourceDir, 'plugin.json');
55
+
56
+ if (!fs.existsSync(manifestPath)) {
57
+ throw new Error(`[${PLUGIN_NAME}] 未在源目录找到 plugin.json:${sourceDir}`);
58
+ }
59
+
60
+ const pluginsBaseDir = path.join(homeDir, '.gemini', 'config', 'plugins');
61
+ const targetDir = path.join(pluginsBaseDir, PLUGIN_NAME);
62
+ fs.mkdirSync(pluginsBaseDir, { recursive: true });
63
+
64
+ removePathSafe(targetDir);
65
+ // 陷阱: Antigravity Go 插件扫描器 os.ReadDir 会跳过根目录软链/Junction,根级必须用真实目录
66
+ fs.mkdirSync(targetDir, { recursive: true });
67
+
68
+ const copiedFiles = [];
69
+ for (const fileName of ROOT_FILES) {
70
+ const srcFile = path.join(sourceDir, fileName);
71
+ if (fs.existsSync(srcFile)) {
72
+ const destFile = path.join(targetDir, fileName);
73
+ if (fileName === 'hooks.json') {
74
+ installHooksJson(srcFile, destFile);
75
+ } else {
76
+ fs.copyFileSync(srcFile, destFile);
77
+ }
78
+ copiedFiles.push(fileName);
79
+ }
80
+ }
81
+
82
+ const dirModes = {};
83
+ for (const dirName of LINK_DIRS) {
84
+ const mode = linkOrCopyDir(
85
+ path.join(sourceDir, dirName),
86
+ path.join(targetDir, dirName),
87
+ forceCopy
88
+ );
89
+ if (mode !== 'skipped') {
90
+ dirModes[dirName] = mode;
91
+ }
92
+ }
93
+
94
+ if (!options.silent) {
95
+ console.log('');
96
+ console.log(`[tokless:antigravity] 已安装至 ${targetDir}`);
97
+ console.log(` 插件源目录 : ${sourceDir}`);
98
+ console.log(` 清单文件 : ${copiedFiles.join(', ')}`);
99
+ console.log(
100
+ ` 模块挂载 : ${Object.entries(dirModes)
101
+ .map(([k, v]) => `${k}[${v}]`)
102
+ .join(', ')}`
103
+ );
104
+ }
105
+
106
+ return {
107
+ target: 'antigravity',
108
+ targetDir,
109
+ copiedFiles,
110
+ dirModes,
111
+ };
112
+ }
113
+
114
+ function uninstall(options = {}) {
115
+ const homeDir = resolveHomeDir(options);
116
+ const targetDir = path.join(homeDir, '.gemini', 'config', 'plugins', PLUGIN_NAME);
117
+ let existed = fs.existsSync(targetDir);
118
+ if (!existed) {
119
+ try {
120
+ fs.lstatSync(targetDir);
121
+ existed = true;
122
+ } catch (err) {
123
+ if (err.code !== 'ENOENT') throw err;
124
+ }
125
+ }
126
+
127
+ if (!existed) {
128
+ if (!options.silent) {
129
+ console.log(`[tokless:antigravity] 未检测到已安装的 ${PLUGIN_NAME}(${targetDir} 不存在)。`);
130
+ }
131
+ return { target: 'antigravity', targetDir, removed: false };
132
+ }
133
+
134
+ removePathSafe(targetDir);
135
+ if (!options.silent) {
136
+ console.log(`[tokless:antigravity] 已卸载 ${PLUGIN_NAME}(已清理 ${targetDir})。`);
137
+ }
138
+ return { target: 'antigravity', targetDir, removed: true };
139
+ }
140
+
141
+ module.exports = {
142
+ id: 'antigravity',
143
+ aliases: ['agy', 'antigravity'],
144
+ label: 'Antigravity (~/.gemini/config/plugins/agy-tokless)',
145
+ PLUGIN_NAME,
146
+ installHooksJson,
147
+ detect,
148
+ install,
149
+ uninstall,
150
+ };
@@ -0,0 +1,245 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const {
6
+ resolveHomeDir,
7
+ shouldForceCopy,
8
+ removePathSafe,
9
+ linkOrCopyDir,
10
+ resolveNodeBinary,
11
+ quoteCommandBinary,
12
+ } = require('./shared');
13
+
14
+ const CORE_FILES = ['package.json', 'index.js', 'README.md', 'LICENSE'];
15
+ const CORE_DIRS = ['scripts', 'tools', 'lib'];
16
+
17
+ function isToklessHookHandler(handler) {
18
+ if (!handler || typeof handler !== 'object') return false;
19
+ const cmd = String(handler.command || '');
20
+ return cmd.includes('read-guard-hook.js');
21
+ }
22
+
23
+ function mergeClaudeSettings(settingsPath, hookCommand) {
24
+ let settings = {};
25
+ if (fs.existsSync(settingsPath)) {
26
+ const raw = fs.readFileSync(settingsPath, 'utf8').trim();
27
+ if (raw) {
28
+ settings = JSON.parse(raw);
29
+ }
30
+ }
31
+
32
+ if (!settings.hooks || typeof settings.hooks !== 'object' || Array.isArray(settings.hooks)) {
33
+ settings.hooks = {};
34
+ }
35
+ if (!Array.isArray(settings.hooks.PreToolUse)) {
36
+ settings.hooks.PreToolUse = [];
37
+ }
38
+
39
+ const cleanedGroups = [];
40
+ for (const group of settings.hooks.PreToolUse) {
41
+ if (!group || typeof group !== 'object') {
42
+ cleanedGroups.push(group);
43
+ continue;
44
+ }
45
+ if (Array.isArray(group.hooks)) {
46
+ const remaining = group.hooks.filter((h) => !isToklessHookHandler(h));
47
+ if (remaining.length > 0) {
48
+ cleanedGroups.push({ ...group, hooks: remaining });
49
+ }
50
+ } else if (!isToklessHookHandler(group)) {
51
+ cleanedGroups.push(group);
52
+ }
53
+ }
54
+
55
+ cleanedGroups.push({
56
+ matcher: 'Read',
57
+ hooks: [
58
+ {
59
+ type: 'command',
60
+ command: hookCommand,
61
+ timeout: 10,
62
+ },
63
+ ],
64
+ });
65
+
66
+ settings.hooks.PreToolUse = cleanedGroups;
67
+ fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
68
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf8');
69
+ return settings;
70
+ }
71
+
72
+ function unmergeClaudeSettings(settingsPath) {
73
+ if (!fs.existsSync(settingsPath)) return false;
74
+ let settings;
75
+ try {
76
+ const raw = fs.readFileSync(settingsPath, 'utf8').trim();
77
+ if (!raw) return false;
78
+ settings = JSON.parse(raw);
79
+ } catch (_) {
80
+ return false;
81
+ }
82
+
83
+ if (!settings || !settings.hooks || !Array.isArray(settings.hooks.PreToolUse)) {
84
+ return false;
85
+ }
86
+
87
+ let changed = false;
88
+ const cleanedGroups = [];
89
+ for (const group of settings.hooks.PreToolUse) {
90
+ if (!group || typeof group !== 'object') {
91
+ cleanedGroups.push(group);
92
+ continue;
93
+ }
94
+ if (Array.isArray(group.hooks)) {
95
+ const remaining = group.hooks.filter((h) => {
96
+ const hit = isToklessHookHandler(h);
97
+ if (hit) changed = true;
98
+ return !hit;
99
+ });
100
+ if (remaining.length > 0) {
101
+ cleanedGroups.push({ ...group, hooks: remaining });
102
+ }
103
+ } else if (isToklessHookHandler(group)) {
104
+ changed = true;
105
+ } else {
106
+ cleanedGroups.push(group);
107
+ }
108
+ }
109
+
110
+ if (!changed) return false;
111
+
112
+ if (cleanedGroups.length > 0) {
113
+ settings.hooks.PreToolUse = cleanedGroups;
114
+ } else {
115
+ delete settings.hooks.PreToolUse;
116
+ if (Object.keys(settings.hooks).length === 0) {
117
+ delete settings.hooks;
118
+ }
119
+ }
120
+
121
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf8');
122
+ return true;
123
+ }
124
+
125
+ function rewriteClaudeSkillDoc(rawSkillMd, cliPath) {
126
+ const unixCli = cliPath.replace(/\\/g, '/');
127
+ const winCli = cliPath.replace(/\//g, '\\');
128
+ return rawSkillMd
129
+ .replace(/\$HOME\/\.gemini\/config\/plugins\/agy-tokless\/tools\/repo-skeleton\/cli\.js/g, unixCli)
130
+ .replace(/\$env:USERPROFILE\\\.gemini\\config\\plugins\\agy-tokless\\tools\\repo-skeleton\\cli\.js/g, winCli);
131
+ }
132
+
133
+ function detect(options = {}) {
134
+ const homeDir = resolveHomeDir(options);
135
+ return fs.existsSync(path.join(homeDir, '.claude'));
136
+ }
137
+
138
+ function install(options = {}) {
139
+ const sourceDir = options.sourceDir || path.resolve(__dirname, '..');
140
+ const homeDir = resolveHomeDir(options);
141
+ const forceCopy = shouldForceCopy(sourceDir, options.copy);
142
+
143
+ const claudeRoot = path.join(homeDir, '.claude');
144
+ const coreDir = path.join(claudeRoot, 'tokless');
145
+ const skillDestDir = path.join(claudeRoot, 'skills', 'code-skeleton');
146
+ const settingsPath = path.join(claudeRoot, 'settings.json');
147
+
148
+ removePathSafe(coreDir);
149
+ fs.mkdirSync(coreDir, { recursive: true });
150
+
151
+ for (const fileName of CORE_FILES) {
152
+ const srcFile = path.join(sourceDir, fileName);
153
+ if (fs.existsSync(srcFile)) {
154
+ fs.copyFileSync(srcFile, path.join(coreDir, fileName));
155
+ }
156
+ }
157
+
158
+ const dirModes = {};
159
+ for (const dirName of CORE_DIRS) {
160
+ const mode = linkOrCopyDir(
161
+ path.join(sourceDir, dirName),
162
+ path.join(coreDir, dirName),
163
+ forceCopy
164
+ );
165
+ if (mode !== 'skipped') {
166
+ dirModes[dirName] = mode;
167
+ }
168
+ }
169
+
170
+ removePathSafe(skillDestDir);
171
+ fs.mkdirSync(skillDestDir, { recursive: true });
172
+ const srcSkillFile = path.join(sourceDir, 'skills', 'code-skeleton', 'SKILL.md');
173
+ const skeletonCliPath = path.join(coreDir, 'tools', 'repo-skeleton', 'cli.js');
174
+ if (fs.existsSync(srcSkillFile)) {
175
+ const rawSkill = fs.readFileSync(srcSkillFile, 'utf8');
176
+ fs.writeFileSync(
177
+ path.join(skillDestDir, 'SKILL.md'),
178
+ rewriteClaudeSkillDoc(rawSkill, skeletonCliPath),
179
+ 'utf8'
180
+ );
181
+ }
182
+
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);
187
+
188
+ if (!options.silent) {
189
+ console.log('');
190
+ console.log(`[tokless:claude] 已安装核心至 ${coreDir}`);
191
+ console.log(` 技能目录 : ${skillDestDir}`);
192
+ console.log(` 钩子配置 : ${settingsPath} (PreToolUse -> Read)`);
193
+ }
194
+
195
+ return {
196
+ target: 'claude',
197
+ coreDir,
198
+ skillDestDir,
199
+ settingsPath,
200
+ hookCommand,
201
+ dirModes,
202
+ };
203
+ }
204
+
205
+ function uninstall(options = {}) {
206
+ const homeDir = resolveHomeDir(options);
207
+ const claudeRoot = path.join(homeDir, '.claude');
208
+ const coreDir = path.join(claudeRoot, 'tokless');
209
+ const skillDestDir = path.join(claudeRoot, 'skills', 'code-skeleton');
210
+ const settingsPath = path.join(claudeRoot, 'settings.json');
211
+
212
+ const hadCore = fs.existsSync(coreDir);
213
+ const hadSkill = fs.existsSync(skillDestDir);
214
+ removePathSafe(coreDir);
215
+ removePathSafe(skillDestDir);
216
+ const unmerged = unmergeClaudeSettings(settingsPath);
217
+ const removed = hadCore || hadSkill || unmerged;
218
+
219
+ if (!options.silent) {
220
+ if (removed) {
221
+ console.log(`[tokless:claude] 已卸载 Claude Code 挂载(已清理 ${coreDir}、技能与 PreToolUse 钩子)。`);
222
+ } else {
223
+ console.log(`[tokless:claude] 未检测到已安装的 Claude Code 挂载。`);
224
+ }
225
+ }
226
+
227
+ return {
228
+ target: 'claude',
229
+ coreDir,
230
+ skillDestDir,
231
+ settingsPath,
232
+ removed,
233
+ };
234
+ }
235
+
236
+ module.exports = {
237
+ id: 'claude',
238
+ aliases: ['claude', 'claude-code'],
239
+ label: 'Claude Code (~/.claude/tokless + PreToolUse Read hook)',
240
+ mergeClaudeSettings,
241
+ unmergeClaudeSettings,
242
+ detect,
243
+ install,
244
+ uninstall,
245
+ };
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const {
6
+ resolveHomeDir,
7
+ shouldForceCopy,
8
+ removePathSafe,
9
+ linkOrCopyDir,
10
+ } = require('./shared');
11
+
12
+ function rewriteCodexSkillDoc(rawSkillMd, cliPath) {
13
+ const unixCli = cliPath.replace(/\\/g, '/');
14
+ const winCli = cliPath.replace(/\//g, '\\');
15
+ return rawSkillMd
16
+ .replace(/\$HOME\/\.gemini\/config\/plugins\/agy-tokless\/tools\/repo-skeleton\/cli\.js/g, unixCli)
17
+ .replace(/\$env:USERPROFILE\\\.gemini\\config\\plugins\\agy-tokless\\tools\\repo-skeleton\\cli\.js/g, winCli);
18
+ }
19
+
20
+ function detect(options = {}) {
21
+ const homeDir = resolveHomeDir(options);
22
+ return fs.existsSync(path.join(homeDir, '.codex'));
23
+ }
24
+
25
+ function install(options = {}) {
26
+ const sourceDir = options.sourceDir || path.resolve(__dirname, '..');
27
+ const homeDir = resolveHomeDir(options);
28
+ const forceCopy = shouldForceCopy(sourceDir, options.copy);
29
+
30
+ const codexRoot = path.join(homeDir, '.codex');
31
+ const skillDestDir = path.join(codexRoot, 'skills', 'code-skeleton');
32
+ const toolsDestDir = path.join(skillDestDir, 'tools');
33
+
34
+ removePathSafe(skillDestDir);
35
+ fs.mkdirSync(skillDestDir, { recursive: true });
36
+
37
+ const mode = linkOrCopyDir(
38
+ path.join(sourceDir, 'tools'),
39
+ toolsDestDir,
40
+ forceCopy
41
+ );
42
+
43
+ const srcSkillFile = path.join(sourceDir, 'skills', 'code-skeleton', 'SKILL.md');
44
+ const skeletonCliPath = path.join(toolsDestDir, 'repo-skeleton', 'cli.js');
45
+ if (fs.existsSync(srcSkillFile)) {
46
+ const rawSkill = fs.readFileSync(srcSkillFile, 'utf8');
47
+ fs.writeFileSync(
48
+ path.join(skillDestDir, 'SKILL.md'),
49
+ rewriteCodexSkillDoc(rawSkill, skeletonCliPath),
50
+ 'utf8'
51
+ );
52
+ }
53
+
54
+ if (!options.silent) {
55
+ console.log('');
56
+ console.log(`[tokless:codex] 已安装 code-skeleton 技能至 ${skillDestDir} (${mode})`);
57
+ }
58
+
59
+ return {
60
+ target: 'codex',
61
+ skillDestDir,
62
+ mode,
63
+ };
64
+ }
65
+
66
+ function uninstall(options = {}) {
67
+ const homeDir = resolveHomeDir(options);
68
+ const skillDestDir = path.join(homeDir, '.codex', 'skills', 'code-skeleton');
69
+ let existed = fs.existsSync(skillDestDir);
70
+ if (!existed) {
71
+ try {
72
+ fs.lstatSync(skillDestDir);
73
+ existed = true;
74
+ } catch (err) {
75
+ if (err.code !== 'ENOENT') throw err;
76
+ }
77
+ }
78
+
79
+ if (!existed) {
80
+ if (!options.silent) {
81
+ console.log(`[tokless:codex] 未检测到已安装的 Codex 技能(${skillDestDir} 不存在)。`);
82
+ }
83
+ return { target: 'codex', skillDestDir, removed: false };
84
+ }
85
+
86
+ removePathSafe(skillDestDir);
87
+ if (!options.silent) {
88
+ console.log(`[tokless:codex] 已卸载 Codex 技能(已清理 ${skillDestDir})。`);
89
+ }
90
+ return { target: 'codex', skillDestDir, removed: true };
91
+ }
92
+
93
+ module.exports = {
94
+ id: 'codex',
95
+ aliases: ['codex', 'codex-cli'],
96
+ label: 'Codex CLI (~/.codex/skills/code-skeleton)',
97
+ detect,
98
+ install,
99
+ uninstall,
100
+ };
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ const antigravity = require('./antigravity');
4
+ const claudeCode = require('./claude-code');
5
+ const codex = require('./codex');
6
+
7
+ // Community PR extension point: register single-file host adapters (e.g. Cursor, Windsurf, Cline, OpenCode) here.
8
+ const TARGET_ADAPTERS = [antigravity, claudeCode, codex];
9
+
10
+ function listTargets() {
11
+ return TARGET_ADAPTERS.slice();
12
+ }
13
+
14
+ function resolveTargetAdapter(name) {
15
+ const normalized = String(name || '').trim().toLowerCase();
16
+ if (!normalized) return null;
17
+ for (const adapter of TARGET_ADAPTERS) {
18
+ if (adapter.id === normalized || (Array.isArray(adapter.aliases) && adapter.aliases.includes(normalized))) {
19
+ return adapter;
20
+ }
21
+ }
22
+ return null;
23
+ }
24
+
25
+ function resolveTargets(targetSpec, options = {}) {
26
+ const mode = options.mode || 'auto';
27
+ if (targetSpec) {
28
+ const rawParts = String(targetSpec)
29
+ .split(',')
30
+ .map((s) => s.trim().toLowerCase())
31
+ .filter(Boolean);
32
+
33
+ if (rawParts.includes('all')) {
34
+ return listTargets();
35
+ }
36
+
37
+ const selected = [];
38
+ const seen = new Set();
39
+ for (const part of rawParts) {
40
+ const adapter = resolveTargetAdapter(part);
41
+ if (!adapter) {
42
+ const supported = TARGET_ADAPTERS.map((a) => a.aliases[0]).concat(['all']).join(', ');
43
+ throw new Error(`未知宿主目标 "${part}"。可选值: ${supported}`);
44
+ }
45
+ if (!seen.has(adapter.id)) {
46
+ seen.add(adapter.id);
47
+ selected.push(adapter);
48
+ }
49
+ }
50
+ return selected;
51
+ }
52
+
53
+ if (mode === 'antigravity-only') {
54
+ return [antigravity];
55
+ }
56
+
57
+ const detected = [antigravity];
58
+ for (const adapter of TARGET_ADAPTERS) {
59
+ if (adapter.id === 'antigravity') continue;
60
+ if (typeof adapter.detect === 'function' && adapter.detect(options)) {
61
+ detected.push(adapter);
62
+ }
63
+ }
64
+ return detected;
65
+ }
66
+
67
+ module.exports = {
68
+ TARGET_ADAPTERS,
69
+ listTargets,
70
+ resolveTargetAdapter,
71
+ resolveTargets,
72
+ antigravity,
73
+ claudeCode,
74
+ codex,
75
+ };