feat(llm): add LLM integration module with OpenRouter and Claude Code adapters

Implements markitect/llm/ package with concrete LLMAdapter implementations:
- OpenRouterAdapter: HTTP via urllib with retry/backoff on 429/5xx
- ClaudeCodeAdapter: subprocess-based Claude CLI with stdin piping
- Factory pattern: create_adapter("openrouter") or create_adapter("claude-code")
- API key resolution chain: constructor > env var > project-root key file
- 42 unit tests, 2 integration tests (gated on API key / CLI availability)

Also adds the infospace-with-history example with Wealth of Nations VSM
analysis pipeline, templates, schemas, source chapters, and processed
output for chapters 1-2. process_chapters.py now supports --provider
and --model flags for automatic LLM-driven processing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-11 01:17:58 +01:00
parent 360c3b1de2
commit fecc2fd4fa
82 changed files with 43767 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
# Assess Completeness & Consistency Metrics
You are a quality assurance analyst evaluating the completeness and
consistency of a growing information space that maps classical economics
to the Viable System Model.
## All Chapter Analyses
@{all_analyses}
## VSM Framework Reference
@{vsm_framework}
## Instructions
1. Review all chapter analyses produced so far.
2. Compute the following completeness metrics:
- **VSM Concept Coverage**: Percentage of VSM concepts (S1, S2, S3, S3*, S4, S5,
plus key concepts like recursion, variety, requisite variety, autonomy,
viability, attenuation/amplification, algedonic signals) that have at
least one mapping. List covered and uncovered concepts.
- **Chapter Coverage**: Percentage of source chapters processed.
- **Entity Count**: Total number of distinct economic entities extracted.
- **Mapping Count**: Total number of entity-to-VSM mappings created.
3. Compute the following consistency metrics:
- **Terminology Consistency** (score 0.0-1.0): Whether the same economic
concept is named consistently across all documents. Flag inconsistencies.
- **Cross-reference Integrity** (score 0.0-1.0): Whether all entity references
in mappings point to existing entities. Flag broken references.
- **Schema Compliance** (percentage): Percentage of output documents that
contain all required sections per their respective schemas.
4. Produce a metrics report summarizing the current state of the information space.
## Output Format
Output a single markdown document with sections for each metric category:
Completeness Metrics, Consistency Metrics, and Recommendations.

View File

@@ -0,0 +1,43 @@
# Extract Economic Entities
You are an analytical economist specializing in classical economic theory.
Your task is to extract distinct economic entities from a chapter of
Adam Smith's *The Wealth of Nations*.
## Source Chapter
@{chapter_text}
## Extraction Guidelines
@{extraction_rules}
## VSM Framework Context
Use the following VSM framework as context to guide your extraction.
Prioritize entities that are likely to have clear mappings to VSM concepts,
but do not exclude entities simply because they lack an obvious mapping.
@{vsm_framework}
## Instructions
1. Read the source chapter carefully.
2. Identify all distinct economic concepts, actors, mechanisms, and institutions.
3. For each entity, produce a separate markdown document following the
Economic Entity Schema v1.0.
4. Each entity document must include:
- An H1 heading with the entity name
- A Definition section (20-150 words)
- A Source Chapter section citing the specific chapter
- A Context section describing where in the argument the entity appears
- An Economic Domain section classifying the entity
5. Optionally include Smith's Original Wording (direct quote) and
Modern Interpretation sections.
6. Use neutral, analytical language throughout.
7. Ensure each entity is distinct and self-contained.
## Output Format
Output each entity as a separate markdown document, delimited by
`--- ENTITY: <entity-name> ---` markers.

View File

@@ -0,0 +1,38 @@
# Map Economic Entities to VSM Concepts
You are a systems theorist specializing in Stafford Beer's Viable System Model.
Your task is to map extracted economic entities to VSM concepts.
## Extracted Entities
@{entities}
## VSM Framework Reference
@{vsm_framework}
## Mapping Guidelines
@{mapping_rules}
## Instructions
1. Review each extracted economic entity carefully.
2. For each entity, determine which VSM system(s) it most closely relates to.
3. Produce a mapping document for each entity-VSM relationship following
the VSM Mapping Schema v1.0.
4. Each mapping document must include:
- An H1 heading in the format "Entity Name -> VSM Concept Name"
- An Economic Entity Reference section
- A VSM Concept Reference section
- A Mapping Rationale section (minimum 30 words) grounded in Beer's definitions
- A Mapping Strength section rated as Strong, Moderate, or Weak
5. Where an entity maps to multiple VSM systems (recursion), create
separate mapping documents for each relationship.
6. Flag entities that don't clearly map to any VSM concept with a
"Mapping Strength: Weak" and note the difficulty in the rationale.
## Output Format
Output each mapping as a separate markdown document, delimited by
`--- MAPPING: <entity-name>-to-<vsm-concept> ---` markers.

View File

@@ -0,0 +1,46 @@
# Synthesize Chapter VSM Analysis
You are an interdisciplinary analyst combining classical economics with
cybernetic systems theory. Your task is to produce a comprehensive
chapter-level analysis showing how economic content maps to the
Viable System Model.
## Source Chapter
@{chapter_text}
## Extracted Entities
@{entities}
## VSM Mappings
@{mappings}
## VSM Framework Reference
@{vsm_framework}
## Instructions
1. Review the source chapter, extracted entities, and VSM mappings together.
2. Produce a single chapter analysis document following the
Chapter Analysis Schema v1.0.
3. The analysis must include:
- An H1 heading with the chapter analysis title
- A Chapter Summary (50-300 words) of the main economic arguments
- An Entities Extracted section listing all entities with brief descriptions
- A VSM Mappings section listing all mappings with entity, concept, and strength
- A VSM Coverage section assessing which systems (S1-S5, S3*) are represented
- A Gaps & Observations section identifying uncovered systems and patterns
4. In the VSM Coverage section, explicitly state which systems are
covered and which are not, based on the mappings.
5. In Gaps & Observations, note:
- Which VSM systems lack representation from this chapter
- Entities that were difficult to map
- Emerging themes or patterns
- Suggestions for enriching coverage in future analysis
## Output Format
Output a single markdown document following the Chapter Analysis Schema v1.0.