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.5 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { isNoiseMessage, stripNoiseMessages } from '../../../src/shared/native-chat-noise'
import type { NativeChatMessage } from '../../../src/shared/native-chat-types'

function msg(
  role: NativeChatMessage['role'],
  text: string,
  blocks?: NativeChatMessage['blocks']
): NativeChatMessage {
  return {
    id: text.slice(0, 8),
    role,
    blocks: blocks ?? [{ type: 'text', text }],
    timestamp: 0,
    source: 'transcript'
  }
}

describe('isNoiseMessage', () => {
  it('flags task-notification and system-reminder user turns', () => {
    expect(isNoiseMessage(msg('user', '<task-notification>\n<task-id>x</task-id>'))).toBe(true)
    expect(isNoiseMessage(msg('user', '<system-reminder>\nbe careful'))).toBe(true)
    expect(
      isNoiseMessage(
        msg(
          'user',
          'Caveat: The messages below were generated by the user while running local commands'
        )
      )
    ).toBe(true)
    expect(isNoiseMessage(msg('user', '[Request interrupted by user]'))).toBe(true)
  })

  it('flags inter-agent harness turns (teammate/agent messages)', () => {
    expect(isNoiseMessage(msg('user', '<teammate-message>ping</teammate-message>'))).toBe(true)
    expect(isNoiseMessage(msg('user', '<agent-message>status update'))).toBe(true)
  })

  it('keeps real user messages', () => {
    expect(isNoiseMessage(msg('user', 'make it work for codex'))).toBe(false)
    expect(isNoiseMessage(msg('user', '<bash-brothers> is my band'))).toBe(false)
  })

  it('keeps assistant, tool, and ordinary system turns', () => {
    expect(isNoiseMessage(msg('assistant', '<system-reminder> in prose'))).toBe(false)
    expect(isNoiseMessage(msg('tool', '<system-reminder> in prose'))).toBe(false)
    expect(isNoiseMessage(msg('system', 'Conversation interrupted'))).toBe(false)
  })

  it('keeps tool-bearing user turns even when their text looks like harness noise', () => {
    for (const block of [
      { type: 'tool-result', output: 'ok' },
      { type: 'tool-call', name: 'Bash', input: { command: 'ls' } }
    ] satisfies NativeChatMessage['blocks']) {
      expect(
        isNoiseMessage(msg('user', '', [{ type: 'text', text: '<task-notification>done' }, block]))
      ).toBe(false)
    }
  })

  it('stripNoiseMessages removes only the noise', () => {
    const out = stripNoiseMessages([
      msg('user', 'hello'),
      msg('user', '<task-notification>done'),
      msg('assistant', 'hi')
    ])
    expect(out.map((m) => m.role)).toEqual(['user', 'assistant'])
  })
})