fix(title): strip a quoted path's line-range suffix in the attachment-only guard

A quoted (space-bearing) @file:/@folder: reference may carry a :start[-end]
line range; the canonical parser (context_references.REFERENCE_PATTERN)
claims the whole token. The guard's local copy stopped at the closing quote,
leaving ":3" as residual "prose", so a quoted, line-ranged attachment-only
opener kept a path-derived title (#92068 regression found in review of #122000).
Mirror the canonical value shape and pin all three quote styles (#122000).
This commit is contained in:
Hermes Agent
2026-09-25 18:05:09 -05:00
committed by brooklyn!
parent 5ef8d96554
commit ce750ff151
2 changed files with 11 additions and 1 deletions

View File

@@ -274,8 +274,12 @@ def _strip_one_wrapper(text: str) -> str:
# written backtick-quoted). Kept local so the titler doesn't import the
# context-reference machinery (circularity / startup cost) just to detect the
# attachment-only shape (#92068).
_QUOTED = r"(?:`[^`\n]+`|\"[^\"\n]+\"|'[^'\n]+')"
# Mirrors the canonical agent.context_references value shape: a quoted
# (space-bearing) path may carry a ``:start[-end]`` line-range suffix, and a
# bare path swallows its own range via ``\S+``.
_CONTEXT_REFERENCE_TOKEN_RE = re.compile(
r"(?<![\w/])@(?:file|folder):(?:(?:`[^`\n]+`|\"[^\"\n]+\"|'[^'\n]+')|\S+)"
rf"(?<![\w/])@(?:file|folder):(?:{_QUOTED}(?::\d+(?:-\d+)?)?|\S+)"
)

View File

@@ -69,6 +69,12 @@ class TestGenerateTitle:
# Backtick-quoted (space-bearing) paths and @folder: refs too.
assert is_titleable_user_message("@file:`my file.txt`") is False
assert is_titleable_user_message("@folder:/some/dir") is False
# A quoted path with a line range is one reference token for the
# canonical parser (context_references.REFERENCE_PATTERN), so the
# guard must strip the range too, not leave ":3" behind as "prose".
assert is_titleable_user_message("@file:`my file.txt`:3") is False
assert is_titleable_user_message('@file:"spaced name.md":12-14') is False
assert is_titleable_user_message("@file:'single quoted.md':1") is False
# The background model-title path refuses the same opener.
assert generate_title(msg) is None