# Diagrams — DD-15: Command Code

## Diagram 1 — The Diff-Driven Taste Loop
```mermaid
flowchart TB
    GEN[Model generates code] --> USER[You accept/reject/edit]
    USER -->|reject or edit| DIFF[Harness computes diff:<br/>generated vs. kept]
    DIFF --> TASTEMD[taste.md<br/>.commandcode/taste/]
    TASTEMD -->|synced to| SERVER[api.commandcode.ai<br/>taste-1 model]
    SERVER -->|shapes next output| GEN
    style TASTEMD fill:#2d2d00,stroke:#8a8a00,color:#d0d000
    style SERVER fill:#15152d,stroke:#20208a,color:#a0a0d0
```
**Reading**: The taste loop is a compounding feedback cycle. Every accept/reject generates a diff → diff becomes a preference → preference shapes future output. The profile persists as Markdown locally and syncs to a hosted model server-side.

## Diagram 2 — Static Memory vs. Learned Memory
```mermaid
flowchart LR
    subgraph STATIC["Static Memory (what you wrote)"]
        AGENTS[AGENTS.md]
        CC[COMMANDCODE.md]
        SESSION[Session state]
    end
    subgraph LEARNED["Learned Memory (what the system inferred)"]
        TASTE[taste.md<br/>diff-driven preferences]
        TSC[taste/typescript/taste.md]
        TARCH[taste/architecture/taste.md]
    end
    STATIC -->|read by model| PROMPT[Prompt assembly]
    LEARNED -->|injected as constraints| PROMPT
    PROMPT --> MODEL[LLM call]
    style LEARNED fill:#2d2d00,stroke:#8a8a00,color:#d0d000
    style STATIC fill:#15152d,stroke:#20208a,color:#a0a0d0
```
**Reading**: Two memory layers. Static = explicit files you wrote. Learned = preferences inferred from your behavior. The learned layer is Command Code's differentiator — no other harness has it.

## Diagram 3 — The Poisoned-Preference Surface
```mermaid
flowchart LR
    INJ[Attacker injects via tool output] --> MODEL[Model writes<br/>'learned' preference]
    MODEL --> TASTE[taste.md]
    TASTE -->|shapes EVERY future output| COMPOUND[Compounding damage:<br/>malicious pattern<br/>influences all code]
    style INJ fill:#2d1515,stroke:#8a2020,color:#d0a0a0
    style TASTE fill:#2d1515,stroke:#8a2020,color:#d0a0a0
    style COMPOUND fill:#2d1515,stroke:#8a2020,color:#d0a0a0
```
**Reading**: Same compounding-poisoning risk as Hermes's skill store (DD-08), applied to preferences. A poisoned preference shapes every future output, not just one response. The defense: harness-managed learning (validate before persist).

## Diagram 4 — Taste Learning Loop (n8n)
```json
{
  "name": "Command Code Taste Loop — DD-15",
  "nodes": [
    { "parameters": { "assignments": { "assignments": [{ "id": "g", "name": "generated_code", "value": "const x = any", "type": "string" },{ "id": "k", "name": "kept_code", "value": "const x: string = getValue()", "type": "string" }]}, "options": {} }, "id": "init", "name": "Signal: accept/reject/edit", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [160, 300], "notesInFlow": true, "notes": "Every accept/reject/edit produces a diff: what the model generated vs. what you kept. This is the learning signal." },
    { "parameters": { "model": "gpt-4o-mini", "messages": "={{ [{role:'system',content:'Based on the correction diffs above, generate deeply personal and opinionated preferences.'},{role:'user',content:'Generated: ' + $json.generated_code + '\\nKept: ' + $json.kept_code}] }}", "options": {} }, "id": "model", "name": "Generate Preference (taste-1)", "type": "@n8n/n8n-nodes-langchain.toolExecuteTool", "typeVersion": 1.1, "position": [400, 300], "notesInFlow": true, "notes": "The taste model takes the diff and produces a preference constraint. Marketing calls this 'meta neuro-symbolic AI with continuous RL.' Verifiable mechanism: diff → preference → Markdown." },
    { "parameters": { "command": "={{ 'echo ' + '\"' + $json.choices[0].message.content + '\"' + ' >> /tmp/taste.md' }}", "executeOnce": true }, "id": "write", "name": "Persist to taste.md", "type": "n8n-nodes-base.executeCommand", "typeVersion": 1, "position": [640, 300], "notesInFlow": true, "notes": "Preference persisted as plain Markdown at .commandcode/taste/taste.md. RISK: model-initiated learning. A poisoned preference compounds — shapes every future output. Defense: validate before persist (Module 4.3)." },
    { "parameters": { "method": "POST", "url": "https://api.commandcode.ai/learn-taste", "sendBody": true, "bodyParameters": { "parameters": [{ "name": "profile", "value": "={{ $json.choices[0].message.content }}" }] }, "options": {} }, "id": "sync", "name": "Sync to Hosted Model", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [880, 300], "notesInFlow": true, "notes": "DATA-EXFILTRATION SURFACE: the preference profile (your coding patterns) leaves your machine by design. The taste-1 model runs server-side." },
    { "parameters": { "content": "={{ JSON.stringify({ result: 'taste updated', next_output: 'shaped by learned preference', surface: 'hosted model sync = pattern exfiltration' }) }}", "options": {} }, "id": "out", "name": "Output", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [1120, 300] }
  ],
  "connections": { "Signal: accept/reject/edit": { "main": [ [ { "node": "Generate Preference (taste-1)", "type": "main", "index": 0 } ] ] }, "Generate Preference (taste-1)": { "main": [ [ { "node": "Persist to taste.md", "type": "main", "index": 0 } ] ] }, "Persist to taste.md": { "main": [ [ { "node": "Sync to Hosted Model", "type": "main", "index": 0 } ] ] }, "Sync to Hosted Model": { "main": [ [ { "node": "Output", "type": "main", "index": 0 } ] ] } },
  "settings": { "executionOrder": "v1" }, "meta": { "templateCreatedBy": "Harness Engineering Master Course — DD-15 Command Code" }
}
```
