llm 분석기능
This commit is contained in:
@@ -10238,6 +10238,26 @@ html.desktop-client .tmb-logo-version {
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
.stg-btn-test:hover { border-color: var(--accent); color: var(--accent); }
|
||||
.stg-btn-test:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
.stg-row-inline {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.stg-code-preview {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
padding: 6px 10px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg3);
|
||||
color: var(--text-muted, var(--text));
|
||||
font-size: 11px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* ── 하단 푸터 (저장/초기화) ── */
|
||||
.stg-footer {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useIndicatorSettings } from './hooks/useIndicatorSettings';
|
||||
import { getAppSettingsCache, useAppSettings } from './hooks/useAppSettings';
|
||||
import { clampVirtualTargetMax } from './utils/virtualTargetLimits';
|
||||
import { resolveTrendSearchAppSettings } from './utils/trendSearchAppSettings';
|
||||
import { resolveLlmAppSettings } from './utils/llmSettings';
|
||||
import TopMenuBar, { type MenuPage } from './components/TopMenuBar';
|
||||
import { TradeNotificationProvider } from './contexts/TradeNotificationContext';
|
||||
import { VerificationIssueNotificationProvider } from './contexts/VerificationIssueNotificationContext';
|
||||
@@ -436,6 +437,10 @@ function AppMainContent({
|
||||
onTrendSearchSettingsChange={s => saveAppDef({
|
||||
trendSearchSettings: resolveTrendSearchAppSettings(s),
|
||||
})}
|
||||
llmSettings={appDefaults.llmSettings}
|
||||
onLlmSettingsChange={s => saveAppDef({
|
||||
llmSettings: resolveLlmAppSettings(s),
|
||||
})}
|
||||
tradingMode={appDefaults.tradingMode}
|
||||
onTradingMode={v => saveAppDef({ tradingMode: v })}
|
||||
liveAutoTradeEnabled={appDefaults.liveAutoTradeEnabled}
|
||||
|
||||
@@ -33,7 +33,9 @@ import {
|
||||
} from '../utils/tradeAlertPopupLayout';
|
||||
import TradeAlertPopupPreview from './TradeAlertPopupPreview';
|
||||
import TrendSearchSettingsPanel from './trendSearch/TrendSearchSettingsPanel';
|
||||
import LlmSettingsPanel from './settings/LlmSettingsPanel';
|
||||
import type { TrendSearchAppSettings } from '../utils/trendSearchAppSettings';
|
||||
import type { LlmAppSettings } from '../utils/llmSettings';
|
||||
import { isTradingSettingsCategory } from '../utils/tradingAccess';
|
||||
import {
|
||||
CHART_LEGEND_SETTING_ITEMS,
|
||||
@@ -176,6 +178,8 @@ interface SettingsPageProps {
|
||||
onVerificationIssueNotify?: (v: boolean) => void;
|
||||
trendSearchSettings?: TrendSearchAppSettings;
|
||||
onTrendSearchSettingsChange?: (s: TrendSearchAppSettings) => void;
|
||||
llmSettings?: LlmAppSettings;
|
||||
onLlmSettingsChange?: (s: LlmAppSettings) => void;
|
||||
/** 설정 화면 진입 시 선택할 카테고리 (예: 모의투자 화면에서 링크) */
|
||||
initialCategory?: SettingsCategoryId;
|
||||
/** 정식 로그인 여부 (게스트는 매매·전략 설정 탭 차단) */
|
||||
@@ -277,6 +281,13 @@ const IcTrendSearch = () => (
|
||||
<circle cx="18" cy="6" r="2" fill="currentColor" stroke="none"/>
|
||||
</svg>
|
||||
);
|
||||
const IcLlm = () => (
|
||||
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
|
||||
<path d="M11 3l1.2 3.6L16 8l-3.8 1.4L11 13l-1.2-3.6L6 8l3.8-1.4L11 3z"/>
|
||||
<path d="M17 14l.8 2.2L20 17l-2.2.8L17 20l-.8-2.2L14 17l2.2-.8L17 14z"/>
|
||||
<rect x="3" y="15" width="6" height="4" rx="1"/>
|
||||
</svg>
|
||||
);
|
||||
const IcBacktest = () => (
|
||||
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
|
||||
<polyline points="2,17 6,11 9,14 13,7 16,10 20,4"/>
|
||||
@@ -304,6 +315,7 @@ const ALL_CATEGORIES: Category[] = [
|
||||
{ id: 'trading', label: '매매설정', icon: <IcTrading />, desc: '모의투자·가상매매 통합 설정 — 자동매매, 미체결 주문 처리, 계좌·비용 등' },
|
||||
{ id: 'live', label: '실거래', icon: <IcLive />, desc: '매매 운영 모드, 업비트 API 키, 실거래 자동매매' },
|
||||
{ id: 'trend-search', label: '추세검색', icon: <IcTrendSearch />, desc: '상승추세 배점, 합격 점수, 결과 수, 자동갱신·투자대상 자동추가' },
|
||||
{ id: 'llm', label: 'LLM 설정', icon: <IcLlm />, desc: 'AI 전략 검증용 LLM 서버 주소·포트·모델·타임아웃' },
|
||||
{ id: 'alert', label: '알림 설정', icon: <IcAlert />, desc: '가격 알림, 신호 알림, 알림 방식 설정' },
|
||||
{ id: 'network', label: '네트워크', icon: <IcNetwork />, desc: 'API 서버 주소, WebSocket, 연결 상태' },
|
||||
{ id: 'admin', label: '관리자 설정', icon: <IcAdmin />, desc: '사용자·역할·메뉴 접근 권한 관리 (관리자 비밀번호 필요)' },
|
||||
@@ -2008,6 +2020,8 @@ const SettingsPage: React.FC<SettingsPageProps> = ({
|
||||
onVerificationIssueNotify,
|
||||
trendSearchSettings,
|
||||
onTrendSearchSettingsChange,
|
||||
llmSettings,
|
||||
onLlmSettingsChange,
|
||||
initialCategory,
|
||||
isFormalLogin = true,
|
||||
onRequireFormalLogin,
|
||||
@@ -2180,6 +2194,16 @@ const SettingsPage: React.FC<SettingsPageProps> = ({
|
||||
<p className="stg-ind-unavailable">추세검색 설정을 불러올 수 없습니다.</p>
|
||||
)
|
||||
);
|
||||
case 'llm': return (
|
||||
llmSettings && onLlmSettingsChange ? (
|
||||
<LlmSettingsPanel
|
||||
settings={llmSettings}
|
||||
onChange={onLlmSettingsChange}
|
||||
/>
|
||||
) : (
|
||||
<p className="stg-ind-unavailable">LLM 설정을 불러올 수 없습니다.</p>
|
||||
)
|
||||
);
|
||||
case 'strategy': return (
|
||||
<StrategyPanel
|
||||
liveMarket={liveMarket}
|
||||
|
||||
@@ -49,6 +49,13 @@ import BacktestAnalysisReportModal from './backtest/BacktestAnalysisReportModal'
|
||||
import type { BacktestAnalysisReportModel } from './backtest/BacktestAnalysisReportModal';
|
||||
import { buildChartBacktestReportModel } from '../utils/backtestReportModel';
|
||||
import { BACKTEST_DISPLAY_BAR_COUNT } from '../utils/backtestWarmup';
|
||||
import StrategyEvaluationAiVerifyModal from './strategyEvaluation/StrategyEvaluationAiVerifyModal';
|
||||
import {
|
||||
buildStrategyEvaluationAiVerifyContext,
|
||||
requestStrategyEvaluationAiVerify,
|
||||
summarizeVerifyContext,
|
||||
} from '../utils/strategyEvaluationAiVerify';
|
||||
import type { StrategyEvaluationAiVerifyResponse } from '../utils/backendApi';
|
||||
|
||||
const LEFT_KEY = 'seval-left-width';
|
||||
const LEFT_OPEN_KEY = 'seval-left-open';
|
||||
@@ -92,6 +99,13 @@ export default function StrategyEvaluationPage({ theme = 'dark' }: Props) {
|
||||
const [reportOpen, setReportOpen] = useState(false);
|
||||
const [reportModel, setReportModel] = useState<BacktestAnalysisReportModel | null>(null);
|
||||
const [reportLoading, setReportLoading] = useState(false);
|
||||
const [aiVerifyOpen, setAiVerifyOpen] = useState(false);
|
||||
const [aiVerifyLoading, setAiVerifyLoading] = useState(false);
|
||||
const [aiVerifyError, setAiVerifyError] = useState<string | null>(null);
|
||||
const [aiVerifyResult, setAiVerifyResult] = useState<StrategyEvaluationAiVerifyResponse | null>(null);
|
||||
const [aiVerifyContext, setAiVerifyContext] = useState<import('../utils/strategyEvaluationAiVerify').StrategyEvaluationAiVerifyContext | null>(null);
|
||||
const [aiVerifySummary, setAiVerifySummary] = useState<string | null>(null);
|
||||
const aiVerifyGenRef = useRef(0);
|
||||
const reportCacheKeyRef = useRef<string | null>(null);
|
||||
const reportGenRef = useRef(0);
|
||||
const evalSessionRef = useRef(0);
|
||||
@@ -369,6 +383,80 @@ export default function StrategyEvaluationPage({ theme = 'dark' }: Props) {
|
||||
|
||||
const reportDisabled = !selectedStrategyId || !selectedStrategy || bars.length < 10 || chartLoading;
|
||||
|
||||
const aiVerifyDisabled = reportDisabled
|
||||
|| evalLoading
|
||||
|| chartLoading
|
||||
|| selectedBarTimeSec == null
|
||||
|| !snapshot;
|
||||
|
||||
const runAiVerify = useCallback(async () => {
|
||||
if (aiVerifyDisabled || !selectedStrategyId || !selectedStrategy || selectedBarTimeSec == null) return;
|
||||
|
||||
const gen = ++aiVerifyGenRef.current;
|
||||
setAiVerifyOpen(true);
|
||||
setAiVerifyLoading(true);
|
||||
setAiVerifyError(null);
|
||||
setAiVerifyResult(null);
|
||||
setAiVerifyContext(null);
|
||||
|
||||
try {
|
||||
const indicatorParams = buildEvalParamsFromStrategy(selectedStrategy, getEvalParams);
|
||||
const context = buildStrategyEvaluationAiVerifyContext({
|
||||
strategy: selectedStrategy,
|
||||
strategyId: selectedStrategyId,
|
||||
market,
|
||||
timeframe: chartTimeframe,
|
||||
bars,
|
||||
selectedBarIndex,
|
||||
snapshot,
|
||||
evalLoading,
|
||||
evalError,
|
||||
chartSignals: backtestSignals,
|
||||
barSignalHighlight,
|
||||
indicatorParams,
|
||||
evaluationBarCount: Math.min(BACKTEST_DISPLAY_BAR_COUNT, bars.length),
|
||||
});
|
||||
setAiVerifySummary(summarizeVerifyContext(context));
|
||||
setAiVerifyContext(context);
|
||||
|
||||
const result = await requestStrategyEvaluationAiVerify(context);
|
||||
if (gen !== aiVerifyGenRef.current) return;
|
||||
setAiVerifyResult(result);
|
||||
} catch (e) {
|
||||
if (gen !== aiVerifyGenRef.current) return;
|
||||
setAiVerifyError(e instanceof Error ? e.message : 'AI 검증 요청 실패');
|
||||
} finally {
|
||||
if (gen === aiVerifyGenRef.current) {
|
||||
setAiVerifyLoading(false);
|
||||
}
|
||||
}
|
||||
}, [
|
||||
aiVerifyDisabled,
|
||||
selectedStrategyId,
|
||||
selectedStrategy,
|
||||
selectedBarTimeSec,
|
||||
market,
|
||||
chartTimeframe,
|
||||
bars,
|
||||
selectedBarIndex,
|
||||
snapshot,
|
||||
evalLoading,
|
||||
evalError,
|
||||
backtestSignals,
|
||||
barSignalHighlight,
|
||||
getEvalParams,
|
||||
]);
|
||||
|
||||
const handleOpenAiVerify = useCallback(() => {
|
||||
void runAiVerify();
|
||||
}, [runAiVerify]);
|
||||
|
||||
const handleCloseAiVerify = useCallback(() => {
|
||||
++aiVerifyGenRef.current;
|
||||
setAiVerifyOpen(false);
|
||||
setAiVerifyLoading(false);
|
||||
}, []);
|
||||
|
||||
const handleOpenReport = useCallback(async () => {
|
||||
if (reportDisabled || !selectedStrategyId || !selectedStrategy) return;
|
||||
|
||||
@@ -618,6 +706,9 @@ export default function StrategyEvaluationPage({ theme = 'dark' }: Props) {
|
||||
onOpenReport={() => { void handleOpenReport(); }}
|
||||
reportDisabled={reportDisabled}
|
||||
reportLoading={reportLoading}
|
||||
onOpenAiVerify={handleOpenAiVerify}
|
||||
aiVerifyDisabled={aiVerifyDisabled}
|
||||
aiVerifyLoading={aiVerifyLoading && aiVerifyOpen}
|
||||
marketTickers={marketFeed.tickers}
|
||||
marketInfos={marketFeed.marketInfos}
|
||||
marketLoading={marketFeed.loading}
|
||||
@@ -711,6 +802,17 @@ export default function StrategyEvaluationPage({ theme = 'dark' }: Props) {
|
||||
onClose={() => setReportOpen(false)}
|
||||
model={reportModel}
|
||||
/>
|
||||
|
||||
<StrategyEvaluationAiVerifyModal
|
||||
open={aiVerifyOpen}
|
||||
onClose={handleCloseAiVerify}
|
||||
loading={aiVerifyLoading}
|
||||
error={aiVerifyError}
|
||||
contextSummary={aiVerifySummary}
|
||||
verifyContext={aiVerifyContext}
|
||||
result={aiVerifyResult}
|
||||
onRetry={() => { void runAiVerify(); }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import type { LlmAppSettings } from '../../utils/llmSettings';
|
||||
import { buildLlmEndpointUrl, buildLlmBaseUrl } from '../../utils/llmSettings';
|
||||
import { fetchLlmConnectionTest } from '../../utils/backendApi';
|
||||
|
||||
interface Props {
|
||||
settings: LlmAppSettings;
|
||||
onChange: (next: LlmAppSettings) => void;
|
||||
}
|
||||
|
||||
const SettingRow: React.FC<{
|
||||
label: string;
|
||||
desc?: string;
|
||||
children: React.ReactNode;
|
||||
}> = ({ label, desc, children }) => (
|
||||
<div className="stg-row">
|
||||
<div className="stg-row-label">
|
||||
<span className="stg-row-title">{label}</span>
|
||||
{desc && <span className="stg-row-desc">{desc}</span>}
|
||||
</div>
|
||||
<div className="stg-row-ctrl">{children}</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const SettingSection: React.FC<{ title: string; children: React.ReactNode }> = ({
|
||||
title, children,
|
||||
}) => (
|
||||
<div className="stg-section">
|
||||
<div className="stg-section-title">{title}</div>
|
||||
<div className="stg-section-body">{children}</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const LlmSettingsPanel: React.FC<Props> = ({ settings, onChange }) => {
|
||||
const [testing, setTesting] = useState(false);
|
||||
const [testResult, setTestResult] = useState<{ ok: boolean; message: string } | null>(null);
|
||||
|
||||
const patch = (p: Partial<LlmAppSettings>) => {
|
||||
setTestResult(null);
|
||||
onChange({ ...settings, ...p });
|
||||
};
|
||||
|
||||
const endpointPreview = useMemo(() => buildLlmEndpointUrl(settings), [settings]);
|
||||
const baseUrlPreview = useMemo(() => buildLlmBaseUrl(settings), [settings]);
|
||||
|
||||
const handleTest = async () => {
|
||||
setTesting(true);
|
||||
setTestResult(null);
|
||||
try {
|
||||
const res = await fetchLlmConnectionTest();
|
||||
setTestResult({ ok: res.ok, message: res.message ?? (res.ok ? '연결 성공' : '연결 실패') });
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : '연결 테스트 실패';
|
||||
setTestResult({ ok: false, message: msg });
|
||||
} finally {
|
||||
setTesting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="llm-settings-panel">
|
||||
<SettingSection title="LLM 사용">
|
||||
<SettingRow
|
||||
label="AI 검증 사용"
|
||||
desc="전략 평가 화면의 AI 검증 기능에서 LLM을 사용합니다. 끄면 AI 검증 버튼이 동작하지 않습니다."
|
||||
>
|
||||
<label className="stg-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={settings.enabled}
|
||||
onChange={e => patch({ enabled: e.target.checked })}
|
||||
/>
|
||||
<span className="stg-toggle-slider" />
|
||||
</label>
|
||||
</SettingRow>
|
||||
</SettingSection>
|
||||
|
||||
<SettingSection title="서버 연결">
|
||||
<SettingRow label="호스트" desc="LLM API 서버 IP 또는 도메인 (Docker 환경에서는 host.docker.internal 등)">
|
||||
<input
|
||||
className="stg-input stg-input--wide"
|
||||
type="text"
|
||||
value={settings.host}
|
||||
onChange={e => patch({ host: e.target.value })}
|
||||
placeholder="127.0.0.1"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="포트" desc="LLM API 서버 포트 (MLX 기본 16000)">
|
||||
<input
|
||||
className="stg-input stg-input--num"
|
||||
type="number"
|
||||
min={1}
|
||||
max={65535}
|
||||
value={settings.port}
|
||||
onChange={e => patch({ port: Number(e.target.value) })}
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="HTTPS" desc="보안 연결(HTTPS) 사용 여부">
|
||||
<label className="stg-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={settings.useHttps}
|
||||
onChange={e => patch({ useHttps: e.target.checked })}
|
||||
/>
|
||||
<span className="stg-toggle-slider" />
|
||||
</label>
|
||||
</SettingRow>
|
||||
<SettingRow label="API 경로" desc="OpenAI 호환 chat completions 엔드포인트 경로">
|
||||
<input
|
||||
className="stg-input stg-input--wide"
|
||||
type="text"
|
||||
value={settings.chatPath}
|
||||
onChange={e => patch({ chatPath: e.target.value })}
|
||||
placeholder="/v1/chat/completions"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="연결 URL 미리보기" desc="저장 후 백엔드가 이 주소로 LLM에 요청합니다.">
|
||||
<code className="stg-code-preview">{endpointPreview}</code>
|
||||
</SettingRow>
|
||||
<SettingRow label="" desc="">
|
||||
<div className="stg-row-inline">
|
||||
<button
|
||||
type="button"
|
||||
className="stg-btn-test"
|
||||
disabled={testing || !settings.enabled}
|
||||
onClick={handleTest}
|
||||
>
|
||||
{testing ? '테스트 중…' : '연결 테스트'}
|
||||
</button>
|
||||
{testResult && (
|
||||
<span className={`stg-badge ${testResult.ok ? 'stg-badge--ok' : 'stg-badge--err'}`}>
|
||||
{testResult.ok ? '● ' : '● '}{testResult.message}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</SettingRow>
|
||||
</SettingSection>
|
||||
|
||||
<SettingSection title="모델·생성 옵션">
|
||||
<SettingRow label="모델" desc="LLM 서버에 등록된 모델 ID">
|
||||
<input
|
||||
className="stg-input stg-input--wide"
|
||||
type="text"
|
||||
value={settings.model}
|
||||
onChange={e => patch({ model: e.target.value })}
|
||||
placeholder="mlx-community/Qwen2.5-7B-Instruct-4bit"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="최대 토큰" desc="한 번에 생성할 최대 토큰 수 (64~8192)">
|
||||
<input
|
||||
className="stg-input stg-input--num"
|
||||
type="number"
|
||||
min={64}
|
||||
max={8192}
|
||||
step={64}
|
||||
value={settings.maxTokens}
|
||||
onChange={e => patch({ maxTokens: Number(e.target.value) })}
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="Temperature" desc="낮을수록 일관된 답변 (0~2, 권장 0.1)">
|
||||
<input
|
||||
className="stg-input stg-input--num"
|
||||
type="number"
|
||||
min={0}
|
||||
max={2}
|
||||
step={0.05}
|
||||
value={settings.temperature}
|
||||
onChange={e => patch({ temperature: Number(e.target.value) })}
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="타임아웃 (ms)" desc={`요청 대기 시간 (5초~10분). Base URL: ${baseUrlPreview}`}>
|
||||
<input
|
||||
className="stg-input stg-input--num"
|
||||
type="number"
|
||||
min={5000}
|
||||
max={600000}
|
||||
step={1000}
|
||||
value={settings.timeoutMs}
|
||||
onChange={e => patch({ timeoutMs: Number(e.target.value) })}
|
||||
/>
|
||||
</SettingRow>
|
||||
</SettingSection>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default LlmSettingsPanel;
|
||||
@@ -0,0 +1,347 @@
|
||||
/**
|
||||
* 전략 평가 — AI 검증 결과 모달
|
||||
*/
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import type {
|
||||
AiVerifyFixPointsBundle,
|
||||
StrategyEvaluationAiVerifyContext,
|
||||
} from '../../utils/strategyEvaluationAiVerify';
|
||||
import { buildAiVerifyFixPoints } from '../../utils/strategyEvaluationAiVerify';
|
||||
import type { StrategyEvaluationAiVerifyResponse } from '../../utils/strategyEvaluationAiVerify';
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
contextSummary: string | null;
|
||||
verifyContext: StrategyEvaluationAiVerifyContext | null;
|
||||
result: StrategyEvaluationAiVerifyResponse | null;
|
||||
onRetry?: () => void;
|
||||
}
|
||||
|
||||
function renderAnalysisMarkdown(text: string): React.ReactNode {
|
||||
const lines = text.split('\n');
|
||||
const nodes: React.ReactNode[] = [];
|
||||
let listItems: string[] = [];
|
||||
|
||||
const flushList = () => {
|
||||
if (listItems.length === 0) return;
|
||||
nodes.push(
|
||||
<ul key={`ul-${nodes.length}`} className="seval-ai-verify-list">
|
||||
{listItems.map((item, i) => (
|
||||
<li key={i}>{item}</li>
|
||||
))}
|
||||
</ul>,
|
||||
);
|
||||
listItems = [];
|
||||
};
|
||||
|
||||
for (const raw of lines) {
|
||||
const line = raw.trimEnd();
|
||||
if (line.startsWith('## ')) {
|
||||
flushList();
|
||||
nodes.push(
|
||||
<h3 key={`h-${nodes.length}`} className="seval-ai-verify-h3">
|
||||
{line.slice(3).trim()}
|
||||
</h3>,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith('- ') || line.startsWith('* ')) {
|
||||
listItems.push(line.slice(2).trim());
|
||||
continue;
|
||||
}
|
||||
if (line === '') {
|
||||
flushList();
|
||||
continue;
|
||||
}
|
||||
flushList();
|
||||
nodes.push(
|
||||
<p key={`p-${nodes.length}`} className="seval-ai-verify-p">
|
||||
{line}
|
||||
</p>,
|
||||
);
|
||||
}
|
||||
flushList();
|
||||
return nodes;
|
||||
}
|
||||
|
||||
function renderPreBlock(text: string, key: string): React.ReactNode {
|
||||
return (
|
||||
<pre key={key} className="seval-ai-verify-pre">{text}</pre>
|
||||
);
|
||||
}
|
||||
|
||||
function asRecord(v: unknown): Record<string, unknown> | null {
|
||||
return v != null && typeof v === 'object' && !Array.isArray(v)
|
||||
? v as Record<string, unknown>
|
||||
: null;
|
||||
}
|
||||
|
||||
const Ta4jDiagnosticsSummary: React.FC<{ diagnostics: Record<string, unknown> }> = ({ diagnostics }) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const entry = asRecord(diagnostics.entryRule);
|
||||
const exit = asRecord(diagnostics.exitRule);
|
||||
const cmp = asRecord(diagnostics.frontendVsBackend);
|
||||
const traceEntry = Array.isArray(entry?.evaluationTraceLog)
|
||||
? (entry.evaluationTraceLog as string[]).slice(0, 8)
|
||||
: [];
|
||||
const traceExit = Array.isArray(exit?.evaluationTraceLog)
|
||||
? (exit.evaluationTraceLog as string[]).slice(0, 8)
|
||||
: [];
|
||||
|
||||
return (
|
||||
<section className="seval-ai-verify-ta4j">
|
||||
<button
|
||||
type="button"
|
||||
className="seval-ai-verify-ta4j-toggle"
|
||||
aria-expanded={open}
|
||||
onClick={() => setOpen(v => !v)}
|
||||
>
|
||||
<span>Ta4j 서버 재평가 (Rule·trace)</span>
|
||||
<span aria-hidden>{open ? '▾' : '▸'}</span>
|
||||
</button>
|
||||
{open && (
|
||||
<div className="seval-ai-verify-ta4j-body">
|
||||
{typeof diagnostics.error === 'string' && (
|
||||
<p className="seval-ai-verify-ta4j-err">{diagnostics.error}</p>
|
||||
)}
|
||||
<div className="seval-ai-verify-ta4j-grid">
|
||||
<span>evalBarIndex: {String(diagnostics.evalBarIndex ?? '—')}</span>
|
||||
<span>매수 Rule: {entry?.satisfiedAtEvalIndex != null ? String(entry.satisfiedAtEvalIndex) : '—'}</span>
|
||||
<span>매도 Rule: {exit?.satisfiedAtEvalIndex != null ? String(exit.satisfiedAtEvalIndex) : '—'}</span>
|
||||
</div>
|
||||
{cmp && (
|
||||
<p className="seval-ai-verify-ta4j-cmp">
|
||||
FE 매수/매도: {String(cmp.frontendOverallEntryMet)} / {String(cmp.frontendOverallExitMet)}
|
||||
{' · '}
|
||||
BE 매수/매도: {String(cmp.backendOverallEntryMet)} / {String(cmp.backendOverallExitMet)}
|
||||
</p>
|
||||
)}
|
||||
{traceEntry.length > 0 && (
|
||||
<>
|
||||
<h4 className="seval-ai-verify-ta4j-trace-title">매수 Rule trace</h4>
|
||||
{renderPreBlock(traceEntry.join('\n'), 'trace-entry')}
|
||||
</>
|
||||
)}
|
||||
{traceExit.length > 0 && (
|
||||
<>
|
||||
<h4 className="seval-ai-verify-ta4j-trace-title">매도 Rule trace</h4>
|
||||
{renderPreBlock(traceExit.join('\n'), 'trace-exit')}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
const FixPointsPanel: React.FC<{
|
||||
bundle: AiVerifyFixPointsBundle;
|
||||
}> = ({ bundle }) => {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [expandedId, setExpandedId] = useState<string | null>(
|
||||
bundle.points[0]?.id ?? null,
|
||||
);
|
||||
|
||||
const handleCopy = useCallback(async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(bundle.cursorPrompt);
|
||||
setCopied(true);
|
||||
window.setTimeout(() => setCopied(false), 2000);
|
||||
} catch {
|
||||
window.prompt('아래 내용을 복사해 Cursor에 붙여넣으세요:', bundle.cursorPrompt);
|
||||
}
|
||||
}, [bundle.cursorPrompt]);
|
||||
|
||||
return (
|
||||
<section className="seval-ai-verify-fixpoints" aria-labelledby="seval-ai-fixpoints-title">
|
||||
<div className="seval-ai-verify-fixpoints-head">
|
||||
<div>
|
||||
<h3 id="seval-ai-fixpoints-title" className="seval-ai-verify-fixpoints-title">
|
||||
수정 포인트 (Cursor AI)
|
||||
</h3>
|
||||
<p className="seval-ai-verify-fixpoints-desc">
|
||||
로직 불일치가 감지되었습니다. 각 항목의 평가 상황·설정·결과를 Cursor에 붙여넣어 원인 분석 및 수정을 요청할 수 있습니다.
|
||||
</p>
|
||||
{bundle.verdictHint && (
|
||||
<p className="seval-ai-verify-fixpoints-verdict">AI 판정: {bundle.verdictHint}</p>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="seval-ai-verify-copy-btn"
|
||||
onClick={() => { void handleCopy(); }}
|
||||
>
|
||||
{copied ? '복사됨 ✓' : '전체 복사'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="seval-ai-verify-fixpoints-list">
|
||||
{bundle.points.map((point, idx) => {
|
||||
const open = expandedId === point.id;
|
||||
return (
|
||||
<article key={point.id} className="seval-ai-verify-fixpoint">
|
||||
<button
|
||||
type="button"
|
||||
className="seval-ai-verify-fixpoint-toggle"
|
||||
aria-expanded={open}
|
||||
onClick={() => setExpandedId(open ? null : point.id)}
|
||||
>
|
||||
<span className="seval-ai-verify-fixpoint-num">{idx + 1}</span>
|
||||
<span className="seval-ai-verify-fixpoint-title">{point.title}</span>
|
||||
<span className="seval-ai-verify-fixpoint-chevron" aria-hidden>{open ? '▾' : '▸'}</span>
|
||||
</button>
|
||||
{open && (
|
||||
<div className="seval-ai-verify-fixpoint-body">
|
||||
<div className="seval-ai-verify-fixpoint-block">
|
||||
<h4>현재 평가 상황</h4>
|
||||
{renderPreBlock(point.situation, `${point.id}-sit`)}
|
||||
</div>
|
||||
<div className="seval-ai-verify-fixpoint-block">
|
||||
<h4>설정 및 예상 결과</h4>
|
||||
{renderPreBlock(point.settingsAndExpected, `${point.id}-exp`)}
|
||||
</div>
|
||||
<div className="seval-ai-verify-fixpoint-block">
|
||||
<h4>현재 결과</h4>
|
||||
{renderPreBlock(point.actualResult, `${point.id}-act`)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
const StrategyEvaluationAiVerifyModal: React.FC<Props> = ({
|
||||
open,
|
||||
onClose,
|
||||
loading,
|
||||
error,
|
||||
contextSummary,
|
||||
verifyContext,
|
||||
result,
|
||||
onRetry,
|
||||
}) => {
|
||||
const bodyRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const fixPoints = useMemo(
|
||||
() => (verifyContext && result
|
||||
? buildAiVerifyFixPoints(verifyContext, result.analysis)
|
||||
: null),
|
||||
[verifyContext, result],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
};
|
||||
window.addEventListener('keydown', onKey);
|
||||
return () => window.removeEventListener('keydown', onKey);
|
||||
}, [open, onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
if (open && result && bodyRef.current) {
|
||||
bodyRef.current.scrollTop = 0;
|
||||
}
|
||||
}, [open, result]);
|
||||
|
||||
const handleBackdrop = useCallback((e: React.MouseEvent) => {
|
||||
if (e.target === e.currentTarget) onClose();
|
||||
}, [onClose]);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const content = (
|
||||
<div
|
||||
className="seval-ai-verify-overlay"
|
||||
role="presentation"
|
||||
onClick={handleBackdrop}
|
||||
>
|
||||
<div
|
||||
className="seval-ai-verify-modal"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="seval-ai-verify-title"
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
<header className="seval-ai-verify-head">
|
||||
<div className="seval-ai-verify-head-main">
|
||||
<h2 id="seval-ai-verify-title" className="seval-ai-verify-title">
|
||||
AI 전략평가 검증
|
||||
</h2>
|
||||
{contextSummary && (
|
||||
<p className="seval-ai-verify-summary">{contextSummary}</p>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="seval-ai-verify-close"
|
||||
aria-label="닫기"
|
||||
onClick={onClose}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div ref={bodyRef} className="seval-ai-verify-body">
|
||||
{loading && (
|
||||
<div className="seval-ai-verify-loading" aria-live="polite">
|
||||
<span className="btd-run-spinner seval-ai-verify-spinner" aria-hidden />
|
||||
<p>LLM이 평가 결과와 차트 시그널을 분석 중입니다…</p>
|
||||
<p className="seval-ai-verify-loading-hint">최대 2분 정도 걸릴 수 있습니다.</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && error && (
|
||||
<div className="seval-ai-verify-error" role="alert">
|
||||
<p>{error}</p>
|
||||
{onRetry && (
|
||||
<button type="button" className="seval-ai-verify-retry" onClick={onRetry}>
|
||||
다시 시도
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && !error && result && (
|
||||
<>
|
||||
<div className="seval-ai-verify-meta">
|
||||
<span>{result.model}</span>
|
||||
<span>{(result.latencyMs / 1000).toFixed(1)}초</span>
|
||||
</div>
|
||||
<div className="seval-ai-verify-analysis">
|
||||
{renderAnalysisMarkdown(result.analysis)}
|
||||
</div>
|
||||
{result.ta4jDiagnostics && (
|
||||
<Ta4jDiagnosticsSummary diagnostics={result.ta4jDiagnostics} />
|
||||
)}
|
||||
{fixPoints && fixPoints.hasIssue && (
|
||||
<FixPointsPanel bundle={fixPoints} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<footer className="seval-ai-verify-foot">
|
||||
<p className="seval-ai-verify-footnote">
|
||||
※ AI 분석은 참고용입니다. 수정 포인트는 Cursor 등에 붙여넣어 코드 수정을 요청할 수 있습니다.
|
||||
</p>
|
||||
<button type="button" className="seval-ai-verify-close-btn" onClick={onClose}>
|
||||
닫기
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return createPortal(content, document.body);
|
||||
};
|
||||
|
||||
export default StrategyEvaluationAiVerifyModal;
|
||||
@@ -91,6 +91,10 @@ interface Props {
|
||||
onOpenReport?: () => void;
|
||||
reportDisabled?: boolean;
|
||||
reportLoading?: boolean;
|
||||
/** AI 전략평가 검증 (LLM) */
|
||||
onOpenAiVerify?: () => void;
|
||||
aiVerifyDisabled?: boolean;
|
||||
aiVerifyLoading?: boolean;
|
||||
/** StrategyEvaluationPage 공유 ticker (종목 탭·검색과 단일 useMarketTicker) */
|
||||
marketTickers?: Map<string, TickerData>;
|
||||
marketInfos?: MarketInfo[];
|
||||
@@ -133,6 +137,9 @@ const StrategyEvaluationChart: React.FC<Props> = ({
|
||||
onOpenReport,
|
||||
reportDisabled = false,
|
||||
reportLoading = false,
|
||||
onOpenAiVerify,
|
||||
aiVerifyDisabled = false,
|
||||
aiVerifyLoading = false,
|
||||
marketTickers,
|
||||
marketInfos,
|
||||
marketLoading,
|
||||
@@ -611,6 +618,26 @@ const StrategyEvaluationChart: React.FC<Props> = ({
|
||||
)}
|
||||
</div>
|
||||
<div className="seval-chart-toolbar-actions">
|
||||
{onOpenAiVerify && (
|
||||
<button
|
||||
type="button"
|
||||
className="btd-analysis-tool seval-chart-ai-verify-btn"
|
||||
title={aiVerifyDisabled ? '전략·차트·봉 평가 데이터를 준비하세요' : 'AI 전략평가·시그널 검증'}
|
||||
aria-label="AI 검증"
|
||||
disabled={aiVerifyDisabled || aiVerifyLoading}
|
||||
onClick={onOpenAiVerify}
|
||||
>
|
||||
{aiVerifyLoading ? (
|
||||
<span className="btd-run-spinner seval-chart-ai-verify-spinner" aria-hidden />
|
||||
) : (
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden>
|
||||
<path d="M12 3l1.5 4.5L18 9l-4.5 1.5L12 15l-1.5-4.5L6 9l4.5-1.5L12 3z" />
|
||||
<path d="M5 19l1 2 2 1-2 1-1 2-1-2-2-1 1-2z" />
|
||||
<path d="M19 13l.75 1.5 1.5.75-1.5.75-.75 1.5-.75-1.5L17.5 15l1.5-.75.75-1.5z" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
{onOpenReport && (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -55,6 +55,10 @@ import {
|
||||
resolveTrendSearchAppSettings,
|
||||
type TrendSearchAppSettings,
|
||||
} from '../utils/trendSearchAppSettings';
|
||||
import {
|
||||
resolveLlmAppSettings,
|
||||
type LlmAppSettings,
|
||||
} from '../utils/llmSettings';
|
||||
import {
|
||||
resolveChartPaneSeparatorOptions,
|
||||
type ChartPaneSeparatorOptions,
|
||||
@@ -215,6 +219,9 @@ export function resolveAppDefaults(s: AppSettingsDto) {
|
||||
trendSearchSettings: resolveTrendSearchAppSettings(
|
||||
s.trendSearchSettings as Partial<TrendSearchAppSettings> | null | undefined,
|
||||
),
|
||||
llmSettings: resolveLlmAppSettings(
|
||||
s.llmSettings as Partial<LlmAppSettings> | null | undefined,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -397,6 +397,381 @@
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
.seval-chart-ai-verify-btn {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
border-radius: 6px;
|
||||
color: color-mix(in srgb, var(--btd-gold, var(--se-gold)) 85%, var(--se-text-muted));
|
||||
}
|
||||
|
||||
.seval-chart-ai-verify-btn:hover:not(:disabled) {
|
||||
color: var(--btd-gold, var(--se-gold));
|
||||
background: color-mix(in srgb, var(--btd-gold, var(--se-gold)) 12%, var(--se-input-bg));
|
||||
}
|
||||
|
||||
.seval-chart-ai-verify-spinner {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
/* ── AI 검증 모달 ─────────────────────────────────────────────── */
|
||||
.seval-ai-verify-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 12000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
}
|
||||
|
||||
.seval-ai-verify-modal {
|
||||
width: min(720px, 100%);
|
||||
max-height: min(88vh, 820px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--se-border);
|
||||
background: var(--se-panel-bg, #1a1d24);
|
||||
box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
|
||||
.seval-ai-verify-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 16px 18px 12px;
|
||||
border-bottom: 1px solid var(--se-border);
|
||||
}
|
||||
|
||||
.seval-ai-verify-title {
|
||||
margin: 0;
|
||||
font-size: 1.05rem;
|
||||
font-weight: 600;
|
||||
color: var(--se-text);
|
||||
}
|
||||
|
||||
.seval-ai-verify-summary {
|
||||
margin: 6px 0 0;
|
||||
font-size: 0.78rem;
|
||||
color: var(--se-text-muted);
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.seval-ai-verify-close {
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--se-text-muted);
|
||||
font-size: 1.5rem;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.seval-ai-verify-body {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding: 16px 18px;
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.seval-ai-verify-loading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 32px 12px;
|
||||
text-align: center;
|
||||
color: var(--se-text-muted);
|
||||
}
|
||||
|
||||
.seval-ai-verify-spinner {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
}
|
||||
|
||||
.seval-ai-verify-loading-hint {
|
||||
font-size: 0.78rem;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.seval-ai-verify-error {
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
background: color-mix(in srgb, #ef5350 12%, transparent);
|
||||
color: #ffb4ab;
|
||||
}
|
||||
|
||||
.seval-ai-verify-retry {
|
||||
margin-top: 12px;
|
||||
padding: 6px 14px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--se-border);
|
||||
background: var(--se-input-bg);
|
||||
color: var(--se-text);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.seval-ai-verify-meta {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
font-size: 0.75rem;
|
||||
color: var(--se-text-muted);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.seval-ai-verify-h3 {
|
||||
margin: 16px 0 8px;
|
||||
font-size: 0.92rem;
|
||||
font-weight: 600;
|
||||
color: var(--btd-gold, var(--se-gold));
|
||||
}
|
||||
|
||||
.seval-ai-verify-h3:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.seval-ai-verify-p {
|
||||
margin: 0 0 8px;
|
||||
font-size: 0.84rem;
|
||||
line-height: 1.55;
|
||||
color: var(--se-text);
|
||||
}
|
||||
|
||||
.seval-ai-verify-list {
|
||||
margin: 0 0 10px;
|
||||
padding-left: 1.2rem;
|
||||
font-size: 0.84rem;
|
||||
line-height: 1.5;
|
||||
color: var(--se-text);
|
||||
}
|
||||
|
||||
.seval-ai-verify-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 12px 18px 16px;
|
||||
border-top: 1px solid var(--se-border);
|
||||
}
|
||||
|
||||
.seval-ai-verify-footnote {
|
||||
margin: 0;
|
||||
font-size: 0.72rem;
|
||||
color: var(--se-text-muted);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.seval-ai-verify-close-btn {
|
||||
flex-shrink: 0;
|
||||
padding: 6px 16px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--se-border);
|
||||
background: var(--se-input-bg);
|
||||
color: var(--se-text);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* ── AI 검증 수정 포인트 (Cursor) ── */
|
||||
.seval-ai-verify-fixpoints {
|
||||
margin-top: 20px;
|
||||
padding-top: 16px;
|
||||
border-top: 1px dashed var(--se-border);
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoints-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoints-title {
|
||||
margin: 0 0 6px;
|
||||
font-size: 0.92rem;
|
||||
font-weight: 600;
|
||||
color: #ffb74d;
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoints-desc {
|
||||
margin: 0;
|
||||
font-size: 0.78rem;
|
||||
line-height: 1.45;
|
||||
color: var(--se-text-muted);
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoints-verdict {
|
||||
margin: 8px 0 0;
|
||||
font-size: 0.78rem;
|
||||
color: var(--se-text);
|
||||
}
|
||||
|
||||
.seval-ai-verify-copy-btn {
|
||||
flex-shrink: 0;
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid color-mix(in srgb, #ffb74d 45%, var(--se-border));
|
||||
background: color-mix(in srgb, #ffb74d 10%, transparent);
|
||||
color: #ffb74d;
|
||||
font-size: 0.78rem;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.seval-ai-verify-copy-btn:hover {
|
||||
background: color-mix(in srgb, #ffb74d 18%, transparent);
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoints-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoint {
|
||||
border: 1px solid var(--se-border);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: color-mix(in srgb, var(--se-input-bg) 80%, transparent);
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoint-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--se-text);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoint-toggle:hover {
|
||||
background: color-mix(in srgb, var(--se-border) 30%, transparent);
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoint-num {
|
||||
flex-shrink: 0;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
background: color-mix(in srgb, #ffb74d 20%, transparent);
|
||||
color: #ffb74d;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoint-title {
|
||||
flex: 1;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoint-chevron {
|
||||
flex-shrink: 0;
|
||||
color: var(--se-text-muted);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoint-body {
|
||||
padding: 0 12px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.seval-ai-verify-fixpoint-block h4 {
|
||||
margin: 0 0 4px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
color: var(--se-text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
.seval-ai-verify-pre {
|
||||
margin: 0;
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--se-border);
|
||||
background: var(--se-panel-bg, #14161a);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
font-size: 0.72rem;
|
||||
line-height: 1.5;
|
||||
color: var(--se-text);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
max-height: 220px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.seval-ai-verify-ta4j {
|
||||
margin-top: 16px;
|
||||
border: 1px solid var(--se-border);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.seval-ai-verify-ta4j-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: none;
|
||||
background: color-mix(in srgb, var(--se-input-bg) 90%, transparent);
|
||||
color: var(--se-text);
|
||||
font-size: 0.82rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.seval-ai-verify-ta4j-body {
|
||||
padding: 10px 12px 12px;
|
||||
border-top: 1px solid var(--se-border);
|
||||
}
|
||||
|
||||
.seval-ai-verify-ta4j-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px 16px;
|
||||
font-size: 0.78rem;
|
||||
color: var(--se-text-muted);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.seval-ai-verify-ta4j-cmp {
|
||||
margin: 0 0 8px;
|
||||
font-size: 0.78rem;
|
||||
line-height: 1.45;
|
||||
color: var(--se-text);
|
||||
}
|
||||
|
||||
.seval-ai-verify-ta4j-err {
|
||||
margin: 0 0 8px;
|
||||
color: #ffb4ab;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.seval-ai-verify-ta4j-trace-title {
|
||||
margin: 8px 0 4px;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
color: var(--se-text-muted);
|
||||
}
|
||||
|
||||
.seval-chart-magnifier-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -556,6 +556,8 @@ export interface AppSettingsDto {
|
||||
tradeAlertTimeFormat?: string;
|
||||
/** 추세검색 기본 설정 */
|
||||
trendSearchSettings?: import('./trendSearchAppSettings').TrendSearchAppSettings | null;
|
||||
/** LLM(AI 검증) 연결·모델 설정 */
|
||||
llmSettings?: import('./llmSettings').LlmAppSettings | null;
|
||||
/** UI 설정 통합 (편집기·팔레트·가상투자 목록·패널 크기 등) */
|
||||
uiPreferences?: import('../types/uiPreferences').UiPreferences | null;
|
||||
}
|
||||
@@ -1676,6 +1678,40 @@ export async function fetchLiveConditionScanSignals(
|
||||
return list ?? [];
|
||||
}
|
||||
|
||||
export interface StrategyEvaluationAiVerifyResponse {
|
||||
analysis: string;
|
||||
model: string;
|
||||
latencyMs: number;
|
||||
/** 서버 Ta4j 재평가·Rule·trace (백엔드 ai-verify 재평가) */
|
||||
ta4jDiagnostics?: Record<string, unknown> | null;
|
||||
}
|
||||
|
||||
/** 전략 평가 — LLM 기반 Rule·시그널 일치 검증 */
|
||||
export async function fetchStrategyEvaluationAiVerify(
|
||||
context: Record<string, unknown>,
|
||||
): Promise<StrategyEvaluationAiVerifyResponse> {
|
||||
return requestOrThrow<StrategyEvaluationAiVerifyResponse>('/strategy/evaluation/ai-verify', {
|
||||
method: 'POST',
|
||||
cache: 'no-store',
|
||||
body: JSON.stringify({ context }),
|
||||
});
|
||||
}
|
||||
|
||||
export interface LlmConnectionTestResponse {
|
||||
ok: boolean;
|
||||
message: string;
|
||||
model?: string;
|
||||
latencyMs?: number;
|
||||
}
|
||||
|
||||
/** 설정 화면 — LLM 서버 연결 테스트 (저장된 설정 기준) */
|
||||
export async function fetchLlmConnectionTest(): Promise<LlmConnectionTestResponse> {
|
||||
return requestOrThrow<LlmConnectionTestResponse>('/strategy/evaluation/llm-test', {
|
||||
method: 'POST',
|
||||
cache: 'no-store',
|
||||
});
|
||||
}
|
||||
|
||||
/** 전략 DSL에 포함된 평가 시간봉 목록 (실시간 체크·STOMP 구독용) */
|
||||
export async function loadStrategyTimeframes(strategyId: number): Promise<string[]> {
|
||||
if (!hasRegisteredUser()) return ['1m'];
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* LLM(AI 검증) 앱 설정 (gc_app_settings.llm_settings_json)
|
||||
*/
|
||||
|
||||
export interface LlmAppSettings {
|
||||
/** LLM AI 검증 사용 여부 */
|
||||
enabled: boolean;
|
||||
/** LLM 서버 호스트 (IP 또는 도메인) */
|
||||
host: string;
|
||||
/** LLM 서버 포트 */
|
||||
port: number;
|
||||
/** HTTPS 사용 여부 */
|
||||
useHttps: boolean;
|
||||
/** OpenAI 호환 chat completions 경로 */
|
||||
chatPath: string;
|
||||
/** 모델 ID */
|
||||
model: string;
|
||||
/** 최대 생성 토큰 */
|
||||
maxTokens: number;
|
||||
/** temperature (0~2) */
|
||||
temperature: number;
|
||||
/** 요청 타임아웃 (ms) */
|
||||
timeoutMs: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_LLM_APP_SETTINGS: LlmAppSettings = {
|
||||
enabled: true,
|
||||
host: '127.0.0.1',
|
||||
port: 16000,
|
||||
useHttps: false,
|
||||
chatPath: '/v1/chat/completions',
|
||||
model: 'mlx-community/Qwen2.5-7B-Instruct-4bit',
|
||||
maxTokens: 1024,
|
||||
temperature: 0.1,
|
||||
timeoutMs: 120_000,
|
||||
};
|
||||
|
||||
function clampInt(v: unknown, min: number, max: number, fallback: number): number {
|
||||
const n = Number(v);
|
||||
if (!Number.isFinite(n)) return fallback;
|
||||
return Math.max(min, Math.min(max, Math.round(n)));
|
||||
}
|
||||
|
||||
function clampFloat(v: unknown, min: number, max: number, fallback: number): number {
|
||||
const n = Number(v);
|
||||
if (!Number.isFinite(n)) return fallback;
|
||||
return Math.max(min, Math.min(max, n));
|
||||
}
|
||||
|
||||
export function resolveLlmAppSettings(
|
||||
raw?: Partial<LlmAppSettings> | null,
|
||||
): LlmAppSettings {
|
||||
const d = DEFAULT_LLM_APP_SETTINGS;
|
||||
if (!raw || typeof raw !== 'object') return { ...d };
|
||||
const host = typeof raw.host === 'string' && raw.host.trim() ? raw.host.trim() : d.host;
|
||||
const chatPath = typeof raw.chatPath === 'string' && raw.chatPath.trim()
|
||||
? (raw.chatPath.startsWith('/') ? raw.chatPath.trim() : `/${raw.chatPath.trim()}`)
|
||||
: d.chatPath;
|
||||
const model = typeof raw.model === 'string' && raw.model.trim() ? raw.model.trim() : d.model;
|
||||
return {
|
||||
enabled: raw.enabled === undefined ? d.enabled : Boolean(raw.enabled),
|
||||
host,
|
||||
port: clampInt(raw.port, 1, 65535, d.port),
|
||||
useHttps: raw.useHttps === undefined ? d.useHttps : Boolean(raw.useHttps),
|
||||
chatPath,
|
||||
model,
|
||||
maxTokens: clampInt(raw.maxTokens, 64, 8192, d.maxTokens),
|
||||
temperature: clampFloat(raw.temperature, 0, 2, d.temperature),
|
||||
timeoutMs: clampInt(raw.timeoutMs, 5_000, 600_000, d.timeoutMs),
|
||||
};
|
||||
}
|
||||
|
||||
/** 설정 UI용 — host·port·프로토콜로 base URL 미리보기 */
|
||||
export function buildLlmBaseUrl(settings: LlmAppSettings): string {
|
||||
const scheme = settings.useHttps ? 'https' : 'http';
|
||||
const omitPort = (settings.useHttps && settings.port === 443)
|
||||
|| (!settings.useHttps && settings.port === 80);
|
||||
if (omitPort) return `${scheme}://${settings.host}`;
|
||||
return `${scheme}://${settings.host}:${settings.port}`;
|
||||
}
|
||||
|
||||
export function buildLlmEndpointUrl(settings: LlmAppSettings): string {
|
||||
return `${buildLlmBaseUrl(settings)}${settings.chatPath}`;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ export type TopMenuId = MenuPage;
|
||||
|
||||
export type SettingsCategoryId =
|
||||
| 'general' | 'chart' | 'indicators' | 'backtest' | 'strategy'
|
||||
| 'trading' | 'paper' | 'virtual' | 'live' | 'trend-search' | 'alert' | 'network' | 'admin';
|
||||
| 'trading' | 'paper' | 'virtual' | 'live' | 'trend-search' | 'llm' | 'alert' | 'network' | 'admin';
|
||||
|
||||
export const TOP_MENU_IDS: TopMenuId[] = [
|
||||
'dashboard', 'widget-dashboard', 'chart', 'paper', 'virtual', 'trend-search', 'strategy-editor', 'strategy-evaluation', 'backtest', 'analysis-report', 'notifications', 'settings', 'verification-board',
|
||||
@@ -17,7 +17,7 @@ export const TOP_MENU_IDS: TopMenuId[] = [
|
||||
|
||||
export const SETTINGS_MENU_IDS: SettingsCategoryId[] = [
|
||||
'general', 'chart', 'indicators', 'backtest', 'strategy', 'trading', 'live',
|
||||
'trend-search', 'alert', 'network', 'admin',
|
||||
'trend-search', 'llm', 'alert', 'network', 'admin',
|
||||
];
|
||||
|
||||
export const ALL_MENU_IDS = [
|
||||
@@ -52,6 +52,7 @@ export const MENU_LABELS: Record<string, string> = {
|
||||
settings_virtual: '설정 · 가상매매',
|
||||
settings_live: '설정 · 실거래',
|
||||
'settings_trend-search': '설정 · 추세검색',
|
||||
settings_llm: '설정 · LLM',
|
||||
settings_alert: '설정 · 알림',
|
||||
settings_network: '설정 · 네트워크',
|
||||
settings_admin: '설정 · 관리자',
|
||||
|
||||
@@ -0,0 +1,698 @@
|
||||
/**
|
||||
* 전략 평가 AI 검증 — LLM 전달용 컨텍스트 구성 및 API 호출
|
||||
*/
|
||||
import type { BacktestSignal, StrategyDto, StrategyEvaluationAiVerifyResponse } from './backendApi';
|
||||
import { fetchStrategyEvaluationAiVerify } from './backendApi';
|
||||
import type { OHLCVBar } from '../types';
|
||||
import type { VirtualIndicatorSnapshot } from '../hooks/useVirtualIndicatorSnapshots';
|
||||
import type { BarSignalHighlight } from './strategyEvaluationBarSignals';
|
||||
import { resolveBarSignalHighlight } from './strategyEvaluationBarSignals';
|
||||
import { formatIndicatorValue } from './virtualStrategyConditions';
|
||||
import { formatVirtualConditionListLabel } from './virtualStrategyConditions';
|
||||
import { buildConditionMetrics } from './virtualSignalMetrics';
|
||||
import { repairUtf8Mojibake } from './textEncoding';
|
||||
import { normalizeEpochSecOptional } from './backtestUiUtils';
|
||||
|
||||
export interface StrategyEvaluationAiVerifyContext {
|
||||
meta: {
|
||||
generatedAt: string;
|
||||
purpose: string;
|
||||
};
|
||||
strategy: {
|
||||
id: number;
|
||||
name: string;
|
||||
buyCondition: unknown;
|
||||
sellCondition: unknown;
|
||||
};
|
||||
chart: {
|
||||
market: string;
|
||||
timeframe: string;
|
||||
barCount: number;
|
||||
evaluationBarCount?: number;
|
||||
/** AI 검증 시 서버 Ta4j 재평가용 — 차트와 동일 OHLCV (평가 구간) */
|
||||
barsForEvaluation?: Array<{
|
||||
time: number;
|
||||
open: number;
|
||||
high: number;
|
||||
low: number;
|
||||
close: number;
|
||||
volume: number;
|
||||
}>;
|
||||
selectedBarIndex: number;
|
||||
selectedBar: {
|
||||
time: number;
|
||||
timeLabel: string;
|
||||
open: number;
|
||||
high: number;
|
||||
low: number;
|
||||
close: number;
|
||||
volume: number;
|
||||
} | null;
|
||||
};
|
||||
evaluation: {
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
matchRate: number | null;
|
||||
overallEntryMet: boolean | null;
|
||||
overallExitMet: boolean | null;
|
||||
buyConditions: Array<{
|
||||
id: string;
|
||||
label: string;
|
||||
side: string;
|
||||
timeframe: string;
|
||||
indicatorType: string;
|
||||
conditionType: string;
|
||||
targetValue: number | null;
|
||||
currentValue: number | null;
|
||||
satisfied: boolean | null;
|
||||
thresholdLabel?: string;
|
||||
}>;
|
||||
sellConditions: Array<{
|
||||
id: string;
|
||||
label: string;
|
||||
side: string;
|
||||
timeframe: string;
|
||||
indicatorType: string;
|
||||
conditionType: string;
|
||||
targetValue: number | null;
|
||||
currentValue: number | null;
|
||||
satisfied: boolean | null;
|
||||
thresholdLabel?: string;
|
||||
}>;
|
||||
};
|
||||
signals: {
|
||||
totalOnChart: number;
|
||||
selectedBarHighlight: BarSignalHighlight;
|
||||
selectedBarSignals: Array<{
|
||||
type: string;
|
||||
time: number;
|
||||
price: number;
|
||||
barIndex: number;
|
||||
}>;
|
||||
nearbySignals: Array<{
|
||||
type: string;
|
||||
time: number;
|
||||
barIndex: number;
|
||||
offsetFromSelected: number;
|
||||
}>;
|
||||
};
|
||||
indicatorParams?: Record<string, Record<string, unknown>> | null;
|
||||
deterministicHints: {
|
||||
expectedBuySignalAtBar: boolean;
|
||||
expectedSellSignalAtBar: boolean;
|
||||
signalMatchesOverallRule: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type { StrategyEvaluationAiVerifyResponse };
|
||||
|
||||
export function buildStrategyEvaluationAiVerifyContext(opts: {
|
||||
strategy: StrategyDto;
|
||||
strategyId: number;
|
||||
market: string;
|
||||
timeframe: string;
|
||||
bars: OHLCVBar[];
|
||||
selectedBarIndex: number;
|
||||
snapshot: VirtualIndicatorSnapshot | undefined;
|
||||
evalLoading: boolean;
|
||||
evalError: string | null;
|
||||
chartSignals: BacktestSignal[];
|
||||
barSignalHighlight: BarSignalHighlight;
|
||||
indicatorParams?: Record<string, Record<string, unknown>> | null;
|
||||
evaluationBarCount?: number;
|
||||
}): StrategyEvaluationAiVerifyContext {
|
||||
const {
|
||||
strategy,
|
||||
strategyId,
|
||||
market,
|
||||
timeframe,
|
||||
bars,
|
||||
selectedBarIndex,
|
||||
snapshot,
|
||||
evalLoading,
|
||||
evalError,
|
||||
chartSignals,
|
||||
barSignalHighlight,
|
||||
indicatorParams,
|
||||
evaluationBarCount,
|
||||
} = opts;
|
||||
|
||||
const selectedBar = bars[selectedBarIndex] ?? null;
|
||||
const barTimeSec = selectedBar?.time ?? null;
|
||||
|
||||
const buyMetrics = snapshot?.rows
|
||||
? buildConditionMetrics(snapshot.rows.filter(r => r.side === 'buy'))
|
||||
: [];
|
||||
const sellMetrics = snapshot?.rows
|
||||
? buildConditionMetrics(snapshot.rows.filter(r => r.side === 'sell'))
|
||||
: [];
|
||||
|
||||
const mapCondition = (m: typeof buyMetrics[number]) => ({
|
||||
id: m.row.id,
|
||||
label: formatVirtualConditionListLabel(m.row),
|
||||
side: m.row.side,
|
||||
timeframe: m.row.timeframe,
|
||||
indicatorType: m.row.indicatorType,
|
||||
conditionType: m.row.conditionType,
|
||||
targetValue: m.row.targetValue,
|
||||
currentValue: m.row.currentValue,
|
||||
satisfied: m.row.satisfied ?? null,
|
||||
thresholdLabel: m.row.thresholdLabel,
|
||||
});
|
||||
|
||||
const selectedBarSignals = chartSignals.filter(s =>
|
||||
signalMatchesBar(s, selectedBarIndex, barTimeSec ?? 0),
|
||||
).map(s => ({
|
||||
type: s.type,
|
||||
time: s.time,
|
||||
price: s.price,
|
||||
barIndex: s.barIndex,
|
||||
}));
|
||||
|
||||
const nearbySignals = chartSignals
|
||||
.map(s => ({
|
||||
signal: s,
|
||||
offset: s.barIndex - selectedBarIndex,
|
||||
}))
|
||||
.filter(x => Math.abs(x.offset) <= 5 && x.offset !== 0)
|
||||
.sort((a, b) => a.offset - b.offset)
|
||||
.slice(0, 12)
|
||||
.map(x => ({
|
||||
type: x.signal.type,
|
||||
time: x.signal.time,
|
||||
barIndex: x.signal.barIndex,
|
||||
offsetFromSelected: x.offset,
|
||||
}));
|
||||
|
||||
const overallEntryMet = snapshot?.overallEntryMet ?? null;
|
||||
const overallExitMet = snapshot?.overallExitMet ?? null;
|
||||
|
||||
const evalCount = evaluationBarCount ?? bars.length;
|
||||
const barsForEvaluation = bars.slice(Math.max(0, bars.length - evalCount)).map(b => ({
|
||||
time: b.time,
|
||||
open: b.open,
|
||||
high: b.high,
|
||||
low: b.low,
|
||||
close: b.close,
|
||||
volume: b.volume,
|
||||
}));
|
||||
|
||||
let signalMatchesOverallRule = '평가 데이터 없음';
|
||||
if (overallEntryMet != null || overallExitMet != null) {
|
||||
const parts: string[] = [];
|
||||
if (overallEntryMet === true && !barSignalHighlight.buy) {
|
||||
parts.push('매수 Rule 충족인데 선택 봉 BUY 시그널 없음 — 포지션 모드·중복 방지·스캔 범위 확인 필요');
|
||||
}
|
||||
if (overallEntryMet === false && barSignalHighlight.buy) {
|
||||
parts.push('매수 Rule 미충족인데 선택 봉 BUY 시그널 있음 — 불일치 의심');
|
||||
}
|
||||
if (overallExitMet === true && !barSignalHighlight.sell) {
|
||||
parts.push('매도 Rule 충족인데 선택 봉 SELL 시그널 없음 — 포지션·스캔 범위 확인 필요');
|
||||
}
|
||||
if (overallExitMet === false && barSignalHighlight.sell) {
|
||||
parts.push('매도 Rule 미충족인데 선택 봉 SELL 시그널 있음 — 불일치 의심');
|
||||
}
|
||||
if (parts.length === 0) {
|
||||
parts.push('전체 Rule과 선택 봉 시그널 표시가 대체로 일치');
|
||||
}
|
||||
signalMatchesOverallRule = parts.join('; ');
|
||||
}
|
||||
|
||||
return {
|
||||
meta: {
|
||||
generatedAt: new Date().toISOString(),
|
||||
purpose: '전략평가 Ta4j Rule 결과와 차트 매매 시그널 일치 여부 검증',
|
||||
},
|
||||
strategy: {
|
||||
id: strategyId,
|
||||
name: repairUtf8Mojibake(strategy.name ?? `전략 #${strategyId}`),
|
||||
buyCondition: strategy.buyCondition ?? null,
|
||||
sellCondition: strategy.sellCondition ?? null,
|
||||
},
|
||||
chart: {
|
||||
market,
|
||||
timeframe,
|
||||
barCount: bars.length,
|
||||
evaluationBarCount,
|
||||
barsForEvaluation,
|
||||
selectedBarIndex,
|
||||
selectedBar: selectedBar
|
||||
? {
|
||||
time: selectedBar.time,
|
||||
timeLabel: new Date(selectedBar.time * 1000).toLocaleString('ko-KR'),
|
||||
open: selectedBar.open,
|
||||
high: selectedBar.high,
|
||||
low: selectedBar.low,
|
||||
close: selectedBar.close,
|
||||
volume: selectedBar.volume,
|
||||
}
|
||||
: null,
|
||||
},
|
||||
evaluation: {
|
||||
loading: evalLoading,
|
||||
error: evalError,
|
||||
matchRate: snapshot?.matchRate ?? null,
|
||||
overallEntryMet,
|
||||
overallExitMet,
|
||||
buyConditions: buyMetrics.map(mapCondition),
|
||||
sellConditions: sellMetrics.map(mapCondition),
|
||||
},
|
||||
signals: {
|
||||
totalOnChart: chartSignals.length,
|
||||
selectedBarHighlight: barSignalHighlight,
|
||||
selectedBarSignals,
|
||||
nearbySignals,
|
||||
},
|
||||
indicatorParams: indicatorParams ?? null,
|
||||
deterministicHints: {
|
||||
expectedBuySignalAtBar: overallEntryMet === true,
|
||||
expectedSellSignalAtBar: overallExitMet === true,
|
||||
signalMatchesOverallRule,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function signalMatchesBar(
|
||||
signal: BacktestSignal,
|
||||
barIndex: number,
|
||||
barTimeSec: number,
|
||||
): boolean {
|
||||
if (signal.barIndex === barIndex) return true;
|
||||
const signalTime = normalizeEpochSecOptional(signal.time);
|
||||
const barTime = normalizeEpochSecOptional(barTimeSec);
|
||||
return signalTime > 0 && barTime > 0 && signalTime === barTime;
|
||||
}
|
||||
|
||||
export async function requestStrategyEvaluationAiVerify(
|
||||
context: StrategyEvaluationAiVerifyContext,
|
||||
): Promise<StrategyEvaluationAiVerifyResponse> {
|
||||
return fetchStrategyEvaluationAiVerify(context as unknown as Record<string, unknown>);
|
||||
}
|
||||
|
||||
/** UI 요약 — 컨텍스트 미리보기 */
|
||||
export function summarizeVerifyContext(ctx: StrategyEvaluationAiVerifyContext): string {
|
||||
const bar = ctx.chart.selectedBar;
|
||||
const buyOk = ctx.evaluation.overallEntryMet;
|
||||
const sellOk = ctx.evaluation.overallExitMet;
|
||||
return [
|
||||
bar ? `봉 ${bar.timeLabel}` : '봉 미선택',
|
||||
buyOk != null ? `매수 ${buyOk ? '충족' : '미충족'}` : '매수 평가 없음',
|
||||
sellOk != null ? `매도 ${sellOk ? '충족' : '미충족'}` : '매도 평가 없음',
|
||||
`차트 시그널 ${ctx.signals.totalOnChart}건`,
|
||||
ctx.signals.selectedBarSignals.length > 0
|
||||
? `선택 봉 시그널 ${ctx.signals.selectedBarSignals.map(s => s.type).join(', ')}`
|
||||
: '선택 봉 시그널 없음',
|
||||
].join(' · ');
|
||||
}
|
||||
|
||||
/** Cursor AI에 붙여넣을 수정 포인트 항목 */
|
||||
export interface AiVerifyFixPoint {
|
||||
id: string;
|
||||
title: string;
|
||||
/** 현재 평가 상황 */
|
||||
situation: string;
|
||||
/** 설정 및 예상 결과 */
|
||||
settingsAndExpected: string;
|
||||
/** 현재 결과 */
|
||||
actualResult: string;
|
||||
}
|
||||
|
||||
export interface AiVerifyFixPointsBundle {
|
||||
hasIssue: boolean;
|
||||
verdictHint: string | null;
|
||||
points: AiVerifyFixPoint[];
|
||||
cursorPrompt: string;
|
||||
}
|
||||
|
||||
function formatConditionLines(
|
||||
conditions: StrategyEvaluationAiVerifyContext['evaluation']['buyConditions'],
|
||||
): string {
|
||||
if (conditions.length === 0) return '(조건 없음)';
|
||||
return conditions.map(c => {
|
||||
const status = c.satisfied === true ? '충족' : c.satisfied === false ? '미충족' : '평가불가';
|
||||
const cur = c.currentValue != null ? String(c.currentValue) : '-';
|
||||
const target = c.thresholdLabel ?? (c.targetValue != null ? String(c.targetValue) : '-');
|
||||
return `- [${c.id}] ${c.label} (${c.timeframe}/${c.indicatorType}): ${status} · 현재=${cur} · 기준=${target}`;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
function formatDslSummary(condition: unknown): string {
|
||||
if (condition == null) return '(DSL 없음)';
|
||||
try {
|
||||
const s = JSON.stringify(condition, null, 2);
|
||||
return s.length > 1200 ? `${s.slice(0, 1200)}\n…(생략)` : s;
|
||||
} catch {
|
||||
return String(condition);
|
||||
}
|
||||
}
|
||||
|
||||
function formatIndicatorParamsSummary(
|
||||
params: Record<string, Record<string, unknown>> | null | undefined,
|
||||
): string {
|
||||
if (!params || Object.keys(params).length === 0) return '(지표 파라미터 없음)';
|
||||
try {
|
||||
const s = JSON.stringify(params, null, 2);
|
||||
return s.length > 800 ? `${s.slice(0, 800)}\n…(생략)` : s;
|
||||
} catch {
|
||||
return '(직렬화 실패)';
|
||||
}
|
||||
}
|
||||
|
||||
function chartSituationSummary(ctx: StrategyEvaluationAiVerifyContext): string {
|
||||
const bar = ctx.chart.selectedBar;
|
||||
const lines = [
|
||||
`전략: ${ctx.strategy.name} (#${ctx.strategy.id})`,
|
||||
`종목/타임프레임: ${ctx.chart.market} / ${ctx.chart.timeframe}`,
|
||||
bar
|
||||
? `선택 봉: index=${ctx.chart.selectedBarIndex}, ${bar.timeLabel}, O=${bar.open} H=${bar.high} L=${bar.low} C=${bar.close}`
|
||||
: '선택 봉: 없음',
|
||||
`평가 범위: 차트 ${ctx.chart.barCount}봉` + (ctx.chart.evaluationBarCount != null
|
||||
? ` · Rule 평가 ${ctx.chart.evaluationBarCount}봉`
|
||||
: ''),
|
||||
ctx.evaluation.matchRate != null ? `조건 일치율: ${ctx.evaluation.matchRate}%` : null,
|
||||
ctx.evaluation.error ? `평가 오류: ${ctx.evaluation.error}` : null,
|
||||
].filter(Boolean);
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
/** LLM 종합 판정에서 로직 문제 여부 추정 */
|
||||
export function detectLogicIssueFromAnalysis(analysis: string): boolean {
|
||||
const text = analysis.replace(/\r/g, '');
|
||||
const verdict = text.match(/##\s*종합\s*판정\s*\n([\s\S]*?)(?=\n##|$)/i);
|
||||
if (verdict) {
|
||||
const body = verdict[1].trim();
|
||||
const head = body.split('\n').slice(0, 4).join(' ');
|
||||
if (/오류\s*의심|주의|불일치|로직\s*문제|의심/.test(head)) return true;
|
||||
if (/정상/.test(head) && !/주의|오류/.test(head)) return false;
|
||||
}
|
||||
return /\b(오류\s*의심|불일치|로직\s*문제)\b/.test(text);
|
||||
}
|
||||
|
||||
function extractVerdictHint(analysis: string | null | undefined): string | null {
|
||||
if (!analysis) return null;
|
||||
const m = analysis.replace(/\r/g, '').match(/##\s*종합\s*판정\s*\n([\s\S]*?)(?=\n##|$)/i);
|
||||
if (!m) return null;
|
||||
const line = m[1].trim().split('\n').find(l => l.trim())?.trim();
|
||||
return line ?? null;
|
||||
}
|
||||
|
||||
function pushBuySignalMismatch(ctx: StrategyEvaluationAiVerifyContext, points: AiVerifyFixPoint[]) {
|
||||
const { overallEntryMet, buyConditions } = ctx.evaluation;
|
||||
const buyHighlight = ctx.signals.selectedBarHighlight.buy;
|
||||
if (overallEntryMet !== true || buyHighlight) return;
|
||||
|
||||
points.push({
|
||||
id: 'buy-rule-no-signal',
|
||||
title: '매수 Rule 충족 ↔ 차트 BUY 시그널 없음',
|
||||
situation: [
|
||||
chartSituationSummary(ctx),
|
||||
'',
|
||||
'【매수 조건 평가】',
|
||||
`overallEntryMet: true (전체 매수 Rule 충족)`,
|
||||
formatConditionLines(buyConditions),
|
||||
'',
|
||||
'【선택 봉 차트 시그널】',
|
||||
`BUY: 없음 · SELL: ${ctx.signals.selectedBarHighlight.sell ? '있음' : '없음'}`,
|
||||
].join('\n'),
|
||||
settingsAndExpected: [
|
||||
'전략 매수 DSL:',
|
||||
formatDslSummary(ctx.strategy.buyCondition),
|
||||
'',
|
||||
'지표 파라미터:',
|
||||
formatIndicatorParamsSummary(ctx.indicatorParams),
|
||||
'',
|
||||
'예상 결과:',
|
||||
'- Ta4j overallEntryMet=true 이면 해당 봉(또는 Rule 실행 시점)에 BUY 시그널이 차트에 표시되어야 함',
|
||||
'- 포지션 모드(LONG_ONLY 등)·이미 보유·중복 방지·스캔 범위(evaluationBarCount)에 따라 시그널이 생략될 수 있음',
|
||||
`- deterministicHints.expectedBuySignalAtBar: ${ctx.deterministicHints.expectedBuySignalAtBar}`,
|
||||
].join('\n'),
|
||||
actualResult: [
|
||||
`선택 봉 BUY 시그널: 없음`,
|
||||
`overallEntryMet: true`,
|
||||
`힌트: ${ctx.deterministicHints.signalMatchesOverallRule}`,
|
||||
ctx.signals.nearbySignals.length > 0
|
||||
? `인접 봉 시그널: ${ctx.signals.nearbySignals.map(s => `${s.type}@${s.offsetFromSelected > 0 ? '+' : ''}${s.offsetFromSelected}`).join(', ')}`
|
||||
: '인접 봉(±5) 시그널: 없음',
|
||||
].join('\n'),
|
||||
});
|
||||
}
|
||||
|
||||
function pushSellSignalMismatch(ctx: StrategyEvaluationAiVerifyContext, points: AiVerifyFixPoint[]) {
|
||||
const { overallExitMet, sellConditions } = ctx.evaluation;
|
||||
const sellHighlight = ctx.signals.selectedBarHighlight.sell;
|
||||
if (overallExitMet !== true || sellHighlight) return;
|
||||
|
||||
points.push({
|
||||
id: 'sell-rule-no-signal',
|
||||
title: '매도 Rule 충족 ↔ 차트 SELL 시그널 없음',
|
||||
situation: [
|
||||
chartSituationSummary(ctx),
|
||||
'',
|
||||
'【매도 조건 평가】',
|
||||
`overallExitMet: true (전체 매도 Rule 충족)`,
|
||||
formatConditionLines(sellConditions),
|
||||
'',
|
||||
'【선택 봉 차트 시그널】',
|
||||
`BUY: ${ctx.signals.selectedBarHighlight.buy ? '있음' : '없음'} · SELL: 없음`,
|
||||
].join('\n'),
|
||||
settingsAndExpected: [
|
||||
'전략 매도 DSL:',
|
||||
formatDslSummary(ctx.strategy.sellCondition),
|
||||
'',
|
||||
'지표 파라미터:',
|
||||
formatIndicatorParamsSummary(ctx.indicatorParams),
|
||||
'',
|
||||
'예상 결과:',
|
||||
'- Ta4j overallExitMet=true 이면 해당 봉에 SELL 시그널이 차트에 표시되어야 함',
|
||||
'- 미보유·포지션 모드·스캔 범위에 따라 시그널이 생략될 수 있음',
|
||||
`- deterministicHints.expectedSellSignalAtBar: ${ctx.deterministicHints.expectedSellSignalAtBar}`,
|
||||
].join('\n'),
|
||||
actualResult: [
|
||||
'선택 봉 SELL 시그널: 없음',
|
||||
'overallExitMet: true',
|
||||
`힌트: ${ctx.deterministicHints.signalMatchesOverallRule}`,
|
||||
].join('\n'),
|
||||
});
|
||||
}
|
||||
|
||||
function pushUnexpectedBuySignal(ctx: StrategyEvaluationAiVerifyContext, points: AiVerifyFixPoint[]) {
|
||||
const { overallEntryMet, buyConditions } = ctx.evaluation;
|
||||
if (overallEntryMet !== false || !ctx.signals.selectedBarHighlight.buy) return;
|
||||
|
||||
points.push({
|
||||
id: 'buy-signal-no-rule',
|
||||
title: '매수 Rule 미충족 ↔ 차트 BUY 시그널 있음',
|
||||
situation: [
|
||||
chartSituationSummary(ctx),
|
||||
'',
|
||||
'【매수 조건 평가】',
|
||||
'overallEntryMet: false',
|
||||
formatConditionLines(buyConditions),
|
||||
'',
|
||||
'【선택 봉 시그널】',
|
||||
ctx.signals.selectedBarSignals.filter(s => s.type === 'BUY').map(s =>
|
||||
`BUY @ barIndex=${s.barIndex}, price=${s.price}, time=${s.time}`,
|
||||
).join('\n') || 'BUY 시그널 있음',
|
||||
].join('\n'),
|
||||
settingsAndExpected: [
|
||||
'전략 매수 DSL:',
|
||||
formatDslSummary(ctx.strategy.buyCondition),
|
||||
'',
|
||||
'예상 결과: overallEntryMet=false 이면 선택 봉에 BUY 시그널이 없어야 함',
|
||||
].join('\n'),
|
||||
actualResult: [
|
||||
'overallEntryMet: false',
|
||||
'선택 봉 BUY 시그널: 있음 → Rule 평가와 백테스트 시그널 생성 로직 불일치 의심',
|
||||
`힌트: ${ctx.deterministicHints.signalMatchesOverallRule}`,
|
||||
].join('\n'),
|
||||
});
|
||||
}
|
||||
|
||||
function pushUnexpectedSellSignal(ctx: StrategyEvaluationAiVerifyContext, points: AiVerifyFixPoint[]) {
|
||||
const { overallExitMet, sellConditions } = ctx.evaluation;
|
||||
if (overallExitMet !== false || !ctx.signals.selectedBarHighlight.sell) return;
|
||||
|
||||
points.push({
|
||||
id: 'sell-signal-no-rule',
|
||||
title: '매도 Rule 미충족 ↔ 차트 SELL 시그널 있음',
|
||||
situation: [
|
||||
chartSituationSummary(ctx),
|
||||
'',
|
||||
'【매도 조건 평가】',
|
||||
'overallExitMet: false',
|
||||
formatConditionLines(sellConditions),
|
||||
].join('\n'),
|
||||
settingsAndExpected: [
|
||||
'전략 매도 DSL:',
|
||||
formatDslSummary(ctx.strategy.sellCondition),
|
||||
'',
|
||||
'예상 결과: overallExitMet=false 이면 선택 봉에 SELL 시그널이 없어야 함',
|
||||
].join('\n'),
|
||||
actualResult: [
|
||||
'overallExitMet: false',
|
||||
'선택 봉 SELL 시그널: 있음 → Rule 평가와 시그널 생성 불일치 의심',
|
||||
].join('\n'),
|
||||
});
|
||||
}
|
||||
|
||||
function pushFailedConditions(ctx: StrategyEvaluationAiVerifyContext, points: AiVerifyFixPoint[]) {
|
||||
const failed = [
|
||||
...ctx.evaluation.buyConditions.filter(c => c.satisfied === false),
|
||||
...ctx.evaluation.sellConditions.filter(c => c.satisfied === false),
|
||||
];
|
||||
if (failed.length === 0) return;
|
||||
|
||||
const entryMet = ctx.evaluation.overallEntryMet;
|
||||
const exitMet = ctx.evaluation.overallExitMet;
|
||||
if (entryMet !== true && exitMet !== true) return;
|
||||
|
||||
points.push({
|
||||
id: 'partial-condition-fail',
|
||||
title: '개별 조건 미충족 vs 전체 Rule 충족',
|
||||
situation: [
|
||||
chartSituationSummary(ctx),
|
||||
'',
|
||||
`overallEntryMet: ${entryMet} · overallExitMet: ${exitMet}`,
|
||||
'',
|
||||
'【미충족 개별 조건】',
|
||||
formatConditionLines(failed),
|
||||
].join('\n'),
|
||||
settingsAndExpected: [
|
||||
'전략 DSL (매수/매도):',
|
||||
formatDslSummary({ buy: ctx.strategy.buyCondition, sell: ctx.strategy.sellCondition }),
|
||||
'',
|
||||
'예상 결과: AND/OR 그룹 논리에 따라 개별 조건과 overallEntryMet/overallExitMet가 일치해야 함',
|
||||
].join('\n'),
|
||||
actualResult: [
|
||||
'일부 leaf 조건은 satisfied=false 이지만 전체 Rule은 충족으로 표시됨',
|
||||
'→ DSL 그룹(AND/OR/NOT) 해석, Ta4j Rule 빌더, 조건 ID 매핑을 확인 필요',
|
||||
].join('\n'),
|
||||
});
|
||||
}
|
||||
|
||||
function pushUnevaluatedConditions(ctx: StrategyEvaluationAiVerifyContext, points: AiVerifyFixPoint[]) {
|
||||
const unknown = [
|
||||
...ctx.evaluation.buyConditions.filter(c => c.satisfied == null),
|
||||
...ctx.evaluation.sellConditions.filter(c => c.satisfied == null),
|
||||
];
|
||||
if (unknown.length === 0) return;
|
||||
|
||||
points.push({
|
||||
id: 'condition-unevaluated',
|
||||
title: '조건 평가 불가 (지표·데이터 누락)',
|
||||
situation: [
|
||||
chartSituationSummary(ctx),
|
||||
'',
|
||||
'【평가 불가 조건】',
|
||||
formatConditionLines(unknown),
|
||||
].join('\n'),
|
||||
settingsAndExpected: [
|
||||
'지표 파라미터:',
|
||||
formatIndicatorParamsSummary(ctx.indicatorParams),
|
||||
'',
|
||||
'예상 결과: 모든 leaf 조건에 currentValue·satisfied가 채워져야 Rule 판정 가능',
|
||||
].join('\n'),
|
||||
actualResult: [
|
||||
`${unknown.length}개 조건 satisfied=null — 지표 스냅샷·봉 데이터·타임프레임 정렬 문제 가능`,
|
||||
ctx.evaluation.error ? `평가 API 오류: ${ctx.evaluation.error}` : '',
|
||||
].filter(Boolean).join('\n'),
|
||||
});
|
||||
}
|
||||
|
||||
export function buildCursorFixPrompt(
|
||||
ctx: StrategyEvaluationAiVerifyContext,
|
||||
points: AiVerifyFixPoint[],
|
||||
verdictHint: string | null,
|
||||
): string {
|
||||
const header = [
|
||||
'# GoldenChart 전략평가 — 로직 불일치 수정 요청',
|
||||
'',
|
||||
'아래 전략평가(Ta4j Rule vs 차트 시그널) 불일치를 분석하고, 코드 수정 포인트와 해결 방안을 제안해 주세요.',
|
||||
'',
|
||||
verdictHint ? `## AI 종합 판정\n${verdictHint}\n` : '',
|
||||
'## 공통 컨텍스트',
|
||||
chartSituationSummary(ctx),
|
||||
'',
|
||||
].join('\n');
|
||||
|
||||
const body = points.map((p, i) => [
|
||||
`## 수정 포인트 ${i + 1}: ${p.title}`,
|
||||
'',
|
||||
'### 현재 평가 상황',
|
||||
p.situation,
|
||||
'',
|
||||
'### 설정 및 예상 결과',
|
||||
p.settingsAndExpected,
|
||||
'',
|
||||
'### 현재 결과',
|
||||
p.actualResult,
|
||||
'',
|
||||
].join('\n')).join('\n');
|
||||
|
||||
const footer = [
|
||||
'## 요청',
|
||||
'- 불일치 원인을 frontend/backend/Ta4j Rule 빌더 관점에서 추적',
|
||||
'- 수정해야 할 파일·함수와 구체적 변경안 제시',
|
||||
'- 재현 방법(종목, 타임프레임, 선택 봉 index) 포함',
|
||||
].join('\n');
|
||||
|
||||
return `${header}${body}${footer}`;
|
||||
}
|
||||
|
||||
/** 로직 문제 시 Cursor AI용 수정 포인트 번들 생성 */
|
||||
export function buildAiVerifyFixPoints(
|
||||
ctx: StrategyEvaluationAiVerifyContext,
|
||||
analysis?: string | null,
|
||||
): AiVerifyFixPointsBundle | null {
|
||||
const points: AiVerifyFixPoint[] = [];
|
||||
pushBuySignalMismatch(ctx, points);
|
||||
pushUnexpectedBuySignal(ctx, points);
|
||||
pushSellSignalMismatch(ctx, points);
|
||||
pushUnexpectedSellSignal(ctx, points);
|
||||
pushFailedConditions(ctx, points);
|
||||
pushUnevaluatedConditions(ctx, points);
|
||||
|
||||
const verdictHint = extractVerdictHint(analysis);
|
||||
const issueFromAnalysis = analysis ? detectLogicIssueFromAnalysis(analysis) : false;
|
||||
const issueFromHints = ctx.deterministicHints.signalMatchesOverallRule
|
||||
!== '전체 Rule과 선택 봉 시그널 표시가 대체로 일치';
|
||||
|
||||
if (points.length === 0 && issueFromAnalysis) {
|
||||
points.push({
|
||||
id: 'llm-verdict-only',
|
||||
title: 'AI가 로직 문제로 판단',
|
||||
situation: [
|
||||
chartSituationSummary(ctx),
|
||||
'',
|
||||
'【조건 요약】',
|
||||
`매수 overallEntryMet: ${ctx.evaluation.overallEntryMet}`,
|
||||
formatConditionLines(ctx.evaluation.buyConditions),
|
||||
'',
|
||||
`매도 overallExitMet: ${ctx.evaluation.overallExitMet}`,
|
||||
formatConditionLines(ctx.evaluation.sellConditions),
|
||||
'',
|
||||
`시그널 힌트: ${ctx.deterministicHints.signalMatchesOverallRule}`,
|
||||
].join('\n'),
|
||||
settingsAndExpected: [
|
||||
'전략 DSL:',
|
||||
formatDslSummary({ buy: ctx.strategy.buyCondition, sell: ctx.strategy.sellCondition }),
|
||||
'',
|
||||
'예상: Ta4j Rule 결과와 차트 시그널·개별 조건 satisfied가 논리적으로 일치',
|
||||
].join('\n'),
|
||||
actualResult: verdictHint
|
||||
? `AI 종합 판정: ${verdictHint}`
|
||||
: (analysis?.slice(0, 400) ?? '분석 텍스트 없음'),
|
||||
});
|
||||
}
|
||||
|
||||
const hasDeterministicIssue = points.some(p => p.id !== 'llm-verdict-only');
|
||||
const shouldShow = issueFromAnalysis || issueFromHints || hasDeterministicIssue;
|
||||
if (!shouldShow || points.length === 0) return null;
|
||||
|
||||
return {
|
||||
hasIssue: true,
|
||||
verdictHint,
|
||||
points,
|
||||
cursorPrompt: buildCursorFixPrompt(ctx, points, verdictHint),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user