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.





首頁
