Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ Rule of thumb: lasting always-on project instructions → `AGENTS.md`; growing w
- Optional HTTP catalog for other OpenCode instances: `"skills": ["http://127.0.0.1:4747/skills/"]` (serves `/skills/index.json` and `/skills/<id>/<id>.md` — separate from the UI path).
- REST: `GET/POST /api/skills`, `GET/PUT/DELETE /api/skills/:id`.

### Health stats

The web UI's **Stats** tab (at `/stats`) shows memory-system health at a glance: totals per scope, per-shard memory counts with stale/missing-shard warnings and a same-tag duplication proxy, the active user-profile version, and a 14-day activity series (captures, skipped captures, profile/compaction injections, and errors bucketed by message) parsed from the plugin's own structured logs in `~/.opencode-mem/`. It is read-only — `GET /api/stats` — and degrades per section if a database is unavailable, so it keeps reporting during incidents.

### Intelligent prompt-based memory extraction

That phrase in the feature list is **auto-capture**: after a conversation, a background AI request summarizes technical work and saves it as memory. No special prompt from you is required. It uses `opencodeProvider` / `opencodeModel` when set, otherwise the manual `memoryProvider` fallback.
Expand Down
61 changes: 43 additions & 18 deletions src/services/api-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import type { UserProfileData } from "./user-profile/types.js";
import { sortProfileItems } from "../utils/profile.js";
import { toPublicProfileData } from "./user-profile/profile-utils.js";
import type { ShardInfo } from "./turso/types.js";
import {
collectDailyStats,
collectProfileStats,
collectShardStats,
type CollectDailyStatsOptions,
} from "./stats-service.js";

async function getAllMemoryShards(): Promise<ShardInfo[]> {
await ensureTursoReady();
Expand Down Expand Up @@ -793,37 +799,56 @@ export async function handleSearch(
}
}

export async function handleStats(): Promise<
export async function handleStats(
options: Pick<CollectDailyStatsOptions, "logDir" | "now"> & { probe?: boolean } = {}
): Promise<
ApiResponse<{
total: number;
byScope: { user: number; project: number };
byType: Record<string, number>;
generatedAt: string;
shards: Awaited<ReturnType<typeof collectShardStats>>["shards"];
profile: Awaited<ReturnType<typeof collectProfileStats>>;
daily: ReturnType<typeof collectDailyStats>;
dailyError?: string;
}>
> {
try {
// Ownership/liveness probes must stay cheap: auth already ran, do not open
// shards or scan logs under the 2s checkServerAvailable timeout.
if (options.probe) {
return { success: true };
}

// Stats only counts Turso/libSQL rows; no embedding needed.
// See handleListTags comment - keep embedding init out of read paths.
const shards = await getAllMemoryShards();
let userCount = 0,
projectCount = 0;
const typeCount: Record<string, number> = {};
for (const shard of shards) {
const db = await tursoConnectionManager.getConnection(shard.dbPath);
const memories = await tursoVectorSearch.getAllMemories(db);
for (const r of memories) {
const containerTag = String(r.container_tag ?? "");
const type = r.type ? String(r.type) : "";
if (containerTag.includes("_user_")) userCount++;
else if (containerTag.includes("_project_")) projectCount++;
if (type) typeCount[type] = (typeCount[type] || 0) + 1;
}
// Shard listing failures stay hard errors so /api/stats consumers (explorer
// header total) never treat an empty total as a successful empty store.
const memoryShards = await getAllMemoryShards();
const [shardStats, profile] = await Promise.all([
collectShardStats(memoryShards),
collectProfileStats(),
]);

let daily: ReturnType<typeof collectDailyStats> = [];
let dailyError: string | undefined;
try {
daily = collectDailyStats(options);
} catch (error) {
dailyError = error instanceof Error ? error.message : String(error);
}

return {
success: true,
data: {
total: userCount + projectCount,
byScope: { user: userCount, project: projectCount },
byType: typeCount,
total: shardStats.total,
byScope: shardStats.byScope,
byType: shardStats.byType,
generatedAt: new Date().toISOString(),
shards: shardStats.shards,
profile,
daily,
...(dailyError ? { dailyError } : {}),
},
};
} catch (error) {
Expand Down
Loading
Loading