Skip to content

docs(plugin): list compaction hook result fields - #57276

Open
rekram1-node wants to merge 12 commits into
devfrom
plugin-compaction-docs
Open

rekram1-node wants to merge 12 commits into
devfrom
plugin-compaction-docs

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Problem

The plugin docs said a compaction hook's result "takes the same fields as a completed compaction message". That isn't true: it takes summary, metadata, native and tokens, and not reason, model or cost. They also didn't mention the two keys v2.1 gives meaning to: metadata.keepID and native.messages.

Change

The example now lists the optional result fields in comments, the way the other hook examples on that page keep internals out of the prose:

event.result = {
  summary: await summarize(event.messages),
  // Optional:
  // metadata: { keepID } - first message to keep verbatim after the summary; defaults to OpenCode's choice
  // native: { messages } - a provider replacement window, replayed instead of `summary` on the same model
  // tokens - usage of your summary request, included in session totals
}

Out of scope

packages/web/.../plugins.mdx (19 locales) lists session.compacted. Those pages document V1 plugins, where that event exists, so they stay as they are.

Verification

  • bunx prettier --check on the page: clean.
  • Checked each comment against packages/core/src/session/compaction.ts:
    • { keepID: split.keepID, ...result.metadata } lets the hook's value win;
    • fromHook records tokens through spend;
    • replay requires the compaction's provider ID and model ID to match.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant