Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"exports": {
".": {
"import": "./src/index.js"
}
},
"./package.json": "./package.json"
},
"bin": {
"codegraph": "./src/cli.js"
Expand Down
7 changes: 3 additions & 4 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import fs from 'node:fs';
import path from 'node:path';
import Database from 'better-sqlite3';
import { Command } from 'commander';
import { buildGraph } from './builder.js';
import { loadConfig } from './config.js';
import { findCycles, formatCycles } from './cycles.js';
import { findDbPath } from './db.js';
import { openReadonlyOrFail } from './db.js';
import { buildEmbeddings, EMBEDDING_STRATEGIES, MODELS, search } from './embedder.js';
import { exportDOT, exportJSON, exportMermaid } from './export.js';
import { setVerbose } from './logger.js';
Expand Down Expand Up @@ -275,7 +274,7 @@ program
.option('--min-confidence <score>', 'Minimum edge confidence threshold (default: 0.5)', '0.5')
.option('-o, --output <file>', 'Write to file instead of stdout')
.action((opts) => {
const db = new Database(findDbPath(opts.db), { readonly: true });
const db = openReadonlyOrFail(opts.db);
const exportOpts = {
fileLevel: !opts.functions,
noTests: resolveNoTests(opts),
Expand Down Expand Up @@ -314,7 +313,7 @@ program
.option('--include-tests', 'Include test/spec files (overrides excludeTests config)')
.option('-j, --json', 'Output as JSON')
.action((opts) => {
const db = new Database(findDbPath(opts.db), { readonly: true });
const db = openReadonlyOrFail(opts.db);
const cycles = findCycles(db, { fileLevel: !opts.functions, noTests: resolveNoTests(opts) });
db.close();

Expand Down
8 changes: 8 additions & 0 deletions src/embedder.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ export async function buildEmbeddings(rootDir, modelKey, customDbPath, options =
const strategy = options.strategy || 'structured';
const dbPath = customDbPath || findDbPath(null);

if (!fs.existsSync(dbPath)) {
console.error(
`No codegraph database found at ${dbPath}.\n` +
`Run "codegraph build" first to analyze your codebase.`,
);
process.exit(1);
}

const db = new Database(dbPath);
initEmbeddingsSchema(db);

Expand Down