tc-tracker
alirezarezvani/claude-skills
使用结构化的 JSON 记录跟踪代码变更,通过强制的状态机以及用于 AI 连续性的会话移交格式。
...展开全部TC Tracker
通过结构化的 JSON 记录、强制的状态机以及会话交接格式,追踪每一次代码变更。当之前的会话过期时,新的 AI 会话可以据此干净地恢复工作。
概述
技术变更(TC)是一条结构化记录,它捕获了什么发生了变更、为什么变更、谁执行的变更、何时变更、如何测试以及工作进展(供下一会话使用)。这些记录以 JSON 格式存储在目标项目的 docs/TC/ 目录中,并经过严格模式验证和状态机校验。
在以下情况下使用此技能:
- 用户要求“追踪此变更”或希望获得代码修改的审计轨迹
- 希望将在进行中的工作交接给未来的 AI 会话
- 需要超越提交消息的结构化发布说明
- 正在对现有项目进行入职培训,并希望进行回溯性的变更文档记录
- 请求执行
/tc init、/tc create、/tc update、/tc status、/tc resume或/tc close
在以下情况下请勿使用此技能:
- 用户仅希望从 git 历史记录中生成变更日志(请使用
engineering/changelog-generator) - 用户仅希望追踪技术债务项(请使用
engineering/tech-debt-tracker) - 变更微不足道(如拼写错误、格式调整)且不会影响行为
存储布局
每个项目在 {project_root}/docs/TC/ 下存储 TC:
docs/TC/
├── tc_config.json # 项目设置
├── tc_registry.json # 主索引 + 统计信息
├── records/
│ └── TC-001-04-05-26-user-auth/
│ └── tc_record.json # 唯一事实来源
└── evidence/
└── TC-001/ # 日志片段、命令输出、截图
TC ID 约定
- 父级 TC:
TC-NNN-MM-DD-YY-functionality-slug(例如TC-001-04-05-26-user-authentication) - 子级 TC:
TC-NNN.A或TC-NNN.A.1(字母表示修订,数字表示子修订) NNN为顺序编号,MM-DD-YY为创建日期,slug 为短横线命名法。
状态机
planned -> in_progress -> implemented -> tested -> deployed
| | | | |
+-> blocked -+ +- in_progress planned
请参阅 references/lifecycle.md 以获取完整的转换表和恢复流程。
工作流命令
该技能附带五个 Python 脚本,用于对 TC 记录执行确定性、仅使用标准库的操作。每个脚本均支持 --help 和 --json。
1. 在项目初始化追踪
python3 scripts/tc_init.py --project "My Project" --root .
创建 docs/TC/、docs/TC/records/、docs/TC/evidence/、tc_config.json 和 tc_registry.json。幂等操作——重新运行会报告“已初始化”及当前统计信息。
2. 创建新的 TC 记录
python3 scripts/tc_create.py \
--root . \
--name "user-authentication" \
--title "Add JWT-based user authentication" \
--scope feature \
--priority high \
--summary "Adds JWT login + middleware" \
--motivation "Required for protected endpoints"
生成下一个顺序 TC ID,创建记录目录,写入完全填充的 tc_record.json(状态为 planned,R1 创建修订版),并更新注册表。
3. 更新 TC 记录
# 状态转换(根据状态机验证)
python3 scripts/tc_update.py --root . --tc-id TC-001-04-05-26-user-auth \
--set-status in_progress --reason "Starting implementation"
# 添加文件
python3 scripts/tc_update.py --root . --tc-id TC-001-04-05-26-user-auth \
--add-file src/auth.py:created
# 附加交接数据
python3 scripts/tc_update.py --root . --tc-id TC-001-04-05-26-user-auth \
--handoff-progress "JWT middleware wired up" \
--handoff-next "Write integration tests" \
--handoff-next "Update README"
每次更改都会追加一个顺序的 R<n></n> 修订条目,刷新 updated 字段,并在原子写入(.tmp 然后重命名)之前根据模式重新验证。
4. 查看状态
# 单个 TC
python3 scripts/tc_status.py --root . --tc-id TC-001-04-05-26-user-auth
# 所有 TC(注册表摘要)
python3 scripts/tc_status.py --root . --all --json
5. 验证记录或注册表
python3 scripts/tc_validator.py --record docs/TC/records/TC-001-.../tc_record.json
python3 scripts/tc_validator.py --registry docs/TC/tc_registry.json
验证器强制执行模式,检查状态机合法性,验证顺序 R<n></n> 和 T<n></n> ID,并断言审批一致性(approved=true 需要 approved_by 和 approved_date)。
请参阅 references/tc-schema.md 以获取完整模式。
斜杠命令分发器
仓库在 commands/tc.md 处提供了一个 /tc 斜杠命令,该命令根据子命令分发到这些脚本:
| 命令 | 操作 |
|---|---|
| `/tc init` | 为当前项目运行 `tc_init.py` |
| `/tc create | 提示输入字段,运行 `tc_create.py` |
| `/tc update | 通过 `tc_update.py` 应用用户描述的更改 |
| `/tc status [tc-id]` | 运行 `tc_status.py` |
| `/tc resume | 显示交接信息,归档先前会话,开始新会话 |
| `/tc close | 转换到 `deployed`,设置审批 |
| `/tc export` | 重新渲染所有派生工件 |
| `/tc dashboard` | 重新渲染注册表摘要 |
斜杠命令是用户界面;Python 脚本是引擎。
会话交接格式
交接块位于每个 TC 内的 session_context.handoff,这是 AI 连续性最重要的字段。它包含:
progress_summary— 已完成的工作next_steps— 剩余操作的有序列表blockers— 阻碍进展的任何事项key_context— 关键决策、陷阱、后续机器人必须了解的模式files_in_progress— 正在编辑的文件及其状态(editing、needs_review、partially_done、ready)decisions_made— 带有理由和时间戳的架构决策
请参阅 references/handoff-format.md 以获取完整结构和填写规则。
验证规则(始终强制执行)
- 状态机 — 仅允许有效的转换。
- 顺序 ID —
revision_history使用R1, R2, R3...;test_cases使用T1, T2, T3...。 - 追加式历史 — 修订条目永远不会被修改或删除。
- 审批一致性 —
approved=true需要approved_by和approved_date。 - TC ID 格式 — 必须匹配
TC-NNN-MM-DD-YY-slug。 - 子级 TC ID 格式 — 必须匹配
TC-NNN.A或TC-NNN.A.N。 - 原子写入 — JSON 先写入
.tmp,然后重命名。 - 注册表统计信息 — 每次写入注册表时重新计算。
非阻塞记账模式
TC 追踪不得中断主要工作流。
- 切勿停下来即时更新 TC 记录。 继续编码。
- 在自然里程碑处,生成一个后台子代理来更新记录。
- 仅在真正需要时提出疑问(“这项工作与任何活动 TC 不匹配——是否创建一个?”),并且每个会话只问一次,而不是每个文件问一次。
- 在会话结束时,在关闭前写入最终的交接块。
回溯批量创建
为了对具有未记录历史记录的现有项目进行入职培训,构建一个 retro_changelog.json(每个逻辑变更一个条目),并在循环中将其提供给 tc_create.py,或者扩展脚本以支持批处理模式。按功能对提交进行分组,而不是按文件分组。
反模式
| 反模式 | 为什么不好 | 应改为执行此操作 |
|---|---|---|
| 编辑 `revision_history` 以“修复”拼写错误 | 历史是追加式的——篡改会破坏审计轨迹 | 添加一个新的修订版以更正该字段 |
| 跳过状态机(“直接将状态设置为 deployed”) | 绕过验证并隐藏跳过的阶段 | 逐步执行 `in_progress -> implemented -> tested -> deployed` |
| 为每个更改的文件创建一个 TC | 碎片化相关工作并导致注册表爆炸 | 每个逻辑单元(功能、修复、重构)一个 TC |
| 在每次代码编辑之间即时更新 TC | 减慢主代理速度,浪费上下文 | 在里程碑处生成后台子代理 |
| 在没有 `approved_by` 的情况下标记 `approved=true` | 验证器将拒绝;误导审计轨迹 | 始终同时设置 `approved_by` 和 `approved_date` |
| 使用文本编辑器直接覆盖 `tc_record.json` | 可能导致写入过程中损坏并跳过验证 | 使用 `tc_update.py`(原子写入 + 模式检查) |
| 在 `notes` 或证据中放置密钥 | 记录会提交到仓库 | 引用环境变量或外部密钥存储 |
| 删除后重用 TC ID | 破坏顺序保证并混淆历史 | 仅向前递增——永不回收 |
| 让 `next_steps` 过时 | 违背了交接的目的 | 在每个里程碑处更新,即使“没有任何更改” |
交叉引用
engineering/changelog-generator— 从 Conventional Commits 生成 Keep-a-Changelog 发布说明。将其与 TC 追踪器配对:TC 用于细粒度的逐变更审计轨迹,changelog 用于面向用户的发布说明。engineering/tech-debt-tracker— 用于追踪长期债务项,而非离散的代码变更。engineering/focused-fix— 当 bug 修复需要系统性的全功能修复时,先运行/focused-fix,然后将结果捕获为 TC。project-management/decision-log— 在 TC 的decisions_made块中做出的架构决策也可以提升为项目范围的决策日志。engineering-team/code-reviewer— 合并前审查自然地融入tested -> deployed转换中;将审查者捕获在approval.approved_by中。
本技能中的参考
- references/tc-schema.md — TC 记录和注册表的完整 JSON 模式。
- references/lifecycle.md — 状态机、有效转换和恢复流程。
- references/handoff-format.md — 会话交接结构和最佳实践。
---
name: tc-tracker
description: Track code changes with structured JSON records, an enforced state machine, and a session handoff format for AI continuity.
---
# TC Tracker
Track every code change with structured JSON records, an enforced state machine, and a session handoff format that lets a new AI session resume work cleanly when a previous one expires.
## Overview
A Technical Change (TC) is a structured record that captures **what** changed, **why** it changed, **who** changed it, **when** it changed, **how it was tested**, and **where work stands** for the next session. Records live as JSON in `docs/TC/` inside the target project, validated against a strict schema and a state machine.
**Use this skill when the user:**
- Asks to "track this change" or wants an audit trail for code modifications
- Wants to hand off in-progress work to a future AI session
- Needs structured release notes that go beyond commit messages
- Onboards an existing project and wants retroactive change documentation
- Asks for `/tc init`, `/tc create`, `/tc update`, `/tc status`, `/tc resume`, or `/tc close`
**Do NOT use this skill when:**
- The user only wants a changelog from git history (use `engineering/changelog-generator`)
- The user only wants to track tech debt items (use `engineering/tech-debt-tracker`)
- The change is trivial (typo, formatting) and won't affect behavior
## Storage Layout
Each project stores TCs at `{project_root}/docs/TC/`:
```
docs/TC/
├── tc_config.json # Project settings
├── tc_registry.json # Master index + statistics
├── records/
│ └── TC-001-04-05-26-user-auth/
│ └── tc_record.json # Source of truth
└── evidence/
└── TC-001/ # Log snippets, command output, screenshots
```
## TC ID Convention
- **Parent TC:** `TC-NNN-MM-DD-YY-functionality-slug` (e.g., `TC-001-04-05-26-user-authentication`)
- **Sub-TC:** `TC-NNN.A` or `TC-NNN.A.1` (letter = revision, digit = sub-revision)
- `NNN` is sequential, `MM-DD-YY` is the creation date, slug is kebab-case.
## State Machine
```
planned -> in_progress -> implemented -> tested -> deployed
| | | | |
+-> blocked -+ +- in_progress <-------+
| (rework / hotfix)
+-> planned
```
> See [references/lifecycle.md](references/lifecycle.md) for the full transition table and recovery flows.
## Workflow Commands
The skill ships five Python scripts that perform deterministic, stdlib-only operations on TC records. Each one supports `--help` and `--json`.
### 1. Initialize tracking in a project
```bash
python3 scripts/tc_init.py --project "My Project" --root .
```
Creates `docs/TC/`, `docs/TC/records/`, `docs/TC/evidence/`, `tc_config.json`, and `tc_registry.json`. Idempotent — re-running reports "already initialized" with current stats.
### 2. Create a new TC record
```bash
python3 scripts/tc_create.py \
--root . \
--name "user-authentication" \
--title "Add JWT-based user authentication" \
--scope feature \
--priority high \
--summary "Adds JWT login + middleware" \
--motivation "Required for protected endpoints"
```
Generates the next sequential TC ID, creates the record directory, writes a fully populated `tc_record.json` (status `planned`, R1 creation revision), and updates the registry.
### 3. Update a TC record
```bash
# Status transition (validated against the state machine)
python3 scripts/tc_update.py --root . --tc-id TC-001-04-05-26-user-auth \
--set-status in_progress --reason "Starting implementation"
# Add a file
python3 scripts/tc_update.py --root . --tc-id TC-001-04-05-26-user-auth \
--add-file src/auth.py:created
# Append handoff data
python3 scripts/tc_update.py --root . --tc-id TC-001-04-05-26-user-auth \
--handoff-progress "JWT middleware wired up" \
--handoff-next "Write integration tests" \
--handoff-next "Update README"
```
Every change appends a sequential `R<n>` revision entry, refreshes `updated`, and re-validates against the schema before writing atomically (`.tmp` then rename).
### 4. View status
```bash
# Single TC
python3 scripts/tc_status.py --root . --tc-id TC-001-04-05-26-user-auth
# All TCs (registry summary)
python3 scripts/tc_status.py --root . --all --json
```
### 5. Validate a record or registry
```bash
python3 scripts/tc_validator.py --record docs/TC/records/TC-001-.../tc_record.json
python3 scripts/tc_validator.py --registry docs/TC/tc_registry.json
```
Validator enforces the schema, checks state-machine legality, verifies sequential `R<n>` and `T<n>` IDs, and asserts approval consistency (`approved=true` requires `approved_by` and `approved_date`).
> See [references/tc-schema.md](references/tc-schema.md) for the full schema.
## Slash-Command Dispatcher
The repo ships a `/tc` slash command at `commands/tc.md` that dispatches to these scripts based on subcommand:
| Command | Action |
|---------|--------|
| `/tc init` | Run `tc_init.py` for the current project |
| `/tc create <name>` | Prompt for fields, run `tc_create.py` |
| `/tc update <tc-id>` | Apply user-described changes via `tc_update.py` |
| `/tc status [tc-id]` | Run `tc_status.py` |
| `/tc resume <tc-id>` | Display handoff, archive prior session, start a new one |
| `/tc close <tc-id>` | Transition to `deployed`, set approval |
| `/tc export` | Re-render all derived artifacts |
| `/tc dashboard` | Re-render the registry summary |
The slash command is the user interface; the Python scripts are the engine.
## Session Handoff Format
The handoff block lives at `session_context.handoff` inside each TC and is the single most important field for AI continuity. It contains:
- `progress_summary` — what has been done
- `next_steps` — ordered list of remaining actions
- `blockers` — anything preventing progress
- `key_context` — critical decisions, gotchas, patterns the next bot must know
- `files_in_progress` — files being edited and their state (`editing`, `needs_review`, `partially_done`, `ready`)
- `decisions_made` — architectural decisions with rationale and timestamp
> See [references/handoff-format.md](references/handoff-format.md) for the full structure and fill-out rules.
## Validation Rules (Always Enforced)
1. **State machine** — only valid transitions are allowed.
2. **Sequential IDs** — `revision_history` uses `R1, R2, R3...`; `test_cases` uses `T1, T2, T3...`.
3. **Append-only history** — revision entries are never modified or deleted.
4. **Approval consistency** — `approved=true` requires `approved_by` and `approved_date`.
5. **TC ID format** — must match `TC-NNN-MM-DD-YY-slug`.
6. **Sub-TC ID format** — must match `TC-NNN.A` or `TC-NNN.A.N`.
7. **Atomic writes** — JSON is written to `.tmp` then renamed.
8. **Registry stats** — recomputed on every registry write.
## Non-Blocking Bookkeeping Pattern
TC tracking must NOT interrupt the main workflow.
- **Never stop to update TC records inline.** Keep coding.
- At natural milestones, spawn a background subagent to update the record.
- Surface questions only when genuinely needed ("This work doesn't match any active TC — create one?"), and ask once per session, not per file.
- At session end, write a final handoff block before closing.
## Retroactive Bulk Creation
For onboarding an existing project with undocumented history, build a `retro_changelog.json` (one entry per logical change) and feed it to `tc_create.py` in a loop, or extend the script for batch mode. Group commits by feature, not by file.
## Anti-Patterns
| Anti-pattern | Why it's bad | Do this instead |
|--------------|--------------|-----------------|
| Editing `revision_history` to "fix" a typo | History is append-only — tampering destroys the audit trail | Add a new revision that corrects the field |
| Skipping the state machine ("just set status to deployed") | Bypasses validation and hides skipped phases | Walk through `in_progress -> implemented -> tested -> deployed` |
| Creating one TC per file changed | Fragments related work and explodes the registry | One TC per logical unit (feature, fix, refactor) |
| Updating TC inline between every code edit | Slows the main agent, wastes context | Spawn a background subagent at milestones |
| Marking `approved=true` without `approved_by` | Validator will reject; misleading audit trail | Always set `approved_by` and `approved_date` together |
| Overwriting `tc_record.json` directly with a text editor | Risks corruption mid-write and skips validation | Use `tc_update.py` (atomic write + schema check) |
| Putting secrets in `notes` or evidence | Records are committed to the repo | Reference an env var or external secret store |
| Reusing TC IDs after deletion | Breaks the sequential guarantee and confuses history | Increment forward only — never recycle |
| Letting `next_steps` go stale | Defeats the purpose of handoff | Update on every milestone, even if it's "nothing changed" |
## Cross-References
- `engineering/changelog-generator` — Generates Keep-a-Changelog release notes from Conventional Commits. Pair it with TC tracker: TC for the granular per-change audit trail, changelog for user-facing release notes.
- `engineering/tech-debt-tracker` — For tracking long-lived debt items rather than discrete code changes.
- `engineering/focused-fix` — When a bug fix needs systematic feature-wide repair, run `/focused-fix` first then capture the result as a TC.
- `project-management/decision-log` — Architectural decisions made inside a TC's `decisions_made` block can also be promoted to a project-wide decision log.
- `engineering-team/code-reviewer` — Pre-merge review fits naturally into the `tested -> deployed` transition; capture the reviewer in `approval.approved_by`.
## References in This Skill
- [references/tc-schema.md](references/tc-schema.md) — Full JSON schema for TC records and the registry.
- [references/lifecycle.md](references/lifecycle.md) — State machine, valid transitions, and recovery flows.
- [references/handoff-format.md](references/handoff-format.md) — Session handoff structure and best practices.





首页
