xclaude-cli 0.1.3 → 0.1.4

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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/xclaude.js +392 -255
  3. package/package.json +1 -1
package/dist/xclaude.js CHANGED
@@ -338,7 +338,7 @@ function processCtx(io) {
338
338
  }
339
339
 
340
340
  // src/commands/add.ts
341
- import fs14 from "node:fs";
341
+ import fs15 from "node:fs";
342
342
 
343
343
  // src/claude/auth.ts
344
344
  import { execFile } from "node:child_process";
@@ -698,9 +698,9 @@ function identityEnv(ctx, name) {
698
698
  return buildEnv(ctx.env, { name, configDir: name === MAIN ? null : accountDir(ctx.paths, name) });
699
699
  }
700
700
 
701
- // src/link/repair.ts
702
- import fs13 from "node:fs";
703
- import path9 from "node:path";
701
+ // src/link/plugins.ts
702
+ import fs10 from "node:fs";
703
+ import path6 from "node:path";
704
704
 
705
705
  // src/core/lock.ts
706
706
  import fs9 from "node:fs";
@@ -785,13 +785,193 @@ function takeOverStale(lockPath) {
785
785
  }
786
786
  }
787
787
 
788
+ // src/core/state.ts
789
+ var MAX_DIRS = 500;
790
+ function emptyState() {
791
+ return { installedVersion: null, lastAccountByDir: {}, lastUsedAccount: null, seenUnknownEntries: {}, listedPlugins: {} };
792
+ }
793
+ function isRecord(v) {
794
+ return typeof v === "object" && v !== null && !Array.isArray(v);
795
+ }
796
+ function loadState(paths) {
797
+ let raw;
798
+ try {
799
+ raw = JSON.parse(readFileOrNull(paths.state) ?? "{}");
800
+ } catch {
801
+ return emptyState();
802
+ }
803
+ const state = emptyState();
804
+ if (!isRecord(raw)) return state;
805
+ if (typeof raw.installedVersion === "string") state.installedVersion = raw.installedVersion;
806
+ if (typeof raw.lastUsedAccount === "string") state.lastUsedAccount = raw.lastUsedAccount;
807
+ if (isRecord(raw.lastAccountByDir)) {
808
+ for (const [dir, name] of Object.entries(raw.lastAccountByDir)) {
809
+ if (typeof name === "string") state.lastAccountByDir[dir] = name;
810
+ }
811
+ }
812
+ if (isRecord(raw.seenUnknownEntries)) {
813
+ for (const [name, entries] of Object.entries(raw.seenUnknownEntries)) {
814
+ if (Array.isArray(entries)) state.seenUnknownEntries[name] = entries.filter((e) => typeof e === "string");
815
+ }
816
+ }
817
+ if (isRecord(raw.listedPlugins)) {
818
+ for (const [name, ids] of Object.entries(raw.listedPlugins)) {
819
+ if (Array.isArray(ids)) state.listedPlugins[name] = ids.filter((id) => typeof id === "string");
820
+ }
821
+ }
822
+ return state;
823
+ }
824
+ function saveState(paths, state) {
825
+ ensureXHome(paths);
826
+ writeFileAtomic(paths.state, `${JSON.stringify(state, null, 2)}
827
+ `, { mode: 384 });
828
+ }
829
+ function updateState(paths, change) {
830
+ const state = loadState(paths);
831
+ change(state);
832
+ saveState(paths, state);
833
+ return state;
834
+ }
835
+ function recordUse(state, dir, account) {
836
+ delete state.lastAccountByDir[dir];
837
+ state.lastAccountByDir[dir] = account;
838
+ const dirs = Object.keys(state.lastAccountByDir);
839
+ for (const old of dirs.slice(0, Math.max(0, dirs.length - MAX_DIRS))) delete state.lastAccountByDir[old];
840
+ state.lastUsedAccount = account;
841
+ }
842
+ function forgetAccount(state, account) {
843
+ for (const [dir, name] of Object.entries(state.lastAccountByDir)) {
844
+ if (name === account) delete state.lastAccountByDir[dir];
845
+ }
846
+ if (state.lastUsedAccount === account) state.lastUsedAccount = null;
847
+ delete state.seenUnknownEntries[account];
848
+ delete state.listedPlugins[account];
849
+ }
850
+
851
+ // src/link/plugins.ts
852
+ function isRecord2(v) {
853
+ return typeof v === "object" && v !== null && !Array.isArray(v);
854
+ }
855
+ function userPlugins(paths) {
856
+ const dir = realpathOrNull(path6.join(paths.store, "plugins"));
857
+ if (!dir) return null;
858
+ let text;
859
+ try {
860
+ text = readFileOrNull(path6.join(dir, "installed_plugins.json"));
861
+ } catch {
862
+ return null;
863
+ }
864
+ if (text === null) return [];
865
+ let json;
866
+ try {
867
+ json = JSON.parse(text);
868
+ } catch {
869
+ return null;
870
+ }
871
+ if (!isRecord2(json) || !isRecord2(json.plugins)) return null;
872
+ return Object.entries(json.plugins).filter(([, records]) => Array.isArray(records) && records.some((r) => isRecord2(r) && r.scope === "user")).map(([id]) => id).sort();
873
+ }
874
+ function planPlugins(paths, account, tracked) {
875
+ const dir = accountDir(paths, account);
876
+ if (!lstatOrNull(dir)?.isDirectory()) return null;
877
+ const store = realpathOrNull(path6.join(paths.store, "plugins"));
878
+ if (!store || realpathOrNull(path6.join(dir, "plugins")) !== store) return null;
879
+ const installed = userPlugins(paths);
880
+ if (!installed) return null;
881
+ const file = path6.join(dir, "settings.json");
882
+ const st = lstatOrNull(file);
883
+ if (st && !st.isFile()) return null;
884
+ const original = st ? fs10.readFileSync(file, "utf8") : null;
885
+ let settings = {};
886
+ if (original !== null) {
887
+ try {
888
+ settings = JSON.parse(original);
889
+ } catch {
890
+ return null;
891
+ }
892
+ }
893
+ if (!isRecord2(settings)) return null;
894
+ const current = settings.enabledPlugins ?? {};
895
+ if (!isRecord2(current)) return null;
896
+ const named = new Set(Object.keys(current).map((id) => id.toLowerCase()));
897
+ const add = installed.filter((id) => !named.has(id.toLowerCase()));
898
+ const keep = [];
899
+ const drop = [];
900
+ for (const id of tracked) {
901
+ if (current[id] !== false) continue;
902
+ if (installed.includes(id)) keep.push(id);
903
+ else drop.push(id);
904
+ }
905
+ let text = null;
906
+ if (add.length || drop.length) {
907
+ const next = { ...current };
908
+ for (const id of drop) delete next[id];
909
+ for (const id of add) next[id] = false;
910
+ const ending = original === null || original.endsWith("\n") ? "\n" : "";
911
+ text = `${JSON.stringify({ ...settings, enabledPlugins: next }, null, 2)}${ending}`;
912
+ }
913
+ return {
914
+ file,
915
+ add,
916
+ drop,
917
+ tracked: [...keep, ...add].sort(),
918
+ text,
919
+ seen: st ? { mtimeMs: st.mtimeMs, size: st.size, ino: st.ino } : null
920
+ };
921
+ }
922
+ function writePlan(plan) {
923
+ if (plan.text === null) return true;
924
+ const st = lstatOrNull(plan.file);
925
+ const unchanged = plan.seen ? st !== null && st.mtimeMs === plan.seen.mtimeMs && st.size === plan.seen.size && st.ino === plan.seen.ino : st === null;
926
+ if (unchanged) writeFileAtomic(plan.file, plan.text);
927
+ return unchanged;
928
+ }
929
+ function changesNothing(plan, tracked) {
930
+ return plan.text === null && plan.tracked.join("\n") === [...tracked].sort().join("\n");
931
+ }
932
+ function listPlugins(paths, account, opts) {
933
+ const result = { added: [], dropped: [], deferred: false };
934
+ try {
935
+ const before = loadState(paths).listedPlugins[account] ?? [];
936
+ const first = planPlugins(paths, account, before);
937
+ if (!first || changesNothing(first, before)) return result;
938
+ const lock = DirLock.acquire(path6.join(paths.locks, "store"), STORE_LOCK, { waitMs: opts.lockWaitMs });
939
+ if (!lock) return { ...result, deferred: true };
940
+ try {
941
+ const tracked = loadState(paths).listedPlugins[account] ?? [];
942
+ const plan = planPlugins(paths, account, tracked);
943
+ if (!plan || changesNothing(plan, tracked)) return result;
944
+ if (!writePlan(plan)) return { ...result, deferred: true };
945
+ updateState(paths, (state) => {
946
+ if (plan.tracked.length) state.listedPlugins[account] = plan.tracked;
947
+ else delete state.listedPlugins[account];
948
+ });
949
+ if (plan.add.length === 1) {
950
+ opts.log(`xclaude: ${plan.add[0]} is installed under another login; ${account}'s /plugin lists it now, turned off`);
951
+ } else if (plan.add.length) {
952
+ opts.log(`xclaude: ${plan.add.length} plugins installed under other logins are in ${account}'s /plugin now, turned off: ${plan.add.join(", ")}`);
953
+ }
954
+ return { added: plan.add, dropped: plan.drop, deferred: false };
955
+ } finally {
956
+ lock.release();
957
+ }
958
+ } catch (e) {
959
+ opts.log(`xclaude: couldn't list other logins' plugins for ${account} (${e.message})`);
960
+ return result;
961
+ }
962
+ }
963
+
964
+ // src/link/repair.ts
965
+ import fs14 from "node:fs";
966
+ import path10 from "node:path";
967
+
788
968
  // src/link/history.ts
789
- import fs11 from "node:fs";
790
- import path7 from "node:path";
969
+ import fs12 from "node:fs";
970
+ import path8 from "node:path";
791
971
 
792
972
  // src/link/merge.ts
793
- import fs10 from "node:fs";
794
- import path6 from "node:path";
973
+ import fs11 from "node:fs";
974
+ import path7 from "node:path";
795
975
  var counter2 = 0;
