notParsec / 문서전체 문서

생성 코드·템플릿

development-progress.js

design/development-progress.js

출처: 현재 작업 폴더 · 원문 다운로드

(function (root) {
  'use strict';
  const states = { todo: '미착수', doing: '진행 중', validation: '검증 대기', done: '완료', blocked: '차단' };
  const stages = { documented: '명세 있음', pending: '미확인', partial: '일부 확인', complete: '확인 완료', na: '해당 없음' };
  const stageNames = { design: '설계', code: '구현', test: '검증', integration: '통합' };
  const parityStates = { unreviewed: '원본 대조 전', different: '원본과 불일치', matched: '원본 일치 확인', exception_verified: '명시 예외 검증' };
  function validate(plan, report) {
    if (report.schemaVersion !== 1 || report.planVersion !== plan.planVersion) throw new Error('개발 기록의 설계 버전 불일치');
    const ids = plan.features.map(f => f.id);
    if (Object.keys(report.features).length !== ids.length || ids.some(id => !Object.hasOwn(report.features, id))) throw new Error('전체 기능의 개발 기록이 필요합니다.');
    const checkEvidence = e => {
      if (!e.label || !/^(?:\.\.\/)?[\w./-]+$/.test(e.path) || e.path.includes('..', 3)) throw new Error('잘못된 근거 링크');
    };
    for (const f of plan.features) {
      const r = report.features[f.id];
      if (!Object.hasOwn(states, r.state) || !r.summary || !r.checkedAt || !Array.isArray(r.remaining) || !Array.isArray(r.evidence)) throw new Error('잘못된 개발 기록: ' + f.id);
      if (r.stages?.design !== 'documented' || ['code', 'test', 'integration'].some(k => !['pending', 'partial', 'complete', 'na'].includes(r.stages[k]))) throw new Error('잘못된 작업 단계: ' + f.id);
      r.evidence.forEach(checkEvidence);
      if (r.state !== 'todo' && !r.evidence.length) throw new Error('진행 근거가 필요합니다: ' + f.id);
      if (r.state === 'todo' && ['code', 'test', 'integration'].some(k => !['pending', 'na'].includes(r.stages[k]))) throw new Error('미착수와 구현 단계가 다릅니다: ' + f.id);
      if (r.state === 'validation' && r.stages.code !== 'complete') throw new Error('검증 대기는 구현 완료 후 기록합니다: ' + f.id);
      if (r.state === 'done' && (r.remaining.length || ['code', 'test', 'integration'].some(k => !['complete', 'na'].includes(r.stages[k])) || f.dependencies.some(id => report.features[id].state !== 'done'))) throw new Error('전체 완료 근거가 부족합니다: ' + f.id);
      if (r.state !== 'done' && !r.remaining.length) throw new Error('남은 작업이 필요합니다: ' + f.id);
      if (plan.parityPolicy) {
        const p = r.parity;
        if (!p || !Object.hasOwn(parityStates, p.status) || !Array.isArray(p.sourceEvidence) || !Array.isArray(p.comparisonEvidence) || !Array.isArray(p.exceptionIds)) throw new Error('원본 대조 기록이 필요합니다: ' + f.id);
        [...p.sourceEvidence, ...p.comparisonEvidence].forEach(checkEvidence);
        if (p.exceptionIds.some(id => !plan.parityPolicy.exceptions.some(e => e.id === id))) throw new Error('명시되지 않은 예외: ' + f.id);
        const verified = ['matched', 'exception_verified'].includes(p.status);
        if (verified && (!p.sourceEvidence.length || !p.comparisonEvidence.length || (p.status === 'exception_verified' && !p.exceptionIds.length) || (p.status === 'matched' && p.exceptionIds.length))) throw new Error('원본 대조 근거 또는 예외 범위가 부족합니다: ' + f.id);
        if (r.state === 'done' && !verified) throw new Error('원본 대조 완료가 필요합니다: ' + f.id);
      }
    }
    for (const m of report.milestones) m.evidence.forEach(checkEvidence);
    for (const step of report.nextSteps) if (step.ids.some(id => !ids.includes(id))) throw new Error('없는 다음 작업 ID');
    return true;
  }
  function totals(features, report) {
    const counts = Object.fromEntries(Object.keys(states).map(s => [s, 0]));
    features.forEach(f => counts[report.features[f.id].state]++);
    return { total: features.length, ...counts, percent: features.length ? Math.round(counts.done / features.length * 100) : 0 };
  }
  function summary(plan, report) {
    return { ...totals(plan.features, report), phases: plan.phases.map(p => ({ ...p, ...totals(plan.features.filter(f => f.phase === p.id), report) })) };
  }
  function rows(plan, report, user, filters = {}) {
    const query = (filters.query || '').trim().toLowerCase();
    return plan.features.filter(f => {
      const r = report.features[f.id];
      return (!filters.phase || filters.phase === 'all' || filters.phase === f.phase)
        && (!filters.status || filters.status === 'all' || filters.status === r.state)
        && (filters.scope !== 'selected' || user.selected.includes(f.id))
        && (!query || [f.id, f.title, f.phase, r.summary, ...r.remaining].join(' ').toLowerCase().includes(query));
    }).sort((a, b) => Number(a.id.slice(1)) - Number(b.id.slice(1)));
  }
  function markdown(plan, report, user) {
    const s = summary(plan, report);
    const lines = ['# notParsec 개발 진행 보고서', '', '기록 기준: ' + report.updatedAt + ' / ' + report.revision, report.summary,
      '', `전체 ${s.total}개 · 완료 ${s.done} · 진행 중 ${s.doing} · 검증 대기 ${s.validation} · 미착수 ${s.todo} · 차단 ${s.blocked}`,
      '구현 기록은 문서에 내장된 검토 시점의 기록이며 실시간 코드 검사 결과가 아닙니다.', '사용자 선택·수동 상태는 별도 기록입니다.', ''];
    for (const p of plan.phases) {
      lines.push('## ' + p.id + ' ' + p.title, '');
      for (const f of plan.features.filter(f => f.phase === p.id)) {
        const r = report.features[f.id];
        lines.push(`- ${f.id} ${f.title} — ${states[r.state]}`, '  ' + Object.entries(stageNames).map(([k, label]) => label + ': ' + stages[r.stages[k]]).join(' / '),
          '  현재: ' + r.summary, '  원본 대조: ' + (parityStates[r.parity?.status] || '원본 대조 전'),
          '  대조 근거: ' + [...(r.parity?.sourceEvidence || []), ...(r.parity?.comparisonEvidence || [])].map(e => e.label + ' (' + e.path + ')').join(', '),
          '  명시 예외: ' + (r.parity?.exceptionIds.join(', ') || '없음'), '  남은 작업: ' + (r.remaining.join(' / ') || '없음'),
          '  근거: ' + (r.evidence.map(e => e.label + ' (' + e.path + ')').join(', ') || '기능 명세만 있음'),
          '  사용자 기록: ' + (user.selected.includes(f.id) ? '범위 포함' : '범위 제외') + ' / ' + (user.status[f.id] || 'todo'));
      }
      lines.push('');
    }
    return lines.join('\n');
  }
  const api = { validate, summary, rows, markdown, states, stages, stageNames, parityStates };
  if (typeof module !== 'undefined' && module.exports) module.exports = api;
  root.DevelopmentProgress = api;
})(globalThis);