feat(markdown): prefer tool description in callout title
This commit is contained in:
@@ -42,9 +42,11 @@ USER_SCAFFOLD = "### User:\n"
|
|||||||
# contain ``` and we get language syntax highlighting in Obsidian for free.
|
# contain ``` and we get language syntax highlighting in Obsidian for free.
|
||||||
FENCE = "````"
|
FENCE = "````"
|
||||||
|
|
||||||
# Used when a tool input mentions a path/file we can dangle in the
|
# Input keys we dangle after the tool name in the callout title, best
|
||||||
# callout title — purely cosmetic.
|
# first — purely cosmetic. ``description`` wins because when a tool
|
||||||
_PATH_KEYS = ("path", "file", "filename", "url", "command", "query")
|
# offers one it's a human-written summary of the call, which beats a
|
||||||
|
# truncated shell command or path.
|
||||||
|
_TITLE_KEYS = ("description", "path", "file", "filename", "url", "command", "query")
|
||||||
|
|
||||||
|
|
||||||
def render_user_text(content: str) -> str:
|
def render_user_text(content: str) -> str:
|
||||||
@@ -114,9 +116,9 @@ def append_to_body(existing: str, new_block: str) -> str:
|
|||||||
def summarize_tool_input(name: str, tool_input: object) -> str:
|
def summarize_tool_input(name: str, tool_input: object) -> str:
|
||||||
"""Build the ``[!tool]- <summary>`` title string.
|
"""Build the ``[!tool]- <summary>`` title string.
|
||||||
|
|
||||||
Tries to pick a single salient field (``path``, ``command``, etc.)
|
Tries to pick a single salient field (``description``, ``path``,
|
||||||
from the input dict so the collapsed callout shows something
|
``command``, etc.) from the input dict so the collapsed callout shows
|
||||||
meaningful in Obsidian. Falls back to just the tool name.
|
something meaningful in Obsidian. Falls back to just the tool name.
|
||||||
"""
|
"""
|
||||||
if not isinstance(tool_input, dict):
|
if not isinstance(tool_input, dict):
|
||||||
return name
|
return name
|
||||||
@@ -125,7 +127,7 @@ def summarize_tool_input(name: str, tool_input: object) -> str:
|
|||||||
# cast keeps the rest of the function readable without sprinkling
|
# cast keeps the rest of the function readable without sprinkling
|
||||||
# per-line type narrowing on every ``.get`` call.
|
# per-line type narrowing on every ``.get`` call.
|
||||||
d = cast("dict[str, Any]", tool_input)
|
d = cast("dict[str, Any]", tool_input)
|
||||||
for key in _PATH_KEYS:
|
for key in _TITLE_KEYS:
|
||||||
value = d.get(key)
|
value = d.get(key)
|
||||||
if isinstance(value, str) and value:
|
if isinstance(value, str) and value:
|
||||||
short = value if len(value) <= 60 else value[:57] + "..."
|
short = value if len(value) <= 60 else value[:57] + "..."
|
||||||
|
|||||||
Reference in New Issue
Block a user