@openxiaobu/codexl 0.1.7 → 0.1.9

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 +5 -1
  2. package/dist/cli.js +70 -28
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -51,7 +51,11 @@ By default, `status` will:
51
51
  - Remaining 5-hour / weekly quotas
52
52
  - Reset times
53
53
  - A status column with local block reasons and countdowns (for example: `5h_limited(2h27m)`)
54
- - Enter an interactive mode where you can toggle `enabled` for any account by `NAME`
54
+ - Enter an interactive mode where you can toggle `enabled` for accounts:
55
+ - Up/Down: move selection
56
+ - Space: toggle `[x]` enabled / `[ ]` disabled
57
+ - Enter: confirm and save
58
+ - `q`: quit
55
59
 
56
60
  If you only want a non-interactive snapshot of the current state:
57
61
 
package/dist/cli.js CHANGED
@@ -59,37 +59,79 @@ async function handleInteractiveToggle() {
59
59
  console.log("当前环境不支持交互式操作,请直接编辑配置文件或使用 --no-interactive 选项。");
60
60
  return;
61
61
  }
62
- const rl = node_readline_1.default.createInterface({
63
- input: process.stdin,
64
- output: process.stdout
65
- });
66
- const ask = (question) => new Promise((resolve) => {
67
- rl.question(question, (answer) => resolve(answer));
68
- });
69
- try {
70
- // 允许连续切换多个账号,回车空行退出。
71
- // 这里使用账号 NAME 作为标识,与 status 表格中的首列一致。
72
- for (;;) {
73
- const name = (await ask("输入要切换启用状态的账号 NAME(直接回车退出):")).trim();
74
- if (!name) {
75
- break;
62
+ const stdin = process.stdin;
63
+ node_readline_1.default.emitKeypressEvents(stdin);
64
+ stdin.setRawMode?.(true);
65
+ const config = (0, config_1.loadConfig)();
66
+ if (config.accounts.length === 0) {
67
+ console.log("当前没有已录入账号。");
68
+ stdin.setRawMode?.(false);
69
+ return;
70
+ }
71
+ // 按名称排序,方便浏览。
72
+ const accounts = [...config.accounts].sort((a, b) => a.name.localeCompare(b.name));
73
+ let cursor = 0;
74
+ let changed = false;
75
+ const render = () => {
76
+ console.log("\n空格切换选中账号启用状态,回车确认,q 退出:\n");
77
+ for (let i = 0; i < accounts.length; i += 1) {
78
+ const account = accounts[i];
79
+ const prefix = i === cursor ? ">" : " ";
80
+ const checkbox = account.enabled ? "[x]" : "[ ]";
81
+ console.log(`${prefix} ${checkbox} ${account.name} (${account.codex_home})`);
82
+ }
83
+ };
84
+ const applyChanges = () => {
85
+ if (!changed)
86
+ return;
87
+ const latest = (0, config_1.loadConfig)();
88
+ for (const account of accounts) {
89
+ const index = latest.accounts.findIndex((item) => item.id === account.id);
90
+ if (index >= 0) {
91
+ latest.accounts[index] = account;
76
92
  }
77
- const config = (0, config_1.loadConfig)();
78
- const index = config.accounts.findIndex((item) => item.name === name);
79
- if (index < 0) {
80
- console.log(`未找到 NAME 为 "${name}" 的账号,请检查后重试。`);
81
- continue;
93
+ }
94
+ (0, config_1.saveConfig)(latest);
95
+ };
96
+ render();
97
+ const onKeypress = (_str, key) => {
98
+ if (key.name === "up") {
99
+ cursor = (cursor - 1 + accounts.length) % accounts.length;
100
+ render();
101
+ return;
102
+ }
103
+ if (key.name === "down") {
104
+ cursor = (cursor + 1) % accounts.length;
105
+ render();
106
+ return;
107
+ }
108
+ if (key.name === "space") {
109
+ accounts[cursor].enabled = !accounts[cursor].enabled;
110
+ changed = true;
111
+ render();
112
+ return;
113
+ }
114
+ if (key.name === "return" || key.name === "enter") {
115
+ applyChanges();
116
+ stdin.off("keypress", onKeypress);
117
+ stdin.setRawMode?.(false);
118
+ console.log("\n已保存账号启用状态变更。");
119
+ return;
120
+ }
121
+ if (key.name === "q" || (key.ctrl && key.name === "c")) {
122
+ stdin.off("keypress", onKeypress);
123
+ stdin.setRawMode?.(false);
124
+ if (changed) {
125
+ applyChanges();
126
+ console.log("\n已保存账号启用状态变更。");
82
127
  }
83
- const account = config.accounts[index];
84
- account.enabled = !account.enabled;
85
- config.accounts[index] = account;
86
- (0, config_1.saveConfig)(config);
87
- console.log(`账号 ${account.name} 已${account.enabled ? "启用" : "禁用"}(id=${account.id},source=${account.codex_home})。`);
128
+ else {
129
+ console.log("\n未做任何变更。");
130
+ }
131
+ return;
88
132
  }
89
- }
90
- finally {
91
- rl.close();
92
- }
133
+ };
134
+ stdin.on("keypress", onKeypress);
93
135
  }
94
136
  /**
95
137
  * 将已有的 Codex HOME 目录中的登录态复制到 codexl 自己的隔离目录并纳入管理。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openxiaobu/codexl",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "本地 Codex 多账号切换与状态管理工具",
5
5
  "type": "commonjs",
6
6
  "main": "dist/cli.js",