Input handling utilities including image tracking and file mention parsing.
Characters allowed in file paths.
Includes alphanumeric, period, underscore, tilde (home), forward/back slashes (path separators), colon (Windows drive letters), and hyphen.
Pattern for extracting @file mentions from input text.
Matches @ followed by one or more path characters or escaped character
pairs (backslash + any character, e.g., \ for spaces in paths).
Uses + (not *) because a bare @ without a path is not a valid
file reference.
Pattern to detect email-like text preceding an @ symbol.
If the character immediately before @ matches this pattern, the @mention
is likely part of an email address (e.g., user@example.com) rather than
a file reference.
Pattern for highlighting @mentions and /commands in rendered
user messages.
Matches either:
/help)@file mentions anywhere in the text (e.g., @README.md)Note: The ^ anchor matches start of string, not start of line. The consumer
in UserMessage.compose() additionally checks start == 0 before styling
slash commands, so a / mid-string is not highlighted.
Pattern for image placeholders with a named id capture group.
Used to extract numeric IDs from placeholder tokens so the tracker can prune stale entries and compute the next available ID.
Extract @file mentions and return the text with resolved file paths.
Parses @file mentions from the input text and resolves them to absolute
file paths. Files that do not exist or cannot be resolved are excluded with
a warning printed to the console.
Email addresses (e.g., user@example.com) are automatically excluded by
detecting email-like characters before the @ symbol.
Backslash-escaped spaces in paths (e.g., @my\ folder/file.txt) are
unescaped before resolution. Tilde paths (e.g., @~/file.txt) are expanded
via Path.expanduser(). Only regular files are returned; directories are
excluded.
This function does not raise exceptions; invalid paths are handled internally with a console warning.
Parse a paste payload that may contain dragged-and-dropped file paths.
The parser is strict on purpose: it only returns paths when the entire paste payload can be interpreted as one or more existing files. Any invalid token falls back to normal text paste behavior by returning an empty list.
Supports common dropped-path formats:
file:// URLs