Skip to content

Commit f3c5d07

Browse files
committed
The legacy instance paths were no longer running InstanceBootstrap, so the file watcher service was never started for normal Hono/CLI flows. Restored bootstrap initialization
1 parent becf57e commit f3c5d07

6 files changed

Lines changed: 39 additions & 0 deletions

File tree

packages/opencode/src/cli/bootstrap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { AppRuntime } from "@/effect/app-runtime"
2+
import { InstanceBootstrap } from "../project/bootstrap"
23
import { Instance } from "../project/instance"
34

45
export async function bootstrap<T>(directory: string, cb: () => Promise<T>) {
56
return Instance.provide({
67
directory,
8+
init: () => AppRuntime.runPromise(InstanceBootstrap.Service.use((bootstrap) => bootstrap.run)),
79
fn: async () => {
810
try {
911
const result = await cb()

packages/opencode/src/cli/cmd/tui/worker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Installation } from "@/installation"
22
import { Server } from "@/server/server"
33
import * as Log from "@opencode-ai/core/util/log"
44
import { Instance } from "@/project/instance"
5+
import { InstanceBootstrap } from "@/project/bootstrap"
56
import { Rpc } from "@/util/rpc"
67
import { upgrade } from "@/cli/upgrade"
78
import { Config } from "@/config/config"
@@ -76,6 +77,7 @@ export const rpc = {
7677
async checkUpgrade(input: { directory: string }) {
7778
await Instance.provide({
7879
directory: input.directory,
80+
init: () => AppRuntime.runPromise(InstanceBootstrap.Service.use((bootstrap) => bootstrap.run)),
7981
fn: async () => {
8082
await upgrade().catch(() => {})
8183
},

packages/opencode/src/effect/app-runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { Truncate } from "@/tool/truncate"
4040
import { ToolRegistry } from "@/tool/registry"
4141
import { Format } from "@/format"
4242
import { Project } from "@/project/project"
43+
import { InstanceBootstrap } from "@/project/bootstrap"
4344
import { Vcs } from "@/project/vcs"
4445
import { Workspace } from "@/control-plane/workspace"
4546
import { Worktree } from "@/worktree"
@@ -91,6 +92,7 @@ export const AppLayer = Layer.mergeAll(
9192
ToolRegistry.defaultLayer,
9293
Format.defaultLayer,
9394
Project.defaultLayer,
95+
InstanceBootstrap.defaultLayer,
9496
Vcs.defaultLayer,
9597
Workspace.defaultLayer,
9698
Worktree.defaultLayer,

packages/opencode/src/server/routes/instance/middleware.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { MiddlewareHandler } from "hono"
22
import { Instance } from "@/project/instance"
3+
import { InstanceBootstrap } from "@/project/bootstrap"
34
import { AppRuntime } from "@/effect/app-runtime"
45
import { AppFileSystem } from "@opencode-ai/core/filesystem"
56
import { WorkspaceContext } from "@/control-plane/workspace-context"
@@ -23,6 +24,7 @@ export function InstanceMiddleware(workspaceID?: WorkspaceID): MiddlewareHandler
2324
async fn() {
2425
return Instance.provide({
2526
directory,
27+
init: () => AppRuntime.runPromise(InstanceBootstrap.Service.use((bootstrap) => bootstrap.run)),
2628
async fn() {
2729
return next()
2830
},

packages/opencode/src/server/workspace.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { WorkspaceID } from "@/control-plane/schema"
55
import { WorkspaceContext } from "@/control-plane/workspace-context"
66
import { Workspace } from "@/control-plane/workspace"
77
import { Flag } from "@opencode-ai/core/flag/flag"
8+
import { InstanceBootstrap } from "@/project/bootstrap"
89
import { Instance } from "@/project/instance"
910
import { Session } from "@/session/session"
1011
import { SessionID } from "@/session/schema"
@@ -99,6 +100,7 @@ export function WorkspaceRouterMiddleware(upgrade: UpgradeWebSocket): Middleware
99100
fn: () =>
100101
Instance.provide({
101102
directory: target.directory,
103+
init: () => AppRuntime.runPromise(InstanceBootstrap.Service.use((bootstrap) => bootstrap.run)),
102104
async fn() {
103105
return next()
104106
},

packages/opencode/test/file/watcher.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from "path"
55
import { ConfigProvider, Deferred, Effect, Layer, ManagedRuntime, Option } from "effect"
66
import { tmpdir } from "../fixture/fixture"
77
import { Bus } from "../../src/bus"
8+
import { bootstrap } from "../../src/cli/bootstrap"
89
import { Config } from "@/config/config"
910
import { FileWatcher } from "../../src/file/watcher"
1011
import { Git } from "../../src/git"
@@ -170,6 +171,34 @@ describeWatcher("FileWatcher", () => {
170171
)
171172
})
172173

174+
test("bootstrap starts root watcher events", async () => {
175+
await using tmp = await tmpdir({ git: true })
176+
const file = path.join(tmp.path, "bootstrap-watch.txt")
177+
const previousFileWatcher = process.env.OPENCODE_EXPERIMENTAL_FILEWATCHER
178+
const previousDisableFileWatcher = process.env.OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER
179+
180+
process.env.OPENCODE_EXPERIMENTAL_FILEWATCHER = "true"
181+
process.env.OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER = "false"
182+
183+
try {
184+
await bootstrap(tmp.path, async () => {
185+
await Effect.runPromise(ready(tmp.path))
186+
await Effect.runPromise(
187+
nextUpdate(
188+
tmp.path,
189+
(evt) => evt.file === file && evt.event === "add",
190+
Effect.promise(() => fs.writeFile(file, "bootstrap")),
191+
).pipe(Effect.tap((evt) => Effect.sync(() => expect(evt).toEqual({ file, event: "add" })))),
192+
)
193+
})
194+
} finally {
195+
if (previousFileWatcher === undefined) delete process.env.OPENCODE_EXPERIMENTAL_FILEWATCHER
196+
else process.env.OPENCODE_EXPERIMENTAL_FILEWATCHER = previousFileWatcher
197+
if (previousDisableFileWatcher === undefined) delete process.env.OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER
198+
else process.env.OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER = previousDisableFileWatcher
199+
}
200+
})
201+
173202
test("watches non-git roots", async () => {
174203
await using tmp = await tmpdir()
175204
const file = path.join(tmp.path, "plain.txt")

0 commit comments

Comments
 (0)