// 설명 문서: docs/specs/openwork-cli-provider.md (v2.0.0) // 공개 상류 지침의 전체 일치 섹션만 BADA 로컬 안내로 바꾼다. 버전 불일치는 그대로 검사한다. const scanner = require('../utils/secret-scanner'); const sections = require('./cli-system-steering-sections.json'); function matchesBoundary(text, offset, length) { return (offset === 0 || text[offset - 1] === '\n') && (offset + length === text.length || text[offset + length] === '\n'); } // 공개 고정 섹션 존재 여부만 관측하며 본문과 사용자 키는 반환하지 않는다. function inspectSteering(content) { return sections.map(section => { let offset = content.indexOf(section.original), boundaryMatched = false; const literalIncluded = offset >= 0; while (offset >= 0) { if (matchesBoundary(content, offset, section.original.length)) { boundaryMatched = true; break; } offset = content.indexOf(section.original, offset + section.original.length); } return { literalIncluded, boundaryMatched }; }); } function normalizeSystemSteering(request) { return { ...request, messages: request.messages.map(message => { if (!['system', 'developer'].includes(message.role) || typeof message.content !== 'string') return message; // 치환 전 원문 서명 검사를 유지한다. 비밀을 포함한 지침을 정규화로 지우지 않는다. if (!scanner.scan(message.content, { entropy: false }).clean) throw Object.assign(new Error('System instruction policy could not be verified'), { code: 'BADA_CLI_PROJECTION', status: 422, retryable: false }); let content = message.content; for (const section of sections) { content = content.replaceAll(section.original, (match, offset, original) => { return matchesBoundary(original, offset, match.length) ? section.replacement : match; }); } return { ...message, content }; }) }; } module.exports = { normalizeSystemSteering, inspectSteering };