AGENT SKILL

代码库架构优化设计

improve-codebase-architecture

找出浅层模块,在 HTML 报告中给出更深层模块的改进建议,然后设计用户选定的方案。当用户希望改进架构、可测试性或接口设计时使用。单次重构请使用 refactoring-protocol;循环清理请使用 rsi。

License 许可
MIT
最近更新
2026-11-04
Stars
★ 4
Forks
2

01 前言 Front Matter

name
improve-codebase-architecture
group
process
description
Finds shallow modules and proposes deeper ones in an HTML report, then designs the chosen one. Use when the user wants better architecture, testability or interface design. For one refactor use refactoring-protocol; for a cleanup loop use rsi.
argument-hint
[area, optional]
disable-model-invocation
true

02 资源文件 1

03 SKILL.md 正文

Improve Codebase Architecture

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

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.

Process

1. Explore

Scope before you scan — YAGNI. Deepening a module pays off by making future changes to it easier, so put extra weight on the parts of the codebase that have recently changed. Decide where to look before you look:

  • If the user named a direction — a module, a subsystem, a pain point — take it, and skip the inference below.
  • Otherwise, walk back a good stretch of the commit history (git log --oneline) to find the codebase's hot spots — the files and areas that keep coming up — and let those paths pull your attention first. If the changes are scattered with no clear hot spot, widen the net.

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

Then dispatch the explorer agent to walk the codebase; if it isn't installed, fall back to the built-in Explore agent. Sub-agents don't inherit skills, so paste the five friction questions below and the /codebase-design glossary terms into the explorer brief. Don't follow rigid heuristics — explore organically and note where you experience friction:

  • 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?

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

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, cmd /c start "" <path> on Windows — and tell them the absolute 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.

For each candidate, render a card with:

  • Files — which files/modules are involved
  • Problem — one sentence: why the current architecture is causing friction
  • Solution — one sentence: what would change, in plain English
  • Wins — bullets 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

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."

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.

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

Before opening the report, check it for leaked template tokens: grep -nE '\{\{|\}\}' <path> over the generated HTML. Fix hits that are leftover template tokens, not code excerpts, then open the report.

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

3. Grilling loop

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.

Run /domain-modeling as terms and decisions crystallise. Offer an ADR only if a future explorer would need the reason to avoid re-suggesting the same thing.

To explore alternative interfaces for the deepened module, run the /codebase-design skill and use its design-it-twice parallel sub-agent pattern.

Stop when the user has a chosen interface direction and the CONTEXT.md/ADR updates are written.

04 同仓库更多 Skills

rubakas
rubakas/agent-notes

security-audit

Audits a codebase for security vulnerabilities, independently verifies each one, and writes a report. Use when asked for a full, multi-phase codebase security audit or pen test, or for focused security guidance on code.

★ 4
rubakas
rubakas/agent-notes

大型任务调查地图规划

wayfinder

为超出单个智能体会话处理能力的大型工作,在问题跟踪器上绘制调查工单地图,然后每个会话解决其中一张工单。当用户想要为一个庞大而松散的想法梳理路径,或继续已有的 wayfinder 地图时使用。

软件开发工程师任务规划与分解
★ 4
rubakas
rubakas/agent-notes

Issue与PR分诊处理

triage

对 issue 和外部 PR 进行分诊:分类、验证,必要时深入质询,并编写可供智能体直接使用的简报。当用户想要对待办积压、特定 issue 或 PR 进行分诊时使用。

软件开发工程师工单与问题跟踪管理
★ 4
rubakas
rubakas/agent-notes

计划规格转工单

to-tickets

将计划、规格说明书或对话拆解为“曳光弹”式工单(tracer-bullet tickets),每个工单都要声明其阻塞依赖边,并发布到已配置的跟踪器。当用户希望将规格说明书或计划转换为工单或 issue 时使用。

软件开发工程师任务规划与分解
★ 4
rubakas
rubakas/agent-notes

对话转规格说明书

to-spec

将当前对话转换为规格说明书(spec)并发布到项目问题跟踪器,不进行访谈,仅对已讨论的内容进行归纳综合。当用户希望将讨论内容整理成规格说明书时使用。

软件开发工程师需求澄清与上下文补全
★ 4
rubakas
rubakas/agent-notes

Agent 工作流跟踪器配置

setup-agent-tracker

为 agent-notes 工作流技能配置仓库的问题跟踪器、分诊(triage)标签词汇表以及领域文档布局。在开始使用新仓库时、仅需执行一次、且在执行 triage、to-spec、to-tickets 或 wayfinder 之前使用。

软件开发工程师工单与问题跟踪管理
★ 4