Skill站外收录 @skilllib/skill-2014279403616808963
skill-status-sync
确保任务状态在 TODO.md 和 state.json 两个文件间原子性同步更新,涵盖状态变更、任务创建、附件添加及元数据调整等操作,通过两阶段提交机制保障数据一致性,并在失败时尝试回滚。
效率工具 AI 技能
Skills.MD
# Status Sync Skill
Atomic status updates across TODO.md and state.json.
## Trigger Conditions
This skill activates when:
- Task status needs to change
- Artifacts are added to a task
- Task metadata needs updating
## Two-Phase Commit Pattern
### Phase 1: Prepare
1. **Read Current State** (using jq/grep for efficiency)
```bash
# Read task from state.json via jq (fast, ~12ms)
task_data=$(jq -r --arg num "$task_number" \
'.active_projects[] | select(.project_number == ($num | tonumber))' \
.claude/specs/state.json)
# Read next_project_number for create operations
next_num=$(jq -r '.next_project_number' .claude/specs/state.json)
# Find task section in TODO.md via grep
task_line=$(grep -n "^### ${task_number}\." .claude/specs/TODO.md | cut -d: -f1)
```
2. **Validate Task Exists**
- Check task_data is not empty (state.json)
- Check task_line is found (TODO.md)
- If not in both: Error
3. **Prepare Updates**
- Calculate new status
- Prepare jq update for state.json
- Prepare Edit for TODO.md task entry
- For create operations: also prepare frontmatter update
- Validate both are consistent
### Phase 2: Commit
1. **Write state.json First**
- Machine state is source of truth
- Faster to query and validate
2. **Write TODO.md Second**
- User-facing representation
- May have formatting variations
3. **Verify Both Updated**
- Re-read both files
- Confirm changes applied
### Rollback (if needed)
If any write fails:
1. Log the failure
2. Attempt to restore original state
3. Return error with details
## Status Mapping
| Operation | Old Status | New Status |
|-----------|------------|------------|
| Start research | not_started | researching |
| Complete research | researching | researched |
| Start planning | researched | planning |
| Complete planning | planning | planned |
| Start implement | planned | implementing |
| Complete implement | implementing | completed |
| Block task | any | blocked |
| Abandon task | any | abandoned |
## Task Creation (Special Case)
When creating a new task, BOTH files require additional updates beyond task entries:
### state.json Updates
```bash
jq --arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'.next_project_number = ($next_num | tonumber) + 1 |
.active_projects = [{new_task_object}] + .active_projects' \
.claude/specs/state.json > /tmp/state.json && \
mv /tmp/state.json .claude/specs/state.json
```
### TODO.md Updates (TWO parts)
1. **Frontmatter**: Update `next_project_number` in YAML frontmatter
```bash
# Use sed or Edit to update frontmatter
sed -i 's/^next_project_number: [0-9]*/next_project_number: NEW_NUM/' \
.claude/specs/TODO.md
```
2. **Task Entry**: Add entry under appropriate priority section
**CRITICAL**: `next_project_number` MUST match in both files after creation.
## Update Formats
### state.json Update
```json
{
"project_number": N,
"status": "new_status",
"last_updated": "ISO_TIMESTAMP",
"artifacts": [
{"path": "...", "type": "research|plan|summary"}
]
}
```
### TODO.md Update
```markdown
### {N}. {Title}
- **Status**: [{NEW_STATUS}]
- **{Artifact}**: [link](path)
```
## Execution Flow
```
1. Receive update request:
- task_number
- new_status
- artifacts (optional)
- metadata (optional)
2. Phase 1 - Prepare:
- Read both files
- Validate task exists
- Prepare updates
3. Phase 2 - Commit:
- Write state.json
- Write TODO.md
- Verify success
4. Return result
```
## Return Format
```json
{
"status": "completed|failed",
"summary": "Updated task #N to [STATUS]",
"task_number": N,
"old_status": "previous",
"new_status": "current",
"files_updated": [
".claude/specs/state.json",
".claude/specs/TODO.md"
]
}
```
## Error Handling
### File Read Error
```json
{
"status": "failed",
"error": "Could not read state.json",
"recovery": "Check file exists and permissions"
}
```
### Task Not Found
```json
{
"status": "failed",
"error": "Task #N not found",
"recovery": "Verify task number, check if archived"
}
```
### Write Failure
```json
{
"status": "failed",
"error": "Failed to write TODO.md",
"recovery": "Check permissions, state.json may be updated"
}
```
### Inconsistency Detected
```json
{
"status": "failed",
"error": "TODO.md and state.json inconsistent",
"recovery": "Run /task --sync to reconcile"
}
```
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「skill-status-sync」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次