WhyBase Reference & Architecture
Requirements: Node.js 20.0.0+ and Git. Everything runs 100% locally with zero cloud API keys.
Quickstart
Preview what init will configure before modifying any files using --dry-run:
npx whybase init --all --sync-rules --dry-run
Initialize WhyBase inside any single repository or multi-repo workspace:
cd your-project npx whybase init --all --sync-rules
Safety guarantees during init:
- Existing
.cursorrules,CLAUDE.md,.continuerules, andAGENTS.mdfiles are never overwritten; WhyBase updates only its own<!-- WHYBASE:START --> ... <!-- WHYBASE:END -->marker block. - If
~/.continue/config.yamlexists, WhyBase automatically saves a backup to~/.continue/config.yaml.whybase.bakbefore editing, or pass--no-globalto skip modifying global user config.
Using WhyBase in AI Editors
whybase init --all automatically registers MCP targets in .mcp.json, .cursor/mcp.json, .vscode/mcp.json, .windsurf/mcp.json, and ~/.continue/config.yaml. Reload your editor window and ask:
"Why does this lock exist and what breaks if I edit src/billing/webhook.ts?" "Check fragile zones in this repo before refactoring." "Record a decision that we must keep LOCK_MS for duplicate Stripe retries."
Language Analysis Depth
WhyBase uses the TypeScript Compiler API for JS/TS and lightweight regex extractors for polyglot repositories:
| Language | Parser | Dependency Depth | Blast Radius Depth |
|---|---|---|---|
| TypeScript / JavaScript | TypeScript Compiler API | Imports, exports, tsconfig.json paths, workspace packages, route hints | File-level + Symbol-level callers |
| Python | Regex AST extractor | Relative/module imports, from ... import symbols, FastAPI route hints | File-level + Symbol regex callers |
| Go / PHP / Rust / Java | Regex extractor | go.mod modules, PSR-4 composer.json, crate::, Java package imports | File / Module-level only (no cross-file symbol graph yet) |
Hotspot Heuristic & Tuning
Fragile zone scoring uses a commit-message keyword heuristic (fix, bug, hotfix, revert, etc.) weighted by commit recency. Because commit subjects like "fix typo" can add noise, you can tune thresholds and keywords directly in .ai-context/config.yaml:
hotspots:
minScore: 4
bugFixWeight: 3
revertWeight: 5
commitWeight: 0.5
bugFixKeywords:
- fix
- hotfix
- regression
- race
Security & Privacy
- Local UI Server Protection:
whybase uibinds only to127.0.0.1, enforces strictHostandOriginallowlists against DNS rebinding, and requires a per-session random CSRF token (X-WhyBase-Token) on all mutating endpoints. - Safe IDE Launcher: Open in IDE resolves absolute paths strictly within the active workspace root, rejects shell metacharacters, and verifies that the exact project folder is already open in your running editor.
- Prompt Injection Guard for AI Decisions: Decisions saved by AI tools via
record_decisionare stampedstatus: ai-unreviewedand excluded fromrules-syncuntil reviewed and approved by a human inwhybase uior Git. - Privacy Warning for
.ai-context/summaries.json:summaries.jsonstores top hotspot file paths and optional Ollama AI summaries. In private or sensitive repositories, add.ai-context/summaries.jsonto your.gitignoreif you do not want internal file paths or AI notes committed.
Visual Knowledge Graph Dashboard
npx whybase ui
Opens http://127.0.0.1:4173 with Explorer & expandable Blast Radius SVG, interactive Dependency Graph, Fragile Zones risk distribution, Decisions & Rules CRUD (with Approve controls for AI drafts), live SSE file-watcher sync, and Click-to-Open IDE.
CLI Commands
| Command | Purpose |
|---|---|
| whybase init [--all] [--local] [--ollama] [--no-hook] [--no-global] [--dry-run] [--sync-rules] | Initializes .ai-context/, builds Git + AST graph, registers MCP targets, and installs the post-commit hook. |
| whybase ui [--port 4173] [--no-open] [--no-watch] | Starts the authenticated localhost dashboard with live SSE sync. |
| whybase watch | Watches source files and keeps .ai-context/.cache/graph.json updated live. |
| whybase sync [--ollama] | Incrementally re-scans Git history and AST dependencies via mtimeMs cache. |
| whybase inspect <file> [--symbol name] | Prints Git stats, fragile score, direct callers, symbol callers, and guardrails. |
| whybase decide "<title>" --rule "..." --context "..." [--paths "..."] | Records a human-reviewed ADR Markdown file in .ai-context/decisions/. |
| whybase rules-sync [--targets cursor,claude,continue,agents] | Mirrors rules.yaml and reviewed ADRs into editor rule marker blocks. |
| whybase hook <install|remove> [--local] | Installs or removes the non-blocking Git post-commit auto-sync hook. |
| whybase pr-check [--base main] [--markdown] [--fail-on-score N] [--max-impact N] | Evaluates changed files for blast radius and fragile zone CI gates. |
| whybase serve [-r path] | Starts the MCP server over stdio. |
| whybase doctor [-r path] | Verifies .ai-context/, graph cache, MCP configs, rules, Git hooks, and Ollama. |
MCP Tools & Resources
get_architecture_map({ focus?, limit? })— Module directories, exports, dependencies, and detected HTTP routes.why_this_exists({ path, symbol? })— Git commits, bug fixes, symbol history, callers, AI notes, co-changed files, and ADRs.get_blast_radius({ path, symbol?, maxDepth? })— Direct, symbol-level, and transitive dependents plus impacted tests and routes.get_fragile_zones({ limit? })— Time-weighted bug-fix and revert hotspots with AI notes and co-changed peers.get_guardrails({ path?, query? })— Glob-scoped rules and decisions with optional keyword search.record_decision({ title, context, rule, paths? })— Saves an AI-drafted ADR markedai-unreviewedin.ai-context/decisions/.
GitHub Actions PR Gate
- name: WhyBase PR Check
run: npx whybase pr-check --base origin/${{ github.base_ref }} --markdown --fail-on-score 12 --max-impact 25 >> "$GITHUB_STEP_SUMMARY"