contextcraft.Engine
Engine(config: Config | None = None) -> None
Bases: Handle
Analyze repositories and generate protected, token-budgeted context.
Reuse an engine to retain parsers, queries, and tokenizer resources. Calls on one engine are serialized, while separate engines may run concurrently. Use it as a context manager to release native resources when finished.
Functions:
- analyze_inputs – Analyze supplied sources without reading them from the filesystem.
- analyze_path – Scan a directory and return a reusable, independently owned analysis.
- close – Release native resources, with repeated calls safely ignored.
- generate – Generate context from an open analysis without rescanning its inputs.
- run – Scan a directory, generate an artifact, and close the temporary analysis.
Attributes:
- closed (
bool) – Whether native resources have been released. - config (
Config) – Default immutable configuration used when creating new analyses.
contextcraft.Engine.analyze_inputs
analyze_inputs(inputs: Iterable[Input], *, root: str | os.PathLike[str] | None = None, config: Config | None = None) -> Analysis
Analyze supplied sources without reading them from the filesystem.
Parameters:
- inputs (
Iterable[Input]) – Logical paths with text, bytes, or a path-only source of None. - root (
str | PathLike[str] | None) – Optional directory used to resolve absolute build metadata paths. - config (
Config | None) – Analysis settings, defaulting to the engine configuration.
Returns:
Analysis– An analysis whose retained data is independent of the engine.
contextcraft.Engine.analyze_path
analyze_path(root: str | os.PathLike[str] = '.', *, config: Config | None = None) -> Analysis
Scan a directory and return a reusable, independently owned analysis.
Parameters:
- root (
str | PathLike[str]) – Repository directory, defaulting to the current directory. - config (
Config | None) – Analysis settings, defaulting to the engine configuration.
Returns:
Analysis– A native analysis to close explicitly or use as a context manager.
contextcraft.Engine.close
close() -> None
Release native resources, with repeated calls safely ignored.
contextcraft.Engine.closed
closed: bool
Whether native resources have been released.
contextcraft.Engine.config
config: Config
Default immutable configuration used when creating new analyses.
contextcraft.Engine.generate
generate(analysis: Analysis, config: Config | None = None) -> Artifact
Generate context from an open analysis without rescanning its inputs.
Parameters:
- analysis (
Analysis) – Repository snapshot to rank and render. - config (
Config | None) – Generation settings, defaulting to the analysis configuration.
Returns:
Artifact– Python-owned output, exact token count, scores, selection, and findings.
Raises:
SecretsDetectedError– Block mode rejects findings in the output view.ValueError– Settings are invalid or the output framing cannot fit.
contextcraft.Engine.run
run(root: str | os.PathLike[str] = '.', *, config: Config | None = None) -> Artifact
Scan a directory, generate an artifact, and close the temporary analysis.
Each call reads fresh inputs. Use analyze_path and generate separately when several outputs should share one repository snapshot.