Repository navigation
refactor(core): drop redundant reconstructions in rpc and project - #57948
Conversation
…on, rpc, project, and workspace
There was a problem hiding this comment.
Mostly a clean no-op cleanup: the rpc.ts and project.ts edits keep the same behaviour, since ref is already a Location.Ref and dotHg is already an AbsolutePath. Core tests and the packages/core type check pass. I also checked import order directly.
Public API: unchanged.
Two concerns, both inline:
workspace.tsimport cycle. ImportingEnvironmentfrom./environment/index.jscreates a cycle back intoworkspace.ts. Loading@opencode/core/workspaceas the first module now throwsReferenceError: Cannot access 'node' before initialization(environment/environment.ts:40). On the base it loads fine. Current entrypoints load the environment module first, so this is latent, but it depends on import order.- Small OAuth behaviour change. It conflicts with the "no behaviour changes" scope.
| import { make } from "effect/process/ChildProcessSpawner" | ||
| import type { EnvironmentDriver } from "./environment/driver.js" | ||
| import { execDefaults } from "./environment/exec-defaults.js" | ||
| import { Environment } from "./environment/index.js" |
There was a problem hiding this comment.
This adds an import cycle: workspace.ts → environment/index.js → environment/environment.ts → workspace.ts. environment.ts reads Workspace.node at module top level, so importing @opencode/core/workspace before anything that loads the environment module now throws ReferenceError: Cannot access 'node' before initialization (repro: bun -e 'await import("./src/workspace.ts")' in packages/core; the base loads fine). Two ways to fix it without the cycle: move makeFiles into a module that doesn't pull in environment.ts (e.g. next to execDefaults), or keep the direct execDefaults import here.
| if (attempt.authorization.mode === "code" && input.code === undefined) { | ||
| return yield* new CodeRequiredError({ attemptID: input.attemptID }) | ||
| } | ||
| if (attempt.completing) |
There was a problem hiding this comment.
Moving the missing-code check below the completing check changes behaviour. A code-mode complete without code while another completion is in flight used to fail with CodeRequiredError; now it hits the Effect.die defect. To keep this a pure refactor, keep the missing-code check before the completing check.
There was a problem hiding this comment.
Both earlier points are addressed: the workspace.ts import cycle and the OAuth reorder in integration.ts are reverted, and @opencode/core/workspace now loads on its own again. The remaining rpc.ts/project.ts changes are true no-ops. Core tests and the packages/core type check pass.
Public API: unchanged.
Problem
RpcandProjectin@opencode/corecarried redundant schema reconstructions:RpcreconstructedLocation.Ref.make({ directory: ref.directory, workspaceID: ref.workspaceID })on every event publish and logical event projection even thoughrefis already aLocation.Ref.Project'shgDiscoverre-wrappeddotHg: AbsolutePathwithAbsolutePath.make(dotHg).Change
Pass
refanddotHgdirectly inrpc.tsandproject.ts:Out of scope