// Example mod: a live pane with buttons, a band above the prompt, and a toast. // // cmd.ui.pane draws a titled panel the person opens and closes; cmd.ui.widget draws a band of // lines around the prompt. Both take a `render` that returns plain data: strings, or elements // ({type: 'text' | 'row' | 'box' | 'button' | 'progress' | 'divider'}). Never React components, // so the same mod draws in any host. // // Values a drawing reads live in cmd.state: host-held, so they survive a hot reload, and // setting one repaints every widget and pane. While the pane is open, Alt+ presses its // buttons and Alt+0 closes it. import type {ModApi} from '@commandcode/harness'; export default function (cmd: ModApi): void { const calls = (): number => cmd.state.get('calls') ?? 0; cmd.on('tool_completed', () => { cmd.state.set('calls', calls() + 1); }); // The band above the prompt: one line, always visible. cmd.ui.widget({ placement: 'above-editor', render: () => [ {type: 'text', text: `tool calls: ${calls()}`, dim: true}, ], }); cmd.ui.pane({ id: 'calls', title: 'Tool calls', render: () => [ {type: 'progress', label: 'budget', value: calls() / 50, width: 20}, { type: 'row', children: [ {type: 'text', text: `${calls()} of 50`, bold: true}, { type: 'button', label: 'Reset', hotkey: 'r', onPress: () => { cmd.state.set('calls', 0); cmd.ui.toast('Counter reset', {level: 'success'}); }, }, ], }, ], }); // /calls opens the pane. cmd.addCommand({ name: 'calls', description: 'Show the tool-call counter pane', handler: () => { cmd.ui.openPane('calls'); }, }); }