Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/shared/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# shared package
28 changes: 28 additions & 0 deletions src/shared/patterns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Shared regex patterns used by both grok_bridge.py and grok_agent.py.

Centralizing these patterns ensures consistent parsing across all modules.
"""

# Canonical list of supported file extensions for filename detection.
SUPPORTED_EXTENSIONS = (
"py|js|ts|jsx|tsx|go|rs|java|c|cpp|h|hpp|cs|rb|php|swift|kt|scala|sh|bash"
)

# Regex pattern string that matches a comment-style filename header, e.g.:
# # filename.py
_FILENAME_PATTERN_STRING = (
r"^\s*#\s*([a-zA-Z_][a-zA-Z0-9_]*\.(?:"
+ SUPPORTED_EXTENSIONS
+ r"))\s*$"
)


def get_filename_pattern_string() -> str:
"""Return the canonical regex string for matching comment-style filename headers.

Both grok_bridge.py and grok_agent.py compile this string (with re.MULTILINE)
so that any change to the supported extension list is automatically reflected
in every consumer.
"""
return _FILENAME_PATTERN_STRING