Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.
TypeScript ai-agentsanthropicclaude-codeclicode-graphcodexcontext-engineeringcursordeveloper-toolsgeminiknowledge-graphllmmcpmcp-serveropen-sourceopenaitree-sitter
fix(skills): see Windows temp folders as scratch paths when compiling
Shrish Dwivedi8aae38f4a9ce
diff --git a/src/skills/compile-split.ts b/src/skills/compile-split.tsindex f8750a16..87fb6c4b 100644--- a/src/skills/compile-split.ts+++ b/src/skills/compile-split.ts@@ -418,8 +418,17 @@ export function splitSheet(sheet: RunSheet, ctx: { repoRoot: string; home: strinreturn { sheet: { ...sheet, calls, checkIndex }, blocked, waits, parts };}-/** A scratch file a step's output went into: `> /tmp/dev.log 2>&1`, `>> "$TMPDIR/x"`, `| tee …/scratchpad/t.log`. */-const SCRATCH_FILE = '(["\']?)(?:(?:\\/private)?\\/(?:tmp|var\\/folders)\\/|\\$\\{?TMPDIR\\}?\\/?|[^\\s\'"`;|&()<>,=]*\\/scratchpad\\/)[^\\s\'"`;|&()<>,]*\\1';+/** `Temp` matched in any case (`[Tt][Ee]…`): Windows paths ignore it. */+const anyCase = (w: string) => w.replace(/[a-z]/gi, (c) => `[${c.toUpperCase()}${c.toLowerCase()}]`);+const SEG = String.raw`[^\\/\s'"\`;|&()<>,]`;+/**+ * Windows' temp folders, with either slash: the person's `AppData\Local\Temp` (as `C:\` or Git Bash's `/c/`),+ * `Windows\Temp`, `%TEMP%` and `$env:TEMP`. What follows the folder is left to the caller.+ */+export const WIN_TEMP = String.raw`(?:(?<![\w.~$-])(?:[A-Za-z]:|\/[A-Za-z])[\\/](?:${anyCase('users')}[\\/]${SEG}+[\\/]${anyCase('appdata')}[\\/]${anyCase('local')}[\\/]${anyCase('temp')}|${anyCase('windows')}[\\/]${anyCase('temp')})(?!${SEG})|%${anyCase('t')}${anyCase('e')}?${anyCase('mp')}%|\$${anyCase('env')}:${anyCase('t')}${anyCase('e')}?${anyCase('mp')}(?!\w))`;++/** A scratch file a step's output went into: `> /tmp/dev.log 2>&1`, `>> "$TMPDIR/x"`, `| tee …/scratchpad/t.log`, `> %TEMP%\x.log`. */+const SCRATCH_FILE = String.raw`(["']?)(?:(?:\/private)?\/(?:tmp|var\/folders)\/|\$\{?TMPDIR\}?\/?|[^\s'"\`;|&()<>,=]*[\\/]scratchpad[\\/]|${WIN_TEMP}[\\/]?)[^\s'"\`;|&()<>,]*\1`;const LOG_TAIL = [new RegExp(String.raw`\s+(?:\d?>>?|&>>?)\s*${SCRATCH_FILE}$`), new RegExp(String.raw`\s*\|\s*tee(?:\s+-a)?\s+${SCRATCH_FILE}$`)];/** Where the output went is not what ran: a trailing log into a scratch folder goes (with its `2>&1`), the step stays. */diff --git a/src/skills/compile.ts b/src/skills/compile.tsindex 45dd7c5f..57284500 100644--- a/src/skills/compile.ts+++ b/src/skills/compile.ts@@ -34,7 +34,7 @@ import { STABLE_BRANCHES, findParams, paramsToMeta } from './params.js';import { renderSkillMd } from './skillmd.js';import { skillProblems } from './validate.js';import { type CompileRefusal, askPhrases, askedJob, carriedSteps, describe, elsewhereLines, freeName, goodName, jobWords, toolCheckWords } from './compile-words.js';-import { type LoopWait, splitSheet, stripScratchLog } from './compile-split.js';+import { type LoopWait, WIN_TEMP, splitSheet, stripScratchLog } from './compile-split.js';import { answersPrompt, loginFeed } from './answers-prompt.js';import { checkShowsFor, shownVersion, versionShaped, versionTie } from './compile-version.js';import { findWaits } from './compile-waits.js';@@ -81,8 +81,8 @@ const WAIT_TAIL = 'do [ $((SECONDS-s)) -ge 300 ] && echo "not ready after 5 min"const PROBE = /^(?:command -v [\w.+-]+|test -[SfdeE] \S+|\[ -S \S+ \]|git rev-parse --verify \S+)$/;const PORCELAIN = 'git status --porcelain';const CHECK_FIRST = /^(?:npm whoami|gh auth status|aws sts get-caller-identity|gcloud auth list|vercel whoami|docker info|colima status)(?:\s+-{1,2}[\w-]+(?:[= ]\S+)?)*$/;-/** A token that is a scratch path: /tmp, /private/tmp, /var/folders, $TMPDIR, or a /scratchpad/ segment. */-const SCRATCH = /(?<![\w.~$-])(?:\/private)?\/(?:tmp|var\/folders)\/[^\s'"`;|&()<>,]*|\$\{?TMPDIR\}?[^\s'"`;|&()<>,]*|[^\s'"`;|&()<>,=]*\/scratchpad\/[^\s'"`;|&()<>,]*/g;+/** A token that is a scratch path: /tmp, /private/tmp, /var/folders, $TMPDIR, a scratchpad segment, or Windows' temp folder. */+const SCRATCH = new RegExp(String.raw`(?<![\w.~$-])(?:\/private)?\/(?:tmp|var\/folders)\/[^\s'"\`;|&()<>,]*|\$\{?TMPDIR\}?[^\s'"\`;|&()<>,]*|[^\s'"\`;|&()<>,=]*[\\/]scratchpad[\\/][^\s'"\`;|&()<>,]*|${WIN_TEMP}[^\s'"\`;|&()<>,]*`, 'g');const PLAIN = /^(?:npm (?:run )?[\w:.-]+|pnpm (?:run )?[\w:.-]+|yarn (?:run )?[\w:.-]+|make [\w.-]+|go test \.\/\.\.\.)$/;type Role = 'step' | 'wait' | 'poll' | 'check' | 'probe' | 'checkFirst' | 'failed' | 'left';diff --git a/test/skills-compile.test.ts b/test/skills-compile.test.tsindex 3354b11e..acd42c41 100644--- a/test/skills-compile.test.ts+++ b/test/skills-compile.test.ts@@ -132,7 +132,8 @@ test("4.5: a publish through script is gated; keystrokes fed to its prompt refus});test("4.5: a helper script run from a scratch folder is copied into the skill; a gated line in it gates the step", () => {- const dir = join(mkdtempSync(join(tmpdir(), "g2-helper-")), "scratchpad");+ // Off Windows, /tmp itself: the run's random temp folder name can read as a secret (see skills-risk-escapes).+ const dir = join(mkdtempSync(process.platform === "win32" ? join(tmpdir(), "g2-helper-") : "/tmp/g2-helper-"), "scratchpad");mkdirSync(dir, { recursive: true });const helper = join(dir, "npm-pty.mjs");const content = "#!/usr/bin/env node\n// npm publish behind a pty, so npm opens the browser itself\nimport { spawn } from 'node:child_process';\nspawn('npm', process.argv.slice(2), { stdio: 'inherit' });\n";@@ -191,6 +192,13 @@ test("refusals: multi-line, truncated, outside-repo, step-too-long, scratch-pathassert.match(refused(compile(sheet([call("node build.mjs --out /tmp/x/out.json")])), "scratch-path"), /\/tmp\/x\/out\.json/);// A scratch script the run didn't record as a helper is a scratch path too.refused(compile(sheet([call("bash /private/tmp/x/scratchpad/go.sh")])), "scratch-path");+ // Windows' temp folder, with either slash and in any case, and a scratchpad under it.+ for (const p of ["C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\x\\out.json", "c:/users/dev/appdata/local/temp/out.json", "/c/Users/dev/AppData/Local/Temp/out.json", "%TEMP%\\out.json", "$env:TMP\\out.json", "D:\\a\\_temp\\scratchpad\\out.json"]) {+ assert.ok(refused(compile(sheet([call(`node build.mjs --out ${p}`)])), "scratch-path").includes(p), p);+ }+ assert.deepEqual(steps(compile(sheet([call("node C:\\Users\\dev\\AppData\\Local\\Tempest\\x.js")]))), ["node C:\\Users\\dev\\AppData\\Local\\Tempest\\x.js"]);+ // Output logged into one is not what ran: the log goes, the step stays.+ assert.deepEqual(steps(compile(sheet([call("npm run build > %TEMP%\\build.log 2>&1")]))), ["npm run build"]);});test("refusals: too-long (an overflowed run, or more than 12 steps), no-steps, no-check, never-save", () => {