From 26cea56020c06c4417312479a507a10ebba3d0b8 Mon Sep 17 00:00:00 2001 From: abevol <85929368+abevol@users.noreply.github.com> Date: Sat, 31 Jan 2026 16:15:43 +0800 Subject: [PATCH] fix: improve Windows path support across CLI commands - Fix #64: sync command now expands tilde (~) on Windows - Fix #65: install command recognizes Windows absolute paths (C:/, C:\) - Support both forward and backward slashes for tilde paths (~/ and ~\) - Support Windows drive letters in both formats (C:/ and C:\) Changes: - Updated sync.ts to expand tilde paths before processing - Enhanced isLocalPath() to detect Windows drive letters - Updated expandPath() to handle both Unix and Windows tilde notation This makes the CLI more intuitive for Windows users, especially those using Git Bash or other Unix-like shells on Windows. --- src/commands/install.ts | 9 ++++++--- src/commands/sync.ts | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/commands/install.ts b/src/commands/install.ts index b4c015e..f747a8b 100644 --- a/src/commands/install.ts +++ b/src/commands/install.ts @@ -27,7 +27,9 @@ function isLocalPath(source: string): boolean { source.startsWith('/') || source.startsWith('./') || source.startsWith('../') || - source.startsWith('~/') + source.startsWith('~/') || + source.startsWith('~\\') || // Windows home directory with backslash + /^[a-zA-Z]:[/\\]/.test(source) // Windows drive (C:/ or C:\) ); } @@ -56,10 +58,11 @@ function getRepoName(repoUrl: string): string | null { } /** - * Expand ~ to home directory + * Expand ~ to home directory and normalize path */ function expandPath(source: string): string { - if (source.startsWith('~/')) { + // Support both Unix (~/) and Windows (~\) tilde notation + if (source.startsWith('~/') || source.startsWith('~\\')) { return join(homedir(), source.slice(2)); } return resolve(source); diff --git a/src/commands/sync.ts b/src/commands/sync.ts index d8746eb..7ffee43 100644 --- a/src/commands/sync.ts +++ b/src/commands/sync.ts @@ -1,5 +1,6 @@ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'; -import { dirname, basename } from 'path'; +import { dirname, basename, resolve, join } from 'path'; +import { homedir } from 'os'; import chalk from 'chalk'; import { checkbox } from '@inquirer/prompts'; import { ExitPromptError } from '@inquirer/core'; @@ -12,11 +13,23 @@ export interface SyncOptions { output?: string; } +/** + * Expand ~ to home directory and resolve path + */ +function expandPath(path: string): string { + // Support both Unix (~/) and Windows (~\) tilde notation + if (path.startsWith('~/') || path.startsWith('~\\')) { + return join(homedir(), path.slice(2)); + } + return resolve(path); +} + /** * Sync installed skills to a markdown file */ export async function syncAgentsMd(options: SyncOptions = {}): Promise { - const outputPath = options.output || 'AGENTS.md'; + const rawOutputPath = options.output || 'AGENTS.md'; + const outputPath = expandPath(rawOutputPath); const outputName = basename(outputPath); // Validate output file is markdown