Skip to content

Context Mention

chimera.context.mentions provides structured context injection via @-mentions in user messages. The MentionResolver parses @file:, @folder:, and @url: references, resolves their content, and returns both a cleaned version of the text and the resolved Mention objects.

ClassDescription
MentionA resolved mention with type, reference, and content fields
MentionResolverParses and resolves @-mentions from user text
SyntaxDescription
@file:pathRead a file’s content
@folder:pathList directory tree (up to 50 entries)
@url:https://...Fetch URL content (requires httpx)
from chimera.context.mentions import MentionResolver
resolver = MentionResolver(workdir="/my/project")
text = "Review @file:utils.py and check @folder:tests/"
cleaned, mentions = resolver.resolve(text)
print(cleaned) # "Review and check"
for m in mentions:
print(f"{m.type}: {m.reference} -> {len(m.content)} chars")

inject() replaces mentions with their resolved content directly in the message text:

expanded = resolver.inject("Fix the bug in @file:main.py")
# Returns:
# Fix the bug in
# --- file: main.py ---
# <file content>

Pass an Environment for workspace-aware file resolution:

from chimera.env.local import LocalEnvironment
from chimera.context.mentions import MentionResolver
env = LocalEnvironment(workdir="/my/project")
resolver = MentionResolver(env=env)
cleaned, mentions = resolver.resolve("Explain @file:src/core.py")
from chimera.context.mentions import MentionResolver, Mention