File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Server } from "../../server/server"
22import { cmd } from "./cmd"
33import { withNetworkOptions , resolveNetworkOptions } from "../network"
44import { Flag } from "@opencode-ai/core/flag/flag"
5+ import { bootstrap } from "../bootstrap"
56
67export const ServeCommand = cmd ( {
78 command : "serve" ,
@@ -11,7 +12,8 @@ export const ServeCommand = cmd({
1112 if ( ! Flag . OPENCODE_SERVER_PASSWORD ) {
1213 console . log ( "Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured." )
1314 }
14- const opts = await resolveNetworkOptions ( args )
15+
16+ const opts = await bootstrap ( process . cwd ( ) , ( ) => resolveNetworkOptions ( args ) )
1517 const server = await Server . listen ( opts )
1618 console . log ( `opencode server listening on http://${ server . hostname } :${ server . port } ` )
1719
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { UI } from "@/cli/ui"
88import * as Log from "@opencode-ai/core/util/log"
99import { errorMessage } from "@/util/error"
1010import { withTimeout } from "@/util/timeout"
11+ import { Instance } from "@/project/instance"
1112import { withNetworkOptions , resolveNetworkOptionsNoConfig } from "@/cli/network"
1213import { Filesystem } from "@/util/filesystem"
1314import type { GlobalEvent } from "@opencode-ai/sdk/v2"
@@ -187,7 +188,11 @@ export const TuiThreadCommand = cmd({
187188 const prompt = await input ( args . prompt )
188189 const config = await TuiConfig . get ( )
189190
190- const network = resolveNetworkOptionsNoConfig ( args )
191+ const network = await Instance . provide ( {
192+ directory : cwd ,
193+ fn : ( ) => resolveNetworkOptionsNoConfig ( args ) ,
194+ } )
195+
191196 const external =
192197 process . argv . includes ( "--port" ) ||
193198 process . argv . includes ( "--hostname" ) ||
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { withNetworkOptions, resolveNetworkOptions } from "../network"
55import { Flag } from "@opencode-ai/core/flag/flag"
66import open from "open"
77import { networkInterfaces } from "os"
8+ import { bootstrap } from "../bootstrap"
89
910function getNetworkIPs ( ) {
1011 const nets = networkInterfaces ( )
@@ -36,7 +37,7 @@ export const WebCommand = cmd({
3637 if ( ! Flag . OPENCODE_SERVER_PASSWORD ) {
3738 UI . println ( UI . Style . TEXT_WARNING_BOLD + "! OPENCODE_SERVER_PASSWORD is not set; server is unsecured." )
3839 }
39- const opts = await resolveNetworkOptions ( args )
40+ const opts = await bootstrap ( process . cwd ( ) , ( ) => resolveNetworkOptions ( args ) )
4041 const server = await Server . listen ( opts )
4142 UI . empty ( )
4243 UI . println ( UI . logo ( " " ) )
Original file line number Diff line number Diff line change @@ -48,14 +48,32 @@ import { ShareNext } from "@/share/share-next"
4848import { SessionShare } from "@/share/session"
4949import { Npm } from "@opencode-ai/core/npm"
5050import { memoMap } from "@opencode-ai/core/effect/memo-map"
51+ import * as Effect from "effect/Effect"
52+
53+ // Adjusts the default Config layer to ensure that plugins are always initialised before
54+ // any other layers read the current config
55+ const ConfigWithPluginPriority = Layer . effect (
56+ Config . Service ,
57+ Effect . gen ( function * ( ) {
58+ const config = yield * Config . Service
59+ const plugin = yield * Plugin . Service
60+
61+ return {
62+ ...config ,
63+ get : ( ) => Effect . andThen ( plugin . init ( ) , config . get ) ,
64+ getGlobal : ( ) => Effect . andThen ( plugin . init ( ) , config . getGlobal ) ,
65+ getConsoleState : ( ) => Effect . andThen ( plugin . init ( ) , config . getConsoleState ) ,
66+ }
67+ } ) ,
68+ ) . pipe ( Layer . provide ( Layer . merge ( Plugin . defaultLayer , Config . defaultLayer ) ) )
5169
5270export const AppLayer = Layer . mergeAll (
5371 Npm . defaultLayer ,
5472 AppFileSystem . defaultLayer ,
5573 Bus . defaultLayer ,
5674 Auth . defaultLayer ,
5775 Account . defaultLayer ,
58- Config . defaultLayer ,
76+ ConfigWithPluginPriority ,
5977 Git . defaultLayer ,
6078 Ripgrep . defaultLayer ,
6179 File . defaultLayer ,
Original file line number Diff line number Diff line change 1- import { Plugin } from "../plugin"
21import { Format } from "../format"
32import { LSP } from "@/lsp/lsp"
43import { File } from "../file"
@@ -16,20 +15,19 @@ import { Config } from "@/config/config"
1615
1716export const InstanceBootstrap = Effect . gen ( function * ( ) {
1817 Log . Default . info ( "bootstrapping" , { directory : Instance . directory } )
19- // everything depends on config so eager load it for nice traces
20- yield * Config . Service . use ( ( svc ) => svc . get ( ) )
21- // Plugin can mutate config so it has to be initialized before anything else.
22- yield * Plugin . Service . use ( ( svc ) => svc . init ( ) )
2318 yield * Effect . all (
2419 [
25- LSP . Service ,
26- ShareNext . Service ,
27- Format . Service ,
28- File . Service ,
29- FileWatcher . Service ,
30- Vcs . Service ,
31- Snapshot . Service ,
32- ] . map ( ( s ) => Effect . forkDetach ( s . use ( ( i ) => i . init ( ) ) ) ) ,
20+ Config . Service . use ( ( i ) => i . get ( ) ) ,
21+ ...[
22+ LSP . Service ,
23+ ShareNext . Service ,
24+ Format . Service ,
25+ File . Service ,
26+ FileWatcher . Service ,
27+ Vcs . Service ,
28+ Snapshot . Service ,
29+ ] . map ( ( s ) => s . use ( ( i ) => i . init ( ) ) ) ,
30+ ] . map ( ( e ) => Effect . forkDetach ( e ) ) ,
3331 ) . pipe ( Effect . withSpan ( "InstanceBootstrap.init" ) )
3432
3533 yield * Bus . Service . use ( ( svc ) =>
You can’t perform that action at this time.
0 commit comments