Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { $ } from 'bun'
await $`rm -rf dist`

await Bun.build({
entrypoints: ['src/index.ts'],
entrypoints: ['src/index.ts', 'src/tui.ts'],
outdir: './dist',
format: 'esm',
target: 'node',
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./tui": {
"types": "./dist/tui.d.ts",
"default": "./dist/tui.js"
}
},
"files": ["dist"],
"scripts": {
"build": "bun run build.ts && tsc --emitDeclarationOnly",
Expand Down
56 changes: 56 additions & 0 deletions src/tui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { TuiPlugin } from '@opencode-ai/plugin'
import { getMode } from './state'

const MODE_LABELS: Record<string, { icon: string; label: string }> = {
'lite': { icon: 'πŸ’¬', label: 'Caveman Lite' },
'full': { icon: 'πŸ”₯', label: 'Caveman Full' },
'ultra': { icon: '⚑', label: 'Caveman Ultra' },
'wenyan-lite': { icon: 'πŸ“œ', label: '文言 Lite' },
'wenyan-full': { icon: 'πŸ“œ', label: '文言 Full' },
'wenyan-ultra': { icon: 'πŸ“œ', label: '文言 Ultra' },
}

function formatMode(mode: string): string {
const info = MODE_LABELS[mode]
return info ? `${info.icon} ${info.label}` : `🦴 ${mode}`
}

export const tui: TuiPlugin = async (api, _options, _meta) => {
// Maintain a Set of session IDs that have caveman active
const activeSessions = new Set<string>()

// Listen for events to know when caveman mode changes
api.event.on('chat.message', (event) => {
const sessionID = event.sessionID
if (!sessionID) return

const mode = getMode(sessionID)
const isActive = mode && mode !== 'off'
if (isActive) {
activeSessions.add(sessionID)
// Trigger a re-render of our slots
api.renderer.render()
} else {
if (activeSessions.has(sessionID)) {
activeSessions.delete(sessionID)
api.renderer.render()
}
}
})

// Register slots for each session
const dispose = api.slots.register({
sidebar_footer: ({ session_id }) => {
const mode = getMode(session_id)
if (!mode || mode === 'off') return null

return (
<text color={api.theme.current.accent}>
{' '}{formatMode(mode)}{' '}
</text>
)
},
})

api.lifecycle.onDispose(dispose)
}