feat: Intelligent Resilience & Trust Reporting (v2.77.2)
This commit is contained in:
+48
-38
@@ -1,60 +1,70 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { MissionState } from './engine';
|
||||
|
||||
export class WikiFormatter {
|
||||
/**
|
||||
* 최종 에이전트 출력물을 P-Reinforce v3.0 표준 포맷으로 변환합니다.
|
||||
*/
|
||||
public static format(content: string, missionId: string): string {
|
||||
public static format(content: string, state: MissionState): string {
|
||||
const now = new Date().toISOString();
|
||||
const missionId = state.missionId;
|
||||
|
||||
// 1. Frontmatter가 없는 경우 주입
|
||||
let formatted = content;
|
||||
if (!content.trim().startsWith('---')) {
|
||||
const frontmatter = [
|
||||
'---',
|
||||
`id: ${missionId}`,
|
||||
`date: ${now}`,
|
||||
'type: knowledge_artifact',
|
||||
'standard: P-Reinforce v3.0',
|
||||
'tags: [automated, connect_ai, brain_sync]',
|
||||
'---',
|
||||
'',
|
||||
''
|
||||
].join('\n');
|
||||
formatted = frontmatter + content;
|
||||
}
|
||||
// 1. Frontmatter 주입 (항상 갱신)
|
||||
const frontmatter = [
|
||||
'---',
|
||||
`id: ${missionId}`,
|
||||
`date: ${now}`,
|
||||
'type: knowledge_artifact',
|
||||
'standard: P-Reinforce v3.0',
|
||||
'tags: [automated, connect_ai, brain_sync]',
|
||||
'---',
|
||||
'',
|
||||
''
|
||||
].join('\n');
|
||||
|
||||
// 2. 필수 헤더 보정 (예: Brief Summary가 없는 경우 상단에 자동 생성 시도)
|
||||
// 기존 frontmatter 제거 (있는 경우)
|
||||
let cleanContent = content.replace(/^---[\s\S]*?---\n*/, '');
|
||||
let formatted = frontmatter + cleanContent;
|
||||
|
||||
// 2. 필수 헤더 보정
|
||||
if (!formatted.includes('## 📌 Brief Summary')) {
|
||||
// 간단한 요약 추출 시도 (첫 문장 등)
|
||||
const summary = content.split('\n').find(l => l.trim().length > 10) || '요약이 생성되지 않았습니다.';
|
||||
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. 코드 스니펫 섹션 보정 (Astra 피드백: 실전 구현 코드 강제)
|
||||
const hasImplementationHeader = formatted.includes('## 💻 Practical Implementation') || formatted.includes('## 💻 실전 구현 코드');
|
||||
if (!hasImplementationHeader) {
|
||||
// 코드 블록이 이미 있다면 그 위에 헤더를 붙여줌
|
||||
// 3. 코드 스니펫 섹션 보정
|
||||
if (!formatted.includes('## 💻 Practical Implementation') && !formatted.includes('## 💻 실전 구현 코드')) {
|
||||
if (formatted.includes('```')) {
|
||||
// 첫 번째 코드 블록 앞에 헤더 삽입
|
||||
formatted = formatted.replace(/```/, '\n## 💻 실전 구현 코드\n\n```');
|
||||
} else {
|
||||
// 코드 블록이 전혀 없는 경우 하단에 플레이스홀더 추가 (추후 보강 유도)
|
||||
const boilerplatePlaceholder = [
|
||||
'',
|
||||
'---',
|
||||
'## 💻 실전 구현 코드 (Boilerplate)',
|
||||
'> [!TIP]',
|
||||
'> 이 문서의 개념을 즉시 적용할 수 있는 **실전 구현 코드**나 **보일러플레이트**가 아직 포함되지 않았습니다.',
|
||||
'> 에이전트에게 "React 예제 코드 포함해줘" 또는 "MSA 구조도 코드로 표현해줘"와 같이 구체적인 구현체 생성을 요청하세요.',
|
||||
'',
|
||||
].join('\n');
|
||||
formatted += boilerplatePlaceholder;
|
||||
}
|
||||
}
|
||||
|
||||
return formatted;
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user