import type { ActivateContext } from "@idea/plugin-sdk"; import { STORAGE_KEYS } from "../constants.js"; export async function initializePluginStorage(ctx: ActivateContext): Promise { if (!ctx.storage) { ctx.logger.warn("plugin-owned storage unavailable"); return; } const activationCount = await incrementStoredNumber(ctx, STORAGE_KEYS.activationCount); const initialized = await ctx.storage.get(STORAGE_KEYS.initialized); if (!initialized) { await ctx.storage.set(STORAGE_KEYS.initialized, true); } ctx.logger.info("plugin-owned storage ready", { activationCount, initialized: initialized ?? false }); } export async function recordCommandRun(ctx: ActivateContext): Promise { if (!ctx.storage) return undefined; return incrementStoredNumber(ctx, STORAGE_KEYS.commandRunCount); } async function incrementStoredNumber(ctx: ActivateContext, key: string): Promise { const current = await ctx.storage?.get(key); const next = typeof current === "number" && Number.isFinite(current) ? current + 1 : 1; await ctx.storage?.set(key, next); return next; }