feat: W7 功能標籤分類、對白檢索與注入 (#8)

用 $.model.complete(Haiku)判斷回應的功能標籤,從角色索引取同標籤對白,
以只增不改的訊息附在使用者訊息之前;失敗一律退回不注入。

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jeffery (jiantw83)
2026-10-14 17:44:09 +00:00
co-authored by Claude Sonnet 5.5
parent 1c4e0c5d98
commit d9e50d196b
12 changed files with 385 additions and 4 deletions
+19 -1
View File
@@ -1,15 +1,33 @@
import type { Register } from 'claude-code'
import { resolveConfig } from './config'
import { INDEXES } from './data/index'
import { buildInjection } from './inject'
import { buildRules, SECTION_ID } from './rules'
// 依強度與稱呼把規則段落加到系統提示最後;人格卡與檢索見 W5~W7。
// 規則段落(W8)加到系統提示最後;每則使用者訊息再依功能標籤檢索角色的對白當語氣參考(W7)。
export const register: Register = (on, options) => {
const config = resolveConfig(options)
const showTiming = options.showTiming === true
let turn = 0
on('prompt.compose', async ($, e, next) => {
const result = await next(e)
const text = buildRules(config)
if (text === null) return result
return { sections: [...result.sections, { id: SECTION_ID, text, scope: 'session' }] }
})
on('prompt.submit', async ($, e, next) => {
if (e.command || e.isMeta) return next(e)
const r = await buildInjection(
{ config, indexes: INDEXES, complete: req => $.model.complete(req), now: Date.now, turn: turn++ },
e.text,
)
if (r === null) return next(e)
if (showTiming) $.ui.status(`anime-companion 分類 ${r.ms}ms → ${r.fn ?? '失敗'}`)
// 附加在使用者訊息之前,只增不改,不影響對話的快取。
if (r.text !== null) await $.session.append({ message: { type: 'user', content: [{ type: 'text', text: r.text }] } })
return next(e)
})
}