Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

2.2 KB
Raw Blame
/**
 * Can this daemon read the SQLite stores at all?
 *
 * Four engines keep their conversations in SQLite rather than in a transcript file
 * (`engines/{opencode,kilo,hermes,devin}/reader.ts`), as does one branch of session repair. They read
 * through `lib/sqliteRead`: `node:sqlite` when this Node has it (the installers' Node does), else the
 * `sqlite3` CLI. macOS ships `/usr/bin/sqlite3` in the base system; a stock `ubuntu:24.04` does NOT
 * (measured), and neither does a slim Node image — so on Linux, on a Node without the binding, those
 * four engines silently mirror nothing until the user installs it.
 *
 * Resolved from PATH directly rather than by spawning: this runs on the startup path and the answer is
 * only used for one advisory log line. The history purge writes through `node:sqlite` too, and falls back to
 * the CLI only on a Node without it. The opencode store rewrite (`kit/nativeSessionModel.ts`) runs the CLI
 * first, whose wait for opencode's lock is not the daemon's, and `node:sqlite` only where no CLI is on PATH.
 */
import { binaryOnPath } from './binaryOnPath.js'
import { builtinSqlite } from './sqliteBuiltin.js'
import { SQLITE_BACKED_ENGINES } from './sqliteRead.js'

let cached: boolean | null = null

export function hasSqliteCli(): boolean {
  if (cached !== null) return cached
  cached = binaryOnPath('sqlite3')
  return cached
}

/** Either way to read a store will do. */
export function hasSqliteReader(): boolean {
  return builtinSqlite() !== null || hasSqliteCli()
}

/** One advisory line at startup. Says what is affected and exactly how to fix it — never throws. */
export function sqlitePreflightMessage(): string | null {
  if (hasSqliteReader()) return null
  const install = process.platform === 'linux'
    ? 'sudo apt install sqlite3   (or your distro\'s equivalent)'
    : 'install the sqlite3 CLI and make sure it is on PATH'
  return `[preflight] no SQLite reader (this Node has no node:sqlite, and no sqlite3 CLI on PATH) — ${SQLITE_BACKED_ENGINES.join(', ')}`
    + ` agents cannot be mirrored. Every other engine is unaffected. Fix: ${install}`
}

/** Test seam: forget the cached answer. */
export function resetSqliteAvailabilityCache(): void { cached = null }