← 技能图谱 · HTML-REPORT
nameimprove-codebase-architecture
descriptionScan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
触发词扫描代码库寻找深化机会,以可视化的 HTML 报告呈现,然后对你选择的任一方案进行追问。
disable-model-invocationtrue

improve-codebase-architecture

Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.

Surface architectural friction and propose deepening opportunities — refactors that turn shallow modules into deep ones. The aim is testability and AI-navigability.

揭示架构摩擦并提出深化机会——将浅模块重构为深模块的重构方案。目标是可测试性和 AI 可导航性。

This command is informed by the project's domain model and built on a shared design vocabulary:

本命令项目的领域模型启发,并建立在共享的设计词汇之上:

  • Run the /codebase-design skill for the architecture vocabulary (module, interface, depth, seam, adapter, leverage, locality) and its principles (the deletion test, "the interface is the test surface", "one adapter = hypothetical seam, two = real"). Use these terms exactly in every suggestion — don't drift into "component," "service," "API," or "boundary."
  • The domain language in CONTEXT.md gives names to good seams; ADRs in docs/adr/ record decisions this command should not re-litigate.
  • 运行 /codebase-design 技能获取架构词汇(模块接口深度接缝适配器杠杆收益局部性)及其原则(删除测试、"接口即测试面"、"一个适配器 = 假设性接缝,两个 = 真实的")。在每个建议中精确使用这些术语——不要偏离到"组件""服务""API"或"边界"。
  • CONTEXT.md 中的领域语言为好的接缝命名;docs/adr/ 中的 ADR 记录了本命令不应重新质疑的决策。

Process

流程

1. Explore

1. 探索

Read the project's domain glossary (CONTEXT.md) and any ADRs in the area you're touching first.

首先阅读项目的领域词汇表(CONTEXT.md)以及你将要触及的区域内任何 ADR。

Then use the Agent tool with subagent_type=Explore to walk the codebase. Don't follow rigid heuristics — explore organically and note where you experience friction:

然后使用 subagent_type=Explore 的代理工具遍历代码库。不要遵循僵化的启发式方法——有机地探索,记下你遇到摩擦的地方:

  • Where does understanding one concept require bouncing between many small modules?
  • Where are modules shallow — interface nearly as complex as the implementation?
  • Where have pure functions been extracted just for testability, but the real bugs hide in how they're called (no locality)?
  • Where do tightly-coupled modules leak across their seams?
  • Which parts of the codebase are untested, or hard to test through their current interface?
  • 理解一个概念需要在多个小模块之间跳转?
  • 哪些模块是的——接口几乎和实现一样复杂?
  • 哪些地方的纯函数仅仅为了可测试性而被提取出来,但真正的 bug 隐藏在其调用方式中(没有局部性)?
  • 哪些地方紧密耦合的模块在接缝处泄露?
  • 代码库的哪些部分未经测试,或通过当前接口难以测试?

Apply the deletion test to anything you suspect is shallow: would deleting it concentrate complexity, or just move it? A "yes, concentrates" is the signal you want.

对任何你怀疑是浅的东西应用删除测试:删除它会集中复杂性,还是仅仅移动它?答案是"会集中"就是你要的信号。

2. Present candidates as an HTML report

2. 以 HTML 报告呈现候选方案

Write a self-contained HTML file to the OS temp directory so nothing lands in the repo. Resolve the temp dir from $TMPDIR, falling back to /tmp (or %TEMP% on Windows), and write to <tmpdir>/architecture-review-<timestamp>.html so each run gets a fresh file. Open it for the user — xdg-open <path> on Linux, open <path> on macOS, start <path> on Windows — and tell them the absolute path.

将独立的 HTML 文件写入操作系统临时目录,这样不会在仓库中留下痕迹。从 $TMPDIR 解析临时目录,回退到 /tmp(Windows 上为 %TEMP%),写入 <tmpdir>/architecture-review-<timestamp>.html,这样每次运行都获得新文件。为用户打开它——Linux 上用 xdg-open <path>,macOS 上用 open <path>,Windows 上用 start <path>——并告诉他们绝对路径。

The report uses Tailwind via CDN for layout and styling, and Mermaid via CDN for diagrams where a graph/flow/sequence reliably communicates the structure. Mix Mermaid with hand-crafted CSS/SVG visuals — use Mermaid when relationships are graph-shaped (call graphs, dependencies, sequences), and hand-built divs/SVG when you want something more editorial (mass diagrams, cross-sections, collapse animations). Each candidate gets a before/after visualisation. Be visual.

