lang-migration-samples
lang-migration 的真实案例集,同时保留原始 Python 项目与 AI 迁移后的 Go 实现。

01 / PROJECT OVERVIEW
项目研究解读
lang-migration 的真实案例集,同时保留原始 Python 项目与 AI 迁移后的 Go 实现。 本仓库以 Python 为主要技术栈,当前快照索引 57 个文件。报告依据README 与目录结构整理,重点呈现项目用途、工程结构和复用方式,不把宣传描述等同于验证结论。
02 / CORE CAPABILITIES
值得关注的能力
- 01
围绕“lang-migration 的真实案例集,同时保留原始 Python 项目与 AI 迁移后的 Go 实现”提供公开实现或研究资料
- 02
以 Python 为主,保留 57 个可检查仓库文件
- 03
提供原始 GitHub 链接、目录导览和本地研究快照,便于复核与二次开发
03 / ENGINEERING
工程与仓库结构
仓库以 Python 为主要实现语言,研究快照包含 57 个文件、4 个主要顶层入口。已提供 README 作为使用与能力说明。 项目最近更新时间为 2026-05-22,许可标记为 未在 API 中声明。
项目文件与实现资料
项目文件与实现资料
项目文件与实现资料
构建、采集与自动化脚本
04 / USE CASES
适合用在哪里
- 学习项目设计与实现
- 评估后用于二次开发
- 作为相关领域的研究参考
05 / QUICK START
从仓库开始
以下命令摘自项目 README 或根据仓库地址生成。请先阅读源仓库的安装要求、许可和脚本,再在自己的环境中运行。
Fix: `defer close(streamCh)`. A mock test would have closed the channel itself and never exposed this.
**Bug 2 — Package `init()` panic** (P5 unit tests):
`continue_cmd.go` contained a PCRE lookahead `(?=^===...)` in a package-level `regexp.MustCompile`. Go's RE2 engine doesn't support lookaheads — the program panicked at startup, failing all 13 `chatcommon` tests. Fix: replaced with a line-by-line scanner (behavioral equivalence). This bug passed P4 compilation but was caught by P5 test execution — validating that PGR requires tests to actually run.
### 5. Structural equivalence produced idiomatic Go
The IPO analysis (P3) documented algorithm steps explicitly, which meant the Go translation preserved loop structure and control flow. The result is Go code that reads naturally — not "Python in Go syntax."
Example architectural decisions from IPO analysis:
- `MixinSession` multi-backend failover with `springSec=300` spring-back to primary
- History lives in `backend.history`, not in `messages` slice (mirrors Python design)
- `ToolClient` (text-protocol) vs `NativeToolClient` (native function calling) preserved as separate types
---
## What the Skill Didn't Cover — Honest Limitations
### ML/CV: Ecosystem substitution, not gaps
The three Python ML/CV modules are handled differently — not all are missing:
| Python | Go approach | Result |
|--------|-------------|--------|
06 / REPOSITORY MAP
目录证据导览
这里列出快照中的前 57 个索引文件中的代表路径,帮助你快速定位源码、文档、测试与资源。
.agents/skills/code-to-doc-generator/SKILL.md.agents/skills/code-to-doc-generator/references/analysis-dimensions.md.agents/skills/code-to-doc-generator/references/document-structure.md.agents/skills/code-to-doc-generator/references/document-types.md.agents/skills/code-to-doc-generator/references/exploration-strategy.md.agents/skills/code-to-doc-generator/references/reverse-sync.md.agents/skills/code-to-doc-generator/skill_coverage_map.svg.agents/skills/lang-migration/SKILL.md.agents/skills/lang-migration/references/lang-pairs/TEMPLATE.md.agents/skills/lang-migration/references/lang-pairs/bun-python.md.agents/skills/lang-migration/references/lang-pairs/c-python.md.agents/skills/lang-migration/references/lang-pairs/cpp-python.md.agents/skills/lang-migration/references/lang-pairs/go-python.md.agents/skills/lang-migration/references/lang-pairs/python-bun.md.agents/skills/lang-migration/references/lang-pairs/python-c.md.agents/skills/lang-migration/references/lang-pairs/python-cpp.md.agents/skills/lang-migration/references/lang-pairs/python-go.md.agents/skills/lang-migration/references/lang-pairs/python-rust.md.agents/skills/lang-migration/references/lang-pairs/python-typescript.md.agents/skills/lang-migration/references/lang-pairs/python-zig.md.agents/skills/lang-migration/references/lang-pairs/rust-python.md.agents/skills/lang-migration/references/lang-pairs/typescript-python.md.agents/skills/lang-migration/references/lang-pairs/zig-python.md.agents/skills/lang-migration/references/phase-0-bootstrap.md.agents/skills/lang-migration/references/phase-1-asset-scan.md.agents/skills/lang-migration/references/phase-2-ecosystem-map.md.agents/skills/lang-migration/references/phase-3-ipo-analysis.md.agents/skills/lang-migration/references/phase-4-translation.md.agents/skills/lang-migration/references/phase-5-verification.md.agents/skills/lang-migration/references/phase-6-gap-report.md.agents/skills/lang-migration/references/phase-gate-review.md.agents/skills/lang-migration/references/schemas.md.agents/skills/lang-migration/references/tdd-retrospective.md.agents/skills/lang-migration/scripts/gap_report.py.agents/skills/lang-migration/scripts/scan_assets.py.agents/skills/lang-migration/templates/asset-inventory.yaml.agents/skills/lang-migration/templates/ecosystem-map.yaml.agents/skills/lang-migration/templates/ipo-registry.yaml.agents/skills/lang-migration/templates/migration-state.yaml.agents/skills/lang-migration/templates/retrospective-checklist.yaml.env.gitmodulesREADME.mdREADME_zh.mdmigration_workspace/asset-inventory.yamlmigration_workspace/ecosystem-map.yamlmigration_workspace/gap-report.mdmigration_workspace/gap-report.yamlmigration_workspace/ipo-registry.yamlmigration_workspace/migration-state.yamlscripts/release/generate-release-notes.ps1scripts/release/generate-validation-index.ps1scripts/release/module-buckets.jsonscripts/release/module-buckets.override.example.jsonscripts/release/release-notes-required-sections.jsonscripts/release/validate-module-buckets.ps1scripts/release/validate-release-notes.ps1
07 / SOURCE NOTES
README 原文摘录
保留原始说明便于复核。中文研究结论以当前快照为依据,后续变化请以 GitHub 仓库为准。
lang-migration Skill — Real-World Case Study
This repository is a live demonstration of the lang-migration skill.
It contains both the original Python source project and its complete Go port, produced end-to-end by an AI agent following the skill's six-phase pipeline. Everything in this document is derived from real migration artifacts — no numbers are estimated or fabricated.
中文报告 / Chinese version: README_zh.md
Projects in This Repository
| Directory | Language | Description |
|---|---|---|
[genericagent/](./genericagent/) | Python 3.11 | Source — GenericAgent, a minimal self-evolving autonomous agent framework |
[go-GenericAgent/](./go-GenericAgent/) | Go 1.25 | Target — 1:1 Go port produced by the lang-migration skill |
[migration_workspace/](./migration_workspace/) | YAML | All persistent migration state: inventory, ecosystem map, IPO registry, gap report |
What Is the lang-migration Skill?
The lang-migration skill is an AI-executable workflow for porting an entire open-source project from one programming language to another. It is not a prompt template — it is a structured, multi-session, self-auditing pipeline enforced through five YAML state files and six sequential phases.
P0 Bootstrap → [PGR-0] → P1 Asset Scan → [PGR-1] → P2 Ecosystem Map → [PGR-2]
→ P3 IPO Analysis → [PGR-3] → P4 Translation → [PGR-4] → P5 Verification → [PGR-5]Core design principles:
| Principle | What it prevents |
|---|---|
| No file is useless — every file gets a migration strategy | AI silently skipping inconvenient files |
| Structural equivalence first, behavioral only when forced | AI drifting to "inspired by" rewrites instead of 1:1 ports |
| No mock, ever | Tests that pass by lying |
| Block, don't skip — stop and ask the human on ambiguous decisions | Silent wrong assumptions accumulating into structural debt |
| State persists in YAML across sessions | Losing context between sessions, re-doing work, inconsistency |
| Phase Gate Review (PGR) before every phase transition | AI marking phases DONE without completing the work |
The PGR mechanism is the skill's most distinctive feature: **a phase is not complete when the AI says it is complete; it is only complete when an autonomous audit loop produces zero findings and sets passed_at in the YAML.**
Migration At a Glance
All numbers below come directly from [migration_workspace/migration-state.yaml](./migration_workspace/migration-state.yaml) and [migration_workspace/asset-inventory.yaml](./migration_workspace/asset-inventory.yaml).
Scale
| Metric | Value |
|---|---|
| Source files scanned | 150 |
| Files fully translated | 147 (98%) |
| Files skipped (GAP_ACCEPTED) | 3 |
| Ecosystem symbols mapped | 58 |
| Functions documented (P3 IPO) | 142 |
| Functions translated (P4) | 142 / 142 |
| Verification checks run (P5) | 898 |
| Verification failures | 0 |
go build ./... | ✅ clean |
go vet ./... | ✅ clean |
| Test packages passing | 37 / 37 |
| Overall test coverage | 60.1% |
| Critical bugs found in P5 | 2 (goroutine leak + init() panic) |
Asset Strategy Breakdown (P1)
| Strategy | Count | Meaning |
|---|---|---|
translate | 52 | Full semantic rewrite in Go |
adapt | 15 | Structure changes required (e.g. merged files, path drift) |
direct_use | 57 | Assets copied as-is (config, HTML, images, SOPs) |
reference_only | 26 | Read for context, no output generated |
Ecosystem Mapping (P2)
58 Python ecosystem symbols mapped across three categories:
| Equivalence type | Count | Example |
|---|---|---|
structural | 38 | json → encoding/json, re → regexp |
behavioral | 10 | asyncio → goroutines + channels |
partial | 7 | PIL.Image → github.com/disintegration/imaging |
none (GAP_ACCEPTED) | 1 | streamlit (no Go equivalent; others solved via ecosystem substitution or CGO bridging) |
Note:ultralytics/YOLOis implemented viagithub.com/yalue/onnxruntime_go(CGO);rapidocr-onnxruntimeis replaced by Tesseract. Neither is GAP_ACCEPTED — see Limitations section.
New Go dependencies introduced: 15 packages (see [go-GenericAgent/go.mod](./go-GenericAgent/go.mod)).
On CGO:internal/memory/uidetectcalls the ONNX Runtime shared library viagithub.com/yalue/onnxruntime_go, which requires CGO. The package uses dual build-tag design: default build (go build ./...) compiles to stubs returningErrCGORequired; building with-tags cgolinksonnxruntime.dll/.sofor full YOLO inference. Tests are run asgo test -tags cgo -count=1 ./....
The Migration Process — Session by Session
The migration ran over 7 active sessions, all tracked in YAML state.
| Session | Phase | Key Work |
|---|---|---|
| 1 | P0–P2 | Bootstrap, full asset scan (150 files), complete ecosystem mapping (58 entries) |
| 2 | P3–P4 partial | IPO analysis for 55 core functions; translation of core engine (loop.go, agent.go, llm/ — split into 6 files) |
| 3 | P4 continued | All frontends (Telegram, Discord, DingTalk, WeCom, QQ, Feishu, TUI, ACP bridge), memory subsystems (adbui, procmem, ljqctrl), reflect subsystem, TMWebDriver, simphtml |
| 4 | P4 gap-fill | ga_cli, session compression, vision API, entry-point scripts, config templates |
| 5 | P5 coverage | Integration tests; goroutine leak fix (streamCh never closed); overall coverage 60.1% |
| 6 | P6 audit | End-to-end audit; desktop pet (Win32 UpdateLayeredWindow, per-pixel alpha, CJK bubble text); final asset count 147 |
| 7 | P5 supplement | ga_cli 48.7%→66.4%; qq 52.0%→65.9%; dingtalk 44.3%→50.4%; tmwebdriver 43.7%→48.4% |
What the Skill Got Right
1. The YAML state files actually worked
Every session started by reading migration-state.yaml. No context was re-established manually. The current_task block told the AI exactly where to resume, including blocked items requiring human input. Across 7 active sessions with the same agent (GitHub Copilot), the migration never had to restart.
2. PGR caught real bugs
The Phase Gate Review mechanism caught two categories of real problems:
Path drift — The AI translated files to structurally-better locations than the inventory predicted. Example:
frontends/btw_cmd.py→ inventoried asinternal/frontends/btw/btw.go, actually atinternal/frontends/chatcommon/btw.go(merged with related files)llmcore.py→ inventoried as a single file, actually split into 6 files (client.go,mykey.go,session.go,sse.go,types.go,utils.go) for Go idiom
Anti-cheating mechanism activated — The gap report (migration_workspace/gap-report.yaml) caught that migration-state.yaml claimed 150 assets DONE while asset-inventory.yaml still had 66 entries marked TODO. The PGR forced a full re-audit. This is the "batch fabrication" pattern the skill explicitly guards against.
3. The blocking protocol preserved correctness on ambiguous decisions
Two ecosystem decisions required human approval before proceeding:
- **
streamlit→ no Go equivalent**: Decided to replace with conductor (HTTP + SSE) rather than embed Python. Required explicitGAP_ACCEPTEDsign-off. - **
ultralytics(YOLO) → implemented via ONNX Runtime + CGO**: Initial assessment flagged a behavior gap; human decision approved the ONNX export path (PyTorch model → ONNX →onnxruntime_go+ CGO), preserving full detection capability under-tags cgobuilds.confirmed_by: human.
Both decisions are logged in [migration_workspace/ecosystem-map.yaml](./migration_workspace/ecosystem-map.yaml) with confirmed_by: human.
4. The "no mock" policy found two real production bugs
Bug 1 — Goroutine leak (P5 integration tests):
// internal/agent/agent.go — BEFORE fix
go func() {
// ... LLM streaming loop
// streamCh was NEVER closed → for-select in caller blocked forever after loop ended
}()Fix: defer close(streamCh). A mock test would have closed the channel itself and never exposed this.
**Bug 2 — Package init() panic** (P5 unit tests):
continue_cmd.go contained a PCRE lookahead (?=^===...) in a package-level regexp.MustCompile. Go's RE2 engine doesn't support lookaheads — the program panicked at startup, failing all 13 chatcommon tests. Fix: replaced with a line-by-line scanner (behavioral equivalence). This bug passed P4 compilation but was caught by P5 test execution — validating that PGR requires tests to actually run.
5. Structural equivalence produced idiomatic Go
The IPO analysis (P3) documented algorithm steps explicitly, which meant the Go translation preserved loop structure and control flow. The result is Go code that reads naturally — not "Python in Go syntax."
Example architectural decisions from IPO analysis:
MixinSessionmulti-backend failover withspringSec=300spring-back to primary- History lives in
backend.history, not inmessagesslice (mirrors Python design) ToolClient(text-protocol) vsNativeToolClient(native function calling) preserved as separate types
What the Skill Didn't Cover — Honest Limitations
ML/CV: Ecosystem substitution, not gaps
The three Python ML/CV modules are handled differently — not all are missing:
| Python | Go approach | Result |
|---|---|---|
ultralytics (YOLO) | internal/memory/uidetect — ONNX Runtime via github.com/yalue/onnxruntime_go (CGO) | Full YOLO inference with -tags cgo build; stubs otherwise |
rapidocr-onnxruntime | internal/memory/ocr — Tesseract (tesseract binary + chi_sim+eng) | Functional OCR, different backend, no CGO needed |
streamlit | internal/frontends/conductor — HTTP + SSE | Replaced by custom web frontend; covers core interactive use cases |
True GAP_ACCEPTED items (no implementation):
| Python | Reason | Impact |
|---|---|---|
pywebview | Python-only embedded browser | Launch wrapper skipped; low impact |
PyQt5 / tkinter (Qt frontend) | Python-only GUI | Qt frontend skipped; desktop pet reimplemented via Win32 API |
WeChat personal bot (iLink) | Proprietary Python API, no Go SDK | WeChat frontend deferred |
MINOR_DEVIATION: Two behavioral differences from source
| Feature | Python behavior | Go behavior | Reason |
|---|---|---|---|
| Telegram streaming | Live-edit bot message as chunks arrive | Collect full response, then send in ≤4000-char segments | telebot.v3 has no clean streaming-edit API |
parsePairs log splitting | PCRE lookahead regex | Line-by-line scanner | Go RE2 engine does not support lookaheads |
Both deviations are documented in [go-GenericAgent/MIGRATION_NOTES.md](./go-GenericAgent/MIGRATION_NOTES.md) with justification. Neither affects correctness.
The skill requires sustained human attention
The migration required approximately 7 active sessions of human supervision. While the YAML state files handled continuity, the human had to:
- Approve
GAP_ACCEPTEDdecisions (2 critical ones) - Unblock path-drift discrepancies discovered during PGR
- Review retrospective entries after bug fixes
This is not a "one prompt, done" tool. It is a structured collaboration protocol.
Translated Module Summary
Frontends (internal/frontends/): conductor (HTTP+SSE), telegram, feishu, discord, dingtalk, wecom, qq, tui (bubbletea), chatcommon (4 files merged), acp, desktoppet (Win32 reimplementation), wechat (GAP_ACCEPTED placeholder)
Memory subsystems (internal/memory/): keychain, adbui, procmem (Windows), ljqctrl (Windows), sessions, vision, skillsearch, autonomous, ocr (Tesseract), uidetect (ONN

