chat.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // ---------------------------------------------------------------------------
  2. // Page-object helpers for the main Cline chat view.
  3. // ---------------------------------------------------------------------------
  4. import type { Terminal } from "@microsoft/tui-test/lib/terminal/term"
  5. import { expectVisible, typeAndSubmit } from "../terminal.js"
  6. /** Wait for the main chat view to be ready */
  7. export async function waitForChatReady(terminal: Terminal): Promise<void> {
  8. await expectVisible(terminal, "What can I do for you?")
  9. }
  10. /** Submit a prompt in the chat input */
  11. export async function submitPrompt(terminal: Terminal, prompt: string, delay = 500): Promise<void> {
  12. await waitForChatReady(terminal)
  13. await typeAndSubmit(terminal, prompt, delay)
  14. }
  15. /** Toggle between Plan and Act mode by pressing Tab */
  16. export async function togglePlanAct(terminal: Terminal): Promise<void> {
  17. terminal.write("\t")
  18. // Wait for the mode indicator to update rather than sleeping a fixed amount
  19. await expectVisible(terminal, /● Plan|● Act/)
  20. }
  21. /** Toggle auto-approve-all with Shift+Tab */
  22. export async function toggleAutoApproveAll(terminal: Terminal): Promise<void> {
  23. terminal.write("\x1b[Z") // shift tab
  24. }
  25. /** Wait for "Task completed" to appear */
  26. export async function waitForTaskCompleted(terminal: Terminal, timeout = 60_000): Promise<void> {
  27. await expectVisible(terminal, "Task completed", { timeout })
  28. }
  29. /** Wait for the "Start New Task (1)" and "Exit (2)" buttons */
  30. export async function waitForTaskButtons(terminal: Terminal, timeout = 60_000): Promise<void> {
  31. await expectVisible(terminal, ["Start New Task", "Exit"], { timeout })
  32. }
  33. /** Press "1" to start a new task after task completion */
  34. export async function startNewTask(terminal: Terminal): Promise<void> {
  35. terminal.write("1")
  36. }
  37. /** Press "2" to exit after task completion */
  38. export async function exitAfterTask(terminal: Terminal): Promise<void> {
  39. terminal.write("2")
  40. }
  41. /** Wait for a permission prompt and approve it (press "1" / Save) */
  42. export async function approvePermission(terminal: Terminal): Promise<void> {
  43. terminal.write("1")
  44. }
  45. /** Wait for a permission prompt and reject it (press "2" / Reject) */
  46. export async function rejectPermission(terminal: Terminal): Promise<void> {
  47. terminal.write("2")
  48. }
  49. /** Navigate to /settings */
  50. export async function openSettings(terminal: Terminal): Promise<void> {
  51. await waitForChatReady(terminal)
  52. await typeAndSubmit(terminal, "/settings")
  53. await expectVisible(terminal, "Settings (Esc to close)")
  54. }
  55. /** Navigate to /history */
  56. export async function openHistory(terminal: Terminal): Promise<void> {
  57. await waitForChatReady(terminal)
  58. await typeAndSubmit(terminal, "/history")
  59. }
  60. /** Navigate to /models */
  61. export async function openModels(terminal: Terminal): Promise<void> {
  62. await waitForChatReady(terminal)
  63. await typeAndSubmit(terminal, "/models")
  64. }
  65. /** Navigate to /skills */
  66. export async function openSkills(terminal: Terminal): Promise<void> {
  67. await waitForChatReady(terminal)
  68. await typeAndSubmit(terminal, "/skills")
  69. }