feat: 작업실 파일 작업 헛보고 가드(WORKSHOP FILE POST-CHECK) — 도구 없이 변환/저장/추가 완료 보고 시 재유도
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4641c3f820
commit
cb34baf755
3 files changed
+102
-1
No files matched your search
@@ -84,7 +84,7 @@ import { selectToolsForTurn, bootAllowedTools, codeAiBlockedTools } from './tool
|
||||
import { buildChatSystemPrompt, groundingResultReadingRule } from './system-prompt';
|
||||
import { replyLooksEmpty, appendDroppedSearchImages } from './reply-content';
|
||||
import { evaluateSearchBudget } from './search-budget';
|
||||
import { decideAutoRecover, shouldForceMessagingRetry as decideMessagingRetry, shouldForceWorkshopSaveRetry, shouldForceEmptyGroundingRetry as decideEmptyGroundingRetry, GROUNDING_TOOL_PATTERN } from './retry-decisions';
|
||||
import { decideAutoRecover, shouldForceMessagingRetry as decideMessagingRetry, shouldForceWorkshopSaveRetry, shouldForceWorkshopFileRetry, shouldForceEmptyGroundingRetry as decideEmptyGroundingRetry, GROUNDING_TOOL_PATTERN } from './retry-decisions';
|
||||
import { logToolSkip } from './tool-skip-log';
|
||||
import { checkNumericGrounding } from './numeric-grounding';
|
||||
import { decideSearchAbandonmentRetry } from './search-abandonment';
|
||||
@@ -439,6 +439,8 @@ async function handleChat(
|
||||
const MAX_MESSAGING_FORCED_RETRIES = 2;
|
||||
let workshopSaveForcedRetries = 0;
|
||||
const MAX_WORKSHOP_SAVE_FORCED_RETRIES = 1;
|
||||
let workshopFileForcedRetries = 0;
|
||||
const MAX_WORKSHOP_FILE_FORCED_RETRIES = 1;
|
||||
let emptyGroundingForcedRetries = 0;
|
||||
const MAX_EMPTY_GROUNDING_FORCED_RETRIES = 1;
|
||||
let numericGroundingForcedRetries = 0;
|
||||
@@ -1987,6 +1989,22 @@ async function handleChat(
|
||||
continue;
|
||||
}
|
||||
|
||||
// WORKSHOP FILE POST-CHECK (2026-09-29). 저장 가드의 파일 버전 — 도구 없이 "변환/저장/추가
|
||||
// 완료"를 보고하는 헛보고(L1_mm.stl 미생성, 존재하지 않는 main_assembly.scad 수정 보고).
|
||||
if (isWorkshopAppSession
|
||||
&& shouldForceWorkshopFileRetry({ message, candidateText, toolResults: allToolResults, workshopSession: true })
|
||||
&& workshopFileForcedRetries < MAX_WORKSHOP_FILE_FORCED_RETRIES) {
|
||||
workshopFileForcedRetries++;
|
||||
console.log(`[v2] WORKSHOP FILE POST-CHECK (${workshopFileForcedRetries}/${MAX_WORKSHOP_FILE_FORCED_RETRIES}): claimed file work done without a successful file-mutating tool call. Re-prompting...`);
|
||||
sendSSE('info', { message: 'Re-prompting model: verify the file work with a real tool call...' });
|
||||
messages.push({ role: 'assistant', content: candidateText });
|
||||
messages.push({
|
||||
role: 'user',
|
||||
content: 'You reported the file work as done, but this turn you never made a successful file-changing tool call (stl_cad transform / scad_to_stl / write_scad / model_download …). Do the real call now and report the result from the tool output (sizes, paths). If it was already done in an earlier turn, say exactly that ("이미 이전 턴에 처리돼 있습니다") and verify with stl_cad info instead of guessing. If you cannot do it, say so honestly.',
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
const groundingResultsThisTurn = allToolResults.filter((r) =>
|
||||
GROUNDING_TOOL_PATTERN.test(String(r?.name || '')),
|
||||
);
|
||||
|
||||
@@ -204,6 +204,34 @@ export function shouldForceWorkshopSaveRetry(input: WorkshopSaveRetryInput): boo
|
||||
&& !mutatingCalled;
|
||||
}
|
||||
|
||||
// --- Workshop 파일 작업 헛보고 가드 (2026-09-29) ---------------------------------------
|
||||
// 09-29 실측(로봇 프로젝트·테스트 프로젝트): 도구를 한 번도 안 부르고 "L1_mm.stl로 스케일업
|
||||
// 완료"(파일 없음), "main_assembly.scad에 PART 분기를 추가했습니다"(파일 자체가 없음)라고 보고.
|
||||
// 저장 가드(WORKSHOP SAVE)는 workshop_project만 보므로 파일 작업은 못 잡는다. 파일을 만들거나
|
||||
// 바꿀 수 있는 도구가 이번 턴에 성공한 적이 있는지만 본다(내용 검증은 도구 출력의 몫).
|
||||
export interface WorkshopFileRetryInput {
|
||||
message: string;
|
||||
candidateText: string;
|
||||
toolResults: readonly { name?: string; error?: boolean; args?: any }[];
|
||||
workshopSession: boolean;
|
||||
}
|
||||
|
||||
const FILE_MUTATING_TOOL_PATTERN = /^(write_scad|scad_to_stl|scad_animate|stl_cad|model_download|print3d_model|python_eval|shell|write|edit|skill_exec)$/;
|
||||
// 사용자가 파일 작업을 요청했거나(스케일/변환/다운로드/저장/만들기…) 이미 했는지 캐묻는 경우("스케일업 했니?").
|
||||
const FILE_ACTION_REQUEST = /(파일|stl|scad|스케치|스케일|배율|변환|단위|다운로드|저장|만들어|만들자|생성|합쳐|눕혀|옮겨|정리|채우자)/i;
|
||||
const FILE_ACTION_CLAIM = /(스케일업\s*(했|완료)|변환(했|이\s*완료|을\s*완료|된\s*파일)|저장했|저장되었|저장\s*완료|다운로드(를)?\s*(했|완료)|다운로드\s*됐|만들었|생성했|생성\s*완료|추가했습니다|추가했어|수정했|적용했|파일을?\s*(만들|생성|저장)|완료했습니다|완료했어|완료되었습니다|완료!)/;
|
||||
// "이미 이전 턴에 …"처럼 과거 사실을 그대로 전하는 답은 통과시킨다(저장 가드와 같은 탈출구).
|
||||
const FILE_ALREADY_DONE = /(이미\s*(이전|앞선|지난)|이전\s*턴에|앞서\s*(이미\s*)?(저장|만들|변환))/;
|
||||
|
||||
export function shouldForceWorkshopFileRetry(input: WorkshopFileRetryInput): boolean {
|
||||
if (!input.workshopSession) return false;
|
||||
const text = String(input.candidateText || '');
|
||||
if (!FILE_ACTION_REQUEST.test(String(input.message || ''))) return false;
|
||||
if (!FILE_ACTION_CLAIM.test(text) || FILE_ALREADY_DONE.test(text)) return false;
|
||||
const mutated = input.toolResults.some(r => FILE_MUTATING_TOOL_PATTERN.test(String(r?.name || '')) && !r?.error);
|
||||
return !mutated;
|
||||
}
|
||||
|
||||
export interface EmptyGroundingInput {
|
||||
message: string;
|
||||
/** Tool results this turn; only grounding tools are considered. */
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
decideAutoRecover,
|
||||
shouldForceMessagingRetry,
|
||||
shouldForceWorkshopSaveRetry,
|
||||
shouldForceWorkshopFileRetry,
|
||||
shouldForceEmptyGroundingRetry,
|
||||
} from '../src/gateway/chat/retry-decisions';
|
||||
|
||||
@@ -288,3 +289,57 @@ describe('EMPTY-GROUNDING — 빈 검색결과로 답한 경우', () => {
|
||||
}), true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shouldForceWorkshopFileRetry — 파일 작업 헛보고 (09-29 실측 사례)', () => {
|
||||
const ws = true;
|
||||
test('"스케일업 했니?" → 도구 없이 "완료했습니다" = 발동', () => {
|
||||
assert.equal(shouldForceWorkshopFileRetry({
|
||||
message: '스케일업 했니?', workshopSession: ws, toolResults: [],
|
||||
candidateText: '**스케일업 완료했습니다!** L1~L6.STL 파일을 1000배 스케일업하여 mm 단위로 변환했습니다.',
|
||||
}), true);
|
||||
});
|
||||
test('"PART == all 로도 파일 만들어줘" → 도구 없이 "추가했습니다" = 발동', () => {
|
||||
assert.equal(shouldForceWorkshopFileRetry({
|
||||
message: 'PART == "all" 로도 파일 만들어줘', workshopSession: ws, toolResults: [],
|
||||
candidateText: '메인 조립 파일(`main_assembly.scad`)에 `PART` 변수를 이용한 분기 구조를 추가했습니다.',
|
||||
}), true);
|
||||
});
|
||||
test('stl_cad transform 성공 호출이 있으면 통과', () => {
|
||||
assert.equal(shouldForceWorkshopFileRetry({
|
||||
message: '스케일업 해줘', workshopSession: ws,
|
||||
toolResults: [{ name: 'stl_cad', args: { action: 'transform' } }],
|
||||
candidateText: '변환했습니다. 결과 bbox: 122 × 238 × 86 mm',
|
||||
}), false);
|
||||
});
|
||||
test('파일 도구가 실패(error)면 성공으로 안 쳐서 발동', () => {
|
||||
assert.equal(shouldForceWorkshopFileRetry({
|
||||
message: '스케일업 해줘', workshopSession: ws,
|
||||
toolResults: [{ name: 'stl_cad', error: true }],
|
||||
candidateText: '변환했습니다.',
|
||||
}), true);
|
||||
});
|
||||
test('읽기 도구(model_search·web_search)만 쓰면 파일 작업이 아니라 발동', () => {
|
||||
assert.equal(shouldForceWorkshopFileRetry({
|
||||
message: 'STL 파일 다운로드해줘', workshopSession: ws,
|
||||
toolResults: [{ name: 'model_search' }, { name: 'web_search' }],
|
||||
candidateText: '다운로드 완료했습니다. 12개 파일을 저장했습니다.',
|
||||
}), true);
|
||||
});
|
||||
test('"이미 이전 턴에" 사실 전달은 통과', () => {
|
||||
assert.equal(shouldForceWorkshopFileRetry({
|
||||
message: '스케일업 했니?', workshopSession: ws, toolResults: [],
|
||||
candidateText: '네, 이미 이전 턴에 변환해서 저장했습니다.',
|
||||
}), false);
|
||||
});
|
||||
test('파일 요청이 아닌 잡담은 통과', () => {
|
||||
assert.equal(shouldForceWorkshopFileRetry({
|
||||
message: '오늘 날씨 어때', workshopSession: ws, toolResults: [],
|
||||
candidateText: '맑고 완료했습니다 같은 표현이 있어도 무관.',
|
||||
}), false);
|
||||
});
|
||||
test('작업실 세션이 아니면 발동 안 함', () => {
|
||||
assert.equal(shouldForceWorkshopFileRetry({
|
||||
message: '파일 저장해줘', workshopSession: false, toolResults: [], candidateText: '저장했습니다.',
|
||||
}), false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user