faheemcode.sdk.utils
Utility functions for the Faheem Code SDK.
deprecated()
Return a decorator that deprecates a callable with explicit metadata.
Use this helper when you can annotate a function, method, or property with
@deprecated(…). It transparently forwards to deprecation.deprecated()
while filling in the SDK’s current version metadata unless custom values are
supplied.
maybe_truncate()
Truncate the middle of content if it exceeds the specified length.
Keeps the head and tail of the content to preserve context at both ends. Optionally saves the full content to a file for later investigation.
- Parameters:
content– The text content to potentially truncatetruncate_after– Maximum length before truncation. If None, no truncation occurstruncate_notice– Notice to insert in the middle when content is truncatedsave_dir– Working directory to save full content file intool_prefix– Prefix for the saved file (e.g., “bash”, “browser”, “editor”)
- Returns: Original content if under limit, or truncated content with head and tail preserved and reference to saved file if applicable
sanitize_faheemcode_mentions()
Sanitize @Faheem Code mentions in text to prevent self-mention loops.
This function inserts a zero-width joiner (ZWJ) after the @ symbol in @Faheem Code mentions, making them non-clickable in GitHub comments while preserving readability. The original case of the mention is preserved.
- Parameters:
text– The text to sanitize - Returns: Text with sanitized @Faheem Code mentions (e.g., “@Faheem Code” -> “@Faheem Code”)
Examples
>>> sanitize_faheemcode_mentions("Thanks @Faheem Code for the help!")
'Thanks @u200dFaheemCode for the help!'
>>> sanitize_faheemcode_mentions("Check @faheem-code and @FAHEEMCODE")
'Check @u200dfaheemcode and @u200dFAHEEMCODE'
>>> sanitize_faheemcode_mentions("No mention here")
'No mention here'
sanitized_env()
Return a copy of env with sanitized values.
PyInstaller-based binaries rewrite LD_LIBRARY_PATH so their vendored
libraries win. This function restores the original value so that subprocess
will not use them.
warn_deprecated()
Emit a deprecation warning for dynamic access to a legacy feature.
Prefer this helper when a decorator is not practical—e.g. attribute accessors,
data migrations, or other runtime paths that must conditionally warn. Provide
explicit version metadata so the SDK reports consistent messages and upgrades
to deprecation.UnsupportedWarning after the removal threshold.