Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:0xK3vin MegaMemory Codebase Inventory Analysis

From Leeroopedia
Knowledge Sources
Domains Codebase_Analysis, Information_Gathering
Last Updated 2026-10-27 12:00 GMT

Overview

An analysis technique that gathers a ranked file inventory of a codebase to identify major modules and inform the structure of a new knowledge graph.

Description

Codebase inventory analysis produces a compact, prioritized view of a project's files — typically ranked by line count — so that an agent (or human) can identify the most significant modules and their relationships without reading every file. The inventory combines tracked source files with untracked (but non-ignored) files, deduplicates, and caps the output to a manageable size. Combined with the README, this gives enough signal to plan a knowledge graph's root concepts.

Problem solved: When bootstrapping a knowledge graph for an unfamiliar project, an agent faces a cold-start problem: what are the major modules? Reading every file is expensive and often unnecessary. A line-count-ranked inventory highlights the largest, most significant files, and the README provides the project's self-description. Together they provide enough structure to create root concepts and begin populating the graph.

Context: MegaMemory's /bootstrap-memory slash command runs a shell pipeline (git ls-files + git ls-files --others --exclude-standard piped through sort -u | xargs wc -l | sort -rn | head -150) to produce the inventory, then reads the README. The agent uses this to identify major modules (Step 3 of the bootstrap workflow), then creates root concepts via createConcept and child concepts via createConcept with parent_id.

Usage

Use this principle when:

  • You are bootstrapping a knowledge graph for a new project and need to identify major modules
  • You want a compact, prioritized file listing rather than an exhaustive tree
  • Line count is a useful proxy for module significance
  • The project is a git repository (or the pipeline degrades gracefully with 2>/dev/null)

Theoretical Basis

The inventory is a ranking function over files:

Failed to parse (syntax error): {\displaystyle \text{inventory}(P) = \text{top}_k\left(\text{sort\_by\_lines}\left(\text{dedupe}\left(\text{tracked}(P) \cup \text{untracked\_not\_ignored}(P)\right)\right)\right) }

where k=150 and sort_by_lines is descending.

Heuristic basis: File size (line count) is a rough proxy for complexity and significance. The largest files tend to be the core modules, data layers, or entry points. This is a heuristic — small but important files (e.g., config.ts) may be missed — so the README is also read to provide semantic grounding.

Pseudo-code:

# Abstract pipeline (NOT real implementation)
files = set(git_ls_files() + git_ls_files_others_exclude_standard())
ranked = sorted(files, key=lambda f: -line_count(f))
inventory = ranked[:150]
readme = read("README.md")
major_modules = agent.identify(inventory, readme)
for module in major_modules:
    create_concept(name=module.name, kind="module", summary=module.summary)

Practical Guide

To apply this technique:

  1. Gather the inventory: Run git ls-files combined with git ls-files --others --exclude-standard to capture both tracked and untracked files.
  2. Rank by line count: Pipe through wc -l | sort -rn so the largest files surface first.
  3. Cap the output: Limit to ~150 files to keep the prompt manageable for LLM reasoning.
  4. Read the README: The README provides the project's self-description, grounding the module analysis with intent that line counts alone can't reveal.
  5. Identify major modules: Reason over the inventory + README to name the top-level systems.
  6. Create root concepts: Each major module becomes a root concept; sub-features become children.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment