Repository navigation
refactor: carve out misplaced helpers from monolith TUs - #6
Merged
Merged
Conversation
These are general path utilities, not config schema concerns. Lifting them
out of src/config/config.cpp puts them next to the rest of the path helpers
in src/utils/paths.{hpp,cpp}. Pure code reorganization — no behavior change.
Callers updated: src/skills/skill_init.cpp and src/daemon/worker.cpp now
include <utils/paths.hpp> directly instead of relying on transitive include
through config.hpp.
Mirrors the convention already used by history_command, init_command, memory_command, proxy_command, websearch_command. The /model dispatch (picker, in-memory swap, --cwd / --default persistence) was the only sibling still inlined in builtin_commands.cpp. Pure code reorganization, no behavior change. builtin_commands.cpp keeps the static 'trim' helper since cmd_page_step still depends on it. The src/commands tree is glob-picked-up by the root CMakeLists, so no CMake change is needed.
Self-contained 65-line Win32 fallback chain (SetProcessDpiAwarenessContext -> SetProcessDpiAwareness -> SetProcessDPIAware) with zero state shared with the rest of desktop/main.cpp. Mirrors the existing tray_icon_win / notifications_win / folder_picker_win convention (_WIN32-guarded TU under namespace acecode::desktop). Pure code reorganization, no behavior change.
Lift the pure-string-manipulation OriginParts struct, parse_origin, and
split_host_port out of server.cpp's anon namespace into a dedicated
web/origin.{hpp,cpp} TU under namespace acecode::web. server.cpp shrinks
by ~50 LOC and the parsers become unit-testable.
ascii_lower stays in server.cpp — it has another caller (is_loopback_host)
that is not part of this carve-out. origin.cpp keeps its own private
ascii_lower.
Adds tests/web/origin_test.cpp covering well-formed http/https, missing
scheme, IPv6 bracketed hosts, bare-IPv6 multi-colon heuristic, default
port fill, and lowercase normalization. Picked up automatically by the
tests/*_test.cpp glob — no CMake change.
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.
Architectural Sweep
Focus: 我当前项目有几个文件和函数快成屎山了, 请按照业务逻辑解耦
Assessment
仓库内有 8 处屎山点按代价滚雪球速度排序:
src/agent_loop.cpp(642 行 + 层级倒挂 importweb/*)、src/web/server.cpp(2406 行 + 反向 includedesktop/)、src/commands/builtin_commands.cpp(1082 行 / 16 命令挤一起)、src/config/config.cpp(956 行 / 7 个无关职责)、src/desktop/main.cpp(961 行)、前端ChatView.jsx(16-prop God 组件)、Sidebar.jsx、sessionTranscript.js。横向问题:层级倒挂 2 处、Rule-of-Three 失败 5 处、通用 utils 被困在使用方文件、SessionEvent 协议没收口。本轮选取 4 个高收益、低风险、相互独立的纯重组,零行为变更:把通用 path 工具搬到
utils/paths、/model命令拆出独立 TU 跟随同目录约定、enable_desktop_dpi_awareness抽离到 Win32 专属 TU、OriginParts/parse_origin从web/server.cpp提取并加单测。剩余的 agent_loop 拆分、web↔core 反向依赖反转、config.cppread_json_field<T>模板化、前端 God 组件拆分等留作后续 P0 战役。Changes
src/utils/paths.{hpp,cpp}←src/config/config.cpp(commit 5b9d2cc): 把expand_path和get_project_dirs_up_to_home从config.cpp迁出。它们是通用路径工具,与 config schema 无关,放在 config 里既膨胀该 TU 也让其它模块被迫 includeconfig.hpp才能用路径工具。src/commands/model_command.{hpp,cpp}←src/commands/builtin_commands.cpp(commit ca257e6): 抽出 113 行/model派发逻辑到独立 TU,跟随同目录已有约定 (history_command.cpp/init_command.cpp/memory_command.cpp/proxy_command.cpp/websearch_command.cpp)。/model是该约定的最后一个 outlier。src/desktop/dpi_win.{hpp,cpp}←src/desktop/main.cpp(commit 2e1e65d): 把 65 行SetProcessDpiAwarenessContext→SetProcessDpiAwareness→SetProcessDPIAwareWin32 fallback 链抽离到专属 TU,镜像同目录已有的tray_icon_win.cpp/notifications_win.cpp/folder_picker_win.cpp模式,把<Windows.h>的 LoadLibraryW/GetProcAddress 包袱关进单独的 Windows-only 编译单元。src/web/origin.{hpp,cpp}+tests/web/origin_test.cpp←src/web/server.cpp(commit 558d490): 把OriginPartsstruct 和parse_origin从 anon namespace 提到独立 TU。这是纯字符串解析,与 Crow / daemon state 无任何耦合,提取后让server.cpp-50 LOC 同时解锁单测覆盖 (well-formed http/https / 缺 scheme / IPv6 brackets / 默认端口填充 / 非法输入)。Validation