Files
westey bad05a2bdc Python: Harness console for python (#6312)
* Add initial harness console for python

* Add textual to project

* Add planning and approval flows with list selector

* Address PR comments

* Fix list selection bug

* Fix PR #6312 round 2 review comments

- Escape untrusted agent text with rich.markup.escape() in observers
  (text_output, planning_output, reasoning_display) to prevent markup injection
- Remove non-functional 'Always approve' choices from tool_approval.py
  (framework lacks CreateAlwaysApproveToolResponse support)
- Remove textual from root pyproject.toml dev deps (sample-specific)
- Add PEP 723 inline script metadata to harness_research.py
- Narrow except Exception to except NoMatches in list_selection.py

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix build error

* Fix build errors

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-09 05:48:35 +00:00

59 lines
1.5 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
"""Abstract base class for console command handlers.
Command handlers intercept user input starting with '/' and execute
local commands before input reaches the agent. They are checked in order;
the first handler that accepts the input prevents further handlers from
being checked.
"""
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from agent_framework import AgentSession
from ..state_driver import IUXStateDriver
class CommandHandler(ABC):
"""Base class for console command handlers.
Subclasses implement get_help_text() for the mode bar and
try_handle() to intercept matching commands.
"""
@abstractmethod
def get_help_text(self) -> str | None:
"""Get the help text for this command.
Displayed in the mode-and-help bar. Return None if the
command is not currently available.
Returns:
Help text like '/todos (show todo list)', or None.
"""
...
@abstractmethod
async def try_handle(
self,
user_input: str,
session: AgentSession,
ux: IUXStateDriver,
) -> bool:
"""Attempt to handle the given user input.
Args:
user_input: The raw user input string.
session: The current agent session.
ux: The UX state driver for rendering output.
Returns:
True if this handler handled the input; False otherwise.
"""
...