ADR-026: Cognitive Supply Chain Architecture
Status: Proposed
Version: 1.0
Date: 2025-12-22
Supersedes: N/A
Related ADRs: ADR-012, ADR-025
Related PRDs: N/A
Context
Traditional prompt engineering treats prompts as ephemeral, disposable text. This leads to:
- Prompt Spaghetti: Unstructured, untestable, and unversioned prompts
- Semantic Drift: AI outputs diverging from specifications over time
- Context Explosion: Accumulating errors and hallucinations in long conversations
- Missing Feedback Loops: No mechanism for prompts to learn from execution failures
The SEA™ Forge delivery pipeline requires a systematic approach where:
- Prompts are treated as Source Code (modular, versioned, testable)
- The file system acts as a Semantic State Machine
- Specs (ADR/SDS/PRD) constrain AI behavior deterministically
- Prompts self-evolve based on execution feedback
Decision
SEA™ Forge SHALL implement a Cognitive Supply Chain Architecture where:
- Prompt files are executable SOPs organized in a Work Breakdown Structure (WBS)
- The file structure is the Semantic Router - directory paths define cognitive context
- Prompts are trainable parameters subject to self-grooming and evolution
- Specs are Boundary Conditions that prevent regression to generic patterns
- Backward chains detect drift between code and specifications
Rationale
Core Principles
1. Prompt-as-Function (The Atomic Unit)
Each prompt file is a Serverless Function with:
- Inputs: Explicit context injection (file references)
- Logic: The SOP/instruction set
- Outputs: Structured artifacts (JSON, Code, not chat)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| ---
type: task
domain: backend/auth
dependencies: ["@/docs/schema.md", "@/utils/logger.ts"]
output_format: "code_block_only"
---
# Context
You are a Senior Backend Engineer.
# Objective
Implement the login handler defined in the user stories.
# Constraints
- Must pass the tests in `login.test.ts`
- No external libraries other than those in `package.json`
|
2. File System as DAG (The Semantic Router)
The Work Breakdown Structure maps to a Directed Acyclic Graph of prompts:
1
2
3
4
5
6
7
8
9
| /prompts
/01_requirements
01_user_stories.prompt.md ← Generates: /docs/stories.md
02_acceptance_criteria.prompt.md
/02_architecture
01_system_design.prompt.md ← Reads: /docs/stories.md
02_api_contracts.prompt.md
/03_implementation
01_scaffold_auth.prompt.md ← Reads: /docs/api_contracts.md
|
The directory path IS the context vector. Child nodes inherit parent context.
3. Test-Driven Prompting
Every task prompt MUST be paired with a validation mechanism:
task_X_test.prompt.md: Generates the failing test
task_X_impl.prompt.md: Generates code to pass the test
This enforces the invariant: No code exists without verification.
4. Stateless Execution (The Semantic Firewall)
Each prompt task:
- Opens with a fresh context window
- Reads only explicit dependencies (not chat history)
- Saves structured output to disk
- Severs the associative chain between tasks
This prevents Context Pollution and Hallucination Loops.
The Processing Phases (MECE WBS)
| Phase |
Objective |
TDD State |
Output |
| 1. Case Initialization |
Define the gap |
RED → GREEN → REFACTOR |
PRD + Acceptance Criteria |
| 2. Structural Design |
Define constraints |
RED → GREEN → REFACTOR |
ADR + SDS |
| 3. Construction |
Synthesize logic |
RED → GREEN → REFACTOR |
Verified Source Code |
| 4. Integration |
Assemble system |
RED → GREEN → REFACTOR |
Deployable Artifact |
| 5. Delivery |
Validate in reality |
RED → GREEN → REFACTOR |
Live Feature + Telemetry |
| 6. Feedback |
Close the loop |
RED → GREEN → REFACTOR |
New Case Files (Flywheel) |
Constraints
- MUST treat prompt files as executable SOPs organized in WBS
- MUST use directory structure as semantic router for cognitive context
- MUST pair every task prompt with a validation mechanism
- MUST execute prompts statelessly with explicit dependencies only
- MUST version prompts in Git with full history
- MUST NOT use chat history as implicit context
- MUST NOT allow code without verification
Quality Attributes
- Deterministic AI Behavior: Prompts constrained by specs
- Version-Controlled Intelligence: Prompts in Git with full history
- Self-Improving System: Evolutionary feedback loops
- Zero Translation Loss: Specs → Prompts → Code alignment
- Reproducible Builds: Delete
/src, regenerate from /prompts
Bounded Contexts Impacted
- Prompt Evolution Engine
- Semantic Groomer Service
- Delivery Pipeline
- Cognitive Extension Layer
Consequences
Positive
- Deterministic AI Behavior: Prompts constrained by specs
- Version-Controlled Intelligence: Prompts in Git with full history
- Self-Improving System: Evolutionary feedback loops
- Zero Translation Loss: Specs → Prompts → Code alignment
- Reproducible Builds: Delete
/src, regenerate from /prompts
Negative
- Higher upfront structure investment
- Requires strict file organization discipline
- Prompt file proliferation in large projects
Additional Notes
- SDS-025: Prompt Evolution Engine
- SDS-026: Semantic Groomer Service
- REF-014: Software Engineering WBS Template