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-prompt-recorder

v1.9.9

Published

OpenCode plugin for recording user prompts. Automatically saves user messages to a local file system with organized directory structure.

Downloads

3,684

Readme

opencode-prompt-recorder

一个用于记录用户提示词和 AI 问答的 OpenCode 插件。自动将用户消息、AI 响应(含模型、Token、TPS 元数据)以及 AI 的问题工具交互保存到本地文件系统,并按目录结构组织。

功能特性

  • ✨ 自动捕获聊天对话中的用户提示词
  • ✨ 记录 AI 的完整响应(含模型、Token 消耗、TPS 速度指标)
  • ✨ 记录 AI 的 question 工具交互(提问和用户回答)
  • 📁 有组织的文件存储:.prompts/yyyy/MM/dd/ 目录结构
  • 🔗 同一 session 的消息自动合并到同一个文件
  • 📝 丰富的元数据:包含会话 ID、日期时间戳、模型信息、TPS 和提示词主题
  • 🛡️ 安全的文件名处理:清理文件名以防止文件系统错误

安装

npm install -g opencode-prompt-recorder
# 或
bun add -g opencode-prompt-recorder

使用方法

将插件添加到你的 opencode.json

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

工作原理

  1. 插件监听 OpenCode 事件(message.updatedmessage.part.updatedsession.createdsession.updated
  2. 每次用户消息时,提取提示词文本和会话 ID
  3. AI 响应时,记录完整回答文本,并从 message.updated 事件提取模型、Token 消耗和响应时间,自动计算 TPS(Token/秒)
  4. 当 AI 通过 question 工具向用户提问时,提问内容和用户回答一并记录
  5. 同一 session 的消息合并到同一个文件,按日期组织存储
  6. 文件首行记录 SessionID,每条消息带有时间戳和元数据

文件内容格式

记录内容分为三类:

用户消息:

============ 2026-06-05 10:05:30 ============

什么是 AI?

AI 响应:

<<<<<<<<<<<< 2026-06-05 10:05:35 | Model: openai/gpt-4o | In: 45 | Out: 128 | R: 10 | TPS: 25.6 <<<<<<<<<<<<

AI 认为人工智能是一种模拟人类智能的技术……

Question 工具问答:

============ 2026-06-05 10:50:15 ============

[Question Tool]
Q: 你更喜欢哪个选项?
  Options: A, B, C
A: A

文件结构

插件创建有组织的目录结构:

.prompts/
    └── 2026/
        └── 06/
            └── 05/
                ├── 260605094300-什么是AI.txt
                └── 260605112000-复制README.txt

文件名格式

每个提示词文件遵循以下格式:yyMMddHHmmss-{主题}.txt

  • yyMMddHHmmss - 首条消息的创建时间(年-月-日-时-分-秒)
  • {主题} - 会话标题的前 40 个字符(已净化);标题不存在时回退到首条消息文本
    • 若文件创建后会话标题才到达,文件会被自动重命名:
      • session.updated 事件触发时立即重命名
      • 若事件先于文件创建到达(竞态),暂存待处理,文件创建后立即应用
      • 创建后 5 秒自动通过 SDK 查询最新标题,兜底修正

配置

无需额外配置。插件将自动:

  • 保存到项目根目录的 .prompts/ 目录
  • 使用当前工作目录作为基础路径
  • 根据需要创建目录

文件命名

  • 主题优先从会话标题提取;标题不存在时回退到首条用户消息的第一行
  • 若文件创建后会话标题才到达,文件会被自动重命名以匹配标题(session.updated 事件 + 待处理队列 + 5 秒 SDK 查询兜底)
  • 同一 session 的后续消息追加到同一文件,文件名不变
  • 文件名中的特殊字符会被自动清理(移除 <>:"/\|?* 及控制字符)
  • 文件名截断至最多 40 个字符
  • 若目标文件名已存在(极低概率),自动附加 -xxxx 随机后缀以避免覆盖

使用场景

  • ✅ LLM 交互的审计跟踪
  • ✅ 训练数据收集和标注
  • ✅ 会话历史和对话回放
  • ✅ 质量保证和监控
  • ✅ 研发洞察

依赖要求

  • OpenCode v0.15.0 或更高版本
  • Node.js 或 Bun 运行时
  • 项目目录的文件系统写入权限

故障排除

提示词未被记录

  • 确保插件已列入 opencode.json 配置
  • 检查项目目录的写入权限
  • 验证 .prompts/ 目录正在创建

文件名包含特殊字符

  • 插件会自动清理文件名,移除非法字符
  • 文件名截断至最多 40 个字符
  • 如果提示词过长,文件名只使用前 40 个字符

许可证

MIT