f838755991986ea77591b79f7f0c07db6b674fb0
Every structured-output call now uses an Anthropic tool instead of
parsing JSON out of free-form prose, and stable system prompts are
sent as cacheable blocks. Behaviour-equivalent to phase 1 from the
caller's point of view; the savings show up in token usage and in the
absence of "AI returned non-JSON response" failure modes.
* src/lib/llmTools.js — single source of truth for tool definitions:
emit_knowledge_graph, emit_handbook_delta, emit_learning_article /
_slides / _infographic / _all, emit_custom_topic, emit_quiz_questions,
emit_graph_actions, plus five article-patch tools (set_intro,
set_section, add_section, remove_section, replace_takeaways).
* src/lib/articlePatches.js — pure applyArticlePatches +
applyAndValidate; rebuilds the article from a sequence of patch tool
calls and re-validates against learningArticleSchema. set_section
falls back to appending when no matching heading exists so the
model's intent is preserved rather than silently dropped.
* src/lib/llmSchemas.js — Zod schemas for the five patch ops,
registered in toolSchemaRegistry so callLLM validates them
automatically.
* src/lib/llm.js — simulation mode now returns a tool_use stub matching
toolChoice.name, so the UI keeps working with Simulation Mode on
after the structured-output migration.
* src/lib/extractionPipeline.js — processSourceText and
analyzeHandbookDelta migrated to callLLM + tool use. System prompts
sent as { cache_control: ephemeral } blocks. Handbook results pass
through normalizeHandbookResult to collapse legacy "executes"
relations into executed_by with swapped source/target.
* src/lib/learningService.js — generateLearningContent picks the right
tool per selectedType; generateCustomTopic uses emit_custom_topic;
refineLearningContent now drives the five patch tools with
toolChoice 'any' and rejects the whole turn if the patched article
fails validation. Article-only refinement is intentional for phase 2;
refining a topic without an article surfaces a clear error.
* src/lib/testService.js — quiz generation via emit_quiz_questions.
* src/components/admin/KnowledgeGraph.jsx — analyzeGraph routed through
the reasoning tier (Opus) since graph-wide consolidation benefits
from a stronger reasoner.
* src/components/chat/prompts.js — buildSystemPrompt now returns three
text blocks: stable preamble (cached), KB context (cached, hash-bust
deferred to phase 5), per-turn user/admin tail (uncached).
* src/lib/__tests__/ — 13 new tests covering each patch op, multi-op
sequencing, post-patch validation failure, and tool/registry shape.
Acceptance: lint and 45/45 tests green; build succeeds; no
`match(/\{[\s\S]*\}/)` JSON extraction left in src/. Live verification
of cache hits on a second extraction within 5 minutes is deferred to
manual smoke testing — needs real `/api/anthropic` traffic.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Respellion Learning Platform
An internal AI-powered learning platform that keeps Respellion employees up to date with the company's evolving knowledge base.
Features
- Weekly Learning Station — Each employee is assigned a topic each week (via deterministic hash of user ID + week number). They choose their preferred format: Article, Slides, or Infographic. Content is generated on-demand by Claude and cached per topic.
- Weekly Test — AI-generated quiz based on the knowledge graph. Results are stored and feed the leaderboard.
- Leaderboard & Gamification — Points for correct answers, badges for streaks and perfect scores.
- R42 Chatbot — An always-available AI assistant (backed by Claude) with access to the full knowledge graph. Can propose graph updates that admins approve or reject.
- Admin Panel — Manage the knowledge graph, sync from GitHub, review generated content, refine it with AI, and monitor team progress.
Tech Stack
| Layer | Technology |
|---|---|
| Frontend | React 18 + Vite |
| Styling | Vanilla CSS (custom properties) + Tailwind utility classes |
| Animations | Framer Motion |
| Icons | Lucide React |
| Graph viz | D3.js (admin knowledge graph only) |
| Backend / DB | PocketBase (self-hosted) |
| AI | Anthropic Claude (via Caddy reverse proxy) |
| Infra | Docker + Caddy |
Getting Started (local dev)
# 1. Install dependencies
npm install
# 2. Start PocketBase (Windows)
./pocketbase.exe serve
# 3. Start the dev server
npm run dev
The Vite dev server proxies /api/anthropic and /pb — see vite.config.js.
Deployment (Docker)
docker compose up -d
The Caddyfile handles:
- SPA fallback routing
/pb/*→ PocketBase sidecar/api/anthropic/*→ Anthropic API (with server-side API key injection)
Key Files
| File | Purpose |
|---|---|
src/lib/learningService.js |
Selective content generation (article / slides / infographic) |
src/lib/extractionPipeline.js |
GitHub file → knowledge graph extraction |
src/lib/api.js |
Anthropic API wrapper (generateContent + chat) |
src/lib/db.js |
All PocketBase data access |
src/lib/giteaService.js |
GitHub API client (folder listing + raw file fetch) |
src/store/AppContext.jsx |
Global state; computes ISO week number on load |
src/components/admin/UploadZone.jsx |
GitHub sync UI (default folder: docs/knowledge-base/) |
AI_AGENT.md |
Detailed context guide for AI coding agents |
Content Types
Learning content is generated on demand per type and merged into the cached object:
| Type | Key in DB | Description |
|---|---|---|
| Article | content.article |
Long-form reading |
| Slides | content.slides |
Slide deck with speaker notes |
| Infographic | content.infographic |
Visual summary with stats and steps |
The podcast type was removed. Do not re-add it.
Documentation
AI_AGENT.md— Full architectural guide for AI coding agents (patterns, gotchas, decisions).CHANGELOG.md— PocketBase upstream changelog (not application changelog).
Description
Languages
JavaScript
95.6%
TypeScript
3.6%
CSS
0.8%