Files
orca/src/main/powershell-osc133-bootstrap.ts
T
0c0367ea88 feat(agents): native Xiaomi MiMo Code support (#6239)
* 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>
2026-06-24 00:17:49 -07:00

84 lines
3.2 KiB
TypeScript

import { getPowerShellOmpShellWrapper } from './pty/omp-shell-wrapper'
export { encodePowerShellCommand } from '../shared/powershell-command-encoding'
const POWERSHELL_OSC133_BOOTSTRAP = `# Orca OSC 133 shell integration for PowerShell.
if ((Test-Path variable:global:__OrcaOsc133State) -and
$null -ne $Global:__OrcaOsc133State.OriginalPrompt) {
return
}
if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
return
}
# Profiles have already loaded normally by the time -EncodedCommand runs.
# Wrap the user's final prompt/readline state; do not source profiles here.
# Preserve Windows CJK output by keeping ConPTY on UTF-8 without bypassing
# profile loading or execution-policy checks.
try {
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
[Console]::InputEncoding = [System.Text.UTF8Encoding]::new()
$OutputEncoding = [Console]::OutputEncoding
} catch { Write-Error $_ -ErrorAction Continue }
# Profiles can re-export user defaults after Orca's spawn env is set.
if ($env:ORCA_OPENCODE_CONFIG_DIR) { $env:OPENCODE_CONFIG_DIR = $env:ORCA_OPENCODE_CONFIG_DIR }
if ($env:ORCA_MIMOCODE_HOME) { $env:MIMOCODE_HOME = $env:ORCA_MIMOCODE_HOME }
${getPowerShellOmpShellWrapper()}
if ($env:ORCA_CODEX_HOME) { $env:CODEX_HOME = $env:ORCA_CODEX_HOME }
$Global:__OrcaOsc133State = @{
OriginalPrompt = $function:prompt
OriginalReadLine = $function:PSConsoleHostReadLine
HasSeenPrompt = $false
HasPSReadLine = $null -ne (Get-Module -Name PSReadLine)
Esc = [char]27
Bel = [char]7
}
function Global:prompt {
# Capture FIRST; any other expression can clobber PowerShell's success bit.
$fakeExitCode = [int](!$global:?)
Set-StrictMode -Off
$result = ""
# Emit D from prompt, not readline state. Some profile setups bypass
# PSConsoleHostReadLine; the consumer only needs completion.
if ($Global:__OrcaOsc133State.HasSeenPrompt) {
$result += "$($Global:__OrcaOsc133State.Esc)]133;D;$fakeExitCode$($Global:__OrcaOsc133State.Bel)"
}
$Global:__OrcaOsc133State.HasSeenPrompt = $true
$result += "$($Global:__OrcaOsc133State.Esc)]133;A$($Global:__OrcaOsc133State.Bel)"
# Preserve the previous success/failure value for prompts that inspect it.
if ($fakeExitCode -ne 0) { Write-Error "failure" -ea ignore }
$result += $Global:__OrcaOsc133State.OriginalPrompt.Invoke()
$result += "$($Global:__OrcaOsc133State.Esc)]133;B$($Global:__OrcaOsc133State.Bel)"
$result
}
if ($Global:__OrcaOsc133State.HasPSReadLine -and
$null -ne $Global:__OrcaOsc133State.OriginalReadLine) {
function Global:PSConsoleHostReadLine {
$commandLine = $Global:__OrcaOsc133State.OriginalReadLine.Invoke()
[Console]::Write("$($Global:__OrcaOsc133State.Esc)]133;C$($Global:__OrcaOsc133State.Bel)")
return $commandLine
}
}
`
export function getPowerShellOsc133Bootstrap(): string {
return POWERSHELL_OSC133_BOOTSTRAP
}
export function isPowerShellExecutableName(shellName: string): boolean {
const normalized = shellName.toLowerCase()
return (
normalized === 'pwsh' ||
normalized === 'pwsh.exe' ||
normalized === 'powershell' ||
normalized === 'powershell.exe'
)
}