Write the current feature's documentation list (plan, architecture, operations manual, test records, review records) into the tasks/todo.md subsection of ## 参考文档 , so that subsequent development processes can look up documents by name.
Step 1: Ensure tasks/todo.md exists
Do not make any prior judgment; execute directly:
mkdir -p {project_root}/tasks
[ -f {project_root}/tasks/todo.md ] || printf '# Todo\n\n## 参考文档\n\n' > {project_root}/tasks/todo.md
grep -q '^## 参考文档' {project_root}/tasks/todo.md || printf '\n## 参考文档\n\n' >> {project_root}/tasks/todo.md
After execution completes,tasks/todo.md will definitely exist and contain the ## 参考文档 subsection.
Step 2: Determine the feature documentation directory
If a directory name is provided at call time:
First distinguish whether the directory is under the project root directory:
arg_dir="{传入的目录参数}"
resolved=$(realpath "$arg_dir" 2>/dev/null || echo "$arg_dir")
project_abs=$(realpath {project_root})
case "$resolved" in
"$project_abs"/*) echo "INSIDE:${resolved#$project_abs/}" ;;
*) echo "OUTSIDE:$resolved" ;;
esac
- Output
INSIDE:<rel>→ use the path relative to the project root directory<rel> - Output
OUTSIDE:<abs>→ Use the absolute path as-is, without relpath conversion(applicable to scenarios where the user manages plan files in an external documentation repository)
Then normalize the converted path and the directory name already recorded in the ## 参考文档 subsection by the same rules and compare them:
- Consistent: follow the existing plan and continue to Step 3
- Inconsistent or the subsection is empty: clear the
## 参考文档subsection, regenerate it according to the new directory name, and continue to Step 3
If no directory name is provided at call time:
Based on the current feature name (extracted from the session context or the title of the requirements analysis/technical design document), determine the subdirectory name under docs/ , format:docs/{feature-name}。
Step 3: Scan the feature documentation directory and assign a value to each type of file
The following commands must be executed; do not skip or replace them with subjective judgment. For existing files, take the most recently modified one; if there is none, generate a new file name ({feature-name} is the feature abbreviation,{today} is today's date yyyy-mm-dd):
d="{resolved_dir}"
feat="{feature-name}"
today="{today}"
FILE_PLAN=$(ls -t "$d"/plan-*.md 2>/dev/null | head -1); [ -z "$FILE_PLAN" ] && FILE_PLAN="plan-${feat}-${today}.md" || FILE_PLAN=$(basename "$FILE_PLAN")
FILE_ARCH=$(ls -t "$d"/arch-*.md 2>/dev/null | head -1); [ -z "$FILE_ARCH" ] && FILE_ARCH="arch-${feat}-${today}.md" || FILE_ARCH=$(basename "$FILE_ARCH")
FILE_OPS_MD=$(ls -t "$d"/ops-*.md 2>/dev/null | head -1); [ -z "$FILE_OPS_MD" ] && FILE_OPS_MD="ops-${feat}-${today}.md" || FILE_OPS_MD=$(basename "$FILE_OPS_MD")
FILE_OPS_SH=$(ls -t "$d"/ops-*.sh 2>/dev/null | head -1); [ -z "$FILE_OPS_SH" ] && FILE_OPS_SH="ops-${feat}-${today}.sh" || FILE_OPS_SH=$(basename "$FILE_OPS_SH")
FILE_REPORT=$(ls -t "$d"/report-*.md 2>/dev/null | head -1); [ -z "$FILE_REPORT" ] && FILE_REPORT="report-${feat}-${today}.md" || FILE_REPORT=$(basename "$FILE_REPORT")
FILE_REVIEW=$(ls -t "$d"/review-*.md 2>/dev/null | head -1); [ -z "$FILE_REVIEW" ] && FILE_REVIEW="review-${feat}-${today}.md" || FILE_REVIEW=$(basename "$FILE_REVIEW")
echo "PLAN: $FILE_PLAN"
echo "ARCH: $FILE_ARCH"
echo "OPS_MD: $FILE_OPS_MD"
echo "OPS_SH: $FILE_OPS_SH"
echo "REPORT: $FILE_REPORT"
echo "REVIEW: $FILE_REVIEW"
The output is the final file name, used directly in Step 4, and must not be modified.
Step 4: Write the list into tasks/todo.md
Write the assignment results from Step 3 into the tasks/todo.md subsection of ## 参考文档 (overwriting the existing content of that subsection):
## 参考文档
- 当前功能文档目录:{resolved_dir}
- 当前功能计划文档:{FILE_PLAN}
- 当前功能架构文档:{FILE_ARCH}
- 当前功能操作手册:{FILE_OPS_MD}
- 当前功能操作脚本:{FILE_OPS_SH}
- 当前功能测试记录文档:{FILE_REPORT}
- 当前功能评审记录文档:{FILE_REVIEW}
After writing, perform verification and display the result:
cat {project_root}/tasks/todo.md
Output tasks/todo.md 已更新 ✓, done.