aiblueprint-cli 1.4.68 → 1.4.70

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.
Files changed (2) hide show
  1. package/dist/cli.js +2043 -1852
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -34891,2028 +34891,2219 @@ async function symlinkCommand(params = {}) {
34891
34891
  }
34892
34892
  }
34893
34893
 
34894
- // src/lib/agents-unifier.ts
34895
- var import_fs_extra13 = __toESM(require_lib4(), 1);
34896
- import crypto from "crypto";
34897
- import os14 from "os";
34898
- import path17 from "path";
34899
-
34900
- // src/lib/backup-utils.ts
34901
- var import_fs_extra12 = __toESM(require_lib4(), 1);
34902
- import path16 from "path";
34903
- import os13 from "os";
34904
- var BACKUP_BASE_DIR = path16.join(os13.homedir(), ".config", "aiblueprint", "backup");
34905
- function getBackupDir() {
34906
- return process.env.AIBLUEPRINT_BACKUP_DIR || BACKUP_BASE_DIR;
34907
- }
34908
- function formatDate(date) {
34909
- const pad = (n) => n.toString().padStart(2, "0");
34910
- return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}-${pad(date.getHours())}-${pad(date.getMinutes())}-${pad(date.getSeconds())}`;
34894
+ // node_modules/@clack/core/dist/index.mjs
34895
+ var import_sisteransi = __toESM(require_src(), 1);
34896
+ var import_picocolors = __toESM(require_picocolors(), 1);
34897
+ import { stdin as j, stdout as M } from "node:process";
34898
+ import * as g from "node:readline";
34899
+ import O from "node:readline";
34900
+ import { Writable as X } from "node:stream";
34901
+ function DD({ onlyFirst: e = false } = {}) {
34902
+ const t = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
34903
+ return new RegExp(t, e ? undefined : "g");
34911
34904
  }
34912
- function createBackupNameSuffix(value) {
34913
- return value.trim().replace(/^[a-zA-Z]:/, (drive) => drive.replace(":", "")).replace(/[\\/]+/g, "--").replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "root";
34905
+ var uD = DD();
34906
+ function P(e) {
34907
+ if (typeof e != "string")
34908
+ throw new TypeError(`Expected a \`string\`, got \`${typeof e}\``);
34909
+ return e.replace(uD, "");
34914
34910
  }
