@@ -8,12 +8,19 @@ local function command_exists(cmd)
88end
99
1010local function get_opencode_version ()
11- local runtime_cmd = util .get_runtime_command ()
11+ local runtime_cmd , runtime_cmd_err = util .get_runtime_command ()
12+ if not runtime_cmd then
13+ return nil , runtime_cmd_err
14+ end
15+
1216 if not command_exists (runtime_cmd [1 ]) then
1317 return nil , ' opencode runtime command not found: ' .. tostring (runtime_cmd [1 ])
1418 end
1519
16- local cmd = util .get_runtime_version_command ()
20+ local cmd , cmd_err = util .get_runtime_version_command ()
21+ if not cmd then
22+ return nil , cmd_err
23+ end
1724
1825 local result = vim .system (cmd ):wait ()
1926 if result .code ~= 0 then
@@ -29,8 +36,11 @@ local function check_opencode_cli()
2936 health .start (' OpenCode CLI' )
3037
3138 local config = require (' opencode.config' )
32- local runtime = config .runtime or {}
33- local connection = runtime .connection or ' spawn'
39+ local connection , connection_err = util .get_runtime_connection ()
40+ if not connection then
41+ health .error (connection_err )
42+ return
43+ end
3444
3545 if connection == ' remote' then
3646 health .info (' CLI executable checks are skipped in remote runtime mode' )
@@ -40,7 +50,12 @@ local function check_opencode_cli()
4050 local state = require (' opencode.state' )
4151 local required_version = state .required_version
4252
43- local runtime_cmd = util .get_runtime_command ()
53+ local runtime_cmd , runtime_cmd_err = util .get_runtime_command ()
54+ if not runtime_cmd then
55+ health .error (runtime_cmd_err )
56+ return
57+ end
58+
4459 if not command_exists (runtime_cmd [1 ]) then
4560 health .error (' opencode runtime command not found' , {
4661 ' Install opencode CLI from: https://docs.opencode.com/installation' ,
@@ -73,21 +88,19 @@ local function check_opencode_server()
7388
7489 local config = require (' opencode.config' )
7590 local runtime = config .runtime or {}
76- local connection = runtime .connection or ' spawn'
91+ local connection , connection_err = util .get_runtime_connection ()
92+ if not connection then
93+ health .error (connection_err )
94+ return
95+ end
7796
7897 if connection == ' remote' then
79- local remote_url = runtime .remote_url
80- if type ( remote_url ) ~= ' string ' or remote_url == ' ' then
81- health .error (' runtime.remote_url is required when runtime.connection is "remote" ' )
98+ local normalized_remote_url , remote_url_err = util . normalize_remote_url ( runtime .remote_url )
99+ if not normalized_remote_url then
100+ health .error (remote_url_err )
82101 return
83102 end
84103
85- local normalized_remote_url = remote_url
86- if normalized_remote_url :match (' ^%d+%.%d+%.%d+%.%d+:%d+$' ) or normalized_remote_url :match (' ^localhost:%d+$' ) then
87- normalized_remote_url = ' http://' .. normalized_remote_url
88- end
89- normalized_remote_url = normalized_remote_url :gsub (' /$' , ' ' )
90-
91104 local server_job = require (' opencode.server_job' )
92105 local ok , result = pcall (function ()
93106 return server_job .call_api (normalized_remote_url .. ' /config' , ' GET' , nil ):wait ()
0 commit comments