Skip to content

fix(skills): replace sqlite3 CLI with in-tree better-sqlite3 wrapper - #2309

Merged
gavrielc merged 2 commits into
nanocoai:mainfrom
glifocat:fix/skills-drop-sqlite3-cli-dep
May 6, 2026
Merged

gavrielc merged 2 commits into
nanocoai:mainfrom
glifocat:fix/skills-drop-sqlite3-cli-dep

Conversation

@glifocat

@glifocat glifocat commented May 6, 2026

Copy link
Copy Markdown
Collaborator

Type of Change

  • Feature skill - adds a channel or integration (source code changes + SKILL.md)
  • Utility skill - adds a standalone tool (code files in .claude/skills/<name>/, no source changes)
  • Operational/container skill - adds a workflow or agent skill (SKILL.md only, no source changes)
  • Fix - bug fix or security fix to source code
  • Simplification - reduces or simplifies source code
  • Documentation - docs, README, or CONTRIBUTING changes only

Description

13 skills + migrate-v2.sh shelled out to the sqlite3 CLI binary even though host setup deliberately avoids it (setup/verify.ts:5: "Uses better-sqlite3 directly (no sqlite3 CLI)") and never installs or probes for it. On hosts where sqlite3 isn't preinstalled (e.g. fresh Ubuntu — see #2191), every one of those calls fails or silently misbehaves. macOS hides the bug since Apple ships /usr/bin/sqlite3.

Closes #2191.

Changes:

  • New scripts/q.ts — ~30 LOC wrapper over the better-sqlite3 dep setup already installs and verifies. Default output matches sqlite3 -list (pipe-separated, no header) so skill text reads identically; only the binary changes. SELECT/WITH go through db.prepare().all(); everything else (including compound mutations) through db.exec().
  • 17 hardcoded invocations migrated across 8 SKILL.md files + add-deltachat/VERIFY.md (init-first-agent, add-deltachat, add-signal, add-emacs, add-whatsapp, add-ollama-provider, debug, add-parallel).
  • manage-channels/SKILL.md showed canonical SQL but never prescribed a tool — the assistant defaulted to sqlite3 and silently failed. Added a one-line wrapper hint above the SQL block.
  • migrate-v2.sh schema/count probes routed through the wrapper (.tables rewritten as SELECT name FROM sqlite_master ...), which was the original failure documented in migrate-v2.sh: misleading 'registered_groups missing' error when sqlite3 CLI not installed #2191.
  • Wrapper convention documented in root CLAUDE.md under "Central DB".
  • 6 vitest cases in scripts/q.test.ts; scripts/**/*.test.ts wired into vitest.config.ts.

Out of scope, flagged for follow-up:

  • debug/SKILL.md and add-parallel/SKILL.md still reference v1-only store/messages.db. Routing through the wrapper now produces a cleaner "no such file" error, but the surrounding sections are v1-era throughout — a v1-content cleanup is its own PR.
  • cleanup-sessions.sh is being addressed in fix(cleanup-sessions): hard-fail when sqlite3 is missing or the query errors #1889 (different style: hard-fail with install hint, rather than wrap). Left untouched here to avoid stepping on that author's work.

Test plan:

  • pnpm test — 263 passed (was 257; +6 from scripts/q.test.ts)
  • pnpm typecheck — clean
  • bash -n migrate-v2.sh — clean
  • grep -rn "sqlite3 " .claude/skills migrate-v2.sh CLAUDE.md — no remaining direct invocations
  • Smoke test against a real data/v2.db: pnpm exec tsx scripts/q.ts data/v2.db "SELECT name FROM sqlite_master WHERE type='table'" returns the expected table list.

For Skills

N/A — no new skill added. 9 existing SKILL.md files were edited mechanically (sqlite3 → wrapper substitution); structure, length, and code/instructions split unchanged.

🤖 Generated with Claude Code

Setup deliberately avoids the sqlite3 CLI (`setup/verify.ts:5` calls
this out: "Uses better-sqlite3 directly (no sqlite3 CLI)") and never
installs or probes for the binary. Despite that, 13 skills shelled out
to `sqlite3 ...` directly, breaking on hosts where the CLI isn't
preinstalled — the same root cause as nanocoai#2191 but spread across the
skill surface.

Add `scripts/q.ts`, a ~30-LOC wrapper over the `better-sqlite3` dep
that setup already installs and verifies. Default output matches
`sqlite3 -list` (pipe-separated, no header) so existing skill text
reads identically — only the binary changes. SELECT/WITH queries go
through `db.prepare().all()`; everything else (INSERT/UPDATE/DELETE,
including compound statements) goes through `db.exec()`.

Migrate every in-tree caller:

- 17 hardcoded invocations across 8 SKILL.md files (init-first-agent,
  add-deltachat, add-signal, add-emacs, add-whatsapp, add-ollama-provider,
  debug, add-parallel) plus add-deltachat/VERIFY.md.
- `manage-channels/SKILL.md` shows canonical SQL but never prescribed
  a tool, so the assistant defaulted to `sqlite3` and silently failed.
  Add a one-line wrapper hint above the SQL block.
- `migrate-v2.sh` schema/count probes (was the original nanocoai#2191 case).
  Replace `.tables` with `SELECT name FROM sqlite_master`.
- Document the wrapper convention in root `CLAUDE.md` under "Central DB".

Add `scripts/q.test.ts` with 6 vitest cases covering both modes,
NULL rendering, empty-result, compound mutations, and arg validation.
Wire `scripts/**/*.test.ts` into `vitest.config.ts`.

Out of scope (flagged for follow-up):
- `debug` and `add-parallel` still reference the v1-only path
  `store/messages.db`. Routing through the wrapper now produces a
  cleaner "no such file" error, but the surrounding sections are
  v1-era throughout — a v1-content cleanup is its own PR.
- `cleanup-sessions.sh` is being addressed in nanocoai#1889 (different style,
  hard-fail rather than wrap); left untouched here to avoid stepping
  on that author's work.

Closes nanocoai#2191.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added follows-guidelines PR was created using the current contributing template PR: Fix Bug fix labels May 6, 2026
…T detection

The first-keyword check (`WITH` → SELECT path) was wrong for CTEs that
precede mutations (e.g. `WITH stale AS (...) DELETE FROM t WHERE ...`).
These would be routed through `db.prepare().all()` instead of executing
the mutation.

Use better-sqlite3's `stmt.reader` property, which asks SQLite's own
parser whether the statement returns data. Single mutations go through
`stmt.run()`; compound statements (which `prepare()` rejects) fall back
to `db.exec()`.

Add a regression test for WITH...DELETE.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gavrielc
gavrielc merged commit aff3f58 into nanocoai:main May 6, 2026
1 check passed
cianwhalley pushed a commit to cianwhalley/nanoclaw that referenced this pull request May 26, 2026
…3-cli-dep

fix(skills): replace sqlite3 CLI with in-tree better-sqlite3 wrapper
@glifocat
glifocat deleted the fix/skills-drop-sqlite3-cli-dep branch September 20, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

follows-guidelines PR was created using the current contributing template PR: Fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate-v2.sh: misleading 'registered_groups missing' error when sqlite3 CLI not installed

2 participants