bookworm-smart-assistant/docs/bookworm-v5.7-architecture.html

958 lines
32 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bookworm v5.7 — 技术架构总览</title>
<style>
:root {
--bg: #0d1117;
--card: #161b22;
--border: #30363d;
--text: #e6edf3;
--text-muted: #8b949e;
--accent: #58a6ff;
--accent2: #7ee787;
--accent3: #d2a8ff;
--accent4: #ffa657;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.6;
}
.header {
text-align: center;
padding: 48px 24px 32px;
background: linear-gradient(135deg, #0d1117 0%, #161b22 50%, #1a1a2e 100%);
border-bottom: 1px solid var(--border);
}
.header h1 { font-size: 2.2rem; margin-bottom: 8px; }
.header .version { color: var(--accent); font-size: 1.1rem; }
.header .meta { color: var(--text-muted); font-size: 0.9rem; margin-top: 12px; }
.header .badges {
display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; margin-top: 16px;
}
.badge {
display: inline-flex; align-items: center; gap: 6px;
padding: 6px 14px; border-radius: 20px; font-size: 0.85rem; font-weight: 600;
}
.badge-blue { background: rgba(88,166,255,0.15); color: var(--accent); border: 1px solid rgba(88,166,255,0.3); }
.badge-green { background: rgba(126,231,135,0.15); color: var(--accent2); border: 1px solid rgba(126,231,135,0.3); }
.badge-purple { background: rgba(210,168,255,0.15); color: var(--accent3); border: 1px solid rgba(210,168,255,0.3); }
.badge-orange { background: rgba(255,166,87,0.15); color: var(--accent4); border: 1px solid rgba(255,166,87,0.3); }
.container { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }
.toc {
background: var(--card); border: 1px solid var(--border); border-radius: 12px;
padding: 24px 32px; margin-bottom: 40px;
}
.toc h2 { font-size: 1.2rem; margin-bottom: 12px; color: var(--accent); }
.toc-grid {
display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 6px 24px;
}
.toc a {
color: var(--text); text-decoration: none; font-size: 0.9rem; padding: 4px 0;
display: block; transition: color 0.2s;
}
.toc a:hover { color: var(--accent); }
.toc .num { color: var(--text-muted); margin-right: 8px; font-weight: 600; }
.diagram-section {
background: var(--card); border: 1px solid var(--border); border-radius: 12px;
margin-bottom: 32px; overflow: hidden;
}
.diagram-header {
padding: 20px 24px; border-bottom: 1px solid var(--border);
display: flex; align-items: center; gap: 12px;
}
.diagram-header .num {
width: 36px; height: 36px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
font-weight: 700; font-size: 0.9rem;
}
.diagram-header h2 { font-size: 1.15rem; }
.diagram-header .tag {
font-size: 0.75rem; padding: 2px 10px; border-radius: 12px;
background: rgba(88,166,255,0.15); color: var(--accent); margin-left: auto;
}
.diagram-body {
padding: 32px 24px; display: flex; justify-content: center;
overflow-x: auto; min-height: 200px;
}
.diagram-body .mermaid { width: 100%; max-width: 100%; }
.summary-table {
background: var(--card); border: 1px solid var(--border); border-radius: 12px;
padding: 24px; margin-top: 40px;
}
.summary-table h2 { font-size: 1.2rem; margin-bottom: 16px; color: var(--accent); }
.summary-table table { width: 100%; border-collapse: collapse; }
.summary-table th, .summary-table td {
padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border);
font-size: 0.9rem;
}
.summary-table th { color: var(--text-muted); font-weight: 600; }
.footer {
text-align: center; padding: 32px; color: var(--text-muted); font-size: 0.85rem;
}
@media (max-width: 768px) {
.header h1 { font-size: 1.5rem; }
.toc-grid { grid-template-columns: 1fr; }
.diagram-body { padding: 16px; }
}
</style>
</head>
<body>
<div class="header">
<h1>Bookworm Smart Assistant</h1>
<div class="version">v5.7 — Neural Gateway Architecture</div>
<div class="meta">14 Technical Architecture Diagrams | Generated 2026-03-02</div>
<div class="badges">
<span class="badge badge-blue">Skills: 52</span>
<span class="badge badge-green">Agents: 10</span>
<span class="badge badge-purple">Hooks: 17</span>
<span class="badge badge-orange">MCP: 22+3</span>
</div>
</div>
<div class="container">
<div class="toc">
<h2>INDEX</h2>
<div class="toc-grid">
<a href="#d1"><span class="num">01</span>System Overview</a>
<a href="#d2"><span class="num">02</span>Route Engine Pipeline</a>
<a href="#d3"><span class="num">03</span>Skill Panorama (52)</a>
<a href="#d4"><span class="num">04</span>Agent Orchestration (10)</a>
<a href="#d5"><span class="num">05</span>Hook Lifecycle (17)</a>
<a href="#d6"><span class="num">06</span>MCP 3-Tier Ecosystem</a>
<a href="#d7"><span class="num">07</span>Self-Evolution Loop</a>
<a href="#d8"><span class="num">08</span>Data Flow & File Topology</a>
<a href="#d9"><span class="num">09</span>Request Lifecycle (Sequence)</a>
<a href="#d10"><span class="num">10</span>Security Defense-in-Depth</a>
<a href="#d11"><span class="num">11</span>Adaptive Learning Loop</a>
<a href="#d12"><span class="num">12</span>Health Score Model (10D)</a>
<a href="#d13"><span class="num">13</span>Production Deployment</a>
<a href="#d14"><span class="num">14</span>Version Timeline</a>
</div>
</div>
<!-- Diagram 1 -->
<div class="diagram-section" id="d1">
<div class="diagram-header">
<div class="num" style="background:rgba(88,166,255,0.2);color:var(--accent);">1</div>
<h2>System Overview</h2>
<span class="tag">graph TB</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
graph TB
subgraph USER["User Layer"]
Input["User Input"]
SlashCmd["/skill-name"]
end
subgraph GATEWAY["Neural Gateway v5.7"]
direction TB
Hook1["route-interceptor"]
Tokenizer["Tokenize + Synonym Expand\n22 groups"]
BM25["BM25 + TF-IDF\n3-tier keywords"]
ContextFusion["Context Fusion\nBM25*0.6 + Session*0.2\n+ Project*0.1 + Workflow*0.1"]
Disambig["Disambiguation\n31 JSON rules"]
BWR["BWR Directive Inject"]
end
subgraph COMPLIANCE["Compliance Gate"]
PreTool["route-compliance-gate\n(PreToolUse:Skill)"]
PostAudit["route-auditor\n(Stop)"]
end
subgraph SKILLS["Skills (52)"]
direction LR
S_AI["AI/Data (3)"]
S_DEV["Dev (12)"]
S_ARCH["Arch (8)"]
S_OPS["DevOps (4)"]
S_SEC["Security (1)"]
S_QA["Quality (3)"]
S_PROD["Product (4)"]
S_BIZ["Business (9)"]
S_CONTENT["Content (5)"]
S_META["Meta (3)"]
end
subgraph AGENTS["Agents (10)"]
direction LR
A_OPUS["Opus (2)\norchestrator\ncode-reviewer"]
A_SONNET["Sonnet (8)\nresearch-analyst | full-stack-builder\nquality-gate | self-auditor\nself-healer | canvas-ui-designer\ntest-writer | pre-deploy-checker"]
end
subgraph MCP_LAYER["MCP Ecosystem (22+3)"]
direction LR
MCP_LOCAL["Local (12)"]
MCP_CLOUD["Cloud (9)"]
MCP_PLUGIN["Plugin (1)"]
MCP_ONDEMAND["On-demand (3)"]
end
subgraph EVOLUTION["Self-Evolution"]
direction LR
DriftDetect["drift-detector"]
Auditor["self-auditor\n8-dim audit"]
Healer["self-healer\nmetadata fix"]
EvoLog["evolution-log\n18 seq"]
end
Input --> Hook1
SlashCmd -.->|"Priority 1"| SKILLS
Hook1 --> Tokenizer --> BM25 --> ContextFusion --> Disambig --> BWR
BWR -->|"BWR directive"| PreTool
PreTool -->|"PASS"| SKILLS
SKILLS --> PostAudit
SKILLS -.->|"complex"| AGENTS
AGENTS --> MCP_LAYER
SKILLS --> MCP_LAYER
PostAudit -->|"feedback"| EVOLUTION
DriftDetect --> Auditor --> Healer --> EvoLog
EvoLog -.->|"weight learning"| BM25
style GATEWAY fill:#1a1a2e,color:#e0e0ff,stroke:#4a4aff
style COMPLIANCE fill:#2d1b2e,color:#ffccff,stroke:#aa44aa
style SKILLS fill:#1b2e1b,color:#ccffcc,stroke:#44aa44
style AGENTS fill:#2e2e1b,color:#ffffcc,stroke:#aaaa44
style MCP_LAYER fill:#1b2e2e,color:#ccffff,stroke:#44aaaa
style EVOLUTION fill:#2e1b1b,color:#ffcccc,stroke:#aa4444
</pre>
</div>
</div>
<!-- Diagram 2 -->
<div class="diagram-section" id="d2">
<div class="diagram-header">
<div class="num" style="background:rgba(126,231,135,0.2);color:var(--accent2);">2</div>
<h2>Route Engine Pipeline</h2>
<span class="tag">flowchart LR</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
flowchart LR
subgraph INPUT["Input"]
Raw["Raw Input"]
Seg["Tokenize"]
Syn["Synonym Expand\n22 groups"]
end
subgraph SCORING["Scoring"]
BM25["BM25\nk1=1.2, b=0.75"]
TF["TF-IDF\ncore/strong/extended"]
CTX["Context Fusion\nwindow=10, decay=0.85"]
PRJ["Project Detect\n9 types"]
WF["Workflow n-gram"]
end
subgraph DECISION["Decision"]
Fusion["Score Fusion\nBM25x0.6+CTXx0.2\n+PRJx0.1+WFx0.1"]
Disamb["Disambiguation\n31 rules"]
Chain["Skill Chain\ncomposable graph"]
Confidence{"Confidence?"}
end
subgraph OUTPUT["Output"]
HIGH["HIGH gte 0.8\nDirect Route"]
MED["MED 0.5-0.8\nRoute + Hints"]
LOW["LOW lt 0.5\ndeveloper-expert"]
end
Raw --> Seg --> Syn
Syn --> BM25
BM25 --> TF --> Fusion
CTX --> Fusion
PRJ --> Fusion
WF --> Fusion
Fusion --> Disamb --> Chain --> Confidence
Confidence -->|"gte 0.8"| HIGH
Confidence -->|"0.5~0.8"| MED
Confidence -->|"lt 0.5"| LOW
</pre>
</div>
</div>
<!-- Diagram 3 -->
<div class="diagram-section" id="d3">
<div class="diagram-header">
<div class="num" style="background:rgba(210,168,255,0.2);color:var(--accent3);">3</div>
<h2>Skill Panorama (52 Skills x 10 Categories)</h2>
<span class="tag">mindmap</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
mindmap
root((Bookworm v5.7\n52 Skills))
AI / Data 3
ai-ml-expert
data-analyst-expert
data-engineer-expert
Dev 12
frontend-expert
backend-builder
mobile-expert
miniprogram-expert
developer-expert
debugger-expert
api-integration-specialist
regex-shell-wizard
ultimate-code-expert
browser-automation-expert
workflow-automation-expert
notification-system-expert
Architecture 8
architect-expert
database-tuning-expert
cloud-native-expert
edge-computing-expert
performance-expert
impact-analyst
diagram-as-code-expert
zero-defect-guardian
DevOps 4
devops-expert
devsecops-expert
git-operation-master
sre-expert
Security 1
security-expert
Quality 3
tester-expert
reviewer-expert
project-audit-expert
Product 4
product-manager-expert
designer-expert
ux-researcher
project-coordinator
Business 9
business-plan-skill
finance-advisor
sales-consultant
pricing-strategist
customer-success-expert
growth-hacker
investor-review-guide
industry-research-cn
legal-review-skill
Content 5
tech-writer-expert
copywriter-expert
email-communicator
social-media-manager
technical-seo-expert
Meta 3
genesis-engine
prompt-optimizer
tech-lead-mentor
</pre>
</div>
</div>
<!-- Diagram 4 -->
<div class="diagram-section" id="d4">
<div class="diagram-header">
<div class="num" style="background:rgba(255,166,87,0.2);color:var(--accent4);">4</div>
<h2>Agent Orchestration (10 Agents)</h2>
<span class="tag">graph TB</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
graph TB
subgraph OPUS["Opus (2)"]
ORC["orchestrator\nDecompose - Schedule - Verify"]
CR["code-reviewer\nMulti-dim Review"]
end
subgraph SONNET_C["Sonnet Compound (3)"]
RA["research-analyst\nExplore + Research"]
FSB["full-stack-builder\nFront+Back+DB E2E"]
QG["quality-gate\nPASS / BLOCKED"]
end
subgraph SONNET_S["Sonnet Specialist (3)"]
CUD["canvas-ui-designer\nHi-fi UI/UX"]
TW["test-writer\nAuto Test Gen"]
PDC["pre-deploy-checker\nDeploy Safety"]
end
subgraph SONNET_M["Sonnet Meta (2)"]
SA["self-auditor\n8-dim Audit"]
SH["self-healer\nDrift Fix"]
end
ORC -->|"research"| RA
ORC -->|"implement"| FSB
ORC -->|"review"| CR
ORC -->|"verify"| QG
FSB -.->|"after impl"| TW
TW -.->|"tests pass"| PDC
SA -->|"audit report"| SH
SH -.->|"after fix"| SA
style OPUS fill:#4a1942,color:#ffccff,stroke:#aa44aa
style SONNET_C fill:#1a3a1a,color:#ccffcc,stroke:#44aa44
style SONNET_S fill:#1a2a3a,color:#cce0ff,stroke:#4488cc
style SONNET_M fill:#3a2a1a,color:#ffe0cc,stroke:#cc8844
</pre>
</div>
</div>
<!-- Diagram 5 -->
<div class="diagram-section" id="d5">
<div class="diagram-header">
<div class="num" style="background:rgba(88,166,255,0.2);color:var(--accent);">5</div>
<h2>Hook Lifecycle (17 Hooks)</h2>
<span class="tag">flowchart TB</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
flowchart TB
subgraph SUBMIT["UserPromptSubmit (1)"]
H1["route-interceptor\nNeural Gateway"]
end
subgraph PRE["PreToolUse (5)"]
H2["block-sensitive-files\nWrite/Edit"]
H3["block-dangerous-commands\nBash"]
H4["commit-message-lint\ngit commit"]
H5["code-quality-gate\nBash"]
H6["route-compliance-gate\nSkill"]
end
subgraph POST["PostToolUse (4 main + 4 sub)"]
H7["post-edit-dispatcher\nParallel Dispatch"]
H7a["check-typescript"]
H7b["check-lint"]
H7c["suggest-tests"]
H7d["drift-detector\n+ integrity-check"]
H8["build-outcome-tracker"]
H9["post-edit-quality-check"]
H10["activity-logger"]
end
subgraph OTHER["SubagentStart / Stop (2)"]
H11["subagent-route-injector"]
H12["route-auditor\nE2E Audit"]
end
H1 -->|"BWR"| PRE
PRE -->|"PASS"| POST
H7 --> H7a & H7b & H7c & H7d
POST --> OTHER
H12 -.->|"feedback"| H1
style SUBMIT fill:#2a1a3a,color:#e0ccff,stroke:#8844cc
style PRE fill:#3a1a1a,color:#ffcccc,stroke:#cc4444
style POST fill:#1a3a2a,color:#ccffe0,stroke:#44cc88
style OTHER fill:#1a2a3a,color:#cce0ff,stroke:#4488cc
</pre>
</div>
</div>
<!-- Diagram 6 -->
<div class="diagram-section" id="d6">
<div class="diagram-header">
<div class="num" style="background:rgba(126,231,135,0.2);color:var(--accent2);">6</div>
<h2>MCP 3-Tier Ecosystem</h2>
<span class="tag">graph LR</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
graph LR
subgraph T1["Tier 1 - Local (12)"]
direction TB
subgraph T1A["AI/Research"]
DR["deep-research"]
C7["context7"]
ST["sequential-thinking"]
end
subgraph T1B["Browser"]
PW["playwright"]
CD["chrome-devtools"]
BB["browserbase"]
end
subgraph T1C["Device"]
MB["mobile"]
end
subgraph T1D["SaaS"]
GH["github"]
SK["slack"]
LN["linear"]
AT["atlassian"]
SB["supabase"]
end
end
subgraph T2["Tier 2 - Cloud (9)"]
direction TB
SE["sentry"]
FG["figma"]
NO["notion"]
GA["gamma"]
CA["canva"]
VE["vercel"]
CL["cloudinary"]
SGW["scholar-gateway"]
GP["graphos"]
end
subgraph T3["Tier 3 - Plugin + On-demand (1+3)"]
direction TB
FB["firebase"]
PG["postgres"]
RD["redis"]
K8["kubernetes"]
end
T1 ---|"always on"| CORE["Claude Code\nRuntime"]
T2 ---|"deferred tools"| CORE
T3 ---|"manual install"| CORE
style T1 fill:#1a2e2e,color:#ccffff,stroke:#44aaaa
style T2 fill:#2e2e1b,color:#ffffcc,stroke:#aaaa44
style T3 fill:#2e1b2e,color:#ffccff,stroke:#aa44aa
</pre>
</div>
</div>
<!-- Diagram 7 -->
<div class="diagram-section" id="d7">
<div class="diagram-header">
<div class="num" style="background:rgba(210,168,255,0.2);color:var(--accent3);">7</div>
<h2>Self-Evolution Loop</h2>
<span class="tag">flowchart LR</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
flowchart LR
subgraph TRIGGER["Trigger"]
Edit["File Edit"]
Session["Session End"]
end
subgraph DETECT["Detection"]
Drift["drift-detector"]
Integrity["integrity-check\nSHA256 x 24"]
end
subgraph AUDIT["Audit - 10 Dimensions"]
H1a["H1 Config 13%"]
H2a["H2 Baseline 13%"]
H3a["H3 Disk 10%"]
H4a["H4 Hooks 13%"]
H5a["H5 Skills 9%"]
H6a["H6 Rules 9%"]
H7a["H7 Accuracy 13%"]
H8a["H8 Learning 10%"]
H9a["H9 Compliance 10%"]
H10a["H10 Hook Eff. 9%"]
end
subgraph HEAL["Healing"]
SelfHeal["self-healer\nmetadata only"]
Actions["Version Sync\nCount Fix\nRegistry Fix"]
end
subgraph LOG["Logging"]
EvoLog["evolution-log\n18 seq"]
Weights["route-weights\nlimit pm 0.5"]
Feedback["route-feedback"]
end
Edit --> Drift --> Integrity
Session --> AUDIT
Integrity --> AUDIT
AUDIT -->|"CRITICAL/WARN"| SelfHeal
SelfHeal --> Actions --> EvoLog
AUDIT --> Weights
AUDIT --> Feedback
Feedback -.->|"adaptive learning\n5-day half-life"| Weights
</pre>
</div>
</div>
<!-- Diagram 8 -->
<div class="diagram-section" id="d8">
<div class="diagram-header">
<div class="num" style="background:rgba(255,166,87,0.2);color:var(--accent4);">8</div>
<h2>Data Flow & File Topology</h2>
<span class="tag">graph TB</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
graph TB
subgraph CONFIG["Config Layer (Source of Truth)"]
CLAUDE["CLAUDE.md"]
SKILL_MD["skills/*/SKILL.md x52"]
AGENT_MD["agents/*.md x10"]
SETTINGS["settings.json"]
end
subgraph COMPILED["Compiled Artifacts"]
INDEX["skills-index.json\n52 x 2573 keywords"]
STATS["stats-compiled.json"]
RULES["rules-compiled.json"]
DISAMB["disambiguation-rules.json\n31 rules"]
SYNS["synonyms.json\n22 groups"]
CHECKSUMS["checksums.json\n24 files SHA256"]
end
subgraph RUNTIME["Runtime Data"]
RF["route-feedback.jsonl"]
RW["route-weights.json"]
AL["activity-log.jsonl"]
EL["evolution-log.jsonl"]
SM["session-memory.json"]
end
subgraph SCRIPTS["Script Engine (46)"]
RA2["route-analyzer.js"]
TF2["tfidf-engine.js"]
SE2["synonym-expander.js"]
CT2["context-tracker.js"]
PD2["project-detector.js"]
WP2["workflow-patterns.js"]
SCR["skill-chain-recommender.js"]
GEN["generate-skill-index.js"]
end
SKILL_MD -->|"extract"| GEN --> INDEX
INDEX --> RA2
SYNS --> SE2 --> RA2
RA2 --> TF2
CT2 --> RA2
PD2 --> RA2
WP2 --> RA2
DISAMB --> RA2
RA2 -->|"scores"| RF
RF -->|"learn"| RW
SETTINGS -->|"register"| COMPILED
CLAUDE --> STATS
AGENT_MD --> STATS
style CONFIG fill:#1a1a2e,color:#e0e0ff,stroke:#4a4aff
style COMPILED fill:#2e2e1b,color:#ffffcc,stroke:#aaaa44
style RUNTIME fill:#1b2e1b,color:#ccffcc,stroke:#44aa44
style SCRIPTS fill:#2e1b2e,color:#ffccff,stroke:#aa44aa
</pre>
</div>
</div>
<!-- Diagram 9 -->
<div class="diagram-section" id="d9">
<div class="diagram-header">
<div class="num" style="background:rgba(88,166,255,0.2);color:var(--accent);">9</div>
<h2>Request Lifecycle (Sequence)</h2>
<span class="tag">sequenceDiagram</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
sequenceDiagram
actor U as User
participant HK1 as route-interceptor
participant RE as Route Engine
participant HK2 as compliance-gate
participant SK as Skill
participant HK3 as post-edit-dispatcher
participant SUB as sub-hooks x4
participant HK4 as activity-logger
participant HK5 as route-auditor
U->>HK1: Input text
HK1->>RE: Tokenize + Synonym expand
RE->>RE: BM25 + TF-IDF score
RE->>RE: Context fusion (0.6+0.2+0.1+0.1)
RE->>RE: Disambiguate (31 rules)
RE-->>HK1: BWR directive
HK1-->>U: additionalContext inject
U->>HK2: Call Skill
HK2->>HK2: Validate BWR match
alt Compliant
HK2-->>SK: PASS
else Violation
HK2-->>U: BLOCKED + suggestion
end
SK->>SK: Execute skill logic
SK->>HK3: Edit/Write trigger
par Parallel Dispatch
HK3->>SUB: check-typescript
HK3->>SUB: check-lint
HK3->>SUB: suggest-tests
HK3->>SUB: drift-detector + integrity
end
SK->>HK4: Activity log (JSONL)
Note over U,HK5: Session End
HK5->>HK5: E2E route audit
HK5->>HK5: actualSkill feedback
HK5-->>RE: route-feedback.jsonl
</pre>
</div>
</div>
<!-- Diagram 10 -->
<div class="diagram-section" id="d10">
<div class="diagram-header">
<div class="num" style="background:rgba(126,231,135,0.2);color:var(--accent2);">10</div>
<h2>Security Defense-in-Depth</h2>
<span class="tag">graph TB</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
graph TB
subgraph L1["Layer 1 - Input Defense (PreToolUse)"]
B1["block-sensitive-files\n.env / credentials"]
B2["block-dangerous-commands\nrm -rf / DROP TABLE"]
B3["commit-message-lint"]
B4["code-quality-gate"]
B5["route-compliance-gate\nBWR validation"]
end
subgraph L2["Layer 2 - Execution Defense (PostToolUse)"]
P1["post-edit-quality-check\nAnti-pattern scan"]
P2["integrity-check\nSHA256 x 24 files"]
P3["drift-detector\nReal-time drift"]
P4["build-outcome-tracker\nSuccess rate"]
end
subgraph L3["Layer 3 - Audit Defense (Stop + Meta)"]
A1["route-auditor\nE2E audit + compliance"]
A2["self-auditor\n10-dim health check"]
A3["activity-logger\nFull JSONL trail"]
end
subgraph SAFEGUARD["Safety Constraints"]
SG1["self-healer: metadata only\nno business logic"]
SG2["Weight clamp +/-0.5\nwhitelist + holdout"]
SG3["Checksums HMAC\ntamper-proof"]
end
L1 -->|"pass"| L2
L2 -->|"pass"| L3
L3 -.->|"CRITICAL/WARNING"| SAFEGUARD
style L1 fill:#3a1a1a,color:#ffcccc,stroke:#cc4444
style L2 fill:#3a2a1a,color:#ffe0cc,stroke:#cc8844
style L3 fill:#1a2a3a,color:#cce0ff,stroke:#4488cc
style SAFEGUARD fill:#1a3a1a,color:#ccffcc,stroke:#44aa44
</pre>
</div>
</div>
<!-- Diagram 11 -->
<div class="diagram-section" id="d11">
<div class="diagram-header">
<div class="num" style="background:rgba(210,168,255,0.2);color:var(--accent3);">11</div>
<h2>Adaptive Learning Loop</h2>
<span class="tag">flowchart TB</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
flowchart TB
subgraph COLLECT["Data Collection"]
Explicit["Explicit Feedback\nUser route corrections"]
Implicit["Implicit Feedback\n5-min post-route usage"]
ComplianceD["Compliance Log\ngate-pass / blocked"]
Build["Build Results\nsuccess / fail / timeout"]
end
subgraph LEARN["Learning Engine"]
Decay["Exponential Decay\nhalf-life 5 days"]
Whitelist["Whitelist Validation\nregistered skills only"]
Clamp["Weight Clamp\n-0.5 to +0.5"]
Holdout["Holdout Validation\n20% reserved"]
Snapshot["Weight Snapshot\nrollback protection"]
end
subgraph APPLY["Application"]
Weights["route-weights.json\nweight delta"]
Index["skills-index.json\n2573 keywords"]
BM25["BM25 Scoring\nbase + learned delta"]
end
subgraph MONITOR["Monitoring"]
H7M["H7 Route Accuracy 13%"]
H8M["H8 Learning Convergence 10%"]
Stale["Stale Detection\nexpired data alert"]
end
Explicit --> Decay
Implicit --> Decay
Decay --> Whitelist --> Clamp --> Holdout
Holdout -->|"validated"| Weights
Holdout -->|"failed"| Snapshot -->|"rollback"| Weights
Weights --> BM25
Index --> BM25
ComplianceD --> H7M
Build --> H8M
H7M --> Stale
H8M --> Stale
style COLLECT fill:#2e1b2e,color:#ffccff,stroke:#aa44aa
style LEARN fill:#1a2e2e,color:#ccffff,stroke:#44aaaa
style APPLY fill:#1b2e1b,color:#ccffcc,stroke:#44aa44
style MONITOR fill:#2e2e1b,color:#ffffcc,stroke:#aaaa44
</pre>
</div>
</div>
<!-- Diagram 12 -->
<div class="diagram-section" id="d12">
<div class="diagram-header">
<div class="num" style="background:rgba(255,166,87,0.2);color:var(--accent4);">12</div>
<h2>Health Score Model (10 Dimensions)</h2>
<span class="tag">pie + graph</span>
</div>
<div class="diagram-body" style="flex-direction:column;align-items:center;gap:32px;">
<pre class="mermaid">
pie title Health Score Weight Distribution (100%)
"H1 Config Consistency" : 13
"H2 Behavior Baseline" : 13
"H3 Disk Health" : 10
"H4 Hook Integrity" : 13
"H5 Skill Index" : 9
"H6 Rule Cache" : 9
"H7 Route Accuracy" : 13
"H8 Learning Convergence" : 10
"H9 Route Compliance" : 10
"H10 Hook Effectiveness" : 9
</pre>
<pre class="mermaid">
graph LR
subgraph STATIC["Static Checks (54%)"]
H1["H1 Config 13%"]
H4["H4 Hooks 13%"]
H5["H5 Skills 9%"]
H6["H6 Rules 9%"]
H10["H10 Hook Eff. 9%"]
end
subgraph DYNAMIC["Dynamic Analysis (36%)"]
H2["H2 Baseline 13%\nIQR + Z-score"]
H7["H7 Accuracy 13%"]
H8["H8 Learning 10%"]
end
subgraph INFRA["Infrastructure (10%)"]
H3["H3 Disk 10%"]
end
subgraph COMP["Compliance (10%)"]
H9["H9 Compliance 10%"]
end
subgraph TUNE["Self-Tuning"]
EWMA["EWMA Threshold"]
TREND["Trend Prediction"]
WOPT["Weight Auto-Opt"]
end
STATIC --> TUNE
DYNAMIC --> TUNE
INFRA --> TUNE
COMP --> TUNE
TUNE -->|"aggregate"| SCORE["Health: 0-100"]
style STATIC fill:#1a2a3a,color:#cce0ff,stroke:#4488cc
style DYNAMIC fill:#2e1b2e,color:#ffccff,stroke:#aa44aa
style INFRA fill:#1a3a1a,color:#ccffcc,stroke:#44aa44
style COMP fill:#3a2a1a,color:#ffe0cc,stroke:#cc8844
</pre>
</div>
</div>
<!-- Diagram 13 -->
<div class="diagram-section" id="d13">
<div class="diagram-header">
<div class="num" style="background:rgba(88,166,255,0.2);color:var(--accent);">13</div>
<h2>Production Deployment</h2>
<span class="tag">graph TB</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
graph TB
subgraph CLIENT["Clients"]
EXT["Chrome Extension"]
WEB["Web Dashboard\n:3005"]
end
subgraph HOST["Server <SERVER_A_IP>"]
subgraph DOCKER["Docker Compose"]
API["FastAPI\n:8002 - :8000"]
PG["PostgreSQL"]
REDIS["Redis"]
end
subgraph OBSERVE["Observability"]
PROM["Prometheus\n:9091"]
GRAF["Grafana\n:3101"]
JAEGER["Jaeger\n:16686 + :4317"]
end
end
subgraph EXTERNAL["External"]
XY["Xianyu WS"]
LLM["LLM API"]
end
EXT -->|"WebSocket"| API
WEB -->|"HTTP REST"| API
API --> PG
API --> REDIS
API -->|"WS dual-path"| XY
API -->|"AI reply gen"| LLM
API -->|"OTel gRPC"| JAEGER
PROM -->|"scrape"| API
GRAF -->|"query"| PROM
GRAF -->|"trace"| JAEGER
style CLIENT fill:#2e2e1b,color:#ffffcc,stroke:#aaaa44
style DOCKER fill:#1a2e2e,color:#ccffff,stroke:#44aaaa
style OBSERVE fill:#1b2e1b,color:#ccffcc,stroke:#44aa44
style EXTERNAL fill:#2e1b2e,color:#ffccff,stroke:#aa44aa
</pre>
</div>
</div>
<!-- Diagram 14 -->
<div class="diagram-section" id="d14">
<div class="diagram-header">
<div class="num" style="background:rgba(126,231,135,0.2);color:var(--accent2);">14</div>
<h2>Version Timeline</h2>
<span class="tag">timeline</span>
</div>
<div class="diagram-body">
<pre class="mermaid">
timeline
title Bookworm Evolution (v5.4 - v5.7)
section v5.4 (Feb 23-24)
seq 1-3 : 3-Layer Defense + Disambiguation (18 rules)
: Learning Safety (whitelist + snapshot + holdout)
: Keyword Gap Detection + Health Trends
section v5.5 (Feb 26 - Mar 01)
seq 4-13 : Dispatcher delegation pattern
: Disambiguation externalized (22 rules JSON)
: H9/H10 scoring fix
: 1320 tests all green
section v5.6 (Mar 01)
seq 14-17 : actualSkill compliance loop
: detectPipeline detection
: Framework summary detection (12)
: 27 disambiguation rules
section v5.7 (Mar 01-02)
seq 18 : MCP 3-tier ecosystem 13 to 22
: Skills 50 to 52
: Disambiguation 28 to 31
: Route accuracy 98%
</pre>
</div>
</div>
<!-- Summary Table -->
<div class="summary-table">
<h2>Key Metrics Summary</h2>
<table>
<thead>
<tr><th>Dimension</th><th>Count</th><th>Notes</th></tr>
</thead>
<tbody>
<tr><td>Skills</td><td>52</td><td>10 categories, all stable, 22 composable</td></tr>
<tr><td>Agents</td><td>10</td><td>2 opus + 8 sonnet</td></tr>
<tr><td>Hooks</td><td>17</td><td>13 registered + 4 sub-hooks</td></tr>
<tr><td>MCP</td><td>22+3</td><td>12 local + 9 cloud + 1 plugin + 3 on-demand</td></tr>
<tr><td>Scripts</td><td>46</td><td>45 .js + 1 .py</td></tr>
<tr><td>Disambiguation</td><td>31</td><td>JSON externalized rules</td></tr>
<tr><td>Synonyms</td><td>22</td><td>Dictionary expansion groups</td></tr>
<tr><td>Keywords</td><td>2573</td><td>core / strong / extended 3-tier</td></tr>
<tr><td>Health Dims</td><td>10</td><td>Auto-tuning weights + EWMA</td></tr>
<tr><td>Evolution</td><td>18 seq</td><td>v5.4 - v5.5 - v5.6 - v5.7</td></tr>
<tr><td>Route Accuracy</td><td>98%</td><td>With A/B experiment framework</td></tr>
</tbody>
</table>
</div>
</div>
<div class="footer">
Bookworm Smart Assistant v5.7 | Neural Gateway Architecture | 2026-03-02
</div>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
mermaid.initialize({
startOnLoad: true,
theme: 'dark',
themeVariables: {
darkMode: true,
background: '#161b22',
primaryColor: '#1f6feb',
primaryTextColor: '#e6edf3',
primaryBorderColor: '#30363d',
lineColor: '#8b949e',
secondaryColor: '#21262d',
tertiaryColor: '#161b22',
fontFamily: '-apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif',
},
flowchart: { useMaxWidth: true, htmlLabels: true, curve: 'basis' },
sequence: { useMaxWidth: true, actorMargin: 80 },
mindmap: { useMaxWidth: true },
pie: { useMaxWidth: true },
});
</script>
</body>
</html>