skillfmt 0.1.0__py3-none-any.whl

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,407 @@
1
+ Metadata-Version: 2.4
2
+ Name: skillfmt
3
+ Version: 0.1.0
4
+ Summary: AI Skill 格式转换与管理工具 — 写一次定义,导出到所有主流 AI 平台
5
+ Project-URL: Homepage, https://github.com/user/skills-manager
6
+ Project-URL: Repository, https://github.com/user/skills-manager
7
+ Project-URL: Issues, https://github.com/user/skills-manager/issues
8
+ Author: Skills Manager Team
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: agent,ai,claude,function-calling,gemini,mcp,openai,skill,tool
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Topic :: Software Development :: Code Generators
25
+ Classifier: Topic :: Utilities
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: pyyaml>=6.0
28
+ Requires-Dist: rich>=13.0.0
29
+ Requires-Dist: typer>=0.9.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest-cov; extra == 'dev'
32
+ Requires-Dist: pytest>=7.0; extra == 'dev'
33
+ Provides-Extra: recommend
34
+ Requires-Dist: jieba>=0.42.1; extra == 'recommend'
35
+ Provides-Extra: remote
36
+ Requires-Dist: httpx>=0.24.0; extra == 'remote'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # Skills Manager
40
+
41
+ > 用一种极简格式定义 AI Skill,一键导出为 OpenAI / Claude / Gemini / MCP 等主流平台格式。
42
+
43
+ ## 核心理念
44
+
45
+ **不要做 Skill 的 npm,做 Skill 的 babel。**
46
+
47
+ AI Agent 生态的工具格式碎片化,同一个能力要在每个平台手写一遍定义。Skills Manager 让你只写一次,到处导出。
48
+
49
+ ## 项目状态
50
+
51
+ - **测试覆盖率**:92%
52
+ - **测试数量**:144 个(全部通过)
53
+ - **支持格式**:5 种(OpenAI / Claude / Gemini / MCP / JSON Schema)
54
+ - **平台打包**:3 种(Claude Desktop / Codex / Claude Code)
55
+
56
+ ## 功能特性
57
+
58
+ ### 核心功能
59
+
60
+ - **格式转换**:一份定义 → 多平台格式(OpenAI / Claude / Gemini / MCP / JSON Schema)
61
+ - **可视化管理**:桌面客户端提供直观的 Skill 浏览、搜索、编辑和导出体验
62
+ - **本地管理**:所有 Skill 统一存储,安装、搜索、查看一条命令或一次点击搞定
63
+ - **自动同步**:安装后自动 symlink 到各 agent 目录,agent 立即可用
64
+ - **格式验证**:安装前自动验证 SKILL.md 格式,确保合规
65
+
66
+ ### 桌面客户端
67
+
68
+ - **Skill 浏览**:卡片式浏览、分类筛选、关键词搜索
69
+ - **类型筛选**:按 component / interactive / workflow 语义类型筛选
70
+ - **一键导出**:选中 Skill → 选择目标平台 → 复制或保存
71
+ - **批量导出**:多选 Skill 批量导出
72
+ - **平台打包**:导出为 Claude Desktop / Codex / Claude Code 平台格式
73
+ - **安装管理**:从目录、.skill 包、自动扫描导入
74
+ - **主题切换**:浅色 / 深色主题
75
+ - **监视路径**:自定义扫描路径
76
+
77
+ ### CLI 工具
78
+
79
+ ```bash
80
+ # Skill 管理
81
+ skills-manager install <source> # 安装(目录 / .skill 包)
82
+ skills-manager uninstall <name> # 卸载
83
+ skills-manager list # 列出已安装
84
+ skills-manager info <name> # 查看详情
85
+
86
+ # 格式导出
87
+ skills-manager export <name> --format openai|claude|gemini|mcp|schema
88
+ skills-manager export --all --format openai # 批量导出
89
+
90
+ # 打包
91
+ skills-manager pack <dir> # 打包为 .skill 文件
92
+ ```
93
+
94
+ ## 安装
95
+
96
+ ### 从源码安装
97
+
98
+ ```bash
99
+ # 克隆仓库
100
+ git clone <repo-url>
101
+ cd skills-manager-prototype
102
+
103
+ # 创建虚拟环境
104
+ python -m venv .venv
105
+ source .venv/bin/activate # Linux/macOS
106
+ # 或
107
+ .venv\Scripts\activate # Windows
108
+
109
+ # 安装依赖
110
+ pip install -e ".[dev]"
111
+ ```
112
+
113
+ ### 运行桌面应用
114
+
115
+ ```bash
116
+ python -m desktop.main
117
+ ```
118
+
119
+ ### 运行 CLI
120
+
121
+ ```bash
122
+ skills-manager --help
123
+ ```
124
+
125
+ ## 快速开始
126
+
127
+ ### 1. 创建一个 Skill
128
+
129
+ 创建目录 `my-skill/`,在其中创建 `SKILL.md`:
130
+
131
+ ```markdown
132
+ ---
133
+ name: hello
134
+ version: "1.0.0"
135
+ description: 一个简单的问候工具
136
+ summary: 向用户打招呼,支持中英文。
137
+ skill_type: component
138
+ intent: 用于测试和演示的简单问候工具
139
+ tags: [demo, greeting]
140
+ category: misc
141
+ ---
142
+
143
+ ## 功能
144
+
145
+ 向用户打招呼。
146
+
147
+ ## 参数
148
+
149
+ | 参数 | 类型 | 必需 | 说明 |
150
+ |------|------|------|------|
151
+ | name | string | ✅ | 用户名称 |
152
+ | language | string | ❌ | 语言:zh / en,默认 zh |
153
+
154
+ ## 示例
155
+
156
+ ```json
157
+ {"name": "世界", "language": "zh"}
158
+ ```
159
+
160
+ ```json
161
+ {"greeting": "你好,世界!"}
162
+ ```
163
+
164
+ ## 适用场景
165
+
166
+ - 测试 Skill 系统
167
+ - 演示基本功能
168
+
169
+ ## 不适用
170
+
171
+ - 生产环境使用
172
+ ```
173
+
174
+ ### 2. 安装 Skill
175
+
176
+ ```bash
177
+ # 从目录安装
178
+ skills-manager install ./my-skill
179
+
180
+ # 或使用桌面应用
181
+ # 点击侧边栏"安装 Skill" → 选择目录
182
+ ```
183
+
184
+ ### 3. 导出 Skill
185
+
186
+ ```bash
187
+ # 导出为 OpenAI 格式
188
+ skills-manager export hello --format openai
189
+
190
+ # 导出为 Claude 格式
191
+ skills-manager export hello --format claude
192
+
193
+ # 导出为 MCP Server
194
+ skills-manager export hello --format mcp --output hello_mcp.py
195
+ ```
196
+
197
+ ### 4. 使用桌面应用
198
+
199
+ ```bash
200
+ python -m desktop.main
201
+ ```
202
+
203
+ 在桌面应用中:
204
+ 1. 浏览已安装的 Skill
205
+ 2. 点击 Skill 查看详情
206
+ 3. 选择格式导出
207
+ 4. 或批量导出多个 Skill
208
+
209
+ ## SKILL.md 格式规范
210
+
211
+ ### Frontmatter(必填)
212
+
213
+ ```yaml
214
+ ---
215
+ name: skill-name # 必填:唯一标识,小写 + 连字符
216
+ version: "1.0.0" # 必填:语义化版本
217
+ description: 一句话描述 # 必填:简短描述(< 200 字)
218
+ summary: | # 必填:2-3 句话摘要
219
+ 详细描述这个 Skill 的功能。
220
+ 支持多行文本。
221
+ ---
222
+ ```
223
+
224
+ ### Frontmatter(可选)
225
+
226
+ ```yaml
227
+ ---
228
+ # 语义类型
229
+ skill_type: component # component | interactive | workflow
230
+ intent: 详细意图说明 # 这个 Skill 要解决什么问题
231
+
232
+ # 分类
233
+ tags: [tag1, tag2] # 自由标签
234
+ category: language # 一级分类标识
235
+
236
+ # 执行配置
237
+ executor:
238
+ type: python # python | node | shell | http
239
+ entry: handler.py # 入口文件
240
+ function: translate # 入口函数名
241
+
242
+ # 安全声明
243
+ security:
244
+ needs_network: true
245
+ needs_api_key: true
246
+
247
+ # 元信息
248
+ author: someone
249
+ license: MIT
250
+ ---
251
+ ```
252
+
253
+ ### Markdown Body
254
+
255
+ ```markdown
256
+ ## 功能
257
+
258
+ 详细描述 Skill 的功能。
259
+
260
+ ## 参数
261
+
262
+ | 参数 | 类型 | 必需 | 说明 |
263
+ |------|------|------|------|
264
+ | param1 | string | ✅ | 参数说明 |
265
+ | param2 | integer | ❌ | 可选参数 |
266
+
267
+ ## 返回
268
+
269
+ | 字段 | 类型 | 说明 |
270
+ |------|------|------|
271
+ | result | string | 返回结果 |
272
+
273
+ ## 示例
274
+
275
+ 输入:
276
+ ```json
277
+ {"param1": "value"}
278
+ ```
279
+
280
+ 输出:
281
+ ```json
282
+ {"result": "processed"}
283
+ ```
284
+
285
+ ## 适用场景
286
+
287
+ - 场景 1
288
+ - 场景 2
289
+
290
+ ## 不适用
291
+
292
+ - 不适用场景 1
293
+ ```
294
+
295
+ ## 支持的导出格式
296
+
297
+ | 格式 | 说明 | 文件扩展名 |
298
+ |------|------|-----------|
299
+ | openai | OpenAI Function Calling | .json |
300
+ | claude | Claude Tool Use | .json |
301
+ | gemini | Gemini Function Declaration | .json |
302
+ | mcp | MCP Server(可运行) | .py |
303
+ | schema | JSON Schema | .json |
304
+
305
+ ## 项目结构
306
+
307
+ ```
308
+ skills-manager-prototype/
309
+ ├── README.md # 本文件
310
+ ├── IMPROVEMENTS.md # 改进计划
311
+ ├── pyproject.toml # 项目配置
312
+ ├── src/skills_manager/ # 核心引擎
313
+ │ ├── __init__.py
314
+ │ ├── ir.py # 中间表示(IR)
315
+ │ ├── parser.py # SKILL.md 解析器
316
+ │ ├── store.py # 本地存储管理
317
+ │ ├── validator.py # 格式验证器
318
+ │ ├── packager.py # 打包器
319
+ │ ├── agent_config.py # Agent 配置生成
320
+ │ ├── cli.py # CLI 入口
321
+ │ └── adapters/ # 格式适配器
322
+ │ ├── base.py # 适配器基类
323
+ │ ├── openai.py # OpenAI 适配器
324
+ │ ├── claude.py # Claude 适配器
325
+ │ ├── gemini.py # Gemini 适配器
326
+ │ ├── mcp.py # MCP 适配器
327
+ │ └── json_schema.py # JSON Schema 适配器
328
+ ├── desktop/ # 桌面客户端(Flet)
329
+ │ ├── main.py # 入口
330
+ │ ├── app.py # 主控类
331
+ │ ├── components.py # 可复用组件
332
+ │ ├── dialogs.py # 对话框
333
+ │ └── pages/ # 页面
334
+ │ ├── browse.py # 浏览页
335
+ │ ├── detail.py # 详情页
336
+ │ ├── export.py # 导出页
337
+ │ ├── editor.py # 编辑器页
338
+ │ └── settings.py # 设置页
339
+ ├── examples/ # 示例 Skills
340
+ │ ├── translator/ # 翻译工具(component)
341
+ │ ├── json-formatter/ # JSON 格式化(component)
342
+ │ ├── code-reviewer/ # 代码审查(component)
343
+ │ ├── interview-prep/ # 面试准备(interactive)
344
+ │ ├── deploy-pipeline/ # 部署流程(workflow)
345
+ │ └── code-generator/ # 代码生成(component)
346
+ └── tests/ # 测试
347
+ ├── test_parser.py
348
+ ├── test_adapters.py
349
+ ├── test_store.py
350
+ ├── test_validator.py
351
+ ├── test_packager.py
352
+ ├── test_agent_config.py
353
+ └── test_cli.py
354
+ ```
355
+
356
+ ## 开发指南
357
+
358
+ ### 运行测试
359
+
360
+ ```bash
361
+ # 运行所有测试
362
+ pytest tests/
363
+
364
+ # 运行特定测试
365
+ pytest tests/test_parser.py -v
366
+
367
+ # 查看覆盖率
368
+ pytest tests/ --cov=skills_manager --cov-report=term-missing
369
+ ```
370
+
371
+ ### 代码质量
372
+
373
+ ```bash
374
+ # 格式化
375
+ ruff format .
376
+
377
+ # 检查
378
+ ruff check .
379
+
380
+ # 类型检查
381
+ mypy src/
382
+ ```
383
+
384
+ ### 添加新适配器
385
+
386
+ 1. 在 `src/skills_manager/adapters/` 创建新文件
387
+ 2. 继承 `BaseAdapter` 类
388
+ 3. 实现 `name`、`file_extension`、`export` 方法
389
+ 4. 在 `__init__.py` 注册适配器
390
+ 5. 添加测试
391
+
392
+ ### 添加新验证规则
393
+
394
+ 1. 在 `src/skills_manager/validator.py` 添加规则
395
+ 2. 返回 `ValidationResult`(errors 或 warnings)
396
+ 3. 添加测试用例
397
+
398
+ ## 文档
399
+
400
+ - [任务书](../task-book.md) — 解决什么问题、做什么不做什么、路线图
401
+ - [技术设计文档](../tech-design.md) — 格式规范、IR、适配器、CLI、存储、实现细节
402
+ - [改进计划](./IMPROVEMENTS.md) — 参考 Product Manager Skills 的改进方向
403
+ - [用户指南](./docs/user-guide.md) — 详细使用说明
404
+
405
+ ## 许可
406
+
407
+ MIT
@@ -0,0 +1,24 @@
1
+ skills_manager/__init__.py,sha256=nhGLnWOM7Z7HmmxkczWrmc3ggyvjKWqZZ3N-dPJAmEI,83
2
+ skills_manager/agent_config.py,sha256=dTO2wXVCMKn8qxej7GCJqKbn7tXreuIsb8TMybdLWdU,1910
3
+ skills_manager/claude_code_checker.py,sha256=MET5z8bLRFdkB8eZzAHFYxMP8ilxbt6L6B8ajL_CfZA,7078
4
+ skills_manager/cli.py,sha256=W8JunTY7MZHaws7M3XyNa4jKC5B5bwh_ws94csFW4ow,13810
5
+ skills_manager/ir.py,sha256=dbG0cV5kKhCF4CE9G4EYQDf9G96dXAtXQiegeK0Rvuw,2004
6
+ skills_manager/logging.py,sha256=jgbvWVHr2ABDbuC73LNUsiF0vXMSU_RUIJ2PxuGUFNA,3449
7
+ skills_manager/packager.py,sha256=gvpbdMA1eCpnDDax-gMRnIv8Rf_9rc__hwWthGaZwT4,6244
8
+ skills_manager/parser.py,sha256=HWtlcTLgtO5KdVzH_sPhq2p5SKoTXS7m6wSEqk3yBk4,9415
9
+ skills_manager/recommend.py,sha256=QQ0I-O8pyXomlmtMftJoquDW-cwDdYt7am5urqehscs,4320
10
+ skills_manager/security.py,sha256=dfhvrHgpHgIK6Dys1RYpxKXGOancH4RjpkGJd_gCPBw,2223
11
+ skills_manager/store.py,sha256=DaRF0T6Bj5iSFKITg4Jy-3EvWL9nRLumy36-fGb-eZg,43216
12
+ skills_manager/validator.py,sha256=9HHhd1TOkTKvT_ycVjkRuMKU0NCmnuBpHnPniQi0Wzs,4770
13
+ skills_manager/adapters/__init__.py,sha256=fNBcFT52Idek9jQ1SZcwkUif1Zpr7A22ewGf2KjRQ3E,518
14
+ skills_manager/adapters/base.py,sha256=CiOwfn-c8i5MxIpqfFkboxLa8f0klAcbGNCKoRq6YWY,2291
15
+ skills_manager/adapters/claude.py,sha256=xgJ8q9-hRrV0_HG-40uaG3WpoMuukHcA9-9bm8zG7Uo,765
16
+ skills_manager/adapters/gemini.py,sha256=fxmQbUvyK_Eb3s7-8QD721MxLQnFDH4ttvKhWjxcHHA,1784
17
+ skills_manager/adapters/json_schema.py,sha256=6PXkOF5lUXYUn_Kx0YfFOBZYeTaG0BdBdC2rejWo0eE,822
18
+ skills_manager/adapters/mcp.py,sha256=exNZ707JzjlsyxI6faAQC5YJbWq4uU4zhmN1XrQr0TE,1717
19
+ skills_manager/adapters/openai.py,sha256=eOodBgYqXQ1NHtwj04Sx83e4enhkux2jWAmwV-1x4Oo,896
20
+ skillfmt-0.1.0.dist-info/METADATA,sha256=LePTqcuiYma7Byz_exnGzbe4IBr-CqLLz7leGH23XtA,11078
21
+ skillfmt-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
22
+ skillfmt-0.1.0.dist-info/entry_points.txt,sha256=OVPC7Bva9eiz9om9CKZLUWuNiBT2Qhus3_68m-ma-Fw,84
23
+ skillfmt-0.1.0.dist-info/licenses/LICENSE,sha256=xD7f3ZoUZ59bb8JFD-Ew4Jcxuj-rcyF8gVLwlBqCPI4,1071
24
+ skillfmt-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ skillfmt = skills_manager.cli:app
3
+ skills = skills_manager.cli:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Skills Manager
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ """Skills Manager - AI Skill 格式转换与管理工具"""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,23 @@
1
+ """适配器模块。
2
+
3
+ 将 SkillIR 转换为各平台的工具定义格式。
4
+ """
5
+
6
+ from .base import Adapter, AdapterError, get_adapter, list_formats
7
+ from .claude import ClaudeAdapter
8
+ from .gemini import GeminiAdapter
9
+ from .json_schema import JsonSchemaAdapter
10
+ from .mcp import MCPAdapter
11
+ from .openai import OpenAIAdapter
12
+
13
+ __all__ = [
14
+ "Adapter",
15
+ "AdapterError",
16
+ "get_adapter",
17
+ "list_formats",
18
+ "OpenAIAdapter",
19
+ "ClaudeAdapter",
20
+ "GeminiAdapter",
21
+ "MCPAdapter",
22
+ "JsonSchemaAdapter",
23
+ ]
@@ -0,0 +1,92 @@
1
+ """适配器基类与注册。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from abc import ABC, abstractmethod
6
+ from typing import TYPE_CHECKING
7
+
8
+ if TYPE_CHECKING:
9
+ from ..ir import SkillIR
10
+
11
+
12
+ class AdapterError(Exception):
13
+ """适配器错误。"""
14
+
15
+
16
+ class Adapter(ABC):
17
+ """所有适配器的基类。"""
18
+
19
+ @property
20
+ @abstractmethod
21
+ def name(self) -> str:
22
+ """适配器名称,如 'openai', 'claude'。"""
23
+ ...
24
+
25
+ @property
26
+ @abstractmethod
27
+ def file_extension(self) -> str:
28
+ """输出文件扩展名,如 '.json', '.py'。"""
29
+ ...
30
+
31
+ @abstractmethod
32
+ def export(self, ir: SkillIR) -> str:
33
+ """将 IR 转换为目标格式的字符串。"""
34
+ ...
35
+
36
+ def export_batch(self, irs: list[SkillIR]) -> str:
37
+ """批量导出多个 IR。"""
38
+ import json
39
+
40
+ results = []
41
+ for ir in irs:
42
+ content = self.export(ir)
43
+ try:
44
+ results.append(json.loads(content))
45
+ except json.JSONDecodeError:
46
+ results.append(content)
47
+ return json.dumps(results, indent=2, ensure_ascii=False)
48
+
49
+
50
+ # 适配器注册表
51
+ _REGISTRY: dict[str, Adapter] = {}
52
+
53
+
54
+ def register(adapter: Adapter) -> None:
55
+ """注册适配器。"""
56
+ _REGISTRY[adapter.name] = adapter
57
+
58
+
59
+ def get_adapter(format_name: str) -> Adapter:
60
+ """获取指定格式的适配器。
61
+
62
+ Raises:
63
+ ValueError: 不支持的格式。
64
+ """
65
+ _ensure_registered()
66
+ if format_name not in _REGISTRY:
67
+ available = ", ".join(sorted(_REGISTRY.keys()))
68
+ raise ValueError(f"Unsupported format: {format_name}. Available: {available}")
69
+ return _REGISTRY[format_name]
70
+
71
+
72
+ def list_formats() -> list[str]:
73
+ """列出所有支持的格式。"""
74
+ _ensure_registered()
75
+ return sorted(_REGISTRY.keys())
76
+
77
+
78
+ def _ensure_registered() -> None:
79
+ """确保所有内置适配器已注册。"""
80
+ if _REGISTRY:
81
+ return
82
+ from .claude import ClaudeAdapter
83
+ from .gemini import GeminiAdapter
84
+ from .json_schema import JsonSchemaAdapter
85
+ from .mcp import MCPAdapter
86
+ from .openai import OpenAIAdapter
87
+
88
+ register(OpenAIAdapter())
89
+ register(ClaudeAdapter())
90
+ register(GeminiAdapter())
91
+ register(MCPAdapter())
92
+ register(JsonSchemaAdapter())
@@ -0,0 +1,33 @@
1
+ """Claude Tool Use 格式适配器。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import TYPE_CHECKING
7
+
8
+ from .base import Adapter
9
+ from ..parser import parameters_to_json_schema
10
+
11
+ if TYPE_CHECKING:
12
+ from ..ir import SkillIR
13
+
14
+
15
+ class ClaudeAdapter(Adapter):
16
+ """Claude Tool Use 格式适配器。"""
17
+
18
+ @property
19
+ def name(self) -> str:
20
+ return "claude"
21
+
22
+ @property
23
+ def file_extension(self) -> str:
24
+ return ".json"
25
+
26
+ def export(self, ir: SkillIR) -> str:
27
+ schema = parameters_to_json_schema(ir.parameters)
28
+ result = {
29
+ "name": ir.name,
30
+ "description": ir.description,
31
+ "input_schema": schema,
32
+ }
33
+ return json.dumps(result, indent=2, ensure_ascii=False)
@@ -0,0 +1,68 @@
1
+ """Gemini Function Declaration 格式适配器。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import TYPE_CHECKING
7
+
8
+ from .base import Adapter
9
+ from ..ir import Parameter
10
+
11
+ if TYPE_CHECKING:
12
+ from ..ir import SkillIR
13
+
14
+
15
+ # JSON Schema 类型 → Gemini 类型
16
+ GEMINI_TYPE_MAP = {
17
+ "string": "STRING",
18
+ "integer": "INTEGER",
19
+ "number": "NUMBER",
20
+ "boolean": "BOOLEAN",
21
+ "array": "ARRAY",
22
+ "object": "OBJECT",
23
+ }
24
+
25
+
26
+ class GeminiAdapter(Adapter):
27
+ """Gemini Function Declaration 格式适配器。"""
28
+
29
+ @property
30
+ def name(self) -> str:
31
+ return "gemini"
32
+
33
+ @property
34
+ def file_extension(self) -> str:
35
+ return ".json"
36
+
37
+ def export(self, ir: SkillIR) -> str:
38
+ params = self._parameters_to_schema(ir.parameters)
39
+ result = {
40
+ "function_declarations": [
41
+ {
42
+ "name": ir.name,
43
+ "description": ir.description,
44
+ "parameters": params,
45
+ }
46
+ ]
47
+ }
48
+ return json.dumps(result, indent=2, ensure_ascii=False)
49
+
50
+ def _parameters_to_schema(self, parameters: list[Parameter]) -> dict:
51
+ """将参数转换为 Gemini 格式的 schema(类型名大写)。"""
52
+ properties = {}
53
+ required = []
54
+
55
+ for p in parameters:
56
+ gemini_type = GEMINI_TYPE_MAP.get(p.type, "STRING")
57
+ prop: dict = {"type": gemini_type, "description": p.description}
58
+ if p.enum:
59
+ prop["enum"] = p.enum
60
+ properties[p.name] = prop
61
+ if p.required:
62
+ required.append(p.name)
63
+
64
+ schema: dict = {"type": "OBJECT", "properties": properties}
65
+ if required:
66
+ schema["required"] = required
67
+
68
+ return schema