34915
- function createTimestampedBackupName(suffix, date = new Date) {
34916
- const base = formatDate(date);
34917
- if (!suffix)
34918
- return base;
34919
- return `${base}--${createBackupNameSuffix(suffix)}`;
34911
+ function L(e) {
34912
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
34920
34913
  }
34921
- async function listBackups() {
34922
- const backupBaseDir = getBackupDir();
34923
- const exists = await import_fs_extra12.default.pathExists(backupBaseDir);
34924
- if (!exists) {
34925
- return [];
34914
+ var W = { exports: {} };
34915
+ (function(e) {
34916
+ var u = {};
34917
+ e.exports = u, u.eastAsianWidth = function(F) {
34918
+ var s = F.charCodeAt(0), i = F.length == 2 ? F.charCodeAt(1) : 0, D = s;
34919
+ return 55296 <= s && s <= 56319 && 56320 <= i && i <= 57343 && (s &= 1023, i &= 1023, D = s << 10 | i, D += 65536), D == 12288 || 65281 <= D && D <= 65376 || 65504 <= D && D <= 65510 ? "F" : D == 8361 || 65377 <= D && D <= 65470 || 65474 <= D && D <= 65479 || 65482 <= D && D <= 65487 || 65490 <= D && D <= 65495 || 65498 <= D && D <= 65500 || 65512 <= D && D <= 65518 ? "H" : 4352 <= D && D <= 4447 || 4515 <= D && D <= 4519 || 4602 <= D && D <= 4607 || 9001 <= D && D <= 9002 || 11904 <= D && D <= 11929 || 11931 <= D && D <= 12019 || 12032 <= D && D <= 12245 || 12272 <= D && D <= 12283 || 12289 <= D && D <= 12350 || 12353 <= D && D <= 12438 || 12441 <= D && D <= 12543 || 12549 <= D && D <= 12589 || 12593 <= D && D <= 12686 || 12688 <= D && D <= 12730 || 12736 <= D && D <= 12771 || 12784 <= D && D <= 12830 || 12832 <= D && D <= 12871 || 12880 <= D && D <= 13054 || 13056 <= D && D <= 19903 || 19968 <= D && D <= 42124 || 42128 <= D && D <= 42182 || 43360 <= D && D <= 43388 || 44032 <= D && D <= 55203 || 55216 <= D && D <= 55238 || 55243 <= D && D <= 55291 || 63744 <= D && D <= 64255 || 65040 <= D && D <= 65049 || 65072 <= D && D <= 65106 || 65108 <= D && D <= 65126 || 65128 <= D && D <= 65131 || 110592 <= D && D <= 110593 || 127488 <= D && D <= 127490 || 127504 <= D && D <= 127546 || 127552 <= D && D <= 127560 || 127568 <= D && D <= 127569 || 131072 <= D && D <= 194367 || 177984 <= D && D <= 196605 || 196608 <= D && D <= 262141 ? "W" : 32 <= D && D <= 126 || 162 <= D && D <= 163 || 165 <= D && D <= 166 || D == 172 || D == 175 || 10214 <= D && D <= 10221 || 10629 <= D && D <= 10630 ? "Na" : D == 161 || D == 164 || 167 <= D && D <= 168 || D == 170 || 173 <= D && D <= 174 || 176 <= D && D <= 180 || 182 <= D && D <= 186 || 188 <= D && D <= 191 || D == 198 || D == 208 || 215 <= D && D <= 216 || 222 <= D && D <= 225 || D == 230 || 232 <= D && D <= 234 || 236 <= D && D <= 237 || D == 240 || 242 <= D && D <= 243 || 247 <= D && D <= 250 || D == 252 || D == 254 || D == 257 || D == 273 || D == 275 || D == 283 || 294 <= D && D <= 295 || D == 299 || 305 <= D && D <= 307 || D == 312 || 319 <= D && D <= 322 || D == 324 || 328 <= D && D <= 331 || D == 333 || 338 <= D && D <= 339 || 358 <= D && D <= 359 || D == 363 || D == 462 || D == 464 || D == 466 || D == 468 || D == 470 || D == 472 || D == 474 || D == 476 || D == 593 || D == 609 || D == 708 || D == 711 || 713 <= D && D <= 715 || D == 717 || D == 720 || 728 <= D && D <= 731 || D == 733 || D == 735 || 768 <= D && D <= 879 || 913 <= D && D <= 929 || 931 <= D && D <= 937 || 945 <= D && D <= 961 || 963 <= D && D <= 969 || D == 1025 || 1040 <= D && D <= 1103 || D == 1105 || D == 8208 || 8211 <= D && D <= 8214 || 8216 <= D && D <= 8217 || 8220 <= D && D <= 8221 || 8224 <= D && D <= 8226 || 8228 <= D && D <= 8231 || D == 8240 || 8242 <= D && D <= 8243 || D == 8245 || D == 8251 || D == 8254 || D == 8308 || D == 8319 || 8321 <= D && D <= 8324 || D == 8364 || D == 8451 || D == 8453 || D == 8457 || D == 8467 || D == 8470 || 8481 <= D && D <= 8482 || D == 8486 || D == 8491 || 8531 <= D && D <= 8532 || 8539 <= D && D <= 8542 || 8544 <= D && D <= 8555 || 8560 <= D && D <= 8569 || D == 8585 || 8592 <= D && D <= 8601 || 8632 <= D && D <= 8633 || D == 8658 || D == 8660 || D == 8679 || D == 8704 || 8706 <= D && D <= 8707 || 8711 <= D && D <= 8712 || D == 8715 || D == 8719 || D == 8721 || D == 8725 || D == 8730 || 8733 <= D && D <= 8736 || D == 8739 || D == 8741 || 8743 <= D && D <= 8748 || D == 8750 || 8756 <= D && D <= 8759 || 8764 <= D && D <= 8765 || D == 8776 || D == 8780 || D == 8786 || 8800 <= D && D <= 8801 || 8804 <= D && D <= 8807 || 8810 <= D && D <= 8811 || 8814 <= D && D <= 8815 || 8834 <= D && D <= 8835 || 8838 <= D && D <= 8839 || D == 8853 || D == 8857 || D == 8869 || D == 8895 || D == 8978 || 9312 <= D && D <= 9449 || 9451 <= D && D <= 9547 || 9552 <= D && D <= 9587 || 9600 <= D && D <= 9615 || 9618 <= D && D <= 9621 || 9632 <= D && D <= 9633 || 9635 <= D && D <= 9641 || 9650 <= D && D <= 9651 || 9654 <= D && D <= 9655 || 9660 <= D && D <= 9661 || 9664 <= D && D <= 9665 || 9670 <= D && D <= 9672 || D == 9675 || 9678 <= D && D <= 9681 || 9698 <= D && D <= 9701 || D == 9711 || 9733 <= D && D <= 9734 || D == 9737 || 9742 <= D && D <= 9743 || 9748 <= D && D <= 9749 || D == 9756 || D == 9758 || D == 9792 || D == 9794 || 9824 <= D && D <= 9825 || 9827 <= D && D <= 9829 || 9831 <= D && D <= 9834 || 9836 <= D && D <= 9837 || D == 9839 || 9886 <= D && D <= 9887 || 9918 <= D && D <= 9919 || 9924 <= D && D <= 9933 || 9935 <= D && D <= 9953 || D == 9955 || 9960 <= D && D <= 9983 || D == 10045 || D == 10071 || 10102 <= D && D <= 10111 || 11093 <= D && D <= 11097 || 12872 <= D && D <= 12879 || 57344 <= D && D <= 63743 || 65024 <= D && D <= 65039 || D == 65533 || 127232 <= D && D <= 127242 || 127248 <= D && D <= 127277 || 127280 <= D && D <= 127337 || 127344 <= D && D <= 127386 || 917760 <= D && D <= 917999 || 983040 <= D && D <= 1048573 || 1048576 <= D && D <= 1114109 ? "A" : "N";
34920
+ }, u.characterLength = function(F) {
34921
+ var s = this.eastAsianWidth(F);
34922
+ return s == "F" || s == "W" || s == "A" ? 2 : 1;
34923
+ };
34924
+ function t(F) {
34925
+ return F.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
34926
34926
  }
34927
- const entries = await import_fs_extra12.default.readdir(backupBaseDir, { withFileTypes: true });
34928
- const backups = [];
34929
- for (const entry of entries) {
34930
- if (!entry.isDirectory())
34931
- continue;
34932
- const match = entry.name.match(/^(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})(?:--.+)?$/);
34933
- if (!match)
34927
+ u.length = function(F) {
34928
+ for (var s = t(F), i = 0, D = 0;D < s.length; D++)
34929
+ i = i + this.characterLength(s[D]);
34930
+ return i;
34931
+ }, u.slice = function(F, s, i) {
34932
+ textLen = u.length(F), s = s || 0, i = i || 1, s < 0 && (s = textLen + s), i < 0 && (i = textLen + i);
34933
+ for (var D = "", C = 0, n = t(F), E = 0;E < n.length; E++) {
34934
+ var a = n[E], o = u.length(a);
34935
+ if (C >= s - (o == 2 ? 1 : 0))
34936
+ if (C + o <= i)
34937
+ D += a;
34938
+ else
34939
+ break;
34940
+ C += o;
34941
+ }
34942
+ return D;
34943
+ };
34944
+ })(W);
34945
+ var tD = W.exports;
34946
+ var eD = L(tD);
34947
+ var FD = function() {
34948
+ return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
34949
+ };
34950
+ var sD = L(FD);
34951
+ function p(e, u = {}) {
34952
+ if (typeof e != "string" || e.length === 0 || (u = { ambiguousIsNarrow: true, ...u }, e = P(e), e.length === 0))
34953
+ return 0;
34954
+ e = e.replace(sD(), " ");
34955
+ const t = u.ambiguousIsNarrow ? 1 : 2;
34956
+ let F = 0;
34957
+ for (const s of e) {
34958
+ const i = s.codePointAt(0);
34959
+ if (i <= 31 || i >= 127 && i <= 159 || i >= 768 && i <= 879)
34934
34960
  continue;
34935
- const [, year, month, day, hour, minute, second] = match;
34936
- const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day), parseInt(hour), parseInt(minute), parseInt(second));
34937
- backups.push({
34938
- name: entry.name,
34939
- path: path16.join(backupBaseDir, entry.name),
34940
- date
34941
- });
34961
+ switch (eD.eastAsianWidth(s)) {
34962
+ case "F":
34963
+ case "W":
34964
+ F += 2;
34965
+ break;
34966
+ case "A":
34967
+ F += t;
34968
+ break;
34969
+ default:
34970
+ F += 1;
34971
+ }
34942
34972
  }
34943
- return backups.sort((a, b) => b.date.getTime() - a.date.getTime());
34944
- }
34945
- var AGENTS_BACKUP_SUBDIR = ".agents";
34946
- var CLAUDE_ITEMS = ["commands", "agents", "skills", "scripts", "settings.json"];
34947
- var MANAGED_FOLDERS = [".claude", ".codex", ".agents"];
34948
- async function copyForBackup(sourcePath, destPath) {
34949
- await import_fs_extra12.default.copy(sourcePath, destPath, {
34950
- overwrite: true,
34951
- dereference: false
34952
- });
34953
- }
34954
- async function hasMeaningfulContent(dir) {
34955
- if (!await import_fs_extra12.default.pathExists(dir))
34956
- return false;
34957
- const files = await import_fs_extra12.default.readdir(dir);
34958
- return files.some((f) => f !== ".DS_Store");
34973
+ return F;
34959
34974
  }
34960
- async function loadBackup(backupPath, claudeDir, codexDir, agentsDir) {
34961
- const exists = await import_fs_extra12.default.pathExists(backupPath);
34962
- if (!exists) {
34963
- throw new Error(`Backup not found: ${backupPath}`);
34975
+ var w = 10;
34976
+ var N = (e = 0) => (u) => `\x1B[${u + e}m`;
34977
+ var I = (e = 0) => (u) => `\x1B[${38 + e};5;${u}m`;
34978
+ var R = (e = 0) => (u, t, F) => `\x1B[${38 + e};2;${u};${t};${F}m`;
34979
+ var r = { modifier: { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], blackBright: [90, 39], gray: [90, 39], grey: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgGray: [100, 49], bgGrey: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } };
34980
+ Object.keys(r.modifier);
34981
+ var iD = Object.keys(r.color);
34982
+ var CD = Object.keys(r.bgColor);
34983
+ [...iD, ...CD];
34984
+ function rD() {
34985
+ const e = new Map;
34986
+ for (const [u, t] of Object.entries(r)) {
34987
+ for (const [F, s] of Object.entries(t))
34988
+ r[F] = { open: `\x1B[${s[0]}m`, close: `\x1B[${s[1]}m` }, t[F] = r[F], e.set(s[0], s[1]);
34989
+ Object.defineProperty(r, u, { value: t, enumerable: false });
34964
34990
  }
34965
- const managedDestinations = {
34966
- ".claude": claudeDir,
34967
- ".codex": codexDir,
34968
- ".agents": agentsDir
34969
- };
34970
- let restoredManagedFolder = false;
34971
- for (const folderName of MANAGED_FOLDERS) {
34972
- const sourcePath = path16.join(backupPath, folderName);
34973
- const destPath = managedDestinations[folderName];
34974
- if (!destPath || !await import_fs_extra12.default.pathExists(sourcePath))
34991
+ return Object.defineProperty(r, "codes", { value: e, enumerable: false }), r.color.close = "\x1B[39m", r.bgColor.close = "\x1B[49m", r.color.ansi = N(), r.color.ansi256 = I(), r.color.ansi16m = R(), r.bgColor.ansi = N(w), r.bgColor.ansi256 = I(w), r.bgColor.ansi16m = R(w), Object.defineProperties(r, { rgbToAnsi256: { value: (u, t, F) => u === t && t === F ? u < 8 ? 16 : u > 248 ? 231 : Math.round((u - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(u / 255 * 5) + 6 * Math.round(t / 255 * 5) + Math.round(F / 255 * 5), enumerable: false }, hexToRgb: { value: (u) => {
34992
+ const t = /[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));
34993
+ if (!t)
34994
+ return [0, 0, 0];
34995
+ let [F] = t;
34996
+ F.length === 3 && (F = [...F].map((i) => i + i).join(""));
34997
+ const s = Number.parseInt(F, 16);
34998
+ return [s >> 16 & 255, s >> 8 & 255, s & 255];
34999
+ }, enumerable: false }, hexToAnsi256: { value: (u) => r.rgbToAnsi256(...r.hexToRgb(u)), enumerable: false }, ansi256ToAnsi: { value: (u) => {
35000
+ if (u < 8)
35001
+ return 30 + u;
35002
+ if (u < 16)
35003
+ return 90 + (u - 8);
35004
+ let t, F, s;
35005
+ if (u >= 232)
35006
+ t = ((u - 232) * 10 + 8) / 255, F = t, s = t;
35007
+ else {
35008
+ u -= 16;
35009
+ const C = u % 36;
35010
+ t = Math.floor(u / 36) / 5, F = Math.floor(C / 6) / 5, s = C % 6 / 5;
35011
+ }
35012
+ const i = Math.max(t, F, s) * 2;
35013
+ if (i === 0)
35014
+ return 30;
35015
+ let D = 30 + (Math.round(s) << 2 | Math.round(F) << 1 | Math.round(t));
35016
+ return i === 2 && (D += 60), D;
35017
+ }, enumerable: false }, rgbToAnsi: { value: (u, t, F) => r.ansi256ToAnsi(r.rgbToAnsi256(u, t, F)), enumerable: false }, hexToAnsi: { value: (u) => r.ansi256ToAnsi(r.hexToAnsi256(u)), enumerable: false } }), r;
35018
+ }
35019
+ var ED = rD();
35020
+ var d = new Set(["\x1B", "›"]);
35021
+ var oD = 39;
35022
+ var y = "\x07";
35023
+ var V = "[";
35024
+ var nD = "]";
35025
+ var G = "m";
35026
+ var _2 = `${nD}8;;`;
35027
+ var z = (e) => `${d.values().next().value}${V}${e}${G}`;
35028
+ var K = (e) => `${d.values().next().value}${_2}${e}${y}`;
35029
+ var aD = (e) => e.split(" ").map((u) => p(u));
35030
+ var k = (e, u, t) => {
35031
+ const F = [...u];
35032
+ let s = false, i = false, D = p(P(e[e.length - 1]));
35033
+ for (const [C, n] of F.entries()) {
35034
+ const E = p(n);
35035
+ if (D + E <= t ? e[e.length - 1] += n : (e.push(n), D = 0), d.has(n) && (s = true, i = F.slice(C + 1).join("").startsWith(_2)), s) {
35036
+ i ? n === y && (s = false, i = false) : n === G && (s = false);
34975
35037
  continue;
34976
- await import_fs_extra12.default.ensureDir(destPath);
34977
- await copyForBackup(sourcePath, destPath);
34978
- restoredManagedFolder = true;
35038
+ }
35039
+ D += E, D === t && C < F.length - 1 && (e.push(""), D = 0);
34979
35040
  }
34980
- if (!restoredManagedFolder) {
34981
- await import_fs_extra12.default.ensureDir(claudeDir);
34982
- for (const item of CLAUDE_ITEMS) {
34983
- const sourcePath = path16.join(backupPath, item);
34984
- const destPath = path16.join(claudeDir, item);
34985
- if (await import_fs_extra12.default.pathExists(sourcePath)) {
34986
- await copyForBackup(sourcePath, destPath);
34987
- }
35041
+ !D && e[e.length - 1].length > 0 && e.length > 1 && (e[e.length - 2] += e.pop());
35042
+ };
35043
+ var hD = (e) => {
35044
+ const u = e.split(" ");
35045
+ let t = u.length;
35046
+ for (;t > 0 && !(p(u[t - 1]) > 0); )
35047
+ t--;
35048
+ return t === u.length ? e : u.slice(0, t).join(" ") + u.slice(t).join("");
35049
+ };
35050
+ var lD = (e, u, t = {}) => {
35051
+ if (t.trim !== false && e.trim() === "")
35052
+ return "";
35053
+ let F = "", s, i;
35054
+ const D = aD(e);
35055
+ let C = [""];
35056
+ for (const [E, a] of e.split(" ").entries()) {
35057
+ t.trim !== false && (C[C.length - 1] = C[C.length - 1].trimStart());
35058
+ let o = p(C[C.length - 1]);
35059
+ if (E !== 0 && (o >= u && (t.wordWrap === false || t.trim === false) && (C.push(""), o = 0), (o > 0 || t.trim === false) && (C[C.length - 1] += " ", o++)), t.hard && D[E] > u) {
35060
+ const c = u - o, f = 1 + Math.floor((D[E] - c - 1) / u);
35061
+ Math.floor((D[E] - 1) / u) < f && C.push(""), k(C, a, u);
35062
+ continue;
34988
35063
  }
34989
- if (agentsDir) {
34990
- const agentsBackupPath = path16.join(backupPath, AGENTS_BACKUP_SUBDIR);
34991
- if (await import_fs_extra12.default.pathExists(agentsBackupPath)) {
34992
- await import_fs_extra12.default.ensureDir(agentsDir);
34993
- await copyForBackup(agentsBackupPath, agentsDir);
35064
+ if (o + D[E] > u && o > 0 && D[E] > 0) {
35065
+ if (t.wordWrap === false && o < u) {
35066
+ k(C, a, u);
35067
+ continue;
34994
35068
  }
35069
+ C.push("");
34995
35070
  }
35071
+ if (o + D[E] > u && t.wordWrap === false) {
35072
+ k(C, a, u);
35073
+ continue;
35074
+ }
35075
+ C[C.length - 1] += a;
34996
35076
  }
34997
- }
34998
- async function createBackup(claudeDir, codexDir, agentsDir) {
34999
- const claudeHasContent = await hasMeaningfulContent(claudeDir);
35000
- const codexHasContent = codexDir ? await hasMeaningfulContent(codexDir) : false;
35001
- const agentsHasContent = agentsDir ? await hasMeaningfulContent(agentsDir) : false;
35002
- if (!claudeHasContent && !codexHasContent && !agentsHasContent) {
35003
- return null;
35004
- }
35005
- const backupPath = path16.join(getBackupDir(), createTimestampedBackupName());
35006
- await import_fs_extra12.default.ensureDir(backupPath);
35007
- if (claudeHasContent) {
35008
- await copyForBackup(claudeDir, path16.join(backupPath, ".claude"));
35077
+ t.trim !== false && (C = C.map((E) => hD(E)));
35078
+ const n = [...C.join(`
35079
+ `)];
35080
+ for (const [E, a] of n.entries()) {
35081
+ if (F += a, d.has(a)) {
35082
+ const { groups: c } = new RegExp(`(?:\\${V}(?<code>\\d+)m|\\${_2}(?<uri>.*)${y})`).exec(n.slice(E).join("")) || { groups: {} };
35083
+ if (c.code !== undefined) {
35084
+ const f = Number.parseFloat(c.code);
35085
+ s = f === oD ? undefined : f;
35086
+ } else
35087
+ c.uri !== undefined && (i = c.uri.length === 0 ? undefined : c.uri);
35088
+ }
35089
+ const o = ED.codes.get(Number(s));
35090
+ n[E + 1] === `
35091
+ ` ? (i && (F += K("")), s && o && (F += z(o))) : a === `
35092
+ ` && (s && o && (F += z(s)), i && (F += K(i)));
35009
35093
  }
35010
- if (codexHasContent && codexDir) {
35011
- await copyForBackup(codexDir, path16.join(backupPath, ".codex"));
35094
+ return F;
35095
+ };
35096
+ function Y(e, u, t) {
35097
+ return String(e).normalize().replace(/\r\n/g, `
35098
+ `).split(`
35099
+ `).map((F) => lD(F, u, t)).join(`
35100
+ `);
35101
+ }
35102
+ var xD = ["up", "down", "left", "right", "space", "enter", "cancel"];
35103
+ var B = { actions: new Set(xD), aliases: new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["\x03", "cancel"], ["escape", "cancel"]]) };
35104
+ function $(e, u) {
35105
+ if (typeof e == "string")
35106
+ return B.aliases.get(e) === u;
35107
+ for (const t of e)
35108
+ if (t !== undefined && $(t, u))
35109
+ return true;
35110
+ return false;
35111
+ }
35112
+ function BD(e, u) {
35113
+ if (e === u)
35114
+ return;
35115
+ const t = e.split(`
35116
+ `), F = u.split(`
35117
+ `), s = [];
35118
+ for (let i = 0;i < Math.max(t.length, F.length); i++)
35119
+ t[i] !== F[i] && s.push(i);
35120
+ return s;
35121
+ }
35122
+ var AD = globalThis.process.platform.startsWith("win");
35123
+ var S = Symbol("clack:cancel");
35124
+ function pD(e) {
35125
+ return e === S;
35126
+ }
35127
+ function m(e, u) {
35128
+ const t = e;
35129
+ t.isTTY && t.setRawMode(u);
35130
+ }
35131
+ function fD({ input: e = j, output: u = M, overwrite: t = true, hideCursor: F = true } = {}) {
35132
+ const s = g.createInterface({ input: e, output: u, prompt: "", tabSize: 1 });
35133
+ g.emitKeypressEvents(e, s), e.isTTY && e.setRawMode(true);
35134
+ const i = (D, { name: C, sequence: n }) => {
35135
+ const E = String(D);
35136
+ if ($([E, C, n], "cancel")) {
35137
+ F && u.write(import_sisteransi.cursor.show), process.exit(0);
35138
+ return;
35139
+ }
35140
+ if (!t)
35141
+ return;
35142
+ const a = C === "return" ? 0 : -1, o = C === "return" ? -1 : 0;
35143
+ g.moveCursor(u, a, o, () => {
35144
+ g.clearLine(u, 1, () => {
35145
+ e.once("keypress", i);
35146
+ });
35147
+ });
35148
+ };
35149
+ return F && u.write(import_sisteransi.cursor.hide), e.once("keypress", i), () => {
35150
+ e.off("keypress", i), F && u.write(import_sisteransi.cursor.show), e.isTTY && !AD && e.setRawMode(false), s.terminal = false, s.close();
35151
+ };
35152
+ }
35153
+ var gD = Object.defineProperty;
35154
+ var vD = (e, u, t) => (u in e) ? gD(e, u, { enumerable: true, configurable: true, writable: true, value: t }) : e[u] = t;
35155
+ var h = (e, u, t) => (vD(e, typeof u != "symbol" ? u + "" : u, t), t);
35156
+
35157
+ class x {
35158
+ constructor(u, t = true) {
35159
+ h(this, "input"), h(this, "output"), h(this, "_abortSignal"), h(this, "rl"), h(this, "opts"), h(this, "_render"), h(this, "_track", false), h(this, "_prevFrame", ""), h(this, "_subscribers", new Map), h(this, "_cursor", 0), h(this, "state", "initial"), h(this, "error", ""), h(this, "value");
35160
+ const { input: F = j, output: s = M, render: i, signal: D, ...C } = u;
35161
+ this.opts = C, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = i.bind(this), this._track = t, this._abortSignal = D, this.input = F, this.output = s;
35012
35162
  }
35013
- if (agentsHasContent && agentsDir) {
35014
- const destPath = path16.join(backupPath, AGENTS_BACKUP_SUBDIR);
35015
- await copyForBackup(agentsDir, destPath);
35163
+ unsubscribe() {
35164
+ this._subscribers.clear();
35165
+ }
35166
+ setSubscriber(u, t) {
35167
+ const F = this._subscribers.get(u) ?? [];
35168
+ F.push(t), this._subscribers.set(u, F);
35169
+ }
35170
+ on(u, t) {
35171
+ this.setSubscriber(u, { cb: t });
35172
+ }
35173
+ once(u, t) {
35174
+ this.setSubscriber(u, { cb: t, once: true });
35175
+ }
35176
+ emit(u, ...t) {
35177
+ const F = this._subscribers.get(u) ?? [], s = [];
35178
+ for (const i of F)
35179
+ i.cb(...t), i.once && s.push(() => F.splice(F.indexOf(i), 1));
35180
+ for (const i of s)
35181
+ i();
35182
+ }
35183
+ prompt() {
35184
+ return new Promise((u, t) => {
35185
+ if (this._abortSignal) {
35186
+ if (this._abortSignal.aborted)
35187
+ return this.state = "cancel", this.close(), u(S);
35188
+ this._abortSignal.addEventListener("abort", () => {
35189
+ this.state = "cancel", this.close();
35190
+ }, { once: true });
35191
+ }
35192
+ const F = new X;
35193
+ F._write = (s, i, D) => {
35194
+ this._track && (this.value = this.rl?.line.replace(/\t/g, ""), this._cursor = this.rl?.cursor ?? 0, this.emit("value", this.value)), D();
35195
+ }, this.input.pipe(F), this.rl = O.createInterface({ input: this.input, output: F, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), O.emitKeypressEvents(this.input, this.rl), this.rl.prompt(), this.opts.initialValue !== undefined && this._track && this.rl.write(this.opts.initialValue), this.input.on("keypress", this.onKeypress), m(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
35196
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), m(this.input, false), u(this.value);
35197
+ }), this.once("cancel", () => {
35198
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), m(this.input, false), u(S);
35199
+ });
35200
+ });
35201
+ }
35202
+ onKeypress(u, t) {
35203
+ if (this.state === "error" && (this.state = "active"), t?.name && (!this._track && B.aliases.has(t.name) && this.emit("cursor", B.aliases.get(t.name)), B.actions.has(t.name) && this.emit("cursor", t.name)), u && (u.toLowerCase() === "y" || u.toLowerCase() === "n") && this.emit("confirm", u.toLowerCase() === "y"), u === "\t" && this.opts.placeholder && (this.value || (this.rl?.write(this.opts.placeholder), this.emit("value", this.opts.placeholder))), u && this.emit("key", u.toLowerCase()), t?.name === "return") {
35204
+ if (this.opts.validate) {
35205
+ const F = this.opts.validate(this.value);
35206
+ F && (this.error = F instanceof Error ? F.message : F, this.state = "error", this.rl?.write(this.value));
35207
+ }
35208
+ this.state !== "error" && (this.state = "submit");
35209
+ }
35210
+ $([u, t?.name, t?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
35211
+ }
35212
+ close() {
35213
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
35214
+ `), m(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
35215
+ }
35216
+ restoreCursor() {
35217
+ const u = Y(this._prevFrame, process.stdout.columns, { hard: true }).split(`
35218
+ `).length - 1;
35219
+ this.output.write(import_sisteransi.cursor.move(-999, u * -1));
35220
+ }
35221
+ render() {
35222
+ const u = Y(this._render(this) ?? "", process.stdout.columns, { hard: true });
35223
+ if (u !== this._prevFrame) {
35224
+ if (this.state === "initial")
35225
+ this.output.write(import_sisteransi.cursor.hide);
35226
+ else {
35227
+ const t = BD(this._prevFrame, u);
35228
+ if (this.restoreCursor(), t && t?.length === 1) {
35229
+ const F = t[0];
35230
+ this.output.write(import_sisteransi.cursor.move(0, F)), this.output.write(import_sisteransi.erase.lines(1));
35231
+ const s = u.split(`
35232
+ `);
35233
+ this.output.write(s[F]), this._prevFrame = u, this.output.write(import_sisteransi.cursor.move(0, s.length - F - 1));
35234
+ return;
35235
+ }
35236
+ if (t && t?.length > 1) {
35237
+ const F = t[0];
35238
+ this.output.write(import_sisteransi.cursor.move(0, F)), this.output.write(import_sisteransi.erase.down());
35239
+ const s = u.split(`
35240
+ `).slice(F);
35241
+ this.output.write(s.join(`
35242
+ `)), this._prevFrame = u;
35243
+ return;
35244
+ }
35245
+ this.output.write(import_sisteransi.erase.down());
35246
+ }
35247
+ this.output.write(u), this.state === "initial" && (this.state = "active"), this._prevFrame = u;
35248
+ }
35016
35249
  }
35017
- return backupPath;
35018
35250
  }
35019
35251
 
35020
- // src/lib/agents-unifier.ts
35021
- var IGNORED_ENTRY_NAMES2 = new Set([
35022
- ".DS_Store",
35023
- ".git",
35024
- "node_modules"
35025
- ]);
35026
- function uniqueByPath(candidates) {
35027
- const seen = new Set;
35028
- const unique = [];
35029
- for (const candidate of candidates) {
35030
- const resolved = path17.resolve(candidate.path);
35031
- if (seen.has(resolved))
35032
- continue;
35033
- seen.add(resolved);
35034
- unique.push({ ...candidate, path: resolved });
35252
+ class dD extends x {
35253
+ get cursor() {
35254
+ return this.value ? 0 : 1;
35255
+ }
35256
+ get _value() {
35257
+ return this.cursor === 0;
35258
+ }
35259
+ constructor(u) {
35260
+ super(u, false), this.value = !!u.initialValue, this.on("value", () => {
35261
+ this.value = this._value;
35262
+ }), this.on("confirm", (t) => {
35263
+ this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = t, this.state = "submit", this.close();
35264
+ }), this.on("cursor", () => {
35265
+ this.value = !this.value;
35266
+ });
35035
35267
  }
35036
- return unique;
35037
35268
  }
35038
- function getContainerCandidates(options, includeCodex = true) {
35039
- const folders = resolveFolders(options);
35040
- const cursorDir = path17.join(folders.rootDir, ".cursor");
35041
- const factoryDir = path17.join(folders.rootDir, ".factory");
35042
- const opencodeDir = path17.join(folders.rootDir, ".config", "opencode");
35043
- return uniqueByPath([
35044
- {
35045
- category: "skills",
35046
- label: "agents-skills",
35047
- path: path17.join(folders.agentsDir, "skills"),
35048
- isDestination: true
35049
- },
35050
- {
35051
- category: "skills",
35052
- label: "claude-skills",
35053
- path: path17.join(folders.claudeDir, "skills"),
35054
- linkWhenMissing: true
35055
- },
35056
- ...includeCodex ? [{
35057
- category: "skills",
35058
- label: "codex-skills",
35059
- path: path17.join(folders.codexDir, "skills"),
35060
- linkWhenMissing: true
35061
- }] : [],
35062
- {
35063
- category: "skills",
35064
- label: "cursor-skills",
35065
- path: path17.join(cursorDir, "skills"),
35066
- linkWhenParentExists: true
35067
- },
35068
- {
35069
- category: "skills",
35070
- label: "cursor-skills-cursor",
35071
- path: path17.join(cursorDir, "skills-cursor"),
35072
- linkWhenParentExists: true
35073
- },
35074
- {
35075
- category: "skills",
35076
- label: "factory-skills",
35077
- path: path17.join(factoryDir, "skills"),
35078
- linkWhenParentExists: true
35079
- },
35080
- {
35081
- category: "skills",
35082
- label: "opencode-skill",
35083
- path: path17.join(opencodeDir, "skill"),
35084
- linkWhenParentExists: true
35085
- },
35086
- {
35087
- category: "skills",
35088
- label: "opencode-skills",
35089
- path: path17.join(opencodeDir, "skills"),
35090
- linkWhenParentExists: true
35091
- },
35092
- {
35093
- category: "agents",
35094
- label: "agents-agents",
35095
- path: path17.join(folders.agentsDir, "agents"),
35096
- isDestination: true
35097
- },
35098
- {
35099
- category: "agents",
35100
- label: "claude-agents",
35101
- path: path17.join(folders.claudeDir, "agents"),
35102
- linkWhenMissing: true
35103
- },
35104
- {
35105
- category: "agents",
35106
- label: "claude-agnets",
35107
- path: path17.join(folders.claudeDir, "agnets")
35108
- },
35109
- {
35110
- category: "agents",
35111
- label: "cursor-agents",
35112
- path: path17.join(cursorDir, "agents"),
35113
- linkWhenParentExists: true
35114
- },
35115
- {
35116
- category: "agents",
35117
- label: "factory-droids",
35118
- path: path17.join(factoryDir, "droids"),
35119
- linkWhenParentExists: true
35120
- },
35121
- {
35122
- category: "agents",
35123
- label: "opencode-agent",
35124
- path: path17.join(opencodeDir, "agent"),
35125
- linkWhenParentExists: true
35126
- },
35127
- {
35128
- category: "agents",
35129
- label: "opencode-agents",
35130
- path: path17.join(opencodeDir, "agents"),
35131
- linkWhenParentExists: true
35132
- }
35133
- ]);
35134
- }
35135
- function getInstructionFileCandidates(options, includeCodex = true) {
35136
- const folders = resolveFolders(options);
35137
- return uniqueByPath([
35138
- {
35139
- label: "agents-instructions",
35140
- path: path17.join(folders.agentsDir, "AGENTS.md"),
35141
- isDestination: true
35142
- },
35143
- {
35144
- label: "claude-instructions",
35145
- path: path17.join(folders.claudeDir, "CLAUDE.md"),
35146
- linkWhenMissing: true
35147
- },
35148
- ...includeCodex ? [{
35149
- label: "codex-instructions",
35150
- path: path17.join(folders.codexDir, "AGENTS.md"),
35151
- linkWhenMissing: true
35152
- }] : []
35153
- ]);
35154
- }
35155
- function getRepositoryContainerCandidates(options) {
35156
- const folders = resolveFolders(options);
35157
- const cursorDir = path17.join(folders.rootDir, ".cursor");
35158
- return uniqueByPath([
35159
- ...getContainerCandidates(options, false),
35160
- {
35161
- category: "rules",
35162
- label: "agents-rules",
35163
- path: path17.join(folders.agentsDir, "rules"),
35164
- isDestination: true
35165
- },
35166
- {
35167
- category: "rules",
35168
- label: "claude-rules",
35169
- path: path17.join(folders.claudeDir, "rules"),
35170
- linkWhenMissing: true
35171
- },
35172
- {
35173
- category: "rules",
35174
- label: "cursor-rules",
35175
- path: path17.join(cursorDir, "rules"),
35176
- linkWhenParentExists: true
35177
- },
35178
- {
35179
- category: "rules",
35180
- label: "claude-memories",
35181
- path: path17.join(folders.claudeDir, "memories"),
35182
- linkSource: false
35183
- },
35184
- {
35185
- category: "rules",
35186
- label: "cursor-memories",
35187
- path: path17.join(cursorDir, "memories"),
35188
- linkSource: false
35189
- },
35190
- {
35191
- category: "rules",
35192
- label: "claude-memory",
35193
- path: path17.join(folders.claudeDir, "memory.md"),
35194
- linkSource: false
35195
- },
35196
- {
35197
- category: "rules",
35198
- label: "cursor-memory",
35199
- path: path17.join(cursorDir, "memory.md"),
35200
- linkSource: false
35201
- },
35202
- {
35203
- category: "rules",
35204
- label: "claude-memory-uppercase",
35205
- path: path17.join(folders.claudeDir, "MEMORY.md"),
35206
- linkSource: false
35207
- },
35208
- {
35209
- category: "rules",
35210
- label: "cursor-memory-uppercase",
35211
- path: path17.join(cursorDir, "MEMORY.md"),
35212
- linkSource: false
35213
- }
35214
- ]);
35215
- }
35216
- async function pathExistsOrSymlink(targetPath) {
35217
- const stat = await import_fs_extra13.default.lstat(targetPath).catch(() => null);
35218
- return Boolean(stat);
35219
- }
35220
- async function realPathIfPossible(targetPath) {
35221
- try {
35222
- return await import_fs_extra13.default.realpath(targetPath);
35223
- } catch {
35224
- return null;
35225
- }
35226
- }
35227
- function samePath(a, b) {
35228
- return path17.resolve(a) === path17.resolve(b);
35229
- }
35230
- function hashString(value) {
35231
- return crypto.createHash("sha256").update(value).digest("hex");
35232
- }
35233
- async function hashPath(targetPath) {
35234
- const stat = await import_fs_extra13.default.lstat(targetPath);
35235
- if (stat.isSymbolicLink()) {
35236
- const linkTarget = await import_fs_extra13.default.readlink(targetPath);
35237
- return hashString(`symlink:${linkTarget}`);
35238
- }
35239
- if (stat.isFile()) {
35240
- const fileHash = crypto.createHash("sha256");
35241
- fileHash.update("file:");
35242
- fileHash.update(await import_fs_extra13.default.readFile(targetPath));
35243
- return fileHash.digest("hex");
35244
- }
35245
- if (stat.isDirectory()) {
35246
- const entries = (await import_fs_extra13.default.readdir(targetPath, { withFileTypes: true })).filter((entry) => !IGNORED_ENTRY_NAMES2.has(entry.name)).sort((a, b) => a.name.localeCompare(b.name));
35247
- const dirHash = crypto.createHash("sha256");
35248
- dirHash.update("dir:");
35249
- for (const entry of entries) {
35250
- dirHash.update(entry.name);
35251
- dirHash.update("\x00");
35252
- dirHash.update(await hashPath(path17.join(targetPath, entry.name)));
35253
- dirHash.update("\x00");
35254
- }
35255
- return dirHash.digest("hex");
35256
- }
35257
- return hashString(`other:${stat.mode}:${stat.size}`);
35258
- }
35259
- var TEXT_EXTENSIONS = new Set([
35260
- ".cjs",
35261
- ".js",
35262
- ".json",
35263
- ".jsonc",
35264
- ".md",
35265
- ".mdc",
35266
- ".mjs",
35267
- ".sh",
35268
- ".toml",
35269
- ".ts",
35270
- ".tsx",
35271
- ".txt",
35272
- ".yaml",
35273
- ".yml"
35274
- ]);
35275
- var PORTABLE_PATH_REPLACEMENTS = [
35276
- [/\.claude\/skills/g, ".agents/skills"],
35277
- [/\.codex\/skills/g, ".agents/skills"],
35278
- [/\.cursor\/skills-cursor/g, ".agents/skills"],
35279
- [/\.cursor\/skills/g, ".agents/skills"],
35280
- [/\.claude\/agents/g, ".agents/agents"],
35281
- [/\.codex\/agents/g, ".agents/agents"],
35282
- [/\.cursor\/agents/g, ".agents/agents"],
35283
- [/\.claude\/rules/g, ".agents/rules"],
35284
- [/\.codex\/rules/g, ".agents/rules"],
35285
- [/\.cursor\/rules/g, ".agents/rules"],
35286
- [/\.claude\/memories/g, ".agents/rules"],
35287
- [/\.codex\/memories/g, ".agents/rules"],
35288
- [/\.cursor\/memories/g, ".agents/rules"]
35289
- ];
35290
- function normalizePortableText(content) {
35291
- let normalized = content;
35292
- for (const [pattern, replacement] of PORTABLE_PATH_REPLACEMENTS) {
35293
- normalized = normalized.replace(pattern, replacement);
35294
- }
35295
- return normalized;
35296
- }
35297
- function isLikelyTextFile(filePath) {
35298
- const ext = path17.extname(filePath).toLowerCase();
35299
- if (TEXT_EXTENSIONS.has(ext))
35300
- return true;
35301
- return path17.basename(filePath) === "SKILL.md";
35302
- }
35303
- async function normalizePortableContent(targetPath) {
35304
- const stat = await import_fs_extra13.default.lstat(targetPath).catch(() => null);
35305
- if (!stat || stat.isSymbolicLink())
35306
- return;
35307
- if (stat.isDirectory()) {
35308
- const entries = await import_fs_extra13.default.readdir(targetPath);
35309
- for (const entry of entries) {
35310
- if (IGNORED_ENTRY_NAMES2.has(entry))
35311
- continue;
35312
- await normalizePortableContent(path17.join(targetPath, entry));
35313
- }
35314
- return;
35315
- }
35316
- if (!stat.isFile() || !isLikelyTextFile(targetPath))
35317
- return;
35318
- const content = await import_fs_extra13.default.readFile(targetPath, "utf-8").catch(() => null);
35319
- if (content === null || content.includes("\x00"))
35320
- return;
35321
- const normalized = normalizePortableText(content);
35322
- if (normalized !== content) {
35323
- await import_fs_extra13.default.writeFile(targetPath, normalized, "utf-8");
35324
- }
35325
- }
35326
- function suffixFromLabel(label) {
35327
- return label.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "source";
35328
- }
35329
- function nameWithSuffix(name, suffix, index) {
35330
- const parsed = path17.parse(name);
35331
- const numberedSuffix = index === 1 ? suffix : `${suffix}-${index}`;
35332
- if (parsed.ext && parsed.name) {
35333
- return `${parsed.name}--${numberedSuffix}${parsed.ext}`;
35334
- }
35335
- return `${name}--${numberedSuffix}`;
35336
- }
35337
- async function findTargetName(destinationDir, originalName, label) {
35338
- const suffix = suffixFromLabel(label);
35339
- let index = 1;
35340
- while (true) {
35341
- const candidate = nameWithSuffix(originalName, suffix, index);
35342
- if (!await pathExistsOrSymlink(path17.join(destinationDir, candidate))) {
35343
- return candidate;
35344
- }
35345
- index++;
35346
- }
35347
- }
35348
- async function addExistingDestinationHashes(destinationDir, knownHashes) {
35349
- if (!await import_fs_extra13.default.pathExists(destinationDir))
35350
- return;
35351
- const entries = await import_fs_extra13.default.readdir(destinationDir, { withFileTypes: true });
35352
- for (const entry of entries) {
35353
- if (IGNORED_ENTRY_NAMES2.has(entry.name))
35354
- continue;
35355
- const entryPath = path17.join(destinationDir, entry.name);
35356
- knownHashes.set(await hashPath(entryPath), entry.name);
35357
- }
35358
- }
35359
- async function importCategoryEntries(category, candidates, destinationDir, result) {
35360
- const sourceEntries = [];
35361
- const destinationExists = await pathExistsOrSymlink(destinationDir);
35362
- const destinationRealPath = destinationExists ? await realPathIfPossible(destinationDir) : null;
35363
- for (const candidate of candidates) {
35364
- if (candidate.category !== category || candidate.isDestination)
35365
- continue;
35366
- const candidateStat = await import_fs_extra13.default.lstat(candidate.path).catch(() => null);
35367
- if (!candidateStat)
35368
- continue;
35369
- const candidateRealPath = await realPathIfPossible(candidate.path);
35370
- if (destinationRealPath && candidateRealPath && samePath(destinationRealPath, candidateRealPath)) {
35371
- continue;
35372
- }
35373
- const entries = await collectCandidateEntries(candidate).catch(() => null);
35374
- if (!entries) {
35375
- result.skipped.push({
35376
- category,
35377
- path: candidate.path,
35378
- reason: "Could not read directory"
35379
- });
35380
- continue;
35381
- }
35382
- const collectableEntries = [];
35383
- for (const entry of entries) {
35384
- if (!await shouldCollectPath(category, entry.name, entry.path))
35385
- continue;
35386
- collectableEntries.push(entry);
35387
- }
35388
- if (collectableEntries.length > 0) {
35389
- sourceEntries.push({ candidate, entries: collectableEntries });
35390
- }
35391
- }
35392
- if (!destinationExists && sourceEntries.length === 0) {
35393
- return false;
35394
- }
35395
- await import_fs_extra13.default.ensureDir(destinationDir);
35396
- const knownHashes = new Map;
35397
- await addExistingDestinationHashes(destinationDir, knownHashes);
35398
- for (const { candidate, entries } of sourceEntries) {
35399
- for (const entry of entries) {
35400
- const sourcePath = entry.path;
35401
- const sourceHash = await hashPath(sourcePath);
35402
- const existingName = knownHashes.get(sourceHash);
35403
- if (existingName) {
35404
- result.duplicates.push({
35405
- category,
35406
- name: entry.name,
35407
- from: sourcePath,
35408
- keptAs: path17.join(destinationDir, existingName)
35409
- });
35410
- continue;
35411
- }
35412
- let targetName = entry.name;
35413
- let targetPath = path17.join(destinationDir, targetName);
35414
- if (await pathExistsOrSymlink(targetPath)) {
35415
- targetName = await findTargetName(destinationDir, entry.name, candidate.label);
35416
- targetPath = path17.join(destinationDir, targetName);
35417
- result.renamed.push({
35418
- category,
35419
- name: entry.name,
35420
- from: sourcePath,
35421
- to: targetPath,
35422
- reason: "Same name with different content"
35423
- });
35269
+ var A;
35270
+ A = new WeakMap;
35271
+ var kD = Object.defineProperty;
35272
+ var $D = (e, u, t) => (u in e) ? kD(e, u, { enumerable: true, configurable: true, writable: true, value: t }) : e[u] = t;
35273
+ var H = (e, u, t) => ($D(e, typeof u != "symbol" ? u + "" : u, t), t);
35274
+ var SD = class extends x {
35275
+ constructor(u) {
35276
+ super(u, false), H(this, "options"), H(this, "cursor", 0), this.options = u.options, this.value = [...u.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: t }) => t === u.cursorAt), 0), this.on("key", (t) => {
35277
+ t === "a" && this.toggleAll();
35278
+ }), this.on("cursor", (t) => {
35279
+ switch (t) {
35280
+ case "left":
35281
+ case "up":
35282
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
35283
+ break;
35284
+ case "down":
35285
+ case "right":
35286
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
35287
+ break;
35288
+ case "space":
35289
+ this.toggleValue();
35290
+ break;
35424
35291
  }
35425
- await import_fs_extra13.default.copy(sourcePath, targetPath, {
35426
- dereference: false,
35427
- overwrite: false
35428
- });
35429
- await normalizePortableContent(targetPath);
35430
- knownHashes.set(await hashPath(targetPath), targetName);
35431
- result.imported.push({
35432
- category,
35433
- name: entry.name,
35434
- from: sourcePath,
35435
- to: targetPath
35436
- });
35437
- }
35438
- }
35439
- return true;
35440
- }
35441
- async function collectCandidateEntries(candidate) {
35442
- const stat = await import_fs_extra13.default.lstat(candidate.path);
35443
- if (stat.isDirectory()) {
35444
- const entries = await import_fs_extra13.default.readdir(candidate.path, { withFileTypes: true });
35445
- return entries.map((entry) => ({
35446
- name: entry.name,
35447
- path: path17.join(candidate.path, entry.name)
35448
- }));
35449
- }
35450
- if (stat.isSymbolicLink()) {
35451
- const targetStat = await import_fs_extra13.default.stat(candidate.path).catch(() => null);
35452
- if (targetStat?.isDirectory()) {
35453
- const entries = await import_fs_extra13.default.readdir(candidate.path, { withFileTypes: true });
35454
- return entries.map((entry) => ({
35455
- name: entry.name,
35456
- path: path17.join(candidate.path, entry.name)
35457
- }));
35458
- }
35459
- }
35460
- return [{
35461
- name: path17.basename(candidate.path),
35462
- path: candidate.path
35463
- }];
35464
- }
35465
- async function shouldCollectPath(category, name, sourcePath) {
35466
- if (IGNORED_ENTRY_NAMES2.has(name))
35467
- return false;
35468
- if (category === "skills" && name === ".cursor-managed-skills-manifest.json") {
35469
- return true;
35470
- }
35471
- const stat = await import_fs_extra13.default.lstat(sourcePath).catch(() => null);
35472
- if (!stat)
35473
- return false;
35474
- return stat.isFile() || stat.isDirectory() || stat.isSymbolicLink();
35475
- }
35476
- function safeRelativePath(rootDir, targetPath) {
35477
- const relativePath = path17.relative(rootDir, targetPath);
35478
- if (!relativePath || relativePath.startsWith("..") || path17.isAbsolute(relativePath)) {
35479
- return path17.join("external", targetPath.replace(/[^a-zA-Z0-9._-]+/g, "-"));
35480
- }
35481
- return relativePath;
35482
- }
35483
- function createBackupPath(rootDir) {
35484
- const projectKey = createBackupNameSuffix(path17.resolve(rootDir));
35485
- return path17.join(getBackupDir(), createTimestampedBackupName(`project-${projectKey}-agents-unify-sources`));
35486
- }
35487
- async function ensureBackupPath(result) {
35488
- if (!result.backupPath) {
35489
- result.backupPath = createBackupPath(result.rootDir);
35490
- await import_fs_extra13.default.ensureDir(result.backupPath);
35491
- }
35492
- return result.backupPath;
35493
- }
35494
- async function createDirectorySymlink(source, target) {
35495
- await import_fs_extra13.default.ensureDir(path17.dirname(target));
35496
- if (os14.platform() === "win32") {
35497
- await import_fs_extra13.default.symlink(source, target, "junction");
35498
- return;
35499
- }
35500
- await import_fs_extra13.default.symlink(source, target, "dir");
35501
- }
35502
- async function createFileSymlink(source, target) {
35503
- await import_fs_extra13.default.ensureDir(path17.dirname(target));
35504
- if (os14.platform() === "win32") {
35505
- await import_fs_extra13.default.symlink(source, target, "file");
35506
- return;
35507
- }
35508
- await import_fs_extra13.default.symlink(source, target);
35509
- }
35510
- async function shouldLinkMissingContainer(candidate) {
35511
- if (candidate.linkWhenMissing)
35512
- return true;
35513
- if (!candidate.linkWhenParentExists)
35514
- return false;
35515
- return import_fs_extra13.default.pathExists(path17.dirname(candidate.path));
35516
- }
35517
- async function linkContainer(candidate, destinationDir, result) {
35518
- if (candidate.linkSource === false) {
35519
- return;
35520
- }
35521
- if (candidate.isDestination || samePath(candidate.path, destinationDir)) {
35522
- return;
35523
- }
35524
- const destinationRealPath = await realPathIfPossible(destinationDir);
35525
- const stat = await import_fs_extra13.default.lstat(candidate.path).catch(() => null);
35526
- if (!stat) {
35527
- if (!await shouldLinkMissingContainer(candidate))
35528
- return;
35529
- await createDirectorySymlink(destinationDir, candidate.path);
35530
- result.linked.push({
35531
- category: candidate.category,
35532
- from: candidate.path,
35533
- to: destinationDir
35534
35292
  });
35535
- return;
35536
35293
  }
35537
- if (stat.isSymbolicLink()) {
35538
- const existingRealPath = await realPathIfPossible(candidate.path);
35539
- if (destinationRealPath && existingRealPath && samePath(destinationRealPath, existingRealPath)) {
35540
- result.alreadyLinked.push({
35541
- category: candidate.category,
35542
- from: candidate.path,
35543
- to: destinationDir
35544
- });
35545
- return;
35546
- }
35547
- await import_fs_extra13.default.remove(candidate.path);
35548
- await createDirectorySymlink(destinationDir, candidate.path);
35549
- result.linked.push({
35550
- category: candidate.category,
35551
- from: candidate.path,
35552
- to: destinationDir
35553
- });
35554
- return;
35294
+ get _value() {
35295
+ return this.options[this.cursor].value;
35555
35296
  }
35556
- const backupRoot = await ensureBackupPath(result);
35557
- const backupTarget = path17.join(backupRoot, safeRelativePath(result.rootDir, candidate.path));
35558
- await import_fs_extra13.default.ensureDir(path17.dirname(backupTarget));
35559
- await import_fs_extra13.default.move(candidate.path, backupTarget, { overwrite: false });
35560
- await createDirectorySymlink(destinationDir, candidate.path);
35561
- result.linked.push({
35562
- category: candidate.category,
35563
- from: candidate.path,
35564
- to: destinationDir,
35565
- movedToBackup: backupTarget
35566
- });
35567
- }
35568
- async function importInstructionFiles(candidates, destinationPath, result) {
35569
- const destinationExists = await pathExistsOrSymlink(destinationPath);
35570
- const destinationRealPath = destinationExists ? await realPathIfPossible(destinationPath) : null;
35571
- const sourceCandidates = [];
35572
- for (const candidate of candidates) {
35573
- if (candidate.isDestination)
35574
- continue;
35575
- const sourceStat = await import_fs_extra13.default.lstat(candidate.path).catch(() => null);
35576
- if (!sourceStat)
35577
- continue;
35578
- const sourceRealPath = await realPathIfPossible(candidate.path);
35579
- if (destinationRealPath && sourceRealPath && samePath(destinationRealPath, sourceRealPath)) {
35580
- continue;
35581
- }
35582
- sourceCandidates.push(candidate);
35297
+ toggleAll() {
35298
+ const u = this.value.length === this.options.length;
35299
+ this.value = u ? [] : this.options.map((t) => t.value);
35583
35300
  }
35584
- if (!destinationExists && sourceCandidates.length === 0) {
35585
- return false;
35301
+ toggleValue() {
35302
+ const u = this.value.includes(this._value);
35303
+ this.value = u ? this.value.filter((t) => t !== this._value) : [...this.value, this._value];
35586
35304
  }
35587
- await import_fs_extra13.default.ensureDir(path17.dirname(destinationPath));
35588
- let destinationHash = destinationExists ? await hashPath(destinationPath) : null;
35589
- for (const candidate of sourceCandidates) {
35590
- const sourceHash = await hashPath(candidate.path);
35591
- if (!destinationHash) {
35592
- await import_fs_extra13.default.copy(candidate.path, destinationPath, {
35593
- dereference: false,
35594
- overwrite: false
35595
- });
35596
- destinationHash = sourceHash;
35597
- result.imported.push({
35598
- category: "instructions",
35599
- name: path17.basename(candidate.path),
35600
- from: candidate.path,
35601
- to: destinationPath
35602
- });
35603
- continue;
35604
- }
35605
- if (sourceHash === destinationHash) {
35606
- result.duplicates.push({
35607
- category: "instructions",
35608
- name: path17.basename(candidate.path),
35609
- from: candidate.path,
35610
- keptAs: destinationPath
35611
- });
35612
- continue;
35613
- }
35614
- const targetName = await findTargetName(path17.dirname(destinationPath), path17.basename(destinationPath), candidate.label);
35615
- const targetPath = path17.join(path17.dirname(destinationPath), targetName);
35616
- await import_fs_extra13.default.copy(candidate.path, targetPath, {
35617
- dereference: false,
35618
- overwrite: false
35305
+ };
35306
+ var OD = Object.defineProperty;
35307
+ var PD = (e, u, t) => (u in e) ? OD(e, u, { enumerable: true, configurable: true, writable: true, value: t }) : e[u] = t;
35308
+ var J = (e, u, t) => (PD(e, typeof u != "symbol" ? u + "" : u, t), t);
35309
+
35310
+ class LD extends x {
35311
+ constructor(u) {
35312
+ super(u, false), J(this, "options"), J(this, "cursor", 0), this.options = u.options, this.cursor = this.options.findIndex(({ value: t }) => t === u.initialValue), this.cursor === -1 && (this.cursor = 0), this.changeValue(), this.on("cursor", (t) => {
35313
+ switch (t) {
35314
+ case "left":
35315
+ case "up":
35316
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
35317
+ break;
35318
+ case "down":
35319
+ case "right":
35320
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
35321
+ break;
35322
+ }
35323
+ this.changeValue();
35619
35324
  });
35620
- result.renamed.push({
35621
- category: "instructions",
35622
- name: path17.basename(candidate.path),
35623
- from: candidate.path,
35624
- to: targetPath,
35625
- reason: "Shared instruction file already exists with different content"
35325
+ }
35326
+ get _value() {
35327
+ return this.options[this.cursor];
35328
+ }
35329
+ changeValue() {
35330
+ this.value = this._value.value;
35331
+ }
35332
+ }
35333
+ class RD extends x {
35334
+ get valueWithCursor() {
35335
+ if (this.state === "submit")
35336
+ return this.value;
35337
+ if (this.cursor >= this.value.length)
35338
+ return `${this.value}█`;
35339
+ const u = this.value.slice(0, this.cursor), [t, ...F] = this.value.slice(this.cursor);
35340
+ return `${u}${import_picocolors.default.inverse(t)}${F.join("")}`;
35341
+ }
35342
+ get cursor() {
35343
+ return this._cursor;
35344
+ }
35345
+ constructor(u) {
35346
+ super(u), this.on("finalize", () => {
35347
+ this.value || (this.value = u.defaultValue);
35626
35348
  });
35627
35349
  }
35628
- return true;
35629
35350
  }
35630
- async function shouldLinkMissingInstruction(candidate) {
35631
- if (candidate.linkWhenMissing)
35632
- return true;
35633
- return false;
35351
+
35352
+ // node_modules/@clack/prompts/dist/index.mjs
35353
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
35354
+ var import_sisteransi2 = __toESM(require_src(), 1);
35355
+ import y2 from "node:process";
35356
+ function ce() {
35357
+ return y2.platform !== "win32" ? y2.env.TERM !== "linux" : !!y2.env.CI || !!y2.env.WT_SESSION || !!y2.env.TERMINUS_SUBLIME || y2.env.ConEmuTask === "{cmd::Cmder}" || y2.env.TERM_PROGRAM === "Terminus-Sublime" || y2.env.TERM_PROGRAM === "vscode" || y2.env.TERM === "xterm-256color" || y2.env.TERM === "alacritty" || y2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
35634
35358
  }
35635
- async function linkInstructionFile(candidate, destinationPath, result) {
35636
- if (candidate.isDestination || samePath(candidate.path, destinationPath)) {
35637
- return;
35359
+ var V2 = ce();
35360
+ var u = (t, n) => V2 ? t : n;
35361
+ var le = u("◆", "*");
35362
+ var L2 = u("■", "x");
35363
+ var W2 = u("▲", "x");
35364
+ var C = u("◇", "o");
35365
+ var ue = u("┌", "T");
35366
+ var o = u("│", "|");
35367
+ var d2 = u("└", "—");
35368
+ var k2 = u("●", ">");
35369
+ var P2 = u("○", " ");
35370
+ var A2 = u("◻", "[•]");
35371
+ var T = u("◼", "[+]");
35372
+ var F = u("◻", "[ ]");
35373
+ var $e = u("▪", "•");
35374
+ var _3 = u("─", "-");
35375
+ var me = u("╮", "+");
35376
+ var de = u("├", "+");
35377
+ var pe = u("╯", "+");
35378
+ var q = u("●", "•");
35379
+ var D = u("◆", "*");
35380
+ var U = u("▲", "!");
35381
+ var K2 = u("■", "x");
35382
+ var b2 = (t) => {
35383
+ switch (t) {
35384
+ case "initial":
35385
+ case "active":
35386
+ return import_picocolors2.default.cyan(le);
35387
+ case "cancel":
35388
+ return import_picocolors2.default.red(L2);
35389
+ case "error":
35390
+ return import_picocolors2.default.yellow(W2);
35391
+ case "submit":
35392
+ return import_picocolors2.default.green(C);
35638
35393
  }
35639
- if (!await pathExistsOrSymlink(destinationPath)) {
35640
- return;
35394
+ };
35395
+ var G2 = (t) => {
35396
+ const { cursor: n, options: r2, style: i } = t, s = t.maxItems ?? Number.POSITIVE_INFINITY, c = Math.max(process.stdout.rows - 4, 0), a = Math.min(c, Math.max(s, 5));
35397
+ let l2 = 0;
35398
+ n >= l2 + a - 3 ? l2 = Math.max(Math.min(n - a + 3, r2.length - a), 0) : n < l2 + 2 && (l2 = Math.max(n - 2, 0));
35399
+ const $2 = a < r2.length && l2 > 0, g2 = a < r2.length && l2 + a < r2.length;
35400
+ return r2.slice(l2, l2 + a).map((p2, v2, f) => {
35401
+ const j2 = v2 === 0 && $2, E = v2 === f.length - 1 && g2;
35402
+ return j2 || E ? import_picocolors2.default.dim("...") : i(p2, v2 + l2 === n);
35403
+ });
35404
+ };
35405
+ var he = (t) => new RD({ validate: t.validate, placeholder: t.placeholder, defaultValue: t.defaultValue, initialValue: t.initialValue, render() {
35406
+ const n = `${import_picocolors2.default.gray(o)}
35407
+ ${b2(this.state)} ${t.message}
35408
+ `, r2 = t.placeholder ? import_picocolors2.default.inverse(t.placeholder[0]) + import_picocolors2.default.dim(t.placeholder.slice(1)) : import_picocolors2.default.inverse(import_picocolors2.default.hidden("_")), i = this.value ? this.valueWithCursor : r2;
35409
+ switch (this.state) {
35410
+ case "error":
35411
+ return `${n.trim()}
35412
+ ${import_picocolors2.default.yellow(o)} ${i}
35413
+ ${import_picocolors2.default.yellow(d2)} ${import_picocolors2.default.yellow(this.error)}
35414
+ `;
35415
+ case "submit":
35416
+ return `${n}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.dim(this.value || t.placeholder)}`;
35417
+ case "cancel":
35418
+ return `${n}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(this.value ?? ""))}${this.value?.trim() ? `
35419
+ ${import_picocolors2.default.gray(o)}` : ""}`;
35420
+ default:
35421
+ return `${n}${import_picocolors2.default.cyan(o)} ${i}
35422
+ ${import_picocolors2.default.cyan(d2)}
35423
+ `;
35641
35424
  }
35642
- const destinationRealPath = await realPathIfPossible(destinationPath);
35643
- const stat = await import_fs_extra13.default.lstat(candidate.path).catch(() => null);
35644
- if (!stat) {
35645
- if (!await shouldLinkMissingInstruction(candidate))
35646
- return;
35647
- await createFileSymlink(destinationPath, candidate.path);
35648
- result.linked.push({
35649
- category: "instructions",
35650
- from: candidate.path,
35651
- to: destinationPath
35652
- });
35653
- return;
35425
+ } }).prompt();
35426
+ var ye = (t) => {
35427
+ const n = t.active ?? "Yes", r2 = t.inactive ?? "No";
35428
+ return new dD({ active: n, inactive: r2, initialValue: t.initialValue ?? true, render() {
35429
+ const i = `${import_picocolors2.default.gray(o)}
35430
+ ${b2(this.state)} ${t.message}
35431
+ `, s = this.value ? n : r2;
35432
+ switch (this.state) {
35433
+ case "submit":
35434
+ return `${i}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.dim(s)}`;
35435
+ case "cancel":
35436
+ return `${i}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(s))}
35437
+ ${import_picocolors2.default.gray(o)}`;
35438
+ default:
35439
+ return `${i}${import_picocolors2.default.cyan(o)} ${this.value ? `${import_picocolors2.default.green(k2)} ${n}` : `${import_picocolors2.default.dim(P2)} ${import_picocolors2.default.dim(n)}`} ${import_picocolors2.default.dim("/")} ${this.value ? `${import_picocolors2.default.dim(P2)} ${import_picocolors2.default.dim(r2)}` : `${import_picocolors2.default.green(k2)} ${r2}`}
35440
+ ${import_picocolors2.default.cyan(d2)}
35441
+ `;
35442
+ }
35443
+ } }).prompt();
35444
+ };
35445
+ var ve = (t) => {
35446
+ const n = (r2, i) => {
35447
+ const s = r2.label ?? String(r2.value);
35448
+ switch (i) {
35449
+ case "selected":
35450
+ return `${import_picocolors2.default.dim(s)}`;
35451
+ case "active":
35452
+ return `${import_picocolors2.default.green(k2)} ${s} ${r2.hint ? import_picocolors2.default.dim(`(${r2.hint})`) : ""}`;
35453
+ case "cancelled":
35454
+ return `${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(s))}`;
35455
+ default:
35456
+ return `${import_picocolors2.default.dim(P2)} ${import_picocolors2.default.dim(s)}`;
35457
+ }
35458
+ };
35459
+ return new LD({ options: t.options, initialValue: t.initialValue, render() {
35460
+ const r2 = `${import_picocolors2.default.gray(o)}
35461
+ ${b2(this.state)} ${t.message}
35462
+ `;
35463
+ switch (this.state) {
35464
+ case "submit":
35465
+ return `${r2}${import_picocolors2.default.gray(o)} ${n(this.options[this.cursor], "selected")}`;
35466
+ case "cancel":
35467
+ return `${r2}${import_picocolors2.default.gray(o)} ${n(this.options[this.cursor], "cancelled")}
35468
+ ${import_picocolors2.default.gray(o)}`;
35469
+ default:
35470
+ return `${r2}${import_picocolors2.default.cyan(o)} ${G2({ cursor: this.cursor, options: this.options, maxItems: t.maxItems, style: (i, s) => n(i, s ? "active" : "inactive") }).join(`
35471
+ ${import_picocolors2.default.cyan(o)} `)}
35472
+ ${import_picocolors2.default.cyan(d2)}
35473
+ `;
35474
+ }
35475
+ } }).prompt();
35476
+ };
35477
+ var fe = (t) => {
35478
+ const n = (r2, i) => {
35479
+ const s = r2.label ?? String(r2.value);
35480
+ return i === "active" ? `${import_picocolors2.default.cyan(A2)} ${s} ${r2.hint ? import_picocolors2.default.dim(`(${r2.hint})`) : ""}` : i === "selected" ? `${import_picocolors2.default.green(T)} ${import_picocolors2.default.dim(s)} ${r2.hint ? import_picocolors2.default.dim(`(${r2.hint})`) : ""}` : i === "cancelled" ? `${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(s))}` : i === "active-selected" ? `${import_picocolors2.default.green(T)} ${s} ${r2.hint ? import_picocolors2.default.dim(`(${r2.hint})`) : ""}` : i === "submitted" ? `${import_picocolors2.default.dim(s)}` : `${import_picocolors2.default.dim(F)} ${import_picocolors2.default.dim(s)}`;
35481
+ };
35482
+ return new SD({ options: t.options, initialValues: t.initialValues, required: t.required ?? true, cursorAt: t.cursorAt, validate(r2) {
35483
+ if (this.required && r2.length === 0)
35484
+ return `Please select at least one option.
35485
+ ${import_picocolors2.default.reset(import_picocolors2.default.dim(`Press ${import_picocolors2.default.gray(import_picocolors2.default.bgWhite(import_picocolors2.default.inverse(" space ")))} to select, ${import_picocolors2.default.gray(import_picocolors2.default.bgWhite(import_picocolors2.default.inverse(" enter ")))} to submit`))}`;
35486
+ }, render() {
35487
+ const r2 = `${import_picocolors2.default.gray(o)}
35488
+ ${b2(this.state)} ${t.message}
35489
+ `, i = (s, c) => {
35490
+ const a = this.value.includes(s.value);
35491
+ return c && a ? n(s, "active-selected") : a ? n(s, "selected") : n(s, c ? "active" : "inactive");
35492
+ };
35493
+ switch (this.state) {
35494
+ case "submit":
35495
+ return `${r2}${import_picocolors2.default.gray(o)} ${this.options.filter(({ value: s }) => this.value.includes(s)).map((s) => n(s, "submitted")).join(import_picocolors2.default.dim(", ")) || import_picocolors2.default.dim("none")}`;
35496
+ case "cancel": {
35497
+ const s = this.options.filter(({ value: c }) => this.value.includes(c)).map((c) => n(c, "cancelled")).join(import_picocolors2.default.dim(", "));
35498
+ return `${r2}${import_picocolors2.default.gray(o)} ${s.trim() ? `${s}
35499
+ ${import_picocolors2.default.gray(o)}` : ""}`;
35500
+ }
35501
+ case "error": {
35502
+ const s = this.error.split(`
35503
+ `).map((c, a) => a === 0 ? `${import_picocolors2.default.yellow(d2)} ${import_picocolors2.default.yellow(c)}` : ` ${c}`).join(`
35504
+ `);
35505
+ return `${r2 + import_picocolors2.default.yellow(o)} ${G2({ options: this.options, cursor: this.cursor, maxItems: t.maxItems, style: i }).join(`
35506
+ ${import_picocolors2.default.yellow(o)} `)}
35507
+ ${s}
35508
+ `;
35509
+ }
35510
+ default:
35511
+ return `${r2}${import_picocolors2.default.cyan(o)} ${G2({ options: this.options, cursor: this.cursor, maxItems: t.maxItems, style: i }).join(`
35512
+ ${import_picocolors2.default.cyan(o)} `)}
35513
+ ${import_picocolors2.default.cyan(d2)}
35514
+ `;
35515
+ }
35516
+ } }).prompt();
35517
+ };
35518
+ var xe = (t = "") => {
35519
+ process.stdout.write(`${import_picocolors2.default.gray(d2)} ${import_picocolors2.default.red(t)}
35520
+
35521
+ `);
35522
+ };
35523
+ var Ie = (t = "") => {
35524
+ process.stdout.write(`${import_picocolors2.default.gray(ue)} ${t}
35525
+ `);
35526
+ };
35527
+ var Se = (t = "") => {
35528
+ process.stdout.write(`${import_picocolors2.default.gray(o)}
35529
+ ${import_picocolors2.default.gray(d2)} ${t}
35530
+
35531
+ `);
35532
+ };
35533
+ var M2 = { message: (t = "", { symbol: n = import_picocolors2.default.gray(o) } = {}) => {
35534
+ const r2 = [`${import_picocolors2.default.gray(o)}`];
35535
+ if (t) {
35536
+ const [i, ...s] = t.split(`
35537
+ `);
35538
+ r2.push(`${n} ${i}`, ...s.map((c) => `${import_picocolors2.default.gray(o)} ${c}`));
35654
35539
  }
35655
- if (stat.isSymbolicLink()) {
35656
- const existingRealPath = await realPathIfPossible(candidate.path);
35657
- if (destinationRealPath && existingRealPath && samePath(destinationRealPath, existingRealPath)) {
35658
- result.alreadyLinked.push({
35659
- category: "instructions",
35660
- from: candidate.path,
35661
- to: destinationPath
35662
- });
35540
+ process.stdout.write(`${r2.join(`
35541
+ `)}
35542
+ `);
35543
+ }, info: (t) => {
35544
+ M2.message(t, { symbol: import_picocolors2.default.blue(q) });
35545
+ }, success: (t) => {
35546
+ M2.message(t, { symbol: import_picocolors2.default.green(D) });
35547
+ }, step: (t) => {
35548
+ M2.message(t, { symbol: import_picocolors2.default.green(C) });
35549
+ }, warn: (t) => {
35550
+ M2.message(t, { symbol: import_picocolors2.default.yellow(U) });
35551
+ }, warning: (t) => {
35552
+ M2.warn(t);
35553
+ }, error: (t) => {
35554
+ M2.message(t, { symbol: import_picocolors2.default.red(K2) });
35555
+ } };
35556
+ var J2 = `${import_picocolors2.default.gray(o)} `;
35557
+ var Y2 = ({ indicator: t = "dots" } = {}) => {
35558
+ const n = V2 ? ["◒", "◐", "◓", "◑"] : ["•", "o", "O", "0"], r2 = V2 ? 80 : 120, i = process.env.CI === "true";
35559
+ let s, c, a = false, l2 = "", $2, g2 = performance.now();
35560
+ const p2 = (m2) => {
35561
+ const h2 = m2 > 1 ? "Something went wrong" : "Canceled";
35562
+ a && N2(h2, m2);
35563
+ }, v2 = () => p2(2), f = () => p2(1), j2 = () => {
35564
+ process.on("uncaughtExceptionMonitor", v2), process.on("unhandledRejection", v2), process.on("SIGINT", f), process.on("SIGTERM", f), process.on("exit", p2);
35565
+ }, E = () => {
35566
+ process.removeListener("uncaughtExceptionMonitor", v2), process.removeListener("unhandledRejection", v2), process.removeListener("SIGINT", f), process.removeListener("SIGTERM", f), process.removeListener("exit", p2);
35567
+ }, B2 = () => {
35568
+ if ($2 === undefined)
35663
35569
  return;
35664
- }
35665
- await import_fs_extra13.default.remove(candidate.path);
35666
- await createFileSymlink(destinationPath, candidate.path);
35667
- result.linked.push({
35668
- category: "instructions",
35669
- from: candidate.path,
35670
- to: destinationPath
35671
- });
35672
- return;
35673
- }
35674
- const backupRoot = await ensureBackupPath(result);
35675
- const backupTarget = path17.join(backupRoot, safeRelativePath(result.rootDir, candidate.path));
35676
- await import_fs_extra13.default.ensureDir(path17.dirname(backupTarget));
35677
- await import_fs_extra13.default.move(candidate.path, backupTarget, { overwrite: false });
35678
- await createFileSymlink(destinationPath, candidate.path);
35679
- result.linked.push({
35680
- category: "instructions",
35681
- from: candidate.path,
35682
- to: destinationPath,
35683
- movedToBackup: backupTarget
35684
- });
35570
+ i && process.stdout.write(`
35571
+ `);
35572
+ const m2 = $2.split(`
35573
+ `);
35574
+ process.stdout.write(import_sisteransi2.cursor.move(-999, m2.length - 1)), process.stdout.write(import_sisteransi2.erase.down(m2.length));
35575
+ }, R2 = (m2) => m2.replace(/\.+$/, ""), O2 = (m2) => {
35576
+ const h2 = (performance.now() - m2) / 1000, w2 = Math.floor(h2 / 60), I2 = Math.floor(h2 % 60);
35577
+ return w2 > 0 ? `[${w2}m ${I2}s]` : `[${I2}s]`;
35578
+ }, H2 = (m2 = "") => {
35579
+ a = true, s = fD(), l2 = R2(m2), g2 = performance.now(), process.stdout.write(`${import_picocolors2.default.gray(o)}
35580
+ `);
35581
+ let h2 = 0, w2 = 0;
35582
+ j2(), c = setInterval(() => {
35583
+ if (i && l2 === $2)
35584
+ return;
35585
+ B2(), $2 = l2;
35586
+ const I2 = import_picocolors2.default.magenta(n[h2]);
35587
+ if (i)
35588
+ process.stdout.write(`${I2} ${l2}...`);
35589
+ else if (t === "timer")
35590
+ process.stdout.write(`${I2} ${l2} ${O2(g2)}`);
35591
+ else {
35592
+ const z2 = ".".repeat(Math.floor(w2)).slice(0, 3);
35593
+ process.stdout.write(`${I2} ${l2}${z2}`);
35594
+ }
35595
+ h2 = h2 + 1 < n.length ? h2 + 1 : 0, w2 = w2 < n.length ? w2 + 0.125 : 0;
35596
+ }, r2);
35597
+ }, N2 = (m2 = "", h2 = 0) => {
35598
+ a = false, clearInterval(c), B2();
35599
+ const w2 = h2 === 0 ? import_picocolors2.default.green(C) : h2 === 1 ? import_picocolors2.default.red(L2) : import_picocolors2.default.red(W2);
35600
+ l2 = R2(m2 ?? l2), t === "timer" ? process.stdout.write(`${w2} ${l2} ${O2(g2)}
35601
+ `) : process.stdout.write(`${w2} ${l2}
35602
+ `), E(), s();
35603
+ };
35604
+ return { start: H2, stop: N2, message: (m2 = "") => {
35605
+ l2 = R2(m2 ?? l2);
35606
+ } };
35607
+ };
35608
+
35609
+ // src/lib/agents-unifier.ts
35610
+ var import_fs_extra13 = __toESM(require_lib4(), 1);
35611
+ import crypto from "crypto";
35612
+ import os14 from "os";
35613
+ import path17 from "path";
35614
+
35615
+ // src/lib/backup-utils.ts
35616
+ var import_fs_extra12 = __toESM(require_lib4(), 1);
35617
+ import path16 from "path";
35618
+ import os13 from "os";
35619
+ var BACKUP_BASE_DIR = path16.join(os13.homedir(), ".config", "aiblueprint", "backup");
35620
+ function getBackupDir() {
35621
+ return process.env.AIBLUEPRINT_BACKUP_DIR || BACKUP_BASE_DIR;
35685
35622
  }
35686
- var RULES_INDEX_START = "<!-- AIBLUEPRINT:RULES:START -->";
35687
- var RULES_INDEX_END = "<!-- AIBLUEPRINT:RULES:END -->";
35688
- function titleFromRulePath(rulePath) {
35689
- return path17.basename(rulePath, path17.extname(rulePath)).replace(/[-_]+/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase());
35623
+ function formatDate(date) {
35624
+ const pad = (n) => n.toString().padStart(2, "0");
35625
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}-${pad(date.getHours())}-${pad(date.getMinutes())}-${pad(date.getSeconds())}`;
35690
35626
  }
35691
- async function readRuleTitle(rulePath) {
35692
- const content = await import_fs_extra13.default.readFile(rulePath, "utf-8").catch(() => "");
35693
- const heading = content.match(/^#\s+(.+)$/m)?.[1]?.trim();
35694
- return heading || titleFromRulePath(rulePath);
35627
+ function createBackupNameSuffix(value) {
35628
+ return value.trim().replace(/^[a-zA-Z]:/, (drive) => drive.replace(":", "")).replace(/[\\/]+/g, "--").replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "root";
35695
35629
  }
35696
- async function collectRuleIndexEntries(rulesDir, rootDir, currentDir = rulesDir) {
35697
- const entries = await import_fs_extra13.default.readdir(currentDir, { withFileTypes: true }).catch(() => []);
35698
- const rules = [];
35630
+ function createTimestampedBackupName(suffix, date = new Date) {
35631
+ const base = formatDate(date);
35632
+ if (!suffix)
35633
+ return base;
35634
+ return `${base}--${createBackupNameSuffix(suffix)}`;
35635
+ }
35636
+ async function listBackups() {
35637
+ const backupBaseDir = getBackupDir();
35638
+ const exists = await import_fs_extra12.default.pathExists(backupBaseDir);
35639
+ if (!exists) {
35640
+ return [];
35641
+ }
35642
+ const entries = await import_fs_extra12.default.readdir(backupBaseDir, { withFileTypes: true });
35643
+ const backups = [];
35699
35644
  for (const entry of entries) {
35700
- if (IGNORED_ENTRY_NAMES2.has(entry.name))
35701
- continue;
35702
- const entryPath = path17.join(currentDir, entry.name);
35703
- if (entry.isDirectory()) {
35704
- rules.push(...await collectRuleIndexEntries(rulesDir, rootDir, entryPath));
35705
- continue;
35706
- }
35707
- if (!entry.isFile() && !entry.isSymbolicLink())
35645
+ if (!entry.isDirectory())
35708
35646
  continue;
35709
- if (![".md", ".mdc"].includes(path17.extname(entry.name).toLowerCase()))
35647
+ const match = entry.name.match(/^(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})(?:--.+)?$/);
35648
+ if (!match)
35710
35649
  continue;
35711
- rules.push({
35712
- title: await readRuleTitle(entryPath),
35713
- relativePath: path17.relative(rootDir, entryPath)
35650
+ const [, year, month, day, hour, minute, second] = match;
35651
+ const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day), parseInt(hour), parseInt(minute), parseInt(second));
35652
+ backups.push({
35653
+ name: entry.name,
35654
+ path: path16.join(backupBaseDir, entry.name),
35655
+ date
35714
35656
  });
35715
35657
  }
35716
- return rules.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
35658
+ return backups.sort((a, b3) => b3.date.getTime() - a.date.getTime());
35717
35659
  }
35718
- function stripGeneratedRulesIndex(content) {
35719
- const start = content.indexOf(RULES_INDEX_START);
35720
- const end = content.indexOf(RULES_INDEX_END);
35721
- if (start === -1 || end === -1 || end < start) {
35722
- return content.trimEnd();
35723
- }
35724
- const beforeStart = content.slice(0, start);
35725
- const headingIndex = beforeStart.lastIndexOf(`
35726
- ## Rules`);
35727
- const blockStart = headingIndex === -1 ? start : headingIndex + 1;
35728
- return `${content.slice(0, blockStart).trimEnd()}
35729
- ${content.slice(end + RULES_INDEX_END.length).trimStart()}`.trimEnd();
35660
+ var AGENTS_BACKUP_SUBDIR = ".agents";
35661
+ var CLAUDE_ITEMS = ["commands", "agents", "skills", "scripts", "settings.json"];
35662
+ var MANAGED_FOLDERS = [".claude", ".codex", ".agents"];
35663
+ async function copyForBackup(sourcePath, destPath) {
35664
+ await import_fs_extra12.default.copy(sourcePath, destPath, {
35665
+ overwrite: true,
35666
+ dereference: false
35667
+ });
35730
35668
  }
35731
- function renderRulesIndexBlock(rules) {
35732
- const lines = [
35733
- "## Rules",
35734
- "",
35735
- "Detailed focused rules live in `.agents/rules/`. Read the relevant file before acting:",
35736
- "",
35737
- RULES_INDEX_START
35738
- ];
35739
- if (rules.length === 0) {
35740
- lines.push("- No repository rules found yet.");
35741
- } else {
35742
- for (const rule of rules) {
35743
- lines.push(`- **${rule.title}** - [${rule.relativePath}](${rule.relativePath})`);
35744
- }
35745
- }
35746
- lines.push(RULES_INDEX_END);
35747
- return lines.join(`
35748
- `);
35669
+ async function hasMeaningfulContent(dir) {
35670
+ if (!await import_fs_extra12.default.pathExists(dir))
35671
+ return false;
35672
+ const files = await import_fs_extra12.default.readdir(dir);
35673
+ return files.some((f) => f !== ".DS_Store");
35749
35674
  }
35750
- async function readExistingInstructions(rootDir) {
35751
- const agentsPath = path17.join(rootDir, "AGENTS.md");
35752
- const claudePath = path17.join(rootDir, "CLAUDE.md");
35753
- const agentsContent = await import_fs_extra13.default.readFile(agentsPath, "utf-8").catch(() => null);
35754
- const claudeContent = await import_fs_extra13.default.readFile(claudePath, "utf-8").catch(() => null);
35755
- if (agentsContent !== null && claudeContent !== null && agentsContent.trim() !== claudeContent.trim()) {
35756
- return `${agentsContent.trimEnd()}
35757
-
35758
- ## Previous Claude Instructions
35759
-
35760
- ${claudeContent.trimStart()}`;
35675
+ async function loadBackup(backupPath, claudeDir, codexDir, agentsDir) {
35676
+ const exists = await import_fs_extra12.default.pathExists(backupPath);
35677
+ if (!exists) {
35678
+ throw new Error(`Backup not found: ${backupPath}`);
35679
+ }
35680
+ const managedDestinations = {
35681
+ ".claude": claudeDir,
35682
+ ".codex": codexDir,
35683
+ ".agents": agentsDir
35684
+ };
35685
+ let restoredManagedFolder = false;
35686
+ for (const folderName of MANAGED_FOLDERS) {
35687
+ const sourcePath = path16.join(backupPath, folderName);
35688
+ const destPath = managedDestinations[folderName];
35689
+ if (!destPath || !await import_fs_extra12.default.pathExists(sourcePath))
35690
+ continue;
35691
+ await import_fs_extra12.default.ensureDir(destPath);
35692
+ await copyForBackup(sourcePath, destPath);
35693
+ restoredManagedFolder = true;
35694
+ }
35695
+ if (!restoredManagedFolder) {
35696
+ await import_fs_extra12.default.ensureDir(claudeDir);
35697
+ for (const item of CLAUDE_ITEMS) {
35698
+ const sourcePath = path16.join(backupPath, item);
35699
+ const destPath = path16.join(claudeDir, item);
35700
+ if (await import_fs_extra12.default.pathExists(sourcePath)) {
35701
+ await copyForBackup(sourcePath, destPath);
35702
+ }
35703
+ }
35704
+ if (agentsDir) {
35705
+ const agentsBackupPath = path16.join(backupPath, AGENTS_BACKUP_SUBDIR);
35706
+ if (await import_fs_extra12.default.pathExists(agentsBackupPath)) {
35707
+ await import_fs_extra12.default.ensureDir(agentsDir);
35708
+ await copyForBackup(agentsBackupPath, agentsDir);
35709
+ }
35710
+ }
35761
35711
  }
35762
- if (agentsContent !== null)
35763
- return agentsContent;
35764
- if (claudeContent !== null)
35765
- return claudeContent;
35766
- return `# Repository Instructions
35767
- `;
35768
35712
  }
35769
- async function copyPathToBackup(result, targetPath) {
35770
- const stat = await import_fs_extra13.default.lstat(targetPath).catch(() => null);
35771
- if (!stat)
35713
+ async function createBackup(claudeDir, codexDir, agentsDir) {
35714
+ const claudeHasContent = await hasMeaningfulContent(claudeDir);
35715
+ const codexHasContent = codexDir ? await hasMeaningfulContent(codexDir) : false;
35716
+ const agentsHasContent = agentsDir ? await hasMeaningfulContent(agentsDir) : false;
35717
+ if (!claudeHasContent && !codexHasContent && !agentsHasContent) {
35772
35718
  return null;
35773
- const backupRoot = await ensureBackupPath(result);
35774
- const backupTarget = path17.join(backupRoot, safeRelativePath(result.rootDir, targetPath));
35775
- await import_fs_extra13.default.ensureDir(path17.dirname(backupTarget));
35776
- await import_fs_extra13.default.copy(targetPath, backupTarget, {
35777
- dereference: false,
35778
- overwrite: false
35779
- });
35780
- return backupTarget;
35781
- }
35782
- async function replaceWithFileSymlink(sourcePath, targetPath) {
35783
- await import_fs_extra13.default.ensureDir(path17.dirname(targetPath));
35784
- const relativeSource = path17.relative(path17.dirname(targetPath), sourcePath) || path17.basename(sourcePath);
35785
- await import_fs_extra13.default.symlink(relativeSource, targetPath, "file");
35786
- }
35787
- async function ensureClaudeInstructionSymlink(result, agentsPath, claudePath) {
35788
- const agentsRealPath = await realPathIfPossible(agentsPath);
35789
- const claudeStat = await import_fs_extra13.default.lstat(claudePath).catch(() => null);
35790
- if (claudeStat?.isSymbolicLink()) {
35791
- const claudeRealPath = await realPathIfPossible(claudePath);
35792
- if (agentsRealPath && claudeRealPath && samePath(agentsRealPath, claudeRealPath)) {
35793
- return;
35794
- }
35795
35719
  }
35796
- if (claudeStat) {
35797
- await copyPathToBackup(result, claudePath);
35798
- await import_fs_extra13.default.remove(claudePath);
35720
+ const backupPath = path16.join(getBackupDir(), createTimestampedBackupName());
35721
+ await import_fs_extra12.default.ensureDir(backupPath);
35722
+ if (claudeHasContent) {
35723
+ await copyForBackup(claudeDir, path16.join(backupPath, ".claude"));
35799
35724
  }
35800
- await replaceWithFileSymlink(agentsPath, claudePath);
35801
- }
35802
- async function writeRepositoryInstructionIndex(result, folders) {
35803
- const rulesDir = path17.join(folders.agentsDir, "rules");
35804
- if (!await pathExistsOrSymlink(rulesDir)) {
35805
- return;
35725
+ if (codexHasContent && codexDir) {
35726
+ await copyForBackup(codexDir, path16.join(backupPath, ".codex"));
35806
35727
  }
35807
- const rules = await collectRuleIndexEntries(rulesDir, folders.rootDir);
35808
- if (rules.length === 0) {
35809
- return;
35728
+ if (agentsHasContent && agentsDir) {
35729
+ const destPath = path16.join(backupPath, AGENTS_BACKUP_SUBDIR);
35730
+ await copyForBackup(agentsDir, destPath);
35810
35731
  }
35811
- const existing = stripGeneratedRulesIndex(await readExistingInstructions(folders.rootDir));
35812
- const content = `${existing}
35732
+ return backupPath;
35733
+ }
35813
35734
 
35814
- ${renderRulesIndexBlock(rules)}
35815
- `;
35816
- const agentsPath = path17.join(folders.rootDir, "AGENTS.md");
35817
- const claudePath = path17.join(folders.rootDir, "CLAUDE.md");
35818
- const agentsStat = await import_fs_extra13.default.lstat(agentsPath).catch(() => null);
35819
- if (agentsStat) {
35820
- await copyPathToBackup(result, agentsPath);
35821
- if (agentsStat.isSymbolicLink()) {
35822
- await import_fs_extra13.default.remove(agentsPath);
35823
- }
35735
+ // src/lib/agents-unifier.ts
35736
+ var IGNORED_ENTRY_NAMES2 = new Set([
35737
+ ".DS_Store",
35738
+ ".git",
35739
+ "node_modules"
35740
+ ]);
35741
+ function uniqueByPath(candidates) {
35742
+ const seen = new Set;
35743
+ const unique = [];
35744
+ for (const candidate of candidates) {
35745
+ const resolved = path17.resolve(candidate.path);
35746
+ if (seen.has(resolved))
35747
+ continue;
35748
+ seen.add(resolved);
35749
+ unique.push({ ...candidate, path: resolved });
35824
35750
  }
35825
- await import_fs_extra13.default.writeFile(agentsPath, content, "utf-8");
35826
- await ensureClaudeInstructionSymlink(result, agentsPath, claudePath);
35827
- result.instructionIndex = {
35828
- agentsPath,
35829
- claudePath,
35830
- indexedRules: rules.map((rule) => rule.relativePath)
35831
- };
35751
+ return unique;
35832
35752
  }
35833
- async function unifyAgentsConfiguration(options = {}) {
35834
- const scope = options.scope ?? "global";
35753
+ function getContainerCandidates(options, includeCodex = true) {
35835
35754
  const folders = resolveFolders(options);
35836
- const includeCodex = scope !== "repository";
35837
- const instructionCandidates = getInstructionFileCandidates(options, includeCodex);
35838
- const candidates = scope === "repository" ? getRepositoryContainerCandidates(options) : getContainerCandidates(options);
35839
- const result = {
35840
- rootDir: folders.rootDir,
35841
- agentsDir: folders.agentsDir,
35842
- scope,
35843
- backupPath: null,
35844
- imported: [],
35845
- duplicates: [],
35846
- renamed: [],
35847
- linked: [],
35848
- alreadyLinked: [],
35849
- skipped: [],
35850
- instructionIndex: null
35851
- };
35852
- const destinationByCategory = {
35853
- skills: path17.join(folders.agentsDir, "skills"),
35854
- agents: path17.join(folders.agentsDir, "agents"),
35855
- instructions: path17.join(folders.agentsDir, "AGENTS.md"),
35856
- rules: path17.join(folders.agentsDir, "rules")
35857
- };
35858
- await importInstructionFiles(instructionCandidates, destinationByCategory.instructions, result);
35859
- const categories = scope === "repository" ? ["skills", "agents", "rules"] : ["skills", "agents"];
35860
- const activeCategories = new Set;
35861
- for (const category of categories) {
35862
- const isActive = await importCategoryEntries(category, candidates, destinationByCategory[category], result);
35863
- if (isActive) {
35864
- activeCategories.add(category);
35755
+ const cursorDir = path17.join(folders.rootDir, ".cursor");
35756
+ const factoryDir = path17.join(folders.rootDir, ".factory");
35757
+ const opencodeDir = path17.join(folders.rootDir, ".config", "opencode");
35758
+ return uniqueByPath([
35759
+ {
35760
+ category: "skills",
35761
+ label: "agents-skills",
35762
+ path: path17.join(folders.agentsDir, "skills"),
35763
+ isDestination: true
35764
+ },
35765
+ {
35766
+ category: "skills",
35767
+ label: "claude-skills",
35768
+ path: path17.join(folders.claudeDir, "skills"),
35769
+ linkWhenMissing: true
35770
+ },
35771
+ ...includeCodex ? [{
35772
+ category: "skills",
35773
+ label: "codex-skills",
35774
+ path: path17.join(folders.codexDir, "skills"),
35775
+ linkWhenMissing: true
35776
+ }] : [],
35777
+ {
35778
+ category: "skills",
35779
+ label: "cursor-skills",
35780
+ path: path17.join(cursorDir, "skills"),
35781
+ linkWhenParentExists: true
35782
+ },
35783
+ {
35784
+ category: "skills",
35785
+ label: "cursor-skills-cursor",
35786
+ path: path17.join(cursorDir, "skills-cursor"),
35787
+ linkWhenParentExists: true
35788
+ },
35789
+ {
35790
+ category: "skills",
35791
+ label: "factory-skills",
35792
+ path: path17.join(factoryDir, "skills"),
35793
+ linkWhenParentExists: true
35794
+ },
35795
+ {
35796
+ category: "skills",
35797
+ label: "opencode-skill",
35798
+ path: path17.join(opencodeDir, "skill"),
35799
+ linkWhenParentExists: true
35800
+ },
35801
+ {
35802
+ category: "skills",
35803
+ label: "opencode-skills",
35804
+ path: path17.join(opencodeDir, "skills"),
35805
+ linkWhenParentExists: true
35806
+ },
35807
+ {
35808
+ category: "agents",
35809
+ label: "agents-agents",
35810
+ path: path17.join(folders.agentsDir, "agents"),
35811
+ isDestination: true
35812
+ },
35813
+ {
35814
+ category: "agents",
35815
+ label: "claude-agents",
35816
+ path: path17.join(folders.claudeDir, "agents"),
35817
+ linkWhenMissing: true
35818
+ },
35819
+ {
35820
+ category: "agents",
35821
+ label: "claude-agnets",
35822
+ path: path17.join(folders.claudeDir, "agnets")
35823
+ },
35824
+ {
35825
+ category: "agents",
35826
+ label: "cursor-agents",
35827
+ path: path17.join(cursorDir, "agents"),
35828
+ linkWhenParentExists: true
35829
+ },
35830
+ {
35831
+ category: "agents",
35832
+ label: "factory-droids",
35833
+ path: path17.join(factoryDir, "droids"),
35834
+ linkWhenParentExists: true
35835
+ },
35836
+ {
35837
+ category: "agents",
35838
+ label: "opencode-agent",
35839
+ path: path17.join(opencodeDir, "agent"),
35840
+ linkWhenParentExists: true
35841
+ },
35842
+ {
35843
+ category: "agents",
35844
+ label: "opencode-agents",
35845
+ path: path17.join(opencodeDir, "agents"),
35846
+ linkWhenParentExists: true
35847
+ }
35848
+ ]);
35849
+ }
35850
+ function getInstructionFileCandidates(options, includeCodex = true) {
35851
+ const folders = resolveFolders(options);
35852
+ return uniqueByPath([
35853
+ {
35854
+ label: "agents-instructions",
35855
+ path: path17.join(folders.agentsDir, "AGENTS.md"),
35856
+ isDestination: true
35857
+ },
35858
+ {
35859
+ label: "claude-instructions",
35860
+ path: path17.join(folders.claudeDir, "CLAUDE.md"),
35861
+ linkWhenMissing: true
35862
+ },
35863
+ ...includeCodex ? [{
35864
+ label: "codex-instructions",
35865
+ path: path17.join(folders.codexDir, "AGENTS.md"),
35866
+ linkWhenMissing: true
35867
+ }] : []
35868
+ ]);
35869
+ }
35870
+ function getRepositoryContainerCandidates(options) {
35871
+ const folders = resolveFolders(options);
35872
+ const cursorDir = path17.join(folders.rootDir, ".cursor");
35873
+ return uniqueByPath([
35874
+ ...getContainerCandidates(options, false),
35875
+ {
35876
+ category: "rules",
35877
+ label: "agents-rules",
35878
+ path: path17.join(folders.agentsDir, "rules"),
35879
+ isDestination: true
35880
+ },
35881
+ {
35882
+ category: "rules",
35883
+ label: "claude-rules",
35884
+ path: path17.join(folders.claudeDir, "rules"),
35885
+ linkWhenMissing: true
35886
+ },
35887
+ {
35888
+ category: "rules",
35889
+ label: "cursor-rules",
35890
+ path: path17.join(cursorDir, "rules"),
35891
+ linkWhenParentExists: true
35892
+ },
35893
+ {
35894
+ category: "rules",
35895
+ label: "claude-memories",
35896
+ path: path17.join(folders.claudeDir, "memories"),
35897
+ linkSource: false
35898
+ },
35899
+ {
35900
+ category: "rules",
35901
+ label: "cursor-memories",
35902
+ path: path17.join(cursorDir, "memories"),
35903
+ linkSource: false
35904
+ },
35905
+ {
35906
+ category: "rules",
35907
+ label: "claude-memory",
35908
+ path: path17.join(folders.claudeDir, "memory.md"),
35909
+ linkSource: false
35910
+ },
35911
+ {
35912
+ category: "rules",
35913
+ label: "cursor-memory",
35914
+ path: path17.join(cursorDir, "memory.md"),
35915
+ linkSource: false
35916
+ },
35917
+ {
35918
+ category: "rules",
35919
+ label: "claude-memory-uppercase",
35920
+ path: path17.join(folders.claudeDir, "MEMORY.md"),
35921
+ linkSource: false
35922
+ },
35923
+ {
35924
+ category: "rules",
35925
+ label: "cursor-memory-uppercase",
35926
+ path: path17.join(cursorDir, "MEMORY.md"),
35927
+ linkSource: false
35865
35928
  }
35929
+ ]);
35930
+ }
35931
+ async function pathExistsOrSymlink(targetPath) {
35932
+ const stat = await import_fs_extra13.default.lstat(targetPath).catch(() => null);
35933
+ return Boolean(stat);
35934
+ }
35935
+ async function realPathIfPossible(targetPath) {
35936
+ try {
35937
+ return await import_fs_extra13.default.realpath(targetPath);
35938
+ } catch {
35939
+ return null;
35866
35940
  }
35867
- for (const candidate of candidates) {
35868
- if (!activeCategories.has(candidate.category))
35869
- continue;
35870
- await linkContainer(candidate, destinationByCategory[candidate.category], result);
35941
+ }
35942
+ function samePath(a, b3) {
35943
+ return path17.resolve(a) === path17.resolve(b3);
35944
+ }
35945
+ function hashString(value) {
35946
+ return crypto.createHash("sha256").update(value).digest("hex");
35947
+ }
35948
+ async function hashPath(targetPath) {
35949
+ const stat = await import_fs_extra13.default.lstat(targetPath);
35950
+ if (stat.isSymbolicLink()) {
35951
+ const linkTarget = await import_fs_extra13.default.readlink(targetPath);
35952
+ return hashString(`symlink:${linkTarget}`);
35871
35953
  }
35872
- for (const candidate of instructionCandidates) {
35873
- await linkInstructionFile(candidate, destinationByCategory.instructions, result);
35954
+ if (stat.isFile()) {
35955
+ const fileHash = crypto.createHash("sha256");
35956
+ fileHash.update("file:");
35957
+ fileHash.update(await import_fs_extra13.default.readFile(targetPath));
35958
+ return fileHash.digest("hex");
35874
35959
  }
35875
- if (scope === "repository") {
35876
- await writeRepositoryInstructionIndex(result, folders);
35960
+ if (stat.isDirectory()) {
35961
+ const entries = (await import_fs_extra13.default.readdir(targetPath, { withFileTypes: true })).filter((entry) => !IGNORED_ENTRY_NAMES2.has(entry.name)).sort((a, b3) => a.name.localeCompare(b3.name));
35962
+ const dirHash = crypto.createHash("sha256");
35963
+ dirHash.update("dir:");
35964
+ for (const entry of entries) {
35965
+ dirHash.update(entry.name);
35966
+ dirHash.update("\x00");
35967
+ dirHash.update(await hashPath(path17.join(targetPath, entry.name)));
35968
+ dirHash.update("\x00");
35969
+ }
35970
+ return dirHash.digest("hex");
35877
35971
  }
35878
- return result;
35972
+ return hashString(`other:${stat.mode}:${stat.size}`);
35879
35973
  }
35880
-
35881
- // src/commands/agents-unify.ts
35882
- function countByCategory(result, key, category) {
35883
- return result[key].filter((entry) => entry.category === category).length;
35974
+ var TEXT_EXTENSIONS = new Set([
35975
+ ".cjs",
35976
+ ".js",
35977
+ ".json",
35978
+ ".jsonc",
35979
+ ".md",
35980
+ ".mdc",
35981
+ ".mjs",
35982
+ ".sh",
35983
+ ".toml",
35984
+ ".ts",
35985
+ ".tsx",
35986
+ ".txt",
35987
+ ".yaml",
35988
+ ".yml"
35989
+ ]);
35990
+ var PORTABLE_PATH_REPLACEMENTS = [
35991
+ [/\.claude\/skills/g, ".agents/skills"],
35992
+ [/\.codex\/skills/g, ".agents/skills"],
35993
+ [/\.cursor\/skills-cursor/g, ".agents/skills"],
35994
+ [/\.cursor\/skills/g, ".agents/skills"],
35995
+ [/\.claude\/agents/g, ".agents/agents"],
35996
+ [/\.codex\/agents/g, ".agents/agents"],
35997
+ [/\.cursor\/agents/g, ".agents/agents"],
35998
+ [/\.claude\/rules/g, ".agents/rules"],
35999
+ [/\.codex\/rules/g, ".agents/rules"],
36000
+ [/\.cursor\/rules/g, ".agents/rules"],
36001
+ [/\.claude\/memories/g, ".agents/rules"],
36002
+ [/\.codex\/memories/g, ".agents/rules"],
36003
+ [/\.cursor\/memories/g, ".agents/rules"]
36004
+ ];
36005
+ function normalizePortableText(content) {
36006
+ let normalized = content;
36007
+ for (const [pattern, replacement] of PORTABLE_PATH_REPLACEMENTS) {
36008
+ normalized = normalized.replace(pattern, replacement);
36009
+ }
36010
+ return normalized;
35884
36011
  }
35885
- function printCategorySummary(result, category) {
35886
- const imported = countByCategory(result, "imported", category);
35887
- const duplicates = countByCategory(result, "duplicates", category);
35888
- const renamed = countByCategory(result, "renamed", category);
35889
- const linked = countByCategory(result, "linked", category);
35890
- const alreadyLinked = countByCategory(result, "alreadyLinked", category);
35891
- console.log(source_default.gray(` ${category}: ${imported} imported, ${duplicates} duplicates skipped, ${renamed} renamed, ${linked} linked, ${alreadyLinked} already linked`));
36012
+ function isLikelyTextFile(filePath) {
36013
+ const ext = path17.extname(filePath).toLowerCase();
36014
+ if (TEXT_EXTENSIONS.has(ext))
36015
+ return true;
36016
+ return path17.basename(filePath) === "SKILL.md";
35892
36017
  }
35893
- async function agentsUnifyCommand(params = {}) {
35894
- try {
35895
- console.log(source_default.blue.bold(`
35896
- AIBlueprint agents unify ${source_default.gray(`v${getVersion()}`)}
35897
- `));
35898
- console.log(source_default.gray(`Scope: ${params.scope ?? "global"}`));
35899
- console.log(source_default.gray(params.scope === "repository" ? "Centralizing project agent configuration into .agents" : "Centralizing reusable agent configuration into .agents, then rendering Codex agents"));
35900
- const result = await unifyAgentsConfiguration(params);
35901
- const codexResult = params.scope === "repository" ? null : await renderCodexAgentsFromMarkdown(params);
35902
- console.log(source_default.green(`
35903
- Unify complete`));
35904
- console.log(source_default.gray(` Shared folder: ${result.agentsDir}`));
35905
- printCategorySummary(result, "instructions");
35906
- printCategorySummary(result, "skills");
35907
- printCategorySummary(result, "agents");
35908
- if (result.scope === "repository") {
35909
- printCategorySummary(result, "rules");
35910
- }
35911
- if (codexResult) {
35912
- console.log(source_default.gray(` codex agents: ${codexResult.rendered.length} rendered, ${codexResult.skipped.length} skipped`));
35913
- }
35914
- if (result.instructionIndex) {
35915
- console.log(source_default.gray(` rules index: ${result.instructionIndex.indexedRules.length} rules indexed in ${result.instructionIndex.agentsPath}`));
35916
- console.log(source_default.gray(` Claude instructions: ${result.instructionIndex.claudePath}`));
35917
- }
35918
- if (result.backupPath) {
35919
- console.log(source_default.gray(` Source backups: ${result.backupPath}`));
35920
- }
35921
- if (result.skipped.length > 0) {
35922
- console.log(source_default.yellow(`
35923
- Skipped paths:`));
35924
- for (const skipped of result.skipped) {
35925
- console.log(source_default.yellow(` ${skipped.path}: ${skipped.reason}`));
35926
- }
36018
+ async function normalizePortableContent(targetPath) {
36019
+ const stat = await import_fs_extra13.default.lstat(targetPath).catch(() => null);
36020
+ if (!stat || stat.isSymbolicLink())
36021
+ return;
36022
+ if (stat.isDirectory()) {
36023
+ const entries = await import_fs_extra13.default.readdir(targetPath);
36024
+ for (const entry of entries) {
36025
+ if (IGNORED_ENTRY_NAMES2.has(entry))
36026
+ continue;
36027
+ await normalizePortableContent(path17.join(targetPath, entry));
35927
36028
  }
35928
- } catch (error) {
35929
- console.error(source_default.red(`
35930
- Agents unify failed:`), error);
35931
- process.exit(1);
36029
+ return;
35932
36030
  }
35933
- }
35934
-
35935
- // src/commands/codex-agents.ts
35936
- async function codexAgentsCommand(options = {}) {
35937
- try {
35938
- console.log(source_default.blue.bold(`
35939
- AIBlueprint Codex agents ${source_default.gray(`v${getVersion()}`)}
35940
- `));
35941
- console.log(source_default.gray("Rendering shared Markdown agents into Codex TOML custom agents"));
35942
- const result = await renderCodexAgentsFromMarkdown(options);
35943
- console.log(source_default.green(`
35944
- Codex agents rendered`));
35945
- console.log(source_default.gray(` Source: ${result.sourceDir}`));
35946
- console.log(source_default.gray(` Target: ${result.targetDir}`));
35947
- console.log(source_default.gray(` Rendered: ${result.rendered.length}`));
35948
- console.log(source_default.gray(` Skipped: ${result.skipped.length}`));
35949
- if (result.skipped.length > 0) {
35950
- console.log(source_default.yellow(`
35951
- Skipped agents:`));
35952
- for (const skipped of result.skipped) {
35953
- console.log(source_default.yellow(` ${skipped.source}: ${skipped.reason}`));
35954
- }
35955
- }
35956
- } catch (error) {
35957
- console.error(source_default.red(`
35958
- Codex agents render failed:`), error);
35959
- process.exit(1);
36031
+ if (!stat.isFile() || !isLikelyTextFile(targetPath))
36032
+ return;
36033
+ const content = await import_fs_extra13.default.readFile(targetPath, "utf-8").catch(() => null);
36034
+ if (content === null || content.includes("\x00"))
36035
+ return;
36036
+ const normalized = normalizePortableText(content);
36037
+ if (normalized !== content) {
36038
+ await import_fs_extra13.default.writeFile(targetPath, normalized, "utf-8");
35960
36039
  }
35961
36040
  }
35962
-
35963
- // src/lib/session-unifier.ts
35964
- var import_fs_extra14 = __toESM(require_lib4(), 1);
35965
- import crypto2 from "crypto";
35966
- import os15 from "os";
35967
- import path18 from "path";
35968
- var MANAGED_FOLDERS2 = [".claude", ".codex", ".agents"];
35969
- var SESSION_PATHS = {
35970
- ".claude": ["projects", "sessions"],
35971
- ".codex": ["sessions", "archived_sessions", "browser/sessions"],
35972
- ".agents": ["sessions"]
35973
- };
35974
- async function listSnapshotSources(parentDir, type) {
35975
- if (!await import_fs_extra14.default.pathExists(parentDir))
35976
- return [];
35977
- const entries = await import_fs_extra14.default.readdir(parentDir, { withFileTypes: true });
35978
- return entries.filter((entry) => entry.isDirectory()).map((entry) => ({
35979
- name: entry.name,
35980
- path: path18.join(parentDir, entry.name),
35981
- type
35982
- }));
36041
+ function suffixFromLabel(label) {
36042
+ return label.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "source";
35983
36043
  }
35984
- async function collectSnapshotSources(folders) {
35985
- const storePaths = getConfigStorePaths(folders.rootDir);
35986
- const sources = [
35987
- ...await listSnapshotSources(storePaths.configsDir, "config"),
35988
- ...await listSnapshotSources(storePaths.backupsDir, "backup")
35989
- ];
35990
- if (path18.resolve(folders.rootDir) === os15.homedir()) {
35991
- sources.push(...await listSnapshotSources(getBackupDir(), "legacy-backup"));
36044
+ function nameWithSuffix(name, suffix, index) {
36045
+ const parsed = path17.parse(name);
36046
+ const numberedSuffix = index === 1 ? suffix : `${suffix}-${index}`;
36047
+ if (parsed.ext && parsed.name) {
36048
+ return `${parsed.name}--${numberedSuffix}${parsed.ext}`;
35992
36049
  }
35993
- return sources.sort((a, b) => a.name.localeCompare(b.name));
36050
+ return `${name}--${numberedSuffix}`;
35994
36051
  }
35995
- async function snapshotFolderPath(snapshot, folder) {
35996
- const managedPath = path18.join(snapshot.path, folder);
35997
- if (await import_fs_extra14.default.pathExists(managedPath))
35998
- return managedPath;
35999
- if (snapshot.type === "legacy-backup") {
36000
- if (folder === ".claude")
36001
- return snapshot.path;
36002
- const legacyAgentsPath = path18.join(snapshot.path, ".agents");
36003
- if (folder === ".agents" && await import_fs_extra14.default.pathExists(legacyAgentsPath)) {
36004
- return legacyAgentsPath;
36052
+ async function addExistingDestinationHashes(destinationDir, knownHashes) {
36053
+ if (!await import_fs_extra13.default.pathExists(destinationDir))
36054
+ return;
36055
+ const entries = await import_fs_extra13.default.readdir(destinationDir, { withFileTypes: true });
36056
+ for (const entry of entries) {
36057
+ if (IGNORED_ENTRY_NAMES2.has(entry.name))
36058
+ continue;
36059
+ const entryPath = path17.join(destinationDir, entry.name);
36060
+ knownHashes.set(await hashPath(entryPath), entry.name);
36061
+ }
36062
+ }
36063
+ async function importCategoryEntries(category, candidates, destinationDir, result, dryRun = false) {
36064
+ const sourceEntries = [];
36065
+ const destinationExists = await pathExistsOrSymlink(destinationDir);
36066
+ const destinationRealPath = destinationExists ? await realPathIfPossible(destinationDir) : null;
36067
+ for (const candidate of candidates) {
36068
+ if (candidate.category !== category || candidate.isDestination)
36069
+ continue;
36070
+ const candidateStat = await import_fs_extra13.default.lstat(candidate.path).catch(() => null);
36071
+ if (!candidateStat)
36072
+ continue;
36073
+ const candidateRealPath = await realPathIfPossible(candidate.path);
36074
+ if (destinationRealPath && candidateRealPath && samePath(destinationRealPath, candidateRealPath)) {
36075
+ continue;
36076
+ }
36077
+ const entries = await collectCandidateEntries(candidate).catch(() => null);
36078
+ if (!entries) {
36079
+ result.skipped.push({
36080
+ category,
36081
+ path: candidate.path,
36082
+ reason: "Could not read directory"
36083
+ });
36084
+ continue;
36085
+ }
36086
+ const collectableEntries = [];
36087
+ for (const entry of entries) {
36088
+ if (!await shouldCollectPath(category, entry.name, entry.path))
36089
+ continue;
36090
+ collectableEntries.push(entry);
36091
+ }
36092
+ if (collectableEntries.length > 0) {
36093
+ sourceEntries.push({ candidate, entries: collectableEntries });
36005
36094
  }
36006
36095
  }
36007
- return null;
36008
- }
36009
- function sanitizeSourceTag(snapshot) {
36010
- return `${snapshot.type}-${snapshot.name}`.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "snapshot";
36011
- }
36012
- function withSourceSuffix(targetPath, sourceTag, index) {
36013
- const parsed = path18.parse(targetPath);
36014
- const suffix = index === 1 ? sourceTag : `${sourceTag}-${index}`;
36015
- if (parsed.ext && parsed.name) {
36016
- return path18.join(parsed.dir, `${parsed.name}--${suffix}${parsed.ext}`);
36096
+ if (!destinationExists && sourceEntries.length === 0) {
36097
+ return false;
36017
36098
  }
36018
- return path18.join(parsed.dir, `${parsed.base}--${suffix}`);
36099
+ if (!dryRun) {
36100
+ await import_fs_extra13.default.ensureDir(destinationDir);
36101
+ }
36102
+ const knownHashes = new Map;
36103
+ await addExistingDestinationHashes(destinationDir, knownHashes);
36104
+ const knownNames = new Set(knownHashes.values());
36105
+ for (const { candidate, entries } of sourceEntries) {
36106
+ for (const entry of entries) {
36107
+ const sourcePath = entry.path;
36108
+ const sourceHash = await hashPath(sourcePath);
36109
+ const existingName = knownHashes.get(sourceHash);
36110
+ if (existingName) {
36111
+ result.duplicates.push({
36112
+ category,
36113
+ name: entry.name,
36114
+ from: sourcePath,
36115
+ keptAs: path17.join(destinationDir, existingName)
36116
+ });
36117
+ continue;
36118
+ }
36119
+ let targetName = entry.name;
36120
+ let targetPath = path17.join(destinationDir, targetName);
36121
+ if (await pathExistsOrSymlink(targetPath) || knownNames.has(targetName)) {
36122
+ targetName = await findAvailableTargetName(destinationDir, entry.name, candidate.label, knownNames);
36123
+ targetPath = path17.join(destinationDir, targetName);
36124
+ result.renamed.push({
36125
+ category,
36126
+ name: entry.name,
36127
+ from: sourcePath,
36128
+ to: targetPath,
36129
+ reason: "Same name with different content"
36130
+ });
36131
+ }
36132
+ if (!dryRun) {
36133
+ await import_fs_extra13.default.copy(sourcePath, targetPath, {
36134
+ dereference: false,
36135
+ overwrite: false
36136
+ });
36137
+ await normalizePortableContent(targetPath);
36138
+ }
36139
+ knownNames.add(targetName);
36140
+ knownHashes.set(dryRun ? sourceHash : await hashPath(targetPath), targetName);
36141
+ result.imported.push({
36142
+ category,
36143
+ name: entry.name,
36144
+ from: sourcePath,
36145
+ to: targetPath
36146
+ });
36147
+ }
36148
+ }
36149
+ return true;
36019
36150
  }
36020
- async function uniqueConflictPath(targetPath, sourceTag) {
36151
+ async function findAvailableTargetName(destinationDir, originalName, label, knownNames) {
36152
+ const suffix = suffixFromLabel(label);
36021
36153
  let index = 1;
36022
36154
  while (true) {
36023
- const candidate = withSourceSuffix(targetPath, sourceTag, index);
36024
- if (!await import_fs_extra14.default.pathExists(candidate))
36155
+ const candidate = nameWithSuffix(originalName, suffix, index);
36156
+ if (!knownNames.has(candidate) && !await pathExistsOrSymlink(path17.join(destinationDir, candidate))) {
36025
36157
  return candidate;
36158
+ }
36026
36159
  index++;
36027
36160
  }
36028
36161
  }
36029
- function hashString2(value) {
36030
- return crypto2.createHash("sha256").update(value).digest("hex");
36031
- }
36032
- async function hashPath2(targetPath) {
36033
- const stat = await import_fs_extra14.default.lstat(targetPath);
36162
+ async function collectCandidateEntries(candidate) {
36163
+ const stat = await import_fs_extra13.default.lstat(candidate.path);
36164
+ if (stat.isDirectory()) {
36165
+ const entries = await import_fs_extra13.default.readdir(candidate.path, { withFileTypes: true });
36166
+ return entries.map((entry) => ({
36167
+ name: entry.name,
36168
+ path: path17.join(candidate.path, entry.name)
36169
+ }));
36170
+ }
36034
36171
  if (stat.isSymbolicLink()) {
36035
- return hashString2(`symlink:${await import_fs_extra14.default.readlink(targetPath)}`);
36172
+ const targetStat = await import_fs_extra13.default.stat(candidate.path).catch(() => null);
36173
+ if (targetStat?.isDirectory()) {
36174
+ const entries = await import_fs_extra13.default.readdir(candidate.path, { withFileTypes: true });
36175
+ return entries.map((entry) => ({
36176
+ name: entry.name,
36177
+ path: path17.join(candidate.path, entry.name)
36178
+ }));
36179
+ }
36036
36180
  }
36037
- if (stat.isFile()) {
36038
- const hash = crypto2.createHash("sha256");
36039
- hash.update("file:");
36040
- hash.update(await import_fs_extra14.default.readFile(targetPath));
36041
- return hash.digest("hex");
36181
+ return [{
36182
+ name: path17.basename(candidate.path),
36183
+ path: candidate.path
36184
+ }];
36185
+ }
36186
+ async function shouldCollectPath(category, name, sourcePath) {
36187
+ if (IGNORED_ENTRY_NAMES2.has(name))
36188
+ return false;
36189
+ if (category === "skills" && name === ".cursor-managed-skills-manifest.json") {
36190
+ return true;
36042
36191
  }
36043
- if (stat.isDirectory()) {
36044
- const entries = (await import_fs_extra14.default.readdir(targetPath, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
36045
- const hash = crypto2.createHash("sha256");
36046
- hash.update("dir:");
36047
- for (const entry of entries) {
36048
- hash.update(entry.name);
36049
- hash.update("\x00");
36050
- hash.update(await hashPath2(path18.join(targetPath, entry.name)));
36051
- hash.update("\x00");
36192
+ const stat = await import_fs_extra13.default.lstat(sourcePath).catch(() => null);
36193
+ if (!stat)
36194
+ return false;
36195
+ return stat.isFile() || stat.isDirectory() || stat.isSymbolicLink();
36196
+ }
36197
+ function safeRelativePath(rootDir, targetPath) {
36198
+ const relativePath = path17.relative(rootDir, targetPath);
36199
+ if (!relativePath || relativePath.startsWith("..") || path17.isAbsolute(relativePath)) {
36200
+ return path17.join("external", targetPath.replace(/[^a-zA-Z0-9._-]+/g, "-"));
36201
+ }
36202
+ return relativePath;
36203
+ }
36204
+ function createBackupPath(rootDir) {
36205
+ const projectKey = createBackupNameSuffix(path17.resolve(rootDir));
36206
+ return path17.join(getBackupDir(), createTimestampedBackupName(`project-${projectKey}-agents-unify-sources`));
36207
+ }
36208
+ async function ensureBackupPath(result, dryRun = false) {
36209
+ if (!result.backupPath) {
36210
+ result.backupPath = createBackupPath(result.rootDir);
36211
+ if (!dryRun) {
36212
+ await import_fs_extra13.default.ensureDir(result.backupPath);
36052
36213
  }
36053
- return hash.digest("hex");
36054
36214
  }
36055
- return hashString2(`other:${stat.mode}:${stat.size}`);
36215
+ return result.backupPath;
36056
36216
  }
36057
- async function mergeSessionPath(params) {
36058
- const {
36059
- sourcePath,
36060
- destinationPath,
36061
- folder,
36062
- sessionRoot,
36063
- snapshot,
36064
- sourceTag,
36065
- result
36066
- } = params;
36067
- const sourceStat = await import_fs_extra14.default.lstat(sourcePath).catch(() => null);
36068
- if (!sourceStat)
36217
+ async function createDirectorySymlink(source, target) {
36218
+ await import_fs_extra13.default.ensureDir(path17.dirname(target));
36219
+ if (os14.platform() === "win32") {
36220
+ await import_fs_extra13.default.symlink(source, target, "junction");
36069
36221
  return;
36070
- const destinationStat = await import_fs_extra14.default.lstat(destinationPath).catch(() => null);
36071
- if (sourceStat.isDirectory() && destinationStat?.isDirectory()) {
36072
- const entries = await import_fs_extra14.default.readdir(sourcePath);
36073
- await import_fs_extra14.default.ensureDir(destinationPath);
36074
- for (const entry of entries) {
36075
- await mergeSessionPath({
36076
- sourcePath: path18.join(sourcePath, entry),
36077
- destinationPath: path18.join(destinationPath, entry),
36078
- folder,
36079
- sessionRoot,
36080
- snapshot,
36081
- sourceTag,
36082
- result
36083
- });
36084
- }
36222
+ }
36223
+ await import_fs_extra13.default.symlink(source, target, "dir");
36224
+ }
36225
+ async function createFileSymlink(source, target) {
36226
+ await import_fs_extra13.default.ensureDir(path17.dirname(target));
36227
+ if (os14.platform() === "win32") {
36228
+ await import_fs_extra13.default.symlink(source, target, "file");
36085
36229
  return;
36086
36230
  }
36087
- if (!destinationStat) {
36088
- await import_fs_extra14.default.ensureDir(path18.dirname(destinationPath));
36089
- await import_fs_extra14.default.copy(sourcePath, destinationPath, {
36090
- overwrite: false,
36091
- dereference: false
36092
- });
36093
- result.imported.push({
36094
- folder,
36095
- sessionRoot,
36096
- from: sourcePath,
36097
- to: destinationPath,
36098
- snapshot: snapshot.name
36099
- });
36231
+ await import_fs_extra13.default.symlink(source, target);
36232
+ }
36233
+ async function shouldLinkMissingContainer(candidate) {
36234
+ if (candidate.linkWhenMissing)
36235
+ return true;
36236
+ if (!candidate.linkWhenParentExists)
36237
+ return false;
36238
+ return import_fs_extra13.default.pathExists(path17.dirname(candidate.path));
36239
+ }
36240
+ async function linkContainer(candidate, destinationDir, result, dryRun = false) {
36241
+ if (candidate.linkSource === false) {
36100
36242
  return;
36101
36243
  }
36102
- if (await hashPath2(sourcePath) === await hashPath2(destinationPath)) {
36103
- result.duplicates.push({
36104
- folder,
36105
- sessionRoot,
36106
- from: sourcePath,
36107
- existing: destinationPath,
36108
- snapshot: snapshot.name
36244
+ if (candidate.isDestination || samePath(candidate.path, destinationDir)) {
36245
+ return;
36246
+ }
36247
+ const destinationRealPath = await realPathIfPossible(destinationDir);
36248
+ const stat = await import_fs_extra13.default.lstat(candidate.path).catch(() => null);
36249
+ if (!stat) {
36250
+ if (!await shouldLinkMissingContainer(candidate))
36251
+ return;
36252
+ if (!dryRun) {
36253
+ await createDirectorySymlink(destinationDir, candidate.path);
36254
+ }
36255
+ result.linked.push({
36256
+ category: candidate.category,
36257
+ from: candidate.path,
36258
+ to: destinationDir
36109
36259
  });
36110
36260
  return;
36111
36261
  }
36112
- const conflictPath = await uniqueConflictPath(destinationPath, sourceTag);
36113
- await import_fs_extra14.default.ensureDir(path18.dirname(conflictPath));
36114
- await import_fs_extra14.default.copy(sourcePath, conflictPath, {
36115
- overwrite: false,
36116
- dereference: false
36117
- });
36118
- result.conflicts.push({
36119
- folder,
36120
- sessionRoot,
36121
- from: sourcePath,
36122
- to: conflictPath,
36123
- snapshot: snapshot.name,
36124
- reason: "Same session path with different content"
36125
- });
36126
- }
36127
- async function unifySessionsFromSnapshots(options = {}) {
36128
- const folders = resolveFolders(options);
36129
- const snapshots = await collectSnapshotSources(folders);
36130
- const destinationByFolder = {
36131
- ".claude": folders.claudeDir,
36132
- ".codex": folders.codexDir,
36133
- ".agents": folders.agentsDir
36134
- };
36135
- const result = {
36136
- rootDir: folders.rootDir,
36137
- scannedSnapshots: snapshots,
36138
- imported: [],
36139
- duplicates: [],
36140
- conflicts: []
36141
- };
36142
- for (const snapshot of snapshots) {
36143
- const sourceTag = sanitizeSourceTag(snapshot);
36144
- for (const folder of MANAGED_FOLDERS2) {
36145
- const sourceFolder = await snapshotFolderPath(snapshot, folder);
36146
- if (!sourceFolder)
36147
- continue;
36148
- for (const sessionRoot of SESSION_PATHS[folder]) {
36149
- const sourcePath = path18.join(sourceFolder, sessionRoot);
36150
- if (!await import_fs_extra14.default.pathExists(sourcePath))
36151
- continue;
36152
- await mergeSessionPath({
36153
- sourcePath,
36154
- destinationPath: path18.join(destinationByFolder[folder], sessionRoot),
36155
- folder,
36156
- sessionRoot,
36157
- snapshot,
36158
- sourceTag,
36159
- result
36160
- });
36161
- }
36262
+ if (stat.isSymbolicLink()) {
36263
+ const existingRealPath = await realPathIfPossible(candidate.path);
36264
+ if (destinationRealPath && existingRealPath && samePath(destinationRealPath, existingRealPath)) {
36265
+ result.alreadyLinked.push({
36266
+ category: candidate.category,
36267
+ from: candidate.path,
36268
+ to: destinationDir
36269
+ });
36270
+ return;
36162
36271
  }
36272
+ if (!dryRun) {
36273
+ await import_fs_extra13.default.remove(candidate.path);
36274
+ await createDirectorySymlink(destinationDir, candidate.path);
36275
+ }
36276
+ result.linked.push({
36277
+ category: candidate.category,
36278
+ from: candidate.path,
36279
+ to: destinationDir
36280
+ });
36281
+ return;
36163
36282
  }
36164
- return result;
36165
- }
36166
-
36167
- // src/commands/session-unify.ts
36168
- function summarizeByFolder(entries) {
36169
- const counts = new Map;
36170
- for (const entry of entries) {
36171
- counts.set(entry.folder, (counts.get(entry.folder) ?? 0) + 1);
36283
+ const backupRoot = await ensureBackupPath(result, dryRun);
36284
+ const backupTarget = path17.join(backupRoot, safeRelativePath(result.rootDir, candidate.path));
36285
+ if (!dryRun) {
36286
+ await import_fs_extra13.default.ensureDir(path17.dirname(backupTarget));
36287
+ await import_fs_extra13.default.move(candidate.path, backupTarget, { overwrite: false });
36288
+ await createDirectorySymlink(destinationDir, candidate.path);
36172
36289
  }
36173
- if (counts.size === 0)
36174
- return "none";
36175
- return [...counts.entries()].map(([folder, count]) => `${folder}: ${count}`).join(", ");
36290
+ result.linked.push({
36291
+ category: candidate.category,
36292
+ from: candidate.path,
36293
+ to: destinationDir,
36294
+ movedToBackup: backupTarget
36295
+ });
36176
36296
  }
36177
- async function sessionsUnifyCommand(params = {}) {
36178
- try {
36179
- console.log(source_default.blue("Unifying saved sessions from configs and backups..."));
36180
- const result = await unifySessionsFromSnapshots(params);
36181
- console.log(source_default.green("Session unify complete"));
36182
- console.log(source_default.gray(` Snapshots scanned: ${result.scannedSnapshots.length}`));
36183
- console.log(source_default.gray(` Imported: ${result.imported.length} (${summarizeByFolder(result.imported)})`));
36184
- console.log(source_default.gray(` Duplicates skipped: ${result.duplicates.length}`));
36185
- console.log(source_default.gray(` Conflicts preserved: ${result.conflicts.length}`));
36186
- if (result.conflicts.length > 0) {
36187
- console.log(source_default.yellow(`
36188
- Conflicting session paths were copied with source suffixes:`));
36189
- for (const conflict of result.conflicts.slice(0, 10)) {
36190
- console.log(source_default.yellow(` ${conflict.to}`));
36191
- }
36192
- if (result.conflicts.length > 10) {
36193
- console.log(source_default.yellow(` ...and ${result.conflicts.length - 10} more`));
36194
- }
36297
+ async function importInstructionFiles(candidates, destinationPath, result, dryRun = false) {
36298
+ const destinationExists = await pathExistsOrSymlink(destinationPath);
36299
+ const destinationRealPath = destinationExists ? await realPathIfPossible(destinationPath) : null;
36300
+ const sourceCandidates = [];
36301
+ for (const candidate of candidates) {
36302
+ if (candidate.isDestination)
36303
+ continue;
36304
+ const sourceStat = await import_fs_extra13.default.lstat(candidate.path).catch(() => null);
36305
+ if (!sourceStat)
36306
+ continue;
36307
+ const sourceRealPath = await realPathIfPossible(candidate.path);
36308
+ if (destinationRealPath && sourceRealPath && samePath(destinationRealPath, sourceRealPath)) {
36309
+ continue;
36195
36310
  }
36196
- } catch (error) {
36197
- console.error(source_default.red("Session unify failed:"), error);
36198
- process.exit(1);
36311
+ sourceCandidates.push(candidate);
36199
36312
  }
36200
- }
36201
-
36202
- // node_modules/@clack/core/dist/index.mjs
36203
- var import_sisteransi = __toESM(require_src(), 1);
36204
- var import_picocolors = __toESM(require_picocolors(), 1);
36205
- import { stdin as j, stdout as M } from "node:process";
36206
- import * as g from "node:readline";
36207
- import O from "node:readline";
36208
- import { Writable as X } from "node:stream";
36209
- function DD({ onlyFirst: e = false } = {}) {
36210
- const t = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
36211
- return new RegExp(t, e ? undefined : "g");
36212
- }
36213
- var uD = DD();
36214
- function P(e) {
36215
- if (typeof e != "string")
36216
- throw new TypeError(`Expected a \`string\`, got \`${typeof e}\``);
36217
- return e.replace(uD, "");
36218
- }
36219
- function L(e) {
36220
- return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
36221
- }
36222
- var W = { exports: {} };
36223
- (function(e) {
36224
- var u = {};
36225
- e.exports = u, u.eastAsianWidth = function(F) {
36226
- var s = F.charCodeAt(0), i = F.length == 2 ? F.charCodeAt(1) : 0, D = s;
36227
- return 55296 <= s && s <= 56319 && 56320 <= i && i <= 57343 && (s &= 1023, i &= 1023, D = s << 10 | i, D += 65536), D == 12288 || 65281 <= D && D <= 65376 || 65504 <= D && D <= 65510 ? "F" : D == 8361 || 65377 <= D && D <= 65470 || 65474 <= D && D <= 65479 || 65482 <= D && D <= 65487 || 65490 <= D && D <= 65495 || 65498 <= D && D <= 65500 || 65512 <= D && D <= 65518 ? "H" : 4352 <= D && D <= 4447 || 4515 <= D && D <= 4519 || 4602 <= D && D <= 4607 || 9001 <= D && D <= 9002 || 11904 <= D && D <= 11929 || 11931 <= D && D <= 12019 || 12032 <= D && D <= 12245 || 12272 <= D && D <= 12283 || 12289 <= D && D <= 12350 || 12353 <= D && D <= 12438 || 12441 <= D && D <= 12543 || 12549 <= D && D <= 12589 || 12593 <= D && D <= 12686 || 12688 <= D && D <= 12730 || 12736 <= D && D <= 12771 || 12784 <= D && D <= 12830 || 12832 <= D && D <= 12871 || 12880 <= D && D <= 13054 || 13056 <= D && D <= 19903 || 19968 <= D && D <= 42124 || 42128 <= D && D <= 42182 || 43360 <= D && D <= 43388 || 44032 <= D && D <= 55203 || 55216 <= D && D <= 55238 || 55243 <= D && D <= 55291 || 63744 <= D && D <= 64255 || 65040 <= D && D <= 65049 || 65072 <= D && D <= 65106 || 65108 <= D && D <= 65126 || 65128 <= D && D <= 65131 || 110592 <= D && D <= 110593 || 127488 <= D && D <= 127490 || 127504 <= D && D <= 127546 || 127552 <= D && D <= 127560 || 127568 <= D && D <= 127569 || 131072 <= D && D <= 194367 || 177984 <= D && D <= 196605 || 196608 <= D && D <= 262141 ? "W" : 32 <= D && D <= 126 || 162 <= D && D <= 163 || 165 <= D && D <= 166 || D == 172 || D == 175 || 10214 <= D && D <= 10221 || 10629 <= D && D <= 10630 ? "Na" : D == 161 || D == 164 || 167 <= D && D <= 168 || D == 170 || 173 <= D && D <= 174 || 176 <= D && D <= 180 || 182 <= D && D <= 186 || 188 <= D && D <= 191 || D == 198 || D == 208 || 215 <= D && D <= 216 || 222 <= D && D <= 225 || D == 230 || 232 <= D && D <= 234 || 236 <= D && D <= 237 || D == 240 || 242 <= D && D <= 243 || 247 <= D && D <= 250 || D == 252 || D == 254 || D == 257 || D == 273 || D == 275 || D == 283 || 294 <= D && D <= 295 || D == 299 || 305 <= D && D <= 307 || D == 312 || 319 <= D && D <= 322 || D == 324 || 328 <= D && D <= 331 || D == 333 || 338 <= D && D <= 339 || 358 <= D && D <= 359 || D == 363 || D == 462 || D == 464 || D == 466 || D == 468 || D == 470 || D == 472 || D == 474 || D == 476 || D == 593 || D == 609 || D == 708 || D == 711 || 713 <= D && D <= 715 || D == 717 || D == 720 || 728 <= D && D <= 731 || D == 733 || D == 735 || 768 <= D && D <= 879 || 913 <= D && D <= 929 || 931 <= D && D <= 937 || 945 <= D && D <= 961 || 963 <= D && D <= 969 || D == 1025 || 1040 <= D && D <= 1103 || D == 1105 || D == 8208 || 8211 <= D && D <= 8214 || 8216 <= D && D <= 8217 || 8220 <= D && D <= 8221 || 8224 <= D && D <= 8226 || 8228 <= D && D <= 8231 || D == 8240 || 8242 <= D && D <= 8243 || D == 8245 || D == 8251 || D == 8254 || D == 8308 || D == 8319 || 8321 <= D && D <= 8324 || D == 8364 || D == 8451 || D == 8453 || D == 8457 || D == 8467 || D == 8470 || 8481 <= D && D <= 8482 || D == 8486 || D == 8491 || 8531 <= D && D <= 8532 || 8539 <= D && D <= 8542 || 8544 <= D && D <= 8555 || 8560 <= D && D <= 8569 || D == 8585 || 8592 <= D && D <= 8601 || 8632 <= D && D <= 8633 || D == 8658 || D == 8660 || D == 8679 || D == 8704 || 8706 <= D && D <= 8707 || 8711 <= D && D <= 8712 || D == 8715 || D == 8719 || D == 8721 || D == 8725 || D == 8730 || 8733 <= D && D <= 8736 || D == 8739 || D == 8741 || 8743 <= D && D <= 8748 || D == 8750 || 8756 <= D && D <= 8759 || 8764 <= D && D <= 8765 || D == 8776 || D == 8780 || D == 8786 || 8800 <= D && D <= 8801 || 8804 <= D && D <= 8807 || 8810 <= D && D <= 8811 || 8814 <= D && D <= 8815 || 8834 <= D && D <= 8835 || 8838 <= D && D <= 8839 || D == 8853 || D == 8857 || D == 8869 || D == 8895 || D == 8978 || 9312 <= D && D <= 9449 || 9451 <= D && D <= 9547 || 9552 <= D && D <= 9587 || 9600 <= D && D <= 9615 || 9618 <= D && D <= 9621 || 9632 <= D && D <= 9633 || 9635 <= D && D <= 9641 || 9650 <= D && D <= 9651 || 9654 <= D && D <= 9655 || 9660 <= D && D <= 9661 || 9664 <= D && D <= 9665 || 9670 <= D && D <= 9672 || D == 9675 || 9678 <= D && D <= 9681 || 9698 <= D && D <= 9701 || D == 9711 || 9733 <= D && D <= 9734 || D == 9737 || 9742 <= D && D <= 9743 || 9748 <= D && D <= 9749 || D == 9756 || D == 9758 || D == 9792 || D == 9794 || 9824 <= D && D <= 9825 || 9827 <= D && D <= 9829 || 9831 <= D && D <= 9834 || 9836 <= D && D <= 9837 || D == 9839 || 9886 <= D && D <= 9887 || 9918 <= D && D <= 9919 || 9924 <= D && D <= 9933 || 9935 <= D && D <= 9953 || D == 9955 || 9960 <= D && D <= 9983 || D == 10045 || D == 10071 || 10102 <= D && D <= 10111 || 11093 <= D && D <= 11097 || 12872 <= D && D <= 12879 || 57344 <= D && D <= 63743 || 65024 <= D && D <= 65039 || D == 65533 || 127232 <= D && D <= 127242 || 127248 <= D && D <= 127277 || 127280 <= D && D <= 127337 || 127344 <= D && D <= 127386 || 917760 <= D && D <= 917999 || 983040 <= D && D <= 1048573 || 1048576 <= D && D <= 1114109 ? "A" : "N";
36228
- }, u.characterLength = function(F) {
36229
- var s = this.eastAsianWidth(F);
36230
- return s == "F" || s == "W" || s == "A" ? 2 : 1;
36231
- };
36232
- function t(F) {
36233
- return F.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
36313
+ if (!destinationExists && sourceCandidates.length === 0) {
36314
+ return false;
36234
36315
  }
36235
- u.length = function(F) {
36236
- for (var s = t(F), i = 0, D = 0;D < s.length; D++)
36237
- i = i + this.characterLength(s[D]);
36238
- return i;
36239
- }, u.slice = function(F, s, i) {
36240
- textLen = u.length(F), s = s || 0, i = i || 1, s < 0 && (s = textLen + s), i < 0 && (i = textLen + i);
36241
- for (var D = "", C = 0, n = t(F), E = 0;E < n.length; E++) {
36242
- var a = n[E], o = u.length(a);
36243
- if (C >= s - (o == 2 ? 1 : 0))
36244
- if (C + o <= i)
36245
- D += a;
36246
- else
36247
- break;
36248
- C += o;
36316
+ if (!dryRun) {
36317
+ await import_fs_extra13.default.ensureDir(path17.dirname(destinationPath));
36318
+ }
36319
+ let destinationHash = destinationExists ? await hashPath(destinationPath) : null;
36320
+ const plannedNames = new Set;
36321
+ for (const candidate of sourceCandidates) {
36322
+ const sourceHash = await hashPath(candidate.path);
36323
+ if (!destinationHash) {
36324
+ if (!dryRun) {
36325
+ await import_fs_extra13.default.copy(candidate.path, destinationPath, {
36326
+ dereference: false,
36327
+ overwrite: false
36328
+ });
36329
+ }
36330
+ destinationHash = sourceHash;
36331
+ plannedNames.add(path17.basename(destinationPath));
36332
+ result.imported.push({
36333
+ category: "instructions",
36334
+ name: path17.basename(candidate.path),
36335
+ from: candidate.path,
36336
+ to: destinationPath
36337
+ });
36338
+ continue;
36249
36339
  }
36250
- return D;
36251
- };
36252
- })(W);
36253
- var tD = W.exports;
36254
- var eD = L(tD);
36255
- var FD = function() {
36256
- return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
36257
- };
36258
- var sD = L(FD);
36259
- function p(e, u = {}) {
36260
- if (typeof e != "string" || e.length === 0 || (u = { ambiguousIsNarrow: true, ...u }, e = P(e), e.length === 0))
36261
- return 0;
36262
- e = e.replace(sD(), " ");
36263
- const t = u.ambiguousIsNarrow ? 1 : 2;
36264
- let F = 0;
36265
- for (const s of e) {
36266
- const i = s.codePointAt(0);
36267
- if (i <= 31 || i >= 127 && i <= 159 || i >= 768 && i <= 879)
36340
+ if (sourceHash === destinationHash) {
36341
+ result.duplicates.push({
36342
+ category: "instructions",
36343
+ name: path17.basename(candidate.path),
36344
+ from: candidate.path,
36345
+ keptAs: destinationPath
36346
+ });
36268
36347
  continue;
36269
- switch (eD.eastAsianWidth(s)) {
36270
- case "F":
36271
- case "W":
36272
- F += 2;
36273
- break;
36274
- case "A":
36275
- F += t;
36276
- break;
36277
- default:
36278
- F += 1;
36279
36348
  }
36349
+ const targetName = await findAvailableTargetName(path17.dirname(destinationPath), path17.basename(destinationPath), candidate.label, plannedNames);
36350
+ const targetPath = path17.join(path17.dirname(destinationPath), targetName);
36351
+ if (!dryRun) {
36352
+ await import_fs_extra13.default.copy(candidate.path, targetPath, {
36353
+ dereference: false,
36354
+ overwrite: false
36355
+ });
36356
+ }
36357
+ plannedNames.add(targetName);
36358
+ result.renamed.push({
36359
+ category: "instructions",
36360
+ name: path17.basename(candidate.path),
36361
+ from: candidate.path,
36362
+ to: targetPath,
36363
+ reason: "Shared instruction file already exists with different content"
36364
+ });
36280
36365
  }
36281
- return F;
36366
+ return true;
36282
36367
  }
36283
- var w = 10;
36284
- var N = (e = 0) => (u) => `\x1B[${u + e}m`;
36285
- var I = (e = 0) => (u) => `\x1B[${38 + e};5;${u}m`;
36286
- var R = (e = 0) => (u, t, F) => `\x1B[${38 + e};2;${u};${t};${F}m`;
36287
- var r = { modifier: { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], blackBright: [90, 39], gray: [90, 39], grey: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgGray: [100, 49], bgGrey: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } };
36288
- Object.keys(r.modifier);
36289
- var iD = Object.keys(r.color);
36290
- var CD = Object.keys(r.bgColor);
36291
- [...iD, ...CD];
36292
- function rD() {
36293
- const e = new Map;
36294
- for (const [u, t] of Object.entries(r)) {
36295
- for (const [F, s] of Object.entries(t))
36296
- r[F] = { open: `\x1B[${s[0]}m`, close: `\x1B[${s[1]}m` }, t[F] = r[F], e.set(s[0], s[1]);
36297
- Object.defineProperty(r, u, { value: t, enumerable: false });
36298
- }
36299
- return Object.defineProperty(r, "codes", { value: e, enumerable: false }), r.color.close = "\x1B[39m", r.bgColor.close = "\x1B[49m", r.color.ansi = N(), r.color.ansi256 = I(), r.color.ansi16m = R(), r.bgColor.ansi = N(w), r.bgColor.ansi256 = I(w), r.bgColor.ansi16m = R(w), Object.defineProperties(r, { rgbToAnsi256: { value: (u, t, F) => u === t && t === F ? u < 8 ? 16 : u > 248 ? 231 : Math.round((u - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(u / 255 * 5) + 6 * Math.round(t / 255 * 5) + Math.round(F / 255 * 5), enumerable: false }, hexToRgb: { value: (u) => {
36300
- const t = /[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));
36301
- if (!t)
36302
- return [0, 0, 0];
36303
- let [F] = t;
36304
- F.length === 3 && (F = [...F].map((i) => i + i).join(""));
36305
- const s = Number.parseInt(F, 16);
36306
- return [s >> 16 & 255, s >> 8 & 255, s & 255];
36307
- }, enumerable: false }, hexToAnsi256: { value: (u) => r.rgbToAnsi256(...r.hexToRgb(u)), enumerable: false }, ansi256ToAnsi: { value: (u) => {
36308
- if (u < 8)
36309
- return 30 + u;
36310
- if (u < 16)
36311
- return 90 + (u - 8);
36312
- let t, F, s;
36313
- if (u >= 232)
36314
- t = ((u - 232) * 10 + 8) / 255, F = t, s = t;
36315
- else {
36316
- u -= 16;
36317
- const C = u % 36;
36318
- t = Math.floor(u / 36) / 5, F = Math.floor(C / 6) / 5, s = C % 6 / 5;
36319
- }
36320
- const i = Math.max(t, F, s) * 2;
36321
- if (i === 0)
36322
- return 30;
36323
- let D = 30 + (Math.round(s) << 2 | Math.round(F) << 1 | Math.round(t));
36324
- return i === 2 && (D += 60), D;
36325
- }, enumerable: false }, rgbToAnsi: { value: (u, t, F) => r.ansi256ToAnsi(r.rgbToAnsi256(u, t, F)), enumerable: false }, hexToAnsi: { value: (u) => r.ansi256ToAnsi(r.hexToAnsi256(u)), enumerable: false } }), r;
36368
+ async function shouldLinkMissingInstruction(candidate) {
36369
+ if (candidate.linkWhenMissing)
36370
+ return true;
36371
+ return false;
36326
36372
  }
36327
- var ED = rD();
36328
- var d = new Set(["\x1B", "›"]);
36329
- var oD = 39;
36330
- var y = "\x07";
36331
- var V = "[";
36332
- var nD = "]";
36333
- var G = "m";
36334
- var _2 = `${nD}8;;`;
36335
- var z = (e) => `${d.values().next().value}${V}${e}${G}`;
36336
- var K = (e) => `${d.values().next().value}${_2}${e}${y}`;
36337
- var aD = (e) => e.split(" ").map((u) => p(u));
36338
- var k = (e, u, t) => {
36339
- const F = [...u];
36340
- let s = false, i = false, D = p(P(e[e.length - 1]));
36341
- for (const [C, n] of F.entries()) {
36342
- const E = p(n);
36343
- if (D + E <= t ? e[e.length - 1] += n : (e.push(n), D = 0), d.has(n) && (s = true, i = F.slice(C + 1).join("").startsWith(_2)), s) {
36344
- i ? n === y && (s = false, i = false) : n === G && (s = false);
36345
- continue;
36373
+ async function linkInstructionFile(candidate, destinationPath, result, dryRun = false) {
36374
+ if (candidate.isDestination || samePath(candidate.path, destinationPath)) {
36375
+ return;
36376
+ }
36377
+ if (!await pathExistsOrSymlink(destinationPath)) {
36378
+ return;
36379
+ }
36380
+ const destinationRealPath = await realPathIfPossible(destinationPath);
36381
+ const stat = await import_fs_extra13.default.lstat(candidate.path).catch(() => null);
36382
+ if (!stat) {
36383
+ if (!await shouldLinkMissingInstruction(candidate))
36384
+ return;
36385
+ if (!dryRun) {
36386
+ await createFileSymlink(destinationPath, candidate.path);
36346
36387
  }
36347
- D += E, D === t && C < F.length - 1 && (e.push(""), D = 0);
36388
+ result.linked.push({
36389
+ category: "instructions",
36390
+ from: candidate.path,
36391
+ to: destinationPath
36392
+ });
36393
+ return;
36348
36394
  }
36349
- !D && e[e.length - 1].length > 0 && e.length > 1 && (e[e.length - 2] += e.pop());
36350
- };
36351
- var hD = (e) => {
36352
- const u = e.split(" ");
36353
- let t = u.length;
36354
- for (;t > 0 && !(p(u[t - 1]) > 0); )
36355
- t--;
36356
- return t === u.length ? e : u.slice(0, t).join(" ") + u.slice(t).join("");
36357
- };
36358
- var lD = (e, u, t = {}) => {
36359
- if (t.trim !== false && e.trim() === "")
36360
- return "";
36361
- let F = "", s, i;
36362
- const D = aD(e);
36363
- let C = [""];
36364
- for (const [E, a] of e.split(" ").entries()) {
36365
- t.trim !== false && (C[C.length - 1] = C[C.length - 1].trimStart());
36366
- let o = p(C[C.length - 1]);
36367
- if (E !== 0 && (o >= u && (t.wordWrap === false || t.trim === false) && (C.push(""), o = 0), (o > 0 || t.trim === false) && (C[C.length - 1] += " ", o++)), t.hard && D[E] > u) {
36368
- const c = u - o, f = 1 + Math.floor((D[E] - c - 1) / u);
36369
- Math.floor((D[E] - 1) / u) < f && C.push(""), k(C, a, u);
36370
- continue;
36395
+ if (stat.isSymbolicLink()) {
36396
+ const existingRealPath = await realPathIfPossible(candidate.path);
36397
+ if (destinationRealPath && existingRealPath && samePath(destinationRealPath, existingRealPath)) {
36398
+ result.alreadyLinked.push({
36399
+ category: "instructions",
36400
+ from: candidate.path,
36401
+ to: destinationPath
36402
+ });
36403
+ return;
36371
36404
  }
36372
- if (o + D[E] > u && o > 0 && D[E] > 0) {
36373
- if (t.wordWrap === false && o < u) {
36374
- k(C, a, u);
36375
- continue;
36376
- }
36377
- C.push("");
36405
+ if (!dryRun) {
36406
+ await import_fs_extra13.default.remove(candidate.path);
36407
+ await createFileSymlink(destinationPath, candidate.path);
36378
36408
  }
36379
- if (o + D[E] > u && t.wordWrap === false) {
36380
- k(C, a, u);
36409
+ result.linked.push({
36410
+ category: "instructions",
36411
+ from: candidate.path,
36412
+ to: destinationPath
36413
+ });
36414
+ return;
36415
+ }
36416
+ const backupRoot = await ensureBackupPath(result, dryRun);
36417
+ const backupTarget = path17.join(backupRoot, safeRelativePath(result.rootDir, candidate.path));
36418
+ if (!dryRun) {
36419
+ await import_fs_extra13.default.ensureDir(path17.dirname(backupTarget));
36420
+ await import_fs_extra13.default.move(candidate.path, backupTarget, { overwrite: false });
36421
+ await createFileSymlink(destinationPath, candidate.path);
36422
+ }
36423
+ result.linked.push({
36424
+ category: "instructions",
36425
+ from: candidate.path,
36426
+ to: destinationPath,
36427
+ movedToBackup: backupTarget
36428
+ });
36429
+ }
36430
+ var RULES_INDEX_START = "<!-- AIBLUEPRINT:RULES:START -->";
36431
+ var RULES_INDEX_END = "<!-- AIBLUEPRINT:RULES:END -->";
36432
+ function titleFromRulePath(rulePath) {
36433
+ return path17.basename(rulePath, path17.extname(rulePath)).replace(/[-_]+/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase());
36434
+ }
36435
+ async function readRuleTitle(rulePath) {
36436
+ const content = await import_fs_extra13.default.readFile(rulePath, "utf-8").catch(() => "");
36437
+ const heading = content.match(/^#\s+(.+)$/m)?.[1]?.trim();
36438
+ return heading || titleFromRulePath(rulePath);
36439
+ }
36440
+ async function collectRuleIndexEntries(rulesDir, rootDir, currentDir = rulesDir) {
36441
+ const entries = await import_fs_extra13.default.readdir(currentDir, { withFileTypes: true }).catch(() => []);
36442
+ const rules = [];
36443
+ for (const entry of entries) {
36444
+ if (IGNORED_ENTRY_NAMES2.has(entry.name))
36445
+ continue;
36446
+ const entryPath = path17.join(currentDir, entry.name);
36447
+ if (entry.isDirectory()) {
36448
+ rules.push(...await collectRuleIndexEntries(rulesDir, rootDir, entryPath));
36381
36449
  continue;
36382
36450
  }
36383
- C[C.length - 1] += a;
36451
+ if (!entry.isFile() && !entry.isSymbolicLink())
36452
+ continue;
36453
+ if (![".md", ".mdc"].includes(path17.extname(entry.name).toLowerCase()))
36454
+ continue;
36455
+ rules.push({
36456
+ title: await readRuleTitle(entryPath),
36457
+ relativePath: path17.relative(rootDir, entryPath)
36458
+ });
36384
36459
  }
36385
- t.trim !== false && (C = C.map((E) => hD(E)));
36386
- const n = [...C.join(`
36387
- `)];
36388
- for (const [E, a] of n.entries()) {
36389
- if (F += a, d.has(a)) {
36390
- const { groups: c } = new RegExp(`(?:\\${V}(?<code>\\d+)m|\\${_2}(?<uri>.*)${y})`).exec(n.slice(E).join("")) || { groups: {} };
36391
- if (c.code !== undefined) {
36392
- const f = Number.parseFloat(c.code);
36393
- s = f === oD ? undefined : f;
36394
- } else
36395
- c.uri !== undefined && (i = c.uri.length === 0 ? undefined : c.uri);
36460
+ return rules.sort((a, b3) => a.relativePath.localeCompare(b3.relativePath));
36461
+ }
36462
+ function stripGeneratedRulesIndex(content) {
36463
+ const start = content.indexOf(RULES_INDEX_START);
36464
+ const end = content.indexOf(RULES_INDEX_END);
36465
+ if (start === -1 || end === -1 || end < start) {
36466
+ return content.trimEnd();
36467
+ }
36468
+ const beforeStart = content.slice(0, start);
36469
+ const headingIndex = beforeStart.lastIndexOf(`
36470
+ ## Rules`);
36471
+ const blockStart = headingIndex === -1 ? start : headingIndex + 1;
36472
+ return `${content.slice(0, blockStart).trimEnd()}
36473
+ ${content.slice(end + RULES_INDEX_END.length).trimStart()}`.trimEnd();
36474
+ }
36475
+ function renderRulesIndexBlock(rules) {
36476
+ const lines = [
36477
+ "## Rules",
36478
+ "",
36479
+ "Detailed focused rules live in `.agents/rules/`. Read the relevant file before acting:",
36480
+ "",
36481
+ RULES_INDEX_START
36482
+ ];
36483
+ if (rules.length === 0) {
36484
+ lines.push("- No repository rules found yet.");
36485
+ } else {
36486
+ for (const rule of rules) {
36487
+ lines.push(`- **${rule.title}** - [${rule.relativePath}](${rule.relativePath})`);
36396
36488
  }
36397
- const o = ED.codes.get(Number(s));
36398
- n[E + 1] === `
36399
- ` ? (i && (F += K("")), s && o && (F += z(o))) : a === `
36400
- ` && (s && o && (F += z(s)), i && (F += K(i)));
36401
36489
  }
36402
- return F;
36403
- };
36404
- function Y(e, u, t) {
36405
- return String(e).normalize().replace(/\r\n/g, `
36406
- `).split(`
36407
- `).map((F) => lD(F, u, t)).join(`
36490
+ lines.push(RULES_INDEX_END);
36491
+ return lines.join(`
36408
36492
  `);
36409
36493
  }
36410
- var xD = ["up", "down", "left", "right", "space", "enter", "cancel"];
36411
- var B = { actions: new Set(xD), aliases: new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["\x03", "cancel"], ["escape", "cancel"]]) };
36412
- function $(e, u) {
36413
- if (typeof e == "string")
36414
- return B.aliases.get(e) === u;
36415
- for (const t of e)
36416
- if (t !== undefined && $(t, u))
36417
- return true;
36418
- return false;
36494
+ async function readExistingInstructions(rootDir) {
36495
+ const agentsPath = path17.join(rootDir, "AGENTS.md");
36496
+ const claudePath = path17.join(rootDir, "CLAUDE.md");
36497
+ const agentsContent = await import_fs_extra13.default.readFile(agentsPath, "utf-8").catch(() => null);
36498
+ const claudeContent = await import_fs_extra13.default.readFile(claudePath, "utf-8").catch(() => null);
36499
+ if (agentsContent !== null && claudeContent !== null && agentsContent.trim() !== claudeContent.trim()) {
36500
+ return `${agentsContent.trimEnd()}
36501
+
36502
+ ## Previous Claude Instructions
36503
+
36504
+ ${claudeContent.trimStart()}`;
36505
+ }
36506
+ if (agentsContent !== null)
36507
+ return agentsContent;
36508
+ if (claudeContent !== null)
36509
+ return claudeContent;
36510
+ return `# Repository Instructions
36511
+ `;
36419
36512
  }
36420
- function BD(e, u) {
36421
- if (e === u)
36422
- return;
36423
- const t = e.split(`
36424
- `), F = u.split(`
36425
- `), s = [];
36426
- for (let i = 0;i < Math.max(t.length, F.length); i++)
36427
- t[i] !== F[i] && s.push(i);
36428
- return s;
36513
+ async function copyPathToBackup(result, targetPath) {
36514
+ const stat = await import_fs_extra13.default.lstat(targetPath).catch(() => null);
36515
+ if (!stat)
36516
+ return null;
36517
+ const backupRoot = await ensureBackupPath(result);
36518
+ const backupTarget = path17.join(backupRoot, safeRelativePath(result.rootDir, targetPath));
36519
+ await import_fs_extra13.default.ensureDir(path17.dirname(backupTarget));
36520
+ await import_fs_extra13.default.copy(targetPath, backupTarget, {
36521
+ dereference: false,
36522
+ overwrite: false
36523
+ });
36524
+ return backupTarget;
36429
36525
  }
36430
- var AD = globalThis.process.platform.startsWith("win");
36431
- var S = Symbol("clack:cancel");
36432
- function pD(e) {
36433
- return e === S;
36526
+ async function planPathBackup(result, targetPath) {
36527
+ const stat = await import_fs_extra13.default.lstat(targetPath).catch(() => null);
36528
+ if (!stat)
36529
+ return null;
36530
+ const backupRoot = await ensureBackupPath(result, true);
36531
+ return path17.join(backupRoot, safeRelativePath(result.rootDir, targetPath));
36434
36532
  }
36435
- function m(e, u) {
36436
- const t = e;
36437
- t.isTTY && t.setRawMode(u);
36533
+ async function replaceWithFileSymlink(sourcePath, targetPath) {
36534
+ await import_fs_extra13.default.ensureDir(path17.dirname(targetPath));
36535
+ const relativeSource = path17.relative(path17.dirname(targetPath), sourcePath) || path17.basename(sourcePath);
36536
+ await import_fs_extra13.default.symlink(relativeSource, targetPath, "file");
36438
36537
  }
36439
- function fD({ input: e = j, output: u = M, overwrite: t = true, hideCursor: F = true } = {}) {
36440
- const s = g.createInterface({ input: e, output: u, prompt: "", tabSize: 1 });
36441
- g.emitKeypressEvents(e, s), e.isTTY && e.setRawMode(true);
36442
- const i = (D, { name: C, sequence: n }) => {
36443
- const E = String(D);
36444
- if ($([E, C, n], "cancel")) {
36445
- F && u.write(import_sisteransi.cursor.show), process.exit(0);
36538
+ async function ensureClaudeInstructionSymlink(result, agentsPath, claudePath, dryRun = false) {
36539
+ const agentsRealPath = await realPathIfPossible(agentsPath);
36540
+ const claudeStat = await import_fs_extra13.default.lstat(claudePath).catch(() => null);
36541
+ if (claudeStat?.isSymbolicLink()) {
36542
+ const claudeRealPath = await realPathIfPossible(claudePath);
36543
+ if (agentsRealPath && claudeRealPath && samePath(agentsRealPath, claudeRealPath)) {
36446
36544
  return;
36447
36545
  }
36448
- if (!t)
36449
- return;
36450
- const a = C === "return" ? 0 : -1, o = C === "return" ? -1 : 0;
36451
- g.moveCursor(u, a, o, () => {
36452
- g.clearLine(u, 1, () => {
36453
- e.once("keypress", i);
36454
- });
36455
- });
36456
- };
36457
- return F && u.write(import_sisteransi.cursor.hide), e.once("keypress", i), () => {
36458
- e.off("keypress", i), F && u.write(import_sisteransi.cursor.show), e.isTTY && !AD && e.setRawMode(false), s.terminal = false, s.close();
36459
- };
36546
+ }
36547
+ if (claudeStat) {
36548
+ if (dryRun) {
36549
+ await planPathBackup(result, claudePath);
36550
+ } else {
36551
+ await copyPathToBackup(result, claudePath);
36552
+ await import_fs_extra13.default.remove(claudePath);
36553
+ }
36554
+ }
36555
+ if (!dryRun) {
36556
+ await replaceWithFileSymlink(agentsPath, claudePath);
36557
+ }
36558
+ result.linked.push({
36559
+ category: "instructions",
36560
+ from: claudePath,
36561
+ to: agentsPath
36562
+ });
36460
36563
  }
36461
- var gD = Object.defineProperty;
36462
- var vD = (e, u, t) => (u in e) ? gD(e, u, { enumerable: true, configurable: true, writable: true, value: t }) : e[u] = t;
36463
- var h = (e, u, t) => (vD(e, typeof u != "symbol" ? u + "" : u, t), t);
36464
-
36465
- class x {
36466
- constructor(u, t = true) {
36467
- h(this, "input"), h(this, "output"), h(this, "_abortSignal"), h(this, "rl"), h(this, "opts"), h(this, "_render"), h(this, "_track", false), h(this, "_prevFrame", ""), h(this, "_subscribers", new Map), h(this, "_cursor", 0), h(this, "state", "initial"), h(this, "error", ""), h(this, "value");
36468
- const { input: F = j, output: s = M, render: i, signal: D, ...C } = u;
36469
- this.opts = C, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = i.bind(this), this._track = t, this._abortSignal = D, this.input = F, this.output = s;
36564
+ async function writeRepositoryInstructionIndex(result, folders, dryRun = false) {
36565
+ const rulesDir = path17.join(folders.agentsDir, "rules");
36566
+ if (!dryRun && !await pathExistsOrSymlink(rulesDir)) {
36567
+ return;
36470
36568
  }
36471
- unsubscribe() {
36472
- this._subscribers.clear();
36569
+ const rules = dryRun ? await collectPlannedRuleIndexEntries(result, folders.rootDir) : await collectRuleIndexEntries(rulesDir, folders.rootDir);
36570
+ if (rules.length === 0) {
36571
+ return;
36473
36572
  }
36474
- setSubscriber(u, t) {
36475
- const F = this._subscribers.get(u) ?? [];
36476
- F.push(t), this._subscribers.set(u, F);
36573
+ const existing = stripGeneratedRulesIndex(await readExistingInstructions(folders.rootDir));
36574
+ const content = `${existing}
36575
+
36576
+ ${renderRulesIndexBlock(rules)}
36577
+ `;
36578
+ const agentsPath = path17.join(folders.rootDir, "AGENTS.md");
36579
+ const claudePath = path17.join(folders.rootDir, "CLAUDE.md");
36580
+ const agentsStat = await import_fs_extra13.default.lstat(agentsPath).catch(() => null);
36581
+ if (agentsStat) {
36582
+ if (dryRun) {
36583
+ await planPathBackup(result, agentsPath);
36584
+ } else {
36585
+ await copyPathToBackup(result, agentsPath);
36586
+ if (agentsStat.isSymbolicLink()) {
36587
+ await import_fs_extra13.default.remove(agentsPath);
36588
+ }
36589
+ }
36477
36590
  }
36478
- on(u, t) {
36479
- this.setSubscriber(u, { cb: t });
36591
+ if (!dryRun) {
36592
+ await import_fs_extra13.default.writeFile(agentsPath, content, "utf-8");
36480
36593
  }
36481
- once(u, t) {
36482
- this.setSubscriber(u, { cb: t, once: true });
36594
+ await ensureClaudeInstructionSymlink(result, agentsPath, claudePath, dryRun);
36595
+ result.instructionIndex = {
36596
+ agentsPath,
36597
+ claudePath,
36598
+ indexedRules: rules.map((rule) => rule.relativePath)
36599
+ };
36600
+ }
36601
+ async function collectPlannedRuleIndexEntries(result, rootDir) {
36602
+ const rules = [];
36603
+ const plannedRuleEntries = [
36604
+ ...result.imported.filter((entry) => entry.category === "rules"),
36605
+ ...result.renamed.filter((entry) => entry.category === "rules")
36606
+ ];
36607
+ for (const entry of plannedRuleEntries) {
36608
+ const ext = path17.extname(entry.to).toLowerCase();
36609
+ if (![".md", ".mdc"].includes(ext))
36610
+ continue;
36611
+ rules.push({
36612
+ title: await readRuleTitle(entry.from),
36613
+ relativePath: path17.relative(rootDir, entry.to)
36614
+ });
36483
36615
  }
36484
- emit(u, ...t) {
36485
- const F = this._subscribers.get(u) ?? [], s = [];
36486
- for (const i of F)
36487
- i.cb(...t), i.once && s.push(() => F.splice(F.indexOf(i), 1));
36488
- for (const i of s)
36489
- i();
36616
+ if (await pathExistsOrSymlink(path17.join(rootDir, ".agents", "rules"))) {
36617
+ rules.push(...await collectRuleIndexEntries(path17.join(rootDir, ".agents", "rules"), rootDir));
36490
36618
  }
36491
- prompt() {
36492
- return new Promise((u, t) => {
36493
- if (this._abortSignal) {
36494
- if (this._abortSignal.aborted)
36495
- return this.state = "cancel", this.close(), u(S);
36496
- this._abortSignal.addEventListener("abort", () => {
36497
- this.state = "cancel", this.close();
36498
- }, { once: true });
36499
- }
36500
- const F = new X;
36501
- F._write = (s, i, D) => {
36502
- this._track && (this.value = this.rl?.line.replace(/\t/g, ""), this._cursor = this.rl?.cursor ?? 0, this.emit("value", this.value)), D();
36503
- }, this.input.pipe(F), this.rl = O.createInterface({ input: this.input, output: F, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), O.emitKeypressEvents(this.input, this.rl), this.rl.prompt(), this.opts.initialValue !== undefined && this._track && this.rl.write(this.opts.initialValue), this.input.on("keypress", this.onKeypress), m(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
36504
- this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), m(this.input, false), u(this.value);
36505
- }), this.once("cancel", () => {
36506
- this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), m(this.input, false), u(S);
36507
- });
36508
- });
36619
+ const byPath = new Map;
36620
+ for (const rule of rules) {
36621
+ byPath.set(rule.relativePath, rule);
36509
36622
  }
36510
- onKeypress(u, t) {
36511
- if (this.state === "error" && (this.state = "active"), t?.name && (!this._track && B.aliases.has(t.name) && this.emit("cursor", B.aliases.get(t.name)), B.actions.has(t.name) && this.emit("cursor", t.name)), u && (u.toLowerCase() === "y" || u.toLowerCase() === "n") && this.emit("confirm", u.toLowerCase() === "y"), u === "\t" && this.opts.placeholder && (this.value || (this.rl?.write(this.opts.placeholder), this.emit("value", this.opts.placeholder))), u && this.emit("key", u.toLowerCase()), t?.name === "return") {
36512
- if (this.opts.validate) {
36513
- const F = this.opts.validate(this.value);
36514
- F && (this.error = F instanceof Error ? F.message : F, this.state = "error", this.rl?.write(this.value));
36515
- }
36516
- this.state !== "error" && (this.state = "submit");
36623
+ return [...byPath.values()].sort((a, b3) => a.relativePath.localeCompare(b3.relativePath));
36624
+ }
36625
+ async function unifyAgentsConfiguration(options = {}) {
36626
+ const scope = options.scope ?? "global";
36627
+ const dryRun = Boolean(options.dryRun);
36628
+ const folders = resolveFolders(options);
36629
+ const includeCodex = scope !== "repository";
36630
+ const instructionCandidates = getInstructionFileCandidates(options, includeCodex);
36631
+ const candidates = scope === "repository" ? getRepositoryContainerCandidates(options) : getContainerCandidates(options);
36632
+ const result = {
36633
+ rootDir: folders.rootDir,
36634
+ agentsDir: folders.agentsDir,
36635
+ scope,
36636
+ backupPath: null,
36637
+ imported: [],
36638
+ duplicates: [],
36639
+ renamed: [],
36640
+ linked: [],
36641
+ alreadyLinked: [],
36642
+ skipped: [],
36643
+ instructionIndex: null
36644
+ };
36645
+ const destinationByCategory = {
36646
+ skills: path17.join(folders.agentsDir, "skills"),
36647
+ agents: path17.join(folders.agentsDir, "agents"),
36648
+ instructions: path17.join(folders.agentsDir, "AGENTS.md"),
36649
+ rules: path17.join(folders.agentsDir, "rules")
36650
+ };
36651
+ await importInstructionFiles(instructionCandidates, destinationByCategory.instructions, result, dryRun);
36652
+ const categories = scope === "repository" ? ["skills", "agents", "rules"] : ["skills", "agents"];
36653
+ const activeCategories = new Set;
36654
+ for (const category of categories) {
36655
+ const isActive = await importCategoryEntries(category, candidates, destinationByCategory[category], result, dryRun);
36656
+ if (isActive) {
36657
+ activeCategories.add(category);
36517
36658
  }
36518
- $([u, t?.name, t?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
36519
36659
  }
36520
- close() {
36521
- this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
36522
- `), m(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
36660
+ for (const candidate of candidates) {
36661
+ if (!activeCategories.has(candidate.category))
36662
+ continue;
36663
+ await linkContainer(candidate, destinationByCategory[candidate.category], result, dryRun);
36523
36664
  }
36524
- restoreCursor() {
36525
- const u = Y(this._prevFrame, process.stdout.columns, { hard: true }).split(`
36526
- `).length - 1;
36527
- this.output.write(import_sisteransi.cursor.move(-999, u * -1));
36665
+ for (const candidate of instructionCandidates) {
36666
+ await linkInstructionFile(candidate, destinationByCategory.instructions, result, dryRun);
36528
36667
  }
36529
- render() {
36530
- const u = Y(this._render(this) ?? "", process.stdout.columns, { hard: true });
36531
- if (u !== this._prevFrame) {
36532
- if (this.state === "initial")
36533
- this.output.write(import_sisteransi.cursor.hide);
36534
- else {
36535
- const t = BD(this._prevFrame, u);
36536
- if (this.restoreCursor(), t && t?.length === 1) {
36537
- const F = t[0];
36538
- this.output.write(import_sisteransi.cursor.move(0, F)), this.output.write(import_sisteransi.erase.lines(1));
36539
- const s = u.split(`
36540
- `);
36541
- this.output.write(s[F]), this._prevFrame = u, this.output.write(import_sisteransi.cursor.move(0, s.length - F - 1));
36542
- return;
36543
- }
36544
- if (t && t?.length > 1) {
36545
- const F = t[0];
36546
- this.output.write(import_sisteransi.cursor.move(0, F)), this.output.write(import_sisteransi.erase.down());
36547
- const s = u.split(`
36548
- `).slice(F);
36549
- this.output.write(s.join(`
36550
- `)), this._prevFrame = u;
36551
- return;
36552
- }
36553
- this.output.write(import_sisteransi.erase.down());
36554
- }
36555
- this.output.write(u), this.state === "initial" && (this.state = "active"), this._prevFrame = u;
36556
- }
36668
+ if (scope === "repository") {
36669
+ await writeRepositoryInstructionIndex(result, folders, dryRun);
36557
36670
  }
36671
+ return result;
36672
+ }
36673
+ async function previewAgentsConfiguration(options = {}) {
36674
+ return unifyAgentsConfiguration({ ...options, dryRun: true });
36558
36675
  }
36559
36676
 
36560
- class dD extends x {
36561
- get cursor() {
36562
- return this.value ? 0 : 1;
36563
- }
36564
- get _value() {
36565
- return this.cursor === 0;
36677
+ // src/commands/agents-unify.ts
36678
+ function countByCategory(result, key, category) {
36679
+ return result[key].filter((entry) => entry.category === category).length;
36680
+ }
36681
+ function printCategorySummary(result, category) {
36682
+ const imported = countByCategory(result, "imported", category);
36683
+ const duplicates = countByCategory(result, "duplicates", category);
36684
+ const renamed = countByCategory(result, "renamed", category);
36685
+ const linked = countByCategory(result, "linked", category);
36686
+ const alreadyLinked = countByCategory(result, "alreadyLinked", category);
36687
+ console.log(source_default.gray(` ${category}: ${imported} imported, ${duplicates} duplicates skipped, ${renamed} renamed, ${linked} linked, ${alreadyLinked} already linked`));
36688
+ }
36689
+ function printPreviewList(title, entries) {
36690
+ if (entries.length === 0)
36691
+ return;
36692
+ console.log(source_default.gray(`
36693
+ ${title}:`));
36694
+ for (const entry of entries.slice(0, 12)) {
36695
+ console.log(source_default.gray(` - ${entry}`));
36566
36696
  }
36567
- constructor(u) {
36568
- super(u, false), this.value = !!u.initialValue, this.on("value", () => {
36569
- this.value = this._value;
36570
- }), this.on("confirm", (t) => {
36571
- this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = t, this.state = "submit", this.close();
36572
- }), this.on("cursor", () => {
36573
- this.value = !this.value;
36574
- });
36697
+ if (entries.length > 12) {
36698
+ console.log(source_default.gray(` ...and ${entries.length - 12} more`));
36575
36699
  }
36576
36700
  }
36577
- var A;
36578
- A = new WeakMap;
36579
- var kD = Object.defineProperty;
36580
- var $D = (e, u, t) => (u in e) ? kD(e, u, { enumerable: true, configurable: true, writable: true, value: t }) : e[u] = t;
36581
- var H = (e, u, t) => ($D(e, typeof u != "symbol" ? u + "" : u, t), t);
36582
- var SD = class extends x {
36583
- constructor(u) {
36584
- super(u, false), H(this, "options"), H(this, "cursor", 0), this.options = u.options, this.value = [...u.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: t }) => t === u.cursorAt), 0), this.on("key", (t) => {
36585
- t === "a" && this.toggleAll();
36586
- }), this.on("cursor", (t) => {
36587
- switch (t) {
36588
- case "left":
36589
- case "up":
36590
- this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
36591
- break;
36592
- case "down":
36593
- case "right":
36594
- this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
36595
- break;
36596
- case "space":
36597
- this.toggleValue();
36598
- break;
36599
- }
36600
- });
36601
- }
36602
- get _value() {
36603
- return this.options[this.cursor].value;
36701
+ function printAgentsUnifyPreview(result) {
36702
+ console.log(source_default.yellow(`
36703
+ Planned changes`));
36704
+ console.log(source_default.gray(` Root: ${result.rootDir}`));
36705
+ console.log(source_default.gray(` Shared folder: ${result.agentsDir}`));
36706
+ console.log(source_default.gray(` Imports: ${result.imported.length}`));
36707
+ console.log(source_default.gray(` Renames: ${result.renamed.length}`));
36708
+ console.log(source_default.gray(` Symlinks/relinks: ${result.linked.length}`));
36709
+ console.log(source_default.gray(` Already linked: ${result.alreadyLinked.length}`));
36710
+ console.log(source_default.gray(` Duplicates skipped: ${result.duplicates.length}`));
36711
+ if (result.backupPath) {
36712
+ console.log(source_default.gray(` Backups: ${result.backupPath}`));
36713
+ }
36714
+ if (result.instructionIndex) {
36715
+ console.log(source_default.gray(` AGENTS.md rules index: ${result.instructionIndex.indexedRules.length} rules`));
36716
+ console.log(source_default.gray(` CLAUDE.md symlink target: ${result.instructionIndex.agentsPath}`));
36717
+ }
36718
+ printPreviewList("Files/folders to import", result.imported.map((entry) => `${entry.from} -> ${entry.to}`));
36719
+ printPreviewList("Name conflicts to preserve", result.renamed.map((entry) => `${entry.from} -> ${entry.to} (${entry.reason})`));
36720
+ printPreviewList("Symlinks/relinks to create", result.linked.map((entry) => entry.movedToBackup ? `${entry.from} -> ${entry.to} (backup: ${entry.movedToBackup})` : `${entry.from} -> ${entry.to}`));
36721
+ printPreviewList("Skipped duplicates", result.duplicates.map((entry) => `${entry.from} (kept: ${entry.keptAs})`));
36722
+ }
36723
+ async function confirmUnify() {
36724
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
36725
+ return true;
36604
36726
  }
36605
- toggleAll() {
36606
- const u = this.value.length === this.options.length;
36607
- this.value = u ? [] : this.options.map((t) => t.value);
36727
+ const answer = await ye({
36728
+ message: "Continue with these unify changes?",
36729
+ initialValue: false
36730
+ });
36731
+ if (pD(answer)) {
36732
+ return false;
36608
36733
  }
36609
- toggleValue() {
36610
- const u = this.value.includes(this._value);
36611
- this.value = u ? this.value.filter((t) => t !== this._value) : [...this.value, this._value];
36734
+ return Boolean(answer);
36735
+ }
36736
+ async function agentsUnifyCommand(params = {}) {
36737
+ try {
36738
+ console.log(source_default.blue.bold(`
36739
+ AIBlueprint agents unify ${source_default.gray(`v${getVersion()}`)}
36740
+ `));
36741
+ console.log(source_default.gray(`Scope: ${params.scope ?? "global"}`));
36742
+ console.log(source_default.gray(params.scope === "repository" ? "Centralizing project agent configuration into .agents" : "Centralizing reusable agent configuration into .agents, then rendering Codex agents"));
36743
+ const preview = await previewAgentsConfiguration(params);
36744
+ printAgentsUnifyPreview(preview);
36745
+ if (!await confirmUnify()) {
36746
+ console.log(source_default.gray(`
36747
+ Unify cancelled`));
36748
+ return;
36749
+ }
36750
+ const result = await unifyAgentsConfiguration(params);
36751
+ const codexResult = params.scope === "repository" ? null : await renderCodexAgentsFromMarkdown(params);
36752
+ console.log(source_default.green(`
36753
+ Unify complete`));
36754
+ console.log(source_default.gray(` Shared folder: ${result.agentsDir}`));
36755
+ printCategorySummary(result, "instructions");
36756
+ printCategorySummary(result, "skills");
36757
+ printCategorySummary(result, "agents");
36758
+ if (result.scope === "repository") {
36759
+ printCategorySummary(result, "rules");
36760
+ }
36761
+ if (codexResult) {
36762
+ console.log(source_default.gray(` codex agents: ${codexResult.rendered.length} rendered, ${codexResult.skipped.length} skipped`));
36763
+ }
36764
+ if (result.instructionIndex) {
36765
+ console.log(source_default.gray(` rules index: ${result.instructionIndex.indexedRules.length} rules indexed in ${result.instructionIndex.agentsPath}`));
36766
+ console.log(source_default.gray(` Claude instructions: ${result.instructionIndex.claudePath}`));
36767
+ }
36768
+ if (result.backupPath) {
36769
+ console.log(source_default.gray(` Source backups: ${result.backupPath}`));
36770
+ }
36771
+ if (result.skipped.length > 0) {
36772
+ console.log(source_default.yellow(`
36773
+ Skipped paths:`));
36774
+ for (const skipped of result.skipped) {
36775
+ console.log(source_default.yellow(` ${skipped.path}: ${skipped.reason}`));
36776
+ }
36777
+ }
36778
+ } catch (error) {
36779
+ console.error(source_default.red(`
36780
+ Agents unify failed:`), error);
36781
+ process.exit(1);
36612
36782
  }
36613
- };
36614
- var OD = Object.defineProperty;
36615
- var PD = (e, u, t) => (u in e) ? OD(e, u, { enumerable: true, configurable: true, writable: true, value: t }) : e[u] = t;
36616
- var J = (e, u, t) => (PD(e, typeof u != "symbol" ? u + "" : u, t), t);
36783
+ }
36617
36784
 
36618
- class LD extends x {
36619
- constructor(u) {
36620
- super(u, false), J(this, "options"), J(this, "cursor", 0), this.options = u.options, this.cursor = this.options.findIndex(({ value: t }) => t === u.initialValue), this.cursor === -1 && (this.cursor = 0), this.changeValue(), this.on("cursor", (t) => {
36621
- switch (t) {
36622
- case "left":
36623
- case "up":
36624
- this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
36625
- break;
36626
- case "down":
36627
- case "right":
36628
- this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
36629
- break;
36785
+ // src/commands/codex-agents.ts
36786
+ async function codexAgentsCommand(options = {}) {
36787
+ try {
36788
+ console.log(source_default.blue.bold(`
36789
+ AIBlueprint Codex agents ${source_default.gray(`v${getVersion()}`)}
36790
+ `));
36791
+ console.log(source_default.gray("Rendering shared Markdown agents into Codex TOML custom agents"));
36792
+ const result = await renderCodexAgentsFromMarkdown(options);
36793
+ console.log(source_default.green(`
36794
+ Codex agents rendered`));
36795
+ console.log(source_default.gray(` Source: ${result.sourceDir}`));
36796
+ console.log(source_default.gray(` Target: ${result.targetDir}`));
36797
+ console.log(source_default.gray(` Rendered: ${result.rendered.length}`));
36798
+ console.log(source_default.gray(` Skipped: ${result.skipped.length}`));
36799
+ if (result.skipped.length > 0) {
36800
+ console.log(source_default.yellow(`
36801
+ Skipped agents:`));
36802
+ for (const skipped of result.skipped) {
36803
+ console.log(source_default.yellow(` ${skipped.source}: ${skipped.reason}`));
36630
36804
  }
36631
- this.changeValue();
36632
- });
36633
- }
36634
- get _value() {
36635
- return this.options[this.cursor];
36805
+ }
36806
+ } catch (error) {
36807
+ console.error(source_default.red(`
36808
+ Codex agents render failed:`), error);
36809
+ process.exit(1);
36636
36810
  }
36637
- changeValue() {
36638
- this.value = this._value.value;
36811
+ }
36812
+
36813
+ // src/lib/session-unifier.ts
36814
+ var import_fs_extra14 = __toESM(require_lib4(), 1);
36815
+ import crypto2 from "crypto";
36816
+ import os15 from "os";
36817
+ import path18 from "path";
36818
+ var MANAGED_FOLDERS2 = [".claude", ".codex", ".agents"];
36819
+ var SESSION_PATHS = {
36820
+ ".claude": ["projects", "sessions"],
36821
+ ".codex": ["sessions", "archived_sessions", "browser/sessions"],
36822
+ ".agents": ["sessions"]
36823
+ };
36824
+ async function listSnapshotSources(parentDir, type) {
36825
+ if (!await import_fs_extra14.default.pathExists(parentDir))
36826
+ return [];
36827
+ const entries = await import_fs_extra14.default.readdir(parentDir, { withFileTypes: true });
36828
+ return entries.filter((entry) => entry.isDirectory()).map((entry) => ({
36829
+ name: entry.name,
36830
+ path: path18.join(parentDir, entry.name),
36831
+ type
36832
+ }));
36833
+ }
36834
+ async function collectSnapshotSources(folders) {
36835
+ const storePaths = getConfigStorePaths(folders.rootDir);
36836
+ const sources = [
36837
+ ...await listSnapshotSources(storePaths.configsDir, "config"),
36838
+ ...await listSnapshotSources(storePaths.backupsDir, "backup")
36839
+ ];
36840
+ if (path18.resolve(folders.rootDir) === os15.homedir()) {
36841
+ sources.push(...await listSnapshotSources(getBackupDir(), "legacy-backup"));
36639
36842
  }
36843
+ return sources.sort((a, b3) => a.name.localeCompare(b3.name));
36640
36844
  }
36641
- class RD extends x {
36642
- get valueWithCursor() {
36643
- if (this.state === "submit")
36644
- return this.value;
36645
- if (this.cursor >= this.value.length)
36646
- return `${this.value}█`;
36647
- const u = this.value.slice(0, this.cursor), [t, ...F] = this.value.slice(this.cursor);
36648
- return `${u}${import_picocolors.default.inverse(t)}${F.join("")}`;
36845
+ async function snapshotFolderPath(snapshot, folder) {
36846
+ const managedPath = path18.join(snapshot.path, folder);
36847
+ if (await import_fs_extra14.default.pathExists(managedPath))
36848
+ return managedPath;
36849
+ if (snapshot.type === "legacy-backup") {
36850
+ if (folder === ".claude")
36851
+ return snapshot.path;
36852
+ const legacyAgentsPath = path18.join(snapshot.path, ".agents");
36853
+ if (folder === ".agents" && await import_fs_extra14.default.pathExists(legacyAgentsPath)) {
36854
+ return legacyAgentsPath;
36855
+ }
36649
36856
  }
36650
- get cursor() {
36651
- return this._cursor;
36857
+ return null;
36858
+ }
36859
+ function sanitizeSourceTag(snapshot) {
36860
+ return `${snapshot.type}-${snapshot.name}`.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "snapshot";
36861
+ }
36862
+ function withSourceSuffix(targetPath, sourceTag, index) {
36863
+ const parsed = path18.parse(targetPath);
36864
+ const suffix = index === 1 ? sourceTag : `${sourceTag}-${index}`;
36865
+ if (parsed.ext && parsed.name) {
36866
+ return path18.join(parsed.dir, `${parsed.name}--${suffix}${parsed.ext}`);
36652
36867
  }
36653
- constructor(u) {
36654
- super(u), this.on("finalize", () => {
36655
- this.value || (this.value = u.defaultValue);
36656
- });
36868
+ return path18.join(parsed.dir, `${parsed.base}--${suffix}`);
36869
+ }
36870
+ async function uniqueConflictPath(targetPath, sourceTag) {
36871
+ let index = 1;
36872
+ while (true) {
36873
+ const candidate = withSourceSuffix(targetPath, sourceTag, index);
36874
+ if (!await import_fs_extra14.default.pathExists(candidate))
36875
+ return candidate;
36876
+ index++;
36657
36877
  }
36658
36878
  }
36659
-
36660
- // node_modules/@clack/prompts/dist/index.mjs
36661
- var import_picocolors2 = __toESM(require_picocolors(), 1);
36662
- var import_sisteransi2 = __toESM(require_src(), 1);
36663
- import y2 from "node:process";
36664
- function ce() {
36665
- return y2.platform !== "win32" ? y2.env.TERM !== "linux" : !!y2.env.CI || !!y2.env.WT_SESSION || !!y2.env.TERMINUS_SUBLIME || y2.env.ConEmuTask === "{cmd::Cmder}" || y2.env.TERM_PROGRAM === "Terminus-Sublime" || y2.env.TERM_PROGRAM === "vscode" || y2.env.TERM === "xterm-256color" || y2.env.TERM === "alacritty" || y2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
36879
+ function hashString2(value) {
36880
+ return crypto2.createHash("sha256").update(value).digest("hex");
36666
36881
  }
36667
- var V2 = ce();
36668
- var u = (t, n) => V2 ? t : n;
36669
- var le = u("◆", "*");
36670
- var L2 = u("■", "x");
36671
- var W2 = u("▲", "x");
36672
- var C = u("◇", "o");
36673
- var ue = u("┌", "T");
36674
- var o = u("│", "|");
36675
- var d2 = u("└", "—");
36676
- var k2 = u("●", ">");
36677
- var P2 = u("○", " ");
36678
- var A2 = u("◻", "[•]");
36679
- var T = u("◼", "[+]");
36680
- var F = u("◻", "[ ]");
36681
- var $e = u("▪", "•");
36682
- var _3 = u("─", "-");
36683
- var me = u("╮", "+");
36684
- var de = u("├", "+");
36685
- var pe = u("╯", "+");
36686
- var q = u("●", "•");
36687
- var D = u("◆", "*");
36688
- var U = u("▲", "!");
36689
- var K2 = u("■", "x");
36690
- var b2 = (t) => {
36691
- switch (t) {
36692
- case "initial":
36693
- case "active":
36694
- return import_picocolors2.default.cyan(le);
36695
- case "cancel":
36696
- return import_picocolors2.default.red(L2);
36697
- case "error":
36698
- return import_picocolors2.default.yellow(W2);
36699
- case "submit":
36700
- return import_picocolors2.default.green(C);
36882
+ async function hashPath2(targetPath) {
36883
+ const stat = await import_fs_extra14.default.lstat(targetPath);
36884
+ if (stat.isSymbolicLink()) {
36885
+ return hashString2(`symlink:${await import_fs_extra14.default.readlink(targetPath)}`);
36701
36886
  }
36702
- };
36703
- var G2 = (t) => {
36704
- const { cursor: n, options: r2, style: i } = t, s = t.maxItems ?? Number.POSITIVE_INFINITY, c = Math.max(process.stdout.rows - 4, 0), a = Math.min(c, Math.max(s, 5));
36705
- let l2 = 0;
36706
- n >= l2 + a - 3 ? l2 = Math.max(Math.min(n - a + 3, r2.length - a), 0) : n < l2 + 2 && (l2 = Math.max(n - 2, 0));
36707
- const $2 = a < r2.length && l2 > 0, g2 = a < r2.length && l2 + a < r2.length;
36708
- return r2.slice(l2, l2 + a).map((p2, v2, f) => {
36709
- const j2 = v2 === 0 && $2, E = v2 === f.length - 1 && g2;
36710
- return j2 || E ? import_picocolors2.default.dim("...") : i(p2, v2 + l2 === n);
36711
- });
36712
- };
36713
- var he = (t) => new RD({ validate: t.validate, placeholder: t.placeholder, defaultValue: t.defaultValue, initialValue: t.initialValue, render() {
36714
- const n = `${import_picocolors2.default.gray(o)}
36715
- ${b2(this.state)} ${t.message}
36716
- `, r2 = t.placeholder ? import_picocolors2.default.inverse(t.placeholder[0]) + import_picocolors2.default.dim(t.placeholder.slice(1)) : import_picocolors2.default.inverse(import_picocolors2.default.hidden("_")), i = this.value ? this.valueWithCursor : r2;
36717
- switch (this.state) {
36718
- case "error":
36719
- return `${n.trim()}
36720
- ${import_picocolors2.default.yellow(o)} ${i}
36721
- ${import_picocolors2.default.yellow(d2)} ${import_picocolors2.default.yellow(this.error)}
36722
- `;
36723
- case "submit":
36724
- return `${n}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.dim(this.value || t.placeholder)}`;
36725
- case "cancel":
36726
- return `${n}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(this.value ?? ""))}${this.value?.trim() ? `
36727
- ${import_picocolors2.default.gray(o)}` : ""}`;
36728
- default:
36729
- return `${n}${import_picocolors2.default.cyan(o)} ${i}
36730
- ${import_picocolors2.default.cyan(d2)}
36731
- `;
36887
+ if (stat.isFile()) {
36888
+ const hash = crypto2.createHash("sha256");
36889
+ hash.update("file:");
36890
+ hash.update(await import_fs_extra14.default.readFile(targetPath));
36891
+ return hash.digest("hex");
36732
36892
  }
36733
- } }).prompt();
36734
- var ye = (t) => {
36735
- const n = t.active ?? "Yes", r2 = t.inactive ?? "No";
36736
- return new dD({ active: n, inactive: r2, initialValue: t.initialValue ?? true, render() {
36737
- const i = `${import_picocolors2.default.gray(o)}
36738
- ${b2(this.state)} ${t.message}
36739
- `, s = this.value ? n : r2;
36740
- switch (this.state) {
36741
- case "submit":
36742
- return `${i}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.dim(s)}`;
36743
- case "cancel":
36744
- return `${i}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(s))}
36745
- ${import_picocolors2.default.gray(o)}`;
36746
- default:
36747
- return `${i}${import_picocolors2.default.cyan(o)} ${this.value ? `${import_picocolors2.default.green(k2)} ${n}` : `${import_picocolors2.default.dim(P2)} ${import_picocolors2.default.dim(n)}`} ${import_picocolors2.default.dim("/")} ${this.value ? `${import_picocolors2.default.dim(P2)} ${import_picocolors2.default.dim(r2)}` : `${import_picocolors2.default.green(k2)} ${r2}`}
36748
- ${import_picocolors2.default.cyan(d2)}
36749
- `;
36893
+ if (stat.isDirectory()) {
36894
+ const entries = (await import_fs_extra14.default.readdir(targetPath, { withFileTypes: true })).sort((a, b3) => a.name.localeCompare(b3.name));
36895
+ const hash = crypto2.createHash("sha256");
36896
+ hash.update("dir:");
36897
+ for (const entry of entries) {
36898
+ hash.update(entry.name);
36899
+ hash.update("\x00");
36900
+ hash.update(await hashPath2(path18.join(targetPath, entry.name)));
36901
+ hash.update("\x00");
36750
36902
  }
36751
- } }).prompt();
36752
- };
36753
- var ve = (t) => {
36754
- const n = (r2, i) => {
36755
- const s = r2.label ?? String(r2.value);
36756
- switch (i) {
36757
- case "selected":
36758
- return `${import_picocolors2.default.dim(s)}`;
36759
- case "active":
36760
- return `${import_picocolors2.default.green(k2)} ${s} ${r2.hint ? import_picocolors2.default.dim(`(${r2.hint})`) : ""}`;
36761
- case "cancelled":
36762
- return `${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(s))}`;
36763
- default:
36764
- return `${import_picocolors2.default.dim(P2)} ${import_picocolors2.default.dim(s)}`;
36903
+ return hash.digest("hex");
36904
+ }
36905
+ return hashString2(`other:${stat.mode}:${stat.size}`);
36906
+ }
36907
+ async function mergeSessionPath(params) {
36908
+ const {
36909
+ sourcePath,
36910
+ destinationPath,
36911
+ folder,
36912
+ sessionRoot,
36913
+ snapshot,
36914
+ sourceTag,
36915
+ result,
36916
+ dryRun
36917
+ } = params;
36918
+ const sourceStat = await import_fs_extra14.default.lstat(sourcePath).catch(() => null);
36919
+ if (!sourceStat)
36920
+ return;
36921
+ const destinationStat = await import_fs_extra14.default.lstat(destinationPath).catch(() => null);
36922
+ if (sourceStat.isDirectory() && (destinationStat?.isDirectory() || dryRun)) {
36923
+ const entries = await import_fs_extra14.default.readdir(sourcePath);
36924
+ if (!dryRun && destinationStat?.isDirectory()) {
36925
+ await import_fs_extra14.default.ensureDir(destinationPath);
36926
+ }
36927
+ for (const entry of entries) {
36928
+ await mergeSessionPath({
36929
+ sourcePath: path18.join(sourcePath, entry),
36930
+ destinationPath: path18.join(destinationPath, entry),
36931
+ folder,
36932
+ sessionRoot,
36933
+ snapshot,
36934
+ sourceTag,
36935
+ result,
36936
+ dryRun
36937
+ });
36938
+ }
36939
+ return;
36940
+ }
36941
+ if (!destinationStat) {
36942
+ if (!dryRun) {
36943
+ await import_fs_extra14.default.ensureDir(path18.dirname(destinationPath));
36944
+ await import_fs_extra14.default.copy(sourcePath, destinationPath, {
36945
+ overwrite: false,
36946
+ dereference: false
36947
+ });
36765
36948
  }
36949
+ result.imported.push({
36950
+ folder,
36951
+ sessionRoot,
36952
+ from: sourcePath,
36953
+ to: destinationPath,
36954
+ snapshot: snapshot.name
36955
+ });
36956
+ return;
36957
+ }
36958
+ if (await hashPath2(sourcePath) === await hashPath2(destinationPath)) {
36959
+ result.duplicates.push({
36960
+ folder,
36961
+ sessionRoot,
36962
+ from: sourcePath,
36963
+ existing: destinationPath,
36964
+ snapshot: snapshot.name
36965
+ });
36966
+ return;
36967
+ }
36968
+ const conflictPath = await uniqueConflictPath(destinationPath, sourceTag);
36969
+ if (!dryRun) {
36970
+ await import_fs_extra14.default.ensureDir(path18.dirname(conflictPath));
36971
+ await import_fs_extra14.default.copy(sourcePath, conflictPath, {
36972
+ overwrite: false,
36973
+ dereference: false
36974
+ });
36975
+ }
36976
+ result.conflicts.push({
36977
+ folder,
36978
+ sessionRoot,
36979
+ from: sourcePath,
36980
+ to: conflictPath,
36981
+ snapshot: snapshot.name,
36982
+ reason: "Same session path with different content"
36983
+ });
36984
+ }
36985
+ async function unifySessionsFromSnapshots(options = {}) {
36986
+ const folders = resolveFolders(options);
36987
+ const dryRun = Boolean(options.dryRun);
36988
+ const snapshots = await collectSnapshotSources(folders);
36989
+ const destinationByFolder = {
36990
+ ".claude": folders.claudeDir,
36991
+ ".codex": folders.codexDir,
36992
+ ".agents": folders.agentsDir
36766
36993
  };
36767
- return new LD({ options: t.options, initialValue: t.initialValue, render() {
36768
- const r2 = `${import_picocolors2.default.gray(o)}
36769
- ${b2(this.state)} ${t.message}
36770
- `;
36771
- switch (this.state) {
36772
- case "submit":
36773
- return `${r2}${import_picocolors2.default.gray(o)} ${n(this.options[this.cursor], "selected")}`;
36774
- case "cancel":
36775
- return `${r2}${import_picocolors2.default.gray(o)} ${n(this.options[this.cursor], "cancelled")}
36776
- ${import_picocolors2.default.gray(o)}`;
36777
- default:
36778
- return `${r2}${import_picocolors2.default.cyan(o)} ${G2({ cursor: this.cursor, options: this.options, maxItems: t.maxItems, style: (i, s) => n(i, s ? "active" : "inactive") }).join(`
36779
- ${import_picocolors2.default.cyan(o)} `)}
36780
- ${import_picocolors2.default.cyan(d2)}
36781
- `;
36782
- }
36783
- } }).prompt();
36784
- };
36785
- var fe = (t) => {
36786
- const n = (r2, i) => {
36787
- const s = r2.label ?? String(r2.value);
36788
- return i === "active" ? `${import_picocolors2.default.cyan(A2)} ${s} ${r2.hint ? import_picocolors2.default.dim(`(${r2.hint})`) : ""}` : i === "selected" ? `${import_picocolors2.default.green(T)} ${import_picocolors2.default.dim(s)} ${r2.hint ? import_picocolors2.default.dim(`(${r2.hint})`) : ""}` : i === "cancelled" ? `${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(s))}` : i === "active-selected" ? `${import_picocolors2.default.green(T)} ${s} ${r2.hint ? import_picocolors2.default.dim(`(${r2.hint})`) : ""}` : i === "submitted" ? `${import_picocolors2.default.dim(s)}` : `${import_picocolors2.default.dim(F)} ${import_picocolors2.default.dim(s)}`;
36994
+ const result = {
36995
+ rootDir: folders.rootDir,
36996
+ scannedSnapshots: snapshots,
36997
+ imported: [],
36998
+ duplicates: [],
36999
+ conflicts: []
36789
37000
  };
36790
- return new SD({ options: t.options, initialValues: t.initialValues, required: t.required ?? true, cursorAt: t.cursorAt, validate(r2) {
36791
- if (this.required && r2.length === 0)
36792
- return `Please select at least one option.
36793
- ${import_picocolors2.default.reset(import_picocolors2.default.dim(`Press ${import_picocolors2.default.gray(import_picocolors2.default.bgWhite(import_picocolors2.default.inverse(" space ")))} to select, ${import_picocolors2.default.gray(import_picocolors2.default.bgWhite(import_picocolors2.default.inverse(" enter ")))} to submit`))}`;
36794
- }, render() {
36795
- const r2 = `${import_picocolors2.default.gray(o)}
36796
- ${b2(this.state)} ${t.message}
36797
- `, i = (s, c) => {
36798
- const a = this.value.includes(s.value);
36799
- return c && a ? n(s, "active-selected") : a ? n(s, "selected") : n(s, c ? "active" : "inactive");
36800
- };
36801
- switch (this.state) {
36802
- case "submit":
36803
- return `${r2}${import_picocolors2.default.gray(o)} ${this.options.filter(({ value: s }) => this.value.includes(s)).map((s) => n(s, "submitted")).join(import_picocolors2.default.dim(", ")) || import_picocolors2.default.dim("none")}`;
36804
- case "cancel": {
36805
- const s = this.options.filter(({ value: c }) => this.value.includes(c)).map((c) => n(c, "cancelled")).join(import_picocolors2.default.dim(", "));
36806
- return `${r2}${import_picocolors2.default.gray(o)} ${s.trim() ? `${s}
36807
- ${import_picocolors2.default.gray(o)}` : ""}`;
36808
- }
36809
- case "error": {
36810
- const s = this.error.split(`
36811
- `).map((c, a) => a === 0 ? `${import_picocolors2.default.yellow(d2)} ${import_picocolors2.default.yellow(c)}` : ` ${c}`).join(`
36812
- `);
36813
- return `${r2 + import_picocolors2.default.yellow(o)} ${G2({ options: this.options, cursor: this.cursor, maxItems: t.maxItems, style: i }).join(`
36814
- ${import_picocolors2.default.yellow(o)} `)}
36815
- ${s}
36816
- `;
37001
+ for (const snapshot of snapshots) {
37002
+ const sourceTag = sanitizeSourceTag(snapshot);
37003
+ for (const folder of MANAGED_FOLDERS2) {
37004
+ const sourceFolder = await snapshotFolderPath(snapshot, folder);
37005
+ if (!sourceFolder)
37006
+ continue;
37007
+ for (const sessionRoot of SESSION_PATHS[folder]) {
37008
+ const sourcePath = path18.join(sourceFolder, sessionRoot);
37009
+ if (!await import_fs_extra14.default.pathExists(sourcePath))
37010
+ continue;
37011
+ await mergeSessionPath({
37012
+ sourcePath,
37013
+ destinationPath: path18.join(destinationByFolder[folder], sessionRoot),
37014
+ folder,
37015
+ sessionRoot,
37016
+ snapshot,
37017
+ sourceTag,
37018
+ result,
37019
+ dryRun
37020
+ });
36817
37021
  }
36818
- default:
36819
- return `${r2}${import_picocolors2.default.cyan(o)} ${G2({ options: this.options, cursor: this.cursor, maxItems: t.maxItems, style: i }).join(`
36820
- ${import_picocolors2.default.cyan(o)} `)}
36821
- ${import_picocolors2.default.cyan(d2)}
36822
- `;
36823
37022
  }
36824
- } }).prompt();
36825
- };
36826
- var xe = (t = "") => {
36827
- process.stdout.write(`${import_picocolors2.default.gray(d2)} ${import_picocolors2.default.red(t)}
36828
-
36829
- `);
36830
- };
36831
- var Ie = (t = "") => {
36832
- process.stdout.write(`${import_picocolors2.default.gray(ue)} ${t}
36833
- `);
36834
- };
36835
- var Se = (t = "") => {
36836
- process.stdout.write(`${import_picocolors2.default.gray(o)}
36837
- ${import_picocolors2.default.gray(d2)} ${t}
37023
+ }
37024
+ return result;
37025
+ }
37026
+ async function previewSessionsFromSnapshots(options = {}) {
37027
+ return unifySessionsFromSnapshots({ ...options, dryRun: true });
37028
+ }
36838
37029
 
36839
- `);
36840
- };
36841
- var M2 = { message: (t = "", { symbol: n = import_picocolors2.default.gray(o) } = {}) => {
36842
- const r2 = [`${import_picocolors2.default.gray(o)}`];
36843
- if (t) {
36844
- const [i, ...s] = t.split(`
36845
- `);
36846
- r2.push(`${n} ${i}`, ...s.map((c) => `${import_picocolors2.default.gray(o)} ${c}`));
37030
+ // src/commands/session-unify.ts
37031
+ function summarizeByFolder(entries) {
37032
+ const counts = new Map;
37033
+ for (const entry of entries) {
37034
+ counts.set(entry.folder, (counts.get(entry.folder) ?? 0) + 1);
36847
37035
  }
36848
- process.stdout.write(`${r2.join(`
36849
- `)}
36850
- `);
36851
- }, info: (t) => {
36852
- M2.message(t, { symbol: import_picocolors2.default.blue(q) });
36853
- }, success: (t) => {
36854
- M2.message(t, { symbol: import_picocolors2.default.green(D) });
36855
- }, step: (t) => {
36856
- M2.message(t, { symbol: import_picocolors2.default.green(C) });
36857
- }, warn: (t) => {
36858
- M2.message(t, { symbol: import_picocolors2.default.yellow(U) });
36859
- }, warning: (t) => {
36860
- M2.warn(t);
36861
- }, error: (t) => {
36862
- M2.message(t, { symbol: import_picocolors2.default.red(K2) });
36863
- } };
36864
- var J2 = `${import_picocolors2.default.gray(o)} `;
36865
- var Y2 = ({ indicator: t = "dots" } = {}) => {
36866
- const n = V2 ? ["◒", "◐", "◓", "◑"] : ["•", "o", "O", "0"], r2 = V2 ? 80 : 120, i = process.env.CI === "true";
36867
- let s, c, a = false, l2 = "", $2, g2 = performance.now();
36868
- const p2 = (m2) => {
36869
- const h2 = m2 > 1 ? "Something went wrong" : "Canceled";
36870
- a && N2(h2, m2);
36871
- }, v2 = () => p2(2), f = () => p2(1), j2 = () => {
36872
- process.on("uncaughtExceptionMonitor", v2), process.on("unhandledRejection", v2), process.on("SIGINT", f), process.on("SIGTERM", f), process.on("exit", p2);
36873
- }, E = () => {
36874
- process.removeListener("uncaughtExceptionMonitor", v2), process.removeListener("unhandledRejection", v2), process.removeListener("SIGINT", f), process.removeListener("SIGTERM", f), process.removeListener("exit", p2);
36875
- }, B2 = () => {
36876
- if ($2 === undefined)
37036
+ if (counts.size === 0)
37037
+ return "none";
37038
+ return [...counts.entries()].map(([folder, count]) => `${folder}: ${count}`).join(", ");
37039
+ }
37040
+ function printPreviewList2(title, entries) {
37041
+ if (entries.length === 0)
37042
+ return;
37043
+ console.log(source_default.gray(`
37044
+ ${title}:`));
37045
+ for (const entry of entries.slice(0, 12)) {
37046
+ console.log(source_default.gray(` - ${entry}`));
37047
+ }
37048
+ if (entries.length > 12) {
37049
+ console.log(source_default.gray(` ...and ${entries.length - 12} more`));
37050
+ }
37051
+ }
37052
+ function printSessionUnifyPreview(result) {
37053
+ console.log(source_default.yellow(`
37054
+ Planned session changes`));
37055
+ console.log(source_default.gray(` Root: ${result.rootDir}`));
37056
+ console.log(source_default.gray(` Snapshots to scan: ${result.scannedSnapshots.length}`));
37057
+ console.log(source_default.gray(` Sessions to import: ${result.imported.length} (${summarizeByFolder(result.imported)})`));
37058
+ console.log(source_default.gray(` Duplicates to skip: ${result.duplicates.length}`));
37059
+ console.log(source_default.gray(` Conflicts to preserve: ${result.conflicts.length}`));
37060
+ printPreviewList2("Session files/folders to import", result.imported.map((entry) => `${entry.from} -> ${entry.to}`));
37061
+ printPreviewList2("Conflicting sessions to copy with source suffix", result.conflicts.map((entry) => `${entry.from} -> ${entry.to}`));
37062
+ }
37063
+ async function confirmUnify2() {
37064
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
37065
+ return true;
37066
+ }
37067
+ const answer = await ye({
37068
+ message: "Continue with these session unify changes?",
37069
+ initialValue: false
37070
+ });
37071
+ if (pD(answer)) {
37072
+ return false;
37073
+ }
37074
+ return Boolean(answer);
37075
+ }
37076
+ async function sessionsUnifyCommand(params = {}) {
37077
+ try {
37078
+ console.log(source_default.blue("Unifying saved sessions from configs and backups..."));
37079
+ const preview = await previewSessionsFromSnapshots(params);
37080
+ printSessionUnifyPreview(preview);
37081
+ if (!await confirmUnify2()) {
37082
+ console.log(source_default.gray(`
37083
+ Session unify cancelled`));
36877
37084
  return;
36878
- i && process.stdout.write(`
36879
- `);
36880
- const m2 = $2.split(`
36881
- `);
36882
- process.stdout.write(import_sisteransi2.cursor.move(-999, m2.length - 1)), process.stdout.write(import_sisteransi2.erase.down(m2.length));
36883
- }, R2 = (m2) => m2.replace(/\.+$/, ""), O2 = (m2) => {
36884
- const h2 = (performance.now() - m2) / 1000, w2 = Math.floor(h2 / 60), I2 = Math.floor(h2 % 60);
36885
- return w2 > 0 ? `[${w2}m ${I2}s]` : `[${I2}s]`;
36886
- }, H2 = (m2 = "") => {
36887
- a = true, s = fD(), l2 = R2(m2), g2 = performance.now(), process.stdout.write(`${import_picocolors2.default.gray(o)}
36888
- `);
36889
- let h2 = 0, w2 = 0;
36890
- j2(), c = setInterval(() => {
36891
- if (i && l2 === $2)
36892
- return;
36893
- B2(), $2 = l2;
36894
- const I2 = import_picocolors2.default.magenta(n[h2]);
36895
- if (i)
36896
- process.stdout.write(`${I2} ${l2}...`);
36897
- else if (t === "timer")
36898
- process.stdout.write(`${I2} ${l2} ${O2(g2)}`);
36899
- else {
36900
- const z2 = ".".repeat(Math.floor(w2)).slice(0, 3);
36901
- process.stdout.write(`${I2} ${l2}${z2}`);
37085
+ }
37086
+ const result = await unifySessionsFromSnapshots(params);
37087
+ console.log(source_default.green("Session unify complete"));
37088
+ console.log(source_default.gray(` Snapshots scanned: ${result.scannedSnapshots.length}`));
37089
+ console.log(source_default.gray(` Imported: ${result.imported.length} (${summarizeByFolder(result.imported)})`));
37090
+ console.log(source_default.gray(` Duplicates skipped: ${result.duplicates.length}`));
37091
+ console.log(source_default.gray(` Conflicts preserved: ${result.conflicts.length}`));
37092
+ if (result.conflicts.length > 0) {
37093
+ console.log(source_default.yellow(`
37094
+ Conflicting session paths were copied with source suffixes:`));
37095
+ for (const conflict of result.conflicts.slice(0, 10)) {
37096
+ console.log(source_default.yellow(` ${conflict.to}`));
36902
37097
  }
36903
- h2 = h2 + 1 < n.length ? h2 + 1 : 0, w2 = w2 < n.length ? w2 + 0.125 : 0;
36904
- }, r2);
36905
- }, N2 = (m2 = "", h2 = 0) => {
36906
- a = false, clearInterval(c), B2();
36907
- const w2 = h2 === 0 ? import_picocolors2.default.green(C) : h2 === 1 ? import_picocolors2.default.red(L2) : import_picocolors2.default.red(W2);
36908
- l2 = R2(m2 ?? l2), t === "timer" ? process.stdout.write(`${w2} ${l2} ${O2(g2)}
36909
- `) : process.stdout.write(`${w2} ${l2}
36910
- `), E(), s();
36911
- };
36912
- return { start: H2, stop: N2, message: (m2 = "") => {
36913
- l2 = R2(m2 ?? l2);
36914
- } };
36915
- };
37098
+ if (result.conflicts.length > 10) {
37099
+ console.log(source_default.yellow(` ...and ${result.conflicts.length - 10} more`));
37100
+ }
37101
+ }
37102
+ } catch (error) {
37103
+ console.error(source_default.red("Session unify failed:"), error);
37104
+ process.exit(1);
37105
+ }
37106
+ }
36916
37107
 
36917
37108
  // src/commands/pro.ts
36918
37109
  import path21 from "path";