Arduino 컴파일: 누락 라이브러리 자동 설치 후 재컴파일

컴파일 에러에서 'fatal error: Foo.h: No such file or directory' 파싱 →
arduino-cli lib search로 최적 라이브러리 찾기 → 자동 설치 → 재컴파일.
성공 시 autoInstalled[] 포함하여 반환, 클라이언트는 "📦 자동 설치" 시스템 메시지 표시.
에러 지속 시 sendCompileErrorToAI()로 AI 채팅에 전달.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
kim
2026-06-11 23:03:54 +09:00
co-authored by Claude Sonnet 4.6
parent 0c46d52f42
commit 8b649e96d5
2 changed files with 206 additions and 43 deletions
+3 -2
View File
@@ -888,7 +888,6 @@ function openArduinoEmulator() {
const file = codeFiles.find(f => f.id === activeCodeFileId);
const btn = document.getElementById('code-emu-btn');
// .ino 파일이 열려 있으면 컴파일 후 에뮬레이터 실행
if (file && file.name.endsWith('.ino')) {
if (btn) { btn.textContent = '⏳ 컴파일 중…'; btn.disabled = true; }
fetch('/api/arduino/compile', {
@@ -897,6 +896,7 @@ function openArduinoEmulator() {
body: JSON.stringify({ code: file.content, board: 'uno' }),
}).then(r => r.json()).then(data => {
if (btn) { btn.textContent = '🔌 에뮬레이터'; btn.disabled = false; }
if (data.autoInstalled?.length) codeAiAppend('system', `📦 라이브러리 자동 설치: ${data.autoInstalled.join(', ')}`);
if (data.error) { sendCompileErrorToAI(data.error, file.name, file.content); return; }
sessionStorage.setItem('arduino_sketch', file.content);
sessionStorage.setItem('arduino_hex', data.hex);
@@ -909,7 +909,6 @@ function openArduinoEmulator() {
codeAiAppend('system', '⚠️ 서버 오류: ' + e.message);
});
} else {
// .ino 아니면 그냥 에뮬레이터 창만 열기
window.open('/arduino-emulator.html', 'arduino-emulator');
}
}
@@ -1322,6 +1321,7 @@ function codeRunWith(mode) {
headers: { 'Content-Type': 'application/json', ...authHeaders({}) },
body: JSON.stringify({ code: file.content, board: 'esp32' }),
}).then(r => r.json()).then(data => {
if (data.autoInstalled?.length) codeAiAppend('system', `📦 라이브러리 자동 설치: ${data.autoInstalled.join(', ')}`);
if (data.error) {
sendCompileErrorToAI(data.error, file.name, file.content);
return;
@@ -1343,6 +1343,7 @@ function codeRunWith(mode) {
headers: { 'Content-Type': 'application/json', ...authHeaders({}) },
body: JSON.stringify({ code: file.content, board }),
}).then(r => r.json()).then(data => {
if (data.autoInstalled?.length) codeAiAppend('system', `📦 라이브러리 자동 설치: ${data.autoInstalled.join(', ')}`);
if (data.error) {
const extra = data.install ? `\n\n설치 필요: ${data.install}` : '';
sendCompileErrorToAI(data.error + extra, file.name, file.content);