- statusbar:輸入框上方狀態列,指令 /statusbar - companion:小說角色陪伴,指令 /companion,自行渲染角色行 - companion 資料目錄改為 ~/.companion - 整併 M4 檔案至 companion;M2 實作移至 hooks/companion/persona - README 移除本機資料夾安裝,補上更新與移除指令 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import type { Register } from 'claude-code'
|
|
|
|
import { fitCompanion } from './companion/band'
|
|
import { createCompanion } from './companion/core'
|
|
import { nodeFs } from './companion/node-fs'
|
|
|
|
let companion: ReturnType<typeof createCompanion> | undefined
|
|
|
|
export const register: Register = on => {
|
|
on('session.start', async ($, e, next) => {
|
|
await $.command.register({
|
|
name: 'companion',
|
|
description: '角色陪伴控制:狀態、切換角色、關閉、使用者設定',
|
|
argumentHint: 'status | switch <角色> | off | setup',
|
|
})
|
|
const home = await $.env.get('HOME')
|
|
companion = createCompanion({ fs: nodeFs, clock: { now: Date.now }, root: `${home ?? ''}/.companion` })
|
|
const first = await companion.ensureActivated()
|
|
if (first.first) $.ui.toast(`已啟用 ${first.name}。用 /companion off 可關閉`)
|
|
|
|
return next(e)
|
|
})
|
|
|
|
on('command.run', { command: 'companion' }, async ($, e) => ({
|
|
text: companion ? await companion.command(e.args) : '尚未就緒。',
|
|
}))
|
|
|
|
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
|
|
const rest = await next(e)
|
|
const view = await companion?.view()
|
|
if (e.props.hasSurvey || !view) return rest
|
|
|
|
const line = fitCompanion(view, e.props.bodyColumns)
|
|
const { Box, Text } = $.ui.resolve(e)
|
|
|
|
return (
|
|
<Box flexDirection="column">
|
|
{rest}
|
|
<Text wrap="truncate">
|
|
{line.map(s => (
|
|
<Text color={s.color} dimColor={s.dim} bold={s.bold}>
|
|
{s.text}
|
|
</Text>
|
|
))}
|
|
</Text>
|
|
</Box>
|
|
)
|
|
})
|
|
}
|