#!/usr/bin/env python3.14# -*- coding: utf-8 -*-"""The web shell's `show` and `edit`: swap the app shell's left pane instead of opening a tab.Replacement bodies (`overlays.toml` → `replace`) for :func:`solver.core.viewer.show` and:func:`solver.core.viewer.edit`. The shell runs on the server while the user's browser iselsewhere, so there is no local browser to drive: each emits an `OSC 5379` sequence on stdoutthat the xterm.js page rides over the PTY → WebSocket pipe, and the page swaps its left pane —the monotonic token lets it ignore the sequence when the PTY replay buffer re-sends it onreconnect. What may be opened is decided by the solver's own checks, so the two bodies agree.The signatures are the originals' exactly — :func:`solver.shell.register.replace_body` refusesanything else — while the help, usage and completion stay the originals'."""from__future__importannotations__all__=['edit','show']fromsolver.configimportExitCodesfromsolver.core.problemsimportProblemfromsolver.core.viewerimportedit_path,pane_path_errorfromsolver.shellimportconsolefromeuler_webshell.shellimportoscdefedit(problem:Problem,filename:str)->int:"""Point the left pane at *filename*'s editor: `edit;<NNNN>;<token>;<relpath>`."""if(rel:=edit_path(problem,filename))isNone:returnExitCodes.EXIT_ERRORosc.emit('edit',f'{problem.number:04d}',str(osc.token()),rel)console.print(f'[muted]editing[/muted] [accent]{rel}[/accent] [muted]in the viewer panel[/muted]')returnExitCodes.EXIT_OKdefshow(problem:Problem,path:str|None=None)->int:"""Swap the left pane to the problem's page (`open;<NNNN>;<token>`) or to *path* (`nav;<token>;<path>`)."""ifpathisnotNone:if(why:=pane_path_error(path))isnotNone:console.print(f'[error]error:[/error] [muted]{path}: {why}[/muted]')returnExitCodes.EXIT_ERRORlabel=pathosc.emit('nav',str(osc.token()),path)else:label=f'{problem.number:04d}'osc.emit('open',label,str(osc.token()))console.print(f'[muted]opening[/muted] [accent]{label}[/accent] [muted]in the viewer panel[/muted]')returnExitCodes.EXIT_OK