updated panel display
This commit is contained in:
+76
-17
@@ -10,7 +10,7 @@ from dataclasses import dataclass, field
|
||||
from contextvars import ContextVar
|
||||
from typing import Any, Dict, List, Optional, Sequence, Callable
|
||||
from SYS.models import PipelineStageContext
|
||||
from SYS.logger import log, debug, is_debug_enabled
|
||||
from SYS.logger import log, debug, debug_panel, is_debug_enabled
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
from SYS.worker import WorkerManagerRegistry, WorkerStages
|
||||
@@ -28,6 +28,47 @@ HELP_EXAMPLE_SOURCE_COMMANDS = {
|
||||
}
|
||||
|
||||
|
||||
def _emit_selection_debug_panel(
|
||||
*,
|
||||
selection_token: Any,
|
||||
selection_indices: Sequence[int],
|
||||
item_count: int,
|
||||
filtered_count: int,
|
||||
stage_table_present: bool,
|
||||
display_table_present: bool,
|
||||
stage_is_last: bool,
|
||||
row_action: Optional[Sequence[Any]] = None,
|
||||
downstream_stages: Optional[Sequence[Sequence[Any]]] = None,
|
||||
mode: Optional[str] = None,
|
||||
) -> None:
|
||||
if not is_debug_enabled():
|
||||
return
|
||||
|
||||
try:
|
||||
rows: List[tuple[str, Any]] = [
|
||||
("selection", str(selection_token or "")),
|
||||
("indices", [int(idx) + 1 for idx in (selection_indices or [])]),
|
||||
("items", int(item_count)),
|
||||
("filtered", int(filtered_count)),
|
||||
("stage_table", bool(stage_table_present)),
|
||||
("display_table", bool(display_table_present)),
|
||||
("stage_is_last", bool(stage_is_last)),
|
||||
("downstream_stages", len(list(downstream_stages or []))),
|
||||
]
|
||||
if mode:
|
||||
rows.insert(1, ("mode", str(mode)))
|
||||
if row_action:
|
||||
rows.append(("row_action", " ".join(str(part) for part in row_action if part is not None)))
|
||||
|
||||
debug_panel(
|
||||
f"Selection replay {selection_token}",
|
||||
rows,
|
||||
border_style="magenta",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def set_live_progress(progress_ui: Any) -> None:
|
||||
"""Register the current Live progress UI so cmdlets can suspend it during prompts."""
|
||||
state = _get_pipeline_state()
|
||||
@@ -1883,6 +1924,7 @@ class PipelineExecutor:
|
||||
selected_row_args: List[str] = []
|
||||
skip_pipe_expansion = source_cmd in {".pipe", ".mpv"} and len(stages) > 0
|
||||
prefer_row_action = False
|
||||
preferred_row_action = None
|
||||
if len(selection_indices) == 1 and not stages:
|
||||
try:
|
||||
row_action = _get_row_action(selection_indices[0])
|
||||
@@ -1890,10 +1932,7 @@ class PipelineExecutor:
|
||||
row_action = None
|
||||
if row_action:
|
||||
prefer_row_action = True
|
||||
debug(
|
||||
"@N: skipping source command expansion because row has explicit selection_action "
|
||||
f"{row_action}"
|
||||
)
|
||||
preferred_row_action = list(row_action)
|
||||
# Command expansion via @N:
|
||||
# - Default behavior: expand ONLY for single-row selections.
|
||||
# - Special case: allow multi-row expansion for add-file directory tables by
|
||||
@@ -1978,7 +2017,7 @@ class PipelineExecutor:
|
||||
except Exception:
|
||||
logger.exception("Failed to record pipeline log step for @N expansion (pipeline_session=%r)", getattr(pipeline_session, 'worker_id', None))
|
||||
elif selected_row_args and stages:
|
||||
debug("@N: skipping source command expansion because downstream stages exist")
|
||||
pass
|
||||
|
||||
stage_table = None
|
||||
try:
|
||||
@@ -2003,8 +2042,6 @@ class PipelineExecutor:
|
||||
except Exception:
|
||||
stage_table = None
|
||||
|
||||
debug(f"@N: stage_table={stage_table is not None}, display_table={display_table is not None}")
|
||||
|
||||
# ====================================================================
|
||||
# PHASE 4: Retrieve and filter items from current result set
|
||||
# ====================================================================
|
||||
@@ -2015,14 +2052,31 @@ class PipelineExecutor:
|
||||
except Exception as exc:
|
||||
debug(f"@N: Exception getting items_list: {exc}")
|
||||
items_list = []
|
||||
|
||||
debug(f"@N: selection_indices={selection_indices}, items_list length={len(items_list)}")
|
||||
resolved_items = items_list if items_list else []
|
||||
if items_list:
|
||||
filtered = [
|
||||
resolved_items[i] for i in selection_indices
|
||||
if 0 <= i < len(resolved_items)
|
||||
]
|
||||
if selection_indices:
|
||||
if len(selection_indices) == 1:
|
||||
selection_label = f"@{selection_indices[0] + 1}"
|
||||
else:
|
||||
selection_label = "@{" + ",".join(str(idx + 1) for idx in selection_indices) + "}"
|
||||
else:
|
||||
selection_label = "@selection"
|
||||
_emit_selection_debug_panel(
|
||||
selection_token=selection_label,
|
||||
selection_indices=selection_indices,
|
||||
item_count=len(items_list),
|
||||
filtered_count=len(filtered),
|
||||
stage_table_present=(stage_table is not None),
|
||||
display_table_present=(display_table is not None),
|
||||
stage_is_last=(not stages),
|
||||
row_action=preferred_row_action,
|
||||
downstream_stages=stages,
|
||||
mode=("row_action" if preferred_row_action else "selection"),
|
||||
)
|
||||
if not filtered:
|
||||
print("No items matched selection in pipeline\n")
|
||||
return False, None
|
||||
@@ -2088,15 +2142,12 @@ class PipelineExecutor:
|
||||
filtered = track_items
|
||||
table_type_hint = "tidal.track"
|
||||
|
||||
debug(f"@N: calling _maybe_run_class_selector with filtered={len(filtered)} items, stage_is_last={not stages}")
|
||||
if PipelineExecutor._maybe_run_class_selector(
|
||||
ctx,
|
||||
config,
|
||||
filtered,
|
||||
stage_is_last=(not stages)):
|
||||
debug(f"@N: _maybe_run_class_selector returned True, returning False")
|
||||
return False, None
|
||||
debug(f"@N: _maybe_run_class_selector returned False, continuing")
|
||||
|
||||
from SYS.pipe_object import coerce_to_pipe_object
|
||||
|
||||
@@ -2105,7 +2156,6 @@ class PipelineExecutor:
|
||||
filtered_pipe_objs
|
||||
if len(filtered_pipe_objs) > 1 else filtered_pipe_objs[0]
|
||||
)
|
||||
debug(f"@N: coerced piped_result, stages={stages}")
|
||||
|
||||
if pipeline_session and worker_manager:
|
||||
try:
|
||||
@@ -2204,7 +2254,6 @@ class PipelineExecutor:
|
||||
print("Auto-applying metadata selection via get-tag")
|
||||
stages.append(["get-tag"])
|
||||
elif auto_stage:
|
||||
debug(f"@N: Found auto_stage={auto_stage}, appending")
|
||||
try:
|
||||
print(f"Auto-running selection via {auto_stage[0]}")
|
||||
except Exception:
|
||||
@@ -2238,7 +2287,6 @@ class PipelineExecutor:
|
||||
if not stages and selection_indices and len(selection_indices) == 1:
|
||||
row_action = _get_row_action(selection_indices[0], items_list)
|
||||
if row_action:
|
||||
debug(f"@N: applying row_action {row_action}")
|
||||
stages.append(row_action)
|
||||
if pipeline_session and worker_manager:
|
||||
try:
|
||||
@@ -2464,7 +2512,18 @@ class PipelineExecutor:
|
||||
ctx = sys.modules[__name__]
|
||||
|
||||
try:
|
||||
debug(f"execute_tokens: tokens={tokens}")
|
||||
try:
|
||||
from SYS.logger import debug_panel
|
||||
|
||||
debug_panel(
|
||||
"Pipeline execution",
|
||||
[
|
||||
("command", " ".join(str(tok) for tok in tokens)),
|
||||
("token_count", len(tokens)),
|
||||
],
|
||||
)
|
||||
except Exception:
|
||||
debug(f"execute_tokens: tokens={tokens}")
|
||||
self._try_clear_pipeline_stop(ctx)
|
||||
|
||||
# REPL guard: stage-local tables should not persist across independent
|
||||
|
||||
Reference in New Issue
Block a user