mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 08:02:28 +00:00
* feat(agents): native Xiaomi MiMo Code support Add mimo-code TUI agent (detect mimo, --prompt, --session resume). Inject MIMOCODE_HOME overlay and /hook/mimo-code status plugin on mimo launch when agent status hooks are enabled; restore via shell-ready wrappers. Reuse OpenCode-family hook normalization in the listener. SSH remote MiMo hook overlays are not included (local/daemon first). Closes #6220 * fix(mimo): remirror overlay config idempotently rmSync overlay config before mirror so a second mimo launch does not hit EEXIST in mirrorEntry and fall back to the user MIMOCODE_HOME. * review: harden mimo code support Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Doan Bac Tam <24356000+doanbactam@users.noreply.github.com> Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com> Co-authored-by: Orca <help@stably.ai>
80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import {
|
|
detectAgentStatusFromTitle,
|
|
extractAllOscTitles,
|
|
extractLastOscTitle,
|
|
getAgentLabel,
|
|
MAX_OSC_TITLE_CHARS
|
|
} from './agent-detection'
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
describe('OSC title extraction', () => {
|
|
it('extracts the last OSC title from BEL-terminated PTY data', () => {
|
|
expect(extractLastOscTitle('\x1b]0;First\x07noise\x1b]2;Second\x07')).toBe('Second')
|
|
})
|
|
|
|
it('extracts all OSC titles including ST-terminated titles', () => {
|
|
expect(extractAllOscTitles('\x1b]0;First\x1b\\noise\x1b]2;Second\x07')).toEqual([
|
|
'First',
|
|
'Second'
|
|
])
|
|
})
|
|
|
|
it('ignores incomplete OSC titles until a later chunk supplies the terminator', () => {
|
|
expect(extractAllOscTitles('\x1b]0;Incomplete title')).toEqual([])
|
|
expect(extractLastOscTitle('\x1b]0;Incomplete title')).toBeNull()
|
|
})
|
|
|
|
it('recovers when an abandoned incomplete OSC title is followed by a fresh title', () => {
|
|
const data = '\x1b]0;abandoned\x1b]0;Fresh title\x07'
|
|
|
|
expect(extractLastOscTitle(data)).toBe('Fresh title')
|
|
expect(extractAllOscTitles(data)).toEqual(['Fresh title'])
|
|
})
|
|
|
|
it('scans large PTY chunks without regex match iteration', () => {
|
|
const matchAll = vi.spyOn(String.prototype, 'matchAll')
|
|
const data = `${'pasted terminal noise \x1b]x;ignored\x07 '.repeat(10_000)}\x1b]0;Agent working\x07`
|
|
|
|
expect(extractLastOscTitle(data)).toBe('Agent working')
|
|
expect(extractAllOscTitles(data).at(-1)).toBe('Agent working')
|
|
expect(matchAll).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('caps oversized OSC titles before downstream title processing', () => {
|
|
const title = `${'a'.repeat(MAX_OSC_TITLE_CHARS)}${'b'.repeat(10_000)}`
|
|
const data = `before\x1b]0;${title}\x07after`
|
|
|
|
const extracted = extractLastOscTitle(data)
|
|
|
|
expect(extracted).toHaveLength(MAX_OSC_TITLE_CHARS)
|
|
expect(extracted?.startsWith('a'.repeat(MAX_OSC_TITLE_CHARS / 2))).toBe(true)
|
|
expect(extracted?.endsWith('b'.repeat(MAX_OSC_TITLE_CHARS / 2))).toBe(true)
|
|
expect(extractAllOscTitles(data)).toEqual([extracted])
|
|
})
|
|
})
|
|
|
|
describe('MiMo title detection', () => {
|
|
it.each([
|
|
['MiMo Code', 'idle'],
|
|
['mimo ready', 'idle'],
|
|
['mimo working', 'working'],
|
|
['\u280b MiMo Code', 'working']
|
|
] as const)('classifies %s', (title, expectedStatus) => {
|
|
expect(getAgentLabel(title)).toBe('MiMo Code')
|
|
expect(detectAgentStatusFromTitle(title)).toBe(expectedStatus)
|
|
})
|
|
|
|
it.each(['~/mimo/working', 'mimo-code-fixtures ready'])(
|
|
'does not classify path or hyphen false positive %s',
|
|
(title) => {
|
|
expect(getAgentLabel(title)).toBeNull()
|
|
expect(detectAgentStatusFromTitle(title)).toBeNull()
|
|
}
|
|
)
|
|
})
|