The design language that makes your AI harness better at design.
JavaScript
Give the quoted .cmd launcher PowerShell's call operator (#1109)
Paul Bakaus233bca98cf61
diff --git a/scripts/lib/cursor-plugin.js b/scripts/lib/cursor-plugin.jsindex 16cd81877..c29b2dd68 100644--- a/scripts/lib/cursor-plugin.js+++ b/scripts/lib/cursor-plugin.js@@ -1,6 +1,7 @@import fs from 'node:fs';import path from 'node:path';import { buildCursorHooksManifest } from './transformers/hooks.js';+import { quoteLauncher } from './plugin-paths.js';const PROJECT_SCRIPTS = '.cursor/skills/impeccable/scripts';@@ -8,8 +9,8 @@ export function rewriteCursorPluginMarkdown(text, { agent = false } = {}) {// Installed plugins live outside the workspace. Keep the shared Setup flow,// but remove its project-install fallback and quote executable paths.text = text.replace(`, and \`${PROJECT_SCRIPTS}\` is the fallback only when the runtime reports no base directory`, '');- text = text.replaceAll(`${PROJECT_SCRIPTS}/impeccable.cmd`, '"<skill-base-dir>/scripts/impeccable.cmd"');- text = text.replaceAll(`${PROJECT_SCRIPTS}/impeccable`, '"<skill-base-dir>/scripts/impeccable"');+ text = text.replaceAll(`${PROJECT_SCRIPTS}/impeccable.cmd`, quoteLauncher('<skill-base-dir>', true));+ text = text.replaceAll(`${PROJECT_SCRIPTS}/impeccable`, quoteLauncher('<skill-base-dir>'));text = text.replaceAll(PROJECT_SCRIPTS, '<skill-base-dir>/scripts');text = text.replace('`<skill-base-dir>/scripts/impeccable context`', '`"<skill-base-dir>/scripts/impeccable" context`');if (agent && text.includes('<skill-base-dir>')) {diff --git a/scripts/lib/plugin-paths.js b/scripts/lib/plugin-paths.jsindex 17f8e78d3..0b1f19cd1 100644--- a/scripts/lib/plugin-paths.js+++ b/scripts/lib/plugin-paths.js@@ -97,10 +97,24 @@ export function rewritePluginMarkdown(content, { isSkillEntrypoint = true } = {}// is what gets quoted; the verb and its arguments follow unquoted..replace(/(?<!["\w/])(\$\{CLAUDE_SKILL_DIR\}|<skill-base-dir>)\/scripts\/impeccable(\.cmd)?(?=[\s`])/g,- '"$1/scripts/impeccable$2"',+ (_, dir, cmd) => quoteLauncher(dir, Boolean(cmd)),);}+/**+ * Spell a quoted launcher path as a command (issue #744). The sh launcher is+ * `"<dir>/scripts/impeccable"`. The `.cmd` launcher also gets PowerShell's call+ * operator: PowerShell parses a quoted string followed by an argument as an+ * expression and fails with `Unexpected token 'context'`, so `& "…"` is the+ * only quoted form that runs there. The `&` is safe because the `.cmd` spelling+ * only ever reaches a Windows shell without sh; it never lands on the sh+ * launcher, where a leading `&` is a syntax error. Shared by every rewrite that+ * quotes launcher paths (plugin, VS Code, Cursor plugin).+ */+export function quoteLauncher(dir, windowsCmd = false) {+ return windowsCmd ? `& "${dir}/scripts/impeccable.cmd"` : `"${dir}/scripts/impeccable"`;+}+/*** Rewrite one agent file's content for the plugin subtree. Same quoting* discipline as the skill rewrite, but the path is the plugin-root@@ -164,6 +178,13 @@ export function verifyPluginSkillRewrite(skillMdPath) {'scripts/lib/plugin-paths.js (issue #523); update SETUP_FALLBACK_TEXT to the new wording.',);}+ if (/(?<!& )"\$\{CLAUDE_SKILL_DIR\}\/scripts\/impeccable\.cmd"/.test(content)) {+ throw new Error(+ `Plugin rewrite drift: ${skillMdPath} quotes the impeccable.cmd launcher without PowerShell's ` ++ 'call operator. A quoted path followed by a verb fails to parse in PowerShell (issue #744); ' ++ 'every quoted .cmd spelling must go through quoteLauncher in scripts/lib/plugin-paths.js.',+ );+ }if (content.includes('<skill-base-dir>')) {throw new Error(`Plugin rewrite drift: ${skillMdPath} still contains the <skill-base-dir> token. ` +diff --git a/scripts/lib/vscode-extension.js b/scripts/lib/vscode-extension.jsindex bd34a04e9..84545d0cb 100644--- a/scripts/lib/vscode-extension.js+++ b/scripts/lib/vscode-extension.js@@ -1,7 +1,7 @@import fs from 'node:fs';import path from 'node:path';-import { rewritePluginMarkdownTree } from './plugin-paths.js';+import { quoteLauncher, rewritePluginMarkdownTree } from './plugin-paths.js';const PROJECT_SCRIPTS = '.github/skills/impeccable/scripts';const PROJECT_FALLBACK =@@ -22,7 +22,7 @@ export function rewriteVSCodeMarkdown(content, { isSkillEntrypoint = false } = {}return content.replaceAll(PROJECT_SCRIPTS, '<skill-base-dir>/scripts').replace(/(?<!["\w/])<skill-base-dir>\/scripts\/impeccable(\.cmd)?(?=[\s`])/g,- '"<skill-base-dir>/scripts/impeccable$1"');+ (_, cmd) => quoteLauncher('<skill-base-dir>', Boolean(cmd)));}/** Stage a declarative skill extension, independently of repo-install sidecars. */diff --git a/tests/cursor-plugin.test.mjs b/tests/cursor-plugin.test.mjsindex e9fe143b3..588e1190c 100644--- a/tests/cursor-plugin.test.mjs+++ b/tests/cursor-plugin.test.mjs@@ -45,7 +45,8 @@ describe('Cursor native plugin', () => {const text = fs.readFileSync(path.join(output, rel), 'utf8');assert.doesNotMatch(text, /\.cursor\/skills|fallback only/);assert.match(text, /"<skill-base-dir>\/scripts\/impeccable" context/);- assert.match(text, /"<skill-base-dir>\/scripts\/impeccable\.cmd" context/);+ assert.match(text, /& "<skill-base-dir>\/scripts\/impeccable\.cmd" context/);+ assert.doesNotMatch(text, /& "<skill-base-dir>\/scripts\/impeccable"/);}assert.match(fs.readFileSync(path.join(output, 'agents/impeccable-asset-producer.md'), 'utf8'), /supplied in the handoff/);assert.equal(fs.statSync(path.join(output, 'skills/impeccable/scripts/impeccable')).mode & 0o111, 0o111);diff --git a/tests/plugin-paths.test.js b/tests/plugin-paths.test.jsindex df94c59f6..990198210 100644--- a/tests/plugin-paths.test.js+++ b/tests/plugin-paths.test.js@@ -20,6 +20,7 @@ import { execFileSync } from 'node:child_process';import { parseFrontmatter } from '../scripts/lib/utils.js';import {rewritePluginMarkdown,+ quoteLauncher,rewritePluginAgentMarkdown,rewritePluginMarkdownTree,verifyPluginSkillRewrite,@@ -53,10 +54,25 @@ describe('rewritePluginMarkdown', () => {'already quoted: `"<skill-base-dir>/scripts/impeccable" hooks on`.',);expect(output).toContain('`"${CLAUDE_SKILL_DIR}/scripts/impeccable" context`');- expect(output).toContain('`"${CLAUDE_SKILL_DIR}/scripts/impeccable.cmd" doctor --json`');+ expect(output).toContain('`& "${CLAUDE_SKILL_DIR}/scripts/impeccable.cmd" doctor --json`');expect(output).not.toContain('""${CLAUDE_SKILL_DIR}');});+ test('gives only the .cmd launcher PowerShell\'s call operator (issue #744)', () => {+ // PowerShell parses `"<path>" context` as a string expression and fails+ // with `Unexpected token 'context'`; `& "<path>" context` runs. The sh+ // launcher must never get the `&`: a leading `&` is a syntax error in sh.+ const input = 'Run `<skill-base-dir>/scripts/impeccable context`; without sh, `<skill-base-dir>/scripts/impeccable.cmd context`.';+ const output = rewritePluginMarkdown(input);+ expect(output).toBe(+ 'Run `"${CLAUDE_SKILL_DIR}/scripts/impeccable" context`; without sh, `& "${CLAUDE_SKILL_DIR}/scripts/impeccable.cmd" context`.',+ );+ expect(output).not.toMatch(/& "[^"]*\/impeccable"/);+ expect(rewritePluginMarkdown(output)).toBe(output);+ expect(quoteLauncher('<dir>')).toBe('"<dir>/scripts/impeccable"');+ expect(quoteLauncher('<dir>', true)).toBe('& "<dir>/scripts/impeccable.cmd"');+ });+test('quotes commands already in the skill-base-dir form without double-quoting', () => {// SKILL.src.md's Setup step 1 carries the token form natively; a base// directory with spaces splits an unquoted path before node sees it.@@ -228,7 +244,7 @@ describe('rewritePluginMarkdownTree', () => {test('raw references retain an explicit base-directory placeholder, including Windows commands', () => {const input = 'Run `.claude/skills/impeccable/scripts/impeccable context` or `<skill-base-dir>/scripts/impeccable.cmd context`.';const output = rewritePluginMarkdown(input, { isSkillEntrypoint: false });- expect(output).toBe('Run `"<skill-base-dir>/scripts/impeccable" context` or `"<skill-base-dir>/scripts/impeccable.cmd" context`.');+ expect(output).toBe('Run `"<skill-base-dir>/scripts/impeccable" context` or `& "<skill-base-dir>/scripts/impeccable.cmd" context`.');expect(output).not.toContain('${CLAUDE_SKILL_DIR}');expect(rewritePluginMarkdown(output, { isSkillEntrypoint: false })).toBe(output);});@@ -305,6 +321,17 @@ describe('verifyPluginSkillRewrite', () => {expect(() => verifyPluginSkillRewrite(p)).toThrow(/Setup step 1 fallback sentence/);});+ test('fails the build when a quoted .cmd launcher lacks the call operator', () => {+ const p = writeSkill(+ rewritePluginMarkdown(goodSkill) + '\nOn a Windows shell without `sh`, call `"${CLAUDE_SKILL_DIR}/scripts/impeccable.cmd"` instead.\n',+ );+ expect(() => verifyPluginSkillRewrite(p)).toThrow(/call operator/);+ const fixed = writeSkill(+ rewritePluginMarkdown(goodSkill + '\nOn a Windows shell without `sh`, call `.claude/skills/impeccable/scripts/impeccable.cmd` instead.\n'),+ );+ expect(() => verifyPluginSkillRewrite(fixed)).not.toThrow();+ });+test('fails the build when a launcher pre-approval survives the removal', () => {const p = writeSkill(rewritePluginMarkdown(goodSkill) + '\n - Bash(${CLAUDE_SKILL_DIR}/scripts/impeccable.cmd *)\n',diff --git a/tests/vscode-extension.test.mjs b/tests/vscode-extension.test.mjsindex c286fcfd0..27ae9284a 100644--- a/tests/vscode-extension.test.mjs+++ b/tests/vscode-extension.test.mjs@@ -57,7 +57,7 @@ describe('VS Code skill extension', () => {it('keeps POSIX and Windows paths quoted, with arguments outside the quotes', () => {const output = rewriteVSCodeMarkdown('Run `.github/skills/impeccable/scripts/impeccable context` or `<skill-base-dir>/scripts/impeccable.cmd context`.');- assert.equal(output, 'Run `"<skill-base-dir>/scripts/impeccable" context` or `"<skill-base-dir>/scripts/impeccable.cmd" context`.');+ assert.equal(output, 'Run `"<skill-base-dir>/scripts/impeccable" context` or `& "<skill-base-dir>/scripts/impeccable.cmd" context`.');assert.equal(rewriteVSCodeMarkdown(output), output);assert.throws(() => rewriteVSCodeMarkdown('changed Setup', { isSkillEntrypoint: true }), /rewrite drift/);});