Dashboard › opencode › Distillation
23431d31-3191-4606-865e-11fb22d4104e["lore_tm_v1_44MDtfCyEaJejZSMHliJe2S8TftzGtmzCcv6ehcEl3M"]
Date: September 9, 2026
packages/opencode/package.json adds the ./server export with types: "./src/server.ts" and Bun/default runtime entry ./dist/server.js; changes build from the raw-TypeScript no-op message to tsx script/build.ts; adds optional peer dependency @opencode/plugin >=0.0.0, dev dependency @opencode/plugin 0.0.0-beta-19378, and dist/ to the published files while retaining @opencode-ai/plugin >=1.1.0.packages/opencode/script/build.ts deletes and recreates packages/opencode/dist, then uses esbuild.build() to bundle src/server.ts into dist/server.js as ESM for Node with target: "esnext" and source maps; it aliases @loreai/core to src/server-core.ts, leaves @opencode/plugin and @loreai/gateway external, and uses logLevel: "info".packages/opencode/src/internal.ts adds exported parseUpstreamExtraHeaders(value), which returns [] for absent input, splits input on "\n", ignores lines whose first colon is absent or at index 0, trims header names and values, permits additional colons in values, and returns nonempty names as [name, headerValue] tuples.packages/opencode/src/index.ts replaces its inline LORE_UPSTREAM_EXTRA_HEADERS parsing with parseUpstreamExtraHeaders(process.env.LORE_UPSTREAM_EXTRA_HEADERS) and continues forwarding only names accepted by shouldForwardUpstreamExtraHeader(name) into output.headers.packages/opencode/src/server-core.ts forms the build-time @loreai/core shim by exporting GATEWAY_AUTH_HEADER from ../../core/src/credential-headers, rewriteRequest from ../../core/src/fetch-interceptor, getGitRemote from ../../core/src/git, and log as a namespace from ../../core/src/log.packages/opencode/src/server-runtime.ts defines LoreServerRuntime with gatewayBase, projectPath, gitRemote, gatewayHeaders, and async release(); ServerRuntimeDependencies permits injected resolveGateway() and gitRemote(path) implementations.acquireServerRuntime(projectPath, dependencies) returns undefined during NODE_ENV=test or when an argv item contains .test. unless LORE_OPENCODE_FORCE_ACTIVE === "1"; it also returns undefined when LORE_DISABLED is exactly "1" or "true".acquireServerRuntime() acquires a shared gateway lease before resolving the Git remote with injected dependencies.gitRemote or getGitRemote; a missing remote becomes "", a thrown Git-remote lookup releases the lease before rethrowing, and the returned runtime’s release() is idempotent.packages/opencode/src/server-runtime.ts maintains one module-level gatewayLeasePromise; concurrent acquisitions share its GatewayLease, increment refs, wait and retry if the lease is closing, and clear a failed promise before propagating its error.resolveGatewayUrl() is: 1. trimmed LORE_REMOTE_URL, accepting it only if probeGateway(url) succeeds and otherwise logging fallthrough; 2. trimmed LORE_GATEWAY_URL, also probe-gated; 3. a port returned by dynamically imported @loreai/gateway.readPortFile(); 4. known local ports 3207 and 5673, with candidate ports deduplicated in a Set and probed as http://127.0.0.1:<port>.createGatewayLease() logs No Lore gateway found, starting in-process…, dynamically imports @loreai/gateway, and calls startGateway({ quiet: true, local: true }); it constructs gatewayBase as http://127.0.0.1:${handle.port} and retains handle.shutdown only when handle.owned is true.gatewayAccessHeadersForRemote(gatewayBase); release decrements refs, shuts down only when the final reference is released, stores the shutdown operation in lease.closing, and clears gatewayLeasePromise in finally if it still points to the active lease.resetServerRuntimeForTest() throws Server runtime reset is test-only unless NODE_ENV === "test"; in tests it detaches the current gatewayLeasePromise, awaits it if present, and invokes its optional shutdown.buildServerHeaders() starts with runtime gateway headers and adds x-lore-session-id, x-lore-agent, x-lore-project, x-lore-git-remote, and x-lore-provider; it conditionally adds x-parent-session-id for parentID.buildServerHeaders() maps a provider ID to environment variable LORE_UPSTREAM_${providerID.toUpperCase().replace(/-/g, "_")} and, when set, emits it as x-lore-upstream-url; it also parses LORE_UPSTREAM_EXTRA_HEADERS and includes only headers permitted by shouldForwardUpstreamExtraHeader(name).packages/opencode/src/server.ts exports a plugin satisfying Plugin.Plugin, with id: "lore" and setup(ctx) acquiring runtime state for ctx.location.project.directory; setup exits without registration when runtime acquisition returns undefined.subagent workers through ctx.agent.transform(), in this order: 1. lore-distill — Lore memory distillation worker; 2. lore-curator — Lore knowledge curator worker; 3. lore-query-expand — Lore query expansion worker.model.request hook looks up the session with ctx.session.get({ sessionID: event.sessionID }), suppresses lookup errors to undefined, builds headers from runtime state plus session ID, optional parent ID, agent, and provider ID, merges them into event.headers, and changes event.baseURL to ${runtime.gatewayBase}/v1 only when x-lore-upstream-url is present.http.request hook replaces event.request with await rewriteRequest(event.request, runtime.gatewayBase, {}).runtime.release() via Promise.allSettled() before rethrowing the original error.Promise.allSettled() for all registration disposers plus runtime.release(); it gathers every rejected reason and throws AggregateError(failures, "Lore plugin cleanup failed") when one or more cleanup operations fail.