Work with in-memory files
Pass Input values when your tool already has the source, such as unsaved editor
buffers or files retrieved from another system.
from contextcraft import Config, Engine, Input
with Engine(Config(budget_tokens=2000)) as engine:
with engine.analyze_inputs([
Input("main.py", "from helper import ready\nprint(ready())\n"),
Input("helper.py", "def ready(): return True\n"),
]) as analysis:
artifact = engine.generate(analysis)
Input sources can be strings or bytes. None keeps an input path-only, and an
optional language name overrides detection. An explicit root directory can give
compilation database paths an absolute base.
Preserve local relationships
Use repository-relative paths consistently. The example names helper.py beside
main.py, so the import can resolve within the supplied inputs. Only the files
you provide are available for analysis.
Read the result
engine.generate returns the same Artifact as directory analysis. Its content
is the serialized output, while tokens, selection, scores, and findings
provide generation metadata. See output schemas
for the serialized formats and Input for
all input fields.