Markdown source

mdvdb tree

Show a file tree of all markdown files with sync status indicators. Each file is classified by comparing the files on disk against the index: Indexed (synced, hash matches), Modified (hash changed since last ingest), New (on disk but not in the index), or Deleted (in the index but no longer on disk).

Usage

mdvdb tree [OPTIONS]

Options

FlagDefaultDescription
--path <PREFIX>(none)Restrict tree to files under this path prefix
--shard <ID>(none)Restrict tree to a configured named Shard (conflicts with --path)

Option Details

--path <PREFIX>

Filters the tree to show only files and directories under the given path prefix. The prefix matches against the relative file paths in the tree.

When --path is used, the tree is rooted at the matching subtree. If no files match the prefix, an empty tree is displayed with zero counts.

# Show tree for docs directory only
mdvdb tree --path docs

# Show tree for a nested directory
mdvdb tree --path src/components

--shard <ID>

Resolves a configured Shard to its recursive folder scope and returns the same tree contract, rooted at that folder. Shards use the shared collection index; this option does not open a separate index. --shard conflicts with --path.

mdvdb tree --shard research
mdvdb tree --shard research --json

Global Options

These options apply to all commands. See Commands Index for details.

FlagShortDescription
--verbose-vIncrease log verbosity (-v info, -vv debug, -vvv trace)
--rootProject root directory (defaults to current directory)
--no-colorDisable colored output
--jsonOutput results as JSON

Sync Status Indicators

Each file in the tree is classified into one of four sync states by comparing the file on disk with what is stored in the index:

StateIndicatorColorDescription
Indexed(none)GreenFile is in the index and its content hash matches the file on disk. Fully synced.
Modified[modified]YellowFile is in the index but its content has changed since the last ingest (SHA-256 hash mismatch).
New[new]BlueFile exists on disk but is not yet in the index. Needs ingestion.
Deleted[deleted]RedFile is in the index but no longer exists on disk. Will be cleaned up on next ingest.

How Sync State Is Determined

  1. Discover all markdown files on disk using the file scanner (respecting .gitignore, .mdvdbignore, and MDVDB_IGNORE_PATTERNS)
  2. Compare each discovered file against the index:
    • If the file’s relative path exists in the index, read the file and compute its SHA-256 content hash
    • If the hash matches the stored hash, the file is Indexed
    • If the hash differs, the file is Modified
    • If the path is not in the index, the file is New
  3. Check for deleted files: any path in the index that is not found on disk is marked Deleted

Human-Readable Output

When run without --json, tree displays an ASCII tree with box-drawing characters and colored status indicators:

.
├── docs
│   ├── api
│   │   ├── authentication.md
│   │   └── endpoints.md [modified]
│   ├── getting-started.md
│   └── overview.md [new]
├── blog
│   ├── 2024-01-15-intro.md
│   └── 2024-03-22-update.md
├── notes
│   └── meeting-notes.md [new]
└── README.md

12 files (8 indexed, 1 modified, 2 new, 1 deleted)

Output Elements

ElementDescription
Tree structureBox-drawing characters (├──, └──, │) showing the directory hierarchy
DirectoriesShown in bold, listed before files at each level
FilesMarkdown files with optional [state] suffix for non-indexed states
Summary lineTotal file count with breakdown by sync state

Color Coding

When colors are enabled (default), the tree uses ANSI colors:

ElementColor
DirectoriesBold
Indexed filesGreen
Modified filesYellow + [modified] suffix
New filesBlue + [new] suffix
Deleted filesRed + [deleted] suffix

Colors can be disabled with --no-color or by setting the NO_COLOR environment variable.

Sorting

Children at each directory level are sorted with:

  1. Directories first (alphabetical)
  2. Files second (alphabetical)

Examples

# Show full file tree
mdvdb tree

# Show tree as JSON
mdvdb tree --json

# Show tree for a specific directory
mdvdb tree --path docs

# Show tree for a specific project
mdvdb tree --root /path/to/project

# Show tree without colors
mdvdb tree --no-color

# Show tree scoped to a directory as JSON
mdvdb tree --path blog --json

# Show the recursive folder represented by a named Shard
mdvdb tree --shard research

JSON Output

FileTree (--json)

{
  "root": {
    "name": ".",
    "path": ".",
    "is_dir": true,
    "state": null,
    "children": [
      {
        "name": "docs",
        "path": "docs",
        "is_dir": true,
        "state": null,
        "children": [
          {
            "name": "api",
            "path": "docs/api",
            "is_dir": true,
            "state": null,
            "children": [
              {
                "name": "authentication.md",
                "path": "docs/api/authentication.md",
                "is_dir": false,
                "state": "indexed",
                "children": []
              },
              {
                "name": "endpoints.md",
                "path": "docs/api/endpoints.md",
                "is_dir": false,
                "state": "modified",
                "children": []
              }
            ]
          },
          {
            "name": "overview.md",
            "path": "docs/overview.md",
            "is_dir": false,
            "state": "new",
            "children": []
          }
        ]
      },
      {
        "name": "README.md",
        "path": "README.md",
        "is_dir": false,
        "state": "indexed",
        "children": []
      }
    ]
  },
  "total_files": 12,
  "indexed_count": 8,
  "modified_count": 1,
  "new_count": 2,
  "deleted_count": 1
}

FileTree Fields

FieldTypeDescription
rootFileTreeNodeRoot node of the file tree
total_filesnumberTotal number of files (indexed + modified + new + deleted)
indexed_countnumberNumber of files that are fully synced with the index
modified_countnumberNumber of files modified since last ingest
new_countnumberNumber of files on disk not yet in the index
deleted_countnumberNumber of files in the index no longer on disk

FileTreeNode Fields

FieldTypeDescription
namestringFile or directory name (e.g., "README.md", "docs")
pathstringRelative path from project root (e.g., "docs/api/endpoints.md")
is_dirbooleantrue for directories, false for files
statestring | nullSync state for files: "indexed", "modified", "new", or "deleted". Always null for directories.
childrenFileTreeNode[]Child nodes (files and subdirectories). Empty array for files.

FileState Values

ValueDescription
"indexed"File hash matches the index. Fully synced.
"modified"File exists in the index but content has changed (hash mismatch).
"new"File exists on disk but is not in the index.
"deleted"File is in the index but no longer on disk.

Filtered Tree (--path)

When --path is used, the JSON output has the same structure but rooted at the matching subtree. If no files match the prefix, an empty tree is returned:

{
  "root": {
    "name": ".",
    "path": ".",
    "is_dir": true,
    "state": null,
    "children": []
  },
  "total_files": 0,
  "indexed_count": 0,
  "modified_count": 0,
  "new_count": 0,
  "deleted_count": 0
}

Notes

  • The tree command never modifies the index. If no usable index exists, it still returns a discovery-only tree and marks every on-disk document new; if an existing index cannot be opened, it warns and degrades to that filesystem view.
  • File discovery respects .gitignore, .mdvdbignore, and MDVDB_IGNORE_PATTERNS — excluded files do not appear in the tree.
  • Summary counts in --path and --shard mode are recomputed from the visible subtree.
  • Deleted files appear in the tree even though they no longer exist on disk. They will be removed from the index on the next mdvdb ingest.
  • The content hash comparison reads files from disk, so the tree command may be slightly slower than status for large projects.
  • mdvdb ingest — Index new and modified files, remove deleted files
  • mdvdb status — Quick summary of index counts without the tree structure
  • mdvdb schema — View inferred metadata schema from indexed files
  • mdvdb get — View detailed metadata for a specific file

See Also