fix(plugin): port to OpenCode V2 session hooks

Aperta
#1 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bun, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
TypeScript
Stelle
0
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.