以 prompt.compose hook 注入依強度與稱呼組成的規則段落;規則為純函式並附測試。 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
16 lines
575 B
TypeScript
16 lines
575 B
TypeScript
import type { Register } from 'claude-code'
|
|
|
|
import { resolveConfig } from './config'
|
|
import { buildRules, SECTION_ID } from './rules'
|
|
|
|
// 依強度與稱呼把規則段落加到系統提示最後;人格卡與檢索見 W5~W7。
|
|
export const register: Register = (on, options) => {
|
|
const config = resolveConfig(options)
|
|
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' }] }
|
|
})
|
|
}
|