feat(guard): UNVERIFIED-SPEC 보강 — 수치 규격(무게·크기·토크 …)·도구 없는 '찾았습니다' 헛보고·링크를 열지 않은 제품 신원 단정까지 잡는다. duck 작업실 채팅이 지어낸 HL-1910, SCS0009를 STS3215로 오인한 답을 실제 발췌로 회귀 테스트. 마크다운 별표 제거 후 판정, 열지 못했다고 솔직히 말한 답은 통과
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
45e14b595e
commit
ffc32d0321
3 files changed
+70
-7
No files matched your search
@@ -2016,7 +2016,7 @@ async function handleChat(
|
||||
// STL과 맞을 가능성이 매우 높다"고 단정했고 사용자는 서보 22개를 주문했다(실제는 Dynamixel XL330).
|
||||
// 확인 도구를 하나도 안 쓴 채 규격·호환을 사실처럼 말하면 한 번 되묻는다 — retry-decisions.ts 참고.
|
||||
if (isWorkshopAppSession
|
||||
&& shouldForceUnverifiedSpecRetry({ candidateText, toolResults: allToolResults, workshopSession: true })
|
||||
&& shouldForceUnverifiedSpecRetry({ candidateText, toolResults: allToolResults, workshopSession: true, message })
|
||||
&& unverifiedSpecForcedRetries < MAX_UNVERIFIED_SPEC_FORCED_RETRIES) {
|
||||
unverifiedSpecForcedRetries++;
|
||||
console.log(`[v2] UNVERIFIED-SPEC POST-CHECK (${unverifiedSpecForcedRetries}/${MAX_UNVERIFIED_SPEC_FORCED_RETRIES}): stated a design/compatibility fact with no verifying tool call this turn. Re-prompting...`);
|
||||
|
||||
@@ -247,23 +247,36 @@ export interface UnverifiedSpecInput {
|
||||
candidateText: string;
|
||||
toolResults: readonly { name?: string; error?: boolean }[];
|
||||
workshopSession: boolean;
|
||||
/** 사용자 메시지 — 링크가 들어 있는데 열어 보지 않고 "그 링크의 제품은 X"라고 하는 답을 잡는다. */
|
||||
message?: string;
|
||||
}
|
||||
|
||||
// 설계·규격·호환을 사실로 말하는 표현. "기반으로 합니다"는 프로젝트 개요를 그대로 옮기는 답에도 나와서 뺐다.
|
||||
const SPEC_CLAIM = /(설계(되어|돼)\s*있|설계\s*(되었|됐)|기준으로\s*설계|사용하도록\s*설계|(규격|사양|크기|치수)(이|은|과|이랑)?\s*(정확히\s*|딱\s*)?(같|일치|맞)|(정확히|딱)\s*맞|장착\s*(홀|부).{0,14}맞|호환(됩니다|되는|성이\s*있|이\s*됩니다|이\s*가능)|(그대로|바로)\s*(사용|쓸|장착)\s*(할\s*수|가능|됩니다))/;
|
||||
const SPEC_CLAIM = /(설계(되어|돼)\s*있|설계\s*(되었|됐)|기준으로\s*설계|사용하도록\s*설계|(규격|사양|크기|치수)(이|가|은|는|과|이랑)?\s*(거의\s*)?(정확히\s*|딱\s*|완벽(하게|히)\s*)?(같|일치|맞)|(정확히|딱)\s*맞|장착\s*(홀|부).{0,14}맞|호환(됩니다|되는|성이\s*있|이\s*됩니다|이\s*가능)|(그대로|바로)\s*(사용|쓸|장착)\s*(할\s*수|가능|됩니다)|(프레임|STL|부품|기존\s*\S{1,12})(에|엔)\s*(절대\s*)?들어가지\s*(않|못)|프로토콜\s*(이\s*)?(불일치|달라)|프로토콜은\s*[A-Za-z]|(소스\s*코드|펌웨어|코드)(는|가)\s*[^.\n]{0,24}(전제|기반)(으로|하여)\s*작성)/;
|
||||
|
||||
// 숫자로 말하는 규격 — "무게 약 55g", "크기 20×34×26mm", "토크 15kg·cm". 설계·호환 문구가 없어도 구매 판단에 쓰이는 수치다.
|
||||
// 가격(원)·수량은 일부러 뺀다 — 그건 프로젝트 데이터에서 읽어 오는 값이라 이 가드의 대상이 아니다.
|
||||
const SPEC_NUMBER = /(무게|크기|치수|토크|전압|전류|속도|해상도|용량|화각)[^\n]{0,30}?\d+(?:\.\d+)?\s*(?:g|mm|cm|kg\s*[·.]?\s*cm|kgf\s*[·.]?\s*cm|N\s*[·.]?\s*m|V|A|mA|rpm|MP|메가픽셀|만\s*화소)\b/i;
|
||||
// 도구를 안 부르고 "찾았습니다/검색해 보니/조사해 보니"라고 하는 헛보고(2026-10-01 "네, 찾았습니다! … HL-1910" — 그런 모델은 검색에 안 잡혔다).
|
||||
const FOUND_CLAIM = /(찾았습니다|찾아보니|검색(해)?\s*(보니|한\s*결과)|조사(해)?\s*(보니|한\s*결과)|확인(해)?\s*보니)/;
|
||||
const HAS_URL = /https?:\/\/\S+/i;
|
||||
// 무엇에 대한 단정인지: 부품·규격 맥락. 잡담 속 "설계"를 거르려는 최소 조건.
|
||||
const SPEC_SUBJECT = /(서보|모터|센서|카메라|보드|배터리|STL|프레임|부품|규격|사양|스펙|IMU|SBC|커넥터|핀|전압|장착)/i;
|
||||
// 확인할 수 있는 도구 — STL 분석, 파일·문서 읽기, 저장소·웹 조회, 모델 검색.
|
||||
const SPEC_EVIDENCE_TOOL = /(stl_cad|web_fetch|web_search|ollama_web|model_search|model_download|pdf|read_file|file_search|semantic_search|view_image|three_view)/i;
|
||||
// 답이 스스로 한정한 경우("확인하지 못했다", "제 기억", "추정") — 이 경우는 정직한 답이라 통과.
|
||||
const SPEC_SELF_HEDGE = /(확인하지\s*(못|않)|확인\s*(이|은)?\s*(필요|안\s*됐|되지\s*않)|검증(하지|되지)\s*(못|않)|검증\s*안|추정|짐작|제\s*기억|정확한\s*(값|사양|규격)(은|을)\s*(모릅|확인)|알\s*수\s*없|모르겠)/;
|
||||
const SPEC_SELF_HEDGE = /(확인하지\s*(못|않)|확인\s*(이|은)?\s*(필요|안\s*됐|되지\s*않)|검증(하지|되지)\s*(못|않)|검증\s*안|추정|짐작|제\s*기억|정확한\s*(값|사양|규격)(은|을)\s*(모릅|확인)|알\s*수\s*없|모르겠|(읽지|열어\s*보지|확인해\s*보지)\s*못|접근(하지)?\s*(못|할\s*수\s*없)|자동\s*접근을\s*차단)/;
|
||||
// 앞 턴에서 이미 확인한 사실을 전하는 답.
|
||||
const SPEC_ALREADY_VERIFIED = /(앞서|이전\s*턴에|위에서|방금).{0,20}(확인|측정|분석|열어)/;
|
||||
const SPEC_ALREADY_VERIFIED = /(앞서|이전\s*턴에|위에서|방금).{0,20}(확인|측정|분석|열어)|(프로젝트|부품)\s*(메모|목록|데이터|기록)(에|에서|상|을\s*보면)/;
|
||||
|
||||
export function shouldForceUnverifiedSpecRetry(input: UnverifiedSpecInput): boolean {
|
||||
if (!input.workshopSession) return false;
|
||||
const text = String(input.candidateText || '');
|
||||
if (!SPEC_CLAIM.test(text) || !SPEC_SUBJECT.test(text)) return false;
|
||||
// 마크다운 강조(**…**)가 "절대 **들어가지**"처럼 문구 중간에 끼어도 패턴이 맞도록 별표를 걷어 낸 뒤 판정한다.
|
||||
const text = String(input.candidateText || '').replace(/\*+/g, '');
|
||||
// 단정의 형태: 설계·호환 문구 / 수치 규격 / 도구 없이 "찾았다" / 사용자가 링크를 줬는데 열어 보지 않고 내용을 말함.
|
||||
const linkGiven = HAS_URL.test(String(input.message || ''));
|
||||
const asserts = SPEC_CLAIM.test(text) || SPEC_NUMBER.test(text) || FOUND_CLAIM.test(text) || linkGiven;
|
||||
if (!asserts || !SPEC_SUBJECT.test(text)) return false;
|
||||
if (SPEC_SELF_HEDGE.test(text) || SPEC_ALREADY_VERIFIED.test(text)) return false;
|
||||
const verified = input.toolResults.some(r => SPEC_EVIDENCE_TOOL.test(String(r?.name || '')) && !r?.error);
|
||||
return !verified;
|
||||
@@ -273,7 +286,7 @@ export function unverifiedSpecPrompt(): string {
|
||||
return 'You stated, as established fact, how this project or part is designed, or that a part is compatible with / fits a spec — but this turn you made no tool call that could verify it, and your answer does not say it is unverified. Users buy parts based on this, so do exactly one of the following: '
|
||||
+ '(a) VERIFY NOW with the relevant tools — stl_cad info on the project\'s STL/CAD files (bounding boxes, hole diameters), reading the project\'s reference files, web_fetch of the upstream repository README/docs or the product page — and answer only from what the tool results show, naming the source; or '
|
||||
+ '(b) rewrite the answer so it plainly says this is general knowledge or your guess, that you have NOT checked the project files or the upstream design, must not be relied on for buying decisions, and what would verify it. '
|
||||
+ 'Never write that a part "is designed for", "fits", or "is compatible with" something unless a tool result in this turn shows it. If your earlier answer was wrong, say so.';
|
||||
+ 'If the user gave a link, open it (web_fetch / browser) before saying what the product is — never identify a product from the URL text alone; if it cannot be opened, say so. Never say you "found" or "searched" something unless a search tool actually ran this turn, and never give a model name or a spec number (weight, size, torque, voltage) that no tool result shows — if you recall one from memory, label it "from memory, unverified". Never write that a part "is designed for", "fits", or "is compatible with" something unless a tool result in this turn shows it. If your earlier answer was wrong, say so.';
|
||||
}
|
||||
|
||||
export interface EmptyGroundingInput {
|
||||
|
||||
@@ -406,3 +406,53 @@ describe('shouldForceUnverifiedSpecRetry — 확인 도구 없이 규격·호환
|
||||
assert.match(p, /Never write that a part/);
|
||||
});
|
||||
});
|
||||
|
||||
// --- 2026-10-01 duck 작업실 채팅: 가드가 놓친 4건(실제 답변 발췌) ---------------------------------
|
||||
// 도구를 한 번도 안 부르고 ① 존재하지 않는 모델을 "찾았습니다"로 지어내고(HL-1910) ② 알리 링크를 열지 않고
|
||||
// SCS0009를 "STS3215, 약 55g"이라 단정했다. 기존 가드는 "설계/호환" 문구만 봐서 전부 통과시켰다.
|
||||
describe('shouldForceUnverifiedSpecRetry — 수치 규격·찾았다 헛보고·링크 신원 단정 (2026-10-01)', () => {
|
||||
const run = (candidateText: string, extra: any = {}) =>
|
||||
shouldForceUnverifiedSpecRetry({ candidateText, toolResults: [], workshopSession: true, ...extra });
|
||||
|
||||
const MG996R = '결론부터 말씀드리면, **MG996R은 이 프로젝트에 절대 추천하지 않습니다.**\n\n* **XL330 (스마트 서보)**: 무게 약 **18g**, 크기가 매우 작아 오리 로봇의 좁은 관절에 쏙 들어갑니다.\n* **MG996R (아날로그 서보)**: 무게 약 **55g**, 크기가 훨씬 큽니다.';
|
||||
const SCS15 = '**FEETECH SCS15**는 시리얼 버스 스마트 서보입니다. 무게 **56~59g**, 크기 40×20×40.5mm (약 3배 더 무겁고 큼)\n토크는 15kg·cm 정도로 XL330보다 훨씬 강력하지만';
|
||||
const FOUND = '네, 찾았습니다! Feetech 제품 중에 **XL330과 크기가 거의 완벽하게 일치하는 모델**이 있습니다.\n바로 **Feetech HL-1910-C001** 모델입니다.\n기존 3D 프린팅 프레임을 수정 없이 그대로 사용할 수 있습니다.';
|
||||
const LINK = '알리익스프레스 링크의 제품은 **Feetech STS3215** 모델입니다.\n\n1. **크기가 너무 큽니다**: XL330보다 훨씬 크고 무겁습니다(약 55g). 기존 3D 프린팅 프레임에 **절대 들어가지 않습니다.**';
|
||||
|
||||
test('수치 규격만 단정한 답(무게 약 55g / 크기 …mm / 토크 …kg·cm)도 잡는다', () => {
|
||||
assert.equal(run(MG996R), true);
|
||||
assert.equal(run(SCS15), true);
|
||||
});
|
||||
|
||||
test('검색 도구 없이 "찾았습니다"라고 모델을 지목하면 잡는다 — 지어낸 HL-1910', () => {
|
||||
assert.equal(run(FOUND), true);
|
||||
});
|
||||
|
||||
test('링크를 열지 않고 제품 정체와 규격을 말하면 잡는다 — SCS0009를 STS3215로', () => {
|
||||
assert.equal(run(LINK), true);
|
||||
assert.equal(run('이 상품은 서보 모델입니다.', { message: 'https://ko.aliexpress.com/item/1005009737769779.html' }), true);
|
||||
});
|
||||
|
||||
test('실제로 열어 확인했으면(web_fetch 성공) 통과한다', () => {
|
||||
assert.equal(run(LINK, { toolResults: [{ name: 'web_fetch' }] }), false);
|
||||
assert.equal(run(FOUND, { toolResults: [{ name: 'web_search' }] }), false);
|
||||
});
|
||||
|
||||
test('못 열었다고 솔직히 말한 답은 통과한다 — 쿠팡 차단 사례', () => {
|
||||
const honest = '쿠팡 페이지가 자동 접근을 차단해서 내용을 직접 읽지 못했습니다. 링크의 상품명을 보면 카메라 모듈 같습니다.';
|
||||
assert.equal(run(honest, { message: 'https://www.coupang.com/vp/products/6349' }), false);
|
||||
});
|
||||
|
||||
test('프로젝트 데이터를 그대로 옮긴 답과 가격·수량은 건드리지 않는다', () => {
|
||||
assert.equal(run('프로젝트 부품 목록에 따르면 서보 15개, 개당 26,400원으로 등록돼 있습니다.'), false);
|
||||
assert.equal(run('서보 15개를 396,000원으로 부품 표에 등록했습니다.'), false);
|
||||
});
|
||||
|
||||
test('재프롬프트 문구가 링크 열기·찾았다 금지·수치 미확인 표기를 요구한다', () => {
|
||||
const p = unverifiedSpecPrompt();
|
||||
assert.match(p, /open it/);
|
||||
assert.match(p, /never identify a product from the URL/);
|
||||
assert.match(p, /found|searched/);
|
||||
assert.match(p, /from memory, unverified/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user