Files added by PR #2008 that were not in main were dropped during the merge. Restore all src/, docs/, and scripts/ files from the pre-merge PR head. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1.4 KiB
1.4 KiB
Key Rules & Gotchas
Must-Follow Rules
- Use
StringEnumfor string enums —Type.Union/Type.Literalbreaks Google's API. - Truncate tool output — Large output causes context overflow, compaction failures, degraded performance.
- Use theme from callback — Don't import theme directly. Use the
themeparameter fromctx.ui.custom()or render functions. - Type the DynamicBorder color param — Write
(s: string) => theme.fg("accent", s). - Call
tui.requestRender()after state changes inhandleInput. - Return
{ render, invalidate, handleInput }from custom components. - Lines must not exceed
widthinrender()— usetruncateToWidth(). - Session control methods only in commands —
waitForIdle(),newSession(),fork(),navigateTree(),reload()will deadlock in event handlers. - Strip leading
@from path arguments in custom tools — some models add it. - Store state in tool result
detailsfor proper branching support.
Common Patterns
- Rebuild on
invalidate()when your component pre-bakes theme colors - Check
signal?.abortedin long-running tool executions - Use
pi.exec()instead ofchild_processfor shell commands - Overlay components are disposed when closed — create fresh instances each time
- Treat
ctx.reload()as terminal — code after it runs from the pre-reload version