796
976
  function asideName(entry) {
797
977
  return `.xclaude-merge-${entry}-${stamp()}-${process.pid}-${counter2++}`;
@@ -816,23 +996,23 @@ function remember(rec, c) {
816
996
  rec.byPath.set(c.path, c);
817
997
  }
818
998
  function requireRealDir(dir) {
819
- const st = fs10.lstatSync(dir);
999
+ const st = fs11.lstatSync(dir);
820
1000
  if (!st.isDirectory()) throw new Error(`${dir} isn't a real directory; it won't be read through`);
821
1001
  return st;
822
1002
  }
823
1003
  function linkText(src, root) {
824
- const text = fs10.readlinkSync(src);
825
- if (path6.isAbsolute(text)) return text;
826
- const resolved = path6.resolve(path6.dirname(src), text);
827
- return resolved === root || resolved.startsWith(`${root}${path6.sep}`) ? text : resolved;
1004
+ const text = fs11.readlinkSync(src);
1005
+ if (path7.isAbsolute(text)) return text;
1006
+ const resolved = path7.resolve(path7.dirname(src), text);
1007
+ return resolved === root || resolved.startsWith(`${root}${path7.sep}`) ? text : resolved;
828
1008
  }
829
1009
  function identicalEntry(src, srcStat, dst, root) {
830
1010
  const dstStat = lstatOrNull(dst);
831
1011
  if (!dstStat) return false;
832
1012
  if (srcStat.isSymbolicLink()) {
833
1013
  if (!dstStat.isSymbolicLink()) return false;
834
- const there = fs10.readlinkSync(dst);
835
- return there === linkText(src, root) || there === fs10.readlinkSync(src);
1014
+ const there = fs11.readlinkSync(dst);
1015
+ return there === linkText(src, root) || there === fs11.readlinkSync(src);
836
1016
  }
837
1017
  return srcStat.isFile() && dstStat.isFile() && sameContent(src, dst);
838
1018
  }
@@ -847,18 +1027,18 @@ function conflictName(dir, name, ctx) {
847
1027
  const base = `${name}.xclaude-conflict-${ctx.account}-${ctx.stamp}`;
848
1028
  for (let n = 1; ; n++) {
849
1029
  const candidate = n === 1 ? base : `${base}-${n}`;
850
- if (!lstatOrNull(path6.join(dir, candidate))) return candidate;
1030
+ if (!lstatOrNull(path7.join(dir, candidate))) return candidate;
851
1031
  }
852
1032
  }
853
1033
  var join = (rel, name) => rel ? `${rel}/${name}` : name;
854
1034
  function linkTree(src, dst, ctx, stats, rec, root = src, rel = "") {
855
1035
  let fresh = 0;
856
- for (const d of fs10.readdirSync(src, { withFileTypes: true })) {
1036
+ for (const d of fs11.readdirSync(src, { withFileTypes: true })) {
857
1037
  ctx.refresh();
858
- const s = path6.join(src, d.name);
859
- const t = path6.join(dst, d.name);
1038
+ const s = path7.join(src, d.name);
1039
+ const t = path7.join(dst, d.name);
860
1040
  const relName = join(rel, d.name);
861
- const st = fs10.lstatSync(s);
1041
+ const st = fs11.lstatSync(s);
862
1042
  const prior = rec.placed.get(relName);
863
1043
  if (st.isDirectory()) {
864
1044
  let target = t;
@@ -866,14 +1046,14 @@ function linkTree(src, dst, ctx, stats, rec, root = src, rel = "") {
866
1046
  target = prior.target;
867
1047
  } else {
868
1048
  try {
869
- fs10.mkdirSync(t, { mode: st.mode & 4095 | 448 });
1049
+ fs11.mkdirSync(t, { mode: st.mode & 4095 | 448 });
870
1050
  remember(rec, { path: t, kind: "dir" });
871
1051
  } catch (e) {
872
1052
  if (errCode(e) !== "EEXIST") throw e;
873
- if (!fs10.lstatSync(t).isDirectory()) {
1053
+ if (!fs11.lstatSync(t).isDirectory()) {
874
1054
  const name2 = conflictName(dst, d.name, ctx);
875
- target = path6.join(dst, name2);
876
- fs10.mkdirSync(target, { mode: st.mode & 4095 | 448 });
1055
+ target = path7.join(dst, name2);
1056
+ fs11.mkdirSync(target, { mode: st.mode & 4095 | 448 });
877
1057
  remember(rec, { path: target, kind: "dir" });
878
1058
  stats.conflicts.push(join(rel, name2));
879
1059
  }
@@ -888,7 +1068,7 @@ function linkTree(src, dst, ctx, stats, rec, root = src, rel = "") {
888
1068
  const place = (to) => {
889
1069
  if (st.isSymbolicLink()) {
890
1070
  const link = linkText(s, root);
891
- fs10.symlinkSync(link, to);
1071
+ fs11.symlinkSync(link, to);
892
1072
  remember(rec, { path: to, kind: "symlink", link });
893
1073
  } else {
894
1074
  fsops.link(s, to);
@@ -914,8 +1094,8 @@ function linkTree(src, dst, ctx, stats, rec, root = src, rel = "") {
914
1094
  continue;
915
1095
  }
916
1096
  const name = conflictName(dst, d.name, ctx);
917
- place(path6.join(dst, name));
918
- rec.placed.set(relName, { target: path6.join(dst, name) });
1097
+ place(path7.join(dst, name));
1098
+ rec.placed.set(relName, { target: path7.join(dst, name) });
919
1099
  stats.moved++;
920
1100
  stats.conflicts.push(join(rel, name));
921
1101
  }
@@ -926,29 +1106,29 @@ function undoLinks(rec) {
926
1106
  const st = lstatOrNull(c.path);
927
1107
  if (!st) continue;
928
1108
  try {
929
- if (c.kind === "dir" && st.isDirectory()) fs10.rmdirSync(c.path);
930
- else if (c.kind === "symlink" && st.isSymbolicLink() && fs10.readlinkSync(c.path) === c.link) fs10.unlinkSync(c.path);
931
- else if (c.kind === "file" && st.ino === c.ino && st.dev === c.dev) fs10.unlinkSync(c.path);
1109
+ if (c.kind === "dir" && st.isDirectory()) fs11.rmdirSync(c.path);
1110
+ else if (c.kind === "symlink" && st.isSymbolicLink() && fs11.readlinkSync(c.path) === c.link) fs11.unlinkSync(c.path);
1111
+ else if (c.kind === "file" && st.ino === c.ino && st.dev === c.dev) fs11.unlinkSync(c.path);
932
1112
  } catch {
933
1113
  }
934
1114
  }
935
1115
  }
936
1116
  function openForEmptying(dir) {
937
1117
  const st = requireRealDir(dir);
938
- if ((st.mode & 448) !== 448) fs10.chmodSync(dir, st.mode & 4095 | 448);
939
- return fs10.readdirSync(dir, { withFileTypes: true });
1118
+ if ((st.mode & 448) !== 448) fs11.chmodSync(dir, st.mode & 4095 | 448);
1119
+ return fs11.readdirSync(dir, { withFileTypes: true });
940
1120
  }
941
1121
  function takeOver(src, placed, rec, dst, ctx, stats, rel) {
942
1122
  const ours = rec.byPath.get(placed.target);
943
1123
  const there = lstatOrNull(placed.target);
944
1124
  if (!ours || ours.kind !== "file" || !there || there.ino !== ours.ino || there.dev !== ours.dev) return false;
945
- const base = path6.basename(placed.target);
1125
+ const base = path7.basename(placed.target);
946
1126
  const old = conflictName(dst, base, ctx);
947
- fsops.link(placed.target, path6.join(dst, old));
948
- const tmp = path6.join(dst, `.xclaude-tmp-${base}-${process.pid}-${counter2++}`);
1127
+ fsops.link(placed.target, path7.join(dst, old));
1128
+ const tmp = path7.join(dst, `.xclaude-tmp-${base}-${process.pid}-${counter2++}`);
949
1129
  fsops.link(src, tmp);
950
- fs10.renameSync(tmp, placed.target);
951
- fs10.unlinkSync(src);
1130
+ fs11.renameSync(tmp, placed.target);
1131
+ fs11.unlinkSync(src);
952
1132
  stats.conflicts.push(join(rel, old));
953
1133
  return true;
954
1134
  }
@@ -958,34 +1138,34 @@ function moveTree(src, dst, ctx, stats, rec = null, root = src, rel = "") {
958
1138
  entries.sort((a, b) => Number(isPlaced(a.name)) - Number(isPlaced(b.name)));
959
1139
  for (const d of entries) {
960
1140
  ctx.refresh();
961
- const s = path6.join(src, d.name);
962
- const st = fs10.lstatSync(s);
1141
+ const s = path7.join(src, d.name);
1142
+ const st = fs11.lstatSync(s);
963
1143
  const relName = join(rel, d.name);
964
1144
  const placed = rec?.placed.get(relName);
965
1145
  if (st.isDirectory()) {
966
- let target = path6.join(dst, d.name);
1146
+ let target = path7.join(dst, d.name);
967
1147
  if (placed && lstatOrNull(placed.target)?.isDirectory()) {
968
1148
  target = placed.target;
969
1149
  } else {
970
1150
  try {
971
- fs10.mkdirSync(target, { mode: st.mode & 4095 | 448 });
1151
+ fs11.mkdirSync(target, { mode: st.mode & 4095 | 448 });
972
1152
  } catch (e) {
973
1153
  if (errCode(e) !== "EEXIST") throw e;
974
- if (!fs10.lstatSync(target).isDirectory()) {
1154
+ if (!fs11.lstatSync(target).isDirectory()) {
975
1155
  const name2 = conflictName(dst, d.name, ctx);
976
- target = path6.join(dst, name2);
977
- fs10.mkdirSync(target, { mode: st.mode & 4095 | 448 });
1156
+ target = path7.join(dst, name2);
1157
+ fs11.mkdirSync(target, { mode: st.mode & 4095 | 448 });
978
1158
  stats.conflicts.push(join(rel, name2));
979
1159
  }
980
1160
  }
981
1161
  }
982
1162
  moveTree(s, target, ctx, stats, rec, root, relName);
983
- fs10.rmdirSync(s);
1163
+ fs11.rmdirSync(s);
984
1164
  continue;
985
1165
  }
986
1166
  if (placed) {
987
1167
  if (stillPlaced(placed, s, st, root)) {
988
- fs10.unlinkSync(s);
1168
+ fs11.unlinkSync(s);
989
1169
  continue;
990
1170
  }
991
1171
  if (st.isFile() && !placed.identical && rec && takeOver(s, placed, rec, dst, ctx, stats, rel)) {
@@ -995,29 +1175,29 @@ function moveTree(src, dst, ctx, stats, rec = null, root = src, rel = "") {
995
1175
  }
996
1176
  if (st.isSymbolicLink()) {
997
1177
  const link = linkText(s, root);
998
- const to = path6.join(dst, d.name);
1178
+ const to = path7.join(dst, d.name);
999
1179
  try {
1000
- fs10.symlinkSync(link, to);
1001
- fs10.unlinkSync(s);
1180
+ fs11.symlinkSync(link, to);
1181
+ fs11.unlinkSync(s);
1002
1182
  stats.moved++;
1003
1183
  continue;
1004
1184
  } catch (e) {
1005
1185
  if (errCode(e) !== "EEXIST") throw e;
1006
1186
  }
1007
- } else if (moveNoClobber(s, path6.join(dst, d.name), st) === "moved") {
1187
+ } else if (moveNoClobber(s, path7.join(dst, d.name), st) === "moved") {
1008
1188
  stats.moved++;
1009
1189
  continue;
1010
1190
  }
1011
- if (identicalEntry(s, st, path6.join(dst, d.name), root)) {
1012
- fs10.unlinkSync(s);
1191
+ if (identicalEntry(s, st, path7.join(dst, d.name), root)) {
1192
+ fs11.unlinkSync(s);
1013
1193
  stats.dropped++;
1014
1194
  continue;
1015
1195
  }
1016
1196
  const name = conflictName(dst, d.name, ctx);
1017
1197
  if (st.isSymbolicLink()) {
1018
- fs10.symlinkSync(linkText(s, root), path6.join(dst, name));
1019
- fs10.unlinkSync(s);
1020
- } else if (moveNoClobber(s, path6.join(dst, name), st) !== "moved") {
1198
+ fs11.symlinkSync(linkText(s, root), path7.join(dst, name));
1199
+ fs11.unlinkSync(s);
1200
+ } else if (moveNoClobber(s, path7.join(dst, name), st) !== "moved") {
1021
1201
  throw new Error(`can't place ${relName}: ${name} is taken`);
1022
1202
  }
1023
1203
  stats.moved++;
@@ -1222,7 +1402,7 @@ function readLines(file) {
1222
1402
  return (readFileOrNull(file) ?? "").split("\n");
1223
1403
  }
1224
1404
  function storeLockPath(S) {
1225
- return `${realpathOrNull(path7.join(S, HISTORY)) ?? path7.join(S, HISTORY)}.lock`;
1405
+ return `${realpathOrNull(path8.join(S, HISTORY)) ?? path8.join(S, HISTORY)}.lock`;
1226
1406
  }
1227
1407
  function mergeAsideIntoStore(ctx, aside, alsoHeld) {
1228
1408
  const refreshAll = () => {
@@ -1233,7 +1413,7 @@ function mergeAsideIntoStore(ctx, aside, alsoHeld) {
1233
1413
  const storeLock = DirLock.acquire(storeLockPath(ctx.S), HISTORY_LOCK, { waitMs, onWait: refreshAll });
1234
1414
  if (!storeLock) return { ok: false, reason: "the shared history.jsonl is busy" };
1235
1415
  try {
1236
- const storeFile = realpathOrNull(path7.join(ctx.S, HISTORY));
1416
+ const storeFile = realpathOrNull(path8.join(ctx.S, HISTORY));
1237
1417
  if (!storeFile) return { ok: false, reason: "~/.claude/history.jsonl doesn't resolve" };
1238
1418
  const storeLines = readLines(storeFile);
1239
1419
  const merged = mergeHistoryLines(storeLines, readLines(aside));
@@ -1241,7 +1421,7 @@ function mergeAsideIntoStore(ctx, aside, alsoHeld) {
1241
1421
  if (!storeLock.refresh() || alsoHeld && !alsoHeld.refresh()) return { ok: false, reason: "a history lock was taken over" };
1242
1422
  writeFileAtomic(storeFile, merged.length ? `${merged.join("\n")}
1243
1423
  ` : "", { mode: 384, fsync: true });
1244
- fs11.unlinkSync(aside);
1424
+ fs12.unlinkSync(aside);
1245
1425
  const before = new Set(storeLines);
1246
1426
  return { ok: true, added: merged.filter((line) => !before.has(line)).length };
1247
1427
  } finally {
@@ -1249,37 +1429,37 @@ function mergeAsideIntoStore(ctx, aside, alsoHeld) {
1249
1429
  }
1250
1430
  }
1251
1431
  function mergeHistory(ctx) {
1252
- const file = path7.join(ctx.A, HISTORY);
1432
+ const file = path8.join(ctx.A, HISTORY);
1253
1433
  const accountLock = DirLock.acquire(`${file}.lock`, HISTORY_LOCK, { waitMs: ctx.lockWaitMs, onWait: ctx.refreshStoreLock });
1254
1434
  if (!accountLock) return { ok: false, reason: `this account's history.jsonl is busy` };
1255
1435
  try {
1256
1436
  const st = lstatOrNull(file);
1257
1437
  if (!st?.isFile()) return { ok: true, added: 0 };
1258
- const storeFile = realpathOrNull(path7.join(ctx.S, HISTORY));
1438
+ const storeFile = realpathOrNull(path8.join(ctx.S, HISTORY));
1259
1439
  if (!storeFile) return { ok: false, reason: "~/.claude/history.jsonl doesn't resolve" };
1260
- const aside = path7.join(ctx.A, asideName(HISTORY));
1261
- fs11.linkSync(file, aside);
1440
+ const aside = path8.join(ctx.A, asideName(HISTORY));
1441
+ fs12.linkSync(file, aside);
1262
1442
  const tmp = siblingName(file, "link");
1263
- fs11.symlinkSync(storeFile, tmp);
1264
- fs11.renameSync(tmp, file);
1443
+ fs12.symlinkSync(storeFile, tmp);
1444
+ fs12.renameSync(tmp, file);
1265
1445
  return mergeAsideIntoStore(ctx, aside, accountLock);
1266
1446
  } finally {
1267
1447
  accountLock.release();
1268
1448
  }
1269
1449
  }
1270
1450
  function resumeHistoryAside(ctx, aside, shared) {
1271
- const file = path7.join(ctx.A, HISTORY);
1451
+ const file = path8.join(ctx.A, HISTORY);
1272
1452
  const st = lstatOrNull(file);
1273
- const asideStat = fs11.lstatSync(aside);
1453
+ const asideStat = fs12.lstatSync(aside);
1274
1454
  if (st?.isFile() && st.ino === asideStat.ino && st.dev === asideStat.dev) {
1275
- fs11.unlinkSync(aside);
1455
+ fs12.unlinkSync(aside);
1276
1456
  return { ok: true, added: 0 };
1277
1457
  }
1278
1458
  if (!shared) return mergeAsideIntoAccount(ctx, aside);
1279
1459
  return mergeAsideIntoStore(ctx, aside, null);
1280
1460
  }
1281
1461
  function mergeAsideIntoAccount(ctx, aside) {
1282
- const file = path7.join(ctx.A, HISTORY);
1462
+ const file = path8.join(ctx.A, HISTORY);
1283
1463
  const lock = DirLock.acquire(`${file}.lock`, HISTORY_LOCK, { waitMs: ctx.lockWaitMs, onWait: ctx.refreshStoreLock });
1284
1464
  if (!lock) return { ok: false, reason: "this account's history.jsonl is busy" };
1285
1465
  try {
@@ -1290,7 +1470,7 @@ function mergeAsideIntoAccount(ctx, aside) {
1290
1470
  if (!lock.refresh()) return { ok: false, reason: "a history lock was taken over" };
1291
1471
  writeFileAtomic(file, merged.length ? `${merged.join("\n")}
1292
1472
  ` : "", { mode: 384, fsync: true });
1293
- fs11.unlinkSync(aside);
1473
+ fs12.unlinkSync(aside);
1294
1474
  const before = new Set(own);
1295
1475
  return { ok: true, added: merged.filter((line) => !before.has(line)).length };
1296
1476
  } finally {
@@ -1299,23 +1479,23 @@ function mergeAsideIntoAccount(ctx, aside) {
1299
1479
  }
1300
1480
 
1301
1481
  // src/link/stub.ts
1302
- import fs12 from "node:fs";
1303
- import path8 from "node:path";
1482
+ import fs13 from "node:fs";
1483
+ import path9 from "node:path";
1304
1484
  var STUB_TEXT = "Shared instructions live in ~/.claude/CLAUDE.md, so edit that file.\n@~/.claude/CLAUDE.md\n";
1305
1485
  function stubState(A, S, enabled, detail) {
1306
- const storeHas = enabled && Boolean(statOrNull(path8.join(S, STUB))?.isFile());
1307
- const a = lstatOrNull(path8.join(A, STUB));
1486
+ const storeHas = enabled && Boolean(statOrNull(path9.join(S, STUB))?.isFile());
1487
+ const a = lstatOrNull(path9.join(A, STUB));
1308
1488
  if (!a) return storeHas ? "create" : "none";
1309
1489
  if (storeHas && !detail) return "ok";
1310
- const isStub = a.isFile() && readFileOrNull(path8.join(A, STUB)) === STUB_TEXT;
1490
+ const isStub = a.isFile() && readFileOrNull(path9.join(A, STUB)) === STUB_TEXT;
1311
1491
  if (storeHas) return isStub ? "ok" : "differs";
1312
1492
  return isStub ? "remove" : "differs";
1313
1493
  }
1314
1494
  function applyStub(A, state) {
1315
- const file = path8.join(A, STUB);
1495
+ const file = path9.join(A, STUB);
1316
1496
  if (state === "create") {
1317
1497
  try {
1318
- fs12.writeFileSync(file, STUB_TEXT, { flag: "wx", mode: 384 });
1498
+ fs13.writeFileSync(file, STUB_TEXT, { flag: "wx", mode: 384 });
1319
1499
  return "created";
1320
1500
  } catch (e) {
1321
1501
  if (errCode(e) === "EEXIST") return null;
@@ -1323,7 +1503,7 @@ function applyStub(A, state) {
1323
1503
  }
1324
1504
  }
1325
1505
  if (state === "remove" && readFileOrNull(file) === STUB_TEXT) {
1326
- fs12.unlinkSync(file);
1506
+ fs13.unlinkSync(file);
1327
1507
  return "removed";
1328
1508
  }
1329
1509
  return null;
@@ -1341,8 +1521,8 @@ function storeKind(p) {
1341
1521
  return st.isDirectory() ? "dir" : st.isFile() ? "file" : "other";
1342
1522
  }
1343
1523
  function classifyEntry(A, S, name, kind) {
1344
- const a = path9.join(A, name);
1345
- const s = path9.join(S, name);
1524
+ const a = path10.join(A, name);
1525
+ const s = path10.join(S, name);
1346
1526
  const lst = lstatOrNull(a);
1347
1527
  const optional = OPTIONAL_DIRS.has(name);
1348
1528
  const sk = storeKind(s);
@@ -1373,7 +1553,7 @@ function inspectAccount(paths, account, table, detail = false) {
1373
1553
  const S = paths.store;
1374
1554
  let dirents;
1375
1555
  try {
1376
- dirents = fs13.readdirSync(A, { withFileTypes: true });
1556
+ dirents = fs14.readdirSync(A, { withFileTypes: true });
1377
1557
  } catch (e) {
1378
1558
  if (errCode(e) !== "ENOENT") throw e;
1379
1559
  return { dir: A, exists: false, entries: [], leftovers: [], stub: "none", names: [] };
@@ -1384,8 +1564,8 @@ function inspectAccount(paths, account, table, detail = false) {
1384
1564
  for (const d of dirents) {
1385
1565
  const name = d.name;
1386
1566
  if (!d.isSymbolicLink() || shared.has(name) || name === STUB || NEVER_SHARED.includes(name) || isIgnored(name)) continue;
1387
- const target = readlinkOrNull(path9.join(A, name));
1388
- const s = path9.join(S, name);
1567
+ const target = readlinkOrNull(path10.join(A, name));
1568
+ const s = path10.join(S, name);
1389
1569
  if (target === null || target !== s && target !== realpathOrNull(s)) continue;
1390
1570
  const kind = name === HISTORY || storeKind(s) === "file" ? "file" : "dir";
1391
1571
  entries.push({ name, kind, state: "unshare", target });
@@ -1450,11 +1630,11 @@ function describeProblems(insp, paths) {
1450
1630
  return problems;
1451
1631
  }
1452
1632
  function ensureStoreEntry(S, name, kind) {
1453
- fs13.mkdirSync(S, { recursive: true, mode: 448 });
1454
- const p = path9.join(S, name);
1633
+ fs14.mkdirSync(S, { recursive: true, mode: 448 });
1634
+ const p = path10.join(S, name);
1455
1635
  try {
1456
- if (kind === "dir") fs13.mkdirSync(p, { mode: 448 });
1457
- else fs13.closeSync(fs13.openSync(p, "wx", 384));
1636
+ if (kind === "dir") fs14.mkdirSync(p, { mode: 448 });
1637
+ else fs14.closeSync(fs14.openSync(p, "wx", 384));
1458
1638
  } catch (e) {
1459
1639
  if (errCode(e) !== "EEXIST") throw e;
1460
1640
  }
@@ -1532,10 +1712,10 @@ var Repairer = class {
1532
1712
  /** realpath(S/E), created first if missing. Never a path inside an account dir. */
1533
1713
  linkTarget(info) {
1534
1714
  ensureStoreEntry(this.S, info.name, info.kind);
1535
- const target = realpathOrNull(path9.join(this.S, info.name));
1715
+ const target = realpathOrNull(path10.join(this.S, info.name));
1536
1716
  if (!target) throw new Error(`${this.storePath(info.name)} doesn't resolve`);
1537
1717
  const accounts = realpathOrNull(this.opts.paths.accounts) ?? this.opts.paths.accounts;
1538
- if (target === accounts || target.startsWith(`${accounts}${path9.sep}`)) {
1718
+ if (target === accounts || target.startsWith(`${accounts}${path10.sep}`)) {
1539
1719
  throw new Error(`${this.storePath(info.name)} resolves into ${tildify(target, this.opts.paths.home)}, inside an account dir; make it a real ${info.kind === "dir" ? "directory" : "file"} again`);
1540
1720
  }
1541
1721
  return target;
@@ -1543,7 +1723,7 @@ var Repairer = class {
1543
1723
  createLink(info, depth) {
1544
1724
  const target = this.linkTarget(info);
1545
1725
  try {
1546
- fs13.symlinkSync(target, path9.join(this.A, info.name));
1726
+ fs14.symlinkSync(target, path10.join(this.A, info.name));
1547
1727
  } catch (e) {
1548
1728
  if (errCode(e) !== "EEXIST" || depth > 0) throw e;
1549
1729
  this.act(classifyEntry(this.A, this.S, info.name, info.kind), depth + 1);
@@ -1551,22 +1731,22 @@ var Repairer = class {
1551
1731
  }
1552
1732
  replaceLink(info) {
1553
1733
  const target = this.linkTarget(info);
1554
- const a = path9.join(this.A, info.name);
1734
+ const a = path10.join(this.A, info.name);
1555
1735
  const tmp = siblingName(a, "link");
1556
- fs13.symlinkSync(target, tmp);
1557
- fs13.renameSync(tmp, a);
1736
+ fs14.symlinkSync(target, tmp);
1737
+ fs14.renameSync(tmp, a);
1558
1738
  this.opts.log(`xclaude: ${this.label}/${info.name} pointed to ${info.target}; relinked to ${this.storePath(info.name)}`);
1559
1739
  }
1560
1740
  unshare(info) {
1561
- const a = path9.join(this.A, info.name);
1741
+ const a = path10.join(this.A, info.name);
1562
1742
  if (info.kind === "file") {
1563
1743
  const tmp = siblingName(a, "unshare");
1564
- fs13.closeSync(fs13.openSync(tmp, "wx", 384));
1565
- fs13.renameSync(tmp, a);
1744
+ fs14.closeSync(fs14.openSync(tmp, "wx", 384));
1745
+ fs14.renameSync(tmp, a);
1566
1746
  } else {
1567
- fs13.unlinkSync(a);
1747
+ fs14.unlinkSync(a);
1568
1748
  try {
1569
- fs13.mkdirSync(a, { mode: 448 });
1749
+ fs14.mkdirSync(a, { mode: 448 });
1570
1750
  } catch (e) {
1571
1751
  if (errCode(e) !== "EEXIST") throw e;
1572
1752
  }
@@ -1592,7 +1772,7 @@ var Repairer = class {
1592
1772
  * was lost: then another process may already rely on those links.
1593
1773
  */
1594
1774
  mergeDir(info) {
1595
- const a = path9.join(this.A, info.name);
1775
+ const a = path10.join(this.A, info.name);
1596
1776
  const target = this.linkTarget(info);
1597
1777
  const ctx = this.moveContext();
1598
1778
  const stats = emptyStats();
@@ -1617,15 +1797,15 @@ var Repairer = class {
1617
1797
  }
1618
1798
  const asides = [];
1619
1799
  for (let attempt = 0; ; attempt++) {
1620
- const aside = path9.join(this.A, asideName(info.name));
1621
- fs13.renameSync(a, aside);
1800
+ const aside = path10.join(this.A, asideName(info.name));
1801
+ fs14.renameSync(a, aside);
1622
1802
  asides.push(aside);
1623
1803
  try {
1624
- fs13.symlinkSync(target, a);
1804
+ fs14.symlinkSync(target, a);
1625
1805
  break;
1626
1806
  } catch (e) {
1627
1807
  if (errCode(e) !== "EEXIST") {
1628
- fs13.renameSync(asides[0], a);
1808
+ fs14.renameSync(asides[0], a);
1629
1809
  if (asides.length === 1) undoLinks(rec);
1630
1810
  throw e;
1631
1811
  }
@@ -1636,7 +1816,7 @@ var Repairer = class {
1636
1816
  }
1637
1817
  asides.forEach((aside, i) => {
1638
1818
  moveTree(aside, target, ctx, stats, i === 0 ? rec : null);
1639
- fs13.rmdirSync(aside);
1819
+ fs14.rmdirSync(aside);
1640
1820
  });
1641
1821
  const line = summarize(this.label, info.name, this.storePath(info.name), stats);
1642
1822
  if (line) this.opts.log(line);
@@ -1672,11 +1852,11 @@ var Repairer = class {
1672
1852
  }
1673
1853
  }
1674
1854
  resumeLeftover(name) {
1675
- const p = path9.join(this.A, name);
1855
+ const p = path10.join(this.A, name);
1676
1856
  if (name.startsWith(".xclaude-link-") || name.startsWith(".xclaude-unshare-") || name.startsWith(".xclaude-tmp-")) {
1677
1857
  const st2 = lstatOrNull(p);
1678
- if (st2?.isDirectory()) fs13.rmdirSync(p);
1679
- else if (st2) fs13.unlinkSync(p);
1858
+ if (st2?.isDirectory()) fs14.rmdirSync(p);
1859
+ else if (st2) fs14.unlinkSync(p);
1680
1860
  return;
1681
1861
  }
1682
1862
  const entry = parseAside(name);
@@ -1687,7 +1867,7 @@ var Repairer = class {
1687
1867
  const st = lstatOrNull(p);
1688
1868
  if (!st) return;
1689
1869
  if (st.isSymbolicLink()) {
1690
- fs13.unlinkSync(p);
1870
+ fs14.unlinkSync(p);
1691
1871
  return;
1692
1872
  }
1693
1873
  if (entry === HISTORY ? !st.isFile() : !st.isDirectory()) {
@@ -1701,22 +1881,22 @@ var Repairer = class {
1701
1881
  return;
1702
1882
  }
1703
1883
  if (!this.opts.table.dirs.includes(entry)) {
1704
- const own = path9.join(this.A, entry);
1705
- if (!lstatOrNull(own)) fs13.mkdirSync(own, { mode: 448 });
1706
- const st2 = fs13.lstatSync(own);
1884
+ const own = path10.join(this.A, entry);
1885
+ if (!lstatOrNull(own)) fs14.mkdirSync(own, { mode: 448 });
1886
+ const st2 = fs14.lstatSync(own);
1707
1887
  if (!st2.isDirectory() || st2.isSymbolicLink()) {
1708
1888
  this.problem(name, `left by an interrupted merge of ${entry}; ${entry} isn't a directory, so move the contents back by hand`);
1709
1889
  return;
1710
1890
  }
1711
1891
  moveTree(p, own, this.moveContext(), emptyStats());
1712
- fs13.rmdirSync(p);
1892
+ fs14.rmdirSync(p);
1713
1893
  return;
1714
1894
  }
1715
1895
  const target = this.linkTarget({ name: entry, kind: "dir", state: "ok" });
1716
1896
  const stats = emptyStats();
1717
1897
  try {
1718
1898
  moveTree(p, target, this.moveContext(), stats);
1719
- fs13.rmdirSync(p);
1899
+ fs14.rmdirSync(p);
1720
1900
  } catch (e) {
1721
1901
  this.cannotMerge(entry, e);
1722
1902
  return;
@@ -1729,7 +1909,7 @@ function unmanageable(A, store) {
1729
1909
  if (lstatOrNull(A)?.isSymbolicLink()) return "is a symlink; xclaude only manages real folders there, so it leaves this one alone";
1730
1910
  const realA = realpathOrNull(A);
1731
1911
  const realS = realpathOrNull(store);
1732
- if (realA && realS && (realA === realS || realS.startsWith(`${realA}${path9.sep}`))) {
1912
+ if (realA && realS && (realA === realS || realS.startsWith(`${realA}${path10.sep}`))) {
1733
1913
  return "is the shared store or holds it; xclaude leaves it alone";
1734
1914
  }
1735
1915
  return null;
@@ -1743,7 +1923,7 @@ function repairAccount(opts) {
1743
1923
  const problems = describeProblems(insp, opts.paths);
1744
1924
  return { clean: problems.length === 0, busy: false, problems, names: insp.names };
1745
1925
  }
1746
- const lock = DirLock.acquire(path9.join(opts.paths.locks, "store"), STORE_LOCK, { waitMs: opts.lockWaitMs });
1926
+ const lock = DirLock.acquire(path10.join(opts.paths.locks, "store"), STORE_LOCK, { waitMs: opts.lockWaitMs });
1747
1927
  if (!lock) {
1748
1928
  const problems = describeProblems(insp, opts.paths);
1749
1929
  return { clean: false, busy: true, problems, names: insp.names };
@@ -1882,17 +2062,19 @@ async function addCommand(ctx, config, args) {
1882
2062
  const dir = accountDir(ctx.paths, name);
1883
2063
  const refusal = unmanageable(dir, ctx.paths.store);
1884
2064
  if (refusal) throw new XError(`not adding ${name}: ${tildify(dir, ctx.paths.home)} ${refusal}. Replace it with a real folder, or remove it, then add ${name} again.`);
1885
- if (fs14.existsSync(dir)) log(`xclaude: ${tildify(dir, ctx.paths.home)} already exists; reusing it`);
2065
+ if (fs15.existsSync(dir)) log(`xclaude: ${tildify(dir, ctx.paths.home)} already exists; reusing it`);
1886
2066
  mkdirPrivate(dir);
2067
+ const table = shareTable(config, ctx.switches);
1887
2068
  const res = repairAccount({
1888
2069
  paths: ctx.paths,
1889
2070
  account: name,
1890
- table: shareTable(config, ctx.switches),
2071
+ table,
1891
2072
  lockWaitMs: Infinity,
1892
2073
  replaceWrongLinks: false,
1893
2074
  log
1894
2075
  });
1895
2076
  for (const pr of res.problems) log(`xclaude: ${problemLine(name, pr)}`);
2077
+ if (table.dirs.includes("plugins")) listPlugins(ctx.paths, name, { lockWaitMs: Infinity, log });
1896
2078
  config = loadConfig(ctx.paths, { create: false }).config;
1897
2079
  config.accounts[name] = defaults;
1898
2080
  saveConfig(ctx.paths, config);
@@ -1918,12 +2100,12 @@ async function addCommand(ctx, config, args) {
1918
2100
 
1919
2101
  // src/commands/doctor.ts
1920
2102
  import { spawnSync as spawnSync2 } from "node:child_process";
1921
- import fs19 from "node:fs";
1922
- import path14 from "node:path";
2103
+ import fs20 from "node:fs";
2104
+ import path15 from "node:path";
1923
2105
 
1924
2106
  // src/link/normalize.ts
1925
- import fs15 from "node:fs";
1926
- import path10 from "node:path";
2107
+ import fs16 from "node:fs";
2108
+ import path11 from "node:path";
1927
2109
  var REGISTRY_FILES = ["plugins/installed_plugins.json", "plugins/known_marketplaces.json"];
1928
2110
  function escapeRe(s) {
1929
2111
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -1943,17 +2125,17 @@ function rewrite(value, re, to, onChange) {
1943
2125
  return value;
1944
2126
  }
1945
2127
  function planNormalization(paths, account) {
1946
- const accountsDir = path10.join(paths.xhome, "accounts");
1947
- const to = path10.join(paths.home, ".claude");
2128
+ const accountsDir = path11.join(paths.xhome, "accounts");
2129
+ const to = path11.join(paths.home, ".claude");
1948
2130
  const name = account ? escapeRe(account) : "[a-z][a-z0-9-]{0,31}";
1949
2131
  const re = new RegExp(`^${escapeRe(accountsDir)}/(${name})(/|$)`);
1950
2132
  const plans = [];
1951
2133
  for (const rel of REGISTRY_FILES) {
1952
- const file = realpathOrNull(path10.join(paths.store, rel));
2134
+ const file = realpathOrNull(path11.join(paths.store, rel));
1953
2135
  if (!file) continue;
1954
2136
  const st = lstatOrNull(file);
1955
2137
  if (!st?.isFile()) continue;
1956
- const original = fs15.readFileSync(file, "utf8");
2138
+ const original = fs16.readFileSync(file, "utf8");
1957
2139
  if (!original.includes(accountsDir)) continue;
1958
2140
  let parsed;
1959
2141
  try {
@@ -1986,7 +2168,7 @@ function applyNormalization(plans) {
1986
2168
  function normalizePaths(paths, opts) {
1987
2169
  const plans = planNormalization(paths, opts.account);
1988
2170
  if (!plans.length) return { changed: [], skipped: [], busy: false };
1989
- const lock = DirLock.acquire(path10.join(paths.locks, "store"), STORE_LOCK, { waitMs: opts.lockWaitMs });
2171
+ const lock = DirLock.acquire(path11.join(paths.locks, "store"), STORE_LOCK, { waitMs: opts.lockWaitMs });
1990
2172
  if (!lock) return { changed: [], skipped: plans.map((p) => p.file), busy: true };
1991
2173
  try {
1992
2174
  const result = applyNormalization(plans);
@@ -2000,12 +2182,12 @@ function normalizePaths(paths, opts) {
2000
2182
  }
2001
2183
 
2002
2184
  // src/link/leftover.ts
2003
- import fs16 from "node:fs";
2004
- import path11 from "node:path";
2185
+ import fs17 from "node:fs";
2186
+ import path12 from "node:path";
2005
2187
  function strayFolders(paths, config) {
2006
2188
  let names;
2007
2189
  try {
2008
- names = fs16.readdirSync(paths.accounts);
2190
+ names = fs17.readdirSync(paths.accounts);
2009
2191
  } catch {
2010
2192
  return [];
2011
2193
  }
@@ -2013,14 +2195,14 @@ function strayFolders(paths, config) {
2013
2195
  const out = [];
2014
2196
  for (const name of names.sort()) {
2015
2197
  if (name.endsWith(".lock") || name === ".DS_Store" || Object.hasOwn(config.accounts, name)) continue;
2016
- const dir = path11.join(paths.accounts, name);
2198
+ const dir = path12.join(paths.accounts, name);
2017
2199
  const st = lstatOrNull(dir);
2018
2200
  if (!st) continue;
2019
2201
  if (st.isSymbolicLink()) out.push({ name, dir, kind: "link", entries: [] });
2020
2202
  else if (!st.isDirectory() || accounts.some((a) => a.dev === st.dev && a.ino === st.ino)) continue;
2021
2203
  else if (accountNameProblem(name)) out.push({ name, dir, kind: "stray", entries: [] });
2022
2204
  else {
2023
- const entries = fs16.readdirSync(dir).filter((e) => e !== ".DS_Store" && !lstatOrNull(path11.join(dir, e))?.isSymbolicLink());
2205
+ const entries = fs17.readdirSync(dir).filter((e) => e !== ".DS_Store" && !lstatOrNull(path12.join(dir, e))?.isSymbolicLink());
2024
2206
  out.push({ name, dir, kind: entries.length ? "content" : "leftover", entries });
2025
2207
  }
2026
2208
  }
@@ -2035,7 +2217,7 @@ function linkNames(table) {
2035
2217
  function hasContent(p) {
2036
2218
  const st = lstatOrNull(p);
2037
2219
  if (!st) return false;
2038
- if (st.isDirectory()) return fs16.readdirSync(p).some((e) => e !== ".DS_Store");
2220
+ if (st.isDirectory()) return fs17.readdirSync(p).some((e) => e !== ".DS_Store");
2039
2221
  return st.size > 0;
2040
2222
  }
2041
2223
  function keepOnlyLinks(dir, table) {
@@ -2043,19 +2225,19 @@ function keepOnlyLinks(dir, table) {
2043
2225
  const shared = linkNames(table);
2044
2226
  const content = [];
2045
2227
  let links = 0;
2046
- for (const name of fs16.readdirSync(dir)) {
2047
- const p = path11.join(dir, name);
2228
+ for (const name of fs17.readdirSync(dir)) {
2229
+ const p = path12.join(dir, name);
2048
2230
  if (shared.has(name) && lstatOrNull(p)?.isSymbolicLink()) links++;
2049
2231
  else if (shared.has(name) && hasContent(p)) content.push(name);
2050
2232
  else removeTree(p);
2051
2233
  }
2052
2234
  if (links || content.length) return { kept: true, content };
2053
- fs16.rmdirSync(dir);
2235
+ fs17.rmdirSync(dir);
2054
2236
  return { kept: false, content };
2055
2237
  }
2056
2238
 
2057
2239
  // src/link/unknown.ts
2058
- import fs17 from "node:fs";
2240
+ import fs18 from "node:fs";
2059
2241
  function unknownEntries(names, table) {
2060
2242
  return names.filter((n) => !isIgnored(n) && !isKnown(n, table)).sort();
2061
2243
  }
@@ -2071,7 +2253,7 @@ function unknownNotice(account, entry, configLabel) {
2071
2253
  function storeUnknownEntries(store, table) {
2072
2254
  let names;
2073
2255
  try {
2074
- names = fs17.readdirSync(store);
2256
+ names = fs18.readdirSync(store);
2075
2257
  } catch (e) {
2076
2258
  if (errCode(e) === "ENOENT") return [];
2077
2259
  throw e;
@@ -2080,8 +2262,8 @@ function storeUnknownEntries(store, table) {
2080
2262
  }
2081
2263
 
2082
2264
  // src/shell/rc.ts
2083
- import fs18 from "node:fs";
2084
- import path12 from "node:path";
2265
+ import fs19 from "node:fs";
2266
+ import path13 from "node:path";
2085
2267
  var START = "# >>> xclaude >>>";
2086
2268
  var END = "# <<< xclaude <<<";
2087
2269
  function dquote(s) {
@@ -2130,14 +2312,14 @@ function sourcesBashrc(text) {
2130
2312
  return text.split("\n").some((l) => !/^\s*#/.test(l) && /\.bashrc\b/.test(l) && /(^|[\s;&|({])(\.|source)\s/.test(l));
2131
2313
  }
2132
2314
  function rcTargets(env, home, platform, want) {
2133
- const zshrc = path12.join(env.ZDOTDIR || home, ".zshrc");
2134
- const bashrc = path12.join(home, ".bashrc");
2315
+ const zshrc = path13.join(env.ZDOTDIR || home, ".zshrc");
2316
+ const bashrc = path13.join(home, ".bashrc");
2135
2317
  const explicit = want.bash || want.zsh;
2136
2318
  const targets = [];
2137
- if (explicit ? want.zsh : fs18.existsSync(zshrc)) targets.push({ shell: "zsh", file: zshrc });
2138
- if (explicit ? want.bash : fs18.existsSync(bashrc)) {
2319
+ if (explicit ? want.zsh : fs19.existsSync(zshrc)) targets.push({ shell: "zsh", file: zshrc });
2320
+ if (explicit ? want.bash : fs19.existsSync(bashrc)) {
2139
2321
  targets.push({ shell: "bash", file: bashrc });
2140
- const profile = path12.join(home, ".bash_profile");
2322
+ const profile = path13.join(home, ".bash_profile");
2141
2323
  const text = platform === "darwin" ? readFileOrNull(profile) : null;
2142
2324
  if (text !== null && !sourcesBashrc(text)) targets.push({ shell: "bash", file: profile });
2143
2325
  }
@@ -2146,11 +2328,11 @@ function rcTargets(env, home, platform, want) {
2146
2328
  function writeRc(file, text, previous) {
2147
2329
  if (text === previous) return { file, status: "unchanged" };
2148
2330
  const real = realpathOrNull(file);
2149
- if (real === null && fs18.lstatSync(file, { throwIfNoEntry: false })?.isSymbolicLink()) return { file, status: "manual", text };
2331
+ if (real === null && fs19.lstatSync(file, { throwIfNoEntry: false })?.isSymbolicLink()) return { file, status: "manual", text };
2150
2332
  try {
2151
2333
  const target = real ?? file;
2152
- fs18.accessSync(path12.dirname(target), fs18.constants.W_OK);
2153
- if (previous !== null) fs18.accessSync(target, fs18.constants.W_OK);
2334
+ fs19.accessSync(path13.dirname(target), fs19.constants.W_OK);
2335
+ if (previous !== null) fs19.accessSync(target, fs19.constants.W_OK);
2154
2336
  writeFileAtomic(target, text, { mode: 420 });
2155
2337
  return { file, status: "written" };
2156
2338
  } catch (e) {
@@ -2160,9 +2342,9 @@ function writeRc(file, text, previous) {
2160
2342
  }
2161
2343
  function knownRcFiles(env, home) {
2162
2344
  return [
2163
- { shell: "zsh", file: path12.join(env.ZDOTDIR || home, ".zshrc") },
2164
- { shell: "bash", file: path12.join(home, ".bashrc") },
2165
- { shell: "bash", file: path12.join(home, ".bash_profile") }
2345
+ { shell: "zsh", file: path13.join(env.ZDOTDIR || home, ".zshrc") },
2346
+ { shell: "bash", file: path13.join(home, ".bashrc") },
2347
+ { shell: "bash", file: path13.join(home, ".bash_profile") }
2166
2348
  ];
2167
2349
  }
2168
2350
  function installedIn(env, home) {
@@ -2171,7 +2353,7 @@ function installedIn(env, home) {
2171
2353
 
2172
2354
  // src/tmux/client.ts
2173
2355
  import { spawnSync } from "node:child_process";
2174
- import path13 from "node:path";
2356
+ import path14 from "node:path";
2175
2357
  var STRIPPED_ENV = [
2176
2358
  "CLAUDE_CONFIG_DIR",
2177
2359
  "XCLAUDE_ACCOUNT",
@@ -2201,9 +2383,9 @@ function escapeArg(arg) {
2201
2383
  }
2202
2384
  var TMUX_INSTALL_HINT = process.platform === "darwin" ? "install it with: brew install tmux" : "install it with your package manager, e.g. sudo apt install tmux";
2203
2385
  function findTmux(env) {
2204
- for (const dir of (env.PATH ?? "").split(path13.delimiter)) {
2205
- if (!dir || !path13.isAbsolute(dir)) continue;
2206
- const candidate = path13.join(dir, "tmux");
2386
+ for (const dir of (env.PATH ?? "").split(path14.delimiter)) {
2387
+ if (!dir || !path14.isAbsolute(dir)) continue;
2388
+ const candidate = path14.join(dir, "tmux");
2207
2389
  if (isExecutableFile(candidate)) return candidate;
2208
2390
  }
2209
2391
  return null;
@@ -2276,10 +2458,10 @@ function readForcedOrgs(ctx) {
2276
2458
  }
2277
2459
  const files = [];
2278
2460
  for (const dir of dirs) {
2279
- files.push(path14.join(dir, "managed-settings.json"));
2461
+ files.push(path15.join(dir, "managed-settings.json"));
2280
2462
  try {
2281
- for (const name of fs19.readdirSync(path14.join(dir, "managed-settings.d")).sort()) {
2282
- if (name.endsWith(".json")) files.push(path14.join(dir, "managed-settings.d", name));
2463
+ for (const name of fs20.readdirSync(path15.join(dir, "managed-settings.d")).sort()) {
2464
+ if (name.endsWith(".json")) files.push(path15.join(dir, "managed-settings.d", name));
2283
2465
  }
2284
2466
  } catch {
2285
2467
  }
@@ -2316,7 +2498,7 @@ function readForcedOrgs(ctx) {
2316
2498
  }
2317
2499
  function remoteCleanupDays(dir) {
2318
2500
  try {
2319
- const json = JSON.parse(readFileOrNull(path14.join(dir, "remote-settings.json")) ?? "null");
2501
+ const json = JSON.parse(readFileOrNull(path15.join(dir, "remote-settings.json")) ?? "null");
2320
2502
  const value = json?.cleanupPeriodDays ?? json?.settings?.cleanupPeriodDays;
2321
2503
  return typeof value === "number" ? value : null;
2322
2504
  } catch {
@@ -2349,6 +2531,9 @@ async function doctorCommand(ctx, args) {
2349
2531
  repairAccount({ paths: ctx.paths, account: name, table, lockWaitMs: Infinity, replaceWrongLinks: true, log });
2350
2532
  }
2351
2533
  if (ctx.switches.normalizePaths && table.dirs.includes("plugins")) normalizePaths(ctx.paths, { lockWaitMs: Infinity, log });
2534
+ if (table.dirs.includes("plugins")) {
2535
+ for (const name of Object.keys(config.accounts)) listPlugins(ctx.paths, name, { lockWaitMs: Infinity, log });
2536
+ }
2352
2537
  }
2353
2538
  report.section("Tools");
2354
2539
  let claude = null;
@@ -2369,7 +2554,7 @@ async function doctorCommand(ctx, args) {
2369
2554
  report.add("ok", `Node ${process.versions.node}`);
2370
2555
  report.section("Config");
2371
2556
  if (configProblem) report.add("error", configProblem);
2372
- else report.add("ok", `${t(ctx.paths.config)}${fs19.existsSync(ctx.paths.config) ? "" : " (not created yet)"}`);
2557
+ else report.add("ok", `${t(ctx.paths.config)}${fs20.existsSync(ctx.paths.config) ? "" : " (not created yet)"}`);
2373
2558
  for (const name of table.refused) report.add("warn", `share.add "${name}" is ignored: never-shared entries and file names can't be shared`);
2374
2559
  const names = identities(config);
2375
2560
  const logins = /* @__PURE__ */ new Map();
@@ -2382,6 +2567,7 @@ async function doctorCommand(ctx, args) {
2382
2567
  if (configProblem) report.add("info", "not checked: fix the config first (account dirs are left alone)");
2383
2568
  else if (!names.length) report.add("info", "no accounts yet; add one with: xclaude add <name>");
2384
2569
  const storeDev = statOrNull(ctx.paths.store)?.dev;
2570
+ const listed = loadState(ctx.paths).listedPlugins;
2385
2571
  for (const name of names) {
2386
2572
  const login = logins.get(name);
2387
2573
  report.lines.push(` ${name}${login ? ` ${describeLogin(login)}` : ""}`);
@@ -2406,6 +2592,10 @@ async function doctorCommand(ctx, args) {
2406
2592
  }
2407
2593
  const unknown = unknownEntries(insp.names, table);
2408
2594
  if (unknown.length) report.add("info", `per-account entries xclaude doesn't know: ${unknown.join(", ")}`, 2);
2595
+ const plugins = table.dirs.includes("plugins") ? planPlugins(ctx.paths, name, listed[name] ?? [])?.add : void 0;
2596
+ if (plugins?.length) {
2597
+ report.add("info", `not in its /plugin yet, installed under another login: ${plugins.join(", ")} (the next launch, or --fix, lists ${plugins.length === 1 ? "it" : "them"} there, turned off)`, 2);
2598
+ }
2409
2599
  const dev = statOrNull(dir)?.dev;
2410
2600
  if (storeDev !== void 0 && dev !== void 0 && dev !== storeDev) {
2411
2601
  report.add(
@@ -2451,7 +2641,7 @@ ${s.orgId}`) ?? [], n]);
2451
2641
  }
2452
2642
  report.section("Store");
2453
2643
  const storeUnknown = storeUnknownEntries(ctx.paths.store, table);
2454
- if (!fs19.existsSync(ctx.paths.store)) report.add("info", `${t(ctx.paths.store)} doesn't exist yet`);
2644
+ if (!fs20.existsSync(ctx.paths.store)) report.add("info", `${t(ctx.paths.store)} doesn't exist yet`);
2455
2645
  else if (storeUnknown.length) report.add("info", `entries in ${t(ctx.paths.store)} that no account links to: ${storeUnknown.join(", ")}`);
2456
2646
  else report.add("ok", t(ctx.paths.store));
2457
2647
  const mainDays = remoteCleanupDays(ctx.paths.store);
@@ -2459,10 +2649,10 @@ ${s.orgId}`) ?? [], n]);
2459
2649
  report.add("warn", `the ~/.claude login's organization sets cleanupPeriodDays to ${mainDays}: plain claude deletes everyone's shared transcripts older than ${mainDays} days`);
2460
2650
  }
2461
2651
  for (const entry of SHARED_DIRS) {
2462
- const p2 = path14.join(ctx.paths.store, entry);
2463
- if (!fs19.existsSync(p2)) continue;
2652
+ const p2 = path15.join(ctx.paths.store, entry);
2653
+ if (!fs20.existsSync(p2)) continue;
2464
2654
  try {
2465
- fs19.accessSync(p2, fs19.constants.W_OK);
2655
+ fs20.accessSync(p2, fs20.constants.W_OK);
2466
2656
  } catch {
2467
2657
  report.add("warn", `${t(p2)} isn't writable, so sessions can't save ${entry} there`);
2468
2658
  }
@@ -2492,8 +2682,8 @@ ${s.orgId}`) ?? [], n]);
2492
2682
  }
2493
2683
 
2494
2684
  // src/shell/init.ts
2495
- import fs20 from "node:fs";
2496
- import path15 from "node:path";
2685
+ import fs21 from "node:fs";
2686
+ import path16 from "node:path";
2497
2687
  function header(shell, version) {
2498
2688
  return `# xclaude ${version}: ${shell} integration. Written by \`xclaude shell install\`, \`xclaude guard on|off\`
2499
2689
  # and after xclaude updates; don't edit, changes are overwritten.
@@ -2598,7 +2788,7 @@ ${guard ? `
2598
2788
  ${GUARD}` : ""}`;
2599
2789
  }
2600
2790
  function initFile(paths, shell) {
2601
- return path15.join(paths.shell, `init.${shell}`);
2791
+ return path16.join(paths.shell, `init.${shell}`);
2602
2792
  }
2603
2793
  function writeInitFiles(paths, config, version) {
2604
2794
  mkdirPrivate(paths.shell);
@@ -2606,11 +2796,11 @@ function writeInitFiles(paths, config, version) {
2606
2796
  writeFileAtomic(initFile(paths, "zsh"), initZsh(version, config.guard), { mode: 420 });
2607
2797
  }
2608
2798
  function refreshInitFiles(paths, config, version) {
2609
- if (fs20.existsSync(paths.shell)) writeInitFiles(paths, config, version);
2799
+ if (fs21.existsSync(paths.shell)) writeInitFiles(paths, config, version);
2610
2800
  }
2611
2801
 
2612
2802
  // package.json
2613
- var package_default = { version: "0.1.3" };
2803
+ var package_default = { version: "0.1.4" };
2614
2804
 
2615
2805
  // src/version.ts
2616
2806
  var VERSION = package_default.version;
@@ -2666,6 +2856,8 @@ Commands:
2666
2856
  Conversations, prompt history, memory and personal content (skills, agents,
2667
2857
  commands, plugins\u2026) are shared by every account, so \`xclaude other -c\`
2668
2858
  continues the last conversation in this folder, whichever account it ran on.
2859
+ Plugins are turned on per account: one installed under another login shows
2860
+ in /plugin, turned off.
2669
2861
  `;
2670
2862
  var COMMAND_HELP = {
2671
2863
  add: `Usage: xclaude add <name> [--model M] [--effort E] [--args "\u2026"]
@@ -2755,7 +2947,8 @@ Checks tools, config, every account's links and login, the shell setup,
2755
2947
  machine-managed settings and the environment. Exits non-zero if something is
2756
2948
  wrong.
2757
2949
 
2758
- --fix repair links, merge left-behind directories, fix CLAUDE.md stubs
2950
+ --fix repair links, merge left-behind directories, fix CLAUDE.md stubs,
2951
+ list plugins installed under other logins (turned off)
2759
2952
  `,
2760
2953
  help: `Usage: xclaude help [command]
2761
2954
  `
@@ -2771,13 +2964,13 @@ function wantsHelp(args) {
2771
2964
  }
2772
2965
 
2773
2966
  // src/shell/complete.ts
2774
- import fs22 from "node:fs";
2775
- import path17 from "node:path";
2967
+ import fs23 from "node:fs";
2968
+ import path18 from "node:path";
2776
2969
 
2777
2970
  // src/claude/help.ts
2778
2971
  import { spawnSync as spawnSync3 } from "node:child_process";
2779
- import fs21 from "node:fs";
2780
- import path16 from "node:path";
2972
+ import fs22 from "node:fs";
2973
+ import path17 from "node:path";
2781
2974
  var FALLBACK_SUBCOMMANDS = ["auth", "mcp", "plugin", "agents", "daemon", "doctor", "update", "install", "setup-token"];
2782
2975
  var opt = (names, value, placeholder, choices) => ({
2783
2976
  names,
@@ -2899,12 +3092,12 @@ function loadHelp(claude, cacheDir, env) {
2899
3092
  const real = realpathOrNull(claude) ?? claude;
2900
3093
  let st;
2901
3094
  try {
2902
- st = fs21.statSync(real);
3095
+ st = fs22.statSync(real);
2903
3096
  } catch {
2904
3097
  return FALLBACK_HELP;
2905
3098
  }
2906
3099
  const key = { path: real, mtimeMs: st.mtimeMs, size: st.size };
2907
- const file = path16.join(cacheDir, "claude-help.json");
3100
+ const file = path17.join(cacheDir, "claude-help.json");
2908
3101
  try {
2909
3102
  const cached = JSON.parse(readFileOrNull(file) ?? "null");
2910
3103
  if (cached && cached.key.path === key.path && cached.key.mtimeMs === key.mtimeMs && cached.key.size === key.size) {
@@ -2997,14 +3190,14 @@ function logicalWords(shell, words2, cword) {
2997
3190
  return { prior, cur };
2998
3191
  }
2999
3192
  function suggestLabel(cwd) {
3000
- const label = path17.basename(cwd).replace(/[^A-Za-z0-9_-]+/g, "-").replace(/^[^A-Za-z0-9]+/, "").slice(0, 64);
3193
+ const label = path18.basename(cwd).replace(/[^A-Za-z0-9_-]+/g, "-").replace(/^[^A-Za-z0-9]+/, "").slice(0, 64);
3001
3194
  return label || null;
3002
3195
  }
3003
3196
  function resumeCandidates(store, cwd) {
3004
- const dir = path17.join(store, "projects", cwd.replace(/[^a-zA-Z0-9]/g, "-"));
3197
+ const dir = path18.join(store, "projects", cwd.replace(/[^a-zA-Z0-9]/g, "-"));
3005
3198
  let files;
3006
3199
  try {
3007
- files = fs22.readdirSync(dir).filter((n) => n.endsWith(".jsonl")).map((n) => ({ id: n.slice(0, -".jsonl".length), file: path17.join(dir, n), mtime: fs22.statSync(path17.join(dir, n)).mtimeMs }));
3200
+ files = fs23.readdirSync(dir).filter((n) => n.endsWith(".jsonl")).map((n) => ({ id: n.slice(0, -".jsonl".length), file: path18.join(dir, n), mtime: fs23.statSync(path18.join(dir, n)).mtimeMs }));
3008
3201
  } catch {
3009
3202
  return [];
3010
3203
  }
@@ -3016,12 +3209,12 @@ function resumeCandidates(store, cwd) {
3016
3209
  function sessionTitle(file) {
3017
3210
  let head;
3018
3211
  try {
3019
- const fd = fs22.openSync(file, "r");
3212
+ const fd = fs23.openSync(file, "r");
3020
3213
  try {
3021
3214
  const buf = Buffer.alloc(16384);
3022
- head = buf.subarray(0, fs22.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
3215
+ head = buf.subarray(0, fs23.readSync(fd, buf, 0, buf.length, 0)).toString("utf8");
3023
3216
  } finally {
3024
- fs22.closeSync(fd);
3217
+ fs23.closeSync(fd);
3025
3218
  }
3026
3219
  } catch {
3027
3220
  return null;
@@ -3063,7 +3256,7 @@ var Completer = class {
3063
3256
  claudeHelp() {
3064
3257
  if (this.help) return this.help;
3065
3258
  this.help = FALLBACK_HELP;
3066
- if (fs22.existsSync(this.ctx.paths.xhome)) {
3259
+ if (fs23.existsSync(this.ctx.paths.xhome)) {
3067
3260
  try {
3068
3261
  const claude = findClaude(this.ctx.env, this.config, this.ctx.paths.home, this.ctx.selfPath);
3069
3262
  this.help = loadHelp(claude, this.ctx.paths.cache, this.ctx.env);
@@ -3250,14 +3443,14 @@ function formatCompletion(c, shell, cur) {
3250
3443
 
3251
3444
  // src/update.ts
3252
3445
  import { spawnSync as spawnSync4 } from "node:child_process";
3253
- import path18 from "node:path";
3446
+ import path19 from "node:path";
3254
3447
  var PACKAGE = "xclaude-cli";
3255
3448
  var REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE}/latest`;
3256
3449
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
3257
3450
  var FETCH_TIMEOUT_MS = 1e4;
3258
3451
  var SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
3259
3452
  function checkFile(paths) {
3260
- return path18.join(paths.cache, "update-check.json");
3453
+ return path19.join(paths.cache, "update-check.json");
3261
3454
  }
3262
3455
  function readUpdateCheck(paths) {
3263
3456
  try {
@@ -3379,82 +3572,25 @@ async function lsCommand(ctx, config, args) {
3379
3572
  }
3380
3573
 
3381
3574
  // src/core/prompt.ts
3382
- import fs23 from "node:fs";
3575
+ import fs24 from "node:fs";
3383
3576
  function confirm(question) {
3384
- fs23.writeSync(2, `${question} [y/N] `);
3577
+ fs24.writeSync(2, `${question} [y/N] `);
3385
3578
  let fd;
3386
3579
  try {
3387
- fd = fs23.openSync("/dev/tty", "r");
3580
+ fd = fs24.openSync("/dev/tty", "r");
3388
3581
  } catch {
3389
3582
  return false;
3390
3583
  }
3391
3584
  try {
3392
3585
  const buf = Buffer.alloc(256);
3393
- const n = fs23.readSync(fd, buf, 0, buf.length, null);
3586
+ const n = fs24.readSync(fd, buf, 0, buf.length, null);
3394
3587
  const answer = buf.subarray(0, n).toString("utf8").trim().toLowerCase();
3395
3588
  return answer === "y" || answer === "yes";
3396
3589
  } catch {
3397
3590
  return false;
3398
3591
  } finally {
3399
- fs23.closeSync(fd);
3400
- }
3401
- }
3402
-
3403
- // src/core/state.ts
3404
- var MAX_DIRS = 500;
3405
- function emptyState() {
3406
- return { installedVersion: null, lastAccountByDir: {}, lastUsedAccount: null, seenUnknownEntries: {} };
3407
- }
3408
- function isRecord(v) {
3409
- return typeof v === "object" && v !== null && !Array.isArray(v);
3410
- }
3411
- function loadState(paths) {
3412
- let raw;
3413
- try {
3414
- raw = JSON.parse(readFileOrNull(paths.state) ?? "{}");
3415
- } catch {
3416
- return emptyState();
3417
- }
3418
- const state = emptyState();
3419
- if (!isRecord(raw)) return state;
3420
- if (typeof raw.installedVersion === "string") state.installedVersion = raw.installedVersion;
3421
- if (typeof raw.lastUsedAccount === "string") state.lastUsedAccount = raw.lastUsedAccount;
3422
- if (isRecord(raw.lastAccountByDir)) {
3423
- for (const [dir, name] of Object.entries(raw.lastAccountByDir)) {
3424
- if (typeof name === "string") state.lastAccountByDir[dir] = name;
3425
- }
3426
- }
3427
- if (isRecord(raw.seenUnknownEntries)) {
3428
- for (const [name, entries] of Object.entries(raw.seenUnknownEntries)) {
3429
- if (Array.isArray(entries)) state.seenUnknownEntries[name] = entries.filter((e) => typeof e === "string");
3430
- }
3431
- }
3432
- return state;
3433
- }
3434
- function saveState(paths, state) {
3435
- ensureXHome(paths);
3436
- writeFileAtomic(paths.state, `${JSON.stringify(state, null, 2)}
3437
- `, { mode: 384 });
3438
- }
3439
- function updateState(paths, change) {
3440
- const state = loadState(paths);
3441
- change(state);
3442
- saveState(paths, state);
3443
- return state;
3444
- }
3445
- function recordUse(state, dir, account) {
3446
- delete state.lastAccountByDir[dir];
3447
- state.lastAccountByDir[dir] = account;
3448
- const dirs = Object.keys(state.lastAccountByDir);
3449
- for (const old of dirs.slice(0, Math.max(0, dirs.length - MAX_DIRS))) delete state.lastAccountByDir[old];
3450
- state.lastUsedAccount = account;
3451
- }
3452
- function forgetAccount(state, account) {
3453
- for (const [dir, name] of Object.entries(state.lastAccountByDir)) {
3454
- if (name === account) delete state.lastAccountByDir[dir];
3592
+ fs24.closeSync(fd);
3455
3593
  }
3456
- if (state.lastUsedAccount === account) state.lastUsedAccount = null;
3457
- delete state.seenUnknownEntries[account];
3458
3594
  }
3459
3595
 
3460
3596
  // src/grammar.ts
@@ -3750,8 +3886,8 @@ function shellCommand(ctx, config, args) {
3750
3886
  }
3751
3887
 
3752
3888
  // src/commands/tmux.ts
3753
- import fs26 from "node:fs";
3754
- import path19 from "node:path";
3889
+ import fs27 from "node:fs";
3890
+ import path20 from "node:path";
3755
3891
 
3756
3892
  // src/launch/args.ts
3757
3893
  function hasFlag(args, flag) {
@@ -3826,7 +3962,7 @@ function needsHelp(defaults, userArgs) {
3826
3962
  }
3827
3963
 
3828
3964
  // src/launch/picker.ts
3829
- import fs24 from "node:fs";
3965
+ import fs25 from "node:fs";
3830
3966
  import tty2 from "node:tty";
3831
3967
  function parseKeys(chunk) {
3832
3968
  const keys = [];
@@ -3895,7 +4031,7 @@ function preselect(names, state, cwd) {
3895
4031
  function openKeyboard() {
3896
4032
  let fd;
3897
4033
  try {
3898
- fd = fs24.openSync("/dev/tty", "r");
4034
+ fd = fs25.openSync("/dev/tty", "r");
3899
4035
  } catch {
3900
4036
  throw new UsageError("account required: there's no terminal to show the picker on (xclaude <account> [claude args\u2026])");
3901
4037
  }
@@ -3919,7 +4055,7 @@ function openKeyboard() {
3919
4055
  function pick(title, items, initial) {
3920
4056
  const keyboard = openKeyboard();
3921
4057
  const { input } = keyboard;
3922
- const write = (s) => fs24.writeSync(2, s);
4058
+ const write = (s) => fs25.writeSync(2, s);
3923
4059
  let index = Math.min(Math.max(initial, 0), items.length - 1);
3924
4060
  let drawn = 0;
3925
4061
  const draw = () => {
@@ -4000,6 +4136,7 @@ function repairForLaunch(ctx, config, account, log) {
4000
4136
  if (ctx.switches.normalizePaths && table.dirs.includes("plugins")) {
4001
4137
  normalizePaths(ctx.paths, { lockWaitMs: LAUNCH_LOCK_WAIT_MS, log });
4002
4138
  }
4139
+ if (table.dirs.includes("plugins") && !res.busy) listPlugins(ctx.paths, account, { lockWaitMs: LAUNCH_LOCK_WAIT_MS, log });
4003
4140
  return unknownEntries(res.names, table);
4004
4141
  }
4005
4142
  async function launch(ctx, config, account, userArgs) {
@@ -4025,7 +4162,7 @@ async function launch(ctx, config, account, userArgs) {
4025
4162
 
4026
4163
  // src/tmux/claude-state.ts
4027
4164
  import { spawnSync as spawnSync5 } from "node:child_process";
4028
- import fs25 from "node:fs";
4165
+ import fs26 from "node:fs";
4029
4166
  function describeAgent(e) {
4030
4167
  if (e.status === "waiting") return { text: e.waitingFor ? `needs input (${e.waitingFor})` : "needs input", rank: 3 };
4031
4168
  if (e.status === "busy") return { text: "working", rank: 2 };
@@ -4033,10 +4170,10 @@ function describeAgent(e) {
4033
4170
  return null;
4034
4171
  }
4035
4172
  function parentLookup() {
4036
- if (process.platform === "linux" && fs25.existsSync("/proc/self/stat")) {
4173
+ if (process.platform === "linux" && fs26.existsSync("/proc/self/stat")) {
4037
4174
  return (pid) => {
4038
4175
  try {
4039
- const stat = fs25.readFileSync(`/proc/${pid}/stat`, "utf8");
4176
+ const stat = fs26.readFileSync(`/proc/${pid}/stat`, "utf8");
4040
4177
  const ppid = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
4041
4178
  return Number.isFinite(ppid) ? ppid : null;
4042
4179
  } catch {
@@ -4162,8 +4299,8 @@ async function tmuxNew(ctx, config, args) {
4162
4299
  account ??= await chooseAccount(ctx, config, `Run Claude Code in tmux session "${req.label}" as`);
4163
4300
  if (!defaultsOf(config, account)) throw unknownAccount(account, config);
4164
4301
  }
4165
- const dir = path19.resolve(ctx.cwd, req.dir ?? ".");
4166
- if (!fs26.statSync(dir, { throwIfNoEntry: false })?.isDirectory()) throw new XError(`--dir ${req.dir}: not a directory`);
4302
+ const dir = path20.resolve(ctx.cwd, req.dir ?? ".");
4303
+ if (!fs27.statSync(dir, { throwIfNoEntry: false })?.isDirectory()) throw new XError(`--dir ${req.dir}: not a directory`);
4167
4304
  const existing = findByLabel(listSessions(tmux), req.label);
4168
4305
  if (existing) {
4169
4306
  throw new XError(`"${req.label}" is running (${describeSession(existing, ctx.paths.home)}): xclaude tmux attach ${req.label}, or kill it first`);