feat(plane): add Plane-TODO sync script

Add plane-sync.js one-way (Plane -> TODO.md) synchronization for the
MITHOME project. Config reads from .mcp.json with .env override. CLI:
--list, --dry-run, --yes, --project, --verbose, --help. Interactive
discrepancy resolution (status mismatches, orphans, new issues), backup
before write, rate limiting. Pure functions covered by node:test unit
tests. Includes PLANE-SYNC-GUIDE.md and TODO.md changelog entry.
This commit is contained in:
Do Siki
2026-08-17 12:18:55 +02:00
parent 3c79a64903
commit f918e300a6
11 changed files with 845 additions and 9 deletions
+101
View File
@@ -0,0 +1,101 @@
// WHY: sections are identified by emoji header; order defines generated layout
const SECTIONS = [
{ key: 'completed', header: /^## ✅/, emoji: '✅', hasNote: false },
{ key: 'todo', header: /^## 🚀/, emoji: '⏳', hasNote: true },
{ key: 'inProgress', header: /^## 🔄/, emoji: '🔄', hasNote: true },
{ key: 'backlog', header: /^## 📋/, emoji: '📋', hasNote: false }
];
const SECTION_LABEL = {
completed: 'Befejezett',
todo: 'TODO',
inProgress: 'In Progress',
backlog: 'Backlog'
};
function parseTodoFile(content) {
const sections = {
completed: { header: null, rows: [] },
todo: { header: null, rows: [] },
inProgress: { header: null, rows: [] },
backlog: { header: null, rows: [] }
};
const rows = [];
let current = null;
for (const line of content.split('\n')) {
const sec = SECTIONS.find(s => s.header.test(line));
if (sec) {
current = sec.key;
if (!sections[current].header) sections[current].header = line;
continue;
}
if (!current || !line.trim().startsWith('|')) continue;
const cols = line.split('|').map(c => c.trim()).filter(c => c !== '');
if (cols.length < 3) continue;
if (cols[0] === 'Plane' || /^[-]+$/.test(cols[0])) continue;
const row = { id: cols[0], name: cols[1], status: cols[2], note: cols[3] || '' };
sections[current].rows.push(row);
rows.push({ section: current, ...row });
}
return { sections, rows };
}
function seqNum(id) {
const match = id.match(/(\d+)$/);
return match ? parseInt(match[1], 10) : 0;
}
function buildTable(sec, rows) {
const header = sec.hasNote
? '| Plane | Feladat | Státusz | Megjegyzés |'
: '| Plane | Feladat | Státusz |';
const separator = sec.hasNote
? '|-------|---------|---------|-----------|'
: '|-------|---------|---------|';
const body = rows
.slice()
.sort((a, b) => seqNum(a.id) - seqNum(b.id))
.map(row => {
if (sec.hasNote) return `| ${row.id} | ${row.name} | ${sec.emoji} | ${row.note || ''} |`;
return `| ${row.id} | ${row.name} | ${sec.emoji} |`;
});
return [header, separator, ...body].join('\n');
}
// WHY: only the section region is regenerated, prefix/suffix (overview, commands) are preserved
function regenerate(content, finalSections) {
const lines = content.split('\n');
const firstIdx = lines.findIndex(l => SECTIONS[0].header.test(l));
const backlogIdx = lines.findIndex(l => SECTIONS[3].header.test(l));
if (firstIdx === -1 || backlogIdx === -1) throw new Error('TODO.md section headers not found');
let endIdx = lines.length;
for (let i = backlogIdx + 1; i < lines.length; i++) {
if (lines[i].trim() === '---') {
endIdx = i;
break;
}
}
const prefix = lines.slice(0, firstIdx).join('\n');
const suffix = lines.slice(endIdx + 1).join('\n');
const headerOf = key => {
const sec = SECTIONS.find(s => s.key === key);
const idx = lines.findIndex(l => sec.header.test(l));
return idx >= 0 ? lines[idx].replace(/^## /, '') : key;
};
const blocks = SECTIONS.map(sec => {
const rows = finalSections[sec.key] || [];
return `## ${headerOf(sec.key)}\n\n${buildTable(sec, rows)}`;
});
const middle = blocks.join('\n\n---\n\n') + '\n\n---\n';
const result = `${prefix}${middle}${suffix}`;
return result.endsWith('\n') ? result : `${result}\n`;
}
module.exports = { SECTIONS, SECTION_LABEL, parseTodoFile, buildTable, regenerate, seqNum };