@nlci/cli
v0.1.0
Published
Command-line interface for NLCI - Neural-LSH Code Intelligence
Maintainers
Readme
@nlci/cli
Command-line interface for NLCI - Neural-LSH Code Intelligence.
Installation
npm install -g @nlci/cli
# or
pnpm add -g @nlci/cliQuick Start
# Initialize NLCI in your project
nlci init
# Scan your codebase to build the index
nlci scan ./src
# Query for similar code
nlci query --file ./src/my-function.ts
# Generate a clone detection report
nlci reportCommands
nlci init
Initialize NLCI configuration in the current directory.
nlci init [options]
Options:
-f, --force Overwrite existing configuration
--typescript Use TypeScript configuration file
--json Use JSON configuration filenlci scan
Scan a directory and build the code similarity index.
nlci scan [path] [options]
Arguments:
path Path to scan (defaults to current directory)
Options:
-o, --output <path> Output path for index file (default: ".nlci-index")
-c, --config <path> Path to configuration file
-i, --include <patterns...> Glob patterns to include
-e, --exclude <patterns...> Glob patterns to exclude
--min-tokens <n> Minimum tokens per code block (default: 10)
--max-tokens <n> Maximum tokens per code block (default: 10000)
-l, --languages <langs...> Languages to include
-v, --verbose Show detailed output
-f, --force Force rebuild of existing indexnlci query
Query for similar code blocks.
nlci query [options]
Options:
-x, --index <path> Path to index file (default: ".nlci-index")
-f, --file <path> Query using code from a file
-c, --code <code> Query using inline code snippet
-t, --threshold <value> Minimum similarity threshold (default: 0.85)
-n, --limit <n> Maximum number of results (default: 10)
--type <type> Filter by clone type (1, 2, 3, 4)
--format <format> Output format: table, json, compact (default: table)
-v, --verbose Show detailed outputnlci report
Generate a code clone report.
nlci report [options]
Options:
-x, --index <path> Path to index file (default: ".nlci-index")
-o, --output <path> Output file path
-f, --format <format> Report format: console, json, html, markdown
-t, --threshold <value> Minimum similarity threshold (default: 0.85)nlci serve
Start a local API server for code similarity queries.
nlci serve [options]
Options:
-x, --index <path> Path to index file (default: ".nlci-index")
-p, --port <port> Port to listen on (default: 3000)
-h, --host <host> Host to bind to (default: localhost)API Endpoints:
GET /health- Health checkGET /stats- Index statisticsPOST /query- Query for similar codePOST /clones- Get all detected clones
nlci stats
Display index statistics.
nlci stats [options]
Options:
-x, --index <path> Path to index file (default: ".nlci-index")
--json Output as JSONConfiguration
NLCI looks for configuration in these locations (in order):
nlci.config.js/nlci.config.tsnlci.config.json.nlcirc/.nlcirc.jsonpackage.json(nlcifield)
Example Configuration
// nlci.config.js
module.exports = {
lsh: {
numTables: 20, // Number of hash tables (L)
numBits: 12, // Bits per hash (K)
dimension: 384, // Embedding dimension
},
embedding: {
model: 'sentence-transformers/all-MiniLM-L6-v2',
batchSize: 32,
maxLength: 512,
},
parser: {
minBlockSize: 10,
maxBlockSize: 10000,
includePatterns: ['**/*.ts', '**/*.js'],
excludePatterns: ['**/node_modules/**'],
},
};Clone Types
| Type | Similarity | Description | | ------ | ---------- | -------------------------------------------------- | | Type-1 | ≥99% | Exact clones (whitespace/comment differences only) | | Type-2 | 95-99% | Parameterized clones (identifier renaming) | | Type-3 | 85-95% | Near-miss clones (statement modifications) | | Type-4 | 70-85% | Semantic clones (different syntax, same logic) |
Performance
- Indexing: O(n) - Linear time to scan codebase
- Query: O(1) - Constant time lookups using LSH
- Memory: Efficient bucket-based storage
License
AGPL-3.0-or-later
