- 移除 TodoItem 中的 priority、created_at 和 updated_at 字段 - 强制每个任务都必须有唯一 id,且由用户负责生成 - 修改合并模式逻辑,merge=true 下保留未提及的旧任务 - 支持已完成和已取消任务重新激活(状态改回 pending 或 in_progress) - 禁止 in_progress 状态退回到 pending,必须标记为 completed 或 cancelled - 优化状态转换校验,允许特定状态间合法切换 - 简化任务变更消息,移除详细的新增/更新/移除统计 - 更新文档和示例,明确 id 必须由用户生成和使用 - 修复和补充测试,增强状态转换和合并模式验证 - 调整任务时间戳生成逻辑,统一使用当前时间及索引 - 该变更提供更合理的任务状态机械及管理模式,提升稳定性和易用性
11 KiB
知识整理工作流:Rollback
Loaded by states: ROLLBACK_CONFIRM, ROLLBACK, ROLLBACK_VERIFY, ROLLBACK_CLEANUP_CONFIRM, ROLLBACK_CLEANUP, ROLLBACK_CLEANUP_VERIFY.
This file owns recovery plan generation, recovery confirmation, recovery execution, recovery verification, cleanup confirmation, cleanup execution, and cleanup verification. It also defines the internal rollback_snapshot and execution_journal contracts.
It MUST NOT generate organization plans, revise classification rules, execute unconfirmed deletes, rename resources, modify permissions, or use wiki +move docs-to-wiki mode.
User-facing language should use "恢复到整理前的位置" / "恢复". Internal state and field names may use rollback.
Required Context
Before executing rules in this file:
active_plan_items,execution_scope,target_scope, andpath_token_mapMUST already exist.rollback_snapshotMUST have been built before the first write operation inEXECUTE.execution_journalMUST contain write-operation results fromEXECUTE.- Follow command syntax and risk behavior from referenced shortcut docs.
- Follow
Non-goalsfrom the main workflow entry.
Normal Path Visibility
Do not mention rollback, recovery readiness, snapshot, or journal on the normal successful execution path.
Load this file only after:
- Execution failed after one or more successful moves and the user chose to try restoring.
- Verification found serious mismatches and the user chose to try restoring.
- The user explicitly asks to rollback / recover the previous organization run.
Internal State Contracts
RollbackSnapshot
rollback_snapshot records original locations before any write command.
Fields:
| Field | Meaning |
|---|---|
plan_id |
Matching PlanItem.plan_id |
source_kind |
drive / wiki |
title |
Resource title |
type |
Resource type used by move commands |
original_token |
Original Drive token when applicable |
original_node_token |
Original Wiki node token when applicable |
original_parent_kind |
drive_folder / drive_root / wiki_node / wiki_space_root / unknown |
original_parent_token |
Original parent token; empty for root markers |
original_space_id |
Original Wiki space ID when restoring to Wiki space root |
original_path |
Original path before organization |
planned_target_parent_token |
Planned target parent token |
planned_target_path |
Planned target path |
rollback_supported |
Whether this item can be restored automatically |
rollback_blocker |
Reason when rollback_supported=false |
Rules:
- Store compact fields only. Do not store full API responses.
drive_rootandwiki_space_rootare valid origins; do not treat empty parent token as missing when the root marker is known.- Items without reliable origin can still execute, but MUST be marked
rollback_supported=false.
ExecutionJournal
execution_journal records every write attempt.
Fields:
| Field | Meaning |
|---|---|
journal_id |
Stable journal row ID |
plan_id |
Matching PlanItem.plan_id when applicable |
operation |
create_folder / create_node / move_drive / move_wiki_node / delete_created_folder / delete_created_node |
status |
success / failed / pending |
input_token |
Token supplied to the command |
input_node_token |
Wiki node token supplied to the command |
input_parent_token |
Source parent token when known |
target_parent_token |
Target parent token supplied to the command |
returned_token |
Token returned by the command |
returned_node_token |
Wiki node token returned by the command |
returned_parent_token |
Parent token returned by the command |
task_id |
Async task ID when returned |
next_command |
Async continuation command when returned |
error |
Error summary when failed |
created_by_workflow |
Whether the resource was created by this workflow run |
rollback_eligible |
Whether this successful operation can be included in rollback_plan |
Rules:
- Append a journal entry immediately after each write attempt.
create_folderandcreate_nodeentries MUST setcreated_by_workflow=true.- Successful
move_driveandmove_wiki_nodeentries may setrollback_eligible=trueonly when matching snapshot origin is supported. - Failed or pending moves MUST NOT enter automatic recovery execution.
- Async operations are
pendinguntildrive +task_resultproves completion.
State: ROLLBACK_CONFIRM
Entry: user chose to try restoring after execution failure / verification mismatch, or explicitly asked to rollback.
MUST:
- Generate
rollback_planfrom successful eligible move journal entries. - Use
execution_journalcurrent token / current node token as the recovery source. - Use
rollback_snapshotoriginal origin as the recovery target. - Generate recovery items in reverse successful move order.
- Exclude failed, pending, and unsupported items from executable recovery.
- Do not include delete actions in
rollback_plan. - Ask for explicit restore execution confirmation.
Confirmation output:
可恢复范围如下:
| 项目 | 数量 |
|------|------|
| 可尝试恢复到原位置 | <recoverable_move_count> |
| 无法安全自动恢复 | <unsupported_count> |
| 未完成 / 等待中的移动 | <pending_count> |
| 本次新建目录 / 节点 | <created_container_count> |
恢复操作只会尝试把已成功移动的资源移回原位置,不会删除、重命名或修改权限。是否执行恢复?
If no move can be restored automatically, report that no automatic restore is available and move to DONE.
Recovery Command Rules
Use only these command forms:
# Drive resource back to original parent folder
lark-cli drive +move \
--file-token <current_token> \
--type <type> \
--folder-token <original_parent_token>
# Drive resource back to root
lark-cli drive +move \
--file-token <current_token> \
--type <type>
# Wiki node back to original parent node
lark-cli wiki +move \
--node-token <current_node_token> \
--target-parent-token <original_parent_token>
# Wiki node back to original space root
lark-cli wiki +move \
--node-token <current_node_token> \
--target-space-id <original_space_id>
MUST NOT:
- Use
wiki +movedocs-to-wiki mode. - Move using path strings.
- Recover failed or pending moves as if they succeeded.
- Delete created folders / nodes in
ROLLBACK.
State: ROLLBACK
Entry: user explicitly confirmed restore execution.
MUST:
- Execute only confirmed
rollback_planitems. - Execute reverse moves in reverse successful move order.
- Continue async move tasks with
drive +task_resultwhen needed. - Record recovery success / failure per rollback item.
- Stop on blockers that make following recovery items unsafe.
Progress output should stay concise:
恢复进度:已尝试 <done>/<total> 项,失败 <failed_count> 项。
State: ROLLBACK_VERIFY
Entry: recovery execution finished.
MUST:
- Rescan the relevant Drive folder / Wiki nodes.
- Compare each rollback item with its original origin.
- Mark status per item.
- If cleanup candidates clearly remain from this workflow run, transition to
ROLLBACK_CLEANUP_CONFIRM. - Do not ask for deletion confirmation in this state.
Verification table:
| plan_id | 标题 | 原位置 | 当前实际位置 | 状态 | 失败原因 |
|---|
Status values:
| Status | Meaning |
|---|---|
rollback_success |
Resource is back under the original parent / root |
rollback_failed |
Resource is still outside the original origin |
missing |
Resource cannot be found |
needs_manual_review |
Actual state is ambiguous or affected by external changes |
Do not delete anything from this state.
State: ROLLBACK_CLEANUP_CONFIRM
Entry: cleanup candidates exist after recovery, or user asks to view / perform cleanup after recovery.
Cleanup is optional and separate from recovery. It may delete resources, so it requires separate confirmation.
Candidate rules:
- Candidate MUST have
created_by_workflow=trueinexecution_journal. - Candidate MUST be a Drive folder or Wiki node created by this workflow run.
- Candidate MUST currently be empty, or contain only workflow-created cleanup candidates that are themselves safe to delete.
- Candidate MUST NOT contain original resources, unknown resources, rollback-failed resources, or user-created resources.
- If child origin is uncertain, mark the candidate
cleanup_blocked.
Generate rollback_cleanup_plan with:
| Field | Meaning |
|---|---|
cleanup_id |
Stable cleanup row ID |
type |
drive_folder / wiki_node |
path |
Current path |
token |
Folder token or node token |
depth |
Current path depth |
safe_to_delete |
Whether deletion is allowed after confirmation |
blocker |
Reason when deletion is blocked |
Confirmation output:
恢复已完成。本次整理新建的部分空目录 / 节点如下,是否需要删除?
| 项目 | 数量 |
|------|------|
| 可删除的新建空目录 / 节点 | <safe_count> |
| 不可删除,需人工确认 | <blocked_count> |
注:删除只会作用于本次 workflow 新建且当前可安全清理的空目录 / 节点。
If the user wants details, paginate cleanup items at 20 rows per page.
State: ROLLBACK_CLEANUP
Entry: user explicitly confirmed cleanup deletion.
MUST:
- Delete only
safe_to_delete=truecleanup items. - Delete deepest paths first.
- Record delete results in
rollback_cleanup_results. - Continue async delete tasks with
drive +task_resultwhen needed.
Command forms:
# Delete workflow-created Drive folder
lark-cli drive +delete \
--file-token <folder_token> \
--type folder \
--yes
# Delete workflow-created Wiki node
lark-cli wiki +node-delete \
--node-token <node_token> \
--obj-type wiki \
--include-children=true \
--yes
--yes is allowed only after the user explicitly confirmed cleanup deletion.
MUST NOT:
- Delete original resources.
- Delete unknown resources.
- Delete rollback-failed resources.
- Delete non-empty folders / nodes that contain anything outside cleanup candidates.
- Delete a knowledge space.
State: ROLLBACK_CLEANUP_VERIFY
Entry: cleanup deletion finished.
MUST:
- Verify each confirmed cleanup target is gone.
- Report failed or pending deletes.
- Stop after reporting cleanup results.
Verification table:
| 类型 | 路径 | token | 状态 | 失败原因 |
|---|
Status values:
| Status | Meaning |
|---|---|
deleted |
Cleanup target was deleted |
delete_pending |
Async deletion is still pending |
delete_failed |
Delete command failed |
still_exists |
Target still exists after deletion attempt |
skipped |
Target was not safe to delete or user did not confirm it |