feat: 경제 타로 전용 카드 10장(불장·존버·분할매수·익절·손절·관망·물타기·배당·적금·텅장) — 경제 주제는 이 카드에서 오늘 날씨에 맞는 3장을 고르고 리딩을 돈 이야기로

This commit is contained in:
minaChoi committed 2026-10-27 10:16:30 +09:00
1 parent b73bc650c4
commit baa4324ea0
15 files changed
+50 -12

No files matched your search

+29 -9
View File
@@ -20,6 +20,10 @@ const questionOf = (topic) => {
}
// 날씨 타로 카드 = 날씨각 각 카드 (서비스와 같은 각 목록)
const DECK = JSON.parse(readFileSync(resolve(import.meta.dirname, '../../backend/seed/index_definition.json'), 'utf8')).map((g) => ({ id: g.code, name: g.name, icon: g.icon, meaning: g.description }))
// 경제 전용 카드: topics.json 에서 deck 이 money 인 대주제는 이 카드에서만 고른다
const MONEY_DECK = JSON.parse(readFileSync(resolve(import.meta.dirname, '../money-deck.json'), 'utf8')).cards.map((g) => ({ id: g.code, name: g.name, icon: g.icon, meaning: g.description, when: g.when }))
const ALL_CARDS = [...DECK, ...MONEY_DECK]
const deckOf = (topic) => (categoryOf(topic ?? '')?.deck === 'money' ? MONEY_DECK : DECK)
// 최근에 쓴 각은 빼서 매일 같은 카드가 나오지 않게 한다 (card.mjs 가 기획할 때마다 적는다)
const HISTORY_FILE = resolve(import.meta.dirname, '../out/tarot-history.json')
const HISTORY_DAYS = 7
@@ -43,7 +47,7 @@ const RULES = [
'카드에 들어가야 하니 칸마다 지금 문구와 비슷한 길이(최대 1.3배)로 쓴다(날씨 타로 리딩은 아래 길이 규칙을 따른다). 줄바꿈은 " ⏎ "로 표시하고, 개수를 지금 문구와 맞춘다.',
'강조할 말은 *별표*로 감싼다. 지금 문구에 별표가 있으면 같은 자리에 둔다.',
`아이콘 칸(i1·i2·i3)은 다음 중 하나의 파일 이름만 쓴다: ${ICONS.join(', ')}`,
'쓰지 않는 것: 투자 권유(종목, 매수·매도, 수익·손실 단정), 건강·의료 단정, 사고·재난·정치, 특정 집단 비하, 욕설.',
'쓰지 않는 것: 투자 권유(종목 추천, 수익·손실 단정), 건강·의료 단정, 사고·재난·정치, 특정 집단 비하, 욕설.',
'"재미로"라는 말이 지금 문구에 있으면 남긴다.',
'주제가 있으면 제목·카드 이름·문장을 모두 그 주제의 말로 바꾼다. 오늘 날씨 사실은 주제에 빗대는 근거로만 쓴다.',
'날씨각의 각 요약 문장("오전 10시 14°, 바람 조금")을 그대로 옮기지 않는다. 날씨 사실은 쉬운 말로 다시 쓴다.',
@@ -69,15 +73,18 @@ const TAROT_TONE = [
'키워드(k)는 4~8자 명사구("같이 걷는 시간", "먼저 보내는 한 줄"). 행운 포인트(l)는 시간·날씨·행동 한 줄 22자 이내("저녁 8시, 17도로 걷기 딱 좋아요").',
]
/** 오늘 고를 수 있는 각: 최근 7일에 쓴 각은 뺀다 (관리자가 고정한 카드는 남긴다) */
function availableDeck(fixed = {}) {
/** 오늘 고를 수 있는 각: 최근 7일에 쓴 각은 뺀다 (관리자가 고정한 카드는 남긴다). 경제 카드는 10장뿐이라 날씨로만 고른다 */
function availableDeck(fixed = {}, topic = '') {
const deck = deckOf(topic)
if (deck === MONEY_DECK) return deck
const recent = new Set(recentCodes())
const keep = new Set(fixed.cards ?? [])
return DECK.filter((c) => !recent.has(c.id) || keep.has(c.id))
return deck.filter((c) => !recent.has(c.id) || keep.has(c.id))
}
function tarotSection(topic, fixed = {}) {
const deck = availableDeck(fixed)
const deck = availableDeck(fixed, topic)
if (deck === MONEY_DECK) return moneySection(topic)
const excluded = DECK.filter((c) => !deck.includes(c)).map((c) => c.name)
return [
'',
@@ -91,6 +98,19 @@ function tarotSection(topic, fixed = {}) {
]
}
function moneySection(topic) {
return [
'',
'## 경제 카드 (이 목록에서만 고른다. card1·card2·card3에 서로 다른 code)',
`표지 질문(question)은 이것을 쓴다(피드백이 바꾸라고 하면 바꾼다): ${questionOf(topic)}`,
'각 카드의 "어울리는 날씨"가 오늘 날씨 데이터와 맞는 카드만 고른다. 맞는 카드가 많으면 더 잘 맞는 것, 아침·낮·저녁으로 이어지는 것을 고른다. 날씨와 안 맞는 카드는 고르지 않는다.',
'리딩은 카드 이름(불장·존버·분할매수·익절·손절·관망·물타기·배당·적금·텅장)의 뜻을 주식·돈 관리 이야기로 직접 풀고, 오늘 날씨를 그 근거로 든다. 산책·꽃구경 같은 날씨 활동 이야기로 새지 않는다. 종목 추천·수익 단정은 하지 않는다.',
...TAROT_TONE,
'',
...MONEY_DECK.map((c) => `- ${c.id}: ${c.name} — ${c.meaning} / 어울리는 날씨: ${c.when}`),
]
}
function buildPrompt(ctx, { topic, feedback, fixed = {} }) {
// 줄바꿈은 ⏎ 로 보여 주고 받을 때 되돌린다 (JSON 안의 \\n 을 글자로 따라 쓰는 일을 막는다)
const fields = ctx.fields.map((f) => `- ${f.key} (${f.label}): ${String(ctx.current[f.key] ?? '').replaceAll('\n', ' ⏎ ')}`).join('\n')
@@ -116,16 +136,16 @@ function buildPrompt(ctx, { topic, feedback, fixed = {} }) {
].join('\n')
}
function schema(ctx, fixed = {}) {
function schema(ctx, fixed = {}, topic = '') {
const properties = { topic: { type: 'string' } }
for (const f of ctx.fields) if (!(isTarot(ctx) && DECK_KEY.test(f.key))) properties[f.key] = { type: 'string' }
if (isTarot(ctx)) for (const k of ['card1', 'card2', 'card3']) properties[k] = { type: 'string', enum: availableDeck(fixed).map((c) => c.id) }
if (isTarot(ctx)) for (const k of ['card1', 'card2', 'card3']) properties[k] = { type: 'string', enum: availableDeck(fixed, topic).map((c) => c.id) }
return { type: 'object', properties, required: Object.keys(properties), additionalProperties: false }
}
/** @returns {Promise<{ topic: string, copy: Record<string, string> }>} */
export function runPlan(ctx, { topic = '', feedback = '', fixed = {} } = {}) {
const args = ['-p', buildPrompt(ctx, { topic, feedback, fixed }), '--output-format', 'json', '--json-schema', JSON.stringify(schema(ctx, fixed)), '--tools', '', '--no-session-persistence', '--model', 'sonnet']
const args = ['-p', buildPrompt(ctx, { topic, feedback, fixed }), '--output-format', 'json', '--json-schema', JSON.stringify(schema(ctx, fixed, topic)), '--tools', '', '--no-session-persistence', '--model', 'sonnet']
return new Promise((done, fail) => {
execFile('claude', args, { cwd: tmpdir(), timeout: 180_000, maxBuffer: 10 * 1024 * 1024 }, (err, stdout) => {
if (err) return fail(new Error(`Claude CLI 실행 실패: ${err.message}. 터미널에서 claude 로그인 상태를 확인하세요.`))
@@ -142,7 +162,7 @@ export function runPlan(ctx, { topic = '', feedback = '', fixed = {} } = {}) {
if (fixed.question) result.question = fixed.question
fixed.cards?.forEach((code, i) => (result[`card${i + 1}`] = code))
;['card1', 'card2', 'card3'].forEach((k, i) => {
const card = DECK.find((c) => c.id === result[k])
const card = ALL_CARDS.find((c) => c.id === result[k])
if (card) Object.assign(result, { [`c${i + 1}`]: card.id, [`n${i + 1}`]: card.name, [`i${i + 1}`]: card.icon })
})
}