logic-diff
它能做什么
用来比较两个版本的代码,看它们做的事情是否一样。它会一步一步地分析代码,找出行为上的重要差异。
适用场景
- ✓当你重构代码,想确认没有出现问题时。
- ✓当你把代码迁移到新版本,想检查结果是否一致时。
- ✓当你测试了两种不同的实现(A/B)后,想知道它们的功能是否完全相同时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/logic-diff/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请比较这两个版本的代码,看看它们的行为是否还是一样的。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会把两个版本的代码放在一起分析,逐步跟踪每个版本的执行过程。它会记录两者的执行路径或结果从哪里开始不一样。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Logic-Lens — Semantic Diff
When to Use
Use this skill when you need compare two code versions for semantic equivalence via semi-formal tracing of both versions side-by-side. Trigger when the user shares a refactor, rewrite, migration, or A/B implementation and wants to confirm behavior is unchanged — "did I break anything", "is this equivalent", "are...
Setup
Use lazy loading per ../_shared/common.md §13:
- Read
../_shared/common.mdonly for language, Iron Law, Verdict header, scope routing, Remedy discipline, config fields, and loading budget. - Read only the relevant step in
logic-diff-guide.mdas you reach it. - Load
../_shared/logic-risks.md,../_shared/semiformal-guide.md,../_shared/semiformal-checklist.md, and../_shared/report-template.mdon demand when the current step needs them.
Process
Step 0. Language + scope routing. Detect language per common.md §1. Confirm two versions are provided. If only one version, switch to logic-review.
Step 1. Identify the shared specification (guide Step 1) — what inputs should both versions handle; what outputs/side effects are expected. If the user states the refactor intentionally changed behavior in a specific area (e.g., "I changed the error path to raise instead of returning None"), record that as a declared spec change and treat divergences within that area as expected. Flag only divergences outside the declared change as findings.
Step 2. Build independent premises for each version (guide Step 2) — apply the Premises Construction Checklist to Version A and Version B separately.
Step 3. Trace both versions for the common case (guide Step 3) — parallel trace, same input, note the first divergence if any.
Step 4. Trace boundary cases (guide Step 4) — empty/null/zero, max/min, error inputs, first/last of collections. Start with at most three highest-risk boundary scenarios unless the user asks for exhaustive equivalence or the shared specification requires more.
Step 5. Identify and classify semantic divergences (guide Step 5) — each divergence is a finding with Premises → Trace → Divergence → Trigger → Remedy and an L-code.
Step 6. Equivalence verdict (guide Step 6) — one of: ✅ Semantically Equivalent, ⚠️ Conditionally Equivalent (state the condition precisely), ❌ Semantically Divergent.
Step 7. Output (guide Step 7) — Report Template with the Verdict header per common.md §5; localize headers if the user wrote in Chinese. Format is mandatory even for trivially short snippets: every divergence finding MUST use the five labeled fields (Premises / Trace / Divergence / Trigger / Remedy); never substitute with a plain paragraph or table.
Mode line in report: Semantic Diff (Chinese: 语义对比).
Limitations
- Use this skill only when the task clearly matches its upstream source and local project context.
- Verify commands, generated code, dependencies, credentials, and external service behavior before applying changes.
- Do not treat examples as a substitute for environment-specific tests, security review, or user approval for destructive or costly actions.
常见问题
“语义等价”是什么意思?
意思是即使代码看起来不一样,或者被重写过,只要对相同的输入产生相同的结果,或者实际效果一致,就算语义等价。
什么是“半形式化追踪”?
这是一种逐步跟踪代码逻辑的方法,就像画一张记录每一步发生了什么的地图,确保不遗漏任何环节。
如果代码本来就故意要有不同的行为怎么办?
如果你事先告诉 AI 计划中的行为变化,它会把这些变化记录下来,只指出那些计划之外的意外差异。
详情
作者的原始描述
Compare two code versions for semantic equivalence via semi-formal tracing of both versions side-by-side.
热度
- GitHub 星标
- 48k
- 排名
- #5096
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。