chore: address Copilot review round 7 (Windows .cmd shims)

Node has refused shell-free `.cmd`/`.bat` spawns since CVE-2024-27980, and an
npm-installed `claude` is a `.cmd` shim on Windows — so every shell-free spawn
of it reported ENOENT there, each in a quiet way: `verify:skills` skipped its
authoritative hand-off, `verify:skills:cli` downloaded the pinned package it
already had (and failed offline), and `skills:eval` said "not on PATH".

- New `scripts/lib/claude-cli.mjs` is the one place that decides how `claude` is
  spawned: `shell` on win32, arguments through the existing `winShellArgs`
  quoting so `cmd.exe` cannot re-parse them as syntax (#1939). Unit-tested with
  the platform injected, since a win32-only bug no runner here executes is
  exactly the kind that ships.
- `verify-skills`, `verify-skills-cli` and `skill-eval` all route their probes
  and spawns through it.
- skill-eval sends the prompt on **stdin** rather than in argv. `claude -p` reads
  a piped prompt (verified end to end), which sidesteps `cmd.exe` metacharacter
  re-parsing entirely rather than relying on quoting a model-visible string, and
  keeps the prompt out of the process table.

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-29 02:32:30 -04:00
commit 09b8f0e834

View file

@ -30,6 +30,7 @@ import { readFileSync, readdirSync, existsSync, statSync } from "node:fs";
import { spawnSync } from "node:child_process";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { claudeSpawnArgs, probeClaudeVersion } from "./lib/claude-cli.mjs";
import {
compareVersions,
parseClaudeVersion,
@ -146,29 +147,25 @@ function main(argv = process.argv.slice(2)) {
// never reaching the reproducible step (Copilot). Accepting merely "new enough"
// would reintroduce exactly the cross-machine schema drift the pin removes.
// Anything else is left to `verify:skills:cli`, which fetches the pin.
const probe = spawnSync("claude", ["--version"], { encoding: "utf8" });
if (probe.error || probe.status !== 0) {
const version = probeClaudeVersion(parseClaudeVersion);
if (version === null) {
console.log(
"verify:skills — no usable `claude` CLI here; `verify:skills:cli` runs the pinned validator.",
);
return;
}
const version = parseClaudeVersion(probe.stdout ?? "");
if (
version === null ||
compareVersions(version, PINNED_VERSION_PARTS) !== 0
) {
if (compareVersions(version, PINNED_VERSION_PARTS) !== 0) {
console.log(
`verify:skills — local \`claude\` is ${version?.join(".") ?? "(unreadable)"}, not the pinned ` +
`verify:skills — local \`claude\` is ${version.join(".")}, not the pinned ` +
`${PINNED_CLI_VERSION}; \`verify:skills:cli\` runs the pinned validator.`,
);
return;
}
const res = spawnSync("claude", ["plugin", "validate", ".claude/skills"], {
cwd: ROOT,
stdio: "inherit",
});
if (res.status !== 0) {
const { command, args, options } = claudeSpawnArgs(
["plugin", "validate", ".claude/skills"],
{ cwd: ROOT, stdio: "inherit" },
);
if (spawnSync(command, args, options).status !== 0) {
console.error("\nverify:skills — `claude plugin validate` failed.");
process.exit(1);
}