Skip to content

Commit 31ad6e8

Browse files
chore: generate
1 parent ea04b23 commit 31ad6e8

5 files changed

Lines changed: 51 additions & 55 deletions

File tree

packages/opencode/specs/effect-migration.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,38 @@ The `InstanceState.make` init callback receives a `Scope`, so you can use `Effec
8282
- **Subscriptions**: Yield `Bus.Service` at the layer level, then use `Stream` + `forkScoped` inside the init closure. The fiber is automatically interrupted when the instance scope closes:
8383

8484
```ts
85-
const bus = yield* Bus.Service
86-
87-
const cache = yield* InstanceState.make<State>(
88-
Effect.fn("Foo.state")(function* (ctx) {
89-
// ... load state ...
90-
91-
yield* bus
92-
.subscribeAll()
93-
.pipe(
94-
Stream.runForEach((event) => Effect.sync(() => { /* handle */ })),
85+
const bus = yield * Bus.Service
86+
87+
const cache =
88+
yield *
89+
InstanceState.make<State>(
90+
Effect.fn("Foo.state")(function* (ctx) {
91+
// ... load state ...
92+
93+
yield* bus.subscribeAll().pipe(
94+
Stream.runForEach((event) =>
95+
Effect.sync(() => {
96+
/* handle */
97+
}),
98+
),
9599
Effect.forkScoped,
96100
)
97101

98-
return { /* state */ }
99-
}),
100-
)
102+
return {
103+
/* state */
104+
}
105+
}),
106+
)
101107
```
102108

103109
- **Resource cleanup**: Use `Effect.acquireRelease` or `Effect.addFinalizer` for resources that need teardown (native watchers, process handles, etc.):
104110

105111
```ts
106-
yield* Effect.acquireRelease(
107-
Effect.sync(() => nativeAddon.watch(dir)),
108-
(watcher) => Effect.sync(() => watcher.close()),
109-
)
112+
yield *
113+
Effect.acquireRelease(
114+
Effect.sync(() => nativeAddon.watch(dir)),
115+
(watcher) => Effect.sync(() => watcher.close()),
116+
)
110117
```
111118

112119
- **Background fibers**: Use `Effect.forkScoped` — the fiber is interrupted on disposal.

packages/opencode/src/file/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,11 @@ export namespace File {
404404
s.cache = next
405405
})
406406

407-
let cachedScan = yield* Effect.cached(
408-
scan().pipe(Effect.catchCause(() => Effect.void)),
409-
)
407+
let cachedScan = yield* Effect.cached(scan().pipe(Effect.catchCause(() => Effect.void)))
410408

411409
const ensure = Effect.fn("File.ensure")(function* () {
412410
yield* cachedScan
413-
cachedScan = yield* Effect.cached(
414-
scan().pipe(Effect.catchCause(() => Effect.void)),
415-
)
411+
cachedScan = yield* Effect.cached(scan().pipe(Effect.catchCause(() => Effect.void)))
416412
})
417413

418414
const init = Effect.fn("File.init")(function* () {

packages/opencode/src/plugin/index.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,16 @@ export namespace Plugin {
149149
})
150150

151151
// Subscribe to bus events, fiber interrupted when scope closes
152-
yield* bus
153-
.subscribeAll()
154-
.pipe(
155-
Stream.runForEach((input) =>
156-
Effect.sync(() => {
157-
for (const hook of hooks) {
158-
hook["event"]?.({ event: input as any })
159-
}
160-
}),
161-
),
162-
Effect.forkScoped,
163-
)
152+
yield* bus.subscribeAll().pipe(
153+
Stream.runForEach((input) =>
154+
Effect.sync(() => {
155+
for (const hook of hooks) {
156+
hook["event"]?.({ event: input as any })
157+
}
158+
}),
159+
),
160+
Effect.forkScoped,
161+
)
164162

165163
return { hooks }
166164
}),

packages/opencode/src/project/vcs.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,20 @@ export namespace Vcs {
159159
const value = { current, root }
160160
log.info("initialized", { branch: value.current, default_branch: value.root?.name })
161161

162-
yield* bus
163-
.subscribe(FileWatcher.Event.Updated)
164-
.pipe(
165-
Stream.filter((evt) => evt.properties.file.endsWith("HEAD")),
166-
Stream.runForEach((_evt) =>
167-
Effect.gen(function* () {
168-
const next = yield* Effect.promise(() => get())
169-
if (next !== value.current) {
170-
log.info("branch changed", { from: value.current, to: next })
171-
value.current = next
172-
yield* bus.publish(Event.BranchUpdated, { branch: next })
173-
}
174-
}),
175-
),
176-
Effect.forkScoped,
177-
)
162+
yield* bus.subscribe(FileWatcher.Event.Updated).pipe(
163+
Stream.filter((evt) => evt.properties.file.endsWith("HEAD")),
164+
Stream.runForEach((_evt) =>
165+
Effect.gen(function* () {
166+
const next = yield* Effect.promise(() => get())
167+
if (next !== value.current) {
168+
log.info("branch changed", { from: value.current, to: next })
169+
value.current = next
170+
yield* bus.publish(Event.BranchUpdated, { branch: next })
171+
}
172+
}),
173+
),
174+
Effect.forkScoped,
175+
)
178176

179177
return value
180178
}),

packages/opencode/test/project/vcs.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ describe("Vcs diff", () => {
162162
await $`git worktree add -b feature/test ${dir} HEAD`.cwd(tmp.path).quiet()
163163

164164
await withVcsOnly(dir, async () => {
165-
const [branch, base] = await Promise.all([
166-
Vcs.branch(),
167-
Vcs.defaultBranch(),
168-
])
165+
const [branch, base] = await Promise.all([Vcs.branch(), Vcs.defaultBranch()])
169166
expect(branch).toBe("feature/test")
170167
expect(base).toBe("main")
171168
})

0 commit comments

Comments
 (0)