100x is a skill by a former Cursor engineer that turns prompts into formally verified, production-ready code
Keep text files LF in every checkout, add the Windows process and link helpers, and keep a temp folder under a profile from reaching the real home
Glitch20ed499e650e
diff --git a/.gitattributes b/.gitattributesindex dfe0770..a2c244b 100644--- a/.gitattributes+++ b/.gitattributes@@ -1,2 +1,4 @@-# Auto detect text files and perform LF normalization-* text=auto+# Text is LF in every checkout, on Windows too. Pinned copies in vendor/ are hashed byte for byte, and the tests compare text with \n.+* text=auto eol=lf+*.cmd text eol=crlf+*.bat text eol=crlfdiff --git a/lib/links.mjs b/lib/links.mjsnew file mode 100644index 0000000..89f144d--- /dev/null+++ b/lib/links.mjs@@ -0,0 +1,57 @@+import fs from 'node:fs';+import path from 'node:path';+import { isWindows } from './proc.mjs';++// Windows lets only an administrator, or a machine in Developer Mode, make a symbolic link. A folder can be linked by a junction without+// either, and a program that has no link to stand on gets a small launcher file instead. X100_NO_SYMLINK=1 asks for the fallbacks on any system.+const refused = (error) => isWindows && ['EPERM', 'EACCES', 'UNKNOWN'].includes(error.code);++const isFolder = (target) => {+ try {+ return fs.statSync(target).isDirectory();+ } catch {+ return false;+ }+};++// Makes linkPath point at target and says what it made: 'symlink' or 'junction'. Throws when neither can be made.+export function makeLink(target, linkPath) {+ const folder = isFolder(target);+ if (!process.env.X100_NO_SYMLINK) {+ try {+ fs.symlinkSync(target, linkPath, folder ? 'dir' : 'file');+ return 'symlink';+ } catch (error) {+ if (!refused(error) || !folder) throw error;+ }+ }+ if (!folder || !isWindows) throw Object.assign(new Error(`could not link ${linkPath} to ${target}`), { code: 'EPERM' });+ fs.symlinkSync(target, linkPath, 'junction');+ return 'junction';+}++export const LINK_WORDS = { symlink: 'a symlink', junction: 'a junction, because this account cannot make symlinks (they need Developer Mode or an administrator)', launcher: 'a launcher file, because Windows runs a program by its file name and not by a link' };++// On Windows the 100x program is a pair of launchers, 100x.cmd for cmd and PowerShell and a script named 100x for Git Bash, each running node on the CLI entry.+export const usesLauncher = (target) => isWindows && path.extname(target) === '.mjs';++export function launcherText(linkPath, target) {+ return path.extname(linkPath).toLowerCase() === '.cmd' ? `@echo off\r\nnode "${target}" %*\r\n` : `#!/bin/sh\nexec node "${target.replaceAll('\\', '/')}" "$@"\n`;+}++export function writeLauncher(linkPath, target) {+ fs.writeFileSync(linkPath, launcherText(linkPath, target));+}++// What a launcher is: missing, ok (it runs this target), elsewhere (it runs another 100x.mjs, named in current), or blocked (not ours).+export function launcherState(linkPath, target) {+ let text;+ try {+ text = fs.readFileSync(linkPath, 'utf8');+ } catch (error) {+ return error.code === 'ENOENT' ? { state: 'missing' } : { state: 'blocked', current: 'a file this install cannot read' };+ }+ if (text === launcherText(linkPath, target)) return { state: 'ok' };+ const other = /node "([^"]+100x\.mjs)"/.exec(text)?.[1];+ return other ? { state: 'elsewhere', current: path.normalize(other) } : { state: 'blocked', current: 'a real file' };+}diff --git a/lib/paths.mjs b/lib/paths.mjsindex 07ef193..01edcf7 100644--- a/lib/paths.mjs+++ b/lib/paths.mjs@@ -26,7 +26,9 @@ export function findProjectRoot(from = process.cwd()) {let dir = path.resolve(from);for (;;) {const candidate = path.join(dir, '.100x');- if (fs.existsSync(candidate) && !sameFolder(candidate, global)) return dir;+ // The folder an install writes into is the home, never a project. Only a home holds the install record, so a stray one that+ // is not this run's home (an older install, or a temp folder that sits under a profile folder, as on Windows) is skipped too.+ if (fs.existsSync(candidate) && !sameFolder(candidate, global) && !fs.existsSync(path.join(candidate, 'install.json'))) return dir;const parent = path.dirname(dir);if (parent === dir) return null;dir = parent;diff --git a/lib/proc.mjs b/lib/proc.mjsnew file mode 100644index 0000000..8116bb5--- /dev/null+++ b/lib/proc.mjs@@ -0,0 +1,109 @@+import { spawn, spawnSync } from 'node:child_process';+import fs from 'node:fs';+import path from 'node:path';+import { CliError } from './errors.mjs';++// Everything that starts, finds, signals or opens a process in a way that differs between macOS, Linux and Windows lives here,+// so the commands read the same on all three.+export const isWindows = process.platform === 'win32';++const cmdQuote = (arg) => `"${String(arg).replaceAll('"', '""')}"`;++// Node refuses to start a .cmd or .bat file without a shell (and npm is npm.cmd on Windows), so those go through cmd.exe, quoted as one line.+const needsCmd = (command) => isWindows && (/\.(cmd|bat)$/i.test(command) || ['npm', 'npx'].includes(command.toLowerCase()));++function invocation(command, args, options) {+ if (!needsCmd(command)) return [command, args, options];+ const line = `"${[command, ...args].map(cmdQuote).join(' ')}"`;+ return [process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', line], { ...options, windowsVerbatimArguments: true }];+}++export function runProgram(command, args = [], options = {}) {+ const [file, argv, opts] = invocation(command, args, { windowsHide: true, ...options });+ return spawnSync(file, argv, opts);+}++// A POSIX shell. The commands the owner sets for a judge or a prototype are written for sh, with $VARIABLES, and on Windows the one+// that Git for Windows ships (Claude Code and Cursor need Git there too) runs them the same way. X100_SH names another one.+let foundSh;+export function findSh() {+ if (foundSh !== undefined) return foundSh;+ foundSh = null;+ if (process.env.X100_SH && fs.existsSync(process.env.X100_SH)) foundSh = process.env.X100_SH;+ else if (!isWindows) foundSh = 'sh';+ else {+ const roots = new Set();+ for (const dir of (process.env.PATH ?? '').split(path.delimiter)) {+ if (!dir) continue;+ // C:\Program Files\Git\cmd and C:\Program Files\Git\bin both sit one folder under the Git root.+ if (fs.existsSync(path.join(dir, 'git.exe'))) roots.add(path.dirname(dir));+ for (const name of ['sh.exe']) if (fs.existsSync(path.join(dir, name)) && !/system32/i.test(dir)) foundSh = foundSh ?? path.join(dir, name);+ }+ for (const base of [process.env.ProgramFiles, process.env['ProgramFiles(x86)'], process.env.ProgramW6432, process.env.LOCALAPPDATA && path.join(process.env.LOCALAPPDATA, 'Programs')]) if (base) roots.add(path.join(base, 'Git'));+ for (const root of roots) {+ for (const rel of [['usr', 'bin', 'sh.exe'], ['bin', 'sh.exe']]) {+ const candidate = path.join(root, ...rel);+ if (!foundSh && fs.existsSync(candidate)) foundSh = candidate;+ }+ }+ }+ return foundSh;+}++export const NO_SH = 'This command is written for a POSIX shell, and none was found. Install Git for Windows (it includes sh), or set X100_SH to the path of an sh.exe.';++// The program and arguments that run one command line the way sh -c does. Without sh on Windows, cmd.exe runs it, which understands %VAR% and not $VAR.+export function shellInvocation(script, { requireSh = false } = {}) {+ const sh = findSh();+ if (sh) return { file: sh, args: ['-c', script], options: {} };+ if (requireSh) throw new CliError(NO_SH);+ return { file: process.env.ComSpec || 'cmd.exe', args: ['/d', '/s', '/c', script], options: { windowsVerbatimArguments: true } };+}++export function spawnShell(script, options = {}, { requireSh = false } = {}) {+ const { file, args, options: extra } = shellInvocation(script, { requireSh });+ return spawn(file, args, { windowsHide: true, ...extra, ...options });+}++// Windows has no process groups to signal. taskkill /T ends a process and everything it started.+export function killTree(pid) {+ if (isWindows) return spawnSync('taskkill', ['/pid', String(pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true }).status === 0;+ try {+ process.kill(-pid, 'SIGTERM');+ return true;+ } catch {+ try {+ process.kill(pid, 'SIGTERM');+ return true;+ } catch {+ return false;+ }+ }+}++const powershell = (script) => {+ const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', script], { encoding: 'utf8', windowsHide: true, timeout: 20000 });+ return result.status === 0 ? result.stdout.trim() : null;+};++// When a process started, as a string that stays the same for the life of that process. null when the system cannot say.+export function processStart(pid) {+ if (isWindows) return powershell(`(Get-Process -Id ${Number(pid)} -ErrorAction Stop).StartTime.ToUniversalTime().ToString('o')`) || null;+ const result = spawnSync('ps', ['-o', 'lstart=', '-p', String(pid)], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });+ return result.status === 0 ? result.stdout.trim() || null : null;+}++// The command line of a running process, or null.+export function processCommand(pid) {+ if (isWindows) return powershell(`(Get-CimInstance Win32_Process -Filter 'ProcessId = ${Number(pid)}' -ErrorAction Stop).CommandLine`) || null;+ const result = spawnSync('ps', ['-p', String(pid), '-o', 'command='], { encoding: 'utf8' });+ return result.status === 0 ? result.stdout : null;+}++// Open a file or an address in the program the system picks for it.+export function openTarget(target) {+ const [file, args] = process.platform === 'darwin' ? ['open', [target]] : isWindows ? ['rundll32.exe', ['url.dll,FileProtocolHandler', target]] : ['xdg-open', [target]];+ const child = spawn(file, args, { detached: true, stdio: 'ignore', windowsHide: true });+ child.on('error', () => {});+ child.unref();+}diff --git a/test/helpers.mjs b/test/helpers.mjsindex 4efecdb..09f3e30 100644--- a/test/helpers.mjs+++ b/test/helpers.mjs@@ -26,7 +26,7 @@ export function sandbox() {dir,home,project,- env: { HOME: home, X100_HOME: path.join(home, '.100x'), X100_SKILLS_DIR: path.join(home, '.agents', 'skills'), PLAYWRIGHT_BROWSERS_PATH: REAL_BROWSER_CACHE, ...(PLAYWRIGHT_BASE ? { X100_PLAYWRIGHT_FROM: PLAYWRIGHT_BASE } : {}) },+ env: { HOME: home, USERPROFILE: home, X100_HOME: path.join(home, '.100x'), X100_SKILLS_DIR: path.join(home, '.agents', 'skills'), PLAYWRIGHT_BROWSERS_PATH: REAL_BROWSER_CACHE, ...(PLAYWRIGHT_BASE ? { X100_PLAYWRIGHT_FROM: PLAYWRIGHT_BASE } : {}) },cleanup: () => fs.rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }),};}