71 lines
3.1 KiB
TypeScript
71 lines
3.1 KiB
TypeScript
import * as vscode from 'vscode';
|
|
import { MissionState } from './engine';
|
|
|
|
export class WikiFormatter {
|
|
/**
|
|
* 최종 에이전트 출력물을 P-Reinforce v3.0 표준 포맷으로 변환합니다.
|
|
*/
|
|
public static format(content: string, state: MissionState): string {
|
|
const now = new Date().toISOString();
|
|
const missionId = state.missionId;
|
|
|
|
// 1. Frontmatter 주입 (항상 갱신)
|
|
const frontmatter = [
|
|
'---',
|
|
`id: ${missionId}`,
|
|
`date: ${now}`,
|
|
'type: knowledge_artifact',
|
|
'standard: P-Reinforce v3.0',
|
|
'tags: [automated, connect_ai, brain_sync]',
|
|
'---',
|
|
'',
|
|
''
|
|
].join('\n');
|
|
|
|
// 기존 frontmatter 제거 (있는 경우)
|
|
let cleanContent = content.replace(/^---[\s\S]*?---\n*/, '');
|
|
let formatted = frontmatter + cleanContent;
|
|
|
|
// 2. 필수 헤더 보정
|
|
if (!formatted.includes('## 📌 Brief Summary')) {
|
|
const summary = cleanContent.split('\n').find(l => l.trim().length > 10) || '요약이 생성되지 않았습니다.';
|
|
const summarySection = `## 📌 Brief Summary\n${summary.substring(0, 200)}...\n\n`;
|
|
formatted = formatted.replace(/---\n\n/, `---\n\n${summarySection}`);
|
|
}
|
|
|
|
// 3. 코드 스니펫 섹션 보정
|
|
if (!formatted.includes('## 💻 Practical Implementation') && !formatted.includes('## 💻 실전 구현 코드')) {
|
|
if (formatted.includes('```')) {
|
|
formatted = formatted.replace(/```/, '\n## 💻 실전 구현 코드\n\n```');
|
|
}
|
|
}
|
|
|
|
// 4. [Astra v4.0] 신뢰성 보고서 (Reliability & Audit Summary)
|
|
const metrics = state.resilienceMetrics;
|
|
const totalDuration = Date.now() - state.startTime;
|
|
const reliabilitySection = [
|
|
'',
|
|
'---',
|
|
'## 🛡️ Reliability & Audit Summary',
|
|
`> [!NOTE]`,
|
|
`> 이 문서는 ConnectAI의 **Intelligent Resilience** 엔진에 의해 검증 및 정제되었습니다.`,
|
|
'',
|
|
'| Metric | Value | Status |',
|
|
'| :--- | :--- | :--- |',
|
|
`| **Conflict Risk** | \`${metrics.maxConflictScore}/100\` | ${metrics.maxConflictScore < 30 ? '✅ Low' : metrics.maxConflictScore < 70 ? '⚠️ Medium' : '🚨 High'} |`,
|
|
`| **Fallbacks Used** | \`${metrics.fallbacks}\` | ${metrics.fallbacks === 0 ? '✅ None' : '💡 Recovered'} |`,
|
|
`| **Auto Retries** | \`${metrics.retries}\` | ${metrics.retries < 3 ? '✅ Stable' : '⚠️ Unstable'} |`,
|
|
`| **Deduplication** | \`${metrics.deduplications}\` | ${metrics.deduplications > 0 ? '🚀 Optimized' : 'Standard'} |`,
|
|
`| **Processing Time** | \`${(totalDuration / 1000).toFixed(1)}s\` | ✅ Fast |`,
|
|
'',
|
|
'### 🔍 Decision Audit Trail',
|
|
state.auditTrail.map(a => `- **[${a.to.toUpperCase()}]** ${a.message} (${a.durationFromPrev}ms)`).join('\n'),
|
|
''
|
|
].join('\n');
|
|
|
|
formatted += reliabilitySection;
|
|
|
|
return formatted;
|
|
}
|
|
}
|