Skip to content

chore(memory): 规范化注释,移除无信息量注释与开发过程标注 - #2

Merged
JohnRichard4096 merged 2 commits into
mainfrom
chore/normalize-comments
Sep 25, 2026
Merged

JohnRichard4096 merged 2 commits into
mainfrom
chore/normalize-comments

Conversation

@AmriaLin

@AmriaLin AmriaLin commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

做了什么

按「注释只保留对代码的补充说明」这一条,把 amrita_plugin_memory 下的注释全部过了一遍。判据是:这条注释是否提供了代码本身读不出来的信息(原因、约束、外部事实)。只做同义复述或状态标注的一律删除。

删除的两类

标签式注释 —— 分节标记,以及对下方代码或分支的同义复述:

  • # status / # reindex / # backup / # click 命令组(cli.py)
  • # 生命周期 / # 核心运行 / # 后处理 / # Prompt 加载 / # 用户画像(runner.py)
  • # 辅助 / # Handler / # 消息生成 / # 压缩辅助工具(rethinking/tools.py)
  • # 精确匹配 / # 前缀匹配 / # 追加模式 / # 替换模式 / # 过滤 / # 排序
  • # 公共参数:scope / # Function Schema 定义 / # Handler 实现

开发过程相关注释:

  • # Configuration for your_plugin_name plugin(config.py 顶部的模板残留,插件名还是占位符)
  • Alembic 的 # ### commands auto generated by Alembic - please adjust! ### 与 # ### end Alembic commands ###(两个 migration 文件,共 8 行)
  • # Phase 3: 阶段编号
  • (实验性功能)、(MVP仅支持单用户)、新版(开发中)、旧版(≤1.9.x) 等状态与版本标注

保留的

解释原因、约束或外部事实的注释,例如:

  • # lazy to avoid circular import
  • # 先备份:这是删除集合后唯一的回滚依据
  • # 空集合:只需重建并写指纹,无需调用嵌入模型
  • # 兜底确保 FK 存在(会话中 chat 插件通常已创建 metadata 行)
  • # 群聊事件 → 群 uni_id;私聊事件 → 个人 uni_id
  • # Guard: 确保任何 \---` 行都能正确分割(不匹配文档内部的减号)`
  • # 所有工具已通过 @on_tools(bound_to=...) 注册到隔离的 MultiToolsManager…

顺带调整

  • keys.py 模块 docstring 去掉「旧版」「新版(开发中)」标注,直接列出两种格式
  • config.py 去掉「— 实验性功能」
  • runner.py 去掉「Phase 3:」阶段编号

补充(9102f6b)

target_user_id 的「单用户」限制不是开发阶段的临时状态,而是设计取舍:多用户场景与用户体量难以预测,因此默认只实现单用户,需要多用户支持时自行实现。原先 (MVP仅支持单用户) 的措辞把设计取舍写成了未完成状态,已改为:

  • SubconsciousConfig docstring 补充该设计说明
  • 字段描述改为「目标用户ID(默认仅实现单用户,多用户需自行实现),为空则不启动」

统计

注释 101 条 → 50 条。12 个文件,+11 / −103。纯注释改动,无逻辑变化。

验证

  • ruff check . 通过
  • ruff format --check . 通过
  • python -m compileall amrita_plugin_memory 通过

一处未动

README.md 第 222 行的表格里还有一处「开发中」:

| Amrita 版本 | 格式                          |
| ≤ 1.9.x     | `user_{qq}` / `group_{群号}`   |
| 开发中       | `QQPlatform_Private_{qq}` / … |

它是文档不是注释,且那一列是「Amrita 版本」,我不确定该填哪个版本号,所以没有改动。需要一并处理的话说一声。

只保留对代码的补充说明,即解释原因、约束或外部事实的注释。删除两类:

- 标签式注释:分节标记,以及对下方代码或分支的同义复述
- 开发过程相关注释:模板残留(your_plugin_name)、Alembic 自动生成标记、
  状态与版本标注

顺带调整:

- keys.py 的格式说明去掉「旧版(≤1.9.x)」「新版(开发中)」标注,直接列出
  两种格式
- config.py 去掉「实验性功能」「MVP」等措辞
- runner.py 去掉「Phase 3」阶段编号

注释行由 101 条降至 50 条,无任何逻辑改动。
@sourcery-ai

sourcery-ai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This comment-only cleanup reduces the amrita_plugin_memory comment set from 101 to 50 by removing redundant structure and development-process annotations, while preserving comments that explain non-obvious rationale, constraints, and external behavior; formatting, linting, and compilation were verified.

File-Level Changes

Change Details Files
Removed comments that only label sections, restate nearby code, or describe development status.
  • Deleted section headers and branch-operation labels across CLI, embedding, matching, rethinking, schema, and tool modules.
  • Removed template, Alembic-generated, phase-number, experimental, MVP, and version-status annotations.
  • Kept comments that document rationale, constraints, fallback behavior, or external facts.
amrita_plugin_memory/cli.py
amrita_plugin_memory/embedding.py
amrita_plugin_memory/matchers.py
amrita_plugin_memory/rethinking/knowledge.py
amrita_plugin_memory/rethinking/runner.py
amrita_plugin_memory/rethinking/schemas.py
amrita_plugin_memory/rethinking/tools.py
amrita_plugin_memory/tools.py
amrita_plugin_memory/migrations/21f55abc2b90_init.py
amrita_plugin_memory/migrations/6004d221a7de_state.py
Normalized remaining documentation to describe supported behavior without development-era labels.
  • Updated the keys module docstring to present both recognized key formats directly.
  • Removed experimental and MVP wording from configuration documentation while retaining the single-user constraint.
  • Converted the Phase 3 annotation into a behavior-focused explanation.
amrita_plugin_memory/keys.py
amrita_plugin_memory/config.py
amrita_plugin_memory/rethinking/runner.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

「仅支持单用户」不是开发阶段的临时限制。多用户场景与用户体量难以预测,
故默认只实现单用户,需要多用户支持时自行实现。

- SubconsciousConfig docstring 补充该设计说明
- target_user_id 描述改为「默认仅实现单用户,多用户需自行实现」
@JohnRichard4096
JohnRichard4096 merged commit 28f926b into main Sep 25, 2026
3 checks passed
@JohnRichard4096
JohnRichard4096 deleted the chore/normalize-comments branch September 25, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants