droid-patch 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { styleText } from "node:util";
2
2
  import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
3
- import { basename, delimiter, dirname, join } from "node:path";
3
+ import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
4
4
  import { homedir, platform } from "node:os";
5
5
  import { execSync } from "node:child_process";
6
6
  import { chmod, copyFile, mkdir, readFile, readdir, readlink, stat, symlink, unlink, writeFile } from "node:fs/promises";
@@ -304,6 +304,29 @@ function getContext(buffer, position, patternLength, contextSize) {
304
304
  return str;
305
305
  }
306
306
 
307
+ //#endregion
308
+ //#region src/alias-utils.ts
309
+ const MANAGED_ALIAS_TARGET_MARKERS = [
310
+ ".droid-patch/bins",
311
+ ".droid-patch/websearch",
312
+ ".droid-patch/proxy",
313
+ ".droid-patch/statusline"
314
+ ];
315
+ function pathExistsWithLstat(path) {
316
+ try {
317
+ lstatSync(path);
318
+ return true;
319
+ } catch {
320
+ return false;
321
+ }
322
+ }
323
+ function isManagedAliasTarget(target) {
324
+ return MANAGED_ALIAS_TARGET_MARKERS.some((marker) => target.includes(marker));
325
+ }
326
+ function symlinkTargetExists(symlinkPath, target) {
327
+ return existsSync(isAbsolute(target) ? target : resolve(dirname(symlinkPath), target));
328
+ }
329
+
307
330
  //#endregion
308
331
  //#region src/metadata.ts
309
332
  /**
@@ -362,6 +385,22 @@ async function listAllMetadata() {
362
385
  return metaList;
363
386
  }
364
387
  /**
388
+ * Remove all alias metadata files
389
+ */
390
+ async function clearAllMetadata() {
391
+ if (!existsSync(META_DIR)) return 0;
392
+ const files = await readdir(META_DIR);
393
+ let removedCount = 0;
394
+ for (const file of files) {
395
+ if (!file.endsWith(".json")) continue;
396
+ try {
397
+ await unlink(join(META_DIR, file));
398
+ removedCount++;
399
+ } catch {}
400
+ }
401
+ return removedCount;
402
+ }
403
+ /**
365
404
  * Remove alias metadata
366
405
  */
