Skip to content

log

Class info

Classes

Name Children Inherits
LogScreen
acptui.ui.screens.log
Live view of the :class:`AgentLog`.

    ๐Ÿ›ˆ DocStrings

    The agent log: stderr of the agent process and (optionally) the JSON-RPC traffic.

    LogScreen

    Bases: Screen[None]

    Live view of the :class:AgentLog.

    Source code in src/acptui/ui/screens/log.py
    class LogScreen(Screen[None]):
        """Live view of the :class:`AgentLog`."""
    
        DEFAULT_CSS = """
        LogScreen {
            #log-title { height: 1; background: $panel; padding: 0 1; }
            RichLog { height: 1fr; }
        }
        """
    
        BINDINGS: ClassVar = [
            Binding("escape,ctrl+l", "close", "Back"),
            Binding("t", "toggle_traffic", "Protocol traffic"),
        ]
    
        def __init__(self, log: AgentLog) -> None:
            super().__init__()
            self.agent_log = log
            self.show_traffic = False
    
        def compose(self) -> ComposeResult:
            yield Static("", id="log-title")
            yield RichLog(wrap=True, highlight=False, markup=False, max_lines=5000)
            yield Footer()
    
        def on_mount(self) -> None:
            self._reload()
            self.agent_log.subscribe(self._append)
    
        def on_unmount(self) -> None:
            self.agent_log.unsubscribe(self._append)
    
        def _reload(self) -> None:
            traffic = "shown" if self.show_traffic else "hidden (t)"
            self.query_one("#log-title", Static).update(
                f"Agent log ยท stderr ยท protocol traffic {traffic}"
            )
            view = self.query_one(RichLog)
            view.clear()
            for line in self.agent_log.lines:
                self._append(line)
    
        def _append(self, line: LogLine) -> None:
            if line.kind in {"incoming", "outgoing"} and not self.show_traffic:
                return
            text = Text.assemble(
                (line.time.strftime("%H:%M:%S "), "dim"),
                (PREFIX[line.kind] + " ", STYLES[line.kind]),
                (line.text, STYLES[line.kind] if line.kind != "stderr" else ""),
            )
            self.query_one(RichLog).write(text)
    
        def action_toggle_traffic(self) -> None:
            """Show or hide the JSON-RPC messages."""
            self.show_traffic = not self.show_traffic
            self._reload()
    
        def action_close(self) -> None:
            """Back to the session."""
            self.dismiss(None)
    

    action_close

    action_close() -> None
    

    Back to the session.

    Source code in src/acptui/ui/screens/log.py
    def action_close(self) -> None:
        """Back to the session."""
        self.dismiss(None)
    

    action_toggle_traffic

    action_toggle_traffic() -> None
    

    Show or hide the JSON-RPC messages.

    Source code in src/acptui/ui/screens/log.py
    def action_toggle_traffic(self) -> None:
        """Show or hide the JSON-RPC messages."""
        self.show_traffic = not self.show_traffic
        self._reload()