Skip to content

Commit 1047bca

Browse files
committed
fix(hermes): share sqlite availability detection
Centralize the adapter-level SQLite availability check so SQLite-backed agents do not duplicate runtime probing logic. Hermes now requires a readable SQLite runtime before reporting a state database as detected. OpenCode keeps its JSON fallback path while only treating database files as usable when SQLite support is present.
1 parent 735ee36 commit 1047bca

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎apps/ccusage/src/adapter/hermes/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { getSqliteDatabaseFactory, withSqliteDatabase } from '@ccusage/internal/
66
import { createFixture } from 'fs-fixture';
77
import { logger } from '../../logger.ts';
88
import { createAgentPricingContext, defineAgentLogLoader } from '../shared.ts';
9+
import { hasReadonlySqliteSupport } from '../sqlite.ts';
910
import { loadHermesUsageEntries } from './parser.ts';
1011
import { detectHermesStateDb } from './paths.ts';
1112
import { calculateHermesCost } from './pricing.ts';
1213

1314
export async function detectHermes(): Promise<boolean> {
14-
return detectHermesStateDb();
15+
return hasReadonlySqliteSupport() && detectHermesStateDb();
1516
}
1617

1718
function createHermesPricingContext(

‎apps/ccusage/src/adapter/opencode/paths.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Result } from '@praha/byethrow';
77
import { createFixture } from 'fs-fixture';
88
import { logger } from '../../logger.ts';
99
import { getExistingDirectories, normalizePathList } from '../path-list.ts';
10+
import { hasReadonlySqliteSupport } from '../sqlite.ts';
1011

1112
const DEFAULT_OPENCODE_PATH = path.join(homedir(), '.local/share/opencode');
1213
export const OPENCODE_CONFIG_DIR_ENV = 'OPENCODE_DATA_DIR';
@@ -113,7 +114,7 @@ export async function detectOpenCodeSources(openCodePath: string): Promise<boole
113114
OPENCODE_MESSAGES_DIR_NAME,
114115
);
115116
return (
116-
hasOpenCodeDatabase(openCodePath) ||
117+
(hasReadonlySqliteSupport() && hasOpenCodeDatabase(openCodePath)) ||
117118
(await hasFileRecursive(messagesDir, { extension: '.json' }))
118119
);
119120
}

‎apps/ccusage/src/adapter/sqlite.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import type { SqliteDatabase } from '@ccusage/internal/sqlite';
2-
import { withSqliteDatabase } from '@ccusage/internal/sqlite';
2+
import { getSqliteDatabaseFactory, withSqliteDatabase } from '@ccusage/internal/sqlite';
33
import { Result } from '@praha/byethrow';
44
import { logger } from '../logger.ts';
55

6+
export function hasReadonlySqliteSupport(): boolean {
7+
return getSqliteDatabaseFactory(logger.warn) != null;
8+
}
9+
610
export function loadReadonlySqliteRows<T>(
711
dbPath: string | null | undefined,
812
errorMessage: string,

0 commit comments

Comments
 (0)