Skip to content

Commit 10cf155

Browse files
Apply PR #20793: refactor(effect): move read tool onto defineEffect
2 parents 0977b9a + ba86434 commit 10cf155

7 files changed

Lines changed: 1014 additions & 978 deletions

File tree

packages/opencode/specs/effect-migration.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ Once individual tools are effectified, change `Tool.Info` (`tool/tool.ts`) so `i
235235
2. Update `Tool.define()` factory to work with Effects
236236
3. Update `SessionPrompt` to `yield*` tool results instead of `await`ing
237237

238+
### Tool migration details
239+
240+
Until the tool interface itself returns `Effect`, use this transitional pattern for migrated tools:
241+
242+
- `Tool.defineEffect(...)` should `yield*` the services the tool depends on and close over them in the returned tool definition.
243+
- Keep the bridge at the Promise boundary only. Prefer a single `Effect.runPromise(...)` in the temporary `async execute(...)` implementation, and move the inner logic into `Effect.fn(...)` helpers instead of scattering `runPromise` islands through the tool body.
244+
- If a tool starts requiring new services, wire them into `ToolRegistry.defaultLayer` so production callers resolve the same dependencies as tests.
245+
246+
Tool tests should use the existing Effect helpers in `packages/opencode/test/lib/effect.ts`:
247+
248+
- Use `testEffect(...)` / `it.live(...)` instead of creating fake local wrappers around effectful tools.
249+
- Yield the real tool export, then initialize it: `const info = yield* ReadTool`, `const tool = yield* Effect.promise(() => info.init())`.
250+
- Run tests inside a real instance with `provideTmpdirInstance(...)` or `provideInstance(tmpdirScoped(...))` so instance-scoped services resolve exactly as they do in production.
251+
252+
This keeps migrated tool tests aligned with the production service graph today, and makes the eventual `Tool.Info``Effect` cleanup mostly mechanical later.
253+
238254
Individual tools, ordered by value:
239255

240256
- [ ] `apply_patch.ts` — HIGH: multi-step orchestration, error accumulation, Bus events

0 commit comments

Comments
 (0)