Core Modules
This section documents the core modules that power ToDoWrite Models.
todowrite.core
Models Module
The models module contains all ToDoWrite Models:
ToDoWrite Core Models Package.
This package provides access to all ToDoWrite SQLAlchemy models. You can import models in two ways:
# Import the entire package (backward compatible) from todowrite.core.models import Goal, Task, Command
# Or import specific models from todowrite.core.models import Goal from todowrite.core.models import Task from todowrite.core.models import Command
Models Available: - Base: SQLAlchemy declarative base - Goal: High-level project objectives - Concept: Abstract ideas and requirements - Context: Background information and constraints - Constraint: Technical and business constraints - Requirement: Specific functional requirements - AcceptanceCriteria: Definition of done criteria - InterfaceContract: API and interface contracts - Phase: Project phases and milestones - Step: Individual steps within phases - Task: Specific tasks with owners and status - SubTask: Breakdown of tasks into smaller units - Command: Executable commands and scripts - Label: Tags and categorization system - Metadata: Extensible metadata for ToDoWrite nodes
- class AcceptanceCriteria(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite AcceptanceCriteria model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- assignee
- created_at
- description
- ended_on
- extra_data
- id
- interface_contracts
- labels
- owner
- progress
- requirements
- severity
- started_on
- status
- title
- updated_at
- work_type
- class Base(**kwargs)[source]
Bases:
DeclarativeBaseBase class for all ToDoWrite models.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- metadata = MetaData()
Refers to the
_schema.MetaDatacollection that will be used for new_schema.Tableobjects.See also
- registry = <sqlalchemy.orm.decl_api.registry object>
Refers to the
_orm.registryin use where new_orm.Mapperobjects will be associated.
- class Command(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Command model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- acceptance_criteria_id
- artifacts
- property artifacts_list
Get artifacts as list.
- assignee
- cmd
- cmd_params
- created_at
- description
- ended_on
- id
- labels
- output
- owner
- progress
- runtime_env
- property runtime_env_dict
Get runtime environment as dictionary.
- severity
- started_on
- status
- sub_tasks
- title
- updated_at
- work_type
- class Concept(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Concept model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- assignee
- contexts
- created_at
- description
- ended_on
- extra_data
- goals
- id
- labels
- owner
- progress
- requirements
- severity
- started_on
- status
- title
- updated_at
- work_type
- class Constraint(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Constraint model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- assignee
- created_at
- description
- ended_on
- extra_data
- goals
- id
- labels
- owner
- progress
- requirements
- severity
- started_on
- status
- title
- updated_at
- work_type
- class Context(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Context model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- assignee
- concepts
- created_at
- description
- ended_on
- extra_data
- goals
- id
- labels
- owner
- progress
- requirements
- severity
- started_on
- status
- title
- updated_at
- work_type
- class Goal(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Goal model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- assignee
- complete_work()[source]
Mark goal as completed by setting ended_on to current timestamp.
- Return type:
- concepts
- constraints
- contexts
- classmethod create(title, description='', owner='', severity='', work_type='', assignee='')[source]
Create a new Goal instance with default values.
- Return type:
- created_at
- description
- ended_on
- extra_data
- id
- labels
- owner
- phases
- progress
- severity
- started_on
- status
- tasks
- title
- updated_at
- work_type
- class InterfaceContract(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite InterfaceContract model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- acceptance_criteria
- assignee
- created_at
- description
- ended_on
- extra_data
- id
- labels
- owner
- phases
- progress
- severity
- started_on
- status
- title
- updated_at
- work_type
- class Label(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Label model for categorizing and tagging other models.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- acceptance_criteria
- commands
- concepts
- constraints
- contexts
- created_at
- goals
- id
- interface_contracts
- name
- phases
- requirements
- steps
- sub_tasks
- tasks
- updated_at
- class Metadata(owner='', labels=None, severity='', work_type='', assignee='', extra=None)[source]
Bases:
objectExtensible metadata for ToDoWrite nodes.
- class Phase(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Phase model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- assignee
- created_at
- description
- ended_on
- extra_data
- goals
- id
- interface_contracts
- labels
- owner
- progress
- severity
- started_on
- status
- steps
- title
- updated_at
- work_type
- class Requirement(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Requirement model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- acceptance_criteria
- assignee
- concepts
- constraints
- contexts
- created_at
- description
- ended_on
- extra_data
- id
- labels
- owner
- progress
- severity
- started_on
- status
- title
- updated_at
- work_type
- class Step(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Step model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- assignee
- created_at
- description
- ended_on
- extra_data
- id
- labels
- owner
- phases
- progress
- severity
- started_on
- status
- tasks
- title
- updated_at
- work_type
- class SubTask(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite SubTask model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- assignee
- commands
- created_at
- description
- ended_on
- extra_data
- id
- labels
- owner
- progress
- severity
- started_on
- status
- tasks
- title
- updated_at
- work_type
- class Task(**kwargs)[source]
Bases:
Base,TimestampMixinToDoWrite Task model for hierarchical task management.
- __init__(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- assignee
- property commands
Get all commands from all subtasks for this task.
Provides complete execution plan visibility by aggregating all commands across all subtasks belonging to this task.
- Returns:
List of all Command objects from all subtasks in execution order.
- property completed_commands_count
Get count of completed commands across all subtasks.
- created_at
- description
- ended_on
- property execution_progress_percentage
Calculate execution progress as percentage based on completed commands.
- extra_data
- goals
- id
- labels
- owner
- progress
- severity
- started_on
- status
- steps
- sub_tasks
- title
- property total_commands_count
Get total number of commands across all subtasks.
- updated_at
- work_type
Schema Validator Module
Schema validation and database initialization:
ToDoWrite Model Schema Validator and Database Initializer.
This module provides programmatic access to the ToDoWrite model schemas, allowing the library to validate data, initialize databases from schemas, and ensure consistency between models and database structure.
- class FieldSchema[source]
Bases:
TypedDictSchema definition for a model field.
- type
- nullable
- default
- max_length
- primary_key
- unique
- class ModelSchema[source]
Bases:
TypedDictSchema definition for a model.
- table_name
- fields
- required_fields
- relationships
- class AssociationTableSchema[source]
Bases:
TypedDictSchema definition for an association table.
- table_name
- columns
- source_model
- target_model
- class ToDoWriteCompleteSchema[source]
Bases:
TypedDictComplete ToDoWrite schema structure.
- models
- association_tables
- generated_at
- description
- exception SchemaValidationError[source]
Bases:
ToDoWriteErrorRaised when schema validation fails.
- exception DatabaseInitializationError[source]
Bases:
ToDoWriteErrorRaised when database initialization from schema fails.
- class ToDoWriteSchemaValidator(schema_path=None)[source]
Bases:
objectToDoWrite Model Schema Validator and Database Manager.
Provides programmatic access to: 1. Validate data against schemas 2. Initialize databases from schema definitions 3. Ensure model-schema consistency 4. Import schemas into properly typed database tables
- get_association_table_schema(table_name)[source]
Get the schema definition for an association table.
- Return type:
- validate_model_data(model_name, data)[source]
Validate data against a specific model schema.
- Return type:
- initialize_database_from_schema(engine, drop_existing=False)[source]
Initialize database with all tables defined in the schema.
- class DatabaseSchemaInitializer(validator=None)[source]
Bases:
objectHelper class for database initialization using schema definitions.
Provides methods to create, drop, and verify database structure based on the ToDoWrite model schema.
- create_database(database_url, drop_existing=False)[source]
Create a new database initialized with the ToDoWrite model schema.
Exceptions Module
Core exception classes:
Custom exceptions for ToDoWrite
This module defines custom exception classes for consistent error handling throughout the ToDoWrite codebase.
- exception ModelError[source]
Bases:
ToDoWriteErrorBase exception for ToDoWrite Models-related errors.
- exception ModelNotFoundError(model_name, record_id)[source]
Bases:
ModelErrorRaised when a model record is not found.
- exception InvalidModelError(message, details=None)[source]
Bases:
ModelErrorRaised when model data is invalid.
- exception StorageError[source]
Bases:
ToDoWriteErrorBase exception for storage-related errors.
- exception DatabaseError(message, original_exception=None)[source]
Bases:
StorageErrorRaised for database-related errors.
- exception YAMLError(message, file_path=None)[source]
Bases:
StorageErrorRaised for YAML-related errors.
- exception SchemaError(message, validation_errors=None)[source]
Bases:
ToDoWriteErrorRaised for schema validation errors.
- exception ConfigurationError[source]
Bases:
ToDoWriteErrorRaised for configuration-related errors.
- exception CLIError[source]
Bases:
ToDoWriteErrorRaised for CLI-related errors.
- exception TokenOptimizationError[source]
Bases:
ToDoWriteErrorRaised for token optimization errors.
Schema Module
JSON schema definitions and validation:
Types Module
Type definitions and collections:
ToDoWrite Core Type Definitions.
This module contains shared type definitions and utility classes used throughout the ToDoWrite package.
Key Concepts: - LayerType: The 12 hierarchical layers from Goal to Command - StatusType: Workflow states for task tracking - Metadata: Extensible metadata system - Command: Executable command definitions
Example
>>> from todowrite.core.models import Goal
>>> from todowrite.core.types import LayerType, Metadata
>>>
>>> goal = Goal(
... title="Launch Product",
... description="Successfully launch the new product",
... owner="product-team",
... severity="high"
... )
- class AcceptanceCriteriaCollection(items=None)[source]
Bases:
ToDoWriteCollectionCollection for AcceptanceCriteria items.
- class CommandCollection(items=None)[source]
Bases:
ToDoWriteCollectionCollection for Command items.
- class Metadata(owner='', labels=None, severity='', work_type='', assignee='', extra=None)[source]
Bases:
objectExtensible metadata for ToDoWrite nodes.
- class PhaseCollection(items=None)[source]
Bases:
ToDoWriteCollectionCollection for Phase items.
- class StepCollection(items=None)[source]
Bases:
ToDoWriteCollectionCollection for Step items.
- class SubTaskCollection(items=None)[source]
Bases:
ToDoWriteCollectionCollection for SubTask items.
- class TaskCollection(items=None)[source]
Bases:
ToDoWriteCollectionCollection for Task items.
Utils Module
Utility functions and helpers:
Utility functions for ToDoWrite
This module contains utility functions that are used across the codebase to avoid code duplication and provide consistent behavior.
- safe_get_nested(data, *keys, default=None)[source]
Safely get a nested value from a dictionary using dot notation.
Project Manager Module
Project management utilities:
- class OptimizationParams[source]
Bases:
TypedDictParameters for token optimization functions
- text
- context
- model
- max_tokens
- class OptimizationResult[source]
Bases:
TypedDictResult from token optimization
- optimized
- error
- tokens_saved
- original_tokens
- optimized_tokens
- optimization_ratio
- strategies_used
- class ProjectManager[source]
Bases:
objectCentralized project management and utility methods.
- check_deprecated_schema()[source]
Check that the deprecated schema doesn’t have unintended changes. Returns True if check passes, False if there are issues.
- Return type:
- check_schema_changes()[source]
Check if schema changes are in the correct location. Returns True if check passes, False if there are issues.
- Return type:
- setup_integration(project_path, db_type='postgres')[source]
Set up ToDoWrite integration in a project.
- init_database_sql()[source]
Return PostgreSQL initialization SQL as string. This provides the SQL content that would be in the init script.
- Return type:
- setup_integration(project_path, db_type='postgres')[source]
Set up ToDoWrite integration in a project.
- Return type:
- create_project_structure(project_path)[source]
Create a basic ToDoWrite project structure.
- Return type:
- validate_project_setup(project_path)[source]
Validate that a project is properly set up for ToDoWrite.
Constants Module
Application constants and configuration:
Shared constants for ToDoWrite
todowrite.storage
Storage backend implementations and utilities:
- class DatabaseSchemaInitializer(validator=None)[source]
Bases:
objectHelper class for database initialization using schema definitions.
Provides methods to create, drop, and verify database structure based on the ToDoWrite model schema.
- create_database(database_url, drop_existing=False)[source]
Create a new database initialized with the ToDoWrite model schema.
- exception SchemaValidationError[source]
Bases:
ToDoWriteErrorRaised when schema validation fails.
- exception StorageConnectionError[source]
Bases:
StorageErrorDatabase connection error.
- exception StorageQueryError[source]
Bases:
StorageErrorDatabase query error.
- class ToDoWriteSchemaValidator(schema_path=None)[source]
Bases:
objectToDoWrite Model Schema Validator and Database Manager.
Provides programmatic access to: 1. Validate data against schemas 2. Initialize databases from schema definitions 3. Ensure model-schema consistency 4. Import schemas into properly typed database tables
- get_associated_models(model_name)[source]
Get list of models that this model has relationships with.
- get_association_table_schema(table_name)[source]
Get the schema definition for an association table.
- Return type:
- initialize_database(database_url, drop_existing=False)[source]
Initialize database with schema using default validator.
- Return type:
- validate_model_data(model_name, data)[source]
Validate data against model schema using default validator.
- Return type:
todowrite.tools
Development and maintenance tools.
Schema Generator
Schema Extractor
Validator Tool
ToDoWrite Schema Validator (tw_validate.py) Validates all YAML files in configs/plans/* against ToDoWrite.schema.json
- class RequirementSpec[source]
Bases:
TypedDictType for a requirement specification.
- title
- description
- priority
- status
- class AcceptanceCriteriaSpec[source]
Bases:
TypedDictType for acceptance criteria specification.
- criteria
- given
- when
- then
- class TaskSpec[source]
Bases:
TypedDictType for a task specification.
- title
- description
- status
- priority
- class SubTaskSpec[source]
Bases:
TypedDictType for a subtask specification.
- title
- description
- status
- parent_task
- class CommandSpec[source]
Bases:
TypedDictType for a command specification.
- command
- description
- parameters
- class PhaseSpec[source]
Bases:
TypedDictType for a phase specification.
- name
- description
- status
- steps
- class StepSpec[source]
Bases:
TypedDictType for a step specification.
- title
- description
- status
- tasks
- class ConceptSpec[source]
Bases:
TypedDictType for a concept specification.
- name
- description
- context
- class ContextSpec[source]
Bases:
TypedDictType for a context specification.
- name
- description
- constraints
- class ConstraintSpec[source]
Bases:
TypedDictType for a constraint specification.
- name
- description
- type
- class InterfaceContractSpec[source]
Bases:
TypedDictType for an interface contract specification.
- name
- interface_type
- methods
- class ToDoWriteYAMLData[source]
Bases:
TypedDictComplete type for ToDoWrite YAML file data structure.
- title
- description
- status
- priority
- requirements
- acceptance_criteria
- tasks
- subtasks
- commands
- phases
- steps
- concepts
- contexts
- constraints
- interface_contracts
- labels
- created_at
- updated_at
- version
- tags
- class JSONSchema[source]
Bases:
TypedDictBase type for JSON Schema definitions.
- type
- properties
- required
- additionalProperties
- ref
- description
- enum
- minimum
- maximum
- pattern
- class ToDoWriteJSONSchema[source]
Bases:
TypedDictType for the complete ToDoWrite JSON schema.
- schema
- id
- title
- description
- type
- properties
- required
- additionalProperties
- class todowriteValidator(schema_path=None)[source]
Bases:
objectSchema validator for ToDoWrite YAML files
- validate_file(file_path, strict=False)[source]
Validate single YAML file against schema
- Return type:
Linting Tool
Tracing Tool
Stub Command Tool
ToDoWrite Command Stub Generator (tw_stub_command.py) Generates executable command stubs from Acceptance Criteria
- class AcceptanceCriteriaSpec[source]
Bases:
TypedDictType for acceptance criteria YAML structure.
- criteria
- given
- when
- then
- ac_ref
- title
- description
- acceptance_criteria_id
- class CommandSpec[source]
Bases:
TypedDictType for command specification.
- command
- ac_ref
- title
- description
- shell_command
- artifacts
- class CommandStubGenerator[source]
Bases:
objectGenerates Command layer stubs from Acceptance Criteria
- generate_command_stub(ac_file)[source]
Generate command stub for single Acceptance Criteria file
- Return type:
- update_ac_children_links(ac_file, cmd_id)[source]
Update Acceptance Criteria file to include command in children links
- Return type:
todowrite.utils
Utility modules:
- find_project_root()[source]
Find the project root (monorepo root) by looking for package structure.
Searches up the directory tree for a directory containing lib_package, cli_package, and web_package subdirectories.
- Return type:
- Returns:
Path to project root directory, or current directory if not found
- get_project_name()[source]
Get the current project name based on project root detection.
- Return type:
- get_project_database_name(environment='development', project_name=None)[source]
Generate a project-specific database name for the given environment.
todowrite.build_system
Build system integration:
- class ValidationResult(is_valid, errors, warnings)[source]
Bases:
objectResult of a validation operation.
- is_valid
- errors
- warnings
- __init__(is_valid, errors, warnings)
- class PackageInfo(name, path, pyproject_path, dist_path)[source]
Bases:
objectInformation about a workspace package.
- name
- path
- pyproject_path
- dist_path
- __init__(name, path, pyproject_path, dist_path)
- class HealthCheckResult(overall_status, checks)[source]
Bases:
objectResult of a workspace health check.
- overall_status
- checks
- __init__(overall_status, checks)
- class BuildSystemValidator[source]
Bases:
ABCAbstract base for build system validators.
- class WorkspaceValidator[source]
Bases:
BuildSystemValidatorValidates UV workspace configuration.
- class VersionValidator[source]
Bases:
BuildSystemValidatorValidates version management configuration.
- class BuildManager(project_root=None)[source]
Bases:
objectManages the unified monorepo build system with clean architecture.
Provides a high-level interface for build operations while maintaining separation of concerns and proper error handling.
- validate_configuration()[source]
Validate that the build system is properly configured.
- Returns:
Detailed validation result
- Return type:
- run_build_script(command)[source]
Run a build script command with proper error handling.
- Parameters:
command (
str) – Command to run (e.g., ‘build’, ‘test’, ‘validate’)- Returns:
Result of the command execution
- Return type:
- Raises:
RuntimeError – If build script not found
- get_workspace_packages()[source]
Get information about workspace packages.
- Return type:
- Returns:
Dict mapping package names to PackageInfo objects
- build_package(package_name)[source]
Build a specific package using hatchling.
- Parameters:
package_name (
str) – Name of package to build- Returns:
Result of build operation
- Return type:
- Raises:
ValueError – If package doesn’t exist
RuntimeError – If build fails
todowrite.version
Version information:
Version information for the ToDoWrite package.