This commit is contained in:
2026-03-19 13:08:15 -07:00
parent 5cbc2c09df
commit cc9c1850a8
7 changed files with 340 additions and 55 deletions

123
CLI.py
View File

@@ -114,6 +114,68 @@ from SYS.cli_parsing import SelectionSyntax, SelectionFilterSyntax, MedeiaLexer
def _notify_mpv_osd(text: str, *, duration_ms: int = 3500) -> bool:
message = str(text or "").strip()
if not message:
return False
try:
from MPV.mpv_ipc import MPVIPCClient, get_ipc_pipe_path
client = MPVIPCClient(
socket_path=get_ipc_pipe_path(),
timeout=0.75,
silent=True,
)
try:
response = client.send_command({
"command": [
"show-text",
message,
max(0, int(duration_ms)),
]
})
finally:
try:
client.disconnect()
except Exception:
pass
return bool(response and response.get("error") == "success")
except Exception as exc:
debug(f"mpv notify failed: {exc}")
return False
def _notify_mpv_completion(metadata: Dict[str, Any], execution_result: Dict[str, Any]) -> bool:
notify = metadata.get("mpv_notify") if isinstance(metadata, dict) else None
if not isinstance(notify, dict):
return False
success = bool(execution_result.get("success"))
error_text = str(execution_result.get("error") or "").strip()
if success:
message = str(notify.get("success_text") or "").strip()
else:
failure_prefix = str(notify.get("failure_text") or "").strip()
message = failure_prefix
if error_text:
if message:
message = f"{message}: {error_text}"
else:
message = error_text
if not message:
return False
try:
duration_ms = int(notify.get("duration_ms") or 3500)
except Exception:
duration_ms = 3500
return _notify_mpv_osd(message, duration_ms=duration_ms)
class _OldWorkerStages:
"""Factory methods for stage/pipeline worker sessions."""
@@ -819,6 +881,14 @@ class CmdletExecutor:
if not cmd_fn:
print(f"Unknown command: {cmd_name}\n")
try:
ctx.set_last_execution_result(
status="failed",
error=f"Unknown command: {cmd_name}",
command_text=" ".join([cmd_name, *args]).strip() or cmd_name,
)
except Exception:
pass
return
config = self._config_loader.load()
@@ -1289,6 +1359,14 @@ class CmdletExecutor:
already_rendered = False
if already_rendered:
try:
ctx.set_last_execution_result(
status=stage_status,
error=stage_error,
command_text=" ".join([cmd_name, *filtered_args]).strip() or cmd_name,
)
except Exception:
pass
return
if progress_ui is not None:
@@ -1351,6 +1429,15 @@ class CmdletExecutor:
pass
# Do not keep stage tables around after a single command; it can cause
# later @ selections to bind to stale tables (e.g. old add-file scans).
try:
if hasattr(ctx, "set_last_execution_result"):
ctx.set_last_execution_result(
status=stage_status,
error=stage_error,
command_text=" ".join([cmd_name, *filtered_args]).strip() or cmd_name,
)
except Exception:
pass
try:
if hasattr(ctx, "set_current_stage_table"):
ctx.set_current_stage_table(None)
@@ -2268,6 +2355,11 @@ Come to love it when others take what you share, as there is no greater joy
continue
pipeline_ctx_ref = None
queued_metadata = (
queued_payload.get("metadata")
if isinstance(queued_payload, dict) and isinstance(queued_payload.get("metadata"), dict)
else None
)
try:
from SYS import pipeline as ctx
@@ -2276,11 +2368,24 @@ Come to love it when others take what you share, as there is no greater joy
except Exception:
pipeline_ctx_ref = None
execution_result: Dict[str, Any] = {
"status": "completed",
"success": True,
"error": "",
"command_text": user_input,
}
try:
from SYS.cli_syntax import validate_pipeline_text
syntax_error = validate_pipeline_text(user_input)
if syntax_error:
execution_result = {
"status": "failed",
"success": False,
"error": str(syntax_error.message or "syntax error"),
"command_text": user_input,
}
print(syntax_error.message, file=sys.stderr)
continue
except Exception:
@@ -2289,6 +2394,12 @@ Come to love it when others take what you share, as there is no greater joy
try:
tokens = shlex.split(user_input)
except ValueError as exc:
execution_result = {
"status": "failed",
"success": False,
"error": str(exc),
"command_text": user_input,
}
print(f"Syntax error: {exc}", file=sys.stderr)
continue
@@ -2434,6 +2545,18 @@ Come to love it when others take what you share, as there is no greater joy
else:
self._cmdlet_executor.execute(cmd_name, tokens[1:])
finally:
if pipeline_ctx_ref and hasattr(pipeline_ctx_ref, "get_last_execution_result"):
try:
latest = pipeline_ctx_ref.get_last_execution_result()
if isinstance(latest, dict) and latest:
execution_result = latest
except Exception:
pass
if queued_metadata:
try:
_notify_mpv_completion(queued_metadata, execution_result)
except Exception:
pass
if pipeline_ctx_ref:
pipeline_ctx_ref.clear_current_command_text()