367
406
  async function removeAliasMetadata(aliasName) {
@@ -543,7 +582,7 @@ async function createAlias(patchedBinaryPath, aliasName, verbose = false) {
543
582
  await copyFile(patchedBinaryPath, binaryDest);
544
583
  await chmod(binaryDest, 493);
545
584
  if (verbose) console.log(styleText("gray", ` Stored binary: ${binaryDest}`));
546
- if (existsSync(targetPath)) {
585
+ if (pathExistsWithLstat(targetPath)) {
547
586
  await unlink(targetPath);
548
587
  if (verbose) console.log(styleText("gray", ` Removed existing: ${targetPath}`));
549
588
  }
@@ -593,7 +632,7 @@ async function createAlias(patchedBinaryPath, aliasName, verbose = false) {
593
632
  } catch {}
594
633
  }
595
634
  const symlinkPath = join(ALIASES_DIR, aliasName);
596
- if (existsSync(symlinkPath)) {
635
+ if (pathExistsWithLstat(symlinkPath)) {
597
636
  await unlink(symlinkPath);
598
637
  if (verbose) console.log(styleText("gray", ` Removed existing symlink`));
599
638
  }
@@ -742,10 +781,9 @@ async function removeAlias(aliasName) {
742
781
  }
743
782
  if (!IS_WINDOWS) for (const pathDir of COMMON_PATH_DIRS) {
744
783
  const pathSymlink = join(pathDir, aliasName);
745
- if (existsSync(pathSymlink)) try {
784
+ if (pathExistsWithLstat(pathSymlink)) try {
746
785
  if (lstatSync(pathSymlink).isSymbolicLink()) {
747
- const target = await readlink(pathSymlink);
748
- if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy") || target.includes(".droid-patch/statusline")) {
786
+ if (isManagedAliasTarget(await readlink(pathSymlink))) {
749
787
  await unlink(pathSymlink);
750
788
  console.log(styleText("green", ` Removed: ${pathSymlink}`));
751
789
  removed = true;
@@ -754,7 +792,7 @@ async function removeAlias(aliasName) {
754
792
  } catch {}
755
793
  }
756
794
  const symlinkPath = join(ALIASES_DIR, aliasName);
757
- if (existsSync(symlinkPath)) {
795
+ if (pathExistsWithLstat(symlinkPath)) {
758
796
  await unlink(symlinkPath);
759
797
  console.log(styleText("green", ` Removed: ${symlinkPath}`));
760
798
  removed = true;
@@ -844,14 +882,16 @@ async function listAliases() {
844
882
  name: aliasName,
845
883
  target,
846
884
  location: binDir,
847
- immediate: checkPathInclusion()
885
+ immediate: checkPathInclusion(),
886
+ stale: false
848
887
  });
849
888
  } catch {
850
889
  aliases.push({
851
890
  name: aliasName,
852
891
  target: fullPath,
853
892
  location: binDir,
854
- immediate: false
893
+ immediate: false,
894
+ stale: false
855
895
  });
856
896
  }
857
897
  }
@@ -867,7 +907,8 @@ async function listAliases() {
867
907
  name: aliasName,
868
908
  target: fullPath,
869
909
  location: proxyDir,
870
- immediate: false
910
+ immediate: false,
911
+ stale: false
871
912
  });
872
913
  }
873
914
  }
@@ -882,11 +923,12 @@ async function listAliases() {
882
923
  try {
883
924
  if (lstatSync(fullPath).isSymbolicLink()) {
884
925
  const target = await readlink(fullPath);
885
- if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy") || target.includes(".droid-patch/statusline")) aliases.push({
926
+ if (isManagedAliasTarget(target)) aliases.push({
886
927
  name: file,
887
928
  target,
888
929
  location: pathDir,
889
- immediate: true
930
+ immediate: true,
931
+ stale: !symlinkTargetExists(fullPath, target)
890
932
  });
891
933
  }
892
934
  } catch {}
@@ -904,7 +946,8 @@ async function listAliases() {
904
946
  name: file,
905
947
  target,
906
948
  location: ALIASES_DIR,
907
- immediate: false
949
+ immediate: false,
950
+ stale: !symlinkTargetExists(fullPath, target)
908
951
  });
909
952
  }
910
953
  } catch {}
@@ -919,9 +962,10 @@ async function listAliases() {
919
962
  console.log(styleText("white", ` Found ${aliases.length} alias(es):`));
920
963
  console.log();
921
964
  for (const alias of aliases) {
922
- const status = alias.immediate ? styleText("green", "✓ immediate") : styleText("yellow", "requires source");
965
+ const status = alias.stale ? styleText("red", "stale broken symlink") : alias.immediate ? styleText("green", "✓ immediate") : styleText("yellow", "requires source");
923
966
  console.log(styleText("green", ` • ${styleText(["cyan", "bold"], alias.name)} [${status}]`));
924
967
  console.log(styleText("gray", ` → ${alias.target}`));
968
+ if (alias.stale) console.log(styleText("yellow", ` Target missing; run \`npx droid-patch remove ${alias.name}\` or \`clear\` to clean it up.`));
925
969
  const meta = await loadAliasMetadata(alias.name);
926
970
  if (meta) {
927
971
  const patchVer = meta.droidPatchVersion ? `droid-patch@${meta.droidPatchVersion}` : "unknown";
@@ -994,7 +1038,7 @@ async function createAliasForWrapper(wrapperPath, aliasName, verbose = false) {
994
1038
  if (writablePathDir) {
995
1039
  const targetPath = join(writablePathDir, aliasName);
996
1040
  if (verbose) console.log(styleText("gray", ` Wrapper: ${wrapperPath}`));
997
- if (existsSync(targetPath)) {
1041
+ if (pathExistsWithLstat(targetPath)) {
998
1042
  await unlink(targetPath);
999
1043
  if (verbose) console.log(styleText("gray", ` Removed existing: ${targetPath}`));
1000
1044
  }
@@ -1015,7 +1059,7 @@ async function createAliasForWrapper(wrapperPath, aliasName, verbose = false) {
1015
1059
  }
1016
1060
  console.log(styleText("yellow", "[*] No writable PATH directory found, using fallback..."));
1017
1061
  const symlinkPath = join(ALIASES_DIR, aliasName);
1018
- if (existsSync(symlinkPath)) {
1062
+ if (pathExistsWithLstat(symlinkPath)) {
1019
1063
  await unlink(symlinkPath);
1020
1064
  if (verbose) console.log(styleText("gray", ` Removed existing symlink`));
1021
1065
  }
@@ -1190,8 +1234,7 @@ async function removeAliasesByFilter(filter) {
1190
1234
  const fullPath = join(pathDir, file);
1191
1235
  try {
1192
1236
  if (lstatSync(fullPath).isSymbolicLink()) {
1193
- const target = await readlink(fullPath);
1194
- if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy") || target.includes(".droid-patch/statusline")) aliasNames.add(file);
1237
+ if (isManagedAliasTarget(await readlink(fullPath))) aliasNames.add(file);
1195
1238
  }
1196
1239
  } catch {}
1197
1240
  }
@@ -1275,8 +1318,7 @@ async function clearAllAliases() {
1275
1318
  const fullPath = join(pathDir, file);
1276
1319
  try {
1277
1320
  if (lstatSync(fullPath).isSymbolicLink()) {
1278
- const target = await readlink(fullPath);
1279
- if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy") || target.includes(".droid-patch/statusline")) aliasNames.add(file);
1321
+ if (isManagedAliasTarget(await readlink(fullPath))) aliasNames.add(file);
1280
1322
  }
1281
1323
  } catch {}
1282
1324
  }
@@ -1342,6 +1384,8 @@ async function clearAllAliases() {
1342
1384
  }
1343
1385
  }
1344
1386
  } catch {}
1387
+ const removedMetadataCount = await clearAllMetadata();
1388
+ if (removedMetadataCount > 0) console.log(styleText("green", ` Removed metadata files: ${removedMetadataCount}`));
1345
1389
  const metadataFile = join(DROID_PATCH_DIR, "metadata.json");
1346
1390
  if (existsSync(metadataFile)) try {
1347
1391
  await unlink(metadataFile);
@@ -1352,5 +1396,5 @@ async function clearAllAliases() {
1352
1396
  }
1353
1397
 
1354
1398
  //#endregion
1355
- export { removeAlias as a, restoreOriginal as c, listAllMetadata as d, loadAliasMetadata as f, listAliases as i, createMetadata as l, patchDroid as m, createAlias as n, removeAliasesByFilter as o, saveAliasMetadata as p, createAliasForWrapper as r, replaceOriginal as s, clearAllAliases as t, formatPatches as u };
1356
- //# sourceMappingURL=alias-DOPp4UYn.mjs.map
1399
+ export { removeAlias as a, restoreOriginal as c, listAllMetadata as d, loadAliasMetadata as f, patchDroid as g, pathExistsWithLstat as h, listAliases as i, createMetadata as l, isManagedAliasTarget as m, createAlias as n, removeAliasesByFilter as o, saveAliasMetadata as p, createAliasForWrapper as r, replaceOriginal as s, clearAllAliases as t, formatPatches as u };
1400
+ //# sourceMappingURL=alias-Dri1cXrO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alias-Dri1cXrO.mjs","names":["IS_WINDOWS"],"sources":["../src/patcher.ts","../src/alias-utils.ts","../src/metadata.ts","../src/alias.ts"],"sourcesContent":["import { readFile, writeFile, copyFile, chmod, stat } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { execSync } from \"node:child_process\";\nimport { styleText } from \"node:util\";\nimport { platform } from \"node:os\";\n\nconst IS_WINDOWS = platform() === \"win32\";\n\nexport interface Patch {\n name: string;\n description: string;\n pattern: Buffer;\n replacement: Buffer;\n variants?: Array<{\n pattern: Buffer;\n replacement: Buffer;\n }>;\n // Regex-based matching: use $1, $2, etc. in regexReplacement for capture groups\n regexPattern?: RegExp;\n regexReplacement?: string | ((match: string) => string);\n // Optional regex to detect already-patched binaries when regexPattern is not found.\n alreadyPatchedRegexPattern?: RegExp;\n // Skip this patch when any named patch has already matched or is already patched.\n skipIfAnySucceeded?: string[];\n // Only show check logs when this patch actually matches or is already patched.\n suppressCheckUnlessFound?: boolean;\n}\n\nexport interface PatchOptions {\n inputPath: string;\n outputPath?: string;\n patches: Patch[];\n dryRun?: boolean;\n backup?: boolean;\n verbose?: boolean;\n}\n\ninterface PatchResult {\n name: string;\n found: number;\n positions?: number[];\n success: boolean;\n alreadyPatched?: boolean;\n hidden?: boolean;\n skipped?: boolean;\n}\n\nexport interface PatchDroidResult {\n success: boolean;\n dryRun?: boolean;\n results: PatchResult[];\n outputPath?: string;\n noPatchNeeded?: boolean;\n patchedCount?: number;\n}\n\nfunction writeReplacementBytes(\n target: Buffer,\n position: number,\n matchBytes: Buffer,\n replacementBytes: Buffer,\n): void {\n if (replacementBytes.length > matchBytes.length) {\n throw new Error(\n `Replacement is longer than matched content: ${replacementBytes.length} > ${matchBytes.length}`,\n );\n }\n\n replacementBytes.copy(target, position, 0, replacementBytes.length);\n\n if (replacementBytes.length < matchBytes.length) {\n target.fill(0x20, position + replacementBytes.length, position + matchBytes.length);\n }\n}\n\nexport async function patchDroid(options: PatchOptions): Promise<PatchDroidResult> {\n const {\n inputPath,\n outputPath,\n patches,\n dryRun = false,\n backup = true,\n verbose = false,\n } = options;\n\n const finalOutputPath = outputPath || `${inputPath}.patched`;\n\n if (!existsSync(inputPath)) {\n throw new Error(`Binary not found: ${inputPath}`);\n }\n\n const stats = await stat(inputPath);\n const fileSizeMB = (stats.size / (1024 * 1024)).toFixed(2);\n\n console.log(styleText(\"white\", `[*] Reading binary: ${styleText(\"cyan\", inputPath)}`));\n console.log(styleText(\"white\", `[*] File size: ${styleText(\"cyan\", fileSizeMB)} MB`));\n console.log();\n\n const data = await readFile(inputPath);\n const buffer = Buffer.from(data);\n\n // Use a working buffer that gets updated after each patch application\n // This ensures later patches search against the already-patched content\n const workingBuffer = Buffer.from(buffer);\n\n const results: PatchResult[] = [];\n const resultByName = new Map<string, PatchResult>();\n\n for (const patch of patches) {\n const shouldSkip =\n patch.skipIfAnySucceeded?.some((dependencyName) => {\n const dependencyResult = resultByName.get(dependencyName);\n return (\n !!dependencyResult && (dependencyResult.found > 0 || dependencyResult.alreadyPatched)\n );\n }) ?? false;\n\n if (shouldSkip) {\n const skippedResult: PatchResult = {\n name: patch.name,\n found: 0,\n success: true,\n alreadyPatched: true,\n hidden: true,\n skipped: true,\n };\n results.push(skippedResult);\n resultByName.set(patch.name, skippedResult);\n continue;\n }\n\n const suppressCheckUnlessFound = !!patch.suppressCheckUnlessFound;\n let checkLogged = false;\n const logCheckHeader = () => {\n if (!checkLogged) {\n console.log(styleText(\"white\", `[*] Checking patch: ${styleText(\"yellow\", patch.name)}`));\n console.log(styleText(\"gray\", ` ${patch.description}`));\n checkLogged = true;\n }\n };\n\n if (!suppressCheckUnlessFound) {\n logCheckHeader();\n }\n\n // Handle regex-based matching\n // For binary files, convert pattern/replacement to Buffer and use findAllPositions\n if (patch.regexPattern && patch.regexReplacement) {\n const content = workingBuffer.toString(\"utf-8\");\n const regex = new RegExp(patch.regexPattern.source, \"g\");\n const matches: Array<{ charIndex: number; match: string; replacement: string }> = [];\n\n let match;\n while ((match = regex.exec(content)) !== null) {\n const replacement =\n typeof patch.regexReplacement === \"function\"\n ? patch.regexReplacement(match[0])\n : match[0].replace(new RegExp(patch.regexPattern.source), patch.regexReplacement);\n matches.push({\n charIndex: match.index,\n match: match[0],\n replacement,\n });\n }\n\n if (matches.length === 0) {\n let alreadyPatched = false;\n if (patch.alreadyPatchedRegexPattern) {\n const alreadyPatchedRegex = new RegExp(patch.alreadyPatchedRegexPattern.source, \"g\");\n alreadyPatched = alreadyPatchedRegex.test(content);\n } else if (typeof patch.regexReplacement === \"string\") {\n // Fallback: look for a sample replacement pattern (best-effort heuristic).\n const sampleReplacement = patch.regexReplacement.replace(/\\$\\d+/g, \"X\");\n alreadyPatched = content.includes(sampleReplacement.slice(0, 20));\n }\n if (!suppressCheckUnlessFound || alreadyPatched) {\n logCheckHeader();\n }\n if (!suppressCheckUnlessFound) {\n console.log(styleText(\"yellow\", ` ! Pattern not found - may already be patched`));\n }\n const missIsHidden = suppressCheckUnlessFound && !alreadyPatched;\n const result = {\n name: patch.name,\n found: 0,\n success: alreadyPatched || missIsHidden,\n alreadyPatched,\n hidden: missIsHidden,\n };\n results.push(result);\n resultByName.set(patch.name, result);\n if (alreadyPatched) {\n console.log(styleText(\"blue\", ` ✓ Binary appears to be already patched`));\n }\n continue;\n }\n\n logCheckHeader();\n console.log(styleText(\"green\", ` ✓ Found ${matches.length} occurrences (regex)`));\n\n if (!dryRun) {\n // Apply regex replacement using Buffer.indexOf for accurate byte positions\n for (const { match, replacement } of matches) {\n const matchBuffer = Buffer.from(match, \"utf-8\");\n const replacementBuffer = Buffer.from(replacement, \"utf-8\");\n\n if (matchBuffer.length !== replacementBuffer.length) {\n console.log(\n styleText(\n \"yellow\",\n ` ! Length mismatch: ${matchBuffer.length} vs ${replacementBuffer.length} (padding remainder with spaces)`,\n ),\n );\n }\n\n // Find the actual byte position in the buffer\n const bytePos = workingBuffer.indexOf(matchBuffer);\n if (bytePos !== -1) {\n writeReplacementBytes(workingBuffer, bytePos, matchBuffer, replacementBuffer);\n }\n }\n }\n\n const result = {\n name: patch.name,\n found: matches.length,\n positions: matches.map((m) => m.charIndex),\n success: true,\n };\n results.push(result);\n resultByName.set(patch.name, result);\n continue;\n }\n\n const variants = [\n { pattern: patch.pattern, replacement: patch.replacement },\n ...(patch.variants || []),\n ];\n\n // Search in the working buffer (which may have earlier patches applied)\n let positions: number[] = [];\n let matchedVariant: (typeof variants)[number] | undefined;\n for (const variant of variants) {\n positions = findAllPositions(workingBuffer, variant.pattern);\n if (positions.length > 0) {\n matchedVariant = variant;\n break;\n }\n }\n\n if (positions.length === 0) {\n const alreadyPatched = variants.some((v) => workingBuffer.includes(v.replacement));\n const missIsHidden = suppressCheckUnlessFound && !alreadyPatched;\n if (!suppressCheckUnlessFound || alreadyPatched) {\n logCheckHeader();\n }\n if (!suppressCheckUnlessFound) {\n console.log(styleText(\"yellow\", ` ! Pattern not found - may already be patched`));\n }\n const result = {\n name: patch.name,\n found: 0,\n success: alreadyPatched || missIsHidden,\n alreadyPatched,\n hidden: missIsHidden,\n };\n results.push(result);\n\n let totalReplacementPositions = 0;\n for (const variant of variants) {\n totalReplacementPositions += findAllPositions(workingBuffer, variant.replacement).length;\n }\n if (totalReplacementPositions > 0) {\n logCheckHeader();\n console.log(\n styleText(\n \"blue\",\n ` ✓ Found ${totalReplacementPositions} occurrences of patched pattern`,\n ),\n );\n console.log(styleText(\"blue\", ` ✓ Binary appears to be already patched`));\n results[results.length - 1].alreadyPatched = true;\n results[results.length - 1].success = true;\n }\n resultByName.set(patch.name, results[results.length - 1]);\n continue;\n }\n\n if (!matchedVariant) {\n throw new Error(`Internal error: matchedVariant not set for patch ${patch.name}`);\n }\n\n logCheckHeader();\n console.log(styleText(\"green\", ` ✓ Found ${positions.length} occurrences`));\n\n if (verbose) {\n for (const pos of positions.slice(0, 5)) {\n const context = getContext(workingBuffer, pos, matchedVariant.pattern.length, 25);\n console.log(\n styleText(\"gray\", ` @ 0x${pos.toString(16).padStart(8, \"0\")}: ...${context}...`),\n );\n }\n if (positions.length > 5) {\n console.log(styleText(\"gray\", ` ... and ${positions.length - 5} more`));\n }\n }\n\n // Apply patch immediately to working buffer so later patches see updated content\n if (!dryRun) {\n for (const pos of positions) {\n writeReplacementBytes(\n workingBuffer,\n pos,\n matchedVariant.pattern,\n matchedVariant.replacement,\n );\n }\n }\n\n const result = {\n name: patch.name,\n found: positions.length,\n positions,\n success: true,\n };\n results.push(result);\n resultByName.set(patch.name, result);\n }\n\n console.log();\n\n if (dryRun) {\n console.log(styleText(\"blue\", \"─\".repeat(60)));\n console.log(styleText([\"blue\", \"bold\"], \" DRY RUN RESULTS\"));\n console.log(styleText(\"blue\", \"─\".repeat(60)));\n console.log();\n\n for (const result of results) {\n if (result.hidden || result.skipped) {\n continue;\n }\n if (result.alreadyPatched) {\n console.log(styleText(\"blue\", ` [✓] ${result.name}: Already patched`));\n } else if (result.found > 0) {\n console.log(\n styleText(\"green\", ` [✓] ${result.name}: ${result.found} occurrences will be patched`),\n );\n } else {\n console.log(styleText(\"yellow\", ` [!] ${result.name}: Pattern not found`));\n }\n }\n\n return {\n success: results.every((r) => r.success || r.alreadyPatched),\n dryRun: true,\n results,\n };\n }\n\n const patchesNeeded = results.filter((r) => r.found > 0 && !r.alreadyPatched);\n\n if (patchesNeeded.length === 0) {\n const allPatched = results.every((r) => r.alreadyPatched);\n if (allPatched) {\n console.log(styleText(\"blue\", \"[*] All patches already applied. Binary is up to date.\"));\n return {\n success: true,\n outputPath: inputPath,\n results,\n noPatchNeeded: true,\n };\n }\n console.log(styleText(\"yellow\", \"[!] No patches could be applied.\"));\n return { success: false, results };\n }\n\n if (backup) {\n const backupPath = `${inputPath}.backup`;\n if (!existsSync(backupPath)) {\n await copyFile(inputPath, backupPath);\n console.log(styleText(\"white\", `[*] Created backup: ${styleText(\"cyan\", backupPath)}`));\n } else {\n console.log(styleText(\"gray\", `[*] Backup already exists: ${backupPath}`));\n }\n }\n\n console.log(styleText(\"white\", \"[*] Applying patches...\"));\n // Patches have already been applied to workingBuffer during the check phase\n // Count total patches applied\n const totalPatched = results.reduce((sum, r) => sum + (r.positions?.length || 0), 0);\n\n console.log(styleText(\"green\", `[*] Applied ${totalPatched} patches`));\n\n // Handle Windows file locking - if file is locked, use a new filename\n let actualOutputPath = finalOutputPath;\n try {\n await writeFile(finalOutputPath, workingBuffer);\n } catch (error) {\n const err = error as NodeJS.ErrnoException;\n if (err.code === \"EBUSY\" && IS_WINDOWS) {\n // File is locked, generate new filename with timestamp\n const timestamp = Date.now();\n const ext = finalOutputPath.endsWith(\".exe\") ? \".exe\" : \"\";\n const basePath = finalOutputPath\n .replace(/\\.exe$/, \"\")\n .replace(/\\.patched$/, \"\")\n .replace(/-\\d+$/, \"\");\n actualOutputPath = `${basePath}-${timestamp}${ext ? ext : \".patched\"}`;\n console.log(styleText(\"yellow\", `[!] Original file locked, saving to: ${actualOutputPath}`));\n await writeFile(actualOutputPath, workingBuffer);\n } else {\n throw error;\n }\n }\n console.log(\n styleText(\"white\", `[*] Patched binary saved: ${styleText(\"cyan\", actualOutputPath)}`),\n );\n\n await chmod(actualOutputPath, 0o755);\n console.log(styleText(\"gray\", \"[*] Set executable permission\"));\n\n console.log();\n console.log(styleText(\"white\", \"[*] Verifying patches...\"));\n const verifyBuffer = await readFile(actualOutputPath);\n\n let allVerified = true;\n for (let i = 0; i < patches.length; i++) {\n const patch = patches[i];\n if (results[i]?.hidden || results[i]?.skipped) {\n continue;\n }\n // Handle regex-based patches\n if (patch.regexPattern && patch.regexReplacement) {\n const content = verifyBuffer.toString(\"utf-8\");\n const oldMatches = [...content.matchAll(new RegExp(patch.regexPattern.source, \"g\"))];\n // For verification, just check that the original pattern is no longer present\n if (oldMatches.length === 0) {\n console.log(styleText(\"green\", ` ✓ ${patch.name}: Verified (regex)`));\n } else {\n console.log(\n styleText(\"red\", ` ✗ ${patch.name}: ${oldMatches.length} occurrences not patched`),\n );\n allVerified = false;\n }\n continue;\n }\n\n const variants = [\n { pattern: patch.pattern, replacement: patch.replacement },\n ...(patch.variants || []),\n ];\n\n let oldCount = 0;\n let newCount = 0;\n for (const variant of variants) {\n if (variant.pattern.length > 0) {\n oldCount += findAllPositions(verifyBuffer, variant.pattern).length;\n }\n if (variant.replacement.length > 0) {\n newCount += findAllPositions(verifyBuffer, variant.replacement).length;\n }\n }\n\n if (oldCount === 0) {\n console.log(styleText(\"green\", ` ✓ ${patch.name}: Verified (${newCount} patched)`));\n } else {\n console.log(styleText(\"red\", ` ✗ ${patch.name}: ${oldCount} occurrences not patched`));\n allVerified = false;\n }\n }\n\n if (allVerified) {\n console.log();\n console.log(styleText(\"green\", \"[+] All patches verified successfully!\"));\n }\n\n if (process.platform === \"darwin\") {\n console.log();\n try {\n console.log(styleText(\"gray\", \"[*] Re-signing binary for macOS...\"));\n execSync(`codesign --force --deep --sign - \"${finalOutputPath}\"`, {\n stdio: \"pipe\",\n });\n console.log(styleText(\"green\", \"[*] Binary re-signed successfully\"));\n } catch {\n console.log(styleText(\"yellow\", \"[!] Could not re-sign binary\"));\n console.log(\n styleText(\n \"gray\",\n ` You may need to run: codesign --force --deep --sign - ${finalOutputPath}`,\n ),\n );\n }\n\n try {\n execSync(`xattr -cr \"${finalOutputPath}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n return {\n success: allVerified,\n outputPath: actualOutputPath,\n results,\n patchedCount: totalPatched,\n };\n}\n\nfunction findAllPositions(buffer: Buffer, pattern: Buffer): number[] {\n const positions: number[] = [];\n let pos = 0;\n\n while (true) {\n pos = buffer.indexOf(pattern, pos);\n if (pos === -1) break;\n positions.push(pos);\n pos += pattern.length;\n }\n\n return positions;\n}\n\nfunction getContext(\n buffer: Buffer,\n position: number,\n patternLength: number,\n contextSize: number,\n): string {\n const start = Math.max(0, position - contextSize);\n const end = Math.min(buffer.length, position + patternLength + contextSize);\n const slice = buffer.slice(start, end);\n\n let str = \"\";\n for (let i = 0; i < slice.length; i++) {\n const c = slice[i];\n if (c >= 32 && c < 127) {\n str += String.fromCharCode(c);\n } else {\n str += \".\";\n }\n }\n return str;\n}\n","import { existsSync, lstatSync } from \"node:fs\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\n\nconst MANAGED_ALIAS_TARGET_MARKERS = [\n \".droid-patch/bins\",\n \".droid-patch/websearch\",\n \".droid-patch/proxy\",\n \".droid-patch/statusline\",\n];\n\nexport function pathExistsWithLstat(path: string): boolean {\n try {\n lstatSync(path);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function isManagedAliasTarget(target: string): boolean {\n return MANAGED_ALIAS_TARGET_MARKERS.some((marker) => target.includes(marker));\n}\n\nexport function symlinkTargetExists(symlinkPath: string, target: string): boolean {\n const resolvedTarget = isAbsolute(target) ? target : resolve(dirname(symlinkPath), target);\n return existsSync(resolvedTarget);\n}\n","/**\n * Alias Metadata Management\n *\n * Stores and retrieves metadata about created aliases, including\n * which patches were applied. This enables the `update` command\n * to re-apply the same patches when the original droid binary is updated.\n */\n\nimport { existsSync } from \"node:fs\";\nimport { mkdir, readdir, readFile, unlink, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\n/**\n * Metadata structure for an alias\n */\nexport interface AliasMetadata {\n /** Alias name */\n name: string;\n /** ISO timestamp when created */\n createdAt: string;\n /** ISO timestamp when last updated */\n updatedAt: string;\n /** Path to the original droid binary used for patching */\n originalBinaryPath: string;\n /** Path where the alias symlink was created */\n aliasPath?: string;\n /** droid-patch version used to create this alias */\n droidPatchVersion?: string;\n /** droid binary version */\n droidVersion?: string;\n /** Patches that were applied */\n patches: {\n isCustom: boolean;\n skipLogin: boolean;\n /** API base URL for binary patching or websearch forward target */\n apiBase: string | null;\n /** Whether websearch is enabled (external providers mode) */\n websearch: boolean;\n /** Whether websearch-proxy is enabled (native provider mode) */\n websearchProxy?: boolean;\n /** @deprecated Old proxy field, kept for backward compatibility */\n proxy?: string | null;\n reasoningEffort: boolean;\n /** Whether telemetry/Sentry is disabled */\n noTelemetry?: boolean;\n /** Standalone mode: mock non-LLM Factory APIs */\n standalone?: boolean;\n };\n}\n\n// Directory for storing metadata files\nconst META_DIR = join(homedir(), \".droid-patch\", \"meta\");\n\n/**\n * Ensure metadata directory exists\n */\nasync function ensureMetaDir(): Promise<void> {\n if (!existsSync(META_DIR)) {\n await mkdir(META_DIR, { recursive: true });\n }\n}\n\n/**\n * Get the path to a metadata file for an alias\n */\nfunction getMetaPath(aliasName: string): string {\n return join(META_DIR, `${aliasName}.json`);\n}\n\n/**\n * Save alias metadata to disk\n */\nexport async function saveAliasMetadata(meta: AliasMetadata): Promise<void> {\n await ensureMetaDir();\n const metaPath = getMetaPath(meta.name);\n await writeFile(metaPath, JSON.stringify(meta, null, 2));\n}\n\n/**\n * Load alias metadata from disk\n * Returns null if metadata doesn't exist\n */\nexport async function loadAliasMetadata(aliasName: string): Promise<AliasMetadata | null> {\n const metaPath = getMetaPath(aliasName);\n if (!existsSync(metaPath)) {\n return null;\n }\n try {\n const content = await readFile(metaPath, \"utf-8\");\n return JSON.parse(content) as AliasMetadata;\n } catch {\n return null;\n }\n}\n\n/**\n * List all alias metadata\n */\nexport async function listAllMetadata(): Promise<AliasMetadata[]> {\n await ensureMetaDir();\n\n const files = await readdir(META_DIR);\n const metaList: AliasMetadata[] = [];\n\n for (const file of files) {\n if (!file.endsWith(\".json\")) continue;\n\n const aliasName = file.replace(/\\.json$/, \"\");\n const meta = await loadAliasMetadata(aliasName);\n if (meta) {\n metaList.push(meta);\n }\n }\n\n return metaList;\n}\n\n/**\n * Remove all alias metadata files\n */\nexport async function clearAllMetadata(): Promise<number> {\n if (!existsSync(META_DIR)) {\n return 0;\n }\n\n const files = await readdir(META_DIR);\n let removedCount = 0;\n\n for (const file of files) {\n if (!file.endsWith(\".json\")) continue;\n\n try {\n await unlink(join(META_DIR, file));\n removedCount++;\n } catch {\n // Ignore individual cleanup failures and continue.\n }\n }\n\n return removedCount;\n}\n\n/**\n * Remove alias metadata\n */\nexport async function removeAliasMetadata(aliasName: string): Promise<boolean> {\n const metaPath = getMetaPath(aliasName);\n if (!existsSync(metaPath)) {\n return false;\n }\n try {\n await unlink(metaPath);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Create a new metadata object with current timestamp\n */\nexport function createMetadata(\n name: string,\n originalBinaryPath: string,\n patches: AliasMetadata[\"patches\"],\n options?: {\n droidPatchVersion?: string;\n droidVersion?: string;\n aliasPath?: string;\n },\n): AliasMetadata {\n const now = new Date().toISOString();\n return {\n name,\n createdAt: now,\n updatedAt: now,\n originalBinaryPath,\n aliasPath: options?.aliasPath,\n droidPatchVersion: options?.droidPatchVersion,\n droidVersion: options?.droidVersion,\n patches,\n };\n}\n\n/**\n * Format patches for display\n */\nexport function formatPatches(patches: AliasMetadata[\"patches\"]): string {\n const applied: string[] = [];\n if (patches.isCustom) applied.push(\"isCustom\");\n if (patches.skipLogin) applied.push(\"skipLogin\");\n // Show apiBase only when not using websearch (binary patch mode)\n if (patches.apiBase && !patches.websearch && !patches.websearchProxy)\n applied.push(`apiBase(${patches.apiBase})`);\n // Show websearch with optional custom target (external providers mode)\n if (patches.websearch) {\n const target = patches.apiBase || \"api.factory.ai\";\n applied.push(`websearch(${target})`);\n }\n // Show websearchProxy (native provider mode)\n if (patches.websearchProxy) {\n applied.push(\"websearchProxy(native)\");\n }\n // Support old proxy field for backward compatibility\n if (patches.proxy && !patches.websearch && !patches.websearchProxy)\n applied.push(`websearch(${patches.proxy})`);\n if (patches.reasoningEffort) applied.push(\"reasoningEffort\");\n if (patches.noTelemetry) applied.push(\"noTelemetry\");\n if (patches.standalone) applied.push(\"standalone\");\n return applied.length > 0 ? applied.join(\", \") : \"(none)\";\n}\n","import {\n existsSync,\n mkdirSync,\n readdirSync,\n unlinkSync,\n lstatSync,\n readFileSync,\n appendFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { symlink, readlink, unlink, copyFile, chmod } from \"node:fs/promises\";\nimport { join, basename, dirname, delimiter } from \"node:path\";\nimport { homedir, platform } from \"node:os\";\nimport { execSync } from \"node:child_process\";\nimport { styleText } from \"node:util\";\nimport { isManagedAliasTarget, pathExistsWithLstat, symlinkTargetExists } from \"./alias-utils.ts\";\nimport {\n clearAllMetadata,\n removeAliasMetadata,\n loadAliasMetadata,\n formatPatches,\n} from \"./metadata.ts\";\n\nconst IS_WINDOWS = platform() === \"win32\";\n\nconst DROID_PATCH_DIR = join(homedir(), \".droid-patch\");\nconst ALIASES_DIR = join(DROID_PATCH_DIR, \"aliases\");\nconst BINS_DIR = join(DROID_PATCH_DIR, \"bins\");\n\n// Unix common PATH directories\nconst UNIX_PATH_DIRS = [\n join(homedir(), \".local/bin\"),\n join(homedir(), \"bin\"),\n join(homedir(), \".bin\"),\n \"/opt/homebrew/bin\",\n \"/usr/local/bin\",\n join(homedir(), \".npm-global/bin\"),\n join(homedir(), \".npm/bin\"),\n join(homedir(), \".pnpm-global/bin\"),\n join(homedir(), \".yarn/bin\"),\n join(homedir(), \".config/yarn/global/node_modules/.bin\"),\n join(homedir(), \".cargo/bin\"),\n join(homedir(), \"go/bin\"),\n join(homedir(), \".deno/bin\"),\n join(homedir(), \".bun/bin\"),\n join(homedir(), \".local/share/mise/shims\"),\n join(homedir(), \".asdf/shims\"),\n join(homedir(), \".nvm/current/bin\"),\n join(homedir(), \".volta/bin\"),\n join(homedir(), \".fnm/current/bin\"),\n];\n\n// Windows common PATH directories\nconst WINDOWS_PATH_DIRS = [\n join(homedir(), \".droid-patch\", \"bin\"),\n join(homedir(), \"scoop\", \"shims\"),\n join(homedir(), \"AppData\", \"Local\", \"Programs\", \"bin\"),\n];\n\nconst COMMON_PATH_DIRS = IS_WINDOWS ? WINDOWS_PATH_DIRS : UNIX_PATH_DIRS;\n\nfunction ensureDirectories(): void {\n if (!existsSync(DROID_PATCH_DIR)) {\n mkdirSync(DROID_PATCH_DIR, { recursive: true });\n }\n if (!existsSync(ALIASES_DIR)) {\n mkdirSync(ALIASES_DIR, { recursive: true });\n }\n if (!existsSync(BINS_DIR)) {\n mkdirSync(BINS_DIR, { recursive: true });\n }\n}\n\nfunction checkPathInclusion(): boolean {\n const pathEnv = process.env.PATH || \"\";\n return pathEnv.split(delimiter).some((p) => p.toLowerCase() === ALIASES_DIR.toLowerCase());\n}\n\nexport function findWritablePathDir(): string | null {\n const pathEnv = process.env.PATH || \"\";\n const pathDirs = pathEnv.split(delimiter);\n\n for (const dir of COMMON_PATH_DIRS) {\n // Case-insensitive comparison for Windows\n const isInPath = pathDirs.some((p) => p.toLowerCase() === dir.toLowerCase());\n if (isInPath) {\n try {\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n const testFile = join(dir, `.droid-patch-test-${Date.now()}`);\n writeFileSync(testFile, \"\");\n unlinkSync(testFile);\n return dir;\n } catch {\n continue;\n }\n }\n }\n\n return null;\n}\n\nfunction getShellConfigPath(): string {\n if (IS_WINDOWS) {\n // Windows doesn't use shell config files for PATH\n return \"\";\n }\n const shell = process.env.SHELL || \"/bin/bash\";\n const shellName = basename(shell);\n\n switch (shellName) {\n case \"zsh\":\n return join(homedir(), \".zshrc\");\n case \"bash\": {\n const bashProfile = join(homedir(), \".bash_profile\");\n if (existsSync(bashProfile)) return bashProfile;\n return join(homedir(), \".bashrc\");\n }\n case \"fish\":\n return join(homedir(), \".config/fish/config.fish\");\n default:\n return join(homedir(), \".profile\");\n }\n}\n\nfunction isPathConfigured(shellConfigPath: string): boolean {\n if (IS_WINDOWS || !shellConfigPath) {\n return false;\n }\n\n if (!existsSync(shellConfigPath)) {\n return false;\n }\n\n try {\n const content = readFileSync(shellConfigPath, \"utf-8\");\n return content.includes(\".droid-patch/aliases\") || content.includes(\"droid-patch/aliases\");\n } catch {\n return false;\n }\n}\n\n/**\n * Add directory to Windows user PATH using setx command\n * This modifies the user's PATH permanently (requires terminal restart)\n */\nfunction addToWindowsUserPath(dir: string): boolean {\n try {\n // Get current user PATH from registry\n let existingPath = \"\";\n try {\n const result = execSync('reg query \"HKCU\\\\Environment\" /v Path 2>nul', {\n encoding: \"utf-8\",\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n });\n const match = result.match(/Path\\s+REG_(?:EXPAND_)?SZ\\s+(.+)/);\n existingPath = match ? match[1].trim() : \"\";\n } catch {\n // PATH not set yet, that's fine\n }\n\n // Check if already in PATH (case-insensitive)\n const paths = existingPath.split(\";\").map((p) => p.toLowerCase().trim());\n if (paths.includes(dir.toLowerCase())) {\n return true; // Already in PATH\n }\n\n // Add to PATH\n const newPath = existingPath ? `${existingPath};${dir}` : dir;\n execSync(`setx PATH \"${newPath}\"`, { stdio: \"pipe\" });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Generate Windows .cmd launcher script\n */\nfunction generateWindowsLauncher(targetPath: string): string {\n return `@echo off\\r\\n\"${targetPath}\" %*\\r\\n`;\n}\n\nfunction addPathToShellConfig(shellConfigPath: string, verbose = false): boolean {\n const shell = process.env.SHELL || \"/bin/bash\";\n const shellName = basename(shell);\n\n let exportLine: string;\n if (shellName === \"fish\") {\n exportLine = `\\n# Added by droid-patch\\nfish_add_path \"${ALIASES_DIR}\"\\n`;\n } else {\n exportLine = `\\n# Added by droid-patch\\nexport PATH=\"${ALIASES_DIR}:$PATH\"\\n`;\n }\n\n try {\n appendFileSync(shellConfigPath, exportLine);\n if (verbose) {\n console.log(styleText(\"gray\", ` Added PATH export to: ${shellConfigPath}`));\n }\n return true;\n } catch (error) {\n console.log(\n styleText(\"yellow\", `[!] Could not write to ${shellConfigPath}: ${(error as Error).message}`),\n );\n return false;\n }\n}\n\nexport interface CreateAliasResult {\n aliasPath: string;\n binaryPath: string;\n immediate?: boolean;\n}\n\nexport async function createAlias(\n patchedBinaryPath: string,\n aliasName: string,\n verbose = false,\n): Promise<CreateAliasResult> {\n ensureDirectories();\n\n console.log(styleText(\"white\", `[*] Creating alias: ${styleText(\"cyan\", aliasName)}`));\n\n // Windows: use .cmd launcher instead of symlink\n if (IS_WINDOWS) {\n return createWindowsAlias(patchedBinaryPath, aliasName, verbose);\n }\n\n const writablePathDir = findWritablePathDir();\n\n if (writablePathDir) {\n const targetPath = join(writablePathDir, aliasName);\n const binaryDest = join(BINS_DIR, `${aliasName}-patched`);\n await copyFile(patchedBinaryPath, binaryDest);\n await chmod(binaryDest, 0o755);\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Stored binary: ${binaryDest}`));\n }\n\n if (pathExistsWithLstat(targetPath)) {\n await unlink(targetPath);\n if (verbose) {\n console.log(styleText(\"gray\", ` Removed existing: ${targetPath}`));\n }\n }\n\n await symlink(binaryDest, targetPath);\n\n if (process.platform === \"darwin\") {\n try {\n console.log(styleText(\"gray\", \"[*] Re-signing binary for macOS...\"));\n execSync(`codesign --force --deep --sign - \"${binaryDest}\"`, {\n stdio: \"pipe\",\n });\n console.log(styleText(\"green\", \"[*] Binary re-signed successfully\"));\n } catch {\n console.log(styleText(\"yellow\", \"[!] Could not re-sign binary\"));\n }\n\n try {\n execSync(`xattr -cr \"${binaryDest}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n console.log(styleText(\"green\", `[*] Created: ${targetPath} -> ${binaryDest}`));\n console.log();\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" ALIAS READY - NO ACTION REQUIRED!\"));\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log();\n console.log(\n styleText(\n \"white\",\n `The alias \"${styleText([\"cyan\", \"bold\"], aliasName)}\" is now available in ALL terminals.`,\n ),\n );\n console.log(styleText(\"gray\", `(Installed to: ${writablePathDir})`));\n\n return {\n aliasPath: targetPath,\n binaryPath: binaryDest,\n immediate: true,\n };\n }\n\n console.log(styleText(\"yellow\", \"[*] No writable PATH directory found, using fallback...\"));\n\n const binaryDest = join(BINS_DIR, `${aliasName}-patched`);\n await copyFile(patchedBinaryPath, binaryDest);\n await chmod(binaryDest, 0o755);\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Copied binary to: ${binaryDest}`));\n }\n\n if (process.platform === \"darwin\") {\n try {\n console.log(styleText(\"gray\", \"[*] Re-signing binary for macOS...\"));\n execSync(`codesign --force --deep --sign - \"${binaryDest}\"`, {\n stdio: \"pipe\",\n });\n console.log(styleText(\"green\", \"[*] Binary re-signed successfully\"));\n } catch {\n console.log(\n styleText(\"yellow\", \"[!] Could not re-sign binary. You may need to do this manually:\"),\n );\n console.log(styleText(\"gray\", ` codesign --force --deep --sign - \"${binaryDest}\"`));\n }\n\n try {\n execSync(`xattr -cr \"${binaryDest}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n const symlinkPath = join(ALIASES_DIR, aliasName);\n\n if (pathExistsWithLstat(symlinkPath)) {\n await unlink(symlinkPath);\n if (verbose) {\n console.log(styleText(\"gray\", ` Removed existing symlink`));\n }\n }\n\n await symlink(binaryDest, symlinkPath);\n await chmod(symlinkPath, 0o755);\n\n console.log(styleText(\"green\", `[*] Created symlink: ${symlinkPath} -> ${binaryDest}`));\n\n const shellConfig = getShellConfigPath();\n\n if (!checkPathInclusion()) {\n if (!isPathConfigured(shellConfig)) {\n console.log(styleText(\"white\", `[*] Configuring PATH in ${shellConfig}...`));\n\n if (addPathToShellConfig(shellConfig, verbose)) {\n console.log(styleText(\"green\", `[*] PATH configured successfully!`));\n console.log();\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" ACTION REQUIRED\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"To use the alias in this terminal, run:\"));\n console.log();\n console.log(styleText(\"cyan\", ` source ${shellConfig}`));\n console.log();\n console.log(styleText(\"gray\", \"Or simply open a new terminal window.\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n } else {\n const exportLine = `export PATH=\"${ALIASES_DIR}:$PATH\"`;\n console.log();\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" Manual PATH Configuration Required\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"Add this line to your shell config:\"));\n console.log(styleText(\"cyan\", ` ${exportLine}`));\n console.log();\n console.log(styleText(\"gray\", `Shell config file: ${shellConfig}`));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n }\n } else {\n console.log(styleText(\"green\", `[*] PATH already configured in ${shellConfig}`));\n console.log();\n console.log(\n styleText(\n \"yellow\",\n `Note: Run \\`source ${shellConfig}\\` or open a new terminal to use the alias.`,\n ),\n );\n }\n } else {\n console.log(styleText(\"green\", `[*] PATH already includes aliases directory`));\n console.log();\n console.log(\n styleText(\n \"green\",\n `You can now use \"${styleText([\"cyan\", \"bold\"], aliasName)}\" command directly!`,\n ),\n );\n }\n\n return {\n aliasPath: symlinkPath,\n binaryPath: binaryDest,\n };\n}\n\n/**\n * Create alias on Windows using .cmd launcher and setx for PATH\n */\n/**\n * Try to copy file, handling Windows file locking\n * If target is locked, use a new filename with timestamp\n */\nasync function copyFileWithLockHandling(\n src: string,\n dest: string,\n verbose = false,\n): Promise<string> {\n try {\n await copyFile(src, dest);\n return dest;\n } catch (error) {\n const err = error as NodeJS.ErrnoException;\n // EBUSY = file is locked/in use (Windows)\n if (err.code === \"EBUSY\" && IS_WINDOWS) {\n // Generate new filename with timestamp\n const timestamp = Date.now();\n const ext = dest.endsWith(\".exe\") ? \".exe\" : \"\";\n const baseName = dest.replace(/\\.exe$/, \"\").replace(/-\\d+$/, \"\"); // Remove old timestamp if any\n const newDest = `${baseName}-${timestamp}${ext}`;\n\n if (verbose) {\n console.log(styleText(\"yellow\", ` [!] File locked, using new path: ${newDest}`));\n }\n\n await copyFile(src, newDest);\n return newDest;\n }\n throw error;\n }\n}\n\nasync function createWindowsAlias(\n patchedBinaryPath: string,\n aliasName: string,\n verbose = false,\n): Promise<CreateAliasResult> {\n const binDir = join(DROID_PATCH_DIR, \"bin\");\n if (!existsSync(binDir)) {\n mkdirSync(binDir, { recursive: true });\n }\n\n // Copy binary to bins directory, handling file locking\n const targetPath = join(BINS_DIR, `${aliasName}-patched.exe`);\n const binaryDest = await copyFileWithLockHandling(patchedBinaryPath, targetPath, verbose);\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Stored binary: ${binaryDest}`));\n }\n\n // Create .cmd launcher in bin directory\n const cmdPath = join(binDir, `${aliasName}.cmd`);\n const cmdContent = generateWindowsLauncher(binaryDest);\n writeFileSync(cmdPath, cmdContent);\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Created launcher: ${cmdPath}`));\n }\n\n // Try to add bin directory to user PATH\n const pathAdded = addToWindowsUserPath(binDir);\n\n console.log(styleText(\"green\", `[*] Created: ${cmdPath}`));\n console.log();\n\n if (pathAdded) {\n if (checkPathInclusion()) {\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" ALIAS READY!\"));\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log();\n console.log(\n styleText(\n \"white\",\n `The alias \"${styleText([\"cyan\", \"bold\"], aliasName)}\" is now available.`,\n ),\n );\n console.log(styleText(\"gray\", `(Installed to: ${binDir})`));\n\n return {\n aliasPath: cmdPath,\n binaryPath: binaryDest,\n immediate: true,\n };\n }\n\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" PATH Updated - Restart Terminal\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"PATH has been updated. Please restart your terminal.\"));\n console.log(\n styleText(\n \"white\",\n `Then you can use \"${styleText([\"cyan\", \"bold\"], aliasName)}\" command directly.`,\n ),\n );\n console.log();\n console.log(styleText(\"gray\", `Installed to: ${binDir}`));\n } else {\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" Manual PATH Configuration Required\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"Add this directory to your PATH:\"));\n console.log(styleText(\"cyan\", ` ${binDir}`));\n console.log();\n console.log(styleText(\"gray\", \"Or run directly:\"));\n console.log(styleText(\"cyan\", ` \"${cmdPath}\"`));\n }\n\n return {\n aliasPath: cmdPath,\n binaryPath: binaryDest,\n immediate: false,\n };\n}\n\nexport async function removeAlias(aliasName: string): Promise<void> {\n console.log(styleText(\"white\", `[*] Removing alias: ${styleText(\"cyan\", aliasName)}`));\n\n let removed = false;\n\n // Windows: check for .cmd launcher\n if (IS_WINDOWS) {\n const binDir = join(DROID_PATCH_DIR, \"bin\");\n const cmdPath = join(binDir, `${aliasName}.cmd`);\n if (existsSync(cmdPath)) {\n await unlink(cmdPath);\n console.log(styleText(\"green\", ` Removed: ${cmdPath}`));\n removed = true;\n }\n\n // Remove Windows binary (.exe)\n const exePath = join(BINS_DIR, `${aliasName}-patched.exe`);\n if (existsSync(exePath)) {\n await unlink(exePath);\n console.log(styleText(\"green\", ` Removed binary: ${exePath}`));\n removed = true;\n }\n\n // Also check for wrapper .cmd in proxy directory\n const proxyDir = join(DROID_PATCH_DIR, \"proxy\");\n const proxyWrapperCmd = join(proxyDir, `${aliasName}.cmd`);\n if (existsSync(proxyWrapperCmd)) {\n await unlink(proxyWrapperCmd);\n console.log(styleText(\"green\", ` Removed wrapper: ${proxyWrapperCmd}`));\n removed = true;\n }\n }\n\n // Check common PATH directories for symlinks (Unix)\n if (!IS_WINDOWS) {\n for (const pathDir of COMMON_PATH_DIRS) {\n const pathSymlink = join(pathDir, aliasName);\n if (pathExistsWithLstat(pathSymlink)) {\n try {\n const stats = lstatSync(pathSymlink);\n if (stats.isSymbolicLink()) {\n const target = await readlink(pathSymlink);\n if (isManagedAliasTarget(target)) {\n await unlink(pathSymlink);\n console.log(styleText(\"green\", ` Removed: ${pathSymlink}`));\n removed = true;\n }\n }\n } catch {\n // Ignore\n }\n }\n }\n }\n\n // Check aliases directory\n const symlinkPath = join(ALIASES_DIR, aliasName);\n if (pathExistsWithLstat(symlinkPath)) {\n await unlink(symlinkPath);\n console.log(styleText(\"green\", ` Removed: ${symlinkPath}`));\n removed = true;\n }\n\n // Remove binary if exists (Unix style without .exe)\n const binaryPath = join(BINS_DIR, `${aliasName}-patched`);\n if (existsSync(binaryPath)) {\n await unlink(binaryPath);\n console.log(styleText(\"green\", ` Removed binary: ${binaryPath}`));\n removed = true;\n }\n\n // Remove new proxy wrapper and related files if exist\n const proxyDir = join(DROID_PATCH_DIR, \"proxy\");\n const proxyWrapperPath = join(proxyDir, aliasName);\n const proxyScriptPath = join(proxyDir, `${aliasName}-proxy.js`);\n\n if (existsSync(proxyWrapperPath)) {\n await unlink(proxyWrapperPath);\n console.log(styleText(\"green\", ` Removed wrapper: ${proxyWrapperPath}`));\n removed = true;\n }\n\n if (existsSync(proxyScriptPath)) {\n await unlink(proxyScriptPath);\n console.log(styleText(\"green\", ` Removed proxy script: ${proxyScriptPath}`));\n removed = true;\n }\n\n // Remove old websearch wrapper and related files if exist (backward compatibility)\n const websearchDir = join(DROID_PATCH_DIR, \"websearch\");\n const wrapperPath = join(websearchDir, aliasName);\n const oldProxyPath = join(websearchDir, `${aliasName}-proxy.js`);\n const preloadPath = join(websearchDir, `${aliasName}-preload.js`);\n\n if (existsSync(wrapperPath)) {\n await unlink(wrapperPath);\n console.log(styleText(\"green\", ` Removed legacy wrapper: ${wrapperPath}`));\n removed = true;\n }\n\n if (existsSync(oldProxyPath)) {\n await unlink(oldProxyPath);\n console.log(styleText(\"green\", ` Removed legacy proxy: ${oldProxyPath}`));\n removed = true;\n }\n\n if (existsSync(preloadPath)) {\n await unlink(preloadPath);\n console.log(styleText(\"green\", ` Removed legacy preload: ${preloadPath}`));\n removed = true;\n }\n\n // Remove statusline wrapper and monitor script if exist\n const statuslineDir = join(DROID_PATCH_DIR, \"statusline\");\n const statuslineWrapperPath = join(statuslineDir, aliasName);\n const statuslineMonitorPath = join(statuslineDir, `${aliasName}-statusline.js`);\n const statuslineSessionsPath = join(statuslineDir, `${aliasName}-sessions.js`);\n\n if (existsSync(statuslineWrapperPath)) {\n await unlink(statuslineWrapperPath);\n console.log(styleText(\"green\", ` Removed statusline wrapper: ${statuslineWrapperPath}`));\n removed = true;\n }\n\n if (existsSync(statuslineMonitorPath)) {\n await unlink(statuslineMonitorPath);\n console.log(styleText(\"green\", ` Removed statusline monitor: ${statuslineMonitorPath}`));\n removed = true;\n }\n\n if (existsSync(statuslineSessionsPath)) {\n await unlink(statuslineSessionsPath);\n console.log(styleText(\"green\", ` Removed sessions browser: ${statuslineSessionsPath}`));\n removed = true;\n }\n\n // Remove metadata\n const metaRemoved = await removeAliasMetadata(aliasName);\n if (metaRemoved) {\n console.log(styleText(\"green\", ` Removed metadata`));\n removed = true;\n }\n\n if (!removed) {\n console.log(styleText(\"yellow\", ` Alias \"${aliasName}\" not found`));\n } else {\n console.log(styleText(\"green\", `[*] Alias \"${aliasName}\" removed successfully`));\n }\n}\n\nexport async function listAliases(): Promise<void> {\n ensureDirectories();\n\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log(styleText([\"cyan\", \"bold\"], \" Droid-Patch Aliases\"));\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log();\n\n interface AliasInfo {\n name: string;\n target: string;\n location: string;\n immediate: boolean;\n stale: boolean;\n }\n\n const aliases: AliasInfo[] = [];\n\n // Windows: check for .cmd launchers in bin directory\n if (IS_WINDOWS) {\n const binDir = join(DROID_PATCH_DIR, \"bin\");\n if (existsSync(binDir)) {\n try {\n const files = readdirSync(binDir);\n for (const file of files) {\n if (file.endsWith(\".cmd\")) {\n const aliasName = file.replace(/\\.cmd$/, \"\");\n const fullPath = join(binDir, file);\n // Read .cmd to find target\n try {\n const content = readFileSync(fullPath, \"utf-8\");\n const match = content.match(/\"([^\"]+)\"/);\n const target = match ? match[1] : fullPath;\n aliases.push({\n name: aliasName,\n target,\n location: binDir,\n immediate: checkPathInclusion(),\n stale: false,\n });\n } catch {\n aliases.push({\n name: aliasName,\n target: fullPath,\n location: binDir,\n immediate: false,\n stale: false,\n });\n }\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n // Also check proxy directory for wrapper .cmd files\n const proxyDir = join(DROID_PATCH_DIR, \"proxy\");\n if (existsSync(proxyDir)) {\n try {\n const files = readdirSync(proxyDir);\n for (const file of files) {\n if (file.endsWith(\".cmd\")) {\n const aliasName = file.replace(/\\.cmd$/, \"\");\n if (!aliases.find((a) => a.name === aliasName)) {\n const fullPath = join(proxyDir, file);\n aliases.push({\n name: aliasName,\n target: fullPath,\n location: proxyDir,\n immediate: false,\n stale: false,\n });\n }\n }\n }\n } catch {\n // Ignore\n }\n }\n } else {\n // Unix: check for symlinks\n for (const pathDir of COMMON_PATH_DIRS) {\n if (!existsSync(pathDir)) continue;\n\n try {\n const files = readdirSync(pathDir);\n for (const file of files) {\n const fullPath = join(pathDir, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n const target = await readlink(fullPath);\n if (isManagedAliasTarget(target)) {\n aliases.push({\n name: file,\n target,\n location: pathDir,\n immediate: true,\n stale: !symlinkTargetExists(fullPath, target),\n });\n }\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n try {\n const files = readdirSync(ALIASES_DIR);\n\n for (const file of files) {\n const fullPath = join(ALIASES_DIR, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n const target = await readlink(fullPath);\n if (!aliases.find((a) => a.name === file)) {\n aliases.push({\n name: file,\n target,\n location: ALIASES_DIR,\n immediate: false,\n stale: !symlinkTargetExists(fullPath, target),\n });\n }\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory doesn't exist or can't be read\n }\n }\n\n if (aliases.length === 0) {\n console.log(styleText(\"gray\", \" No aliases configured.\"));\n console.log();\n console.log(styleText(\"gray\", \" Create one with: npx droid-patch --is-custom <alias-name>\"));\n } else {\n console.log(styleText(\"white\", ` Found ${aliases.length} alias(es):`));\n console.log();\n for (const alias of aliases) {\n const status = alias.stale\n ? styleText(\"red\", \"stale broken symlink\")\n : alias.immediate\n ? styleText(\"green\", \"✓ immediate\")\n : styleText(\"yellow\", \"requires source\");\n console.log(styleText(\"green\", ` • ${styleText([\"cyan\", \"bold\"], alias.name)} [${status}]`));\n console.log(styleText(\"gray\", ` → ${alias.target}`));\n if (alias.stale) {\n console.log(\n styleText(\n \"yellow\",\n ` Target missing; run \\`npx droid-patch remove ${alias.name}\\` or \\`clear\\` to clean it up.`,\n ),\n );\n }\n\n // Load and display metadata\n const meta = await loadAliasMetadata(alias.name);\n if (meta) {\n // Version info\n const patchVer = meta.droidPatchVersion\n ? `droid-patch@${meta.droidPatchVersion}`\n : \"unknown\";\n const droidVer = meta.droidVersion ? `droid@${meta.droidVersion}` : \"unknown\";\n console.log(styleText(\"gray\", ` Versions: ${patchVer}, ${droidVer}`));\n\n // Flags/patches\n const flags = formatPatches(meta.patches);\n console.log(styleText(\"gray\", ` Flags: ${flags}`));\n\n // Created time\n if (meta.createdAt) {\n const date = new Date(meta.createdAt).toLocaleString();\n console.log(styleText(\"gray\", ` Created: ${date}`));\n }\n } else {\n console.log(styleText(\"yellow\", ` (no metadata - created by older version)`));\n }\n console.log();\n }\n }\n\n console.log();\n console.log(styleText(\"gray\", ` Aliases directory: ${ALIASES_DIR}`));\n console.log(\n styleText(\n \"gray\",\n ` PATH configured: ${checkPathInclusion() ? styleText(\"green\", \"Yes\") : styleText(\"yellow\", \"No\")}`,\n ),\n );\n console.log();\n}\n\nexport interface ReplaceOriginalResult {\n originalPath: string;\n backupPath: string;\n}\n\nexport async function replaceOriginal(\n patchedBinaryPath: string,\n originalPath: string,\n verbose = false,\n): Promise<ReplaceOriginalResult> {\n ensureDirectories();\n\n console.log(\n styleText(\"white\", `[*] Replacing original binary: ${styleText(\"cyan\", originalPath)}`),\n );\n\n const latestBackupPath = join(BINS_DIR, \"droid-original-latest\");\n\n if (!existsSync(latestBackupPath)) {\n await copyFile(originalPath, latestBackupPath);\n console.log(styleText(\"green\", `[*] Created backup: ${latestBackupPath}`));\n } else {\n if (verbose) {\n console.log(styleText(\"gray\", ` Backup already exists: ${latestBackupPath}`));\n }\n }\n\n await copyFile(patchedBinaryPath, originalPath);\n await chmod(originalPath, 0o755);\n console.log(styleText(\"green\", `[*] Replaced: ${originalPath}`));\n\n if (process.platform === \"darwin\") {\n try {\n console.log(styleText(\"gray\", \"[*] Re-signing binary for macOS...\"));\n execSync(`codesign --force --deep --sign - \"${originalPath}\"`, {\n stdio: \"pipe\",\n });\n console.log(styleText(\"green\", \"[*] Binary re-signed successfully\"));\n } catch {\n console.log(styleText(\"yellow\", \"[!] Could not re-sign binary. You may need to run:\"));\n console.log(styleText(\"gray\", ` codesign --force --deep --sign - \"${originalPath}\"`));\n }\n\n try {\n execSync(`xattr -cr \"${originalPath}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n console.log();\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" REPLACEMENT COMPLETE\"));\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"The patched binary is now active in all terminals.\"));\n console.log(styleText(\"white\", \"No need to restart or source anything!\"));\n console.log();\n console.log(styleText(\"gray\", `To restore the original, run:`));\n console.log(styleText(\"cyan\", ` npx droid-patch restore`));\n\n return {\n originalPath,\n backupPath: latestBackupPath,\n };\n}\n\n/**\n * Create alias for wrapper script\n * Unlike createAlias, this function creates symlink pointing to wrapper script\n * Used for features like websearch that require preprocessing\n */\nexport async function createAliasForWrapper(\n wrapperPath: string,\n aliasName: string,\n verbose = false,\n): Promise<CreateAliasResult> {\n ensureDirectories();\n\n console.log(styleText(\"white\", `[*] Creating alias: ${styleText(\"cyan\", aliasName)}`));\n\n // Windows: create .cmd launcher pointing to wrapper\n if (IS_WINDOWS) {\n return createWindowsWrapperAlias(wrapperPath, aliasName, verbose);\n }\n\n const writablePathDir = findWritablePathDir();\n\n if (writablePathDir) {\n const targetPath = join(writablePathDir, aliasName);\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Wrapper: ${wrapperPath}`));\n }\n\n if (pathExistsWithLstat(targetPath)) {\n await unlink(targetPath);\n if (verbose) {\n console.log(styleText(\"gray\", ` Removed existing: ${targetPath}`));\n }\n }\n\n await symlink(wrapperPath, targetPath);\n\n console.log(styleText(\"green\", `[*] Created: ${targetPath} -> ${wrapperPath}`));\n console.log();\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" ALIAS READY - NO ACTION REQUIRED!\"));\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log();\n console.log(\n styleText(\n \"white\",\n `The alias \"${styleText([\"cyan\", \"bold\"], aliasName)}\" is now available in ALL terminals.`,\n ),\n );\n console.log(styleText(\"gray\", `(Installed to: ${writablePathDir})`));\n\n return {\n aliasPath: targetPath,\n binaryPath: wrapperPath,\n immediate: true,\n };\n }\n\n // Fallback: use ~/.droid-patch/aliases\n console.log(styleText(\"yellow\", \"[*] No writable PATH directory found, using fallback...\"));\n\n const symlinkPath = join(ALIASES_DIR, aliasName);\n\n if (pathExistsWithLstat(symlinkPath)) {\n await unlink(symlinkPath);\n if (verbose) {\n console.log(styleText(\"gray\", ` Removed existing symlink`));\n }\n }\n\n await symlink(wrapperPath, symlinkPath);\n\n console.log(styleText(\"green\", `[*] Created symlink: ${symlinkPath} -> ${wrapperPath}`));\n\n const shellConfig = getShellConfigPath();\n\n if (!checkPathInclusion()) {\n if (!isPathConfigured(shellConfig)) {\n console.log(styleText(\"white\", `[*] Configuring PATH in ${shellConfig}...`));\n\n if (addPathToShellConfig(shellConfig, verbose)) {\n console.log(styleText(\"green\", `[*] PATH configured successfully!`));\n console.log();\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" ACTION REQUIRED\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"To use the alias in this terminal, run:\"));\n console.log();\n console.log(styleText(\"cyan\", ` source ${shellConfig}`));\n console.log();\n console.log(styleText(\"gray\", \"Or simply open a new terminal window.\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n } else {\n const exportLine = `export PATH=\"${ALIASES_DIR}:$PATH\"`;\n console.log();\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" Manual PATH Configuration Required\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"Add this line to your shell config:\"));\n console.log(styleText(\"cyan\", ` ${exportLine}`));\n console.log();\n console.log(styleText(\"gray\", `Shell config file: ${shellConfig}`));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n }\n } else {\n console.log(styleText(\"green\", `[*] PATH already configured in ${shellConfig}`));\n console.log();\n console.log(\n styleText(\n \"yellow\",\n `Note: Run \\`source ${shellConfig}\\` or open a new terminal to use the alias.`,\n ),\n );\n }\n } else {\n console.log(styleText(\"green\", `[*] PATH already includes aliases directory`));\n console.log();\n console.log(\n styleText(\n \"green\",\n `You can now use \"${styleText([\"cyan\", \"bold\"], aliasName)}\" command directly!`,\n ),\n );\n }\n\n return {\n aliasPath: symlinkPath,\n binaryPath: wrapperPath,\n };\n}\n\n/**\n * Create Windows alias for wrapper script (.cmd pointing to wrapper .cmd)\n */\nasync function createWindowsWrapperAlias(\n wrapperPath: string,\n aliasName: string,\n verbose = false,\n): Promise<CreateAliasResult> {\n const binDir = join(DROID_PATCH_DIR, \"bin\");\n if (!existsSync(binDir)) {\n mkdirSync(binDir, { recursive: true });\n }\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Wrapper: ${wrapperPath}`));\n }\n\n // Create .cmd launcher in bin directory that calls the wrapper\n const cmdPath = join(binDir, `${aliasName}.cmd`);\n const cmdContent = generateWindowsLauncher(wrapperPath);\n writeFileSync(cmdPath, cmdContent);\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Created launcher: ${cmdPath}`));\n }\n\n // Try to add bin directory to user PATH\n const pathAdded = addToWindowsUserPath(binDir);\n\n console.log(styleText(\"green\", `[*] Created: ${cmdPath}`));\n console.log();\n\n if (pathAdded) {\n if (checkPathInclusion()) {\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" ALIAS READY!\"));\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log();\n console.log(\n styleText(\n \"white\",\n `The alias \"${styleText([\"cyan\", \"bold\"], aliasName)}\" is now available.`,\n ),\n );\n console.log(styleText(\"gray\", `(Installed to: ${binDir})`));\n\n return {\n aliasPath: cmdPath,\n binaryPath: wrapperPath,\n immediate: true,\n };\n }\n\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" PATH Updated - Restart Terminal\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"PATH has been updated. Please restart your terminal.\"));\n console.log(\n styleText(\n \"white\",\n `Then you can use \"${styleText([\"cyan\", \"bold\"], aliasName)}\" command directly.`,\n ),\n );\n console.log();\n console.log(styleText(\"gray\", `Installed to: ${binDir}`));\n } else {\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" Manual PATH Configuration Required\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"Add this directory to your PATH:\"));\n console.log(styleText(\"cyan\", ` ${binDir}`));\n console.log();\n console.log(styleText(\"gray\", \"Or run directly:\"));\n console.log(styleText(\"cyan\", ` \"${cmdPath}\"`));\n }\n\n return {\n aliasPath: cmdPath,\n binaryPath: wrapperPath,\n immediate: false,\n };\n}\n\nexport async function restoreOriginal(originalPath: string): Promise<void> {\n ensureDirectories();\n\n const latestBackupPath = join(BINS_DIR, \"droid-original-latest\");\n\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log(styleText([\"cyan\", \"bold\"], \" Restore Original Droid\"));\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log();\n\n if (!existsSync(latestBackupPath)) {\n const localBackup = `${originalPath}.backup`;\n if (existsSync(localBackup)) {\n console.log(styleText(\"white\", `[*] Found local backup: ${localBackup}`));\n console.log(styleText(\"white\", `[*] Restoring to: ${originalPath}`));\n\n await copyFile(localBackup, originalPath);\n await chmod(originalPath, 0o755);\n\n if (process.platform === \"darwin\") {\n try {\n execSync(`codesign --force --deep --sign - \"${originalPath}\"`, {\n stdio: \"pipe\",\n });\n execSync(`xattr -cr \"${originalPath}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n console.log();\n console.log(styleText(\"green\", \"═\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" RESTORE COMPLETE\"));\n console.log(styleText(\"green\", \"═\".repeat(60)));\n console.log();\n console.log(styleText(\"green\", \"Original droid binary has been restored from local backup.\"));\n return;\n }\n\n console.log(styleText(\"red\", \"[!] No backup found.\"));\n console.log(styleText(\"gray\", ` Checked: ${latestBackupPath}`));\n console.log(styleText(\"gray\", ` Checked: ${localBackup}`));\n console.log();\n console.log(styleText(\"gray\", \"If you have a manual backup, restore it with:\"));\n console.log(styleText(\"cyan\", ` cp /path/to/backup ${originalPath}`));\n return;\n }\n\n console.log(styleText(\"white\", `[*] Restoring from: ${latestBackupPath}`));\n console.log(styleText(\"white\", `[*] Restoring to: ${originalPath}`));\n\n const targetDir = dirname(originalPath);\n if (!existsSync(targetDir)) {\n mkdirSync(targetDir, { recursive: true });\n }\n\n await copyFile(latestBackupPath, originalPath);\n await chmod(originalPath, 0o755);\n\n if (process.platform === \"darwin\") {\n try {\n execSync(`codesign --force --deep --sign - \"${originalPath}\"`, {\n stdio: \"pipe\",\n });\n execSync(`xattr -cr \"${originalPath}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n console.log();\n console.log(styleText(\"green\", \"═\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" RESTORE COMPLETE\"));\n console.log(styleText(\"green\", \"═\".repeat(60)));\n console.log();\n console.log(styleText(\"green\", \"Original droid binary has been restored.\"));\n console.log(styleText(\"green\", \"All terminals will now use the original version.\"));\n}\n\n/**\n * Filter options for removing aliases\n * Uses the same names as CLI options for consistency\n */\nexport type FilterFlag =\n | \"is-custom\"\n | \"skip-login\"\n | \"websearch\"\n | \"api-base\"\n | \"reasoning-effort\"\n | \"disable-telemetry\"\n | \"standalone\";\n\nexport interface RemoveFilterOptions {\n /** Remove aliases created by this droid-patch version */\n patchVersion?: string;\n /** Remove aliases for this droid version */\n droidVersion?: string;\n /** Remove aliases that have these flags enabled (all must match) */\n flags?: FilterFlag[];\n}\n\n/**\n * Remove aliases matching filter criteria\n */\nexport async function removeAliasesByFilter(filter: RemoveFilterOptions): Promise<void> {\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log(styleText([\"cyan\", \"bold\"], \" Remove Aliases by Filter\"));\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log();\n\n // Show filter criteria\n if (filter.patchVersion) {\n console.log(styleText(\"white\", ` Filter: droid-patch version = ${filter.patchVersion}`));\n }\n if (filter.droidVersion) {\n console.log(styleText(\"white\", ` Filter: droid version = ${filter.droidVersion}`));\n }\n if (filter.flags && filter.flags.length > 0) {\n console.log(styleText(\"white\", ` Filter: flags = ${filter.flags.join(\", \")}`));\n }\n console.log();\n\n // Collect all alias names\n const aliasNames = new Set<string>();\n\n // Check common PATH directories for symlinks\n for (const pathDir of COMMON_PATH_DIRS) {\n if (!existsSync(pathDir)) continue;\n\n try {\n const files = readdirSync(pathDir);\n for (const file of files) {\n const fullPath = join(pathDir, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n const target = await readlink(fullPath);\n if (isManagedAliasTarget(target)) {\n aliasNames.add(file);\n }\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n // Check aliases directory\n if (existsSync(ALIASES_DIR)) {\n try {\n const files = readdirSync(ALIASES_DIR);\n for (const file of files) {\n const fullPath = join(ALIASES_DIR, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n aliasNames.add(file);\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n // Filter aliases by metadata\n const matchingAliases: string[] = [];\n\n for (const aliasName of aliasNames) {\n const meta = await loadAliasMetadata(aliasName);\n\n // If no metadata, skip (can't filter without metadata)\n if (!meta) {\n continue;\n }\n\n let matches = true;\n\n // Check droid-patch version\n if (filter.patchVersion && meta.droidPatchVersion !== filter.patchVersion) {\n matches = false;\n }\n\n // Check droid version\n if (filter.droidVersion && meta.droidVersion !== filter.droidVersion) {\n matches = false;\n }\n\n // Check flags (all specified flags must match)\n if (filter.flags && filter.flags.length > 0) {\n const patches = meta.patches;\n for (const flag of filter.flags) {\n switch (flag) {\n case \"is-custom\":\n if (!patches.isCustom) matches = false;\n break;\n case \"skip-login\":\n if (!patches.skipLogin) matches = false;\n break;\n case \"websearch\":\n if (!patches.websearch) matches = false;\n break;\n case \"reasoning-effort\":\n if (!patches.reasoningEffort) matches = false;\n break;\n case \"api-base\":\n if (!patches.apiBase) matches = false;\n break;\n case \"disable-telemetry\":\n if (!patches.noTelemetry) matches = false;\n break;\n case \"standalone\":\n if (!patches.standalone) matches = false;\n break;\n }\n if (!matches) break;\n }\n }\n\n if (matches) {\n matchingAliases.push(aliasName);\n }\n }\n\n if (matchingAliases.length === 0) {\n console.log(styleText(\"yellow\", \" No aliases match the filter criteria.\"));\n console.log();\n return;\n }\n\n console.log(styleText(\"white\", ` Found ${matchingAliases.length} matching alias(es):`));\n for (const name of matchingAliases) {\n console.log(styleText(\"gray\", ` • ${name}`));\n }\n console.log();\n\n // Remove each matching alias\n for (const aliasName of matchingAliases) {\n await removeAlias(aliasName);\n console.log();\n }\n\n console.log(styleText(\"green\", `[*] Removed ${matchingAliases.length} alias(es)`));\n}\n\n/**\n * Clear all droid-patch aliases and related files\n */\nexport async function clearAllAliases(): Promise<void> {\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log(styleText([\"cyan\", \"bold\"], \" Clearing All Droid-Patch Data\"));\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log();\n\n // Collect all alias names\n const aliasNames = new Set<string>();\n\n // Check common PATH directories for symlinks\n for (const pathDir of COMMON_PATH_DIRS) {\n if (!existsSync(pathDir)) continue;\n\n try {\n const files = readdirSync(pathDir);\n for (const file of files) {\n const fullPath = join(pathDir, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n const target = await readlink(fullPath);\n if (isManagedAliasTarget(target)) {\n aliasNames.add(file);\n }\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n // Check aliases directory\n if (existsSync(ALIASES_DIR)) {\n try {\n const files = readdirSync(ALIASES_DIR);\n for (const file of files) {\n const fullPath = join(ALIASES_DIR, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n aliasNames.add(file);\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n if (aliasNames.size === 0) {\n console.log(styleText(\"yellow\", \" No aliases found.\"));\n } else {\n console.log(styleText(\"white\", ` Found ${aliasNames.size} alias(es) to remove:`));\n for (const name of aliasNames) {\n console.log(styleText(\"gray\", ` • ${name}`));\n }\n console.log();\n\n // Remove each alias\n for (const aliasName of aliasNames) {\n await removeAlias(aliasName);\n console.log();\n }\n }\n\n // Clean up directories (including legacy files)\n console.log(styleText(\"white\", \" Cleaning up directories...\"));\n const dirsToClean = [\n join(DROID_PATCH_DIR, \"bins\"),\n join(DROID_PATCH_DIR, \"aliases\"),\n join(DROID_PATCH_DIR, \"proxy\"),\n join(DROID_PATCH_DIR, \"websearch\"),\n join(DROID_PATCH_DIR, \"statusline\"),\n ];\n\n for (const dir of dirsToClean) {\n if (existsSync(dir)) {\n try {\n const files = readdirSync(dir);\n for (const file of files) {\n const fullPath = join(dir, file);\n try {\n await unlink(fullPath);\n console.log(styleText(\"green\", ` Removed: ${fullPath}`));\n } catch {\n // Ignore\n }\n }\n } catch {\n // Ignore\n }\n }\n }\n\n // Clean up legacy temp files from old versions\n const legacyTempFiles = [\"/tmp/droid-search-proxy.pid\", \"/tmp/droid-search-proxy.log\"];\n\n for (const tempFile of legacyTempFiles) {\n if (existsSync(tempFile)) {\n try {\n await unlink(tempFile);\n console.log(styleText(\"green\", ` Removed legacy: ${tempFile}`));\n } catch {\n // Ignore\n }\n }\n }\n\n // Clean up temp port files (pattern: /tmp/droid-websearch-*.port)\n try {\n const tmpFiles = readdirSync(\"/tmp\");\n for (const file of tmpFiles) {\n if (file.startsWith(\"droid-websearch-\") && file.endsWith(\".port\")) {\n const fullPath = join(\"/tmp\", file);\n try {\n await unlink(fullPath);\n console.log(styleText(\"green\", ` Removed temp: ${fullPath}`));\n } catch {\n // Ignore\n }\n }\n // Also clean old droid-search-proxy-*.port files\n if (file.startsWith(\"droid-search-proxy-\") && file.endsWith(\".port\")) {\n const fullPath = join(\"/tmp\", file);\n try {\n await unlink(fullPath);\n console.log(styleText(\"green\", ` Removed legacy temp: ${fullPath}`));\n } catch {\n // Ignore\n }\n }\n }\n } catch {\n // Ignore\n }\n\n const removedMetadataCount = await clearAllMetadata();\n if (removedMetadataCount > 0) {\n console.log(styleText(\"green\", ` Removed metadata files: ${removedMetadataCount}`));\n }\n\n // Clean up metadata file\n const metadataFile = join(DROID_PATCH_DIR, \"metadata.json\");\n if (existsSync(metadataFile)) {\n try {\n await unlink(metadataFile);\n console.log(styleText(\"green\", ` Removed: ${metadataFile}`));\n } catch {\n // Ignore\n }\n }\n\n console.log();\n console.log(styleText(\"green\", \"[*] All droid-patch data cleared successfully\"));\n}\n"],"mappings":";;;;;;;;AAMA,MAAMA,eAAa,UAAU,KAAK;AAkDlC,SAAS,sBACP,QACA,UACA,YACA,kBACM;AACN,KAAI,iBAAiB,SAAS,WAAW,OACvC,OAAM,IAAI,MACR,+CAA+C,iBAAiB,OAAO,KAAK,WAAW,SACxF;AAGH,kBAAiB,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IAAI,UAAU,SAAS,gBAAgB,WAAW,CAAC;WACrD;;SAIJ;AASZ,MAAK,MAAM,YAFa,CAAC,+BAA+B,8BAA8B,CAGpF,KAAI,WAAW,SAAS,CACtB,KAAI;AACF,QAAM,OAAO,SAAS;AACtB,UAAQ,IAAI,UAAU,SAAS,uBAAuB,WAAW,CAAC;SAC5D;AAOZ,KAAI;EACF,MAAM,WAAW,YAAY,OAAO;AACpC,OAAK,MAAM,QAAQ,UAAU;AAC3B,OAAI,KAAK,WAAW,mBAAmB,IAAI,KAAK,SAAS,QAAQ,EAAE;IACjE,MAAM,WAAW,KAAK,QAAQ,KAAK;AACnC,QAAI;AACF,WAAM,OAAO,SAAS;AACtB,aAAQ,IAAI,UAAU,SAAS,qBAAqB,WAAW,CAAC;YAC1D;;AAKV,OAAI,KAAK,WAAW,sBAAsB,IAAI,KAAK,SAAS,QAAQ,EAAE;IACpE,MAAM,WAAW,KAAK,QAAQ,KAAK;AACnC,QAAI;AACF,WAAM,OAAO,SAAS;AACtB,aAAQ,IAAI,UAAU,SAAS,4BAA4B,WAAW,CAAC;YACjE;;;SAKN;CAIR,MAAM,uBAAuB,MAAM,kBAAkB;AACrD,KAAI,uBAAuB,EACzB,SAAQ,IAAI,UAAU,SAAS,+BAA+B,uBAAuB,CAAC;CAIxF,MAAM,eAAe,KAAK,iBAAiB,gBAAgB;AAC3D,KAAI,WAAW,aAAa,CAC1B,KAAI;AACF,QAAM,OAAO,aAAa;AAC1B,UAAQ,IAAI,UAAU,SAAS,gBAAgB,eAAe,CAAC;SACzD;AAKV,SAAQ,KAAK;AACb,SAAQ,IAAI,UAAU,SAAS,gDAAgD,CAAC"}
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as removeAlias, d as listAllMetadata, f as loadAliasMetadata, i as listAliases, l as createMetadata, m as patchDroid, n as createAlias, o as removeAliasesByFilter, p as saveAliasMetadata, r as createAliasForWrapper, t as clearAllAliases, u as formatPatches } from "./alias-DOPp4UYn.mjs";
2
+ import { a as removeAlias, d as listAllMetadata, f as loadAliasMetadata, g as patchDroid, h as pathExistsWithLstat, i as listAliases, l as createMetadata, m as isManagedAliasTarget, n as createAlias, o as removeAliasesByFilter, p as saveAliasMetadata, r as createAliasForWrapper, t as clearAllAliases, u as formatPatches } from "./alias-Dri1cXrO.mjs";
3
3
  import bin from "tiny-bin";
4
4
  import { styleText } from "node:util";
5
5
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
@@ -1409,8 +1409,8 @@ const SKIP_LOGIN_PATCH_RULES = [{
1409
1409
  alreadyPatchedRegexPattern: SKIP_LOGIN_V068_PLUS_PATCHED_REGEX
1410
1410
  }]
1411
1411
  }];
1412
- const FACTORYD_SELF_PATH_REGEX = /(function ([A-Za-z$_][A-Za-z0-9$_]*)\(([A-Za-z$_][A-Za-z0-9$_]*)\)\{if\()([A-Za-z$_][A-Za-z0-9$_]*)\.basename\(process\.execPath\)\.includes\("droid"\)(\)return process\.execPath;return \3\?"droid-dev":"droid"\})/g;
1413
- const FACTORYD_SELF_PATH_PATCHED_REGEX = /function ([A-Za-z$_][A-Za-z0-9$_]*)\(([A-Za-z$_][A-Za-z0-9$_]*)\)\{if\(\(1\|\|([A-Za-z$_][A-Za-z0-9$_]*)\.basename\(process\.execPath\)\.includes\(""\)\)\)return process\.execPath;return \2\?"droid-dev":"droid"\}/g;
1412
+ const FACTORYD_SELF_PATH_REGEX = /if\(([A-Za-z$_][A-Za-z0-9$_]*)\.basename\(process\.execPath\)\.includes\("droid"\)\)/g;
1413
+ const FACTORYD_SELF_PATH_PATCHED_REGEX = /if\(\(1\|\|([A-Za-z$_][A-Za-z0-9$_]*)\.basename\(process\.execPath\)\.includes\(""\)\)\)/g;
1414
1414
  const FACTORYD_SKIP_LOGIN_AUTH_REGEX = /async function ([A-Za-z$_][A-Za-z0-9$_]*)\(([A-Za-z$_][A-Za-z0-9$_]*)\)\{let ([A-Za-z$_][A-Za-z0-9$_]*)=([A-Za-z$_][A-Za-z0-9$_]*)\(\)\.apiBaseUrl,([A-Za-z$_][A-Za-z0-9$_]*)=await fetch\(`\$\{\3\}\/api\/cli\/whoami`,\{method:"GET",headers:\{Authorization:`Bearer \$\{\2\}`\}\}\),([A-Za-z$_][A-Za-z0-9$_]*)=await \5\.text\(\);if\(!\5\.ok\)throw new ([A-Za-z$_][A-Za-z0-9$_]*)\("API key verification failed",\{statusCode:\5\.status,body:\6\}\);let ([A-Za-z$_][A-Za-z0-9$_]*)=([A-Za-z$_][A-Za-z0-9$_]*)\(\6,([A-Za-z$_][A-Za-z0-9$_]*),"whoami response"\);return\{userId:\8\.userId,email:"",orgId:\8\.orgId\}\}/g;
1415
1415
  const FACTORYD_SKIP_LOGIN_AUTH_PATCHED_REGEX = /async function [A-Za-z$_][A-Za-z0-9$_]*\(([A-Za-z$_][A-Za-z0-9$_]*)\)\{if\(\/\^fk\/\.test\(\1\)\)return\{userId:"f",orgId:"f"\};let ([A-Za-z$_][A-Za-z0-9$_]*)=await fetch\(`\$\{([A-Za-z$_][A-Za-z0-9$_]*)\(\)\.apiBaseUrl\}\/api\/cli\/whoami`,\{headers:\{Authorization:`Bearer \$\{\1\}`\}\}\);if\(!\2\.ok\)throw new [A-Za-z$_][A-Za-z0-9$_]*\("API key verification failed"\);\2=[A-Za-z$_][A-Za-z0-9$_]*\(await \2\.text\(\),([A-Za-z$_][A-Za-z0-9$_]*),"whoami response"\);return\{userId:\2\.userId,email:"",orgId:\2\.orgId\}\s+\}/g;
1416
1416
  function createFactorydSelfPathPatch() {
@@ -1420,7 +1420,7 @@ function createFactorydSelfPathPatch() {
1420
1420
  pattern: Buffer.from(""),
1421
1421
  replacement: Buffer.from(""),
1422
1422
  regexPattern: FACTORYD_SELF_PATH_REGEX,
1423
- regexReplacement: "$1(1||$4.basename(process.execPath).includes(\"\"))$5",
1423
+ regexReplacement: "if((1||$1.basename(process.execPath).includes(\"\")))",
1424
1424
  alreadyPatchedRegexPattern: FACTORYD_SELF_PATH_PATCHED_REGEX
1425
1425
  };
1426
1426
  }
@@ -2109,10 +2109,9 @@ bin("droid-patch", "CLI tool to patch droid binary with various modifications").
2109
2109
  ];
2110
2110
  for (const dir of commonPathDirs) {
2111
2111
  const possiblePath = join(dir, meta.name);
2112
- if (existsSync(possiblePath)) try {
2112
+ if (pathExistsWithLstat(possiblePath)) try {
2113
2113
  if ((await lstat(possiblePath)).isSymbolicLink()) {
2114
- const target = await readlink(possiblePath);
2115
- if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/proxy") || target.includes(".droid-patch/statusline")) {
2114
+ if (isManagedAliasTarget(await readlink(possiblePath))) {
2116
2115
  aliasPath = possiblePath;
2117
2116
  if (verbose) console.log(styleText("gray", ` Found existing symlink: ${aliasPath}`));
2118
2117
  break;
@@ -2122,7 +2121,7 @@ bin("droid-patch", "CLI tool to patch droid binary with various modifications").
2122
2121
  }
2123
2122
  }
2124
2123
  if (aliasPath) try {
2125
- if (existsSync(aliasPath)) {
2124
+ if (pathExistsWithLstat(aliasPath)) {
2126
2125
  if (await readlink(aliasPath) !== execTargetPath) {
2127
2126
  await unlink(aliasPath);
2128
2127
  await symlink(execTargetPath, aliasPath);