1.0.8 • Published 4 months ago

codesnap-analyzer v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

CodeSnap Analyzer Node.js

https://github.com/phamhung075/codesnap-analyzer

A tool for creating comprehensive snapshots of your codebase with token counting for LLMs. result like GitIngest

Installation

npm install -g codesnap-analyzer

Usage

Command Line

# Analyze current directory
codesnap

# Analyze specific directory
codesnap ./my-project

# With options
codesnap . -o output.txt -i "*.ts" "*.tsx" -e "tests" "docs"

Example Output Command Line

PS D:\DaiHung\__labo\codesnap> codesnap . 
šŸ“ø Starting CodeSnap analysis...
šŸ“ Project: codesnap-analyzer
šŸ“‚ Directory: D:\DaiHung\__labo\codesnap
šŸ“ Output will be saved to: D:\DaiHung\__labo\codesnap\codesnap\codesnap-analyzer.txt

šŸ” Looking for .gitignore at: D:\DaiHung\__labo\codesnap\.gitignore
āœ… Found .gitignore file

šŸ“‹ Active ignore patterns:

   Default patterns:
   - node_modules
   - package-lock.json
   - yarn.lock
   - .npm
   - .git
   - .svn
   - .hg
   - dist
   - build
   - out
   - .idea
   - .vscode
   - .tmp
   - tmp
   - .DS_Store
   - Thumbs.db
   - *.jpg
   - *.jpeg
   - *.png
   - *.gif
   - *.ico
   - *.pdf
   - *.exe
   - *.dll
   - *.so
   - *.dylib
   - codesnap

   From .gitignore:
   - node_modules/
   - package-lock.json
   - yarn.lock
   - .npm/
   - dist/
   - build/
   - lib/
   - *.tsbuildinfo
   - coverage/
   - .nyc_output/
   - jest-report/
   - test-report/
   - logs/
   - *.log
   - npm-debug.log*
   - yarn-debug.log*
   - yarn-error.log*
   - pids
   - *.pid
   - *.seed
   - *.pid.lock
   - .idea/
   - .vscode/
   - *.swp
   - *.swo
   - .DS_Store
   - .env
   - .env.*
   - !.env.example
   - .temp/
   - .tmp/
   - .cache/
   - *.tsbuildinfo
   - .npm
   - .eslintcache
   - docs/_build/
   - docs/_static/
   - docs/_templates/
   - debug.log
   - debug.test.log
   - output/
   - codesnap/

šŸ“‚ Starting directory analysis...
šŸ“ Base directory: D:\DaiHung\__labo\codesnap

āš™ļø  Settings:
   Max file size: 10.00 MB
   Max total files: 10000
   Max total size: 500.00 MB

šŸ” Scanning for files...
   ā­ļø  Skipping directory: .git (matches ignore pattern)
   ā­ļø  Skipping directory: codesnap (matches ignore pattern)
   ā­ļø  Skipping directory: dist (matches ignore pattern)
   ā­ļø  Skipping directory: node_modules (matches ignore pattern)
✨ Found 18 files total

šŸ“„ Processing files:
   āœ… Reading: .gitignore
   āœ… Reading: README.md
   āœ… Reading: eslint.config.mjs
   āœ… Reading: jestconfig.json
   āœ… Reading: package.json
   āœ… Reading: pnpm-lock.yaml
   āœ… Reading: src/__tests__/cli.test.ts
   āœ… Reading: src/cli.ts
   āœ… Reading: src/constants/analyze.ts
   āœ… Reading: src/constants/patterns.ts
   āœ… Reading: src/core/analyzer.ts
   āœ… Reading: src/index.ts
   āœ… Reading: src/services/codesnap.ts
   āœ… Reading: src/services/formatter.ts
   āœ… Reading: src/types/types.ts
   āœ… Reading: src/utils/file.ts
   āœ… Reading: src/utils/token-counter.ts
   āœ… Reading: tsconfig.json

āœ… Analysis completed successfully!
šŸ“Š Summary:
Project Directory: AIanalist
Total Files Analyzed: 107
Total Size: 0.33 MB
Date: 2025-01-01T17:49:26.916Z

Token counts and costs by model:
   GPT-3.5: 70.7K tokens → $0.1060
   GPT-4:   70.7K tokens → $2.1200
   Claude:  70.7K tokens → $1.0600
   LLaMA 2: 77.7K tokens → $0.1555

Example Output File

codesnap-analyzer.txt

Programmatic Usage

import { analyze } from 'codesnap-analyzer';

async function analyzeProject() {
  const result = await analyze('./my-project', {
    output: 'analysis.txt',
    includePatterns: ['*.ts', '*.tsx'],
    excludePatterns: ['tests', 'docs']
  });

  console.log(result.summary);
  console.log(result.tokenCounts);
}

Features

  • Comprehensive codebase analysis
  • Token counting for multiple LLM models (GPT-3.5, GPT-4, Claude, LLaMA 2)
  • Respect .gitignore patterns
  • Customizable include/exclude patterns
  • Binary file detection
  • Size limits handling
  • Tree structure visualization

Options

  • `output`: Output file path
  • `excludePatterns`: Additional patterns to exclude
  • `includePatterns`: Patterns to include

Token Counting

Provides token counts for:

  • GPT-3.5
  • GPT-4
  • Claude
  • LLaMA 2

License

MIT