报告使用通过 CDN 加载的 Tailwind 进行布局和样式设置,使用通过 CDN 加载的 Mermaid 处理能用图形/流程/序列可靠传达结构的图表。将 Mermaid 与手工制作的 CSS/SVG 视觉元素混合使用——当关系是图形形状(调用图、依赖关系、序列)时使用 Mermaid,当想要更具编辑性的内容(体量图、剖面图、折叠动画)时使用手工构建的 div/SVG。每个候选方案都有前后对比可视化。要有视觉冲击力。

For each candidate, render a card with:

对每个候选方案,渲染一个包含以下内容的卡片:

  • Files — which files/modules are involved
  • Problem — why the current architecture is causing friction
  • Solution — plain English description of what would change
  • Benefits — explained in terms of locality and leverage, and how tests would improve
  • Before / After diagram — side-by-side, custom-drawn, illustrating the shallowness and the deepening
  • Recommendation strength — one of Strong, Worth exploring, Speculative, rendered as a badge
  • 文件——涉及哪些文件/模块
  • 问题——当前架构为何造成摩擦
  • 方案——用简明语言描述会变化什么
  • 收益——从局部性和杠杆收益的角度解释,以及测试将如何改善
  • 前后对比图——并排、自定义绘制,展示浅度和深化
  • 推荐强度——StrongWorth exploringSpeculative 之一,渲染为徽章

End the report with a Top recommendation section: which candidate you'd tackle first and why.

首选推荐部分结束报告:你会先处理哪个候选方案以及为什么。

Use CONTEXT.md vocabulary for the domain, and the /codebase-design vocabulary for the architecture. If CONTEXT.md defines "Order," talk about "the Order intake module" — not "the FooBarHandler," and not "the Order service."

使用 CONTEXT.md 的词汇表描述领域,使用 /codebase-design 的词汇表描述架构。 如果 CONTEXT.md 定义了"Order",就说"Order intake 模块"——而不是"FooBarHandler"或"Order 服务"。

ADR conflicts: if a candidate contradicts an existing ADR, only surface it when the friction is real enough to warrant revisiting the ADR. Mark it clearly in the card (e.g. a warning callout: "contradicts ADR-0007 — but worth reopening because…"). Don't list every theoretical refactor an ADR forbids.

ADR 冲突:如果某个候选方案与现有 ADR 矛盾,只有当摩擦足够真实、值得重新审视 ADR 时才提出。在卡片中清晰标记(例如警告提示:"与 ADR-0007 矛盾——但值得重新讨论,因为……")。不要列出 ADR 禁止的每一个理论上的重构。

See HTML-REPORT.md for the full HTML scaffold, diagram patterns, and styling guidance.

参见 HTML-REPORT.md 了解完整的 HTML 脚手架、图表模式及样式指南。

Do NOT propose interfaces yet. After the file is written, ask the user: "Which of these would you like to explore?"

暂不提出接口。文件写入后,询问用户:"你想探索哪一个?"

3. Grilling loop

3. 追问循环

Once the user picks a candidate, run the /grilling skill to walk the design tree with them — constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive.

用户选定候选方案后,运行 /grilling 技能与他们一起遍历设计树——约束条件、依赖关系、深化模块的形态、接缝背后的内容、哪些测试能存活。

Side effects happen inline as decisions crystallize — run the /domain-modeling skill to keep the domain model current as you go:

随着决策逐步明确,副作用会即时发生——运行 /domain-modeling 技能让领域模型在过程中保持最新:

  • Naming a deepened module after a concept not in CONTEXT.md? Add the term to CONTEXT.md. Create the file lazily if it doesn't exist.
  • Sharpening a fuzzy term during the conversation? Update CONTEXT.md right there.
  • User rejects the candidate with a load-bearing reason? Offer an ADR, framed as: "Want me to record this as an ADR so future architecture reviews don't re-suggest it?" Only offer when the reason would actually be needed by a future explorer to avoid re-suggesting the same thing — skip ephemeral reasons ("not worth it right now") and self-evident ones.
  • Want to explore alternative interfaces for the deepened module? Run the /codebase-design skill and use its design-it-twice parallel sub-agent pattern.
  • 将深化模块命名为 CONTEXT.md 中未有的概念? 将该术语添加到 CONTEXT.md。如果文件不存在,懒加载创建。
  • 对话中明确了一个模糊术语? 立即更新 CONTEXT.md
  • 用户因承载性理由拒绝了候选方案? 提供 ADR,表述为:"要我把它记录为 ADR,这样以后的架构审查就不会再次推荐它吗?" 只有当理由对未来的探索者避免再次推荐同一方案确实有必要时才提供——跳过临时性理由("现在不值得")和不言自明的理由。
  • 想探索深化模块的替代接口? 运行 /codebase-design 技能,使用其双重设计并行子代理模式。