Files
jsc-marketplace/plugins/companion/hooks/register.tsx
T
rootandClaude Sonnet 5.5 1bc2a335ee fix: 助理列與狀態列之間補上一行間距
助理列到輸入框的間距由引擎固定留一行,狀態列到助理列原本沒有間距。
為助理列加上 marginTop,使兩段間距相同。

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 14:16:46 +08:00

52 lines
1.7 KiB
TypeScript

import type { Register } from 'claude-code'
import { fitCompanion } from './companion/band'
import { createCompanion } from './companion/core'
import { engineFs } from './companion/engine-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: engineFs({ read: p => $.fs.read(p), write: (p, t) => $.fs.write(p, t), list: p => $.fs.list(p) }), 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}
<Box marginTop={1}>
<Text wrap="truncate">
{line.map(s => (
<Text color={s.color} dimColor={s.dim} bold={s.bold}>
{s.text}
</Text>
))}
</Text>
</Box>
</Box>
)
})
}