/** * ndomo — session_end custom tool. * * Mirror of the equivalent plugin tool in src/plugin.ts, exposed as a * standalone OpenCode custom tool. Opens its own DB connection and runs * migrations on first use. Use this when you want DB access from outside * the plugin (e.g. from agents that don't load the plugin). */ import { tool } from "@opencode-ai/plugin"; import { closeDb, endSession, openDb, resolveProjectDir, runMigrations } from "ndomo/db"; export default tool({ description: "Mark a session as ended. Sets ended_at to the current timestamp.", args: { id: tool.schema.string() }, execute: async (args, ctx) => { const projectDir = resolveProjectDir(ctx); const db = openDb(projectDir); runMigrations(db); try { return JSON.stringify(endSession(db, args.id)); } finally { closeDb(db); } }, });