Skip to content

Commit 98488f7

Browse files
benjaminshafiigithub-actions[bot]
authored andcommitted
feat(hotreload): make reload userland-driven
1 parent af0d2a8 commit 98488f7

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

packages/opencode/src/flag/flag.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ export namespace Flag {
3535
// Experimental
3636
export const OPENCODE_EXPERIMENTAL = truthy("OPENCODE_EXPERIMENTAL")
3737
export const OPENCODE_EXPERIMENTAL_HOT_RELOAD = OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_HOT_RELOAD")
38-
export const OPENCODE_EXPERIMENTAL_HOT_RELOAD_MODE = process.env["OPENCODE_EXPERIMENTAL_HOT_RELOAD_MODE"]
39-
export const OPENCODE_EXPERIMENTAL_HOT_RELOAD_DEBOUNCE_MS = number("OPENCODE_EXPERIMENTAL_HOT_RELOAD_DEBOUNCE_MS")
4038
export const OPENCODE_EXPERIMENTAL_HOT_RELOAD_COOLDOWN_MS = number("OPENCODE_EXPERIMENTAL_HOT_RELOAD_COOLDOWN_MS")
4139
export const OPENCODE_EXPERIMENTAL_FILEWATCHER = truthy("OPENCODE_EXPERIMENTAL_FILEWATCHER")
4240
export const OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER = truthy("OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER")

packages/opencode/src/project/hotreload.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ export namespace HotReload {
118118
() => {
119119
if (!Flag.OPENCODE_EXPERIMENTAL_HOT_RELOAD) return {}
120120

121-
const debounce = Flag.OPENCODE_EXPERIMENTAL_HOT_RELOAD_DEBOUNCE_MS ?? 700
122121
const cooldown = Flag.OPENCODE_EXPERIMENTAL_HOT_RELOAD_COOLDOWN_MS ?? 1500
123-
const mode = Flag.OPENCODE_EXPERIMENTAL_HOT_RELOAD_MODE === "manual" ? "manual" : "auto"
124122
let timer: ReturnType<typeof setTimeout> | undefined
125123
let busy = false
126124
let last = 0
@@ -142,11 +140,6 @@ export namespace HotReload {
142140
await Command.reset()
143141
}
144142

145-
const schedule = () => {
146-
if (timer) clearTimeout(timer)
147-
timer = setTimeout(() => flush("timer"), debounce)
148-
}
149-
150143
const flush = (reason: "timer" | "session" | "api") => {
151144
timer = undefined
152145
if (busy) return { ok: true, queued, sessions: active() }
@@ -193,16 +186,14 @@ export namespace HotReload {
193186
busy = false
194187
if (!latest) return
195188
if (timer) clearTimeout(timer)
196-
timer = setTimeout(() => flush("timer"), debounce)
189+
timer = setTimeout(() => flush("timer"), 0)
197190
})
198191
return { ok: true, queued: false, sessions }
199192
}
200193

201-
const request = (hit: { file: string; event: "add" | "change" | "unlink" }, mode: "file" | "api") => {
194+
const request = (hit: { file: string; event: "add" | "change" | "unlink" }) => {
202195
latest = hit
203-
if (mode === "api") return flush("api")
204-
schedule()
205-
return { ok: true, queued, sessions: active() }
196+
return flush("api")
206197
}
207198

208199
const unsubFile = Bus.subscribe(FileWatcher.Event.Updated, (event) => {
@@ -215,8 +206,6 @@ export namespace HotReload {
215206
} as const
216207

217208
void Bus.publish(Event.Changed, hit)
218-
if (mode === "manual") return
219-
void request(hit, "file")
220209
})
221210

222211
const unsubSession = Bus.subscribe(SessionStatus.Event.Status, () => {
@@ -225,7 +214,7 @@ export namespace HotReload {
225214
timer = setTimeout(() => flush("session"), 0)
226215
})
227216

228-
log.info("hot reload enabled", { debounce, cooldown, mode })
217+
log.info("hot reload enabled", { cooldown, mode: "manual" })
229218
return {
230219
unsubFile,
231220
unsubSession,
@@ -256,7 +245,7 @@ export namespace HotReload {
256245
}
257246
const file = input?.file?.trim() || "api"
258247
const event = input?.event || "change"
259-
const result = req({ file, event }, "api")
248+
const result = req({ file, event })
260249
return { ...result, enabled: true }
261250
}
262251
}

0 commit comments

Comments
 (0)