fix(plugin): port to OpenCode V2 session hooks

未关闭
#1 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
bun, typescript

调研方向

Start by locating the plugin's setup function and its compaction hook, then compare the callback shape with the OpenCode V2 contract described in the issue. Trace how session directories and the two configuration paths are resolved, and review the hook tests for deduplication, durable instructions, and error handling. Done means bun test passes and the isolated E2E checks in the issue succeed.

由索引模型根据 Issue 内容生成。

描述

Problem

0.1.11 never re-injects AGENTS.md. It registers ctx.session.hook("compaction", ...) and mutates event.context / event.options.context / event.prompt. In OpenCode V2 (verified on 2.2.5) ctx.session.hook exists but the callback receives one mutable event with system, messages, and options — none of the mutated fields above, so the hook is a silent no-op.

Additionally, the V1-style setup() that returns a hooks object (instead of registering hooks and returning a cleanup function) can break plugin loading on a shared opencode serve.

Evidence

  • V2 docs: compaction runs for checkpoint summaries; inject context by pushing into event.system; context runs before every agent model request.
  • opencode plugin list and the binary contract: Expected plugin to have a non-empty name / setup() function.

Fix

  • compaction hook: push a bounded full AGENTS.md block into event.system so the summary preserves the mandates.
  • context hook: push a bounded digest every request and record a durable session instruction entry (session.instructions.entry.put, once per session) so the rules survive compaction.
  • Resolve AGENTS.md from the session directory upward, then ~/.config/opencode/AGENTS.md, then ~/.config/opencode/prompts/AGENTS.md.
  • Skip injection when the system prompt already carries the file (avoid duplication with native instructions).
  • Wrap every hook in try/catch: a plugin failure must never break model resolution or a request.
  • Unit tests for hooks, dedupe, durable entry, resolution and error swallowing.

Verification

  • bun test: 13 pass.
  • Isolated E2E (OPENCODE_CONFIG_DIR, --standalone, mock OpenAI server): model answers; digest present on every request; full rules present in the compaction request; post-compaction request carries the digest.
主要语言
TypeScript
星标
0
派生
0
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。