tips.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import { createMemo, createSignal, For } from "solid-js"
  2. import { DEFAULT_THEMES, useTheme } from "@tui/context/theme"
  3. const themeCount = Object.keys(DEFAULT_THEMES).length
  4. const themeTip = `Use {highlight}/theme{/highlight} or {highlight}Ctrl+X T{/highlight} to switch between ${themeCount} built-in themes`
  5. type TipPart = { text: string; highlight: boolean }
  6. function parse(tip: string): TipPart[] {
  7. const parts: TipPart[] = []
  8. const regex = /\{highlight\}(.*?)\{\/highlight\}/g
  9. const found = Array.from(tip.matchAll(regex))
  10. const state = found.reduce(
  11. (acc, match) => {
  12. const start = match.index ?? 0
  13. if (start > acc.index) {
  14. acc.parts.push({ text: tip.slice(acc.index, start), highlight: false })
  15. }
  16. acc.parts.push({ text: match[1], highlight: true })
  17. acc.index = start + match[0].length
  18. return acc
  19. },
  20. { parts, index: 0 },
  21. )
  22. if (state.index < tip.length) {
  23. parts.push({ text: tip.slice(state.index), highlight: false })
  24. }
  25. return parts
  26. }
  27. export function Tips() {
  28. const theme = useTheme().theme
  29. const parts = parse(TIPS[Math.floor(Math.random() * TIPS.length)])
  30. return (
  31. <box flexDirection="row" maxWidth="100%">
  32. <text flexShrink={0} style={{ fg: theme.warning }}>
  33. ● Tip{" "}
  34. </text>
  35. <text flexShrink={1}>
  36. <For each={parts}>
  37. {(part) => <span style={{ fg: part.highlight ? theme.text : theme.textMuted }}>{part.text}</span>}
  38. </For>
  39. </text>
  40. </box>
  41. )
  42. }
  43. const TIPS = [
  44. "Type {highlight}@{/highlight} followed by a filename to fuzzy search and attach files",
  45. "Start a message with {highlight}!{/highlight} to run shell commands directly (e.g., {highlight}!ls -la{/highlight})",
  46. "Press {highlight}Tab{/highlight} to cycle between Build and Plan agents",
  47. "Use {highlight}/undo{/highlight} to revert the last message and file changes",
  48. "Use {highlight}/redo{/highlight} to restore previously undone messages and file changes",
  49. "Run {highlight}/share{/highlight} to create a public link to your conversation at opencode.ai",
  50. "Drag and drop images into the terminal to add them as context",
  51. "Press {highlight}Ctrl+V{/highlight} to paste images from your clipboard into the prompt",
  52. "Press {highlight}Ctrl+X E{/highlight} or {highlight}/editor{/highlight} to compose messages in your external editor",
  53. "Run {highlight}/init{/highlight} to auto-generate project rules based on your codebase",
  54. "Run {highlight}/models{/highlight} or {highlight}Ctrl+X M{/highlight} to see and switch between available AI models",
  55. themeTip,
  56. "Press {highlight}Ctrl+X N{/highlight} or {highlight}/new{/highlight} to start a fresh conversation session",
  57. "Use {highlight}/sessions{/highlight} or {highlight}Ctrl+X L{/highlight} to list and continue previous conversations",
  58. "Run {highlight}/compact{/highlight} to summarize long sessions near context limits",
  59. "Press {highlight}Ctrl+X X{/highlight} or {highlight}/export{/highlight} to save the conversation as Markdown",
  60. "Press {highlight}Ctrl+X Y{/highlight} to copy the assistant's last message to clipboard",
  61. "Press {highlight}Ctrl+P{/highlight} to see all available actions and commands",
  62. "Run {highlight}/connect{/highlight} to add API keys for 75+ supported LLM providers",
  63. "The leader key is {highlight}Ctrl+X{/highlight}; combine with other keys for quick actions",
  64. "Press {highlight}F2{/highlight} to quickly switch between recently used models",
  65. "Press {highlight}Ctrl+X B{/highlight} to show/hide the sidebar panel",
  66. "Use {highlight}PageUp{/highlight}/{highlight}PageDown{/highlight} to navigate through conversation history",
  67. "Press {highlight}Ctrl+G{/highlight} or {highlight}Home{/highlight} to jump to the beginning of the conversation",
  68. "Press {highlight}Ctrl+Alt+G{/highlight} or {highlight}End{/highlight} to jump to the most recent message",
  69. "Press {highlight}Shift+Enter{/highlight} or {highlight}Ctrl+J{/highlight} to add newlines in your prompt",
  70. "Press {highlight}Ctrl+C{/highlight} when typing to clear the input field",
  71. "Press {highlight}Escape{/highlight} to stop the AI mid-response",
  72. "Switch to {highlight}Plan{/highlight} agent to get suggestions without making actual changes",
  73. "Use {highlight}@agent-name{/highlight} in prompts to invoke specialized subagents",
  74. "Press {highlight}Ctrl+X Right/Left{/highlight} to cycle through parent and child sessions",
  75. "Create {highlight}opencode.json{/highlight} in project root for project-specific settings",
  76. "Place settings in {highlight}~/.config/opencode/opencode.json{/highlight} for global config",
  77. "Add {highlight}$schema{/highlight} to your config for autocomplete in your editor",
  78. "Configure {highlight}model{/highlight} in config to set your default model",
  79. "Override any keybind in config via the {highlight}keybinds{/highlight} section",
  80. "Set any keybind to {highlight}none{/highlight} to disable it completely",
  81. "Configure local or remote MCP servers in the {highlight}mcp{/highlight} config section",
  82. "OpenCode auto-handles OAuth for remote MCP servers requiring auth",
  83. "Add {highlight}.md{/highlight} files to {highlight}.opencode/command/{/highlight} to define reusable custom prompts",
  84. "Use {highlight}$ARGUMENTS{/highlight}, {highlight}$1{/highlight}, {highlight}$2{/highlight} in custom commands for dynamic input",
  85. "Use backticks in commands to inject shell output (e.g., {highlight}`git status`{/highlight})",
  86. "Add {highlight}.md{/highlight} files to {highlight}.opencode/agent/{/highlight} for specialized AI personas",
  87. "Configure per-agent permissions for {highlight}edit{/highlight}, {highlight}bash{/highlight}, and {highlight}webfetch{/highlight} tools",
  88. 'Use patterns like {highlight}"git *": "allow"{/highlight} for granular bash permissions',
  89. 'Set {highlight}"rm -rf *": "deny"{/highlight} to block destructive commands',
  90. 'Configure {highlight}"git push": "ask"{/highlight} to require approval before pushing',
  91. "OpenCode auto-formats files using prettier, gofmt, ruff, and more",
  92. 'Set {highlight}"formatter": false{/highlight} in config to disable all auto-formatting',
  93. "Define custom formatter commands with file extensions in config",
  94. "OpenCode uses LSP servers for intelligent code analysis",
  95. "Create {highlight}.ts{/highlight} files in {highlight}.opencode/tool/{/highlight} to define new LLM tools",
  96. "Tool definitions can invoke scripts written in Python, Go, etc",
  97. "Add {highlight}.ts{/highlight} files to {highlight}.opencode/plugin/{/highlight} for event hooks",
  98. "Use plugins to send OS notifications when sessions complete",
  99. "Create a plugin to prevent OpenCode from reading sensitive files",
  100. "Use {highlight}opencode run{/highlight} for non-interactive scripting",
  101. "Use {highlight}opencode run --continue{/highlight} to resume the last session",
  102. "Use {highlight}opencode run -f file.ts{/highlight} to attach files via CLI",
  103. "Use {highlight}--format json{/highlight} for machine-readable output in scripts",
  104. "Run {highlight}opencode serve{/highlight} for headless API access to OpenCode",
  105. "Use {highlight}opencode run --attach{/highlight} to connect to a running server",
  106. "Run {highlight}opencode upgrade{/highlight} to update to the latest version",
  107. "Run {highlight}opencode auth list{/highlight} to see all configured providers",
  108. "Run {highlight}opencode agent create{/highlight} for guided agent creation",
  109. "Use {highlight}/opencode{/highlight} in GitHub issues/PRs to trigger AI actions",
  110. "Run {highlight}opencode github install{/highlight} to set up the GitHub workflow",
  111. "Comment {highlight}/opencode fix this{/highlight} on issues to auto-create PRs",
  112. "Comment {highlight}/oc{/highlight} on PR code lines for targeted code reviews",
  113. 'Use {highlight}"theme": "system"{/highlight} to match your terminal\'s colors',
  114. "Create JSON theme files in {highlight}.opencode/themes/{/highlight} directory",
  115. "Themes support dark/light variants for both modes",
  116. "Reference ANSI colors 0-255 in custom themes",
  117. "Use {highlight}{env:VAR_NAME}{/highlight} syntax to reference environment variables in config",
  118. "Use {highlight}{file:path}{/highlight} to include file contents in config values",
  119. "Use {highlight}instructions{/highlight} in config to load additional rules files",
  120. "Set agent {highlight}temperature{/highlight} from 0.0 (focused) to 1.0 (creative)",
  121. "Configure {highlight}maxSteps{/highlight} to limit agentic iterations per request",
  122. 'Set {highlight}"tools": {"bash": false}{/highlight} to disable specific tools',
  123. 'Set {highlight}"mcp_*": false{/highlight} to disable all tools from an MCP server',
  124. "Override global tool settings per agent configuration",
  125. 'Set {highlight}"share": "auto"{/highlight} to automatically share all sessions',
  126. 'Set {highlight}"share": "disabled"{/highlight} to prevent any session sharing',
  127. "Run {highlight}/unshare{/highlight} to remove a session from public access",
  128. "Permission {highlight}doom_loop{/highlight} prevents infinite tool call loops",
  129. "Permission {highlight}external_directory{/highlight} protects files outside project",
  130. "Run {highlight}opencode debug config{/highlight} to troubleshoot configuration",
  131. "Use {highlight}--print-logs{/highlight} flag to see detailed logs in stderr",
  132. "Press {highlight}Ctrl+X G{/highlight} or {highlight}/timeline{/highlight} to jump to specific messages",
  133. "Press {highlight}Ctrl+X H{/highlight} to toggle code block visibility in messages",
  134. "Press {highlight}Ctrl+X S{/highlight} or {highlight}/status{/highlight} to see system status info",
  135. "Enable {highlight}tui.scroll_acceleration{/highlight} for smooth macOS-style scrolling",
  136. "Toggle username display in chat via command palette ({highlight}Ctrl+P{/highlight})",
  137. "Run {highlight}docker run -it --rm ghcr.io/anomalyco/opencode{/highlight} for containerized use",
  138. "Use {highlight}/connect{/highlight} with OpenCode Zen for curated, tested models",
  139. "Commit your project's {highlight}AGENTS.md{/highlight} file to Git for team sharing",
  140. "Use {highlight}/review{/highlight} to review uncommitted changes, branches, or PRs",
  141. "Run {highlight}/help{/highlight} or {highlight}Ctrl+X H{/highlight} to show the help dialog",
  142. "Use {highlight}/details{/highlight} to toggle tool execution details visibility",
  143. "Use {highlight}/rename{/highlight} to rename the current session",
  144. "Press {highlight}Ctrl+Z{/highlight} to suspend the terminal and return to your shell",
  145. ]