@@ -1152,192 +1152,16 @@ pub(crate) fn classify_runtime(
11521152 }
11531153}
11541154
1155- /// The oldest `codex-acp` version supported by Buzz managed agents.
1156- ///
1157- /// Older 1.x adapters are detected successfully, but can still bundle a Codex runtime
1158- /// that does not reliably give `buzz` CLI subprocesses outbound relay access.
1159- ///
1160- /// Bump policy: raise this only when a newer adapter fixes a defect that breaks managed
1161- /// agents, and only to a version already published on npm — every user below the floor is
1162- /// offered a reinstall on their next discovery pass.
1163- pub ( crate ) const MIN_CODEX_ACP_VERSION : ( u64 , u64 , u64 ) = ( 1 , 1 , 7 ) ;
1164-
1165- /// Probe the full version of a `codex-acp` binary by running `--version`.
1166- ///
1167- /// The 1.x adapter (`@agentclientprotocol/codex-acp`) outputs
1168- /// `@agentclientprotocol/codex-acp <major>.<minor>.<patch>` on stdout and exits 0.
1169- /// The old 0.16.x adapter (`@zed-industries/codex-acp`) is a Rust binary that does
1170- /// not recognise `--version` and exits non-zero.
1171- ///
1172- /// Returns the `(major, minor, patch)` triple on success, `None` on any failure
1173- /// (non-zero exit, unparseable output, timeout, or missing binary).
1174- ///
1175- /// The parse is deliberately strict: exactly three numeric dot-separated components.
1176- /// Partial versions (`1.2`) and prerelease tags (`1.2.0-rc1`) return `None` and so
1177- /// classify as [`AcpAvailabilityStatus::AdapterOutdated`] — failing closed offers a
1178- /// reinstall rather than running an adapter whose version cannot be compared.
1179- ///
1180- /// The probe is bounded by a 5-second deadline. The child is polled with
1181- /// [`std::process::Child::try_wait`] (the repo's standard deadline pattern) and
1182- /// killed if it does not exit in time.
1183- ///
1184- /// Stdout is redirected to a temporary file rather than a pipe, so forked
1185- /// descendants cannot hold EOF open. Reads from a regular file return EOF at its
1186- /// current write position regardless of inherited file descriptors, cross-platform.
1187- pub ( crate ) fn probe_codex_acp_version ( binary_path : & Path ) -> Option < ( u64 , u64 , u64 ) > {
1188- probe_codex_acp_version_with_path (
1189- binary_path,
1190- crate :: managed_agents:: readiness:: cli_probe:: augmented_path ( ) . as_deref ( ) ,
1191- )
1192- }
1193- pub ( crate ) fn probe_codex_acp_version_with_path (
1194- binary_path : & Path ,
1195- augmented_path : Option < & str > ,
1196- ) -> Option < ( u64 , u64 , u64 ) > {
1197- probe_codex_acp_version_inner ( binary_path, augmented_path, None )
1198- }
1199-
1200- fn probe_codex_acp_version_with_plan (
1201- binary_path : & Path ,
1202- plan : & super :: runtime_plan:: RuntimeExecutionPlan ,
1203- ) -> Option < ( u64 , u64 , u64 ) > {
1204- probe_codex_acp_version_inner (
1205- binary_path,
1206- plan. generated_environment ( "PATH" ) ,
1207- Some ( plan) ,
1208- )
1209- }
1210-
1211- fn probe_codex_acp_version_inner (
1212- binary_path : & Path ,
1213- augmented_path : Option < & str > ,
1214- runtime_plan : Option < & super :: runtime_plan:: RuntimeExecutionPlan > ,
1215- ) -> Option < ( u64 , u64 , u64 ) > {
1216- use std:: io:: { Read as _, Seek as _, SeekFrom } ;
1217- use std:: time:: { Duration , Instant } ;
1218- const VERSION_PROBE_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
1219-
1220- // A regular file returns EOF at its current size even when a descendant
1221- // inherits its descriptor, bounding the post-exit read cross-platform.
1222- let mut tmp = tempfile:: tempfile ( ) . ok ( ) ?;
1223-
1224- let mut command = Command :: new ( binary_path) ;
1225- command. arg ( "--version" ) ;
1226- if let Some ( path) = augmented_path {
1227- command. env ( "PATH" , path) ;
1228- }
1229- if let Some ( plan) = runtime_plan {
1230- plan. apply_environment ( & mut command) ;
1231- }
1232- crate :: util:: configure_no_window ( & mut command) ;
1233- let mut child = command
1234- . stdout ( tmp. try_clone ( ) . ok ( ) ?)
1235- . stderr ( std:: process:: Stdio :: null ( ) )
1236- . spawn ( )
1237- . ok ( ) ?;
1238-
1239- // Poll until the deadline rather than blocking on stdout EOF.
1240- let deadline = Instant :: now ( ) + VERSION_PROBE_TIMEOUT ;
1241- let exit_status = loop {
1242- match child. try_wait ( ) {
1243- Ok ( Some ( status) ) => break status,
1244- Ok ( None ) => {
1245- if Instant :: now ( ) >= deadline {
1246- let _ = child. kill ( ) ;
1247- let _ = child. wait ( ) ;
1248- return None ;
1249- }
1250- std:: thread:: sleep ( Duration :: from_millis ( 50 ) ) ;
1251- }
1252- Err ( _) => {
1253- let _ = child. kill ( ) ;
1254- let _ = child. wait ( ) ;
1255- return None ;
1256- }
1257- }
1258- } ;
1259-
1260- if !exit_status. success ( ) {
1261- return None ;
1262- }
1263-
1264- // Read at most 4 KiB from the regular file without blocking.
1265- tmp. seek ( SeekFrom :: Start ( 0 ) ) . ok ( ) ?;
1266- let mut buf = Vec :: with_capacity ( 128 ) ;
1267- let _ = ( & mut tmp as & mut dyn std:: io:: Read )
1268- . take ( 4096 )
1269- . read_to_end ( & mut buf) ;
1270-
1271- let stdout = String :: from_utf8_lossy ( & buf) ;
1272- // Output format: "<package-name> <major>.<minor>.<patch>"
1273- let version_str = stdout. split_whitespace ( ) . last ( ) ?;
1274- let mut components = version_str. split ( '.' ) ;
1275- let major = components. next ( ) ?. parse :: < u64 > ( ) . ok ( ) ?;
1276- let minor = components. next ( ) ?. parse :: < u64 > ( ) . ok ( ) ?;
1277- let patch = components. next ( ) ?. parse :: < u64 > ( ) . ok ( ) ?;
1278- if components. next ( ) . is_some ( ) {
1279- return None ;
1280- }
1281- Some ( ( major, minor, patch) )
1282- }
1283-
1284- /// Classifies a resolved codex-acp binary path as [`AcpAvailabilityStatus::Available`]
1285- /// or [`AcpAvailabilityStatus::AdapterOutdated`].
1286- ///
1287- /// The 0.16.x adapter (`@zed-industries/codex-acp`) does not recognise `--version`
1288- /// and exits non-zero — that probe failure yields `AdapterOutdated`. An adapter is
1289- /// available only when its version is at least [`MIN_CODEX_ACP_VERSION`].
1290- ///
1291- /// Used by `discover_acp_runtimes`, `cli_login_requirements`, and
1292- /// `install_acp_runtime_blocking` so the version-gate logic is not duplicated.
1293- pub ( crate ) fn codex_adapter_availability ( path : & Path ) -> AcpAvailabilityStatus {
1294- match probe_codex_acp_version ( path) {
1295- Some ( version) if version >= MIN_CODEX_ACP_VERSION => AcpAvailabilityStatus :: Available ,
1296- _ => AcpAvailabilityStatus :: AdapterOutdated ,
1297- }
1298- }
1299-
1300- pub ( crate ) fn codex_adapter_availability_with_plan (
1301- plan : & super :: runtime_plan:: RuntimeExecutionPlan ,
1302- ) -> AcpAvailabilityStatus {
1303- let version = plan
1304- . harness_path ( )
1305- . ok ( )
1306- . and_then ( |path| {
1307- plan. verify ( )
1308- . ok ( )
1309- . and_then ( |( ) | probe_codex_acp_version_with_plan ( path, plan) )
1310- } ) ;
1311- match version {
1312- Some ( version) if version >= MIN_CODEX_ACP_VERSION => AcpAvailabilityStatus :: Available ,
1313- _ => AcpAvailabilityStatus :: AdapterOutdated ,
1314- }
1315- }
1155+ mod codex_version;
13161156
1317- /// Returns `true` when the codex-acp binary at `path` is below
1318- /// [`MIN_CODEX_ACP_VERSION`] or cannot be probed using `augmented_path`. Thin wrapper
1319- /// around [`codex_adapter_is_outdated_with_path`].
1157+ pub ( crate ) use codex_version:: {
1158+ codex_adapter_availability, codex_adapter_availability_with_plan,
1159+ codex_adapter_is_outdated_with_path, probe_codex_acp_version,
1160+ probe_codex_acp_version_with_path, MIN_CODEX_ACP_VERSION ,
1161+ } ;
13201162#[ cfg( test) ]
1321- pub ( crate ) fn codex_adapter_is_outdated ( path : & Path ) -> bool {
1322- codex_adapter_is_outdated_with_path (
1323- path,
1324- crate :: managed_agents:: readiness:: cli_probe:: augmented_path ( ) . as_deref ( ) ,
1325- )
1326- }
1327-
1328- /// Returns `true` when the codex-acp binary at `path` is below
1329- /// [`MIN_CODEX_ACP_VERSION`] or cannot be probed with the supplied PATH.
1330- pub ( crate ) fn codex_adapter_is_outdated_with_path (
1331- path : & Path ,
1332- augmented_path : Option < & str > ,
1333- ) -> bool {
1334- !matches ! (
1335- probe_codex_acp_version_with_path( path, augmented_path) ,
1336- Some ( version) if version >= MIN_CODEX_ACP_VERSION
1337- )
1338- }
1163+ pub ( crate ) use codex_version:: codex_adapter_is_outdated;
13391164
1340- /// Intermediate struct built before the (potentially slow) auth probe phase.
13411165struct PartialEntry {
13421166 runtime : & ' static KnownAcpRuntime ,
13431167 entry : AcpRuntimeCatalogEntry ,
0 commit comments