@muid-io/smart-toc
v3.6.6
Published
Smart Table of Contents generator for markdown files with exact line numbers, Roman numeral header detection (I., II., III.), emoji-aware table alignment, navigation commands, and YAML metadata for AI agents. Minimal by default, with optional AI instructi
Maintainers
Readme
@muid-io/smart-toc
Smart Table of Contents generator for markdown files with exact line numbers and navigation commands
Perfect for AI agents and large documentation files (500+ lines).
🚀 Quick Start
NPM Installation (Recommended)
# Run directly with npx (no installation)
npx @muid-io/smart-toc document.md
# Or install globally
npm install -g @muid-io/smart-toc
# Then use anywhere
stoc document.md
# or
smart-toc document.mdPython Installation (Alternative)
# Download the script
curl -O https://registry.npmjs.org/@muid-io/smart-toc/-/smart-toc-2.7.0.tgz
tar -xzf smart-toc-2.7.0.tgz
cd package/bin/
# Run directly
python3 smart-toc.py document.md📖 Usage
Default: Generate .toc File
stoc document.md
# Creates: document.toc (separate navigation file)Output includes:
- Exact line numbers for every section
- grep/sed commands for instant navigation
- Structure statistics
- AI agent usage instructions
Insert TOC into Original File
stoc document.md --insert-toc
# Modifies document.md (creates backup first)Advanced Options
# Control header depth
stoc document.md --max-header-depth 4
# With buffer zone (for frequently updated docs)
stoc document.md --insert-toc --buffer --buffer-size 30
# Custom output path
stoc document.md -o custom-toc.md
# Auto-create TOC section if missing
stoc document.md --insert-toc --auto-create
# See all options
stoc --help🤖 For AI Agents
How to Use
Check for .toc file:
stoc document.md # Creates document.tocRead the .toc file for navigation table
Use line numbers to jump directly:
Read(file="document.md", offset=458, limit=100)Use search commands from TOC:
grep -n "SECTION_START: Configuration" -A 75
Benefits
- ✅ 10x faster document navigation
- ✅ 90% token savings (no full file reads)
- ✅ 100% accurate line numbers
- ⚡ Instant section lookup
📋 Requirements
- Node.js: 14.0.0 or higher (for npm package)
- Python: 3.6 or higher (automatically detected)
Both are required for the npm package to work.
📊 Features
What It Generates
## 📑 CURRENT DOCUMENT TABLE OF CONTENTS
### Navigation Table
| Section/Header | Line(s) | Description | Search Command |
|-------------------------|---------|-------------|----------------|
| Configuration | 45-120 | Setup info | `grep -n ...` |
| ├── Database Settings | 58 | DB config | `grep -n ...` |
| API Reference | 125-250 | API docs | `sed -n ...` |Key Features
- ✅ Parses SECTION markers and markdown headers
- ✅ Generates exact line numbers
- ✅ Creates navigation commands (grep/sed)
- ✅ Shows document structure at a glance
- ✅ Verbose output with statistics
- ✅ Automatic backups (with --insert-toc)
- ✅ Buffer zones for TOC growth
- ✅ No external dependencies (Python stdlib only)
🎯 When to Use
Use Default .toc Mode When:
- ✅ Want to review structure without modifying original
- ✅ Need quick AI agent reference
- ✅ Document structure might change
- ✅ Want to keep TOC and document separate
Use --insert-toc Mode When:
- ✅ Document needs to be self-contained
- ✅ Publishing/sharing documentation
- ✅ TOC should be part of version control
- ✅ Using buffer zones for frequent updates
📚 Documentation
Full documentation available in the docs/ directory:
- README_ANALYZER_V2.7.md - Complete guide
- CHANGELOG.md - Version history
- PORTABLE_PACKAGE_GUIDE.md - Portable usage
🔧 Development
Local Testing
git clone <repo>
cd smart-toc
npm link
stoc --helpPublishing (for maintainers)
# Set up auth (one time)
npm config set //registry.npmjs.org/:_authToken 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
# Publish
npm publish --access public
# Update version
npm version patch # or minor/major
npm publish📝 Examples
Example 1: Large Documentation
# Generate TOC for large file
stoc ARCHITECTURE.md
# Review structure
cat ARCHITECTURE.toc
# If satisfied, insert into original
stoc ARCHITECTURE.md --insert-tocExample 2: API Documentation
# With custom header depth
stoc API_DOCS.md --max-header-depth 5
# Creates detailed TOC with deeper nestingExample 3: Frequently Updated Docs
# Use buffer zone to prevent line shift issues
stoc CHANGELOG.md --insert-toc --buffer --buffer-size 50🐛 Troubleshooting
Python Not Found
# Install Python 3
# Ubuntu/Debian:
sudo apt install python3
# macOS:
brew install python3
# Windows:
# Download from https://www.python.org/Permission Denied
# Make script executable
chmod +x node_modules/@muid-io/smart-toc/bin/*.pyModule Not Found
# Reinstall package
npm uninstall -g @muid-io/smart-toc
npm install -g @muid-io/smart-toc📦 Package Contents
@muid-io/smart-toc/
├── index.js # Node.js wrapper
├── bin/
│ └── smart-toc.py # Python script
├── docs/
│ ├── README_ANALYZER_V2.7.md
│ ├── CHANGELOG.md
│ └── PORTABLE_PACKAGE_GUIDE.md
├── package.json
└── README.md🔗 Links
- NPM Package: https://www.npmjs.com/package/@muid-io/smart-toc
- Organization: https://www.npmjs.com/org/muid-io
- Issues: https://github.com/muid-io/smart-toc/issues
📄 License
MIT License - see LICENSE file for details
👥 Author
LifeAiTools - Universal TOC parser/analyzer for AI needs Maintained by: @muid-io
🙏 Acknowledgments
- Built for AI agents and large documentation
- Optimized for Claude Code and similar tools
- Part of the muid.io toolkit
Version: 2.7.0 Last Updated: October 30, 2025 Status: ✅ Production Ready
