Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 标题
refactor: 提取重复定义的共享常量和工具函数到 src/common/constants.ts
描述
多个文件中独立定义了完全相同的常量和工具函数。这种重复会带来维护风险——当逻辑需要修改时,必须同步更新每一份副本,容易遗漏导致不一致。本 PR 将这些重复项提取到统一的共享模块 src/common/constants.ts 中,并将所有重复定义替换为导入引用。
背景
在代码审查中发现以下重复定义:
常量 / 函数 重复所在文件
INVALID_FILE_NAME_PATTERN src/main/main.ts、src/renderer/components/cowork/CoworkSessionDetail.tsx
sanitizeExportFileName() src/main/main.ts、src/renderer/components/cowork/CoworkSessionDetail.tsx
MIN_MEMORY_USER_MEMORIES_MAX_ITEMS src/main/main.ts、src/main/coworkStore.ts
MAX_MEMORY_USER_MEMORIES_MAX_ITEMS src/main/main.ts、src/main/coworkStore.ts
MEMORY_PROCEDURAL_TEXT_RE src/main/coworkStore.ts、src/main/libs/coworkRunner.ts
MEMORY_ASSISTANT_STYLE_TEXT_RE src/main/coworkStore.ts、src/main/libs/coworkRunner.ts
改动内容
新增文件: src/common/constants.ts — 上述所有共享常量和工具函数的唯一定义,附带 JSDoc 注释。
修改文件:
src/main/main.ts — 移除 3 个常量定义和 1 个函数定义,改为从 common/constants 导入。
src/renderer/components/cowork/CoworkSessionDetail.tsx — 移除 1 个常量定义和 1 个函数定义,改为从 common/constants 导入。
src/main/coworkStore.ts — 移除 4 个常量定义,改为从 common/constants 导入。
src/main/libs/coworkRunner.ts — 移除 2 个常量定义,改为从 common/constants 导入。