여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제 - 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다 - eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다 파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이). site·frontend·admin tsc, site vitest 105 passed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
56 lines
2.2 KiB
JavaScript
56 lines
2.2 KiB
JavaScript
/** 지역 이야기 프롬프트를 백엔드가 읽을 JSON 으로 뽑는다. */
|
|
import {mkdirSync, writeFileSync} from 'node:fs';
|
|
import {dirname, resolve} from 'node:path';
|
|
import {fileURLToPath} from 'node:url';
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const OUT = resolve(here, '../../backend/services/prompts/section_prompts.json');
|
|
|
|
// TS 를 그대로 읽을 수 없으므로 원문에서 값을 떼어 낸다 — 이 파일은 순수 상수 선언이라 파서를 세울 이유가 없다.
|
|
const src = await import('node:fs').then((fs) =>
|
|
fs.readFileSync(resolve(here, '../src/lib/section-prompts.ts'), 'utf8'),
|
|
);
|
|
|
|
function block(name) {
|
|
const m = src.match(new RegExp(`export const ${name} = \`([\\s\\S]*?)\`;`));
|
|
if (!m) throw new Error(`${name} 를 찾지 못했다 — section-prompts.ts 의 모양이 바뀌었다`);
|
|
return m[1];
|
|
}
|
|
|
|
const rules = block('SECTION_PROMPT_RULES');
|
|
|
|
// 목록을 여기 손으로 적지 않는다.
|
|
const kinds = (() => {
|
|
const m = src.match(/export const STORY_KINDS: StoryKind\[\] = \[([\s\S]*?)\];/);
|
|
if (!m) throw new Error('STORY_KINDS 를 찾지 못했다 — section-prompts.ts 의 모양이 바뀌었다');
|
|
return [...m[1].matchAll(/'([^']+)'/g)].map((hit) => hit[1]);
|
|
})();
|
|
const specs = {};
|
|
for (const kind of kinds) {
|
|
const body = src.match(new RegExp(`\\n ${kind}: \\{([\\s\\S]*?)\\n \\},`));
|
|
if (!body) throw new Error(`${kind} 항목을 찾지 못했다`);
|
|
const take = (field) => {
|
|
const m = body[1].match(new RegExp(`${field}: \`([\\s\\S]*?)\`,`));
|
|
if (!m) throw new Error(`${kind}.${field} 를 찾지 못했다`);
|
|
return m[1];
|
|
};
|
|
const label = body[1].match(/label: '([^']*)'/);
|
|
const maxItems = body[1].match(/maxItems: (\d+)/);
|
|
if (!label || !maxItems) throw new Error(`${kind} 의 label/maxItems 를 찾지 못했다`);
|
|
specs[kind] = {
|
|
kind,
|
|
label: label[1],
|
|
maxItems: Number(maxItems[1]),
|
|
task: take('task'),
|
|
rules: take('rules'),
|
|
};
|
|
}
|
|
|
|
mkdirSync(dirname(OUT), {recursive: true});
|
|
writeFileSync(
|
|
OUT,
|
|
`${JSON.stringify({_generated: 'npm run export:prompts — 손으로 고치지 않는다', rules, specs}, null, 2)}\n`,
|
|
'utf8',
|
|
);
|
|
console.log(`프롬프트 ${kinds.length}종 → ${OUT}`);
|