feat: v2.2.173-193 — 4인 팀 운영 슬래시 13개 + ASTRA 검증 엔진 6종
4인 팀 운영 슬래시 (v2.2.173~189):
- 일과 리듬: /morning, /evening, /weekly, /standup
- 트래커 (event-sourced .astra/*.jsonl): /runway, /customers, /hire
- 작업·결정: /task, /blocked, /onesie, /decisions
- 외부 출력: /draft, /feedback
- 분석: /cohort (MoM 추세)
ASTRA 추론·검색 엔진 (v2.2.183~192):
- v2.2.183 Conflict Surface — scoring.conflictSeverity 를 [CONFLICT WARNINGS] 블록으로
서피스 + 교차-문서 발산(Jaccard) 감지
- v2.2.184 Chain-of-Verification — [VERIFICATION CHECKLIST] 답변 작성 전 그라운딩 자기 점검
(instructional, strictMode 옵션)
- v2.2.185 Actionability Scoring — 최근 슬래시 명령 + 열린 파일 신호로 검색 결과 재가중
- v2.2.186 Temporal Markers + Distillation Loop — LongTerm/Episodic 만료 필터 +
30일+ stale episode → LongTerm 'episode-digest' 승급 (수동 /memory distill + 세션 종료 자동)
- v2.2.187 Hierarchical Context Window + LLM Semantic Re-rank — 3-level 추상도 매칭
+ 토큰 예산 통과 후 LLM 1회로 의도-부합 재정렬 (opt-in)
- v2.2.190 Intent Clarification + Citation Trace — 모호 차원 감지 시 역질문 우선
+ 답변 끝 사용 출처 한 줄 정리
- v2.2.191 Post-hoc Self-Check — 답변 완료 후 별도 LLM 호출 1회로 답함/그라운딩/모순 평가,
footer 한 줄로 표시 (opt-in, semantic re-rank 와 같은 안전 fallback 패턴)
- v2.2.192 Terminology Dictionary — .astra/glossary.md 사용자 편집 파일 + Term Check
지침 통합 + /glossary init/path/reload
- v2.2.193 /help — 카테고리별 명령 목록 + 6종 verification 블록 현재 on/off
신규 모듈:
- src/retrieval/{conflictBlock,coveBlock,actionabilityScoring,hierarchicalLevel,
semanticRerank,intentClarification,citationTrace,terminologyBlock}.ts
- src/memory/distillation.ts + types.ts 에 expiresAt/promoted/episode-digest 추가
- src/agent/postHocSelfCheck.ts
- src/features/{customers,feedback,hire,runway}/*.ts (event-sourced stores)
ASTRA 검증 5종 자동 주입 (buildAstraModeSystemPrompt, casual 모드 제외):
[INTENT CLARIFICATION GUIDANCE] (답변 시작 전) → [TERMINOLOGY DICTIONARY] +
[CONFLICT WARNINGS] + [VERIFICATION CHECKLIST] (작성 중) → [CITATION TRACE] (끝)
+ 6번째: Post-hoc Self-Check footer (답변 완료 후, opt-in)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,14 @@ import {
|
||||
mapWeightToRetrievalRatio,
|
||||
ResolvedKnowledgeMix,
|
||||
} from '../../retrieval/knowledgeMix';
|
||||
import { buildConflictWarningsBlock, ConflictThresholdSetting } from '../../retrieval/conflictBlock';
|
||||
import { buildCoveChecklistBlock } from '../../retrieval/coveBlock';
|
||||
import { captureWorkStateSignals } from '../../retrieval/actionabilityScoring';
|
||||
import { getRecentSlashCommands } from '../../features/datacollect/slashRouter';
|
||||
import { semanticRerank, DEFAULT_SEMANTIC_RERANK_OPTIONS } from '../../retrieval/semanticRerank';
|
||||
import { detectAmbiguity, buildIntentClarificationBlock, IntentStrictness } from '../../retrieval/intentClarification';
|
||||
import { buildCitationTraceBlock } from '../../retrieval/citationTrace';
|
||||
import { buildTerminologyBlock } from '../../retrieval/terminologyBlock';
|
||||
|
||||
/**
|
||||
* 한 turn 의 RAG / 5-layer memory 컨텍스트 빌드.
|
||||
@@ -54,6 +62,29 @@ export interface TurnContextSink {
|
||||
retrieval: TurnRetrievalSummary | null;
|
||||
lessons: string[];
|
||||
knowledgeMix: ResolvedKnowledgeMix | null;
|
||||
/**
|
||||
* [CONFLICT WARNINGS] 시스템 프롬프트 블록 — 빈 문자열이면 충돌 없음.
|
||||
* buildAstraModeSystemPrompt 가 직접 prompt 에 주입.
|
||||
*/
|
||||
conflictWarnings: string;
|
||||
/**
|
||||
* [VERIFICATION CHECKLIST] Chain-of-Verification 블록 — 빈 문자열이면 CoVe 비활성/근거 없음.
|
||||
* 모델이 답변 *작성 전* 그라운딩 체크하도록 instructional prompt 주입.
|
||||
*/
|
||||
coveChecklist: string;
|
||||
/**
|
||||
* [INTENT CLARIFICATION GUIDANCE] 블록 — 질의가 모호한 차원이 감지된 경우 LLM 에게
|
||||
* 답변보다 *역질문* 우선 지시. 빈 문자열이면 모호 차원 없음 또는 disable.
|
||||
*/
|
||||
intentClarification: string;
|
||||
/**
|
||||
* [CITATION TRACE] 블록 — 답변 끝에 사용 출처 한 줄 정리 지시. 검색 결과 있을 때만.
|
||||
*/
|
||||
citationTrace: string;
|
||||
/** Post-hoc Self-Check 용 — selected chunks 의 (title, excerpt) 요약. */
|
||||
selfCheckSources: Array<{ title: string; excerpt: string }>;
|
||||
/** [TERMINOLOGY DICTIONARY] 시스템 프롬프트 블록 — 글로서리 파일 있을 때만 채워짐. */
|
||||
terminology: string;
|
||||
}
|
||||
|
||||
export interface MemoryContextDeps {
|
||||
@@ -163,6 +194,12 @@ export async function buildMemoryContext(deps: MemoryContextDeps): Promise<strin
|
||||
const mixedBrainFileLimit = mapWeightToBrainFileLimit(knowledgeMix.weight, config.memoryLongTermFiles);
|
||||
const mixedRetrievalRatio = mapWeightToRetrievalRatio(knowledgeMix.weight);
|
||||
|
||||
// Actionability — work-state 신호 캡처 (최근 슬래시 명령 + 열린 파일).
|
||||
// 설정으로 disable 가능. 신호 없으면 retrieve() 가 legacy 동작.
|
||||
const workStateSignals = config.actionabilityEnabled !== false
|
||||
? captureWorkStateSignals(getRecentSlashCommands())
|
||||
: undefined;
|
||||
|
||||
// Unified RAG Pipeline 호출.
|
||||
const result = deps.retrievalOrchestrator.retrieve(deps.currentPrompt, {
|
||||
brain: deps.activeBrain,
|
||||
@@ -180,8 +217,29 @@ export async function buildMemoryContext(deps: MemoryContextDeps): Promise<strin
|
||||
queryEmbedding,
|
||||
embeddingModel: config.embeddingModel || undefined,
|
||||
embeddingBlendAlpha: config.embeddingBlendAlpha,
|
||||
workStateSignals,
|
||||
hierarchicalReweightEnabled: config.hierarchicalReweightEnabled !== false,
|
||||
});
|
||||
|
||||
// Semantic Re-rank (LLM, async) — selectedChunks 의 *순서* 만 재배치. 토큰 예산을
|
||||
// 통과한 chunks 안에서 의도-부합도 순으로 재정렬해 LLM attention bias 활용.
|
||||
// 기본 OFF — latency 우려. 사용자가 명시 enable 시만.
|
||||
if (config.semanticRerankEnabled && result.selectedChunks.length >= 3) {
|
||||
const rerankModel = (config.semanticRerankModel || '').trim() || config.defaultModel;
|
||||
if (rerankModel && config.ollamaUrl) {
|
||||
const rerankRes = await semanticRerank(deps.currentPrompt, result.selectedChunks, {
|
||||
ollamaUrl: config.ollamaUrl,
|
||||
model: rerankModel,
|
||||
candidateK: config.semanticRerankCandidateK ?? DEFAULT_SEMANTIC_RERANK_OPTIONS.candidateK,
|
||||
timeoutMs: (config.semanticRerankTimeoutSec ?? 8) * 1000,
|
||||
excerptLength: DEFAULT_SEMANTIC_RERANK_OPTIONS.excerptLength,
|
||||
});
|
||||
// In-place 교체 — buildContextString 가 이 배열을 그대로 읽음.
|
||||
result.selectedChunks = rerankRes.rerankedChunks;
|
||||
result.fusionLog.push(`Semantic re-rank: ${rerankRes.success ? '✓' : '✗'} ${rerankRes.note} (${rerankRes.durationMs}ms)`);
|
||||
}
|
||||
}
|
||||
|
||||
// Fire-and-forget background embedding. Vector 없는 파일만 embed 하므로
|
||||
// steady-state turn 은 작업량 0 — 다음 turn 이 혜택.
|
||||
if (config.embeddingModel) {
|
||||
@@ -225,6 +283,67 @@ export async function buildMemoryContext(deps: MemoryContextDeps): Promise<strin
|
||||
};
|
||||
|
||||
deps.turnCtx.lessons = lessonChunks.map((c) => c.content);
|
||||
|
||||
// Conflict Surface — selectedChunks 의 per-doc conflictSeverity 신호 + 교차-문서
|
||||
// 발산 후보를 LLM 에 노출. 블록은 [CONTEXT] *밖*에 주입돼 token-truncation 보호.
|
||||
// 설정으로 disable 가능 — 기본 켜져 있음 (v4 정책이 이미 CONFLICT WARNING 플래그 참조).
|
||||
if (config.conflictHighlightingEnabled !== false) {
|
||||
const threshold: ConflictThresholdSetting = (config.conflictSeverityThreshold || 'medium') as ConflictThresholdSetting;
|
||||
deps.turnCtx.conflictWarnings = buildConflictWarningsBlock(result.selectedChunks, {
|
||||
selfFlagThreshold: threshold,
|
||||
crossDivergenceEnabled: config.conflictCrossDocEnabled !== false,
|
||||
});
|
||||
} else {
|
||||
deps.turnCtx.conflictWarnings = '';
|
||||
}
|
||||
|
||||
// CoVe (Chain-of-Verification) — 답변 *작성 전* 그라운딩 체크리스트를 시스템 프롬프트에
|
||||
// 주입. 모델이 한 패스 안에서 self-verify. Conflict Surface 와 보완 관계 — 충돌
|
||||
// 데이터를 *어떻게* verify 할지 지시.
|
||||
if (config.coveEnabled !== false) {
|
||||
deps.turnCtx.coveChecklist = buildCoveChecklistBlock(result.selectedChunks, deps.currentPrompt, {
|
||||
topSourcesCount: config.coveTopSourcesCount ?? 5,
|
||||
strictMode: config.coveStrictMode === true,
|
||||
});
|
||||
} else {
|
||||
deps.turnCtx.coveChecklist = '';
|
||||
}
|
||||
|
||||
// Intent Clarification — 모호 차원 감지 시 *역질문 우선* 지시. CoVe / Citation 과
|
||||
// 동일 패턴: instructional system prompt block.
|
||||
if (config.intentClarificationEnabled !== false) {
|
||||
const strict = (config.intentClarificationStrictness || 'medium') as IntentStrictness;
|
||||
const ambig = detectAmbiguity(deps.currentPrompt, strict);
|
||||
deps.turnCtx.intentClarification = buildIntentClarificationBlock(ambig);
|
||||
} else {
|
||||
deps.turnCtx.intentClarification = '';
|
||||
}
|
||||
|
||||
// Citation Trace — 답변 끝에 출처 한 줄 명시 지시. CoVe Strict 의 가벼운 형제.
|
||||
// 검색 결과가 있을 때만 의미 있음.
|
||||
if (config.citationTraceEnabled !== false && result.selectedChunks.length > 0) {
|
||||
deps.turnCtx.citationTrace = buildCitationTraceBlock(result.selectedChunks);
|
||||
} else {
|
||||
deps.turnCtx.citationTrace = '';
|
||||
}
|
||||
|
||||
// Self-Check 용 source 미리보기 — agent.ts 가 post-stream 에서 사용.
|
||||
deps.turnCtx.selfCheckSources = result.selectedChunks.slice(0, 5).map((c) => ({
|
||||
title: c.title || '(제목 없음)',
|
||||
excerpt: (c.content || '').slice(0, 200),
|
||||
}));
|
||||
|
||||
// Terminology Dictionary — 사용자 편집 글로서리 파일을 시스템 프롬프트 블록으로 주입.
|
||||
// 파일 없으면 빈 문자열 (no-op). 캐시 + mtime 체크로 매 turn 디스크 read 최소화.
|
||||
if (config.glossaryEnabled !== false) {
|
||||
deps.turnCtx.terminology = buildTerminologyBlock({
|
||||
relPath: config.glossaryPath || '.astra/glossary.md',
|
||||
maxBodyLength: config.glossaryMaxBodyLength ?? 4000,
|
||||
});
|
||||
} else {
|
||||
deps.turnCtx.terminology = '';
|
||||
}
|
||||
|
||||
// Lessons 블록은 일반 RAG context 보다 앞 — context-overflow truncation 에서 먼저
|
||||
// 살아남게.
|
||||
const lessonBlock = buildLessonChecklistBlock(lessonChunks.map((c) => ({ title: c.title, content: c.content })));
|
||||
|
||||
Reference in New Issue
Block a user