Files
markitect-main/migrations/prompts/003_create_runs_and_manifests.sql
tegwick c56c92c815
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / code-quality (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled
feat(prompts): implement Phase 4 - Execution Engine (FR-4, FR-5)
Implement three-stage execution lifecycle with idempotent runs and complete
provenance tracking via RunManifest.

Core Features:
- PromptRun model with execution lifecycle stages:
  1. Analysis: Template analysis and macro extraction
  2. Compilation: Macro resolution and context compilation
  3. Processing: LLM execution and output generation
- InputBundleHash for deterministic idempotency (FR-4.3)
- RunManifest for complete execution provenance (FR-5)
- LLMAdapter interface for pluggable model providers
- MockLLMAdapter for testing without API calls
- PromptExecutionEngine orchestrating full lifecycle

Idempotent Execution (FR-4.4):
- Calculate SHA-256 hash of complete input context
- Skip execution if identical hash exists
- Cache successful runs by hash
- Support force re-execution via config flag

RunManifest Tracking (FR-5.2):
- Template metadata (id, name, digest)
- Resolved input artifacts and digests
- Compiled prompt digest
- Model configuration
- Output artifacts
- Dependency edges for graph construction
- Timing metadata for performance analysis

Tests (27 passing):
- 17 execution model tests (config, bundle, runs, stages)
- 10 engine tests (execution, idempotency, errors, caching)

Implements:
- FR-4.1: Three-stage execution lifecycle
- FR-4.2: CompiledPrompt during compilation
- FR-4.3: InputBundleHash calculation
- FR-4.4: Skip execution for identical hashes
- FR-5.1: RunManifest persistence
- FR-5.2: Complete manifest contents
- FR-5.3: Nested run linking (foundation)

Files Created:
- markitect/prompts/execution/models.py
- markitect/prompts/execution/manifest.py
- markitect/prompts/execution/llm_adapter.py
- markitect/prompts/execution/engine.py
- migrations/prompts/003_create_runs_and_manifests.sql
- tests/unit/prompts/test_execution_models.py
- tests/unit/prompts/test_execution_engine.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 23:15:33 +01:00

72 lines
2.9 KiB
SQL

-- Migration 003: Create prompt runs and manifests tables
-- Implements FR-4: PromptRun Lifecycle and FR-5: RunManifest Persistence
-- Date: 2026-02-08
-- Prompt runs table
CREATE TABLE IF NOT EXISTS prompt_runs (
id TEXT PRIMARY KEY,
template_id TEXT NOT NULL REFERENCES prompt_artifacts(id),
input_bundle_hash TEXT NOT NULL,
status TEXT NOT NULL,
stage TEXT NOT NULL,
parent_run_id TEXT REFERENCES prompt_runs(id),
depth INTEGER DEFAULT 0,
config JSON,
started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
completed_at TIMESTAMP,
error_message TEXT,
metadata JSON
);
-- Run manifests table
CREATE TABLE IF NOT EXISTS run_manifests (
run_id TEXT PRIMARY KEY REFERENCES prompt_runs(id),
template_metadata JSON NOT NULL,
resolved_inputs JSON NOT NULL,
compiled_prompt_digest TEXT NOT NULL,
model_config JSON NOT NULL,
output_artifacts JSON,
dependency_edges JSON,
validation_results JSON,
impact_debt JSON,
timing_metadata JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Indexes for performance
CREATE INDEX IF NOT EXISTS idx_runs_template ON prompt_runs(template_id);
CREATE INDEX IF NOT EXISTS idx_runs_bundle_hash ON prompt_runs(input_bundle_hash);
CREATE INDEX IF NOT EXISTS idx_runs_parent ON prompt_runs(parent_run_id);
CREATE INDEX IF NOT EXISTS idx_runs_status ON prompt_runs(status);
-- Unique constraint for idempotency (FR-4.4)
-- Note: Allows multiple failed runs, but only one successful run per hash
CREATE UNIQUE INDEX IF NOT EXISTS idx_runs_successful_hash
ON prompt_runs(input_bundle_hash)
WHERE status = 'success';
-- Comments (for documentation)
-- prompt_runs.id: Unique UUID for this run
-- prompt_runs.template_id: Template being executed
-- prompt_runs.input_bundle_hash: SHA-256 hash for idempotency
-- prompt_runs.status: pending, running, success, failed, skipped
-- prompt_runs.stage: pending, analysis, compilation, processing, complete, failed
-- prompt_runs.parent_run_id: Parent run for nested generators
-- prompt_runs.depth: Nesting depth (0 for top-level)
-- prompt_runs.config: RunConfig JSON
-- prompt_runs.started_at: Execution start time
-- prompt_runs.completed_at: Execution completion time
-- prompt_runs.error_message: Error message if failed
-- prompt_runs.metadata: Additional metadata
-- run_manifests.run_id: Associated run ID
-- run_manifests.template_metadata: Template info (id, name, digest)
-- run_manifests.resolved_inputs: Array of resolved input artifacts
-- run_manifests.compiled_prompt_digest: Digest of compiled prompt
-- run_manifests.model_config: Model configuration used
-- run_manifests.output_artifacts: Array of produced artifacts
-- run_manifests.dependency_edges: Dependency graph edges
-- run_manifests.validation_results: Quality validation results
-- run_manifests.impact_debt: Suppressed recomputation records
-- run_manifests.timing_metadata: Stage timing information