Dashboard › opencode › Distillation
f9aef09b-a8d6-4a26-83fe-bf1e4ebf937d["lore_tm_v1_p2b4ZxXuLHt9l3Q1WOGUis-bCnMUFTnIeP-TFHDoR80","lore_tm_v1_pH4nsaUvIOP9AU_eMmM5YW77K7OQxIq3oFhH9Of1rNI","lore_tm_v1_Sq1-4wM30IGvIICKMl2QY9Xqivtsyad_fUVK0ZHBMjM"]
/home/byk/Code/opencode-lore-v2/packages/gateway/src/compaction.ts: line 374 defines LORE_AGENT_HEADER, line 441 defines isMetaRequest(req: GatewayRequest): boolean, and line 446 reads req.rawHeaders[LORE_AGENT_HEADER].packages/gateway/src/compaction.ts, LORE_AGENT_HEADER is exactly "x-lore-agent"; the OpenCode plugin injects this header to identify the calling agent.x-lore-agent matches a primary conversation agent, it is “always a normal turn.” PRIMARY_AGENTS contains "coder" and "code", and isMetaRequest() returns false for them.x-lore-agent matches a known meta/housekeeping agent, it is “always passthrough.” META_AGENTS contains "title", "summary", "summarize", "categorize", "label", and "classify", and isMetaRequest() returns true for them.isMetaRequest() in packages/gateway/src/compaction.ts uses two detection layers: 1. the authoritative explicit x-lore-agent header; 2. heuristic scoring for all clients using structural, token-budget, and keyword signals. Unknown header values fall through to heuristics.isMetaRequest() treats compaction separately: if isCompactionRequest(req) is true, it returns false.packages/gateway/src/compaction.ts are: SCORE_FEW_TOOLS = 3 when tools ≤ 2; SCORE_FEW_MESSAGES = 3 when messages ≤ 2; SCORE_SHORT_SYSTEM = 2 when system prompt length is < 500 characters; SCORE_LOW_MAX_TOKENS = 3 when maxTokens is > 0 and ≤ 300; SCORE_META_KEYWORDS = 2; and META_SCORE_THRESHOLD = 8. The threshold preserves backward compatibility because the former three-check AND totaled 3+3+2 = 8.META_MAX_TOOLS = 2, META_MAX_MESSAGES = 2, META_MAX_SYSTEM_LENGTH = 500, META_MAX_TOKENS = 300, and META_KEYWORD_SYSTEM_LENGTH = 2000; keyword scanning is limited to shorter system prompts to avoid false positives on large prompts.META_KEYWORDS in packages/gateway/src/compaction.ts contains, in order: 1. "generate a title", 2. "generate a short title", 3. "title for the conversation", 4. "title for this conversation", 5. "summarize this conversation", 6. "summarize the conversation", 7. "conversation summary", 8. "categorize", 9. "classify this", 10. "label this".packages/opencode/src/server.ts imports rewriteRequest from @loreai/core, the Plugin type from @opencode/plugin, and acquireServerRuntime plus buildServerHeaders from ./server-runtime.packages/opencode/src/server.ts defines 3 hidden subagent workers, in order: 1. lore-distill — “Lore memory distillation worker”; 2. lore-curator — “Lore knowledge curator worker”; 3. lore-query-expand — “Lore query expansion worker”. During agent transformation, each receives its description, mode = "subagent", and hidden = true.{ id: "lore", setup } satisfies Plugin.Plugin; setup acquires shared server runtime using ctx.location.project.directory and returns immediately if no runtime is available.model.request hook fetches the session using event.sessionID, tolerates lookup failure with .catch(() => undefined), and calls buildServerHeaders() with runtime, sessionID, optional parentID, agent: event.agent, and providerID: event.model.providerID. It merges the result into event.headers; when "x-lore-upstream-url" exists, it sets event.baseURL to ${runtime.gatewayBase}/v1.http.request hook replaces event.request with await rewriteRequest(event.request, runtime.gatewayBase, {}).packages/opencode/src/server.ts tracks hook registrations for disposal. If setup fails, it uses Promise.allSettled() to dispose all completed registrations and call runtime.release(), then rethrows the original error.packages/opencode/src/server.ts is idempotent via a cleaned boolean. It runs all registration disposals plus runtime.release() with Promise.allSettled(), collects rejected reasons, and throws new AggregateError(failures, "Lore plugin cleanup failed") when any cleanup operation fails.