xiaohongshu
xiaohongshu
go-module-renamer
Go 模块重命名自动化工具。用于新 git clone 的项目进行 Go 模块重命名,支持全量/部分重命名智能识别,文本替换优先策略,完善的验证和回滚机制。
Full skill instructions
自动化 Go 项目模块重命名,支持智能识别重命名类型(全量/部分),使用文本替换策略快速更新模块引用,提供浅层和深层双重验证,确保重命名安全可靠。
对于全新克隆的项目:
# 1. 检测当前模块名
.claude/skills/go-module-renamer/scripts/detect_module.sh
# 2. 分析重命名类型
python3 .claude/skills/go-module-renamer/scripts/analyze_rename_type.py \
<旧模块名> <新模块名>
# 3. 执行重命名
python3 .claude/skills/go-module-renamer/scripts/perform_rename.py \
<旧模块名> <新模块名>
# 4. 浅层验证
.claude/skills/go-module-renamer/scripts/validate_quick.sh
# 5. 深层验证
python3 .claude/skills/go-module-renamer/scripts/validate_deep.py <旧模块名>
在实际重命名前先查看影响范围:
python3 .claude/skills/go-module-renamer/scripts/perform_rename.py \
<旧模块名> <新模块名> --dry-run
适用情况:域名或用户名变更
github.com/fsyyft-go/kratos-layout → github.com/new-org/new-project
工作流程:
开始
↓
1. 检测当前模块名
[detect_module.sh]
输出:模块名结构(域名、用户名、项目名)
↓
2. 分析重命名类型
[analyze_rename_type.py]
判断:全量重命名(前两部分不同)
↓
3. 执行重命名
[perform_rename.py]
├─ 创建备份(.backup/)
├─ 替换完整模块路径
│ ├─ go.mod 模块声明
│ ├─ .go 文件导入路径
│ ├─ .proto 文件 go_package
│ └─ 文档中的代码示例
├─ 替换项目名
│ ├─ Makefile 变量
│ ├─ 配置文件
│ └─ 文档标题
└─ 清理模板注释
↓
4. 浅层验证
[validate_quick.sh]
├─ go fmt
├─ go mod tidy
├─ make lint
└─ make build
↓
5. 深层验证
[validate_deep.py]
├─ 搜索代码文件残留
├─ 检查配置文件
└─ 审查文档引用
↓
完成
适用情况:仅项目名变更
github.com/fsyyft-go/kratos-layout → github.com/fsyyft-go/new-project
工作流程:
开始
↓
1. 检测当前模块名
[detect_module.sh]
↓
2. 分析重命名类型
[analyze_rename_type.py]
判断:部分重命名(仅最后部分不同)
↓
3. 执行重命名
[perform_rename.py]
├─ 创建备份(.backup/)
└─ 替换项目名
├─ Makefile 变量
├─ Docker 镜像名
├─ 配置文件
└─ 文档标题
↓
4. 验证(同上)
↓
完成
功能:
用法:
.claude/skills/go-module-renamer/scripts/detect_module.sh
输出示例:
{
"full_path": "github.com/fsyyft-go/kratos-layout",
"domain": "github.com",
"username": "fsyyft-go",
"project": "kratos-layout"
}
返回值:
0 - 成功1 - go.mod 不存在2 - 无法解析模块名自动化程度:100% 脚本自动化,无需大模型介入
功能:
用法:
python3 .claude/skills/go-module-renamer/scripts/analyze_rename_type.py \
<旧模块名> <新模块名>
示例:
python3 .claude/skills/go-module-renamer/scripts/analyze_rename_type.py \
github.com/fsyyft-go/kratos-layout \
github.com/new-org/new-project
输出示例:
{
"type": "full",
"old_module": "github.com/fsyyft-go/kratos-layout",
"new_module": "github.com/new-org/new-project",
"old_project": "kratos-layout",
"new_project": "new-project",
"replacements": {
"full_replace": [...],
"partial_replace": [...]
}
}
自动化程度:100% 脚本自动化,无需大模型介入
功能:
用法:
# 基本用法
python3 .claude/skills/go-module-renamer/scripts/perform_rename.py \
<旧模块名> <新模块名>
# 指定重命名类型
python3 .claude/skills/go-module-renamer/scripts/perform_rename.py \
<旧模块名> <新模块名> --type=full
# 试运行模式(不实际修改文件)
python3 .claude/skills/go-module-renamer/scripts/perform_rename.py \
<旧模块名> <新模块名> --dry-run
参数说明:
old_module - 旧模块名(必需)new_module - 新模块名(必需)--type - 重命名类型:auto(默认)、full、partial--dry-run - 试运行模式,不实际修改文件Python 环境管理:
.venv 虚拟环境自动化程度:
功能:
用法:
# 完整验证
.claude/skills/go-module-renamer/scripts/validate_quick.sh
# 跳过 lint 检查
.claude/skills/go-module-renamer/scripts/validate_quick.sh --skip-lint
# 跳过编译验证
.claude/skills/go-module-renamer/scripts/validate_quick.sh --skip-build
验证命令序列:
go fmt ./... - 代码格式化go mod tidy - 依赖管理make lint - Lint 检查(可选)make build - 编译验证(可选)输出示例:
======================================
步骤 1: 代码格式化 (go fmt)
======================================
✓ 通过: 代码格式化完成
======================================
步骤 2: 依赖管理 (go mod tidy)
======================================
✓ 通过: 依赖管理完成
...
======================================
验证总结
======================================
总步骤数: 4
通过: 4
失败: 0
✅ 浅层验证全部通过!
返回值:
0 - 全部通过1 - 有失败自动化程度:100% 脚本自动化,无需大模型介入
功能:
用法:
# 基本用法
python3 .claude/skills/go-module-renamer/scripts/validate_deep.py <旧模块名>
# 指定旧项目名
python3 .claude/skills/go-module-renamer/scripts/validate_deep.py \
<旧模块名> --old-project=<旧项目名>
分类规则:
| 文件类型 | 残留引用处理 | 理由 |
|---|---|---|
| .go、.proto | ❌ 报告错误 | 代码文件不应该有残留 |
| Makefile、config.yaml | ⚠️ 警告 | 可能需要手动检查 |
| README.md | ✅ 自动替换 | 明显的文档引用 |
| .github/*.md | ✅ 自动替换 | GitHub 文档 |
| 注释、文档 | ℹ️ 信息提示 | 可能是历史说明 |
输出示例:
🔍 深层验证:搜索残留引用
搜索模式:
- github.com/fsyyft-go/kratos-layout
- kratos-layout
📂 搜索代码文件...
📂 搜索配置文件...
📂 搜索文档文件...
==================================================
📊 深层验证结果
==================================================
❌ 代码文件中的残留(2 个文件):
- internal/server/server.go
行 10: import "github.com/fsyyft-go/kratos-layout/internal/conf"
- api/helloworld/v1/greeter.proto
行 5: option go_package = "github.com/fsyyft-go/kratos-layout/api"
⚠️ 配置文件中的残留(1 个文件):
- Makefile
行 5: IMAGE_NAME := fsyyft/kratos-layout
ℹ️ 文档文件中的残留(3 个文件):
- README.md
- docs/api.md
- .github/CONTRIBUTING.md
返回值:
0 - 无残留或仅有文档残留1 - 代码文件中有残留2 - 配置文件中有残留自动化程度:
目标:快速发现明显的编译和语法错误
时间:1-3 分钟
验证内容:
通过标准:
目标:发现所有残留的旧模块名引用
时间:3-5 分钟
验证内容:
通过标准:
症状:
cannot find package "github.com/old/module/path"
解决方案:
go mod tidy症状: 深层验证发现代码文件中有残留引用
解决方案:
示例:
grep -rn "旧模块名" --include="*.go" .
sed -i '' 's|旧模块名|新模块名|g' file.go
判断依据:
回滚方法:
# 自动回滚(使用备份)
cp -r .backup/* .
# 或使用 Git
git checkout .
症状:
ModuleNotFoundError: No module named 'yaml'
解决方案:
pip install pyyaml触发条件:
回滚步骤:
备份代码
通知团队
准备环境
规划验证
使用试运行模式
--dry-run 查看影响范围创建备份
.backup 目录分步执行
验证结果
提交更改
更新文档
通知相关人员
总体自动化程度:80% 脚本 + 20% 大模型辅助
| 介入点 | 触发条件 | 大模型职责 | 介入程度 |
|---|---|---|---|
| Python 环境检测 | 脚本启动时 | 检查虚拟环境,决定是否创建 | 10% |
| 类型分析确认 | 分析完成 | 显示结果,让用户确认 | 5% |
| 未知文件类型 | 遇到新类型文件 | 判断如何处理 | 5% |
| 特殊情况处理 | 发现复杂情况 | 提供处理建议 | 10% |
| 文档引用分析 | 深层验证 | 判断是否需要更新 | 20% |
| 验证失败诊断 | lint/build 失败 | 分析错误,提供解决方案 | 30% |
| 用户指导 | 用户询问 | 解释操作,提供后续步骤 | 按需 |
包含 5 个可执行脚本:
所有脚本:
包含详细的参考资料:
file_patterns.md
validation_rules.md
包含报告模板和示例文件(待补充)。
# 克隆项目
git clone https://github.com/fsyyft-go/kratos-layout.git my-project
cd my-project
# 1. 检测当前模块名
.claude/skills/go-module-renamer/scripts/detect_module.sh
# 输出:github.com/fsyyft-go/kratos-layout
# 2. 试运行查看影响
python3 .claude/skills/go-module-renamer/scripts/perform_rename.py \
github.com/fsyyft-go/kratos-layout \
github.com/myorg/my-project \
--dry-run
# 3. 执行重命名
python3 .claude/skills/go-module-renamer/scripts/perform_rename.py \
github.com/fsyyft-go/kratos-layout \
github.com/myorg/my-project
# 4. 验证
.claude/skills/go-module-renamer/scripts/validate_quick.sh
python3 .claude/skills/go-module-renamer/scripts/validate_deep.py \
github.com/fsyyft-go/kratos-layout
# 5. 提交
git add .
git commit -m "feat: 重命名模块为 github.com/myorg/my-project"
当 validate_deep.py 发现代码文件中有残留时:
$ python3 validate_deep.py github.com/fsyyft-go/kratos-layout
❌ 代码文件中的残留(1 个文件):
- internal/server/server.go
行 15: import "github.com/fsyyft-go/kratos-layout/internal/conf"
⚠️ 发现代码文件中的残留引用,这可能导致编译或运行时错误。
建议:手动检查并修复这些文件
修复方法:
# 方法 1:使用 sed
sed -i '' 's|github.com/fsyyft-go/kratos-layout|github.com/myorg/my-project|g' \
internal/server/server.go
# 方法 2:使用编辑器批量替换
# 在 VSCode 中:Cmd+Shift+H,查找旧模块名,替换为新模块名
# 方法 3:重新运行 perform_rename.py
python3 .claude/skills/go-module-renamer/scripts/perform_rename.py \
github.com/fsyyft-go/kratos-layout \
github.com/myorg/my-project
当 validate_quick.sh 执行失败时:
$ validate_quick.sh
======================================
步骤 3: Lint 检查 (make lint)
======================================
✗ 失败: Lint 检查失败
level=error msg="internal/server/server.go:15:2: import shadowing: \
conf \"github.com/myorg/my-project/internal/conf\""
大模型分析:
// 修复前
import "github.com/myorg/my-project/internal/conf"
// 修复后(使用别名)
import serverconf "github.com/myorg/my-project/internal/conf"
.backup/ 在项目根目录Git 远程仓库
依赖包
CI/CD
文档
团队协作
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience