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

@jochenyang/coda

v0.2.0

Published

Conversation context manager for OpenCode — automatic archival, tool output pruning, and smart recall for long-running sessions

Readme


coda 自动帮你打理 OpenCode 对话上下文:每轮修剪过时的工具输出,上下文压力到 80% 时自动归档+裁切旧消息,并通过智能召回"回忆"之前的内容。无需输入任何 / 命令,一行配置即可在后台静默运行。


为什么需要 coda

| 痛点 | 解决方案 | |------|----------| | 上下文窗口很快被撑满 | 每轮自动修剪过时工具输出的长文本,释放 token | | AI 记不住之前聊过什么 | 归档块保留摘要,coda-decompress 可随时找回原文 | | 长会话碰到模型上下文上限 | 压力到 80% 时自动归档、裁切,让出空间继续开发 | | 多会话之间没有连续性 | Smart recall 自动根据话题匹配注入相关归档块 | | 系统内置压缩不可逆 | 归档内容随时可恢复,决策记录和代码评审不会丢 |


工作原理

每轮对话,coda 在 OpenCode 插件管线中运行以下步骤:

messages.transform(每轮运行)
  │
  ├─ Step 2.75  修剪保护尾之外的工具输出
  │             (跳过 edit/write/question,缩短长结果)
  │
  ├─ Step 3     如果上下文压力 ≥80%:
  │               → 归档最旧消息为可恢复块
  │               → 裁切已归档的原始消息
  │               → 注入一行说明
  │
  ├─ Step 5     Smart recall:自动注入相关归档块
  │             (每 5 轮或系统压缩后触发)
  │
  └─ Step 9     持久化状态

压力 <80% 时:仅工具输出修剪在后台运行——完全静默,零打扰。

压力 ≥80% 时:归档+裁切一步完成——先于系统内置压缩(~85%)处理,保证可逆性。


AI 工具接口

| 工具 | 用途 | |------|---------| | coda-archive | 手动归档已完成对话段(AI 生成摘要) | | coda-decompress | 按 ID 恢复指定归档块的完整内容 | | coda-context | 遍历/搜索所有归档块 |


安装方式

npm install @jochenyang/coda

在 OpenCode 配置中注册:

// ~/.config/opencode/opencode.json
{
  "plugin": [
    "@jochenyang/coda"
  ]
}

无需额外构建步骤。 OpenCode 直接从安装的包中加载插件。


构建与发布

# 安装依赖
npm install

# 类型检查
npm run typecheck

# 运行测试(161 个)
npm test

# 构建分发包
npm run build             # → dist/index.js + dist/index.d.ts

# 发布到 npm
npm publish

使用 tsup 打包为单个 ESM 文件并生成类型声明。@opencode-ai/plugin@anthropic-ai/tokenizer 标记为 external,运行时由 OpenCode 解析。


项目结构

├── src/
│   ├── index.ts          # 插件入口——工具注册 + 变换管线
│   ├── state.ts          # 状态持久化(读/写/迁移)+ 类型定义
│   ├── compress.ts       # 块创建、自动归档、状态更新
│   ├── condense.ts       # 三级块降级(L1→L2→L3)
│   ├── prompts.ts        # 系统提示扩展模板
│   ├── messages.ts       # 消息裁剪、工具输出修剪、消息 ID
│   ├── recall.ts         # 智能上下文注入 + compaction 钩子
│   ├── scorer.ts         # 关键词提取 + 块相关性评分
│   ├── protect.ts        # 块/消息保护(基于轮次、话题)
│   ├── notification.ts   # 忽略消息通知辅助函数
│   └── *.test.ts         # 每个模块的 Vitest 测试(161 个)
├── dist/                 # 构建输出(由 tsup 生成)
├── package.json
├── tsconfig.json
├── tsup.config.ts
├── vitest.config.ts
├── LICENSE
├── README.md
└── README.zh.md

配置参数

关键常量定义在 src/state.ts 中:

| 常量 | 默认值 | 说明 | |---|---|---| | CONTEXT_PRESSURE_RATIO | 0.8 | 触发归档+裁切的上下文压力阈值(80%) | | PROTECTED_MESSAGE_COUNT | 12 | 最近 N 条消息永不裁切或修剪 | | PROTECTED_TURNS | 3 | 最近 N 轮对话免于归档 | | MAX_INJECTION_TOKENS | 4000 | 压缩后上下文注入的最大 token 数 | | SMART_INJECTION_TOKENS | 2000 | 智能召回注入的最大 token 数 |


状态存储

状态文件按项目、按会话隔离存储:

~/.config/opencode/plugins/coda/state/<项目名>/<会话ID>.json

写操作通过 per-session 串行 Promise 队列执行,避免读写竞争。


许可

MIT — 详见 LICENSE