Layer Management
Mega Brain uses a 3-layer classification system to separate community code (L1), premium content (L2), and personal data (L3). This system controls what gets distributed, packaged, and gitignored.Layer Overview
L1 - Community
Open source coreDistributed via npm as
mega-brain-aiGit: TrackedL2 - Premium
Populated contentPrivate repo (paying users)Git: Tracked (private)
L3 - Personal
User-generated dataLocal only / personal backupGit: Ignored
Quick Reference
| Layer | Name | Git Status | Distribution | Who Uses It |
|---|---|---|---|---|
| L1 | Community | Tracked | npm package (public) | Everyone — open source core |
| L2 | Premium | Tracked | Private repo (gated) | Paying users |
| L3 | Personal | Gitignored | Local only / personal backup | Individual user only |
| NEVER | Secrets | Gitignored | Never shared anywhere | Nobody |
| DELETE | Obsolete | N/A | Remove from repo | N/A |
| REVIEW | Unclear | Varies | Needs human decision | Pending classification |
Layer Definitions
L1 - Community (npm package)
What Belongs in L1
What Belongs in L1
The open-source engine that powers Mega Brain. Distributed via npm as
mega-brain-ai.Git status: Fully trackedDistribution: Public — npm publishContents:- Core processing engine (
core/) - CLI binaries (
bin/) - Claude Code integration templates (
.claude/) - Conclave (collaborative agent templates) (
agents/conclave/) - Agent templates (
agents/_templates/) - Documentation (
docs/) - Empty structure markers (
.gitkeepfiles anywhere)
.gitkeep files are always L1, regardless of directory, because they contain no personal data.L1 Distribution
L1 Distribution
L1 content is published to npm and available to everyone:What’s included:
- All core functionality
- Skills and hooks system
- Agent templates (empty)
- Documentation
- CLI tools
- Populated knowledge base (L2)
- User data (L3)
- Secrets (NEVER)
L2 - Premium (populated content)
What Belongs in L2
What Belongs in L2
Content generated through the Mega Brain pipeline — actual knowledge, agent personalities, dossiers, playbooks.Git status: Tracked in private repo (gitignored in public L1 repo)Distribution: Private — premium repository or direct syncContents:
- Populated mind clone agents (
agents/minds/with content) - Populated cargo agents (
agents/cargo/with profiles) - Knowledge dossiers (
knowledge/dossiers/) - Knowledge playbooks (
knowledge/playbooks/) - DNA knowledge base (
knowledge/dna/) - Knowledge sources (
knowledge/sources/) - Pipeline artifacts with extracted knowledge
L2 Distribution
L2 Distribution
L2 content requires premium access:Requires:
- Paid subscription OR
- Private repository access OR
- Running full pipeline to generate content
L3 - Personal (never distributed)
What Belongs in L3
What Belongs in L3
User-generated content specific to one person’s workflow — raw materials, logs, session history, company data.Git status: Gitignored (not committed to any shared repo)Distribution: Local backup only — never sharedContents:
- Raw input materials (
inbox/) - Processing and session logs (
logs/) - Session history (
.claude/sessions/) - Mission control state (
.claude/mission-control/) - Company-specific data (
agents/sua-empresa/)
L3 Backup
L3 Backup
L3 content is valuable to you but meaningless to others:
L3 backups are your responsibility. They are not included in git or npm distribution.
NEVER - Secrets and Credentials
What Belongs in NEVER
What Belongs in NEVER
Files that must never be committed to any git repository, shared, or distributed.Git status: Always gitignoredDistribution: Never — not even in personal backups if avoidableContents:
- Environment files (
.env,.env.local,.env.production) - API keys and credentials (
credentials.json,token.json) - Certificate files (
*.key,*.pem,*.secret) - MCP configuration with embedded tokens (
.mcp.json) - Local settings overrides (
settings.local.json)
DELETE - Obsolete Content
What Belongs in DELETE
What Belongs in DELETE
Files/directories that were once useful but are now superseded, abandoned, or replaced.Git status: Should be removed via
git rmDistribution: Remove everywhereExamples from Phase 7 audit:REVIEW - Needs Human Classification
What Belongs in REVIEW
What Belongs in REVIEW
Files that the automated classifier could not confidently assign to a layer.Git status: Varies — depends on final classificationDistribution: Cannot be determined until classifiedScale: 12,183 items in Phase 7 audit (58.6% of repo)Common candidates:
- IDE configuration (
.vscode/,.cursor/,.windsurf/) - Root-level project files (
README.md,package.json) - Planning artifacts (
.planning/) - Unrecognized directory structures
REVIEW is not a final classification — it signals to stop and decide manually.
Classification Rules
Decision Flowchart
Classification Criteria
| Criteria | L1 | L2 | L3 | NEVER | DELETE | REVIEW |
|---|---|---|---|---|---|---|
| Contains API keys or tokens | ✅ | |||||
| Obsolete/replaced implementation | ✅ | |||||
| User’s pipeline output (personal) | ✅ | |||||
| User-specific business content | ✅ | |||||
| Populated knowledge (dossiers, playbooks) | ✅ | |||||
| Core engine code | ✅ | |||||
Empty structure marker (.gitkeep) | ✅ | |||||
| Cannot determine without context | ✅ |
Path Examples
- L1 Examples
- L2 Examples
- L3 Examples
- NEVER Examples
| Path | Reason |
|---|---|
core/ | Core engine |
core/tasks/HO-TP-001.md | Core engine |
bin/ | Core engine |
.claude/hooks/ | Core engine |
agents/conclave/ | Core engine |
docs/ | Core engine |
inbox/.gitkeep | Empty structure marker |
knowledge/dna/.gitkeep | Empty structure marker |
Programmatic Classification
Using audit_layers.py
Classification Patterns
DELETE > NEVER > L3 > L2 > L1 > REVIEW
To add a new classification rule, edit the appropriate
*_PATTERNS list in audit_layers.py and re-run the audit.How to Classify a New File
Check NEVER Patterns
Does the filename match
.env, *.key, *.pem, credentials.json, etc.?Does the content contain API keys, tokens, or passwords?If YES → classify as NEVER and ensure it’s in .gitignoreCheck DELETE Patterns
Is this file/directory in
DELETE_PATTERNS from audit_layers.py?Is it explicitly superseded by a newer implementation?If YES → classify as DELETE and schedule for git rmCheck L3 Patterns
Does the path start with
inbox/, logs/, .claude/sessions/, or agents/sua-empresa/?If YES → classify as L3 (unless it’s a .gitkeep, which is L1)Check L2 Patterns
Does the path start with
agents/minds/, knowledge/dossiers/, or artifacts/insights/?If YES → classify as L2 (unless it’s a .gitkeep or empty directory, which is L1)Check L1 Patterns
Does the path start with
core/, bin/, .claude/, agents/conclave/, or docs/?Is it a .gitkeep file anywhere in the repo?If YES → classify as L1Gitignore Templates
Mega Brain provides layer-specific.gitignore templates:
- L1 (Community)
- L3 (Personal Backup)
docs/audit/L1-GITIGNORE-TEMPLATE.txtCommunity vs Pro Features
| Feature | Community (L1) | Pro (L1 + L2) |
|---|---|---|
| CLI & Templates | ✅ | ✅ |
| Skills & Hooks | ✅ | ✅ |
| Agent Templates | ✅ (empty) | ✅ (populated) |
| Knowledge Base | ❌ | ✅ (populated) |
| Mind Clone Agents | ❌ | ✅ |
| Pipeline Processing | ✅ (run locally) | ✅ (pre-processed) |
| Council / Conclave | ✅ (templates) | ✅ (trained) |
Validation
Mega Brain enforces layer compliance through validation tools:See Validation for complete validation system documentation.
Troubleshooting
File in Wrong Layer
File in Wrong Layer
Problem: File is classified incorrectlySolutions:
- Check if path matches any pattern in
audit_layers.py - Verify
.gitkeepfiles are not being treated as content - Update layer patterns if needed
- Re-run audit to verify fix
Package Contains Non-L1 Files
Package Contains Non-L1 Files
Problem:
validate-package.js reports violationsSolutions:- Check which files are flagged (layer and reason)
- Move L2/L3 files to correct location
- Add violations to
.gitignore - Update
package.jsonfiles field if needed - Re-run validation
Secrets in Package
Secrets in Package
Problem:
pre-publish-gate.js detects secretsSolutions:- Identify which file contains secret
- Remove secret from file or add to NEVER category
- Ensure file is in
.gitignore - Run
git rm --cachedif already committed - Re-run gate validation
Too Many REVIEW Items
Too Many REVIEW Items
Problem: 58.6% of files are REVIEWSolutions:
- Run audit to see REVIEW breakdown
- Classify common patterns (IDE config, etc.)
- Update
audit_layers.pywith new patterns - Document classification decisions
- Re-run audit to reduce REVIEW count
Best Practices
Layer Management Guidelines
- Respect layer boundaries - Don’t mix L1/L2/L3 content
- Use .gitkeep for structure - Empty dirs need .gitkeep (always L1)
- Classify on creation - Decide layer when creating file
- Validate before commit - Run validation tools
- Never commit NEVER - Double-check .gitignore
- Document exceptions - Explain unusual classifications
- Update patterns - Keep audit_layers.py current
- Review REVIEW items - Reduce ambiguity over time
Related Files
| File | Purpose |
|---|---|
core/intelligence/audit_layers.py | Programmatic classifier |
docs/audit/AUDIT-REPORT.json | Latest full audit (20,797 items) |
docs/audit/AUDIT-REPORT.md | Human-readable audit summary |
docs/audit/L1-GITIGNORE-TEMPLATE.txt | .gitignore for L1 distribution |
docs/audit/L2-GITIGNORE-TEMPLATE.txt | .gitignore for L2 distribution |
docs/audit/L3-GITIGNORE-TEMPLATE.txt | .gitignore for L3 backup |
.gitignore | Active gitignore (L1 rules) |
bin/validate-package.js | Package layer validator |
bin/pre-publish-gate.js | Pre-publish security gate |
Related Documentation
Validation
Complete validation system with security gates
Publishing
Publishing workflow and package preparation
Hooks System
Layer enforcement via PreToolUse hooks
Architecture
System architecture and design principles
