fix(herdr): run the panel on Windows through Git for Windows' sh (#924)

Windows has no sh on PATH, so every panel exec failed with "program not
found". A default Git for Windows install puts only Git\cmd on PATH, so
when sh cannot start the panel asks `git --exec-path` for the Git root
and uses its bin/sh.exe, which sets up the MSYS PATH itself. The shell
found is kept per machine, because a space's machine can run a
different OS than the window.

Under that sh, jobs printed their temp folder as /tmp/..., which Herdr's
native readTextFile cannot open, so every job waited out its 15 minutes.
READY now prints the cygpath -m form (C:/...) when cygpath exists; MSYS
sh accepts it too, and other platforms are unchanged.

Closes #922
This commit is contained in:
Willie
2026-11-16 22:15:41 +08:00
committed by GitHub
parent 94cf438066
commit 313ffdeea0
10 changed files with 120 additions and 15 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ This is a standalone mod share folder: `mods/skillshare/`, this recipe and `prev
- `main.js` imports `gpui-kit`, `gpui-base` and `herdr`. Its default role draws the panel; `toggle` draws the button. Dialog roles include `install`, `uninstall`, `audit`, `source`, `syncboth`, `conflict`, `upgrade`, `panelupdate`, `text`, `hook` and `able`.
- `model.js` parses CLI output and holds shell scripts; `jobs.js` runs detached work; `channel.js` carries requests, locks and notices; `operations.js` runs mutations; `loader.js` reads resources, checks and previews. `version.js` records the release. `mark.svg` and `icons/` supply the art.
- Herdr APIs: `exec`, `readTextFile`, `spaces`, `focused`, `machines`, `agents`, `knownAgents`, `layout`, `shared`, `setShared`, `settings`, `theme`, `props`, `openOverlay`, `closeOverlay`, `nextCommand`, `run` and `hc`. Commands: `layout.toggle`, `layout.hide` and `agent.focus`; `hc send` hands off audits.
- Programs: `skillshare`, `git`, `curl`, `sh` and standard filesystem/process tools. skillshare must be installed on every connected machine in `~/.local/bin`, `~/go/bin`, `/opt/homebrew/bin` or `/usr/local/bin`.
- Programs: `skillshare`, `git`, `curl`, `sh` (on Windows, Git for Windows' `bin/sh.exe`) and standard filesystem/process tools. skillshare must be installed on every connected machine in `~/.local/bin`, `~/go/bin`, `/opt/homebrew/bin` or `/usr/local/bin`.
- Long work uses detached jobs and polled temp files. Preview reads up to 40 file names and 60 kB per file. MCP env/header/token values are redacted.
- Panel updates fetch `herdr/skillshare/mods/skillshare` from the latest published release. Both installation options use that same updater and version. The standalone files are generated from that source with `python3 scripts/herdr/package-mod.py`.
@@ -3,6 +3,31 @@
// reads in, and the tests pass real sh and fs.
import { START, START_SCRIPT, ALIVE, SWEEP, JOB_MINUTES, lastLine } from "./model.js";
// withShell(program) turns program(command, args, on), which rejects when the command can't
// start, into shell(args, on), which runs `sh args` on machine `on`. Windows has no sh on PATH,
// but Git for Windows' default install puts git there: `git --exec-path` prints
// <root>/<mingw64|ucrt64>/libexec/git-core, and <root>/bin/sh.exe sets up the MSYS PATH itself
// (usr/bin/sh.exe would find Windows' own find.exe). The shell that started is kept per machine;
// a failure is not, because the machine may only be unreachable for now.
export function withShell(program) {
const shells = new Map();
const gitShell = async (on) => {
const git = await program("git", ["--exec-path"], on).catch(() => null);
const m = /^([A-Za-z]:\/.*)\/[^/]+\/libexec\/git-core\/?$/.exec(git?.code === 0 ? git.stdout.trim().replace(/\\/g, "/") : "");
return m ? `${m[1]}/bin/sh.exe` : null;
};
return async (args, on = null) => {
const known = shells.get(on);
if (known) return program(known, args, on);
const run = async (sh) => { const r = await program(sh, args, on); shells.set(on, sh); return r; };
return run("sh").catch(async (e) => {
const sh = await gitShell(on);
if (!sh) throw e;
return run(sh);
});
};
}
// createRunner({ exec, readText }):
// exec(script, args, on) runs `sh -c script` on machine `on` (null: this computer) and resolves
// to { code, stdout, stderr }; it must not reject. Herdr stops an exec after 30 s.
+5 -3
View File
@@ -14,7 +14,7 @@ import {
parseJSON, lastLine, failure, flag, sourceLine, buildItems, shownRows, endedRequests, afterRead, afterChecks, hookArgs, toggleArgs, rowState, previewTargets, eligibleTargets, targetList, waitsForSync, syncScopes, overviewAnswer, resourceProgress, remoteLine, waitingNames, mapLanes, needsBothWays, filterItems, groupItems, sourceGroups, counts,
cloneUrl, installResult, newerVersion, panelUpdate, updateState, ago, auditMessage, parseDiscover, parseAudit,
} from "./model.js";
import { createRunner } from "./jobs.js";
import { createRunner, withShell } from "./jobs.js";
import { createChannel, EVERY } from "./channel.js";
import { operate } from "./operations.js";
import { findProject, loadResources, loadChecks, loadMachine, loadLatestRelease, loadPreview, loadFile } from "./loader.js";
@@ -31,9 +31,11 @@ const PATHS = 'PATH="$HOME/.local/bin:$HOME/go/bin:/opt/homebrew/bin:/usr/local/
// ---- Running skillshare on the space's machine ----
// Herdr's adapter for the job runner (jobs.js): every script gets the usual PATH.
// Herdr's adapter for the job runner (jobs.js): every script gets the usual PATH, in sh or, on
// Windows, Git for Windows' sh.
const shell = withShell((command, args, on) => exec(command, args, { on }));
const runner = createRunner({
exec: (script, args, on) => exec("sh", ["-c", `${PATHS}\n${script}`, "skillshare-panel", ...args], { on })
exec: (script, args, on) => shell(["-c", `${PATHS}\n${script}`, "skillshare-panel", ...args], on)
.catch((e) => ({ code: 127, stdout: "", stderr: String(e.message ?? e) })),
readText: (path, on) => readTextFile(path, { on }),
});
@@ -15,7 +15,9 @@ export const SCOPES = [["all", "All"], ["project", "Project"], ["global", "Globa
const DETACH = 'unset HC_SCOPE; if command -v setsid >/dev/null 2>&1; then bg() { exec setsid "$@"; }; else set -m; bg() { exec "$@"; }; fi';
// Named so SWEEP can tell the panel's job folders from anything else in the temp folder.
const TEMP = 'd=$(mktemp -d "${TMPDIR:-/tmp}/skillshare-panel.XXXXXX")';
const READY = 'i=0; while [ ! -s "$d/pid" ] && [ $i -lt 50 ]; do sleep 0.1; i=$((i+1)); done; printf %s "$d"';
// The panel reads the folder's files with Herdr, not sh, so under Git for Windows' sh it gets
// the Windows path (cygpath -m: C:/...), which that sh accepts too.
const READY = 'i=0; while [ ! -s "$d/pid" ] && [ $i -lt 50 ]; do sleep 0.1; i=$((i+1)); done; command -v cygpath >/dev/null 2>&1 && d=$(cygpath -m "$d"); printf %s "$d"';
// sh -c START <name> <dir> <args...>: runs skillshare <args> in <dir>; prints the temp folder.
export const START = `${DETACH}; ${TEMP}; dir=$1; shift
bg sh -c 'echo $$ >"$2/pid"; cd "$1" 2>/dev/null || cd; d=$2; shift 2; skillshare "$@" >"$d/out" 2>"$d/err" </dev/null; echo $? >"$d/code"' job "$dir" "$d" "$@" >/dev/null 2>&1 </dev/null &
+1
View File
@@ -98,6 +98,7 @@ Read ~/.config/herdr-app/AGENTS.md, then update only the installed skillshare mo
## How it reads
- It runs on the shown space's machine (`exec` with `on`), in the focused terminal's folder.
On Windows, which has no `sh`, it runs through Git for Windows' `bin/sh.exe`.
- A folder with `.skillshare/config.yaml` or `skillshare/config.yaml` is a project; both
scopes show and the All · Project · Global switch appears beside the tabs.
- Per scope, independent detached reads run `list --all`, `diff`, `mcp list`, `plugin list` and
+1 -1
View File
@@ -106,7 +106,7 @@ Left to right, everything as in Herdr's `main` layout, plus two blocks:
- `git`, which clones the install URL you type from the network, and the skillshare repository for a panel update;
- `curl`, which asks GitHub for the latest release;
- `find`, `sed`, `sort` and `head` to list a previewed skill's files and read the first 60 kB of one;
- `sh`, `mktemp`, `find` and `rm` for temp folders (`rm -rf` only on folders it made with `mktemp -d`, named `skillshare-panel.*`, and on an unfinished `.bak-update-<version>.tmp` in its own folder);
- `sh` (on Windows, which has none on PATH, Git for Windows' `bin/sh.exe`, found through `git --exec-path`; `cygpath` there turns a job's temp folder into the `C:/...` path `readTextFile` can open), `mktemp`, `find` and `rm` for temp folders (`rm -rf` only on folders it made with `mktemp -d`, named `skillshare-panel.*`, and on an unfinished `.bak-update-<version>.tmp` in its own folder);
- `cp`, `mkdir`, `mv` and `grep` for a panel update;
- `setsid` where it exists, `sleep`, `cat`, `kill -0`, `ps` and `grep` to run long commands detached and check they still run;
- `hc send` for the audit hand-off.
+25
View File
@@ -3,6 +3,31 @@
// reads in, and the tests pass real sh and fs.
import { START, START_SCRIPT, ALIVE, SWEEP, JOB_MINUTES, lastLine } from "./model.js";
// withShell(program) turns program(command, args, on), which rejects when the command can't
// start, into shell(args, on), which runs `sh args` on machine `on`. Windows has no sh on PATH,
// but Git for Windows' default install puts git there: `git --exec-path` prints
// <root>/<mingw64|ucrt64>/libexec/git-core, and <root>/bin/sh.exe sets up the MSYS PATH itself
// (usr/bin/sh.exe would find Windows' own find.exe). The shell that started is kept per machine;
// a failure is not, because the machine may only be unreachable for now.
export function withShell(program) {
const shells = new Map();
const gitShell = async (on) => {
const git = await program("git", ["--exec-path"], on).catch(() => null);
const m = /^([A-Za-z]:\/.*)\/[^/]+\/libexec\/git-core\/?$/.exec(git?.code === 0 ? git.stdout.trim().replace(/\\/g, "/") : "");
return m ? `${m[1]}/bin/sh.exe` : null;
};
return async (args, on = null) => {
const known = shells.get(on);
if (known) return program(known, args, on);
const run = async (sh) => { const r = await program(sh, args, on); shells.set(on, sh); return r; };
return run("sh").catch(async (e) => {
const sh = await gitShell(on);
if (!sh) throw e;
return run(sh);
});
};
}
// createRunner({ exec, readText }):
// exec(script, args, on) runs `sh -c script` on machine `on` (null: this computer) and resolves
// to { code, stdout, stderr }; it must not reject. Herdr stops an exec after 30 s.
+5 -3
View File
@@ -14,7 +14,7 @@ import {
parseJSON, lastLine, failure, flag, sourceLine, buildItems, shownRows, endedRequests, afterRead, afterChecks, hookArgs, toggleArgs, rowState, previewTargets, eligibleTargets, targetList, waitsForSync, syncScopes, overviewAnswer, resourceProgress, remoteLine, waitingNames, mapLanes, needsBothWays, filterItems, groupItems, sourceGroups, counts,
cloneUrl, installResult, newerVersion, panelUpdate, updateState, ago, auditMessage, parseDiscover, parseAudit,
} from "./model.js";
import { createRunner } from "./jobs.js";
import { createRunner, withShell } from "./jobs.js";
import { createChannel, EVERY } from "./channel.js";
import { operate } from "./operations.js";
import { findProject, loadResources, loadChecks, loadMachine, loadLatestRelease, loadPreview, loadFile } from "./loader.js";
@@ -31,9 +31,11 @@ const PATHS = 'PATH="$HOME/.local/bin:$HOME/go/bin:/opt/homebrew/bin:/usr/local/
// ---- Running skillshare on the space's machine ----
// Herdr's adapter for the job runner (jobs.js): every script gets the usual PATH.
// Herdr's adapter for the job runner (jobs.js): every script gets the usual PATH, in sh or, on
// Windows, Git for Windows' sh.
const shell = withShell((command, args, on) => exec(command, args, { on }));
const runner = createRunner({
exec: (script, args, on) => exec("sh", ["-c", `${PATHS}\n${script}`, "skillshare-panel", ...args], { on })
exec: (script, args, on) => shell(["-c", `${PATHS}\n${script}`, "skillshare-panel", ...args], on)
.catch((e) => ({ code: 127, stdout: "", stderr: String(e.message ?? e) })),
readText: (path, on) => readTextFile(path, { on }),
});
+3 -1
View File
@@ -15,7 +15,9 @@ export const SCOPES = [["all", "All"], ["project", "Project"], ["global", "Globa
const DETACH = 'unset HC_SCOPE; if command -v setsid >/dev/null 2>&1; then bg() { exec setsid "$@"; }; else set -m; bg() { exec "$@"; }; fi';
// Named so SWEEP can tell the panel's job folders from anything else in the temp folder.
const TEMP = 'd=$(mktemp -d "${TMPDIR:-/tmp}/skillshare-panel.XXXXXX")';
const READY = 'i=0; while [ ! -s "$d/pid" ] && [ $i -lt 50 ]; do sleep 0.1; i=$((i+1)); done; printf %s "$d"';
// The panel reads the folder's files with Herdr, not sh, so under Git for Windows' sh it gets
// the Windows path (cygpath -m: C:/...), which that sh accepts too.
const READY = 'i=0; while [ ! -s "$d/pid" ] && [ $i -lt 50 ]; do sleep 0.1; i=$((i+1)); done; command -v cygpath >/dev/null 2>&1 && d=$(cygpath -m "$d"); printf %s "$d"';
// sh -c START <name> <dir> <args...>: runs skillshare <args> in <dir>; prints the temp folder.
export const START = `${DETACH}; ${TEMP}; dir=$1; shift
bg sh -c 'echo $$ >"$2/pid"; cd "$1" 2>/dev/null || cd; d=$2; shift 2; skillshare "$@" >"$d/out" 2>"$d/err" </dev/null; echo $? >"$d/code"' job "$dir" "$d" "$@" >/dev/null 2>&1 </dev/null &
+51 -5
View File
@@ -1,11 +1,11 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { mkdtempSync, writeFileSync, rmSync, symlinkSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { createRunner } from "../skillshare/mods/skillshare/jobs.js";
import { createRunner, withShell } from "../skillshare/mods/skillshare/jobs.js";
import { SWEEP } from "../skillshare/mods/skillshare/model.js";
// A runner over real sh with a fake `skillshare` (body). Like Herdr, each exec's process group
@@ -14,8 +14,9 @@ function fakeRunner(t, body, opts = {}) {
const root = mkdtempSync(join(tmpdir(), "ss-jobs-"));
t.after(() => rmSync(root, { recursive: true, force: true }));
writeFileSync(join(root, "skillshare"), `#!/bin/sh\n${body}\n`, { mode: 0o755 });
if (opts.cygpath) writeFileSync(join(root, "cygpath"), `#!/bin/sh\n${opts.cygpath(root)}\n`, { mode: 0o755 });
const env = { ...process.env, PATH: `${root}:${process.env.PATH}`, TMPDIR: root };
const scripts = [];
const scripts = [], reads = [];
const exec = (script, args, on) => new Promise((resolve) => {
scripts.push({ script, on });
const sh = spawn("sh", ["-c", script, "test", ...args], { env, detached: true });
@@ -27,8 +28,8 @@ function fakeRunner(t, body, opts = {}) {
resolve({ code: code ?? 1, stdout, stderr });
});
});
const readText = (path) => readFile(path, "utf8").catch(() => null);
return { runner: createRunner({ exec, readText, pollMs: 20, aliveEvery: 2, ...opts }), scripts };
const readText = (path) => { reads.push(path); return readFile(path, "utf8").catch(() => null); };
return { runner: createRunner({ exec, readText, pollMs: 20, aliveEvery: 2, ...opts }), scripts, reads, root };
}
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -56,3 +57,48 @@ test("the first job on each machine sweeps old job folders once", async (t) => {
await runner.job(["c"], { on: "other", sleep });
assert.deepEqual(scripts.filter((s) => s.script === SWEEP).map((s) => s.on), [null, "other"]);
});
test("where cygpath exists, the job's files are read at the path it prints", async (t) => {
// Git for Windows' sh: Herdr reads files natively, so it needs C:/... rather than /tmp/...
const alias = mkdtempSync(join(tmpdir(), "ss-alias-"));
t.after(() => rmSync(alias, { recursive: true, force: true }));
const { runner, reads, root } = fakeRunner(t, "echo ok", { cygpath: (r) => `printf %s "$2" | sed "s|^${r}|${alias}/root|"` });
symlinkSync(root, join(alias, "root"));
const r = await runner.job(["list"], { sleep });
assert.deepEqual([r.stdout, reads.every((p) => p.startsWith(`${alias}/root/`))], ["ok\n", true]);
});
// A Herdr exec on a Windows machine: sh can't start, git is on PATH.
function windowsProgram(calls, gitPath = "C:/Program Files/Git/ucrt64/libexec/git-core\r\n") {
return async (command, args, on) => {
calls.push([command, on]);
if (command === "sh") throw new Error("cannot start sh: program not found");
if (command === "git") return { code: 0, stdout: gitPath, stderr: "" };
return { code: 0, stdout: args.join(" "), stderr: "" };
};
}
test("without sh, a script runs in Git for Windows' bin/sh.exe", async () => {
const calls = [];
const r = await withShell(windowsProgram(calls))(["-c", "echo hi"], "win");
assert.deepEqual([calls.at(-1), r.stdout], [["C:/Program Files/Git/bin/sh.exe", "win"], "-c echo hi"]);
});
test("where sh starts, git is never asked", async () => {
const calls = [];
const shell = withShell(async (command, args, on) => { calls.push(command); return { code: 0, stdout: "", stderr: "" }; });
for (const on of [null, null, "linux"]) await shell(["-c", ":"], on);
assert.deepEqual(calls, ["sh", "sh", "sh"]);
});
test("each machine looks for its shell once", async () => {
const calls = [];
const shell = withShell(windowsProgram(calls));
for (const on of ["win", "win", null]) await shell(["-c", ":"], on);
assert.deepEqual(calls.filter(([c]) => c === "git").map(([, on]) => on), ["win", null]);
});
test("without sh or Git for Windows, the reason sh could not start stands", async () => {
const shell = withShell(windowsProgram([], "/usr/lib/git-core\n"));
await assert.rejects(shell(["-c", ":"]), /cannot start sh/);
});