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.

1.6 KB
Raw Blame
import type { PtyOwnerBackend } from './pty-owner-backend'
import type { PtyStartupIngressIntent } from './pty-startup-ingress-intent'
import type { TerminalOscColorQueryReplyColors } from './terminal-osc-color-reply'

export type PtyIngressEmission = {
  data: string
  rawStartSeq: number
  rawEndSeq: number
  transformed: boolean
}

export type PtyStartupIngressOptions = {
  intent?: PtyStartupIngressIntent
  ownerBackend?: PtyOwnerBackend
  /** Host-wide viewer colours, read per query so a theme change reaches a long-lived pane.
   *  Defaults to this process's pushed colours. */
  resolveHostColors?: () => TerminalOscColorQueryReplyColors | null
  write: (data: string) => void
  onEmission: (emission: PtyIngressEmission) => void
}

export type PtyIngressSourceSpan = {
  data: string
  rawStartSeq: number
  rawEndSeq: number
}

export type PtyStartupIngressOperation =
  | { kind: 'data'; chunk: PtyIngressSourceSpan }
  | { kind: 'close-query' }
  | { kind: 'snapshot' }
  | { kind: 'teardown' }
  | { kind: 'expire' }
  | { kind: 'release-echo' }
  | { kind: 'release-query' }

export function slicePtyIngressSourceSpan(
  span: PtyIngressSourceSpan,
  start: number,
  end = span.data.length
): PtyIngressSourceSpan {
  return {
    data: span.data.slice(start, end),
    rawStartSeq: span.rawStartSeq + start,
    rawEndSeq: span.rawStartSeq + end
  }
}

export function combinePtyIngressSourceSpans(
  first: PtyIngressSourceSpan | null,
  second: PtyIngressSourceSpan
): PtyIngressSourceSpan {
  if (!first) {
    return second
  }
  return {
    data: first.data + second.data,
    rawStartSeq: first.rawStartSeq,
    rawEndSeq: second.rawEndSeq
  }
}