feat(todo): 子任务系统 — 复杂任务支持子任务拆解与依赖追踪
- 新增 `sub add <parent_id>` / `sub status <sid>` CLI 命令
- SID 格式 {parentId}{Letter},支持依赖声明(deps)与校验
- HTML 新增子任务展开块、进度徽章、依赖色标(绿=完成/红=未完成)
- 父任务全部子任务完成时自动转为「待验收」;手动设 done 时检查子任务
- 更新 /todo 命令文档补充 sub 子命令说明
- #21 已录入 8 个实现子任务(21A–21H),含完整依赖链
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+302
-26
@@ -10,7 +10,7 @@
|
||||
* accepted 已验收 仅限用户设置(手动编辑 JSON 或 `done <id>` 命令)
|
||||
*
|
||||
* 子命令:
|
||||
* add --title "..." [--level high|mid|low] [--tags a,b] [--desc "..."]
|
||||
* add --title "..." [--level high|mid|low] [--tier 1|2|3] [--tags a,b] [--desc "..."]
|
||||
* status <id> <open|doing|done> — 更新开发状态(Claude 可调用)
|
||||
* done <id> [--version vX.Y.Z] — 标记已验收交付(仅用户调用)
|
||||
* reject <id> --reason "原因" — 拒绝验收,退回 open 并升为 high(仅用户调用)
|
||||
@@ -18,6 +18,8 @@
|
||||
* rm <id>
|
||||
* list
|
||||
* render
|
||||
* sub add <parent_id> --title "..." [--tier 1|2|3] [--deps "21A,21B"]
|
||||
* sub status <sid> <open|doing|done> — 更新子任务状态(如 21A)
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
||||
@@ -37,6 +39,11 @@ const LEVEL_ORDER = { high: 0, mid: 1, low: 2 };
|
||||
const STATUS_LABEL = { open: '待开始', doing: '开发中', done: '待验收', accepted: '已验收' };
|
||||
const STATUS_ORDER = { open: 0, doing: 1, done: 2, accepted: 3 };
|
||||
|
||||
const TIER_LABEL = { 1: '一级', 2: '二级', 3: '三级' };
|
||||
|
||||
const SUB_STATUS_ICON = { open: '○', doing: '◐', done: '✓' };
|
||||
const SUB_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
|
||||
// ─── 数据读写 ────────────────────────────────────────────────────────────────
|
||||
|
||||
function load() {
|
||||
@@ -44,7 +51,6 @@ function load() {
|
||||
return { meta: { title: '酒库管理系统 — 项目 TODO', updated_at: now() }, seq: 0, items: [] };
|
||||
}
|
||||
const db = JSON.parse(readFileSync(DB, 'utf8'));
|
||||
// 迁移旧格式:无 status 字段时,依据 done 布尔值补全
|
||||
for (const item of db.items) {
|
||||
if (!item.status) {
|
||||
item.status = item.done ? 'accepted' : 'open';
|
||||
@@ -76,6 +82,45 @@ function gitTag() {
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 子任务工具 ──────────────────────────────────────────────────────────────
|
||||
|
||||
function nextSubtaskLetter(item) {
|
||||
const existing = (item.subtasks || []).map(s => s.sid);
|
||||
for (const l of SUB_LETTERS) {
|
||||
const sid = `${item.id}${l}`;
|
||||
if (!existing.includes(sid)) return l;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function parseSid(sid) {
|
||||
const m = String(sid).match(/^(\d+)([A-Za-z])$/);
|
||||
if (!m) return null;
|
||||
return { parentId: parseInt(m[1], 10), letter: m[2].toUpperCase() };
|
||||
}
|
||||
|
||||
function findSubtask(db, sid) {
|
||||
const parsed = parseSid(sid);
|
||||
if (!parsed) { console.error(`错误:无效子任务 ID "${sid}",格式应为 21A`); process.exit(1); }
|
||||
const parent = db.items.find(i => i.id === parsed.parentId);
|
||||
if (!parent) { console.error(`错误:找不到父任务 id=${parsed.parentId}`); process.exit(1); }
|
||||
const normalSid = sid.toUpperCase();
|
||||
const sub = (parent.subtasks||[]).find(s => s.sid === normalSid);
|
||||
if (!sub) { console.error(`错误:找不到子任务 ${normalSid}`); process.exit(1); }
|
||||
return { parent, sub };
|
||||
}
|
||||
|
||||
function subtasksDoneCount(item) {
|
||||
if (!item.subtasks || !item.subtasks.length) return { done: 0, total: 0 };
|
||||
const done = item.subtasks.filter(s => s.status === 'done' || s.status === 'accepted').length;
|
||||
return { done, total: item.subtasks.length };
|
||||
}
|
||||
|
||||
function allSubtasksDone(item) {
|
||||
const { done, total } = subtasksDoneCount(item);
|
||||
return total > 0 && done === total;
|
||||
}
|
||||
|
||||
// ─── 终端 summary ────────────────────────────────────────────────────────────
|
||||
|
||||
function levelText(level) {
|
||||
@@ -101,9 +146,20 @@ function printSummary(db) {
|
||||
if (byStatus[st].length === 0) continue;
|
||||
console.log(`${label}(${byStatus[st].length}):`);
|
||||
for (const i of byStatus[st]) {
|
||||
const tags = i.tags && i.tags.length ? ' ' + i.tags.join('/') : '';
|
||||
const lvl = LEVEL_LABEL[i.level] || i.level;
|
||||
console.log(` [${lvl}] #${i.id} ${i.title}${tags}`);
|
||||
const tags = i.tags && i.tags.length ? ' ' + i.tags.join('/') : '';
|
||||
const lvl = LEVEL_LABEL[i.level] || i.level;
|
||||
const tier = i.tier ? '·' + TIER_LABEL[i.tier] : '';
|
||||
const { done, total: stTotal } = subtasksDoneCount(i);
|
||||
const subInfo = stTotal > 0 ? ` [${done}/${stTotal}子任务]` : '';
|
||||
console.log(` [${lvl}${tier}] #${i.id} ${i.title}${tags}${subInfo}`);
|
||||
if (stTotal > 0) {
|
||||
for (const s of i.subtasks) {
|
||||
const icon = SUB_STATUS_ICON[s.status] || '○';
|
||||
const deps = s.deps && s.deps.length ? ` (需: ${s.deps.join(',')})` : '';
|
||||
const stier = s.tier ? ` [${TIER_LABEL[s.tier]}]` : '';
|
||||
console.log(` ${icon} ${s.sid}${stier} ${s.title}${deps}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +192,43 @@ function statusClass(status) {
|
||||
return { open: 's-open', doing: 's-doing', done: 's-done', accepted: 's-accepted' }[status] || 's-open';
|
||||
}
|
||||
|
||||
function renderSubtasks(item) {
|
||||
if (!item.subtasks || item.subtasks.length === 0) return '';
|
||||
const { done, total } = subtasksDoneCount(item);
|
||||
const pct = total > 0 ? Math.round(done / total * 100) : 0;
|
||||
|
||||
const subItems = item.subtasks.map(s => {
|
||||
const stCls = statusClass(s.status);
|
||||
const stLbl = STATUS_LABEL[s.status] || s.status;
|
||||
const icon = SUB_STATUS_ICON[s.status] || '○';
|
||||
const tierBadge = s.tier ? `<span class="tag tier-${s.tier}">${TIER_LABEL[s.tier]}</span>` : '';
|
||||
const depBadges = (s.deps||[]).map(dep => {
|
||||
const depSub = item.subtasks.find(x => x.sid === dep);
|
||||
const depDone = depSub && (depSub.status === 'done' || depSub.status === 'accepted');
|
||||
return `<span class="dep-badge ${depDone ? 'dep-done' : 'dep-pending'}" title="${dep} ${depDone ? '已完成' : '未完成'}">${esc(dep)}</span>`;
|
||||
}).join('');
|
||||
const depsHtml = s.deps && s.deps.length
|
||||
? `<span class="dep-section"><span class="dep-label">依赖:</span>${depBadges}</span>`
|
||||
: '';
|
||||
|
||||
return `<li class="subtask-item ${stCls}" data-sid="${esc(s.sid)}">
|
||||
<span class="sub-icon ${stCls}">${icon}</span>
|
||||
<span class="sub-sid">${esc(s.sid)}</span>
|
||||
<span class="sub-title">${esc(s.title)}</span>
|
||||
<div class="sub-badges">${tierBadge}<span class="tag status-badge ${stCls}">${stLbl}</span>${depsHtml}</div>
|
||||
</li>`;
|
||||
}).join('\n');
|
||||
|
||||
return `<div class="subtask-block">
|
||||
<div class="subtask-header">
|
||||
<span class="subtask-label">子任务</span>
|
||||
<span class="subtask-progress-text">${done} / ${total} 完成</span>
|
||||
<div class="subtask-progress-bar"><div class="subtask-progress-fill" style="width:${pct}%"></div></div>
|
||||
</div>
|
||||
<ul class="subtask-list">${subItems}</ul>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderItems(items) {
|
||||
if (!items.length) return '<p class="empty-tip">暂无条目</p>';
|
||||
return items.map(i => {
|
||||
@@ -149,27 +242,36 @@ function renderItems(items) {
|
||||
const rejectBtn = i.status === 'done'
|
||||
? `<button class="reject-btn" data-id="${i.id}" data-title="${esc(i.title)}">拒绝验收</button>`
|
||||
: '';
|
||||
const { done: subDone, total: subTotal } = subtasksDoneCount(i);
|
||||
const subProgressBadge = subTotal > 0
|
||||
? `<span class="tag sub-progress-badge">${subDone}/${subTotal} 子任务</span>`
|
||||
: '';
|
||||
const meta = `<div class="item-meta">
|
||||
<span class="meta-date">🕐 ${fmtDate(i.created_at)}</span>
|
||||
${i.status === 'accepted' ? `<span class="meta-date">✅ 验收 ${fmtDate(i.completed_at)}${i.version ? ' · <span class="ver-badge">'+esc(i.version)+'</span>' : ''}</span>` : ''}
|
||||
</div>`;
|
||||
const lvlCls = levelClass(i.level);
|
||||
const subtasksBlock = renderSubtasks(i);
|
||||
return `
|
||||
<li class="todo-card ${stCls}"
|
||||
data-id="${i.id}"
|
||||
data-level="${esc(i.level)}"
|
||||
data-status="${esc(i.status)}"
|
||||
data-tier="${esc(i.tier ?? '')}"
|
||||
data-tags="${esc((i.tags||[]).join(','))}">
|
||||
<div class="card-header">
|
||||
<span class="item-title">${esc(i.title)}</span>
|
||||
<div class="card-badges">
|
||||
<span class="tag status-badge ${stCls}">${stLbl}</span>
|
||||
<span class="tag ${lvlCls}">${levelText(i.level)}</span>
|
||||
${i.tier ? `<span class="tag tier-${i.tier}">${TIER_LABEL[i.tier]}</span>` : ''}
|
||||
${subProgressBadge}
|
||||
${rejectBtn}
|
||||
</div>
|
||||
</div>
|
||||
${rejectNote}
|
||||
${desc}
|
||||
${subtasksBlock}
|
||||
<div class="card-footer">
|
||||
<div class="tag-row">${tags}</div>
|
||||
${meta}
|
||||
@@ -269,7 +371,6 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
padding: 14px 18px; margin-bottom: 10px;
|
||||
border-left-width: 4px;
|
||||
}
|
||||
/* 卡片左边框颜色与状态匹配 */
|
||||
.todo-card.s-open { border-left-color: #3b82f6; }
|
||||
.todo-card.s-doing { border-left-color: #f97316; }
|
||||
.todo-card.s-done { border-left-color: #eab308; }
|
||||
@@ -297,6 +398,7 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
.t-tag { background: #efefef; color: #555; cursor: pointer; transition: .12s; }
|
||||
.t-tag:hover { background: #d9e8fb; color: #1d4ed8; }
|
||||
.ver-badge { font-weight: 700; color: #1f7a44; }
|
||||
.sub-progress-badge { background: #f0f4ff; color: #3730a3; }
|
||||
|
||||
/* 状态徽章 */
|
||||
.status-badge { font-size: 11.5px; }
|
||||
@@ -310,6 +412,11 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
.empty-tip { font-size: 14px; color: #8aa3c4; margin: 8px 0 24px; }
|
||||
.hidden { display: none !important; }
|
||||
|
||||
/* ── 改动等级徽章 ── */
|
||||
.tier-1 { background: #ede9fe; color: #6d28d9; }
|
||||
.tier-2 { background: #ccfbf1; color: #0f766e; }
|
||||
.tier-3 { background: #f1f5f9; color: #475569; }
|
||||
|
||||
/* ── 拒绝按钮 & 拒绝原因 ── */
|
||||
.reject-btn {
|
||||
padding: 3px 10px; border-radius: 6px; border: 1.5px solid #dc2626;
|
||||
@@ -324,6 +431,56 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
}
|
||||
.reject-date { color: #ef9999; font-size: 12px; }
|
||||
|
||||
/* ── 子任务区 ── */
|
||||
.subtask-block {
|
||||
margin-top: 12px; padding: 10px 14px;
|
||||
background: #f8fafc; border: 1px solid #e4e9ef; border-radius: 8px;
|
||||
}
|
||||
.subtask-header {
|
||||
display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap;
|
||||
}
|
||||
.subtask-label {
|
||||
font-size: 11px; font-weight: 700; color: #7b8794;
|
||||
text-transform: uppercase; letter-spacing: .6px;
|
||||
}
|
||||
.subtask-progress-text { font-size: 12px; color: #52606d; }
|
||||
.subtask-progress-bar {
|
||||
flex: 1; height: 5px; background: #e4e9ef; border-radius: 3px; min-width: 60px;
|
||||
}
|
||||
.subtask-progress-fill { height: 100%; background: #22c55e; border-radius: 3px; transition: width .4s; }
|
||||
.subtask-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
|
||||
.subtask-item {
|
||||
display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
|
||||
padding: 6px 10px; border-radius: 6px; font-size: 13px;
|
||||
background: #fff; border: 1px solid #e8edf2;
|
||||
}
|
||||
.subtask-item.s-done { background: #f0fdf4; border-color: #bbf7d0; }
|
||||
.subtask-item.s-doing { background: #fff7ed; border-color: #fed7aa; }
|
||||
.subtask-item.s-accepted { background: #f0fdf4; border-color: #bbf7d0; opacity: .75; }
|
||||
.sub-icon {
|
||||
width: 16px; text-align: center; font-size: 13px; font-weight: 700; flex-shrink: 0;
|
||||
}
|
||||
.sub-icon.s-done { color: #16a34a; }
|
||||
.sub-icon.s-doing { color: #ea580c; }
|
||||
.sub-icon.s-open { color: #93aec8; }
|
||||
.sub-icon.s-accepted { color: #16a34a; }
|
||||
.sub-sid {
|
||||
font-family: "JetBrains Mono", monospace; font-size: 11.5px;
|
||||
color: #52606d; font-weight: 700; min-width: 32px; flex-shrink: 0;
|
||||
}
|
||||
.sub-title { flex: 1; font-size: 13px; min-width: 120px; }
|
||||
.subtask-item.s-done .sub-title,
|
||||
.subtask-item.s-accepted .sub-title { text-decoration: line-through; color: #52606d; }
|
||||
.sub-badges { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
|
||||
.dep-section { display: flex; align-items: center; gap: 3px; }
|
||||
.dep-label { font-size: 11px; color: #8aa3c4; margin-right: 2px; }
|
||||
.dep-badge {
|
||||
padding: 1px 6px; border-radius: 8px; font-size: 11px;
|
||||
font-weight: 700; font-family: monospace; cursor: default;
|
||||
}
|
||||
.dep-done { background: #dcfce7; color: #166534; }
|
||||
.dep-pending { background: #fee2e2; color: #b91c1c; }
|
||||
|
||||
/* ── 拒绝 Modal ── */
|
||||
.modal-overlay {
|
||||
position: fixed; inset: 0; background: rgba(0,0,0,.45);
|
||||
@@ -392,6 +549,14 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
<button class="filter-btn" data-filter-status="done">待验收</button>
|
||||
<button class="filter-btn" data-filter-status="accepted">已验收</button>
|
||||
</div>
|
||||
<div class="filter-sep"></div>
|
||||
<div class="filter-group">
|
||||
<span class="filter-label">改动等级</span>
|
||||
<button class="filter-btn active" data-filter-tier="all">全部</button>
|
||||
<button class="filter-btn" data-filter-tier="1">一级</button>
|
||||
<button class="filter-btn" data-filter-tier="2">二级</button>
|
||||
<button class="filter-btn" data-filter-tier="3">三级</button>
|
||||
</div>
|
||||
${allTags.length ? `<div class="filter-sep"></div>
|
||||
<div class="filter-group">
|
||||
<span class="filter-label">平台 / 标签</span>
|
||||
@@ -445,23 +610,25 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
(function() {
|
||||
let curLevel = 'all';
|
||||
let curStatus = 'all';
|
||||
let curTier = 'all';
|
||||
let curTags = new Set();
|
||||
|
||||
function applyFilter() {
|
||||
document.querySelectorAll('.todo-card').forEach(card => {
|
||||
const lvl = card.dataset.level;
|
||||
const status = card.dataset.status;
|
||||
const tier = card.dataset.tier;
|
||||
const tags = card.dataset.tags ? card.dataset.tags.split(',') : [];
|
||||
|
||||
let show = true;
|
||||
if (curLevel !== 'all' && lvl !== curLevel) show = false;
|
||||
if (curStatus !== 'all' && status !== curStatus) show = false;
|
||||
if (curTier !== 'all' && String(tier) !== curTier) show = false;
|
||||
if (curTags.size > 0 && ![...curTags].some(t => tags.includes(t))) show = false;
|
||||
|
||||
card.classList.toggle('hidden', !show);
|
||||
});
|
||||
|
||||
// 筛选后自动展开包含结果的区域
|
||||
if (curStatus !== 'all') {
|
||||
const wrap = document.getElementById('list-wrap-' + curStatus);
|
||||
if (wrap) {
|
||||
@@ -472,7 +639,6 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
}
|
||||
}
|
||||
|
||||
// 重要度筛选
|
||||
document.querySelectorAll('[data-filter-level]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
curLevel = btn.dataset.filterLevel;
|
||||
@@ -481,7 +647,14 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
});
|
||||
});
|
||||
|
||||
// 状态筛选
|
||||
document.querySelectorAll('[data-filter-tier]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
curTier = btn.dataset.filterTier;
|
||||
document.querySelectorAll('[data-filter-tier]').forEach(b => b.classList.toggle('active', b === btn));
|
||||
applyFilter();
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-filter-status]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
curStatus = btn.dataset.filterStatus;
|
||||
@@ -490,7 +663,6 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
});
|
||||
});
|
||||
|
||||
// 标签筛选(多选)
|
||||
document.querySelectorAll('[data-filter-tag]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
const t = btn.dataset.filterTag;
|
||||
@@ -500,7 +672,6 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
});
|
||||
});
|
||||
|
||||
// 卡片标签 → 快速筛选
|
||||
document.querySelectorAll('.t-tag').forEach(tag => {
|
||||
tag.addEventListener('click', e => {
|
||||
e.stopPropagation();
|
||||
@@ -510,7 +681,6 @@ ul.todo-list { list-style: none; margin: 0; padding: 0; }
|
||||
});
|
||||
});
|
||||
|
||||
// 区域折叠切换
|
||||
document.querySelectorAll('.section-title[data-toggle]').forEach(title => {
|
||||
title.addEventListener('click', () => {
|
||||
const st = title.dataset.toggle;
|
||||
@@ -622,6 +792,8 @@ function cmdAdd(db, args) {
|
||||
const level = ['high','mid','low'].includes(args.level) ? args.level : 'mid';
|
||||
const tags = args.tags ? args.tags.split(',').map(t => t.trim()).filter(Boolean) : [];
|
||||
const desc = args.desc || null;
|
||||
const tierRaw = parseInt(args.tier, 10);
|
||||
const tier = [1,2,3].includes(tierRaw) ? tierRaw : null;
|
||||
|
||||
db.seq++;
|
||||
const item = {
|
||||
@@ -629,6 +801,7 @@ function cmdAdd(db, args) {
|
||||
title,
|
||||
desc,
|
||||
level,
|
||||
tier,
|
||||
tags,
|
||||
status: 'open',
|
||||
created_at: now(),
|
||||
@@ -640,11 +813,12 @@ function cmdAdd(db, args) {
|
||||
save(db);
|
||||
writeFileSync(HTML, buildHtml(db), 'utf8');
|
||||
|
||||
console.log(`✅ 已添加 #${item.id} [${levelText(level)}] ${title}${tags.length ? ' ' + tags.join('/') : ''}`);
|
||||
const tierStr = tier ? '·' + TIER_LABEL[tier] : '';
|
||||
console.log(`✅ 已添加 #${item.id} [${levelText(level)}${tierStr}] ${title}${tags.length ? ' ' + tags.join('/') : ''}`);
|
||||
printSummary(db);
|
||||
}
|
||||
|
||||
/** status <id> <open|doing|done> — Claude 可调用,accepted 由用户手动设置 */
|
||||
/** status <id> <open|doing|done> */
|
||||
function cmdStatus(db, args) {
|
||||
const id = args._[0];
|
||||
const newStatus = args._[1];
|
||||
@@ -658,9 +832,17 @@ function cmdStatus(db, args) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const item = findItem(db, id);
|
||||
item.status = newStatus;
|
||||
item.done = false;
|
||||
const item = findItem(db, id);
|
||||
|
||||
// 有未完成子任务时,禁止手动将父任务标记为 done
|
||||
if (newStatus === 'done' && !allSubtasksDone(item) && item.subtasks && item.subtasks.length > 0) {
|
||||
const { done: doneCount, total } = subtasksDoneCount(item);
|
||||
console.error(`❌ 父任务还有未完成的子任务(${doneCount}/${total} 完成),请先通过 sub status 完成所有子任务`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
item.status = newStatus;
|
||||
item.done = false;
|
||||
|
||||
save(db);
|
||||
writeFileSync(HTML, buildHtml(db), 'utf8');
|
||||
@@ -670,11 +852,17 @@ function cmdStatus(db, args) {
|
||||
printSummary(db);
|
||||
}
|
||||
|
||||
/** done <id> — 标记已验收交付(仅用户调用),记录版本号 */
|
||||
/** done <id> [--version vX.Y.Z] */
|
||||
function cmdDone(db, args) {
|
||||
const id = args._[0];
|
||||
const item = findItem(db, id);
|
||||
|
||||
// 有未完成子任务时提示警告(但允许用户强制验收)
|
||||
if (item.subtasks && item.subtasks.length > 0 && !allSubtasksDone(item)) {
|
||||
const { done: doneCount, total } = subtasksDoneCount(item);
|
||||
console.warn(`⚠️ 注意:还有未完成的子任务(${doneCount}/${total} 完成),已强制标记为验收`);
|
||||
}
|
||||
|
||||
let version = args.version || null;
|
||||
if (!version) {
|
||||
version = gitTag();
|
||||
@@ -693,7 +881,7 @@ function cmdDone(db, args) {
|
||||
printSummary(db);
|
||||
}
|
||||
|
||||
/** reject <id> --reason "原因" — 拒绝验收,退回 open 并升级为 high(仅 done 状态可用) */
|
||||
/** reject <id> --reason "原因" */
|
||||
function cmdReject(db, args) {
|
||||
const id = args._[0];
|
||||
const reason = (args.reason || '').trim();
|
||||
@@ -709,13 +897,13 @@ function cmdReject(db, args) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const prevLevel = item.level;
|
||||
item.status = 'open';
|
||||
item.done = false;
|
||||
item.level = 'high';
|
||||
const prevLevel = item.level;
|
||||
item.status = 'open';
|
||||
item.done = false;
|
||||
item.level = 'high';
|
||||
item.reject_reason = reason;
|
||||
item.rejected_at = now();
|
||||
item.version = null;
|
||||
item.rejected_at = now();
|
||||
item.version = null;
|
||||
|
||||
save(db);
|
||||
writeFileSync(HTML, buildHtml(db), 'utf8');
|
||||
@@ -767,6 +955,93 @@ function cmdRender(db) {
|
||||
console.log('🖨️ todo/todo.html 已重新渲染');
|
||||
}
|
||||
|
||||
// ─── 子任务命令 ───────────────────────────────────────────────────────────────
|
||||
|
||||
/** sub add <parent_id> --title "..." [--tier 1|2|3] [--deps "21A,21B"] */
|
||||
function cmdSubAdd(db, args) {
|
||||
const parentIdRaw = args._[0];
|
||||
const title = (args.title || '').trim();
|
||||
if (!parentIdRaw) { console.error('错误:请指定父任务 id,例如:sub add 21 --title "..."'); process.exit(1); }
|
||||
if (!title) { console.error('错误:--title 不能为空'); process.exit(1); }
|
||||
|
||||
const parent = findItem(db, parentIdRaw);
|
||||
if (!parent.subtasks) parent.subtasks = [];
|
||||
|
||||
const letter = nextSubtaskLetter(parent);
|
||||
if (!letter) { console.error('错误:子任务数量已达上限(26)'); process.exit(1); }
|
||||
|
||||
const sid = `${parent.id}${letter}`;
|
||||
const tierRaw = parseInt(args.tier, 10);
|
||||
const tier = [1,2,3].includes(tierRaw) ? tierRaw : null;
|
||||
const deps = args.deps
|
||||
? args.deps.split(',').map(d => d.trim().toUpperCase()).filter(Boolean)
|
||||
: [];
|
||||
|
||||
// 校验依赖的 sid 是否存在
|
||||
for (const dep of deps) {
|
||||
const exists = parent.subtasks.find(s => s.sid === dep);
|
||||
if (!exists) { console.error(`错误:依赖的子任务 ${dep} 不存在`); process.exit(1); }
|
||||
}
|
||||
|
||||
const sub = { sid, title, tier, deps, status: 'open', created_at: now() };
|
||||
parent.subtasks.push(sub);
|
||||
|
||||
// 有子任务的父任务自动进入 doing
|
||||
if (parent.status === 'open') {
|
||||
parent.status = 'doing';
|
||||
}
|
||||
|
||||
save(db);
|
||||
writeFileSync(HTML, buildHtml(db), 'utf8');
|
||||
|
||||
const tierStr = tier ? ` [${TIER_LABEL[tier]}]` : '';
|
||||
const depsStr = deps.length ? ` 依赖: ${deps.join(', ')}` : '';
|
||||
console.log(`✅ 已添加子任务 ${sid}${tierStr}「${title}」→ #${parent.id}「${parent.title}」${depsStr}`);
|
||||
printSummary(db);
|
||||
}
|
||||
|
||||
/** sub status <sid> <open|doing|done> */
|
||||
function cmdSubStatus(db, args) {
|
||||
const sid = (args._[0] || '').toUpperCase();
|
||||
const newStatus = args._[1];
|
||||
|
||||
if (!['open','doing','done'].includes(newStatus)) {
|
||||
console.error(`错误:无效状态 "${newStatus}",可选:open | doing | done`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const { parent, sub } = findSubtask(db, sid);
|
||||
sub.status = newStatus;
|
||||
|
||||
// 所有子任务完成时自动将父任务推进为 done(待验收)
|
||||
if (newStatus === 'done' && allSubtasksDone(parent)) {
|
||||
parent.status = 'done';
|
||||
parent.done = false;
|
||||
console.log(`🎉 所有子任务均已完成,父任务 #${parent.id}「${parent.title}」自动转为「待验收」`);
|
||||
}
|
||||
|
||||
save(db);
|
||||
writeFileSync(HTML, buildHtml(db), 'utf8');
|
||||
|
||||
const emoji = { open: '📋', doing: '🔨', done: '🔍' }[newStatus];
|
||||
console.log(`${emoji} ${sub.sid}「${sub.title}」→ ${STATUS_LABEL[newStatus]}`);
|
||||
printSummary(db);
|
||||
}
|
||||
|
||||
/** sub <subcmd> ... */
|
||||
function cmdSub(db, args) {
|
||||
const subCmd = args._[0];
|
||||
const subArgs = { ...args, _: args._.slice(1) };
|
||||
|
||||
switch (subCmd) {
|
||||
case 'add': cmdSubAdd(db, subArgs); break;
|
||||
case 'status': cmdSubStatus(db, subArgs); break;
|
||||
default:
|
||||
console.error(`未知子命令:sub ${subCmd}\n用法:\n node todo.mjs sub add <parent_id> --title "..." [--tier N] [--deps "21A,21B"]\n node todo.mjs sub status <sid> <open|doing|done>`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 入口 ────────────────────────────────────────────────────────────────────
|
||||
|
||||
const [,, subcmd, ...rest] = process.argv;
|
||||
@@ -780,11 +1055,12 @@ switch (subcmd) {
|
||||
case 'reject': cmdReject(db, args); break;
|
||||
case 'reopen': cmdReopen(db, args); break;
|
||||
case 'rm': cmdRm(db, args); break;
|
||||
case 'sub': cmdSub(db, args); break;
|
||||
case 'list':
|
||||
case undefined:
|
||||
case '': cmdList(db); break;
|
||||
case 'render': cmdRender(db); break;
|
||||
default:
|
||||
console.error(`未知子命令:${subcmd}\n用法:node todo.mjs add|status|done|reject|reopen|rm|list|render`);
|
||||
console.error(`未知子命令:${subcmd}\n用法:node todo.mjs add|status|done|reject|reopen|rm|sub|list|render`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user