* test: cover Windows hook shell drift for Claude (#3413) * fix: scope Windows hook syntax to Gemini runtime (#3413) * docs: add changeset for #3413 * docs: set changeset pr for #3413 * fix: route Windows hook formatting through runtime-aware projection seam * test: cover runtime projection edge cases for Windows hooks * fix(docs): add shell-command-projection to inventory parity * docs: align CLI module shipped count after rebase
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Shell Command Projection Module
|
|
*
|
|
* Tracer-bullet seam for runtime-aware projection of serialized command text
|
|
* that GSD writes into runtime config or prints for copy/paste. This module
|
|
* does NOT execute commands; it only renders command text for external shells
|
|
* and runtimes.
|
|
*/
|
|
|
|
/**
|
|
* Return true when a managed hook command must be prefixed with PowerShell's
|
|
* call operator so a quoted executable token is invokable by the target
|
|
* runtime/shell combination.
|
|
*
|
|
* Current evidence-backed policy:
|
|
* - Gemini on Windows requires `& ` for quoted node/bash runners.
|
|
* - Claude Code on Windows does NOT: its hook commands execute under bash/Git
|
|
* Bash and `& ` breaks there (#3413).
|
|
*
|
|
* Keep the policy conservative until another runtime has a verified need.
|
|
*/
|
|
function hookCommandNeedsPowerShellCallOperator(opts = {}) {
|
|
const platform = opts.platform || process.platform;
|
|
const runtime = opts.runtime || 'generic';
|
|
return platform === 'win32' && runtime === 'gemini';
|
|
}
|
|
|
|
/**
|
|
* Project a fully-assembled hook command string for the target runtime.
|
|
*/
|
|
function formatHookCommandForRuntime(command, opts = {}) {
|
|
return hookCommandNeedsPowerShellCallOperator(opts) ? `& ${command}` : command;
|
|
}
|
|
|
|
/**
|
|
* Project a managed hook script path token for serialized shell commands.
|
|
* Windows managed hook commands normalize to forward slashes so the same path
|
|
* survives JSON/TOML/config surfaces consistently.
|
|
*/
|
|
function formatManagedHookScriptToken(scriptPath, opts = {}) {
|
|
const platform = opts.platform || process.platform;
|
|
if (platform !== 'win32') return null;
|
|
return JSON.stringify(scriptPath.replace(/\\/g, '/'));
|
|
}
|
|
|
|
module.exports = {
|
|
hookCommandNeedsPowerShellCallOperator,
|
|
formatHookCommandForRuntime,
|
|
formatManagedHookScriptToken,
|
|
};
|