ruvnet / ruvnet/agentdb

doctor command: db.get() is not a valid better-sqlite3 API, and ESM require() misreports core modules as "not available"

Open
#23 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
89
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Confirmed on 3.0.0-alpha.20 (current npm latest at time of filing). Two independent bugs in dist/cli/commands/doctor.js.

Bug 1 — wrong better-sqlite3 API, fails every real database

doctor.js line 84:

const config = db.get('SELECT * FROM config WHERE key = ?', ['initialized']);

better-sqlite3's Database instance has no .get() method — the real API is db.prepare(sql).get(...params). This throws TypeError: db.get is not a function immediately, caught by the outer try/catch and reported as:

❌ Database error: db.get is not a function

...on every database, regardless of actual health. Same issue at line 92 (db.get(\SELECT COUNT(*) as count FROM ${table}`)`).

A second, independent problem in the same query: even with the correct API, SELECT * FROM config assumes a config table that doesn't exist in the schema AgentDB itself creates. Verified against a real, populated agentdb.db — 28 real tables (episodes, skills, causal_edges, learning_sessions, recall_certificates, etc.), none named config.

Bug 2 — require() used in an ESM file, misreports fs/path/crypto as missing

package.json declares "type": "module", and doctor.js itself opens with import { createDatabase } from '../../db-fallback.js'; — genuinely ESM. Lines ~148-158:

for (const mod of coreModules) {
    try { require(mod.module); ... }
    catch { console.log(`  ❌ ${mod.name} not available`); }
}

In ESM, bare require is undefined — this throws ReferenceError: require is not defined, caught and misreported as "fs/path/crypto not available," even though these are always-present Node builtins. The same require(...) pattern appears again around line 246 for the optional @xenova/transformers check — likely the same root cause, just less obviously wrong there since "not installed" happens to still read as a plausible message.

Repro

agentdb doctor

against any real, populated database.

Impact

doctor reports ❌ System Status: ISSUES DETECTED on fully healthy installations — actively misleading for anyone using it to diagnose real problems.

Suggested fix

  • Replace db.get(sql, params) with db.prepare(sql).get(...params), and drop or rewrite the config table check to match the actual schema.
  • Replace the require() core-module probe with import(mod.module) (or just remove it — these are guaranteed-present builtins).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with dist/cli/commands/doctor.js and package.json, then inspect the schema AgentDB creates to compare it with the checks in doctor. Reproduce with agentdb doctor against a populated database; done means healthy installations no longer report database or Node core-module errors, while the optional transformer check remains meaningful.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, sqlite
Domain
cli, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.