review-duplication
google-gemini/gemini-cli
在代码审查过程中运用这项技能,主动检查代码库中是否存在功能重复、重复造轮子,或者未能复用现有项目的最佳实践和共享工具的情况。
...展开全部评论重复
概述
该技能提供了一个结构化的工作流,用于在代码审查期间对代码库进行调查,以识别重复的逻辑、重复实现的辅助函数,以及未利用的现成模式复用机会。通过执行此工作流,可确保新代码与现有项目架构无缝集成。
工作流:检查代码重复
在进行代码审查时,请在完成审查前执行以下步骤:
1. 提取核心逻辑
分析新代码,识别其中引入的核心算法、辅助函数、通用数据结构或 UI 组件。不要局限于具体的业务逻辑,而要深入探究其底层机制。
2. 推测现有位置并追踪依赖关系
思考如果项目中已存在此类代码,它通常会位于何处。请提供从代码库根目录开始的绝对路径以消除歧义。
- 辅助函数:
packages/core/src/utils/、packages/cli/src/utils/ - UI 组件:
packages/cli/src/ui/components/、packages/cli/src/ui/ - 服务:
packages/core/src/services/、packages/cli/src/services/ - 配置:
packages/core/src/config/、packages/cli/src/config/ - 核心逻辑:如果功能不属于 React UI 特定范畴,请将其归入
packages/core/。
追踪第三方依赖:如果拉取请求引入了新的实用程序库导入(例如lodash.merge、date-fns),请追踪项目当前如何以及在何处使用该库。很可能已有现成的封装或共享实用程序。
检查包文件:在标记复杂算法的自定义实现之前,请检查package.json,确认是否已安装提供此功能的标准库(如lodash或uuid)。
3. 调查代码库(子代理委托)
将代码库调查这项繁重的工作委托给专门的子代理。它们经过优化,能够进行深度搜索和语义映射,同时不会使您的会话历史记录臃肿。
为确保审查全面,您必须为子代理制定高度具体的目标,并向它们提供您在步骤 1 中发现的“线索”。
- 代码库调查员:将
codebase_investigator作为主要调查员。在委派任务时,请制定一个目标,要求其针对代码库提出具体且具有调查性质的问题,并明确包含以下搜索维度:- 结构相似性:询问现有代码是否使用了相同的底层 API(例如,“是否有现有代码出于类似目的使用了
Intl.DateTimeFormat或setTimeout?”)。 - 命名约定:询问是否存在命名模式相似的现有符号(例如,“是否有命名模式类似
*Format*或*Debounce*的现有符号?”)。 - 注释与文档:询问拉取请求(PR)的注释或 JSDoc 中是否存在描述其他地方类似行为的关键词。
- 架构适配性:询问此类逻辑目前集中在哪里(例如,“集中化的日期格式化逻辑位于何处?”)。
- 重构指导:至关重要的是,要求子代理解释如何重构新代码,以便利用其发现的任何现有逻辑。
- 结构相似性:询问现有代码是否使用了相同的底层 API(例如,“是否有现有代码出于类似目的使用了
- 通才型代理:使用
通才型代理进行详细且需要多次迭代的比较。例如:“审查 PR 中MyNewComponent的实现,并从语义上将其与packages/ui/src中的所有组件进行比较。是否有现有的组件可以扩展或直接替代?” - 保留简单搜索的快速路径:对于极其简单且无歧义的检查(例如
,“package.json中是否包含lodash?”),应直接进行搜索以节省时间。对于任何开放式的“调查”,默认采用委托处理。
4. 评估最佳实践
检查新代码是否符合项目既定的规范。
- 错误处理:是否使用了项目标准的错误类或日志机制?
- 状态管理:是否绕过了既定的存储或上下文?
- 样式:是否硬编码了颜色或间距,而非使用主题变量? 如果拉取请求引入了新的模式,请将其与文档中记载的标准进行对比,并明确确认是否本应使用现有的项目模式。
5. 提出建设性反馈
若发现该 PR 重复了现有功能或未遵循最佳实践:
- 请提供清晰的评审评论。
- 指明来源:明确提及应复用的绝对或项目相对文件路径,以及具体的符号(函数、组件、类)。
- 实现指导:提供简短的代码片段或清晰的说明,展示如何集成现有代码以满足任务要求。
- 阐明价值:简要说明重用现有代码的好处(例如:可维护性、一致性、内置的边界情况处理)。
示例评论:
“看起来这个 PR 引入了一个新的
formatDate实用函数。我们在src/utils/dateHelpers.ts中已经有一个经过充分测试且功能完善的formatDate函数。你可以通过如下方式导入该函数来替换你的实现:
import{ formatDate }from '../utils/dateHelpers';// 然后在此处使用: constdisplayDate =formatDate(userDate,'MMM Do, YYYY');复用该函数可确保日期格式化与应用程序其余部分保持一致,并能正确处理时区转换。”
该仓库的更多内容
effortgoogle-gemini/gemini-cli估算解决给定问题所需的实现工作量。2026-07-07106.2kqualitygoogle-gemini/gemini-cli评估 GitHub 问题是否为垃圾信息、内容为空、需要更多信息,还是可以继续处理。2026-07-07 106.2k spec-generator google-gemini/gemini-cli 生成结构化的 Workable Spec JSON,以指导开发者工作者。2026-07-07106.2kantigravity-supportgoogle-gemini/gemini-cli当用户提出问题、寻求帮助或请求有关安装、配置或迁移至 Antigravity CLI 的操作指南时使用。 该技能提供源自官方 Antigravity CLI 文档的最新详细信息、要求和命令。2026-06-09106.2kagent-tuigoogle-gemini/gemini-cli主代理:请勿直接使用此技能。 若需测试 TUI,请调用 `tui_tester` 子代理。通过编程方式驱动终端用户界面(TUI)应用程序,以进行测试、自动化和检查。适用场景:自动化 CLI/TUI 交互、对终端应用进行回归测试,或验证交互行为。 此外,在以下情况下也可使用:用户询问“什么是 agent-tui”、“agent-tui 做什么”、“演示 agent-tui”、“向我展示 agent-tui”、“agent-tui 是如何工作的”,或者希望看到其实际运行效果。2026-05-18106.2ktui-testergoogle-gemini/gemini-cli 关于如何使用终端自动化测试 Gemini CLI 行为和视觉输出的专家指南。2026-05-18106.2kReview Duplication
Overview
This skill provides a structured workflow for investigating a codebase during a code review to identify duplicated logic, reinvented utilities, and missed opportunities to reuse established patterns. By executing this workflow, you ensure that new code integrates seamlessly with the existing project architecture.
Workflow: Investigating for Duplication
When reviewing code, perform the following steps before finalizing your review:
1. Extract Core Logic
Analyze the new code to identify the core algorithms, utility functions, generic data structures, or UI components being introduced. Look beyond the specific business logic to see the underlying mechanics.
2. Hypothesize Existing Locations & Trace Dependencies
Think about where this type of code would live if it already existed in the project. Provide absolute paths from the repo root to disambiguate.
- Utilities:
packages/core/src/utils/,packages/cli/src/utils/ - UI Components:
packages/cli/src/ui/components/,packages/cli/src/ui/ - Services:
packages/core/src/services/,packages/cli/src/services/ - Configuration:
packages/core/src/config/,packages/cli/src/config/ - Core Logic: Call out
packages/core/if functionality does not appear React UI specific.
Trace Third-Party Dependencies: If the PR introduces a new import for a utility library (e.g., lodash.merge, date-fns), trace how and where the project currently uses that library. There is likely an existing wrapper or shared utility.
Check Package Files: Before flagging a custom implementation of a complex algorithm, check package.json to see if a standard library (like lodash or uuid) is already installed that provides this functionality.
3. Investigate the Codebase (Sub-Agent Delegation)
Delegate the heavy lifting of codebase investigation to specialized sub-agents. They are optimized to perform deep searches and semantic mapping without bloating your session history.
To ensure a comprehensive review, you MUST formulate highly specific objectives for the sub-agents, providing them with the "scents" you discovered in Step 1.
- Codebase Investigator: Use the
codebase_investigatoras your primary researcher. When delegating, formulate an objective that asks specific, investigative questions about the codebase, explicitly including these search vectors:- Structural Similarity: Ask if existing code uses the same underlying APIs (e.g., "Does any existing code use
Intl.DateTimeFormatorsetTimeoutfor similar purposes?"). - Naming Conventions: Ask if there are existing symbols with similar naming patterns (e.g., "Are there existing symbols with naming patterns like
*Format*or*Debounce*?"). - Comments & Documentation: Ask if keywords from the PR's comments or JSDoc exist in describing similar behavior elsewhere.
- Architectural Fit: Ask where this type of logic is currently centralized (e.g., "Where is centralized date formatting logic located?").
- Refactoring Guidance: Crucially, ask the sub-agent to explain how the new code could be refactored to use any existing logic it finds.
- Structural Similarity: Ask if existing code uses the same underlying APIs (e.g., "Does any existing code use
- Generalist Agent: Use the
generalistfor detailed, turn-intensive comparisons. For example: "Review the implementation ofMyNewComponentin the PR and compare it semantically against all components inpackages/ui/src. Are there any existing components that could be extended or used instead?" - Retain Fast Path for Simple Searches: For extremely simple, unambiguous checks (e.g., "Does
package.jsonincludelodash?"), perform a direct search to save time. Default to delegation for any open-ended "investigations."
4. Evaluate Best Practices
Check if the new code aligns with the project's established conventions.
- Error Handling: Does it use the project's standard error classes or logging mechanisms?
- State Management: Does it bypass established stores or contexts?
- Styling: Does it hardcode colors or spacing instead of using theme variables? If the PR introduces a new pattern, compare it against the documented standards and explicitly confirm if an existing project pattern should have been used instead.
5. Formulate Constructive Feedback
If you discover that the PR duplicates existing functionality or ignores a best practice:
- Provide a clear review comment.
- Identify the Source: Explicitly mention the absolute or project-relative file path and the specific symbol (function, component, class) that should be reused.
- Implementation Guidance: Provide a brief code snippet or a clear explanation showing how to integrate the existing code to fulfill the task's requirements.
- Explain the Value: Briefly explain why reusing the existing code is beneficial (e.g., maintainability, consistency, built-in edge case handling).
Example comment:
"It looks like this PR introduces a new
formatDateutility. We already have a robust, testedformatDatefunction insrc/utils/dateHelpers.ts.You can replace your implementation by importing it like this:
import { formatDate } from '../utils/dateHelpers';// Then use it here: const displayDate = formatDate(userDate, 'MMM Do, YYYY');Reusing this ensures that the date formatting remains consistent with the rest of the application and handles timezone conversions correctly."
More from this repository
effortgoogle-gemini/gemini-cliEstimates the implementation effort required to address the given issue.
2026-07-07106.2kqualitygoogle-gemini/gemini-cliEvaluates whether a GitHub issue is spam, empty, needs more information, or is OK to proceed.
2026-07-07106.2kspec-generatorgoogle-gemini/gemini-cliGenerates a structured Workable Spec JSON to guide a Developer Worker.
2026-07-07106.2kantigravity-supportgoogle-gemini/gemini-cliUse when the user asks questions, seeks help, or requests instructions related to installing, setting up, or migrating to Antigravity CLI. This skill provides the latest up to date details, requirements, and commands sourced from the official Antigravity CLI documentation.
2026-06-09106.2kagent-tuigoogle-gemini/gemini-cliMain Agents: Do NOT use this skill directly. If you need to test the TUI, invoke the `tui_tester` subagent. Drive terminal UI (TUI) applications programmatically for testing, automation, and inspection. Use when: automating CLI/TUI interactions, regression testing terminal apps, or verifying interactive behavior. Also use when: user asks "what is agent-tui", "what does agent-tui do", "demo agent-tui", "show me agent-tui", "how does agent-tui work", or wants to see it in action.
2026-05-18106.2ktui-testergoogle-gemini/gemini-cliExpert guidance for testing Gemini CLI behavior and visual output using terminal automation.
2026-05-18106.2k




首页
