Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

2.9 KB
Raw Blame
import { mkdirSync, writeFileSync } from 'node:fs'
import path from 'node:path'
import { HOLD_ALTERNATE_SCREEN_OPEN } from './alternate-screen-fixture-script'

export type HiddenPressureOutputMode = 'tui' | 'plain' | 'title' | 'latin' | 'rich-model'

export function pressureOutputScript(runId: string, mode: HiddenPressureOutputMode): string {
  const headerPrefix = mode === 'tui' || mode === 'rich-model' ? '\\x1b[0m' : ''
  const donePrefix = mode === 'tui' || mode === 'rich-model' ? '\\x1b[0m' : ''
  const chunkExpression =
    mode === 'plain'
      ? "'plain pressure pane=' + paneIndex + ' frame=' + frame + ' ' + chunkBody + '\\n'"
      : mode === 'latin'
        ? "'latin pressure café déjà vu São Tomé Żubrówka pane=' + paneIndex + ' frame=' + frame + ' ' + chunkBody + '\\n'"
        : mode === 'title'
          ? "'\\x1b]0;title pressure pane=' + paneIndex + ' frame=' + frame + ' ' + chunkBody + '\\x07'"
          : mode === 'rich-model'
            ? "'\\x1b[?2026h\\x1b[?1049h\\x1b[2J\\x1b[H\\x1b[?25l\\x1b[2;36m╭────────────────────────────────────────╮\\x1b[0m\\r\\n\\x1b[2;36m│ rich model pane=' + paneIndex + ' frame=' + frame + ' 😀 ███░ │\\x1b[0m\\r\\n\\x1b[2;36m│ ' + chunkBody + ' │\\x1b[0m\\r\\n\\x1b[2;36m╰────────────────────────────────────────╯\\x1b[0m\\x1b[6;4H\\x1b[?25h\\x1b[?2026l\\n'"
            : "'\\x1b[?2026h\\x1b[1;1Hpressure pane=' + paneIndex + ' frame=' + frame + ' ' + chunkBody + '\\x1b[?2026l\\n'"
  // Hold rich-model’s alternate-screen owner open or dead-TUI recovery discards its frames and completion marker.
  const holdOpen = mode === 'rich-model' ? `\n${HOLD_ALTERNATE_SCREEN_OPEN}` : ''
  return `
const paneIndex = process.argv[2] ?? '0'
const targetChars = Number(process.argv[3] ?? '0')
const delayMs = Number(process.argv[4] ?? '0')
const header = '${headerPrefix}OPENCODE_PRESSURE_START_${runId}_' + paneIndex + '\\n'
const chunkBody = '#'.repeat(8192)
let written = 0
process.stdout.write(header)
function writeMore() {
  let canContinue = true
  while (canContinue && written < targetChars) {
    const frame = String(written).padStart(8, '0')
    const chunk = ${chunkExpression}
    written += chunk.length
    canContinue = process.stdout.write(chunk)
  }
  if (written < targetChars) {
    process.stdout.once('drain', writeMore)
    return
  }
  process.stdout.write('${donePrefix}OPENCODE_PRESSURE_DONE_${runId}_' + paneIndex + '\\n')
}
setTimeout(writeMore, Number.isFinite(delayMs) && delayMs > 0 ? delayMs : 0)${holdOpen}
`
}

export function writePressureOutputScript(
  scriptPath: string,
  runId: string,
  mode: HiddenPressureOutputMode
): void {
  mkdirSync(path.dirname(scriptPath), { recursive: true })
  writeFileSync(scriptPath, pressureOutputScript(runId, mode))
}