Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

4.8 KB
Raw Blame
import { engineLabel } from './agentNames.js'
import type { MessageHold } from '../engines/facets/screen.js'
export type { MessageHold } from '../engines/facets/screen.js'

const HOLDS: ReadonlySet<string> = new Set<MessageHold>(['permission_open', 'question_open', 'menu_open', 'rewind_picker_open',
  'transcript_open', 'search_open', 'trust_open', 'update_prompt_open', 'model_prompt_open', 'sign_in_open', 'popup_open',
  'prompt_hidden', 'screen_unreadable'])

/**
 * The holds that can be passing: an engine still starting draws nothing yet, a redraw can be caught
 * between frames, a capture can fail once. A message waits a little for these to clear before it is
 * refused (sessionInput.ts), as it does for the pane's control lease.
 */
const PASSING: ReadonlySet<string> = new Set<MessageHold>(['prompt_hidden', 'screen_unreadable'])
export function passingHold(reason: string): boolean {
  return PASSING.has(reason)
}

export function isMessageHold(reason: string): reason is MessageHold {
  return HOLDS.has(reason)
}

function engineName(engine: string): string {
  return engine === 'claude' ? 'Claude Code' : engineLabel(engine)
}

/**
 * What the person is told when their message was typed but its Enter not pressed: the engine opened
 * something between the two, which the Enter would have answered. The text waits in the composer.
 */
export function messageWithheldText(engine: string, hold: string): string {
  const name = engineName(engine)
  const [what, then] = hold === 'permission_open' ? ['asked for permission', 'Answer the request in the app or in its terminal']
    : hold === 'question_open' ? ['asked you a question', 'Answer the question in the app or in its terminal']
      : ['opened another screen', 'Finish what\'s on its screen in its terminal']
  return `${name} ${what} just as your message was typed, so it was not sent; it waits in ${name}'s prompt. ${then}, then press Enter in its terminal to send the message, or clear it there.`
}

/** What the person is told: why their message was not typed, and what lets it through. */
export function messageHoldText(engine: string, hold: MessageHold): string {
  const name = engineName(engine)
  switch (hold) {
    case 'permission_open':
      return `${name} is asking for ${engine === 'codex' ? 'approval' : 'permission'}. Answer it first, in the app or in its terminal, then send the message again.`
    case 'question_open':
      return `${name} is asking you a question. Answer it first, in the app or in its terminal, then send the message again.`
    case 'menu_open':
      return `${name} has a menu open, where Enter would pick from it. Close it with Esc in its terminal, then send the message again.`
    case 'rewind_picker_open':
      return engine === 'codex'
        ? 'Codex is browsing its transcript, where Enter would rewind the conversation. Close it with Esc in its terminal, then send the message again.'
        : `${name} has its Rewind menu open, where Enter would pick a point to rewind to. Close it with Esc in its terminal, then send the message again.`
    case 'transcript_open':
      return engine === 'codex'
        ? 'Codex is showing its transcript (ctrl+t), where a message is not typed. Close it with q in its terminal, then send the message again.'
        : `${name} is showing its transcript (ctrl+o), where a message is not typed. Close it with Esc in its terminal, then send the message again.`
    case 'search_open':
      return engine === 'codex'
        ? 'Codex has a search open, where a message would become what it searches for. Close it with Esc in its terminal, then send the message again.'
        : `${name} is searching its prompt history (ctrl+r), where Enter would send an earlier prompt. Close it with ctrl+c in its terminal, then send the message again.`
    case 'trust_open':
      // The folder's trust, or Claude Code's question about an MCP server the folder brings (engines/claude/screen.ts).
      return `${name} is asking whether to trust this folder or an MCP server it brings. Answer it in its terminal, then send the message again.`
    case 'update_prompt_open':
      return `${name} is asking whether to update. Answer it in its terminal, then send the message again.`
    case 'model_prompt_open':
      return `${name} is asking whether to switch to a new model. Answer it in its terminal, then send the message again.`
    case 'sign_in_open':
      return `${name} is asking how to sign in. Sign in in its terminal, then send the message again.`
    case 'popup_open':
      return `${name} message not sent. Close suggestions with Esc in its terminal, then retry.`
    case 'prompt_hidden':
      return `${name} isn't showing its prompt; finish what's on its screen in its terminal, then send the message again.`
    case 'screen_unreadable':
      return `${name}'s screen could not be read, so the message was not typed. Send it again in a moment.`
  }
}