Dashboard › opencode › Distillation
f1e30b8f-8193-4aee-981d-9920c987f4e3["lore_tm_v1_LDZyNaxvT39lYgZvqaf1DvunjCY0ISYOM2kZbGZsmGM","lore_tm_v1_Tn1QBSF0ejsIxkxKsGRyXy1tkoTt4m_JjZpg1cUfiOk","lore_tm_v1_NeGR1ijOb66JE2xz8mSgSEYHol2IDggfPh75iBh4IZM","lore_tm_v1_FOCr7pWOW15FeE78ugUYzyJcPd--AC5keYxh2VFCzss","lore_tm_v1_J9i6YG2AZVgo3_5DBEvp1ZT5BEcmaE5UeIwTEcks2_0","lore_tm_v1_-3YxrgVnrk3M9oaTvYnIaaRRP_KHI-TKt68IMKJY1R0"]
Date: Sep 9, 2026
null, are not cached, and are retried on a later turn./home/byk/Code/opencode-lore-v2/packages/core/test/fetch-interceptor-install.test.ts contains 348 lines of end-to-end coverage for installFetchInterceptor() and interceptUrlForProtocol(), using gateway http://127.0.0.1:3207, injected headers x-lore-session-id: sess-123 and x-lore-project: /home/me/proj, and observation of both authorization and x-api-key.https://api.anthropic.com/v1/messages → gateway /v1/messages with upstream base https://api.anthropic.com; Codex https://chatgpt.com/backend-api/codex/responses → /v1/codex/responses with upstream base https://chatgpt.com/backend-api; OpenRouter /api/v1/chat/completions → /v1/chat/completions with upstream base https://openrouter.ai/api; original bodies and auth headers remain intact; direct gateway requests are observed without URL alteration./v2/chat/completions with model + messages routes as OpenAI Chat; /llm/messages with top-level system + messages routes as Anthropic; /custom/responses with array input routes as OpenAI Responses; Uint8Array bodies are detected; unrecognized { model, prompt } bodies and unreadable ReadableStream bodies bypass gateway rewriting.x-lore-upstream-path regression tests for issue #1052 pin full original paths: GitHub Copilot /chat/completions, OpenAI /v1/chat/completions, OpenRouter /api/v1/chat/completions, and ChatGPT Codex /backend-api/codex/responses.interceptUrlForProtocol() tests verify exact mappings openai → /v1/chat/completions, anthropic → /v1/messages, and openai-responses → /v1/responses; recognized endpoint suffixes are stripped from upstreamBase, full original pathname is retained in upstreamPath, query strings such as ?stream=true are preserved on the gateway URL, and unknown suffixes fall back to the upstream origin./home/byk/Code/opencode-lore-v2/packages/core/test/fetch-interceptor-body.test.ts contains 211 lines. detectProtocolFromBody() tests establish precedence and markers: 1. OpenAI Responses via array input, max_output_tokens, or previous_response_id; 2. Anthropic via top-level system plus array messages; 3. OpenAI Chat via model plus array messages.null for {}, missing model, non-array messages, prompt-only bodies, invalid JSON, JSON null, and array-root bodies. store and instructions alone do not mark Responses and remain classified as OpenAI Chat when model and array messages are present./home/byk/Code/opencode-lore-v2/packages/core/test/fetch-interceptor-paths.test.ts contains 231 lines covering recognized Anthropic, OpenAI Chat, OpenAI Responses, aggregator /api/v1/..., generic /api/..., provider-prefixed /openai/v1/... and /anthropic/v1/..., and Codex /codex/responses paths, including query strings and an Anthropic /v1/messages/foo subpath./health, /v1/models, /v1/embeddings, /api/foo/embeddings, and /codex/foo; malformed URLs and empty strings return false without throwing./home/byk/Code/opencode-lore-v2/packages/core/test/fetch-interceptor-global.test.ts contains 137 lines of regressions for issues #1027 and #1107. Four invariants are tested: 1. install stores the pre-install fetch under Symbol.for("lore.fetchInterceptor.originalFetch"); 2. the slot never stores the interceptor; 3. an independently evaluated second module copy no-ops rather than stacking another interceptor; 4. that second copy’s cleanup is a no-op and cannot tear down the first copy’s interceptor./home/byk/Code/opencode-lore-v2/packages/opencode/src/index.ts, a 503-line OpenCode plugin entry that imports log, getGitRemote, discoverWorkspaceRoot, and installFetchInterceptor from @loreai/core, while keeping helper functions in ./internal.ts to avoid exposing callable exports to OpenCode’s legacy loader.resolveGatewayUrl() uses order: 1. LORE_REMOTE_URL, 2. LORE_GATEWAY_URL, 3. @loreai/gateway’s readPortFile(), 4. known ports 3207 and 5673; unreachable remote or explicit URLs fall through to local discovery.startInProcess() dynamically imports @loreai/gateway, calls startGateway({ quiet: true, local: true }), constructs http://127.0.0.1:${handle.port}, logs reuse when handle.owned is false, and stores failures in lastGatewayStartError.processInitDone, processLoreActive, processLoreBase, and memoized loreInitPromise; isInertTestEnv() treats NODE_ENV=test or any .test. argv entry as inert unless LORE_OPENCODE_FORCE_ACTIVE=1.log.silenceStderr() suppresses all terminal output, including bundled gateway warnings, while retaining file and Sentry logging. Gateway startup failure is surfaced through surfaceGatewayUnavailable(); stale-build-looking errors recommend pnpm --filter @loreai/gateway run bundle or run build.projectState, keyed by ctx.project.id, with exact fields projectPath, gitRemote, and lastSeenAt; currentProject holds a paired { path, gitRemote } fallback. Both project and session-parent caches use SESSION_STATE_TTL_MS = 24 * 60 * 60 * 1000 (24 hours), with opportunistic stale-entry reaping.resolveParentSession(client, sessionID) calls client.session.get({ path: { id: sessionID } }), caches successful results including null primary-session parents in sessionParent, and forwards non-null parent IDs as x-parent-session-id for issue #1300.config hook sets cfg.compaction = { auto: false, prune: false }, invokes applyLoreProviderConfig(cfg, gatewayBase), and registers 3 hidden workers with mode: "subagent": 1. lore-distill — “Lore memory distillation worker”; 2. lore-curator — “Lore knowledge curator worker”; 3. lore-query-expand — “Lore query expansion worker.” mode: "subagent" is required because OpenCode only honors hidden: true for subagent-mode agents."chat.headers" hook injects remote gateway access headers, x-lore-session-id, x-lore-agent, optional x-parent-session-id, per-project x-lore-project and x-lore-git-remote, and runtime provider ID as x-lore-provider.LORE_UPSTREAM_${providerID.toUpperCase().replace(/-/g, "_")} and sets x-lore-upstream-url only when the environment value exists and that output header is not already present.LORE_UPSTREAM_EXTRA_HEADERS is parsed by parseUpstreamExtraHeaders() and copied literally into outgoing headers only when shouldForwardUpstreamExtraHeader(name) permits it, supporting corporate proxies, LiteLLM, and Cloudflare AI Gateway without clobbering gateway-managed headers.LorePlugin and the same-reference default export. Other helpers remain in ./internal.ts because OpenCode’s legacy loader invokes every function export as a plugin and throws on non-function exports; the constraint is guarded by the “plugin entry module export shape” test in test/index.test.ts./home/byk/Code/opencode/packages/core/src/plugin contains exactly 13 entries: agent.ts, command.ts, command/, host.ts, internal.ts, layer-map.example.ts, models-dev.ts, promise.ts, provider.ts, provider/, skill.ts, skill/, and variant.ts.