npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-history-plugin

v1.0.0

Published

OpenCode plugin for searching and browsing conversation history from the local SQLite database

Readme

OpenCode 历史记录插件

一个 OpenCode 插件,提供从本地 SQLite 数据库搜索和浏览对话历史记录的工具。它让 AI 智能体可以回忆过去的讨论、决策和解决方案——充当长期记忆。

English

功能特性

  • 全文关键词搜索 — 使用 AND/OR 关键词匹配,搜索所有历史对话。
  • 会话浏览 — 通过会话 ID 查看完整的会话记录,支持从尾部截取。
  • 丰富的过滤条件 — 按角色(user/assistant)、会话 ID、工作区目录等过滤。
  • 上下文片段提取 — 默认显示关键词附近的上下文,也支持全文输出模式。
  • 分页支持 — 内置 limit/offset 分页,带总数提示。
  • 零配置 — 直接读取 OpenCode 的 SQLite 数据库(~/.local/share/opencode/opencode.db)。

安装

OpenCode 配置文件 中添加插件:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["opencode-history-plugin"]
}

OpenCode 会在下次启动时自动安装插件。

使用方法

工具 — history_search

通过关键词搜索历史对话消息。

参数:

| 参数 | 类型 | 默认值 | 说明 | | --------------- | -------- | --------- | ---- | | keyword | string[] | 必填 | 关键词列表,使用 SQL LIKE 匹配(%keyword%) | | match_mode | "AND" | "OR" | "AND" | 多关键词组合方式 | | role | "all" | "user" | "assistant" | "all" | 按消息角色过滤 | | limit | number | 20 | 最多返回条数(上限 200) | | offset | number | 0 | 跳过前 N 条结果,用于分页 | | session | string | "" | 限定在某个 session ID 内搜索 | | directory | string | "" | 限定工作区目录(支持 % 通配符) | | full | boolean | false | 输出完整文本而非片段 | | context_lines | number | 3 | 片段模式下关键词命中行前后各展示多少行 |

输出示例:

  1. [user]  2026-05-20 14:30:22  修复部署脚本
     ses_abc123
     ...我们尝试了 docker compose 但端口映射有问题...
     ...把健康检查间隔改成了 30 秒...

  2. [asst]  2026-05-20 14:32:10  修复部署脚本
     ses_abc123
     ...已更新 docker-compose.yml 的端口绑定...

工具 — history_view

查看指定会话的完整对话记录。

参数:

| 参数 | 类型 | 默认值 | 说明 | | ------------ | ------ | ------ | ---- | | session_id | string | 必填 | 会话 ID(如 ses_abc123) | | last | number | 0 | 只看最后 N 轮对话(0 = 全部) |

输出示例:

============================================================
  修复部署脚本
  /home/user/my-project
  2026-05-20 14:30:00   ses_abc123
============================================================

----------------------------------------------------------
  [1] user  2026-05-20 14:30:22

      部署一直失败...
----------------------------------------------------------
  [2] asst  2026-05-20 14:32:10

      我找到问题了——docker-compose.yml 里的端口映射...
----------------------------------------------------------

架构

  • 单文件 — 所有代码都在 index.ts 中,无需构建步骤。
  • 只读 SQLite — 通过 bun:sqlite 以只读模式打开 OpenCode 数据库。不写入,无风险。
  • SQL 注入安全 — 所有用户输入均通过参数化查询绑定传递。
  • PluginModule V1 — 使用标准的 export default { id, server() } 格式。
  • 纯 ESM — 项目使用 "type": "module",通过 Bun 原生执行 TypeScript。

环境要求

  • OpenCode 及 Bun 运行时
  • OpenCode SQLite 数据库位于 ~/.local/share/opencode/opencode.db

许可证

MIT