Scope skill usage to request profile

This commit is contained in:
ekko
2026-05-24 08:48:40 +08:00
committed by ekko
parent f372d0a905
commit 4db3940e65
3 changed files with 67 additions and 2 deletions
@@ -7,8 +7,13 @@ import {
} from '../../services/config-helpers'
import { pinSkill } from '../../services/hermes/hermes-cli'
import { isPathWithin } from '../../services/hermes/hermes-path'
import { getActiveProfileName } from '../../services/hermes/hermes-profile'
import { getSkillUsageStatsFromDb } from '../../db/hermes/sessions-db'
function requestedProfile(ctx: any): string {
return ctx.state?.profile?.name || getActiveProfileName() || 'default'
}
/** Read bundled manifest as a name→hash map from ~/.hermes/skills/.bundled_manifest */
function readBundledManifest(manifestContent: string | null): Map<string, string> {
const map = new Map<string, string>()
@@ -284,7 +289,7 @@ export async function usageStats(ctx: any) {
const days = Number.isFinite(rawDays) && rawDays > 0 ? Math.min(rawDays, 365) : 7
try {
ctx.body = await getSkillUsageStatsFromDb(days)
ctx.body = await getSkillUsageStatsFromDb(days, undefined, requestedProfile(ctx))
} catch (err: any) {
ctx.status = 500
ctx.body = { error: `Failed to read skill usage stats: ${err.message}` }
+2 -1
View File
@@ -953,11 +953,12 @@ function formatUnixDate(timestamp: number | null): string {
export async function getSkillUsageStatsFromDb(
days = 7,
nowSeconds = Math.floor(Date.now() / 1000),
profile?: string,
): Promise<HermesSkillUsageStats> {
const normalizedDays = Number.isFinite(days) ? days : 7
const safeDays = Math.max(1, Math.floor(normalizedDays))
const since = nowSeconds - safeDays * 24 * 60 * 60
const db = await openSessionDb()
const db = await openSessionDb(profile)
try {
const hasStartedIndex = db.prepare("PRAGMA index_list(sessions)").all()