diff --git a/crates/setup/src/clients.rs b/crates/setup/src/clients.rs index 793a4f411..481981a34 100644 --- a/crates/setup/src/clients.rs +++ b/crates/setup/src/clients.rs @@ -79,13 +79,24 @@ impl Host { self.env.get(k).filter(|v| !v.is_empty()).map(|v| self.expand(v)) } - /// Expand a leading `~` and make relative paths relative to home. + /// Expand a leading `~` (`~/...`, plus `~\...` on Windows) and make relative paths relative to home. fn expand(&self, v: &str) -> PathBuf { if v == "~" { return self.home.clone(); } + if self.os == Os::Windows + && let Some(rest) = v.strip_prefix("~/").or_else(|| v.strip_prefix("~\\")) + { + if std::path::Path::new(rest).is_absolute() { + return PathBuf::from(rest); + } + if !rest.contains(':') { + return rest.split(['/', '\\']).filter(|s| !s.is_empty()).fold(self.home.clone(), |acc, seg| acc.join(seg)); + } + } if let Some(rest) = v.strip_prefix("~/") { - return self.home.join(rest); + let rest = rest.trim_start_matches('/'); + return if rest.is_empty() { self.home.clone() } else { self.home.join(rest) }; } let p = PathBuf::from(v); if p.is_absolute() { p } else { self.home.join(p) } @@ -378,16 +389,7 @@ pub fn clients(host: &Host) -> Vec { // Qoder let qoder = host.var("QODER_CONFIG_DIR").unwrap_or_else(|| h.join(".qoder")); - add( - "qoder", - "Qoder", - qoder.join("settings.json"), - vec![qoder.clone()], - Format::Jsonc, - vec!["mcpServers"], - Shape::Plain, - Some(h.join(".qoder").join("skills")), - ); + add("qoder", "Qoder", qoder.join("settings.json"), vec![qoder.clone()], Format::Jsonc, vec!["mcpServers"], Shape::Plain, Some(qoder.join("skills"))); // Devin let devin = match host.os { diff --git a/crates/setup/tests/qoder_skills_and_windows_tilde.rs b/crates/setup/tests/qoder_skills_and_windows_tilde.rs new file mode 100644 index 000000000..a84d27b43 --- /dev/null +++ b/crates/setup/tests/qoder_skills_and_windows_tilde.rs @@ -0,0 +1,122 @@ +//! Regressions for `QODER_CONFIG_DIR` skill-directory overrides and Windows `~\` tilde-prefix +//! path expansion in `craft_anything_setup::clients`. + +use craft_anything_setup::{CheckStatus, DoctorRequest, Host, Os, PlanRequest, apply, clients, doctor, plan, uninstall}; +use std::collections::BTreeMap; +use std::path::Path; + +/// `QODER_CONFIG_DIR` relocates Qoder's configuration folder, so `skills_dir` must follow that +/// override across `clients`, `plan`, `apply`, `doctor`, and `uninstall` instead of writing into +/// `/.qoder/skills`. +#[test] +fn qoder_config_dir_override_moves_skills_with_settings() { + let dir = tempfile::tempdir().unwrap(); + let home = dir.path().join("home"); + let custom_qoder = dir.path().join("custom-qoder"); + std::fs::create_dir_all(&home).unwrap(); + std::fs::create_dir_all(&custom_qoder).unwrap(); + + let cli = dir.path().join(if cfg!(windows) { "craft-anything-cli.exe" } else { "craft-anything-cli" }); + std::fs::write(&cli, "").unwrap(); + + let mut host = Host::with_home(&home); + host.env.insert("QODER_CONFIG_DIR".into(), custom_qoder.display().to_string()); + + let qoder = clients(&host).into_iter().find(|c| c.id == "qoder").expect("qoder client"); + assert_eq!(qoder.config, custom_qoder.join("settings.json")); + assert_eq!(qoder.skills_dir, custom_qoder.join("skills")); + + let req = PlanRequest { clients: vec!["qoder".into()], all_detected: false, command: vec![cli.display().to_string(), "mcp".into()], include_skill: true }; + let p = plan(&host, &req).expect("plan qoder"); + assert!(!p.blocked, "{:?}", p.actions); + assert_eq!(p.skills.len(), 1); + assert_eq!(p.skills[0].dir, custom_qoder.join("skills")); + + let rep = apply(&p); + assert_eq!(rep.status, "configured"); + assert!(custom_qoder.join("skills").join("craft-anything").join("SKILL.md").is_file()); + assert!(!home.join(".qoder").exists(), "default ~/.qoder must not be created when QODER_CONFIG_DIR is set"); + + let doc = doctor(&host, &DoctorRequest { clients: vec!["qoder".into()], cli_path: Some(cli), extra: Vec::new(), self_test: false, engines: false }); + assert!(doc.healthy, "{:?}", doc.checks); + let skill_check_name = format!("skill:{}", custom_qoder.join("skills").display()); + assert!( + doc.checks.iter().any(|c| c.name == skill_check_name && c.status == CheckStatus::Ok), + "expected Ok skill check for {skill_check_name}, got: {:?}", + doc.checks + ); + + let un = uninstall(&host); + assert_eq!(un.status, "removed"); + assert!(!custom_qoder.join("skills").join("craft-anything").exists()); +} + +/// On Windows (`Os::Windows`), `Host::var` expands leading `~\` backslash home prefixes (including +/// nested segments and bare `~\`) relative to `host.home` instead of creating a literal `~` folder. +#[test] +fn windows_host_expands_backslash_tilde_prefixes_without_literal_tilde_segment() { + let dir = tempfile::tempdir().unwrap(); + let home = dir.path().join("Users").join("dev"); + let mut env = BTreeMap::new(); + env.insert("CODEX_HOME".into(), r"~\.codex-custom".into()); + env.insert("HERMES_HOME".into(), r"~\AppData\Local\hermes-custom".into()); + env.insert("GROK_HOME".into(), r"~/AppData\Local\grok-mixed".into()); + env.insert("KIMI_CODE_HOME".into(), r"~\sub1/sub2\kimi".into()); + env.insert("QWEN_HOME".into(), r"~\".into()); + env.insert("QODER_CONFIG_DIR".into(), r"~\.qoder-win".into()); + #[cfg(windows)] + { + env.insert("COPILOT_HOME".into(), r"~/D:\copilot-abs".into()); + env.insert("PI_CODING_AGENT_DIR".into(), r"~\sub\C:\other".into()); + } + let host = Host { home: home.clone(), env, os: Os::Windows }; + + let cs = clients(&host); + let of = |id: &str| cs.iter().find(|c| c.id == id).unwrap_or_else(|| panic!("missing {id}")); + + assert_eq!(of("codex").config, home.join(".codex-custom").join("config.toml")); + assert_eq!(of("hermes").config, home.join("AppData").join("Local").join("hermes-custom").join("config.yaml")); + assert_eq!(of("grok_build").config, home.join("AppData").join("Local").join("grok-mixed").join("config.toml")); + assert_eq!(of("kimi_code").config, home.join("sub1").join("sub2").join("kimi").join("mcp.json")); + assert_eq!(of("qwen_code").config, home.join("settings.json")); + assert_eq!(of("qwen_code").markers[0].as_os_str(), home.as_os_str()); + assert_eq!(of("qoder").config, home.join(".qoder-win").join("settings.json")); + assert_eq!(of("qoder").skills_dir, home.join(".qoder-win").join("skills")); + #[cfg(windows)] + { + assert_eq!(of("copilot_cli").config, Path::new(r"D:\copilot-abs\mcp-config.json")); + assert!(of("copilot_cli").config.is_absolute()); + assert!(of("pi").config.is_absolute(), "must not degrade into a drive-relative path: {}", of("pi").config.display()); + } + + for id in ["codex", "hermes", "grok_build", "kimi_code", "qwen_code", "qoder"] { + let cfg = &of(id).config; + assert!(!cfg.components().any(|c| c.as_os_str() == Path::new("~").as_os_str()), "{id} retained a literal `~` path component: {}", cfg.display()); + } +} + +/// Non-Windows hosts expand `~` and `~/...` as usual while leaving `~user/...` and backslash +/// `~\...` strings untouched as ordinary relative path segments. +#[test] +fn unix_hosts_keep_forward_tilde_and_leave_other_tilde_forms_relative() { + for os in [Os::Linux, Os::Macos] { + let mut env = BTreeMap::new(); + env.insert("CODEX_HOME".into(), "~/codex-unix".into()); + env.insert("HERMES_HOME".into(), "~//hermes-double".into()); + env.insert("QWEN_HOME".into(), "~/".into()); + env.insert("GROK_HOME".into(), "~other/grok".into()); + env.insert("KIMI_CODE_HOME".into(), r"~\literal-backslash".into()); + let home = Path::new("/home/u").to_path_buf(); + let host = Host { home: home.clone(), env, os }; + + let cs = clients(&host); + let of = |id: &str| cs.iter().find(|c| c.id == id).unwrap(); + assert_eq!(of("codex").config, home.join("codex-unix").join("config.toml")); + assert_eq!(of("hermes").config, home.join("hermes-double").join("config.yaml")); + assert_eq!(of("qwen_code").config, home.join("settings.json")); + assert_eq!(of("qwen_code").markers[0].as_os_str(), home.as_os_str()); + assert_eq!(of("grok_build").config, home.join("~other/grok").join("config.toml")); + assert_eq!(of("kimi_code").config, home.join(r"~\literal-backslash").join("mcp.json")); + assert!(of("kimi_code").config.to_string_lossy().contains('~'), "Unix host must not strip `~\\`: {}", of("kimi_code").config.display()); + } +} diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 94a3fb3b3..fcc6c20ba 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -974,6 +974,8 @@ Owner: open · Status: in progress - [x] `doctor` looks a registration's bare command (`craft-anything-cli`, as a hand-made entry names it) up on PATH, as the app starting it does, instead of calling it missing. — claimed: Plastic-time, branch bugfix/r2.2-doctor-cli-on-path +- [x] Follow `QODER_CONFIG_DIR` for Qoder's `skills` directory as well as `settings.json`, and expand leading `~\` backslash home prefixes in setup environment overrides on Windows. + — claimed: Plastic-time, branch bugfix/r2.2-qoder-skills-and-windows-tilde - [x] Settings says when a saved agent program is gone and which one runs in its place (`AiHub::replaced_programs`, read on a worker with the AI list), with "Use it" to save that one when it's a file of its own (#721, #1468) diff --git a/docs/STATUS.md b/docs/STATUS.md index 8f858f802..e85ddbcd4 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -69,6 +69,7 @@ coverage and secrets passed. The companion CLI was built with locked dependencie | Watched descendant regression | A guarded Rust parent starts the heartbeat child in its inherited process group/job. No shell quoting is involved. The watched launch is stopped before missing startup markers can fail an assertion | macOS regressions pass for descendant shutdown, startup-timeout cleanup and direct ignored-fixture runs without guards. Windows execution of this replacement remains pending; the prior shell fixture failed there. The platform suite still has the separately tracked preview-connection fixture failure | | Disabled chat backends | Naming a backend that is off refuses chat and either side of compare with a settings error and guidance, before API or coding-agent setup | Isolated hub regressions for disabled API and agent backends, both compare positions, and enabled/automatic controls. Invalid tunnel settings detect API setup before the guard. No live provider or agent was used | | Setup YAML empty & flow blocks | Hermes `config.yaml` edits accept spaced empty braces (`{ }`), YAML 1.2 null variants (`Null`, `NULL`), and complete one-line flow entries (`{...}`/`[...]`, including `*alias` references to earlier anchors) while refusing automatic edits with a manual-edit message when a `mcp_servers` child spans multiple lines in flow style, opens a flow collection on the next line after an empty header, or places `{`/`[`/`}`/`]`/`,` at child indentation. | Six regressions in `yaml_empty_and_flow_blocks` cover `{ }`, `Null`/`NULL`, verbatim preservation of one-line flow siblings (including anchor aliases) across `set`/`remove`, multi-line flow child refusal, next-line flow blocks and child-indent flow punctuation refusal, block/quoted/plain `{` sibling preservation, and end-to-end Hermes `plan`/`apply`/`uninstall`. | +| Setup `QODER_CONFIG_DIR` skills & Windows `~\` overrides | `QODER_CONFIG_DIR` relocates Qoder's `skills` folder alongside `settings.json`, and `Host::var` on Windows (`Os::Windows`) expands leading `~\` backslash home prefixes without creating a literal `~` path segment while leaving Unix backslash paths untouched. | Three integration regressions in `qoder_skills_and_windows_tilde` cover end-to-end Qoder `plan`/`apply`/`doctor`/`uninstall` under `QODER_CONFIG_DIR`, Windows `~\` environment overrides, and Linux/macOS tilde controls; two fail before the fix. | | Request-based project kinds | Low-level tools and media players keep the app target when “level” or “player” describes the tool. Explicit game requests and game engines still select the game target | Request-classification regression cases | | ZIP64 end-record framing | Retain bounded fixed fields with a warning when the declared extent disagrees with its locator. Recover records shifted by prepended data within a 64 KiB lookbehind, checking classic-field agreement and directory placement; records with extensions must frame them exactly for recovery. An unusable locator still keeps classic-directory fallback. Undersized payloads, arithmetic overflow and fixed fields overlapping the locator remain rejected. | Synthetic regressions cover CRC-checked payloads, short/long declared extents, shifted genuine ZIP64 records with and without extensions, saturated directory fields, the recovery budget, and classic 65,535-entry archives with locator/record-shaped comments and prepended data. Warnings are serialized only when present. | | Runner-owned app windows | Runtime capture tries the launched process and its descendants; the captured window owner's PID is also used for the UI tree. Unrelated processes with matching names are excluded. Process discovery has a deadline, output cap and candidate limit | Hermetic regressions cover runner/child/grandchild ownership, unrelated windows, direct launches, cycles, malformed rows, caps and errors. A macOS process snapshot finds an owned child without opening a window. Windows and real Go GUI capture have not been run |