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.

959 B
Raw Blame
import { expect } from 'vitest'
import { tokenizeStartupCommand } from './tui-agent-startup-shell'

// Decode target-shell script carriers for assertions: POSIX octal via printf %b or PowerShell UTF-16 base64.

export function unwrapPosixShellScript(command: string | undefined): string {
  const tokenized = tokenizeStartupCommand(command ?? '', 'posix')
  expect(tokenized.ok).toBe(true)
  const wrapper = tokenized.ok ? (tokenized.tokens[2] ?? '') : ''
  const encoded = wrapper.match(/printf %b "([\\0-7]+)"/)?.[1]
  if (!encoded) {
    return wrapper
  }
  const bytes = [...encoded.matchAll(/\\0([0-7]{3})/g)].map((match) => Number.parseInt(match[1], 8))
  return new TextDecoder().decode(new Uint8Array(bytes))
}

export function unwrapPowerShellScript(command: string | undefined): string {
  const encoded = command?.match(/-EncodedCommand\s+(\S+)/)?.[1]
  expect(encoded).toBeDefined()
  return Buffer.from(encoded!, 'base64').toString('utf16le')
}