mcpField
G
ghost-repo-context

ghost-repo-context

github.com/ghostsecurity开发4273.9k 次安装4 周前更新
代码仓库

关于 ghost-repo-context

ghost-repo-context 是一项仓库分析技能,用于检测项目、概述架构,并将结果写入 repo.md。它只使用仓库本地文件,并可复用已有的缓存上下文。

主要功能

  1. 01检测仓库中的项目
  2. 02概述各项目架构
  3. 03记录检测与摘要字段
  4. 04仅使用本地文件,不访问网页
  5. 05检查并复用已有上下文

适用场景

  1. 01在审查仓库前建立上下文
  2. 02记录检测到的项目和组件
  3. 03repo.md 已存在时避免重复分析

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ghostsecurity/skills --skill ghost-repo-context

安装后在 Claude Code 中输入/ghost-repo-context确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

detector.md
summarizer.md
template-repo.md

详细介绍

仓库上下文构建器

通过检测项目、总结其架构并将结果写入 repo.md,收集仓库上下文。所有工作都由你自行完成——不要启动子 Agent,也不要委派任务。

输入

从 $ARGUMENTS 中解析以下内容(key=value 键值对):

  • repo_path:仓库根目录的路径
  • cache_dir:缓存目录的路径(默认为 ~/.ghost/repos/<repo_id>/cache)

$ARGUMENTS

如果未提供 cache_dir,请计算其路径:

repo_name=$(basename "$(pwd)") && remote_url=$(git remote get-url origin 2>/dev/null || pwd) && short_hash=$(printf '%s' "$remote_url" | git hash-object --stdin | cut -c1-8) && repo_id="${repo_name}-${short_hash}" && cache_dir="$HOME/.ghost/repos/${repo_id}/cache" && echo "cache_dir=$cache_dir"

工具限制

不得使用 WebFetch 或 WebSearch。所有工作只能使用仓库中的本地文件。

设置

查找此技能自身所在的目录,以便引用 Agent 文件:

skill_dir=$(find . -path '*/skills/repo-context/SKILL.md' 2>/dev/null | head -1 | xargs dirname)
echo "skill_dir=$skill_dir"

首先检查缓存

检查 <cache_dir>/repo.md 是否已存在。如果存在,跳过所有步骤并返回:

Repository context is at: <cache_dir>/repo.md

如果不存在,则运行 mkdir -p <cache_dir> 并继续。


工作流程

  1. 检测项目 — 阅读 <skill_dir>/detector.md,并按照其中的说明检查 <repo_path>。保存完整的检测输出(步骤 2 所需的项目详情)。如果未检测到项目,则写入一个简短的 repo.md,注明“No projects detected”,然后跳到步骤 4。

  2. 总结每个项目 — 阅读 <skill_dir>/summarizer.md。对于步骤 1 中检测到的每个项目,使用该项目的详情(id、type、base_path、languages、frameworks、dependency_files、extensions、evidence),按照 summarizer 中的说明进行操作。收集每个项目的总结。如果某个项目的总结失败,将其标记为“summary unavailable”,然后继续处理其余项目。

  3. 写入 repo.md — 按照 <skill_dir>/template-repo.md 中的格式,将检测结果和总结合并写入 <cache_dir>/repo.md。每个项目都应包含:

    • 检测:ID、类型、基础路径、语言、框架、依赖文件、扩展名、证据
    • 总结:架构总结、敏感数据类型、业务关键性、组件映射、证据
  4. 验证 — 重新读取 <cache_dir>/repo.md,并验证其中包含 <skill_dir>/template-repo.md 中预期的各部分(例如,包含检测和总结字段的项目条目)。如果文件缺失或格式错误,则重试写入一次,然后再报告错误。

  5. 输出 — 返回:Repository context is at: <cache_dir>/repo.md

评论

支持 Markdown