Cathedral Audit
A structured process for measuring and closing spec-code drift in the Cathedral C# codebase.
When to Run
- - After a build wave (multiple features/refactors landed)
- Before starting a new major feature (establish baseline)
- When spec-code drift is suspected
- Periodically as a health check (not on a calendar — trigger on events)
Process Overview
CODEBLOCK0
Step 1: Forward Audit (Specs → Code)
For each spec in kitty-specs/, compare what the spec says against what the code does.
Output per spec: One of:
- - ✅ Conformant — code matches spec
- ⚠️ Divergent — code exists but differs from spec
- ❌ Missing — spec describes something not built
Deliverable: INLINECODE1
Use parallel CC agents (one per spec batch) for speed if memory allows. On memory-constrained hosts (e.g., WSL2), run sequentially — two concurrent CC sessions will OOM. Provide each agent read-only access.
Step 2: Reverse Audit (Code → Specs)
Scan all .cs files in src/Cathedral.Core/ and src/Cathedral.TestHarness/. For each file/subsystem, determine:
- - Is it covered by a spec?
- Does it match what the spec says?
- Is it dead/orphaned code?
Output sections:
- 1. Executive Summary — counts with delta from previous audit
- Unspecced Code — files/subsystems with no spec coverage
- Architectural Divergences — code takes a fundamentally different path than spec
- Code Exceeding Spec — code has features the spec doesn't document
- Dead/Orphaned Code — files with no callers or references
- Bugs Discovered — runtime, data, or logic bugs found during review
- Comparison with Previous Audit — what improved, what remains
Deliverable: INLINECODE5
Use parallel CC agents (group files by directory/subsystem) for speed if memory allows. Run sequentially on memory-constrained hosts.
Step 3: Consolidation & Prioritization
Merge findings from both audits into a prioritized action plan:
| Priority | Category | Criteria |
|---|
| P0 | Bug fixes | Runtime impact — broken endpoints, data corruption, crashes |
| P1 |
Dead code removal | Safe deletes that reduce confusion and LOC |
|
P2 | Data quality fixes | Dropped data, wrong defaults, double-logging |
|
P3 | Spec coverage | Write new specs for unspecced code (no code changes) |
|
P4 | Spec accuracy | Update existing specs to document code-exceeding-spec features |
|
P5 | Mechanical refactors | Renames, wiring, entity-scoping completion |
|
P6 | Architectural gaps | V2 features where code diverges from spec by design (defer) |
Rules:
- - Bugs always get their own section with severity ratings
- "Code exceeding spec" = spec update, not code change
- Architectural divergences that are intentionally deferred (V2 work) go to P6 and are documented but not actioned
- Each priority level should be achievable in a single CC session
Deliverable: Recommendations section in the reverse audit report.
Step 4: Execution
Execute fixes by priority tier (P0 first, P6 last or deferred).
Per priority tier:
- 1. Log intent to
memory/YYYY-MM-DD.md — tier name, CC session name, what's being attempted - Write a task briefing for CC (see
references/cc-task-template.md) - Launch CC session: INLINECODE8
- Set up monitoring cron (every 5 min)
- When CC completes: log results to daily memory — files changed, what was done, any issues
- Verify build before committing —
dotnet build must pass - If CC gets killed (OOM): check
git diff --stat, verify build manually, fix any issues, log the incident - Commit with descriptive message referencing the priority tier
- Log commit hash to daily memory
Hard rules:
- - ⚠️ ALWAYS verify
dotnet build passes before committing. No exceptions. CC may get OOM-killed mid-build-check. - ⚠️ ALWAYS log to daily memory file at every step. Log intent before launch, results after completion, commit hash after commit. If the session dies, the log survives for recovery.
- One commit per priority tier (or logical grouping)
Logging template for daily memory:
CODEBLOCK1
Step 5: Verification
After all tiers are complete, optionally run a quick re-audit to measure improvement:
- - Compare counts: unspecced, divergent, dead code, bugs
- Verify delta matches expectations
- Document remaining gaps and whether they're P6/deferred or newly discovered
Deliverable: Updated audit files with comparison section.
Logging
Every audit produces a complete trail in memory/YYYY-MM-DD.md:
- - Audit launch — which audits are being run, baseline reference
- Audit results — summary counts, key findings
- Each priority tier — intent, CC session, results, issues, commit hash
- Final summary — total commits, total lines changed, what's resolved vs deferred
This is non-negotiable. The Feb 17-18 amnesia incident proved that unlogged work is lost work. Log-then-act: write what you're about to do BEFORE doing it, then update with results.
Baseline Tracking
Always compare against the previous audit. Store audits as:
CODEBLOCK2
The executive summary table with deltas is the key metric:
CODEBLOCK3
CC Task Briefing Template
See references/cc-task-template.md for the standard format for CC task briefings.
大教堂审计
一种用于测量和弥合大教堂C#代码库中规范与代码之间偏差的结构化流程。
何时执行
- - 在构建波次之后(多个功能/重构已落地)
- 在开始新的主要功能之前(建立基线)
- 当怀疑规范与代码存在偏差时
- 定期作为健康检查(不按日历——按事件触发)
流程概览
- 1. 正向审计(规范 → 代码)
- 反向审计(代码 → 规范)
- 整合与优先级排序
- 执行
- 验证
步骤1:正向审计(规范 → 代码)
对于 kitty-specs/ 中的每个规范,比较规范所述内容与代码实际实现。
每个规范的输出: 以下之一:
- - ✅ 符合 — 代码与规范匹配
- ⚠️ 偏离 — 代码存在但与规范不同
- ❌ 缺失 — 规范描述了未构建的内容
交付物: kitty-specs/000-project-context/spec-audit-YYYY-MM-DD.md
如果内存允许,可使用并行CC代理(每个规范批次一个代理)以提高速度。在内存受限的主机(如WSL2)上,请顺序执行——两个并发CC会话会导致内存溢出。 为每个代理提供只读访问权限。
步骤2:反向审计(代码 → 规范)
扫描 src/Cathedral.Core/ 和 src/Cathedral.TestHarness/ 中的所有 .cs 文件。对于每个文件/子系统,确定:
- - 是否有规范覆盖?
- 是否与规范所述一致?
- 是否为死代码/孤立代码?
输出部分:
- 1. 执行摘要 — 计数及与上次审计的差异
- 无规范代码 — 没有规范覆盖的文件/子系统
- 架构偏差 — 代码采用与规范根本不同的路径
- 超出规范的代码 — 代码具有规范未记录的功能
- 死代码/孤立代码 — 没有调用者或引用的文件
- 发现的缺陷 — 审查期间发现的运行时、数据或逻辑错误
- 与上次审计的比较 — 哪些改进了,哪些仍然存在
交付物: kitty-specs/000-project-context/reverse-audit-YYYY-MM-DD.md
如果内存允许,可使用并行CC代理(按目录/子系统分组文件)以提高速度。在内存受限的主机上顺序执行。
步骤3:整合与优先级排序
将两次审计的发现合并为一份优先级行动计划:
| 优先级 | 类别 | 标准 |
|---|
| P0 | 缺陷修复 | 运行时影响 — 断开的端点、数据损坏、崩溃 |
| P1 |
死代码移除 | 安全删除,减少混乱和代码行数 |
|
P2 | 数据质量修复 | 数据丢失、错误默认值、重复日志记录 |
|
P3 | 规范覆盖 | 为无规范代码编写新规范(无代码更改) |
|
P4 | 规范准确性 | 更新现有规范以记录超出规范的功能 |
|
P5 | 机械性重构 | 重命名、连接、实体范围完善 |
|
P6 | 架构缺口 | V2功能,代码按设计偏离规范(推迟) |
规则:
- - 缺陷始终有自己独立的部分,并附有严重性评级
- 超出规范的代码 = 更新规范,而非更改代码
- 有意推迟的架构偏差(V2工作)归入P6,记录但不执行
- 每个优先级级别应能在单个CC会话中完成
交付物: 反向审计报告中的建议部分。
步骤4:执行
按优先级层级执行修复(P0优先,P6最后或推迟)。
每个优先级层级:
- 1. 记录意图 到 memory/YYYY-MM-DD.md — 层级名称、CC会话名称、尝试执行的内容
- 为CC编写任务简报(参见 references/cc-task-template.md)
- 启动CC会话:cat /tmp/task.md | claude -p --allowedTools Edit,Write,Read,Bash
- 设置监控定时任务(每5分钟)
- 当CC完成时:记录结果 到每日内存 — 更改的文件、完成的操作、任何问题
- 提交前验证构建 — dotnet build 必须通过
- 如果CC被终止(内存溢出):检查 git diff --stat,手动验证构建,修复任何问题,记录事件
- 提交并附上引用优先级层级的描述性消息
- 记录提交哈希 到每日内存
硬性规则:
- - ⚠️ 始终在提交前验证 dotnet build 通过。 无例外。CC可能在构建检查过程中被OOM终止。
- ⚠️ 始终在每个步骤记录到每日内存文件。 启动前记录意图,完成后记录结果,提交后记录提交哈希。如果会话死亡,日志仍可用于恢复。
- 每个优先级层级(或逻辑分组)一个提交
每日内存的日志记录模板:
markdown
[优先级层级名称]
- - CC会话:[名称](启动时间 ~HH:MM CST)
- 任务:[简要描述]
- 状态:[运行中 | ✅ 完成 | ❌ 失败 | ⚠️ 被终止]
- 更改的文件:[数量]
- 关键操作:[完成的操作]
- 问题:[遇到的任何问题]
- 提交为 [哈希]
步骤5:验证
所有层级完成后,可选择运行快速重新审计以衡量改进:
- - 比较计数:无规范代码、偏离代码、死代码、缺陷
- 验证差异是否符合预期
- 记录剩余的缺口以及它们是否为P6/推迟或新发现
交付物: 带有比较部分的更新审计文件。
日志记录
每次审计在 memory/YYYY-MM-DD.md 中生成完整轨迹:
- - 审计启动 — 正在运行的审计、基线参考
- 审计结果 — 摘要计数、关键发现
- 每个优先级层级 — 意图、CC会话、结果、问题、提交哈希
- 最终摘要 — 总提交数、总更改行数、已解决与推迟的内容
这是不可协商的。2月17-18日的失忆事件证明,未记录的工作就是丢失的工作。先记录后行动:在执行之前写下你将要做什么,然后用结果更新。
基线跟踪
始终与上次审计进行比较。将审计存储为:
kitty-specs/000-project-context/
spec-audit-YYYY-MM-DD.md (正向)
reverse-audit-YYYY-MM-DD.md (反向)
带有差异的执行摘要表是关键指标:
markdown
12 | 7 | -5 |
| 死代码 | 14 | 8 | -6 |
| 缺陷 | 0 | 8 | +8 |
| 符合 | ~60 | ~120 | +60 |
CC任务简报模板
参见 references/cc-task-template.md 获取CC任务简报的标准格式。