Lilian-nan/repo2skill

GitHub: Lilian-nan/repo2skill

一款将 GitHub 仓库转换为 Anthropic skill 的安全优先流水线,内置安全审计在转换前拦截提示词注入和供应链攻击。

Stars: 1 | Forks: 0

# Repo2Skill 将不受信任的 GitHub 仓库转换为兼容 Anthropic 的 skill,但前提是它必须通过安全审计。 [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/f3ac6409bf034617.svg)](https://github.com/Lilian-nan/repo2skill/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](./LICENSE) [![Python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/) ## 为什么开发此工具 大多数“repo to skill”工作流过早信任源仓库。这对 AI agent 来说是一个糟糕的默认设置,因为设置文档、安装钩子、工作流文件和 AI 指令文件都可能携带提示词注入 (prompt-injection) 或供应链攻击载荷。 `repo2skill` 颠倒了顺序: 1. 先审计 2. 仅在安全时进行分析 3. 生成具有渐进式披露 (progressive disclosure) 的简洁 skill 4. 将其打包为 `.skill` 归档文件 ## 有何不同 | 典型的 repo-to-skill 工具 | `repo2skill` | | --- | --- | | 读取 README 并开始生成 | 在打包前审计高风险文件 | | 将仓库指令视为受信任的上下文 | 将上游 AI 指令视为不受信任的输入 | | 将所有内容转储到一个大提示词中 | 保持 `SKILL.md` 简短,并将细节推入 `references/` | | 专注于顺利路径的转换 | 默认在遇到 `CRITICAL` 和 `HIGH` 级别发现时阻止 | ## 流水线 ``` flowchart LR repo["Repository URL or local path"] --> audit["Security audit"] audit -->|"clean or reviewed"| analyze["Repository analysis"] audit -->|"critical or high risk"| stop["Stop and report findings"] analyze --> generate["Generate SKILL.md + references"] generate --> package["Package .skill archive"] ``` ## 30 秒演示 ``` python3 scripts/repo2skill.py https://github.com/owner/repo --output-dir dist ``` 成功输出: ``` Source: https://github.com/owner/repo Commit: 0123456789abcdef Max severity: NONE Files scanned: 18 Skill directory: /path/to/dist/repo Skill archive: /path/to/dist/repo.skill ``` 针对恶意仓库的阻止输出: ``` # 安全审计报告 ## 概要 - CRITICAL: 1 finding ### [CRITICAL] 恶意 npm 生命周期钩子 - Location: package.json:4 ``` ## 安装要求 - Python 3.9+ - `git` 不需要第三方 Python 依赖。 ## 使用方法 从 GitHub 生成: ``` python3 scripts/repo2skill.py https://github.com/owner/repo --output-dir dist ``` 从本地检出的仓库生成: ``` python3 scripts/repo2skill.py /path/to/local/repo --output-dir dist ``` 机器可读输出: ``` python3 scripts/repo2skill.py SOURCE --output-dir dist --json ``` 显式指定 monorepo 子目录: ``` python3 scripts/repo2skill.py SOURCE --subdir apps/web --output-dir dist ``` 仅在您有意想要报告和生成输出时覆盖安全停止: ``` python3 scripts/repo2skill.py SOURCE --output-dir dist --allow-risky ``` 在具有文件感知规则的情况下对 stdin 运行原始审计器: ``` python3 scripts/audit_github.py --stdin --filename package.json --json < package.json ``` ## 生成输出 ``` dist// ├── SKILL.md └── references/ ├── commands.md ├── overview.md ├── security-audit.md └── setup.md dist/.skill ``` 生成的 `SKILL.md` 形状示例: ``` --- name: demo-tool description: > Use when the user needs help working with Demo Tool. --- # Demo Tool Short purpose summary. ## Workflow 1. Start with `references/overview.md` 2. Open `references/setup.md` for prerequisites 3. Open `references/commands.md` for install and run commands 4. Open `references/security-audit.md` for provenance ``` ## 仓库布局 - `SKILL.md`:agent 运行时使用的 skill 入口点 - `scripts/audit_github.py`:无依赖的安全扫描器 - `scripts/repo2skill.py`:转换流水线 - `references/`:转换规则和渐进式披露指导 - `tests/`:回归测试和固件 - `assets/social-preview.png`:适用于 GitHub 的社交预览图 - `agents/openai.yaml`:用于 skill 注册中心的 UI 元数据 ## 本地验证 ``` python3 -m py_compile scripts/audit_github.py scripts/repo2skill.py python3 -m unittest discover -s tests -p 'test_*.py' -v ``` ## 路线图 - 更强大的 monorepo 包选择 - 跨更多生态系统的更好命令提取 - 更丰富的发布产物和生成示例 ## 许可证 MIT
标签:Anthropic, CIS基准, DevSecOps, DLL 劫持, DNS 反向解析, GitHub集成, LLM应用开发, Python, Skill封装, 上游代理, 云安全监控, 人工智能安全, 合规性, 大语言模型, 文档安全, 无后门, 服务器监控, 网络安全研究, 软件开发工具包, 静态分析