Internals Reference
This page documents SpecSoloist's internal modules. It is intended for contributors and agents working on the framework itself, not for library users.
For the public-facing API, see Public API.
Parser
SpecParser
Handles spec file discovery, reading, parsing, creation, and validation.
__init__
Initialize the parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_dir
|
str
|
Directory where spec files are stored. |
required |
template_dir
|
Optional[str]
|
Optional override for template location (for testing). |
None
|
create_spec
Creates a new specification file from the template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Component name (e.g., "auth" creates "auth.spec.md"). |
required |
description
|
str
|
Brief description of the component. |
required |
spec_type
|
str
|
Component type ("function", "type", "bundle", "module", "workflow"). |
'function'
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the created spec file. |
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the spec already exists. |
validate_spec
Validates a spec for basic structure based on its type.
Returns a dict with 'valid' bool and 'errors' list.
get_reference_warnings
Returns quality warnings for a reference spec (not errors).
extract_verification_snippet
Extracts the code block from the '# Verification' section, if present.
parse_arrangement
Parses an Arrangement from YAML or Markdown frontmatter.
ParsedSpec
dataclass
A fully parsed specification.
SpecMetadata
dataclass
Parsed frontmatter from a spec file.
Compiler
SpecCompiler
Compiles specs to code using an LLM provider.
__init__
Initialize the compiler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
LLMProvider
|
LLM provider used for code generation. |
required |
global_context
|
str
|
Optional project-level context injected into every prompt. |
''
|
event_bus
|
Optional[EventBus]
|
Optional event bus for LLM call observability. |
None
|
compile_code
Compiles a spec to implementation code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ParsedSpec
|
The parsed specification. |
required |
model
|
Optional[str]
|
Optional model override. |
None
|
arrangement
|
Optional[Arrangement]
|
Optional build arrangement. |
None
|
reference_specs
|
Optional[dict]
|
Optional dict of reference spec name to ParsedSpec, injected as context. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The generated code. |
compile_typedef
Compiles a typedef spec to type definitions (dataclasses, TypedDicts, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ParsedSpec
|
The parsed specification (must be type: typedef). |
required |
model
|
Optional[str]
|
Optional model override. |
None
|
arrangement
|
Optional[Arrangement]
|
Optional build arrangement. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The generated type definition code. |
compile_orchestrator
Compiles an orchestrator spec to workflow execution code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ParsedSpec
|
The parsed specification (must be type: orchestrator). |
required |
model
|
Optional[str]
|
Optional model override. |
None
|
arrangement
|
Optional[Arrangement]
|
Optional build arrangement. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The generated orchestration code. |
compile_tests
Generates a test suite for a spec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ParsedSpec
|
The parsed specification. |
required |
model
|
Optional[str]
|
Optional model override. |
None
|
arrangement
|
Optional[Arrangement]
|
Optional build arrangement. |
None
|
reference_specs
|
Optional[dict]
|
Optional dict of reference spec name to ParsedSpec, injected as context. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The generated test code. |
generate_fix
Generates a fix for failing tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ParsedSpec
|
The parsed specification (source of truth). |
required |
code_content
|
str
|
Current implementation code. |
required |
test_content
|
str
|
Current test code. |
required |
error_log
|
str
|
Test failure output. |
required |
model
|
Optional[str]
|
Optional model override. |
None
|
arrangement
|
Optional[Arrangement]
|
Optional build arrangement. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The raw LLM response with FILE markers. |
Runner
TestRunner
Handles execution of tests for different languages.
__init__
Initialize the test runner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
build_dir
|
str
|
Directory where code and tests are built. |
required |
config
|
Optional[SpecSoloistConfig]
|
SpecSoloist configuration. |
None
|
get_test_path
Returns the path to the test file for a module.
get_code_path
Returns the path to the implementation file for a module.
test_exists
Checks if a test file exists for the module.
code_exists
Checks if an implementation file exists for the module.
write_code
Writes implementation code to the build directory.
write_tests
Writes test code to the build directory.
write_file
Writes a file to a specific path.
If filename is relative, it's relative to build_dir.
run_tests
Runs the test command for a module based on its language configuration.
TestResult
dataclass
Result of a test run.
Dependency Resolver
DependencyResolver
Resolves dependencies between specs and computes build orders.
__init__
Initialize the resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
SpecParser
|
SpecParser used to read spec frontmatter and list specs. |
required |
build_graph
Build a DependencyGraph from spec frontmatter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec_names
|
List[str]
|
Specs to include. Defaults to all specs in the src directory. |
None
|
Returns:
| Type | Description |
|---|---|
DependencyGraph
|
DependencyGraph with all dependency relationships populated. |
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
If a spec depends on a name that doesn't exist. |
resolve_build_order
Return a linear build order with dependencies before dependents.
Raises:
| Type | Description |
|---|---|
CircularDependencyError
|
If specs form a dependency cycle. |
get_parallel_build_order
Return specs grouped into parallel build levels.
Each level is a list of specs that can be compiled concurrently because all their dependencies appear in earlier levels.
get_affected_specs
Return all specs that transitively depend on changed_spec, in build order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
changed_spec
|
str
|
The spec that changed. |
required |
graph
|
DependencyGraph
|
Pre-built dependency graph. Built from all specs if not provided. |
None
|
DependencyGraph
dataclass
Represents dependency relationships between specs.
add_spec
Register a spec and its dependencies in the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Spec name to register. |
required |
depends_on
|
List[str]
|
List of spec names this spec depends on. |
None
|
CircularDependencyError
MissingDependencyError
Bases: Exception
Raised when a spec depends on one that doesn't exist.
Build Manifest
BuildManifest
dataclass
Collection of build records, persisted as JSON.
update_spec
Record a successful build for a spec, stamped with the current UTC time.
IncrementalBuilder
Determines which specs need rebuilding.
__init__
Initialize the incremental builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
BuildManifest
|
The current build manifest recording previous compilation state. |
required |
src_dir
|
str
|
Path to the directory containing spec files. |
required |
needs_rebuild
Return True if a spec needs to be recompiled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec_name
|
str
|
Name of the spec to check. |
required |
current_hash
|
str
|
SHA-256 hash of the current spec file content. |
required |
current_deps
|
List[str]
|
Current list of dependency names from the spec. |
required |
rebuilt_specs
|
set
|
Set of spec names already rebuilt in this run. |
required |
get_rebuild_plan
Return the ordered subset of specs that need rebuilding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
build_order
|
List[str]
|
Full topological build order for all specs. |
required |
spec_hashes
|
Dict[str, str]
|
Mapping of spec name to current content hash. |
required |
spec_deps
|
Dict[str, List[str]]
|
Mapping of spec name to current dependency list. |
required |
SpecBuildInfo
dataclass
Spec Drift Detection
SpecDiffResult
dataclass
SpecDiffIssue
dataclass
A single drift issue found by spec_diff.
Respec
Respecer
Reverse engineers Python source code into SpecSoloist specifications.
This is the fallback implementation used when --no-agent is specified. The preferred approach is agent-first (see score/prompts/respec.md).
__init__
Initialize the Respecer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[SpecSoloistConfig]
|
Framework configuration. Defaults to config from environment. |
None
|
provider
|
Optional[LLMProvider]
|
LLM provider. Defaults to the provider configured in config. |
None
|