AI 项目

lang-migration-samples

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

lang-migration-samples 项目封面或真实界面
Python主要技术栈
1GitHub Stars
0Forks
57索引文件
未声明许可标记
2026-05-22最近更新

01 / PROJECT OVERVIEW

项目研究解读

lang-migration 的真实案例集,同时保留原始 Python 项目与 AI 迁移后的 Go 实现。 本仓库以 Python 为主要技术栈,当前快照索引 57 个文件。报告依据README 与目录结构整理,重点呈现项目用途、工程结构和复用方式,不把宣传描述等同于验证结论。

02 / CORE CAPABILITIES

值得关注的能力

  1. 01

    围绕“lang-migration 的真实案例集,同时保留原始 Python 项目与 AI 迁移后的 Go 实现”提供公开实现或研究资料

  2. 02

    以 Python 为主,保留 57 个可检查仓库文件

  3. 03

    提供原始 GitHub 链接、目录导览和本地研究快照,便于复核与二次开发

03 / ENGINEERING

工程与仓库结构

仓库以 Python 为主要实现语言,研究快照包含 57 个文件、4 个主要顶层入口。已提供 README 作为使用与能力说明。 项目最近更新时间为 2026-05-22,许可标记为 未在 API 中声明。

01README.md

项目文件与实现资料

02README_zh.md

项目文件与实现资料

03migration_workspace

项目文件与实现资料

04scripts

构建、采集与自动化脚本

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
  • .gitmodules
  • README.md
  • README_zh.md
  • migration_workspace/asset-inventory.yaml
  • migration_workspace/ecosystem-map.yaml
  • migration_workspace/gap-report.md
  • migration_workspace/gap-report.yaml
  • migration_workspace/ipo-registry.yaml
  • migration_workspace/migration-state.yaml
  • scripts/release/generate-release-notes.ps1
  • scripts/release/generate-validation-index.ps1
  • scripts/release/module-buckets.json
  • scripts/release/module-buckets.override.example.json
  • scripts/release/release-notes-required-sections.json
  • scripts/release/validate-module-buckets.ps1
  • scripts/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

DirectoryLanguageDescription
[genericagent/](./genericagent/)Python 3.11Source — GenericAgent, a minimal self-evolving autonomous agent framework
[go-GenericAgent/](./go-GenericAgent/)Go 1.25Target — 1:1 Go port produced by the lang-migration skill
[migration_workspace/](./migration_workspace/)YAMLAll 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:

PrincipleWhat it prevents
No file is useless — every file gets a migration strategyAI silently skipping inconvenient files
Structural equivalence first, behavioral only when forcedAI drifting to "inspired by" rewrites instead of 1:1 ports
No mock, everTests that pass by lying
Block, don't skip — stop and ask the human on ambiguous decisionsSilent wrong assumptions accumulating into structural debt
State persists in YAML across sessionsLosing context between sessions, re-doing work, inconsistency
Phase Gate Review (PGR) before every phase transitionAI 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
MetricValue
Source files scanned150
Files fully translated147 (98%)
Files skipped (GAP_ACCEPTED)3
Ecosystem symbols mapped58
Functions documented (P3 IPO)142
Functions translated (P4)142 / 142
Verification checks run (P5)898
Verification failures0
go build ./...✅ clean
go vet ./...✅ clean
Test packages passing37 / 37
Overall test coverage60.1%
Critical bugs found in P52 (goroutine leak + init() panic)
Asset Strategy Breakdown (P1)
StrategyCountMeaning
translate52Full semantic rewrite in Go
adapt15Structure changes required (e.g. merged files, path drift)
direct_use57Assets copied as-is (config, HTML, images, SOPs)
reference_only26Read for context, no output generated
Ecosystem Mapping (P2)

58 Python ecosystem symbols mapped across three categories:

Equivalence typeCountExample
structural38json → encoding/json, re → regexp
behavioral10asyncio → goroutines + channels
partial7PIL.Image → github.com/disintegration/imaging
none (GAP_ACCEPTED)1streamlit (no Go equivalent; others solved via ecosystem substitution or CGO bridging)
Note: ultralytics/YOLO is implemented via github.com/yalue/onnxruntime_go (CGO); rapidocr-onnxruntime is 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/uidetect calls the ONNX Runtime shared library via github.com/yalue/onnxruntime_go, which requires CGO. The package uses dual build-tag design: default build (go build ./...) compiles to stubs returning ErrCGORequired; building with -tags cgo links onnxruntime.dll/.so for full YOLO inference. Tests are run as go test -tags cgo -count=1 ./....

The Migration Process — Session by Session

The migration ran over 7 active sessions, all tracked in YAML state.

SessionPhaseKey Work
1P0–P2Bootstrap, full asset scan (150 files), complete ecosystem mapping (58 entries)
2P3–P4 partialIPO analysis for 55 core functions; translation of core engine (loop.go, agent.go, llm/ — split into 6 files)
3P4 continuedAll frontends (Telegram, Discord, DingTalk, WeCom, QQ, Feishu, TUI, ACP bridge), memory subsystems (adbui, procmem, ljqctrl), reflect subsystem, TMWebDriver, simphtml
4P4 gap-fillga_cli, session compression, vision API, entry-point scripts, config templates
5P5 coverageIntegration tests; goroutine leak fix (streamCh never closed); overall coverage 60.1%
6P6 auditEnd-to-end audit; desktop pet (Win32 UpdateLayeredWindow, per-pixel alpha, CJK bubble text); final asset count 147
7P5 supplementga_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 as internal/frontends/btw/btw.go, actually at internal/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 explicit GAP_ACCEPTED sign-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 cgo builds. 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:

  • 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:

PythonGo approachResult
ultralytics (YOLO)internal/memory/uidetect — ONNX Runtime via github.com/yalue/onnxruntime_go (CGO)Full YOLO inference with -tags cgo build; stubs otherwise
rapidocr-onnxruntimeinternal/memory/ocr — Tesseract (tesseract binary + chi_sim+eng)Functional OCR, different backend, no CGO needed
streamlitinternal/frontends/conductor — HTTP + SSEReplaced by custom web frontend; covers core interactive use cases

True GAP_ACCEPTED items (no implementation):

PythonReasonImpact
pywebviewPython-only embedded browserLaunch wrapper skipped; low impact
PyQt5 / tkinter (Qt frontend)Python-only GUIQt frontend skipped; desktop pet reimplemented via Win32 API
WeChat personal bot (iLink)Proprietary Python API, no Go SDKWeChat frontend deferred
MINOR_DEVIATION: Two behavioral differences from source
FeaturePython behaviorGo behaviorReason
Telegram streamingLive-edit bot message as chunks arriveCollect full response, then send in ≤4000-char segmentstelebot.v3 has no clean streaming-edit API
parsePairs log splittingPCRE lookahead regexLine-by-line scannerGo 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_ACCEPTED decisions (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