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,61 @@
---
id: extraction-rules
name: extraction_rules
artifact_type: content
description: Guidelines for extracting economic entities from source text
version: 1.0.0
---
# Entity Extraction Rules
## What Constitutes an Entity
An economic entity is a distinct concept, actor, mechanism, or institution
that plays a functional role in Adam Smith's economic analysis. Extract
entities at the level of specificity where they carry independent meaning.
## Extraction Criteria
1. **Concepts**: Abstract economic ideas (e.g., "division of labour",
"effectual demand", "natural price"). Extract when Smith defines,
explains, or argues about the concept.
2. **Actors**: Economic agents with defined roles (e.g., "the labourer",
"the merchant", "the sovereign"). Extract when the actor performs
a distinct economic function.
3. **Mechanisms**: Processes or dynamics that produce economic effects
(e.g., "accumulation of stock", "market price adjustment",
"foreign trade"). Extract when the mechanism is described as
producing specific outcomes.
4. **Institutions**: Organised structures that shape economic behaviour
(e.g., "the corporation", "the guild", "the joint-stock company").
Extract when the institution's economic function is described.
## Granularity Rules
- Extract at the level of a single coherent concept.
- Do NOT extract synonyms as separate entities — choose the primary term
Smith uses and note variations.
- DO extract distinct aspects of a broad concept as separate entities when
Smith treats them independently (e.g., "wages of labour" and "profits
of stock" are separate from "price of commodities" even though they
compose it).
- If an entity appears across multiple chapters, extract it on first
significant appearance and note cross-references in later chapters.
## Naming Conventions
- Use Smith's own terminology where possible.
- Normalise to lowercase except for proper nouns.
- Use the most common form Smith uses (e.g., "division of labour" not
"divided labour").
## Quality Checks
- Each entity must have a definition that would be comprehensible without
reading the source chapter.
- Each entity must cite the specific book and chapter of first appearance.
- Economic Domain must be one of: Production, Distribution, Exchange,
Consumption, Accumulation, Regulation, or General Theory.

View File

@@ -0,0 +1,75 @@
---
id: mapping-rules
name: mapping_rules
artifact_type: content
description: Guidelines for mapping economic entities to VSM concepts
version: 1.0.0
---
# VSM Mapping Rules
## Mapping Principles
1. **Ground in Beer's definitions.** Every mapping rationale must reference
the specific VSM system function, not just a superficial resemblance.
2. **Prefer structural over metaphorical mappings.** A mapping is strong
when the economic entity performs the same *functional role* in Smith's
economic system as the VSM component performs in an organisation.
3. **Allow multiple mappings.** A single economic entity may map to
multiple VSM systems. For example, "the sovereign" may map to both
S3 (regulation) and S5 (policy). Create separate mapping documents
for each relationship.
4. **Respect recursion.** Consider at which level of recursion the mapping
applies. The division of labour within a single workshop (S1-level)
differs from the division of labour across an entire national economy
(higher recursion level).
## Mapping Strength Criteria
### Strong
- The entity directly performs the function of the VSM system.
- The mapping would be recognisable to a VSM practitioner without explanation.
- Example: "market price mechanism" → S2 (Coordination) — prices coordinate
supply and demand between producers.
### Moderate
- The entity partially performs the function or performs it in a limited context.
- The mapping requires some argument but is defensible.
- Example: "merchant" → S4 (Intelligence) — merchants gather information
about foreign markets, but this is not their primary function.
### Weak
- The mapping is speculative or metaphorical rather than structural.
- The connection exists but requires significant interpretive work.
- Example: "moral sentiments" → S5 (Policy) — broad ethical framework
shapes economic behaviour, but the connection is indirect.
## What NOT to Map
- Do not force mappings where none exist. It is valid for an entity to have
no clear VSM mapping — flag it with "Mapping Strength: Weak" and explain
the difficulty.
- Do not map purely descriptive/historical content that lacks functional
significance.
## VSM System Checklist
When mapping, consider each system:
| System | Question to Ask |
|--------|----------------|
| S1 | Does this entity directly produce value or output? |
| S2 | Does this entity coordinate between operational units? |
| S3 | Does this entity regulate internal operations? |
| S3* | Does this entity provide audit or verification? |
| S4 | Does this entity scan the environment or plan for the future? |
| S5 | Does this entity define identity, policy, or purpose? |
Also consider the key concepts:
- **Recursion**: At what level does this entity operate?
- **Variety**: Does this entity manage variety (attenuate or amplify)?
- **Algedonic signals**: Does this entity serve as an emergency signal?
- **Autonomy**: Does this entity relate to operational autonomy?