Dashboard › opencode › Distillation
62cd8698-e43e-4b62-9c90-d01e0d875bab["lore_tm_v1_xoP8U0r1WnN3IcfxfXuXTqdqO7fOwAeypx8-eyQWbsk","lore_tm_v1_68QfJDOe4MG5rbgkCN7pZuBn8bGndEQaT-vvALa2BFA","lore_tm_v1_bk4xKGVFXPn3mlEiuSqnXWqXjrdNesTP8tfM4x3u70g","lore_tm_v1_1J0VnnXdHRl0esiqhjv_NcZqj5pKZ5hCaVqM9HDiXaw","lore_tm_v1_eCDkHeyUHXMOheU7nbYE1D4LC46g5Fv3SYf_NDKwEt4","lore_tm_v1_lRBxSD-ng2utlbdsCPKXwGnZYOKuHlqwUpQigbZ7y58","lore_tm_v1_Dm8UCO8aQOWOtnoCF3kP0sdo9dIh3Fc7X2QdB3U-2AU","lore_tm_v1_btbnPBgjcShURfXuCmyJAnwNUQ6-TBgs1JYSx-Zypjo","lore_tm_v1_d-da-_92d77P-NFpI3JH9bp1U278tK-nz3bKJcmo8N0","lore_tm_v1_fAKmUkZko4dwMpVYEq83enjl3D2zjbmNYL197oesF5o","lore_tm_v1_4CxNnDnxq6ShprkEN7Pe6CawwRt1BxjxWi3LPXjqA8s","lore_tm_v1_MnVK4kt-_OWiMbl6FVoAHSPVoF_M4mWh84DsYfnAdoY","lore_tm_v1_augDg_xmaJdBqE5f3UmTJha_MICiBmStQzqt3rmbdTM"]
Date: September 9, 2026
/home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/aisdk.ts defines AISDKHooks with sdk and language hooks. sdk receives readonly model: Model.Info, package: string, options: Record<string, any>, and mutable optional sdk?: any; language receives readonly model: Model.Info, sdk: any, options: Record<string, any>, and mutable optional language?: LanguageModelV3. AISDKDomain.hook is ModelHooks<AISDKHooks>./home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/registration.ts defines Registration.dispose(): Promise<void>, ModelHookOptions.providerID?: string, Hooks<Spec>, ModelHooks<Spec>, and Transform<Input>. ModelHooks accepts provider scoping only when the hook input has a readonly model property; unscoped hooks apply to every provider./home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/session.ts defines SessionPrompt with sessionID, messageID, mutable prompt, optional metadata, and delivery; SessionContext with session/agent/model identity plus mutable system, messages, tools, generation, and providerOptions.SessionRequestKind in /home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/session.ts is the exact union "primary" | "compaction" | "title" | "generate". SessionModelRequest, SessionHttpRequest, and SessionHttpResponse all carry sessionID, agent, model, and kind; model-request hooks may mutate baseURL and headers, HTTP-request hooks may mutate request, and HTTP-response hooks may mutate response./home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/session.ts defines SessionRetryDecision as { retry: false } | { retry: true; delay: number }. SessionRetry includes sessionID, agent, model, error: SessionError.Error, attempt, and mutable decision.SessionHooks contains 6 hooks in order: 1. prompt, 2. context, 3. "model.request", 4. "http.request", 5. "http.response", 6. retry. SessionDomain exposes the selected SessionApi methods plus hook: ModelHooks<SessionHooks>./home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/agent.ts defines AgentEditor operations list(), get(id), default(id | undefined), update(id, callback), and remove(id). AgentDomain extends AgentApi and adds transform: Transform<AgentEditor> and reload(): Promise<void>./home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/catalog.ts defines CatalogProviderRecord with mutable provider information and a readonly model map. CatalogEditor.provider supports list, get, update, and remove; CatalogEditor.model supports get, update, remove, and default.get()/set(providerID, modelID). CatalogDomain extends CatalogApi with transform and reload./home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/event.ts limits EventDomain to Pick<EventApi, "subscribe">./home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/tool.ts defines Promise-facing ToolContext.progress(update: Tool.Metadata): Promise<void> and Info.execute(input, context): Promise<Tool.Result<Output>>. It re-exports CallID, Error, Metadata, Options, and Result from @opencode/schema/tool.ToolEditor in /home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/tool.ts supports list, get, namespace, add, update, and remove; update ignores missing IDs. Tool hooks are "execute.before" with mutable tool and input, and "execute.after" with either { status: "completed", result } or { status: "error", error }. ToolDomain provides transform, reload, and hook.x-lore-agent matches, the request is “always a normal turn.”x-lore-agent matches, the request is “always passthrough.”x-lore-session-id, x-lore-agent, x-lore-provider, and, for child sessions, x-parent-session-id. Search evidence located header construction in /home/byk/Code/opencode-lore/packages/opencode/src/index.ts and tests in packages/opencode/test/routing.e2e.test.ts, subagent-detection.test.ts, and session-state.test.ts.lore-distill, lore-curator, and lore-query-expand; relevant definitions occur in /home/byk/Code/opencode-lore/packages/opencode/src/index.ts, while gateway worker-health handling recognizes the same worker identities.ctx.session.hook("prompt", ...); Effect SDK and server tests exercise prompt and context; core provider and model-request tests exercise "model.request", "http.request", and "http.response". Provider implementations using these hooks include OpenAI, GitHub Copilot, Azure, Anthropic, Google Vertex, GitLab, SAP AI Core, Snowflake Cortex, Cloudflare Workers AI, Cloudflare AI Gateway, Factory, Dynamic, OpenAI-compatible, and Vercel./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts defines HookScope with sessionID, agent, model, and kind. sessionHeaders() emits "x-session-affinity", "X-Session-Id", optional "x-parent-session-id", "User-Agent", "x-opencode-project", "x-opencode-session", and "x-opencode-client".promptCacheKey() in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts strips the ses_ prefix only when the session ID matches /^ses_[0-9a-f]{64}$/; otherwise it returns the unchanged ID.applyModelHooks() triggers session.model.request before dispatch, providing the current route baseURL and a copied header record. Hook changes can replace the route endpoint’s baseURL and HTTP headers while retaining the existing request body and query.httpMiddleware() in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts exposes outbound exchanges through web-standard Request and Response: it triggers session.http.request, reconstructs request bodies as Uint8Array when present, invokes the handler, triggers session.http.response, omits bodies for statuses 204, 205, and 304, then converts the possibly modified response back to HttpClientResponse. Non-Error failures are wrapped with new Error(String(cause)).SessionModelRequest.prepare builds mutable hook context with sessionID, effective context agent, model ref, transcript system and messages, tool definitions, empty generation, and empty providerOptions; unless input.contextHooks === false, it triggers session.context.session.context hooks recognizes definitions by object identity first and original key second, allowing hooks to edit descriptions/schemas, rename, or remove tools. Hook-invented entries matching neither an original object nor key are dropped; canonical tool.name is retained so renamed calls can map back to executable tools.boundImages(unsupportedParts(...)), optional generation/provider options, session headers, and promptCacheKey(session.fork?.sessionID ?? session.id). A TODO notes that cache lineage should be persisted so nested forks reuse the root session’s cache key./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts rejects a route-hook change when an existing compaction window’s selected provider context is incompatible with the newly selected route, dying with Provider context is incompatible with the route selected by model request hooks.session.http.request or session.http.response hooks exist. A session WebSocket transport is used only when input.webSocket === "session", the model supports responsesWebsockets, the provider flag is enabled, and no HTTP hooks are installed.SessionModelRequest.prepare returns { request, options, retry, executeTool }. executeTool uses the hooked definitions and converts declined tool defects into failures; retry triggers the session.retry hook and discards its result./home/byk/Code/opencode-v2-pilot/packages/schema/src/location.ts defines Location.Ref as { directory: AbsolutePath, workspaceID?: WorkspaceID } and Location.Info as directory/workspace plus project { id: ProjectID, directory: AbsolutePath, canonical: AbsolutePath }. Location.response(data) wraps a schema as { location: Info, data }./home/byk/Code/opencode-v2-pilot/packages/schema/AGENTS.md requires dependency direction @opencode/schema <- @opencode/protocol <- @opencode/server; browser-safe serializable contracts in Schema; current contracts unversioned; retained legacy contracts explicitly V1 under src/v1/; and no permanent V2 naming for replacement architecture.PascalCase exported schema values, camelCase combinators, same-name interfaces for public Schema.Struct records, readonly public contracts, optional(...) for omitted undefined properties, Schema.Json for JSON values, and Schema.Unknown for opaque values. Schema.Any is restricted to documented unsafe compatibility boundaries.Schema.Any, stable unique public identifiers, exact facade/schema identity, and exclusion of V1-only events from current Protocol manifests./home/byk/Code/opencode-v2-pilot/packages/client/src/promise/api.ts derives Client from ReturnType<typeof OpenCode.make> and exports aliases for AgentApi, CommandApi, ConfigApi, EventApi, GenerateApi, IntegrationApi, McpApi, ModelApi, PluginApi, PermissionApi, ProviderApi, ReferenceApi, WebSearchApi, SessionApi, SkillApi, VcsApi, and WorktreeApi; it also re-exports RpcApi, RpcCallOptions, RpcClient, and RpcEventPayload.CatalogApi in /home/byk/Code/opencode-v2-pilot/packages/client/src/promise/api.ts consists of provider: ProviderApi and model: ModelApi.