Craft Anything: understand how any software works, and craft your own.
Rust
Look up a relative program where it starts before calling its path empty (#772)
FuryNocturnTV (Tare Fernandez)4d6e3b01bfe1
diff --git a/crates/platform/src/process.rs b/crates/platform/src/process.rsindex a23d5aa9..fd949ced 100644--- a/crates/platform/src/process.rs+++ b/crates/platform/src/process.rs@@ -300,7 +300,7 @@ impl Process {// output is piped here, so it never needs one.#[cfg(windows)]wrap.wrap(process_wrap::std::JobObject).wrap(process_wrap::std::CreationFlags(windows::Win32::System::Threading::CREATE_NO_WINDOW));- let mut child = wrap.spawn().map_err(|e| spawn_error(&name, &self.program, e, self.remediation.as_deref()))?;+ let mut child = wrap.spawn().map_err(|e| spawn_error(&name, &self.program, self.cwd.as_deref(), e, self.remediation.as_deref()))?;let pid = child.id();let start = Instant::now();let activity = Arc::new(AtomicU64::new(0));@@ -367,11 +367,23 @@ fn use_search_path(cmd: &mut std::process::Command) {}}-fn spawn_error(name: &str, program: &OsStr, e: std::io::Error, remediation: Option<&str>) -> ToolError {- let found = crate::which::which_in(&program.to_string_lossy(), crate::which::search_path()).into_iter().next();+fn spawn_error(name: &str, program: &OsStr, cwd: Option<&std::path::Path>, e: std::io::Error, remediation: Option<&str>) -> ToolError {+ // Unix starts a relative path from the folder the child runs in; Windows from ours.+ let looked_up = if cfg!(unix) { started_from(program, cwd) } else { std::path::PathBuf::from(program) };+ let found = crate::which::which_in(&looked_up.to_string_lossy(), crate::which::search_path()).into_iter().next();spawn_error_for(name, program, e, remediation, found)}+/// Where a program given by a relative path is when it starts in `cwd`. A bare name is left for+/// the PATH lookup.+fn started_from(program: &OsStr, cwd: Option<&std::path::Path>) -> std::path::PathBuf {+ let path = std::path::Path::new(program);+ match cwd {+ Some(dir) if path.is_relative() && path.components().count() > 1 => dir.join(path),+ _ => path.to_path_buf(),+ }+}+/// `found` is where the program was looked up. "Not found" from the system for a file that is/// there means something it needs is missing (the interpreter of an npm script, #152, #95): saying/// the program isn't installed sent people to reinstall what they had.@@ -920,7 +932,7 @@ impl Launch {const CREATE_NO_WINDOW: u32 = 0x0800_0000;cmd.creation_flags(CREATE_NO_WINDOW);}- let child = cmd.spawn().map_err(|e| spawn_error(&name, &self.program, e, self.remediation.as_deref()))?;+ let child = cmd.spawn().map_err(|e| spawn_error(&name, &self.program, self.cwd.as_deref(), e, self.remediation.as_deref()))?;let launched = Launched { pid: child.id(), started: Instant::now(), state: Arc::new(Mutex::new(LaunchState { child: Some(child), ended: None })) };// Reap it when it closes. If no thread can be made the child still runs (and `ended`// stays unknown); on Unix it stays a zombie until we exit, which is harmless.@@ -1318,6 +1330,20 @@ mod error_tests {assert!(err.message.contains("isn't on your PATH"), "{}", err.message);assert_eq!(err.details.as_ref().and_then(|d| d["reason"].as_str()), Some("not_found"));}++ /// A relative path is looked up in the folder the program starts in, not in ours; a bare name+ /// and an absolute path are left as they are.+ #[test]+ fn a_relative_program_is_looked_up_where_it_starts() {+ use std::path::Path;+ let dir = Path::new("project");+ let rel = Path::new("bin").join("agent");+ assert_eq!(started_from(rel.as_os_str(), Some(dir)), dir.join(&rel));+ assert_eq!(started_from(rel.as_os_str(), None), rel);+ assert_eq!(started_from(OsStr::new("agent"), Some(dir)), Path::new("agent"));+ let abs = std::env::temp_dir().join("agent");+ assert_eq!(started_from(abs.as_os_str(), Some(dir)), abs);+ }}#[cfg(all(test, unix))]@@ -1349,6 +1375,22 @@ mod tests {assert_eq!(err.details.as_ref().and_then(|d| d["reason"].as_str()), Some("not_found"));}+ /// The same script by a relative path, started in its project: it is there (where it was+ /// started), so it isn't reported as a path with no file.+ #[test]+ fn a_relative_program_that_cannot_start_is_found_in_its_own_folder() {+ use std::os::unix::fs::PermissionsExt as _;+ let dir = tempfile::tempdir().unwrap();+ std::fs::create_dir(dir.path().join("bin")).unwrap();+ let script = dir.path().join("bin").join("agent");+ std::fs::write(&script, "#!/nonexistent/interpreter\n").unwrap();+ std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();+ let err = Process::new("./bin/agent").cwd(dir.path()).run().unwrap_err();+ assert_eq!(err.details.as_ref().and_then(|d| d["reason"].as_str()), Some("found_but_not_started"), "{}", err.message);+ let err = Launch::new("./bin/agent").cwd(dir.path()).start_watched().map(|_| ()).unwrap_err();+ assert_eq!(err.details.as_ref().and_then(|d| d["reason"].as_str()), Some("found_but_not_started"), "{}", err.message);+ }+#[test]fn captures_output_and_exit_code() {let out = Process::new("sh").args(["-c", "echo hello; echo oops >&2; exit 3"]).run().unwrap();diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 648ee02d..eda4f1c5 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -410,6 +410,9 @@ Owner: open · Status: in progress- [x] A saved agent program path that no longer exists (Codex desktop moves its CLI to a newbuild folder on every update) says so and names the path, instead of "isn't installed orisn't on your PATH" (#721); it stays a missing program, so a builder turn isn't retried+- [x] A relative program path started in another folder is looked up where it was started+ before it's reported as missing (Unix: a script whose interpreter is missing was said to+ have no file there)- [ ] When a saved Codex desktop path is gone, offer the CLI found in its newest build folder(asking first, never replacing a custom program silently), and let Detect/Test check theconfigured program itself (#721)diff --git a/docs/STATUS.md b/docs/STATUS.mdindex 9ebc09ad..9a33efb4 100644--- a/docs/STATUS.md+++ b/docs/STATUS.md@@ -13,7 +13,7 @@ workspace clippy, layers, fmt and the secret scan of all history were clean. Chi| SQLite payload limits | Capped records retain column positions, disclose partial TEXT and BLOB values, omit incomplete BLOB hashes, and report partial coverage with read notes | Hand-built overflow-page regressions for five oversized records (including WITHOUT ROWID in declaration order) and two controls; table and index engine coverage and limitation regressions || SQLite added columns | Short records include missing trailing fields using literal column defaults, or NULL when absent; unsupported default expressions produce NULL with a row note. Stored fields and records longer than the schema retain their values. Defaults are filled before restoring rowid aliases | Nine hand-built parser regressions and an engine tool test cover added-column defaults, rewritten records and short records with a rowid alias, including a missing alias field || OpenCode models and thinking | OpenCode V2 locally and over SSH; Settings → AI lists only that instance's enabled chat models and supported Low/Medium/High/Xhigh/Max variants. Selection is validated and saved through UI, CLI and `ai_models_list` / `ai_model_set`. Explicit-selection execution is refused until native MCP integration exists; local ACP runs require clearing the selection. See [OpenCode](opencode.md). | Stand-in catalogue/process, persistence, remote-command and UI tests; local live catalogue checks (34 models, all five depths represented). Regression checks reject native chat/builds before process I/O with ACP on/off, local/SSH and model-only/depth-only/combined selections. No live SSH host or paid generation used |-| Missing program paths | A program started by its path (a saved agent program, for one) that has no file there is reported with that path, as possibly moved by an update, with reason `path_missing`, instead of "isn't installed or isn't on your PATH"; a bare name still speaks of PATH. It stays a missing program (`EngineMissing`), so builder turns aren't retried (#721) | A regression starts a program at a path with no file on Windows 10 and checks the message, remediation and reason, with a bare-name control. Not checked: a real Codex desktop update, or the app's Settings screen with a stale path |+| Missing program paths | A program started by its path (a saved agent program, for one) that has no file there is reported with that path, as possibly moved by an update, with reason `path_missing`, instead of "isn't installed or isn't on your PATH"; a bare name still speaks of PATH. A relative path is looked up where the program starts (on Unix, its working folder), so a script there whose interpreter is missing isn't called a path with no file. It stays a missing program (`EngineMissing`), so builder turns aren't retried (#721) | A regression starts a program at a path with no file on Windows 10 and checks the message, remediation and reason, with a bare-name control; on Linux (Docker), a relative script with a missing interpreter started in its folder, through `Process` and `Launch`. Not checked: a real Codex desktop update, or the app's Settings screen with a stale path || Mach-O Objective-C pointers | Chained offsets mapped only into file-empty `__PAGEZERO` reach the image-base fallback; pointer candidates must be backed by file bytes | Synthetic thin and fat Mach-O regression, plain-pointer and authenticated-rebase controls, null and unmapped-pointer checks. Real binaries were not checked for this correction || Apple app graphs | Selecting a macOS bundle recognises its root-relative `Contents/Info.plist` and retains its service/extension type; nested XPC bundles appear in `services` and as `xpc-service` graph nodes, including their executables when hosted in frameworks | Synthetic inventory tests, including parent-directory and flat bundle layouts, selected services/extensions, framework-hosted service executables, and bare-program controls. Ordinary selected directories with `Contents/Info.plist` need an Apple bundle suffix; archives retain layout-based recognition. Framework libraries and dylibs stay excluded from executables. Real app bundles were not checked for this correction || Chinese UI | Simplified (`zh-hans`) and Traditional (`zh-hant`) Chinese in Settings → General → Language; System chooses a supported OS language, otherwise English. Both catalogs cover UI controls and tool titles; translated titles are searchable. Raw tool data, AI text, logs, CLI/MCP and the separate browser viewer keep their original text. See [localisation](localization.md). | Catalog integrity and locale-resolution tests; `cargo xtask i18n-coverage`; isolated UI language-switch test. Platform visual checks are recorded separately. |