Dashboard › opencode › Distillation
0232502b-ba57-475a-8bd8-423ee0c6eb80["lore_tm_v1_lFBr3o8S3XPOKjRjgxtWa96ymm7Ex0BHLkpgMFtmCQo","lore_tm_v1_sjUiI6uzjQtbfNjtfaCSb0urAWOlqHK39nSxzMqxdqo","lore_tm_v1_x6pwzFILfMOufycSmUoqBPsaWVgqcpsvyXu3yG8IJM8","lore_tm_v1_nJbyFwjYzI4tYHs6TVkPjnmQpUNWC1JJTEQqOA8y5_E","lore_tm_v1_j3OvcO5UzXQJ-RUkDWG9GtPLJdzTjqArgNSAjPuWfL4","lore_tm_v1_evo41yr0dXsTO6tpAakOz4DuzmMwpUL0lNRCxG4PMuo","lore_tm_v1_6lmakWlWNdmUdZOVabgx-PU1c1lwTuUjsbTBnpc0Rdc","lore_tm_v1_XTo1BdR9b0StBfRBhkKvwX5EczLJ1I10ZLtXjtGGHwc","lore_tm_v1_K5TBLJjsS1PthxzsR7VEbPGxF__Uoqrp1JZO1jbsTSo"]
fetch; /home/byk/Code/opencode-lore/packages/opencode/test/routing.e2e.test.ts checks that active discovery resolves a non-empty gatewayBase, provider config is pinned to the gateway, and the installed interceptor rewrites api.anthropic.com through the in-process Lore gateway to a mocked upstream./home/byk/Code/opencode/packages/plugin/src/v2/promise/plugin.ts: Plugin has readonly id and setup(context: PluginContext): Promise<void> | void; define(plugin) returns the plugin unchanged; and PluginDomain exposes asynchronous add(plugin) and remove(id)./home/byk/Code/opencode-lore/packages/gateway/test/start-gateway-reuse.test.ts tests: an authenticated existing gateway is reused instead of producing EADDRINUSE; the returned handle has owned: false, the existing port, and the existing managementToken.6669, hosts ["127.0.0.1"], and token "forbidden-port-control-token".padEnd(32, "x"): public status is "healthy", a wrong token yields { kind: "rejected" }, the correct token authenticates with { pid: process.pid }, fetchMemoryHealth(baseURL) is non-null, and startGateway(...) reuses the server with owned: false./home/byk/Code/opencode-lore/packages/gateway/test/start-gateway-reuse.test.ts preserves global fetch transport for non-loopback probes such as https://gateway.example.test/health, while a loopback HTTP server that hangs is classified as "timeout" with a 10 ms deadline.49152 is reused when no port is explicit, selecting authenticated host "0.0.0.0"; and an existing gateway requested through non-overlapping interface "127.0.0.2" is reused with actual config host ["127.0.0.1"]./health response { status: "ok", service: "lore" } makes probeGateway(...) true but is rejected by startGateway(...) as “not an authenticated lore gateway”; a non-HTTP TCP process is rejected with the same friendly classification./home/byk/Code/opencode-lore/packages/gateway/test/start-gateway-reuse.test.ts: if writeProcess(...) writes the process record and then throws "injected process-record write failure", startup rejects and both readPortFile() and readGatewayProcessFile() become null."injected listener close failure", startup reports that discovery evidence was retained; the published port remains 49321, the process record retains that port, and neither port nor process evidence is removed.startGateway(...): concurrent starts serialize through process-record publication so the first owns the new gateway and the second reuses its port/token; during replacement, a successor waits until predecessor shutdown removes discovery records, then starts as owned: true./home/byk/Code/opencode-lore/packages/gateway/src/index.ts: the library exports loadConfig, DEFAULT_PORTS, DEFAULT_PORT, GatewayConfig, startServer, handleRequest, resetPipelineState, readPortFile, readGatewayProcessFile, startGateway, probeGateway, probeGatewayProcess, probeGatewayProcessHost, probeUrlFor, GatewayHandle, and StartOptions; it exports Stricli runCli plus legacy _cli during migration.__filename is always defined in the CJS runtime branch of /home/byk/Code/opencode-lore/packages/gateway/src/index.ts; direct-execution detection compares process.argv[1] with __filename for CJS or fileURLToPath(import.meta.url) for ESM, returning false on errors.packages/gateway/script/import-meta-url.js rewrites import.meta.url to an injected import_meta_url shim in CJS bundles to avoid esbuild’s empty-import-meta warning, even though that branch is unreachable at CJS runtime because __filename is always defined./home/byk/Code/opencode-lore/packages/gateway/src/index.ts dynamically imports commandStart and invokes commandStart({ quiet: true }); embedded direct execution defaults to start, not run, because there is no TTY or reason to auto-detect agents./home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/adapter.ts lines 210-319: fromPromise(plugin) adapts Promise plugins to the Effect-only runtime; registrations attach to the plugin scope for disposal, and captured fiber context preserves boot-time batching so transforms coalesce into one reload per domain.fromPromise(plugin) dynamically imports ClientApi and OpenCodeEvent, obtains endpoint groups for agent, command, experimental, generate, integration, MCP, model, plugin, permission, provider, reference, session, skill, VCS, web search, and worktree, captures Scope.Scope, and creates streams.register(...) runs scoped registration and exposes Promise-based dispose; run(...) executes Effects with the captured context; promiseExecutor adapts tool execution and wraps progress updates with Effect.promise; adaptApiMethod(...) compiles an endpoint, decodes input ?? {}, calls the Effect method, returns undefined for no-content endpoints, and otherwise encodes the result.transform(...) registers callbacks against an Effect domain; the constructed PromiseContext forwards app, location, and options, adapts agent/provider/model methods through protocol endpoints, exposes agent/catalog transforms and reloads, and wraps AI SDK callbacks with Promise.resolve(...)./home/byk/Code/opencode-v2-pilot/packages/plugin/src/promise/plugin.ts: Context includes app, location, options, and domains for agent, aisdk, catalog, command, event, integration, mcp, generate, permission, plugin, reference, rpc, session, shell, skill, storage, tool, vcs, websearch, and worktree; experimental.terminal exposes only persistentPty.read, while plugin exposes only PluginApi.list.Cleanup = () => Promise<void> | void; Plugin.setup(context: Context) may synchronously or asynchronously return Cleanup or void; define(plugin) returns the plugin unchanged./home/byk/Code/opencode-lore/packages/opencode/src/index.ts imports only LorePlugin from its entry surface and keeps helpers in ./internal.ts; the reason is that OpenCode’s legacy loader invokes every exported function as a plugin, and leaked helper exports previously inserted undefined into the hooks array and crashed event dispatch with undefined is not an object (evaluating 'A.event').chat.headers.resolveGatewayUrl() discovery order: LORE_REMOTE_URL, then LORE_GATEWAY_URL, then a dynamically imported readPortFile(), then known ports [3207, 5673]; URLs have trailing slashes removed, each candidate is probed, and failure returns null.startInProcess() dynamically imports startGateway from @loreai/gateway, calls startGateway({ quiet: true, local: true }), returns http://127.0.0.1:${handle.port}, logs reuse when handle.owned is false, and stores failures in lastGatewayStartError before returning null./home/byk/Code/opencode-lore/packages/opencode/src/index.ts stores them together in currentProject, ensuring a path is never emitted with a remote resolved for a different project; this prevents non-repository directories from becoming “git-remote magnets.”processInitDone, processLoreActive, and processLoreBase are process-wide; projectState is keyed by ctx.project.id and stores { projectPath, gitRemote, lastSeenAt }; SESSION_STATE_TTL_MS = 24 * 60 * 60 * 1000; stale project entries are opportunistically reaped, with a stated estimate of about 200 bytes per entry and 20 KB for 100 projects.sessionParent caches session.id → { parentID: string | null, lastSeenAt } under the same 24-hour TTL; parent IDs are immutable, successful lookups including null are cached, and failures are not cached so transient errors can retry on the next turn.resolveParentSession(...) catches failures and returns null.resolveParentSession(...) calls client.session.get({ path: { id: sessionID } }), reads res.data?.parentID ?? null, refreshes cache timestamps, and forwards a non-null parent as x-parent-session-id so the gateway recognizes Task child sessions as sub-agents and sizes LTM injection accordingly for issue #1300.isInertTestEnv() is false when LORE_OPENCODE_FORCE_ACTIVE === "1"; otherwise it is true for NODE_ENV === "test" or any argv entry containing .test.. Active routing tests retain test isolation while forcing real wiring through LORE_GATEWAY_URL.log.silenceStderr() prevents any stdout/stderr bytes from corrupting OpenCode’s full-screen TUI while logs still go to file and Sentry; gateway discovery/start is memoized in loreInitPromise to prevent concurrent plugin calls racing through probe→spawn.surfaceGatewayUnavailable(...) raises a TUI-safe notification; module/not-found/export errors are described as likely stale builds and recommend pnpm --filter @loreai/gateway run bundle or run build.discoverWorkspaceRoot(ctx.worktree || ctx.directory); cached git remote is reused only if the project’s cached path matches, otherwise getGitRemote(thisProjectPath) ?? "" runs; currentProject is updated on each plugin call as fallback for requests bypassing chat.headers.cfg.compaction = { auto: false, prune: false }, calls applyLoreProviderConfig(cfg, gatewayBase), and registers hidden agents in this order: "lore-distill" ("Lore memory distillation worker"), "lore-curator" ("Lore knowledge curator worker"), and "lore-query-expand" ("Lore query expansion worker"); each uses mode: "subagent" and hidden: true because OpenCode only honors hidden status for subagent-mode agents.