Skip to content

The design language that makes your AI harness better at design.

JavaScript

Fix Windows global skill installation (#1099)

Paul Bakaus570ca4f953e7
diff --git a/.gitattributes b/.gitattributes
index 00c3dc30d..2b013c336 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -10,6 +10,10 @@ tests/oracle/** -text
ui/component-review/theme.css text eol=lf
crates/context/assets/component-review.js text eol=lf
+# cmd.exe can miss batch labels in LF-only scripts. Keep the launcher in CRLF
+# on every checkout so release bundles contain a native Windows batch file.
+skill/scripts/impeccable.cmd text eol=crlf
+
# Machine-written files that a line diff cannot usefully show. `-diff` makes
# `git diff`, `git show` and `git log -p` print "Binary files differ" instead
# of the content; `linguist-generated` collapses them in GitHub's PR view.
diff --git a/crates/skills/src/hook_manifest.rs b/crates/skills/src/hook_manifest.rs
index 72c4aaf77..0e02a5f70 100644
--- a/crates/skills/src/hook_manifest.rs
+++ b/crates/skills/src/hook_manifest.rs
@@ -180,6 +180,25 @@ pub fn quoted_launcher_path(skill_root: &str, provider: &str, absolute: bool) ->
})
}
+/// GitHub Copilot hook manifests are project files even for a user-scoped
+/// skill install. Keep their normal project command untouched, but point a
+/// global install at the user's actual install root. On Windows, Git Bash's
+/// `$HOME` may differ from the `USERPROFILE` directory used by `os.homedir()`,
+/// so write that resolved root with Bash-compatible forward slashes.
+fn quoted_github_user_launcher(skill_root: &str, win32: bool) -> QuotedPath {
+ let path = if win32 {
+ jsp::win32::join(&[skill_root, ".github", "skills", "impeccable", "scripts", "impeccable"])
+ .replace('\\', "/")
+ } else {
+ "$HOME/.github/skills/impeccable/scripts/impeccable".to_string()
+ };
+ QuotedPath {
+ posix: if win32 { sh_single_quote(&path) } else { json_string(&path) },
+ win32: json_string(&path),
+ raw: path,
+ }
+}
+
/// JS: guardHookCommand(quotedPath, provider), launcher edition, in the
/// shape the public build's `transformers/hooks.js` `guardedLauncher` emits:
/// `[ ! -f X ] || X <verb>` (not `|| true`, so the launcher's exit code, and
@@ -197,7 +216,7 @@ pub fn hook_command(quoted: &QuotedPath, provider: &str, win32: bool) -> String
let q = match (provider, win32) {
(".gemini", _) => return gemini_hook_command(quoted, verb, win32),
(".grok", true) => return windows_hook_command(quoted, provider),
- (".agents", _) | (_, false) => &quoted.posix,
+ (".agents", _) | (".github", _) | (_, false) => &quoted.posix,
(_, true) => &quoted.win32,
};
format!("[ ! -f {q} ] || {q} {verb}")
@@ -236,7 +255,12 @@ pub fn windows_hook_command(quoted: &QuotedPath, provider: &str) -> String {
/// JS: rewriteHookCommandsForSkillRoot(value, provider, {skillRoot, absolute})
pub fn rewrite_hook_commands_for_skill_root(value: &Value, provider: &str, skill_root: &str, absolute: bool) -> Value {
- let Some(quoted) = quoted_launcher_path(skill_root, provider, absolute) else {
+ let quoted = if provider == ".github" && absolute {
+ Some(quoted_github_user_launcher(skill_root, cfg!(windows)))
+ } else {
+ quoted_launcher_path(skill_root, provider, absolute)
+ };
+ let Some(quoted) = quoted else {
return value.clone();
};
rewrite_value(value, provider, &quoted, cfg!(windows))
@@ -245,7 +269,12 @@ pub fn rewrite_hook_commands_for_skill_root(value: &Value, provider: &str, skill
/// `rewrite_hook_commands_for_skill_root` with the platform made explicit
/// (tests drive the Windows form from any host).
pub fn rewrite_hook_commands_for_platform(value: &Value, provider: &str, skill_root: &str, absolute: bool, win32: bool) -> Value {
- let Some(quoted) = quoted_launcher_path(skill_root, provider, absolute) else {
+ let quoted = if provider == ".github" && absolute {
+ Some(quoted_github_user_launcher(skill_root, win32))
+ } else {
+ quoted_launcher_path(skill_root, provider, absolute)
+ };
+ let Some(quoted) = quoted else {
return value.clone();
};
rewrite_value(value, provider, &quoted, win32)
diff --git a/crates/skills/tests/drift_ports_tests.rs b/crates/skills/tests/drift_ports_tests.rs
index 1cbe532ae..0249fc92b 100644
--- a/crates/skills/tests/drift_ports_tests.rs
+++ b/crates/skills/tests/drift_ports_tests.rs
@@ -107,6 +107,19 @@ fn create_fake_universal_bundle(root: &str, providers: &[&str]) -> String {
);
}
if providers.contains(&".github") {
+ write(
+ &format!("{bundle_root}/.github/hooks/impeccable.json"),
+ &json!({
+ "version": 1,
+ "hooks": { "postToolUse": [{
+ "type": "command",
+ "matcher": "edit|create|apply_patch",
+ "bash": "[ ! -f \"$(git rev-parse --show-toplevel)/.github/skills/impeccable/scripts/impeccable\" ] || \"$(git rev-parse --show-toplevel)/.github/skills/impeccable/scripts/impeccable\" hook",
+ "timeoutSec": 5
+ }] },
+ })
+ .to_string(),
+ );
write(
&format!("{bundle_root}/.github/agents/impeccable-finish-reviewer.agent.md"),
"---\nname: impeccable-finish-reviewer\ndescription: Reviews a finished build.\n---\nCopilot reviewer body.\n",
@@ -695,6 +708,75 @@ fn global_install_rewrites_grok_project_hooks_to_the_global_skill_path() {
std::fs::remove_dir_all(&root).ok();
}
+#[test]
+fn global_install_rewrites_github_project_hook_to_the_global_skill_path() {
+ let root = temp_root("github-global");
+ let project = format!("{root}/project");
+ let home = format!("{root}/home");
+ let tmpdir = format!("{root}/tmp");
+ for dir in [&project, &home, &tmpdir] {
+ std::fs::create_dir_all(dir).unwrap();
+ }
+ std::fs::create_dir_all(format!("{project}/.git")).unwrap();
+ let bundle_root = create_fake_universal_bundle(&project, &[".github"]);
+ let env = base_env(&home, &tmpdir, &bundle_root);
+
+ let r = run_cli(
+ &["install", "-y", "--providers=github", "--scope=global"],
+ &project,
+ &env,
+ );
+ assert_eq!(r.code, 0, "{}\n{}", r.stdout, r.stderr);
+ let manifest = read(&format!("{project}/.github/hooks/impeccable.json"));
+ let expected = if cfg!(windows) {
+ format!("{}/.github/skills/impeccable/scripts/impeccable", home.replace('\\', "/"))
+ } else {
+ "$HOME/.github/skills/impeccable/scripts/impeccable".to_string()
+ };
+ assert!(
+ manifest.contains(&expected),
+ "global GitHub hook did not name the user-scoped launcher: {manifest}"
+ );
+ assert!(
+ !manifest.contains("git rev-parse --show-toplevel"),
+ "global GitHub hook still names the project-scoped launcher: {manifest}"
+ );
+ std::fs::remove_dir_all(&root).ok();
+}
+
+#[cfg(windows)]
+#[test]
+fn windows_global_github_hook_uses_userprofile_when_shell_home_differs() {
+ let root = temp_root("github-global-windows-home");
+ let project = format!("{root}/project");
+ let home = format!("{root}/profile-home");
+ let shell_home = format!("{root}/git-bash-home");
+ let tmpdir = format!("{root}/tmp");
+ for dir in [&project, &home, &shell_home, &tmpdir] {
+ std::fs::create_dir_all(dir).unwrap();
+ }
+ std::fs::create_dir_all(format!("{project}/.git")).unwrap();
+ let bundle_root = create_fake_universal_bundle(&project, &[".github"]);
+ let mut env = base_env(&home, &tmpdir, &bundle_root);
+ env.insert("HOME".to_string(), shell_home.clone());
+
+ let r = run_cli(
+ &["install", "-y", "--providers=github", "--scope=global"],
+ &project,
+ &env,
+ );
+ assert_eq!(r.code, 0, "{}\n{}", r.stdout, r.stderr);
+ let manifest = read(&format!("{project}/.github/hooks/impeccable.json"));
+ let expected = format!(
+ "{}/.github/skills/impeccable/scripts/impeccable",
+ home.replace('\\', "/")
+ );
+ assert!(manifest.contains(&expected), "global GitHub hook did not name USERPROFILE: {manifest}");
+ assert!(!manifest.contains("$HOME"), "global GitHub hook still depends on Git Bash HOME: {manifest}");
+ assert!(!manifest.contains(&shell_home.replace('\\', "/")), "global GitHub hook names the wrong HOME: {manifest}");
+ std::fs::remove_dir_all(&root).ok();
+}
+
#[test]
fn user_scope_update_writes_claude_user_settings() {
let root = temp_root("claude-user-settings");
diff --git a/crates/skills/tests/hook_manifest_tests.rs b/crates/skills/tests/hook_manifest_tests.rs
index cf0ad08f0..f06630802 100644
--- a/crates/skills/tests/hook_manifest_tests.rs
+++ b/crates/skills/tests/hook_manifest_tests.rs
@@ -191,12 +191,28 @@ fn install_from_an_older_bundle_never_runs_the_post_edit_verb_before_the_edit()
}
#[test]
-fn github_manifests_pass_through_and_grok_is_rewritten() {
- // .github stays untouched: its committed manifest carries a portable
- // `$(git rev-parse ...)` command that must never become machine-local.
+fn github_project_manifest_stays_portable_and_global_install_uses_home() {
+ // Project installs keep the committed `$(git rev-parse ...)` form.
let bundle = json!({ "version": 1, "hooks": { "postToolUse": [{ "type": "command", "bash": "[ ! -f \"$(git rev-parse --show-toplevel)/.github/skills/impeccable/scripts/impeccable\" ] || \"$(git rev-parse --show-toplevel)/.github/skills/impeccable/scripts/impeccable\" hook" }] } });
- assert_eq!(rewrite_hook_commands_for_platform(&bundle, ".github", "/proj", true, false), bundle);
+ assert_eq!(rewrite_hook_commands_for_platform(&bundle, ".github", "/proj", false, false), bundle);
+ // A global install still writes the manifest into the project, so its
+ // launcher must resolve from the user profile instead of the repository.
+ let global = rewrite_hook_commands_for_platform(&bundle, ".github", "/home/u", true, false);
+ assert_eq!(
+ global["hooks"]["postToolUse"][0]["bash"],
+ "[ ! -f \"$HOME/.github/skills/impeccable/scripts/impeccable\" ] || \"$HOME/.github/skills/impeccable/scripts/impeccable\" hook"
+ );
+ let windows = rewrite_hook_commands_for_platform(&bundle, ".github", r"C:\Users\u", true, true);
+ assert_eq!(
+ windows["hooks"]["postToolUse"][0]["bash"],
+ "[ ! -f 'C:/Users/u/.github/skills/impeccable/scripts/impeccable' ] || 'C:/Users/u/.github/skills/impeccable/scripts/impeccable' hook"
+ );
+ assert!(!windows["hooks"]["postToolUse"][0]["bash"].as_str().unwrap().contains("$HOME"));
assert!(value_has_impeccable_hook_marker(&bundle));
+}
+
+#[test]
+fn grok_manifest_is_rewritten() {
// .grok is rewritten like the other command-hook providers (upstream
// 49571365, #642): a global install must not leave the bundled
// project-relative path behind.
diff --git a/tests/launcher-download.test.mjs b/tests/launcher-download.test.mjs
index 68e434ac6..690d831d9 100644
--- a/tests/launcher-download.test.mjs
+++ b/tests/launcher-download.test.mjs
@@ -220,6 +220,12 @@ test('cmd launcher stages each run under its own name', () => {
assert.match(source, /mkdir "%staging%" >nul 2>nul\r?\nif errorlevel 1 goto claim_staging/);
});
+test('cmd launcher is checked out with CRLF line endings', () => {
+ const source = fs.readFileSync(path.join(ROOT, 'skill/scripts/impeccable.cmd'));
+ const withoutCrlf = Buffer.from(source.toString('binary').replaceAll('\r\n', ''));
+ assert.equal(withoutCrlf.includes(10), false, 'cmd.exe batch labels require CRLF line endings');
+});
+
test('cmd launcher forwards engine exit code through cmd /c', { skip: WINDOWS ? false : 'Windows-only cmd /c exit-code forwarding' }, async t => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'impeccable-launcher-exit-'));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));