codex-slot 0.1.17 → 0.1.18

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.
@@ -71,15 +71,50 @@ function resolveEmailFromAuth(auth) {
71
71
  return undefined;
72
72
  }
73
73
  }
74
+ /**
75
+ * 将来源 HOME 下的账号级 `.auth.json` 文件集合镜像到目标 HOME。
76
+ *
77
+ * 业务含义:
78
+ * 1. 仅同步 `accounts` 目录下的账号级认证文件。
79
+ * 2. 来源不存在某个 `.auth.json` 时,会删除目标中的同名残留,避免旧登录态混入。
80
+ * 3. 来源缺少 `accounts` 目录时,视为没有任何账号级认证文件。
81
+ *
82
+ * @param sourceAccountsDir 来源 `accounts` 目录绝对路径。
83
+ * @param targetAccountsDir 目标 `accounts` 目录绝对路径。
84
+ * @returns 无返回值。
85
+ * @throws 当文件复制或删除失败时透传文件系统错误。
86
+ */
87
+ function syncAccountAuthFiles(sourceAccountsDir, targetAccountsDir) {
88
+ const sourceAuthFiles = new Set();
89
+ if (node_fs_1.default.existsSync(sourceAccountsDir)) {
90
+ for (const entry of node_fs_1.default.readdirSync(sourceAccountsDir, { withFileTypes: true })) {
91
+ if (!entry.isFile() || !entry.name.endsWith(".auth.json")) {
92
+ continue;
93
+ }
94
+ sourceAuthFiles.add(entry.name);
95
+ node_fs_1.default.copyFileSync(node_path_1.default.join(sourceAccountsDir, entry.name), node_path_1.default.join(targetAccountsDir, entry.name));
96
+ }
97
+ }
98
+ for (const entry of node_fs_1.default.readdirSync(targetAccountsDir, { withFileTypes: true })) {
99
+ if (!entry.isFile() || !entry.name.endsWith(".auth.json")) {
100
+ continue;
101
+ }
102
+ if (!sourceAuthFiles.has(entry.name)) {
103
+ node_fs_1.default.rmSync(node_path_1.default.join(targetAccountsDir, entry.name), { force: true });
104
+ }
105
+ }
106
+ }
74
107
  /**
75
108
  * 将来源 HOME 下的官方 `.codex` 登录态复制到目标 HOME。
76
109
  *
77
110
  * 只复制认证和账号元数据所需文件,不复制历史日志、缓存等无关内容。
111
+ * 其中 `auth.json` 为必需文件,`accounts/registry.json` 与账号级 `.auth.json`
112
+ * 允许缺失;缺失时会同步删除目标中的对应残留文件,避免旧缓存污染当前登录态。
78
113
  *
79
114
  * @param sourceHome 来源 HOME 目录。
80
115
  * @param targetHome 目标 HOME 目录。
81
116
  * @returns 无返回值。
82
- * @throws 当来源目录缺少关键认证文件时抛出错误。
117
+ * @throws 当来源目录缺少 `auth.json` 或复制失败时抛出错误。
83
118
  */
84
119
  function cloneCodexAuthState(sourceHome, targetHome) {
85
120
  const sourceCodexDir = getCodexDataDir(sourceHome);
@@ -87,25 +122,21 @@ function cloneCodexAuthState(sourceHome, targetHome) {
87
122
  const sourceAuthPath = node_path_1.default.join(sourceCodexDir, "auth.json");
88
123
  const sourceAccountsDir = node_path_1.default.join(sourceCodexDir, "accounts");
89
124
  const sourceRegistryPath = node_path_1.default.join(sourceAccountsDir, "registry.json");
125
+ const targetAccountsDir = node_path_1.default.join(targetCodexDir, "accounts");
126
+ const targetRegistryPath = node_path_1.default.join(targetAccountsDir, "registry.json");
90
127
  if (!node_fs_1.default.existsSync(sourceAuthPath)) {
91
128
  throw new Error((0, text_1.bi)(`来源目录缺少 auth.json: ${sourceAuthPath}`, `Source directory is missing auth.json: ${sourceAuthPath}`));
92
129
  }
93
- if (!node_fs_1.default.existsSync(sourceRegistryPath)) {
94
- throw new Error((0, text_1.bi)(`来源目录缺少 registry.json: ${sourceRegistryPath}`, `Source directory is missing registry.json: ${sourceRegistryPath}`));
95
- }
96
130
  node_fs_1.default.mkdirSync(targetCodexDir, { recursive: true });
97
- node_fs_1.default.mkdirSync(node_path_1.default.join(targetCodexDir, "accounts"), { recursive: true });
131
+ node_fs_1.default.mkdirSync(targetAccountsDir, { recursive: true });
98
132
  node_fs_1.default.copyFileSync(sourceAuthPath, node_path_1.default.join(targetCodexDir, "auth.json"));
99
- node_fs_1.default.copyFileSync(sourceRegistryPath, node_path_1.default.join(targetCodexDir, "accounts", "registry.json"));
100
- for (const entry of node_fs_1.default.readdirSync(sourceAccountsDir, { withFileTypes: true })) {
101
- if (!entry.isFile()) {
102
- continue;
103
- }
104
- if (!entry.name.endsWith(".auth.json")) {
105
- continue;
106
- }
107
- node_fs_1.default.copyFileSync(node_path_1.default.join(sourceAccountsDir, entry.name), node_path_1.default.join(targetCodexDir, "accounts", entry.name));
133
+ if (node_fs_1.default.existsSync(sourceRegistryPath)) {
134
+ node_fs_1.default.copyFileSync(sourceRegistryPath, targetRegistryPath);
135
+ }
136
+ else {
137
+ node_fs_1.default.rmSync(targetRegistryPath, { force: true });
108
138
  }
139
+ syncAccountAuthFiles(sourceAccountsDir, targetAccountsDir);
109
140
  }
110
141
  /**
111
142
  * 检查某个 HOME 下的官方登录态是否完整。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-slot",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "本地 Codex 多账号切换与状态管理工具",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cli.js",