mcpField
R
repo

repo

github.com/johnlindquist开发2638 次安装45 周前更新
代码仓库

关于 repo

repo 是面向开发者和编码 Agent 的代码库分析技能,可梳理项目结构并为 AI 工作整理上下文。它涵盖代码与导出项索引、依赖分析,以及上下文包和文档生成脚本。

主要功能

  1. 01检查代码库结构
  2. 02生成代码与导出项索引
  3. 03分析导入和依赖关系
  4. 04生成 AI 上下文包
  5. 05辅助编写 README 和 API 文档

适用场景

  1. 01帮助 Agent 熟悉陌生代码库
  2. 02整理关键文件供 AI 分析
  3. 03检查内部及外部依赖
  4. 04起草项目与 API 文档

安装

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

$npx skills add https://github.com/johnlindquist/claude --skill repo

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

详细介绍

仓库上下文

为代码库生成上下文包和映射。

结构分析

快速结构
# Tree view (basic)
tree -L 2 -I 'node_modules|.git|dist|build'

# With file counts
tree -L 2 -I 'node_modules|.git' --dirsfirst -C

# Just directories
tree -d -L 3 -I 'node_modules|.git'
详细结构
#!/bin/bash
# repo-structure.sh

echo "# Repository Structure"
echo ""
echo "## Root Files"
ls -la | grep "^-" | awk '{print "- " $NF}'

echo ""
echo "## Directories"
for dir in */; do
  if [[ "$dir" != "node_modules/" && "$dir" != ".git/" ]]; then
    echo "### $dir"
    ls -la "$dir" | head -10
    echo ""
  fi
done

代码映射

生成代码映射
#!/bin/bash
# codemap.sh - Generate code map

echo "# Code Map"
echo ""

# Find all source files
find src -name "*.ts" -o -name "*.tsx" | while read file; do
  echo "## $file"
  echo '```typescript'

  # Extract exports
  grep -E "^export (function|const|class|interface|type)" "$file" | head -20

  echo '```'
  echo ""
done
函数索引
# List all exported functions
grep -rh "^export function" src/ | sort

# With file locations
grep -rn "^export function" src/ | sort
类索引
# List all classes
grep -rn "^export class" src/ | sort

# With methods
grep -rh "^export class\|^\s*\(async \)\?[a-z]\+(" src/ | head -50

上下文包

为 AI 创建上下文包
#!/bin/bash
# bundle-context.sh - Create context for AI

OUTPUT="CONTEXT.md"

cat > $OUTPUT << 'EOF'
# Repository Context

## Project Overview
EOF

# Add package.json summary
if [ -f package.json ]; then
  echo '```json' >> $OUTPUT
  jq '{name, description, main, scripts: .scripts | keys}' package.json >> $OUTPUT
  echo '```' >> $OUTPUT
fi

# Add key files
echo "" >> $OUTPUT
echo "## Key Files" >> $OUTPUT

for file in src/index.ts src/main.ts app.ts; do
  if [ -f "$file" ]; then
    echo "" >> $OUTPUT
    echo "### $file" >> $OUTPUT
    echo '```typescript' >> $OUTPUT
    head -100 "$file" >> $OUTPUT
    echo '```' >> $OUTPUT
  fi
done

echo "Context bundle created: $OUTPUT"
智能打包(仅关键文件)
#!/bin/bash
# smart-pack.sh - Pack only important files

# Identify key files
KEY_PATTERNS=(
  "package.json"
  "tsconfig.json"
  "src/index.ts"
  "src/main.ts"
  "README.md"
)

for pattern in "${KEY_PATTERNS[@]}"; do
  if [ -f "$pattern" ]; then
    echo "=== $pattern ==="
    cat "$pattern"
    echo ""
  fi
done

导入分析

依赖图
# Find what imports what
grep -rh "^import.*from" src/ | \
  sed "s/.*from ['\"]//; s/['\"].*//" | \
  sort | uniq -c | sort -rn | head -20
外部依赖
# Most used external packages
grep -rh "^import.*from ['\"]" src/ | \
  grep -v "from ['\"]\./" | \
  sed "s/.*from ['\"]//; s/['\"].*//" | \
  sort | uniq -c | sort -rn
内部模块图
# Internal imports
grep -rh "^import.*from ['\"]\./" src/ | \
  sed "s/.*from ['\"]//; s/['\"].*//" | \
  sort | uniq -c | sort -rn

AI 驱动的分析

架构摘要
STRUCTURE=$(tree -L 2 -I 'node_modules|.git' --dirsfirst)
PACKAGE=$(cat package.json 2>/dev/null)

gemini -m pro -o text -e "" "Analyze this repository structure:

Structure:
$STRUCTURE

package.json:
$PACKAGE

Provide:
1. Architecture pattern used
2. Main entry points
3. Key modules and their purpose
4. Dependencies overview
5. Suggested improvements"
代码质量概览
# Get sample of files
SAMPLES=$(find src -name "*.ts" | head -5 | xargs cat)

gemini -m pro -o text -e "" "Review code quality:

$SAMPLES

Assess:
1. Code organization
2. Naming conventions
3. Error handling
4. Type safety
5. Suggestions"

文档生成

自动生成 README
gemini -m pro -o text -e "" "Generate a README for this project:

package.json:
$(cat package.json)

Main file:
$(cat src/index.ts | head -100)

Include:
- Description
- Installation
- Usage
- API overview
- Contributing"
API 文档
# Extract all exports
EXPORTS=$(grep -rh "^export" src/ | head -50)

gemini -m pro -o text -e "" "Generate API documentation for:

$EXPORTS

Format as markdown with:
- Function signatures
- Parameter descriptions
- Return types
- Example usage"

最佳实践

  1. 忽略噪音 - 排除 node_modules、.git、build
  2. 关注入口点 - 从主文件开始
  3. 跟踪依赖 - 了解导入了什么
  4. 使用 AI 生成摘要 - 大型代码库需要综合归纳
  5. 保持上下文包更新 - 在重大变更后重新生成
  6. 分享上下文 - 帮助他人快速理解

评论

支持 Markdown