Skip to main content

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: Tracked

L2 - 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)

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 (.gitkeep files anywhere)
Real Examples:
.gitkeep files are always L1, regardless of directory, because they contain no personal data.
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
What’s NOT included:
  • Populated knowledge base (L2)
  • User data (L3)
  • Secrets (NEVER)

L2 - Premium (populated content)

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
Real Examples:
L2 is a superset of L1. L2 distribution includes all L1 content plus populated knowledge.
L2 content requires premium access:
Requires:
  • Paid subscription OR
  • Private repository access OR
  • Running full pipeline to generate content

L3 - Personal (never distributed)

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/)
Real Examples:
L3 content is gitignored and never leaves your machine except in personal backups.
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

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)
Real Examples:
If a file contains API keys, tokens, passwords, or private keys — it is NEVER. When in doubt, classify as NEVER.

DELETE - Obsolete Content

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:
Run python3 core/intelligence/audit_layers.py to get current delete candidates.

REVIEW - Needs Human Classification

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
Real Examples:
REVIEW is not a final classification — it signals to stop and decide manually.

Classification Rules

Decision Flowchart

Classification Criteria

Path Examples

Programmatic Classification

Using audit_layers.py

Classification Patterns

Priority order: 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 .gitignore
2

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 rm
3

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 L1
6

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:
Location: docs/audit/L1-GITIGNORE-TEMPLATE.txt

Community vs Pro Features

Community users can generate L2 content by running the pipeline on their own materials. L2 distribution just provides pre-built content.

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

Problem: File is classified incorrectlySolutions:
  1. Check if path matches any pattern in audit_layers.py
  2. Verify .gitkeep files are not being treated as content
  3. Update layer patterns if needed
  4. Re-run audit to verify fix
Problem: validate-package.js reports violationsSolutions:
  1. Check which files are flagged (layer and reason)
  2. Move L2/L3 files to correct location
  3. Add violations to .gitignore
  4. Update package.json files field if needed
  5. Re-run validation
Problem: pre-publish-gate.js detects secretsSolutions:
  1. Identify which file contains secret
  2. Remove secret from file or add to NEVER category
  3. Ensure file is in .gitignore
  4. Run git rm --cached if already committed
  5. Re-run gate validation
Problem: 58.6% of files are REVIEWSolutions:
  1. Run audit to see REVIEW breakdown
  2. Classify common patterns (IDE config, etc.)
  3. Update audit_layers.py with new patterns
  4. Document classification decisions
  5. Re-run audit to reduce REVIEW count

Best Practices

Layer Management Guidelines

  1. Respect layer boundaries - Don’t mix L1/L2/L3 content
  2. Use .gitkeep for structure - Empty dirs need .gitkeep (always L1)
  3. Classify on creation - Decide layer when creating file
  4. Validate before commit - Run validation tools
  5. Never commit NEVER - Double-check .gitignore
  6. Document exceptions - Explain unusual classifications
  7. Update patterns - Keep audit_layers.py current
  8. Review REVIEW items - Reduce ambiguity over time

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