From 5d43b5ed76cbf06109c4effb68828dc41a59abc7 Mon Sep 17 00:00:00 2001 From: ypshidifu Date: Sun, 20 Sep 2026 23:45:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20OpenCode=202.x=20Plugin=20API=EF=BC=8C=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=B1=BB=E5=9E=8B=E5=92=8C=20tool=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index da2079e..069333b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ /** - * OpenCode Plugin: Show All Sessions + * OpenCode 2.x Plugin: Show All Sessions * * This plugin provides /sessions-all command to show all sessions * regardless of the current working directory. */ -import { tool } from "@opencode-ai/plugin"; +import { type Plugin, tool } from "@opencode-ai/plugin"; import { exec } from "child_process"; import { promisify } from "util"; import { join } from "path"; @@ -47,7 +47,6 @@ function getDbPath(): string { async function getAllSessionsFromDb(): Promise { try { const dbPath = getDbPath(); - console.log(`[oc-session-all] Database path: ${dbPath}`); const query = ` SELECT id, project_id, directory, title, time_created, time_updated, cost @@ -102,7 +101,10 @@ function formatCost(cost: number): string { return `$${cost.toFixed(4)}`; } -export const OcSessionAll = async ({ project, client, $ }: any) => { +/** + * OpenCode 2.x Plugin + */ +export const OcSessionAll: Plugin = async ({ project, client, $, directory, worktree }) => { console.log("[oc-session-all] Plugin loaded"); return { @@ -110,7 +112,7 @@ export const OcSessionAll = async ({ project, client, $ }: any) => { "sessions-all": tool({ description: "显示所有项目的会话记录,绕过目录过滤限制。Show all sessions from all projects.", args: {}, - async execute() { + async execute(args, context) { const sessions = await getAllSessionsFromDb(); if (!sessions || sessions.length === 0) { @@ -119,16 +121,6 @@ export const OcSessionAll = async ({ project, client, $ }: any) => { let output = "=== 所有会话记录 (All Sessions) ===\n\n"; - // Group sessions by project - const byProject = new Map(); - for (const session of sessions) { - const key = session.project_id || "unknown"; - if (!byProject.has(key)) { - byProject.set(key, []); - } - byProject.get(key)!.push(session); - } - // Display sessions let index = 1; for (const session of sessions) {