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 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
Path Examples
- L1 Examples
- L2 Examples
- L3 Examples
- NEVER Examples
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
1
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 .gitignore2
Check 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 rm3
Check 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)4
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)5
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 L16
Apply REVIEW
If none of the above matched, classify as REVIEW.Open a discussion or consult the classification criteria table.Document the decision and add it to
audit_layers.py to prevent future ambiguity.Gitignore Templates
Mega Brain provides layer-specific.gitignore templates:
- L1 (Community)
- L3 (Personal Backup)
docs/audit/L1-GITIGNORE-TEMPLATE.txtCommunity vs Pro Features
Validation
Mega Brain enforces layer compliance through validation tools:1
Package Validation
validate-package.js ensures only L1 files are in npm package:2
Pre-Publish Gate
pre-publish-gate.js blocks publish if non-L1 or secrets detected:3
Full Audit
audit_layers.py generates complete classification report: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
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
