@bytedance/doubao-cli 2.37.1 → 2.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,18 +22,21 @@ Doubao CLI 是豆包面向终端及自动化场景的独立命令行工具。无
22
22
  通过 npm 安装:
23
23
 
24
24
  ```powershell
25
- npm install -g @bytedance/doubao-cli
25
+ npm install -g @bytedance/doubao-cli --foreground-scripts
26
26
  ```
27
27
 
28
+ `--foreground-scripts` 让 npm 安装脚本读取终端输入。首次安装或没有运行中的实例时可省略。
29
+
28
30
  查看 npm 已发布版本列表:
29
31
 
30
32
  ```powershell
31
33
  npm view @bytedance/doubao-cli versions --json
32
34
  ```
33
35
 
34
- 更新脚本会尝试停止 `--service-start` 服务任务;请先退出所有 TUI,再执行
35
- `doubao update`,或重复上面的安装命令。
36
- 有实例仍在运行时,更新会停止并提示退出,不会自动终止进程。
36
+ 更新可执行 `doubao update`,也可重复上面的安装命令。当前版本达到 2.37.3 后,`doubao update`
37
+ 可在终端中询问是否退出运行中的实例。直接用 npm 安装时,已安装版本和目标版本均需达到 2.37.3。
38
+ 输入 `Y` 会请求退出实例并继续,正在执行的任务会中断。输入 `N` 会取消本次操作。
39
+ 旧版或无法读取终端输入时,若提示仍有实例运行,请手动退出后重试。
37
40
  已下载的安装包会在 SHA-256 校验通过后复用,退出实例后重试无需重复下载。
38
41
  `doubao update` 在版本相同时提示已是最新版本;本机版本较新时保留本机版本,不自动降级。
39
42
  交互式启动时发现新版本,会询问是否更新:输入 `Y` 更新后退出,输入 `N` 继续执行原命令。
package/artifacts.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
- "version": "2.37.1",
2
+ "version": "2.38.1",
3
3
  "platforms": {
4
4
  "linux-x64": {
5
- "url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.37.1/doubao-cli-2.37.1-linux-x64-signed.tar.gz",
6
- "sha256": "c1e4ac2ebe50616dbf4be65546048fcc705b3ff6126044d62f56a2c739f97ce5",
7
- "root": "doubao-cli-2.37.1-linux-x64"
5
+ "url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.38.1/doubao-cli-2.38.1-linux-x64-signed.tar.gz",
6
+ "sha256": "39af09309a6e817506d7638f9ebe775c0f6e86025ff175640a80896d1544cafd",
7
+ "root": "doubao-cli-2.38.1-linux-x64"
8
8
  },
9
9
  "darwin-arm64": {
10
- "url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.37.1/doubao-cli-2.37.1-darwin-arm64-signed-signed.tar.gz",
11
- "sha256": "5e9e5d0b260da5f97341df6d9244b46a9485f8facd0499cf523eedd66f7b77d7",
12
- "root": "doubao-cli-2.37.1-darwin-arm64"
10
+ "url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.38.1/doubao-cli-2.38.1-darwin-arm64-signed-signed.tar.gz",
11
+ "sha256": "a53580452fe0a841f1b51e5ce7d732737053a9830a99fbff29c79d35d353ca24",
12
+ "root": "doubao-cli-2.38.1-darwin-arm64"
13
13
  },
14
14
  "win32-x64": {
15
- "url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.37.1/doubao-cli-2.37.1-win-x64-signed.zip",
16
- "sha256": "528c1dcc395ae5b4d669662596aaca9ee45069d9ef53863b63ca6a98ed797570",
17
- "root": "doubao-cli-2.37.1-win-x64"
15
+ "url": "https://lf-flow-web-cdn.doubao.com/obj/flow-doubao/doubao_cli/2.38.1/doubao-cli-2.38.1-win-x64-signed.zip",
16
+ "sha256": "e906cae447dea189e784226be6210acbc80f7bd25a5c91d6b8d48f28f4e77555",
17
+ "root": "doubao-cli-2.38.1-win-x64"
18
18
  }
19
19
  }
20
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytedance/doubao-cli",
3
- "version": "2.37.1",
3
+ "version": "2.38.1",
4
4
  "description": "Doubao CLI for terminal and automation workflows",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "bin": {
@@ -9,28 +9,6 @@ const { setTimeout: delay } = require('node:timers/promises');
9
9
  const packageRoot = path.resolve(__dirname, '..');
10
10
  const platforms = ['win32-x64', 'darwin-arm64', 'linux-x64'];
11
11
 
12
- function stopCurrentService(app, platform, execute = execFileSync) {
13
- const binary = platform === 'win32-x64' ? 'doubao.exe' : 'doubao';
14
- const executable = path.join(app, 'current', binary);
15
- let info;
16
- try {
17
- info = fs.lstatSync(executable);
18
- } catch (error) {
19
- if (error.code === 'ENOENT') return false;
20
- return false;
21
- }
22
- if (!info.isFile() || info.isSymbolicLink() || info.nlink !== 1) {
23
- return false;
24
- }
25
- try {
26
- execute(executable, ['--service-stop'],
27
- { cwd: path.dirname(executable), stdio: 'ignore', windowsHide: true, timeout: 5000 });
28
- return true;
29
- } catch {
30
- return false;
31
- }
32
- }
33
-
34
12
  function validateConfig(config, version) {
35
13
  if (config.version !== version) throw new Error('下载清单版本必须与 package.json 一致。');
36
14
  for (const platform of platforms) {
@@ -185,17 +163,29 @@ async function install(root = packageRoot, applicationRoot) {
185
163
  const payload = path.join(temporary, 'payload');
186
164
  await renameStaged(staged, payload);
187
165
  runner = support.prepareUpdater(payload, app);
188
- // Reporting metadata only: an unreadable old manifest must not block repair.
189
- let fromVersion = '';
190
- try {
191
- const manifest = JSON.parse(fs.readFileSync(path.join(app, 'current/manifest.json'), 'utf8'));
192
- if (typeof manifest.version === 'string') fromVersion = manifest.version;
193
- } catch { /* First installation or damaged old manifest. */ }
166
+ const fromVersion = support.readCurrentVersion(app);
194
167
  const operation = process.env.DOUBAO_CLI_INSTALL_OPERATION === 'update' ? 'update' : 'install';
195
- stopCurrentService(app, platform);
196
- support.invokeUpdater(path.join(runner, support.updaterName), app,
197
- ['--staging=' + path.basename(temporary), '--from-version=' + fromVersion,
198
- '--to-version=' + version, '--operation=' + operation]);
168
+ const updates = require('./update.cjs');
169
+ const updater = path.join(runner, support.updaterName);
170
+ let waitForRuntime = operation === 'update' && process.env.DOUBAO_CLI_WAIT_FOR_RUNTIME === '1';
171
+ // A CLI-initiated exit may still be draining when npm starts.
172
+ if (!waitForRuntime && updates.shouldConfirmExit(app, fromVersion, { executable: updater, version })) {
173
+ const updating = operation === 'update';
174
+ const answer = await updates.confirmUpdate(
175
+ updating ? updates.exitForUpdatePrompt : updates.exitForInstallPrompt,
176
+ updates.invalidExitAnswer);
177
+ if (answer !== true) {
178
+ const message = answer === null ? '已取消本次操作。'
179
+ : updating ? '已取消豆包 CLI 更新。' : '已取消豆包 CLI 安装。';
180
+ console.error(message);
181
+ throw Object.assign(new Error(message), { reported: true, exitCode: answer === null ? 130 : 1 });
182
+ }
183
+ waitForRuntime = updates.exitInstances(app);
184
+ }
185
+ const args = ['--staging=' + path.basename(temporary), '--from-version=' + fromVersion,
186
+ '--to-version=' + version, '--operation=' + operation];
187
+ if (waitForRuntime) args.push('--wait-for-runtime');
188
+ support.invokeUpdater(updater, app, args);
199
189
  console.log('豆包 CLI ' + version + ' 已安装。');
200
190
  try { fs.unlinkSync(path.join(app, 'downloads', artifact.sha256.toLowerCase())); }
201
191
  catch (error) {
@@ -222,8 +212,8 @@ async function install(root = packageRoot, applicationRoot) {
222
212
  }
223
213
 
224
214
  module.exports = { validateConfig, validatePath, verifyChecksum, extract, validateRuntime,
225
- cachedArchive, renameStaged, stopCurrentService, install };
215
+ cachedArchive, renameStaged, install };
226
216
  if (require.main === module) install().catch(error => {
227
217
  if (!error.reported) console.error('豆包 CLI 安装失败:' + error.message);
228
- process.exitCode = 1;
218
+ process.exitCode = error.exitCode ?? 1;
229
219
  });
package/scripts/run.cjs CHANGED
@@ -3,33 +3,9 @@
3
3
 
4
4
  const path = require('node:path');
5
5
  const { spawn } = require('node:child_process');
6
- const readline = require('node:readline');
7
6
  const runtime = require('./runtime.cjs');
8
7
  const updates = require('./update.cjs');
9
8
 
10
- function confirmUpdate() {
11
- return new Promise((resolve) => {
12
- const input = readline.createInterface({ input: process.stdin, output: process.stderr });
13
- input.once('close', () => {
14
- process.stdin.pause();
15
- process.stdin.unref();
16
- resolve(null);
17
- });
18
- input.on('SIGINT', () => input.close());
19
- const ask = () => input.question('是否现在更新?[Y/N] ', (answer) => {
20
- const choice = answer.trim().toLowerCase();
21
- if (choice !== 'y' && choice !== 'n') {
22
- console.error('请输入 Y 开始更新,或输入 N 跳过并继续。');
23
- ask();
24
- return;
25
- }
26
- resolve(choice === 'y');
27
- input.close();
28
- });
29
- ask();
30
- });
31
- }
32
-
33
9
  async function run(args = process.argv.slice(2), root = runtime.appRoot()) {
34
10
  if (args[0] === 'update') {
35
11
  if (args.length !== 1) throw new Error('用法:doubao update');
@@ -40,10 +16,18 @@ async function run(args = process.argv.slice(2), root = runtime.appRoot()) {
40
16
  const message = isInfoQuery(args) ? null : updates.notifier(version);
41
17
  if (message) {
42
18
  console.error(message);
43
- const confirmed = await confirmUpdate();
44
- if (confirmed === null) return 130;
19
+ const confirmExit = updates.shouldConfirmExit(root, version);
20
+ const confirmed = confirmExit
21
+ ? await updates.confirmUpdate(updates.exitForUpdatePrompt, updates.invalidExitAnswer)
22
+ : await updates.confirmUpdate();
23
+ if (confirmed === null) {
24
+ if (confirmExit) console.error('已取消本次操作。');
25
+ return 130;
26
+ }
45
27
  if (confirmed) {
46
- try { return await updates.update(root); }
28
+ try {
29
+ return await updates.update(root, { exitConfirmed: confirmExit });
30
+ }
47
31
  catch (error) {
48
32
  console.error(`无法更新豆包 CLI:${error.message}`);
49
33
  return 1;
@@ -72,7 +56,7 @@ async function run(args = process.argv.slice(2), root = runtime.appRoot()) {
72
56
  }
73
57
 
74
58
  function isInfoQuery(args) {
75
- if (['--version', '-v', '--help', '-h'].includes(args[0])) return true;
59
+ if (['--version', '-v', '--help', '-h', 'exit'].includes(args[0])) return true;
76
60
  return ['auth', 'login', 'logout'].includes(args[0]) &&
77
61
  args.slice(1).some((arg) => arg === '--help' || arg === '-h');
78
62
  }
@@ -45,6 +45,16 @@ function checkCurrent(root) {
45
45
  }
46
46
  }
47
47
 
48
+ function readCurrentVersion(root) {
49
+ try {
50
+ const { version } = JSON.parse(fs.readFileSync(path.join(root, 'current/manifest.json'), 'utf8'));
51
+ return typeof version === 'string' ? version : '';
52
+ } catch {
53
+ // First installation or a damaged manifest must not block repair.
54
+ return '';
55
+ }
56
+ }
57
+
48
58
  const updaterName = process.platform === 'win32' ? 'update.exe' : 'update';
49
59
 
50
60
  function invokeUpdater(executable, root, args) {
@@ -71,5 +81,5 @@ function prepareUpdater(source, root) {
71
81
  } catch (error) { fs.rmSync(runner, { recursive: true, force: true }); throw error; }
72
82
  }
73
83
 
74
- module.exports = { appRoot, directory, platform, packageRoot, checkCurrent,
84
+ module.exports = { appRoot, directory, platform, packageRoot, checkCurrent, readCurrentVersion,
75
85
  updaterName, prepareUpdater, invokeUpdater };
@@ -2,9 +2,14 @@
2
2
 
3
3
  const fs = require('node:fs');
4
4
  const path = require('node:path');
5
- const { spawn, execFileSync } = require('node:child_process');
5
+ const { spawn, spawnSync, execFileSync } = require('node:child_process');
6
+ const readline = require('node:readline');
6
7
  const runtime = require('./runtime.cjs');
7
8
 
9
+ const exitForUpdatePrompt = '检测到豆包 CLI 正在运行。退出后立即更新?正在执行的任务会中断。[Y/N] ';
10
+ const exitForInstallPrompt = '检测到豆包 CLI 正在运行。退出后继续安装?正在执行的任务会中断。[Y/N] ';
11
+ const invalidExitAnswer = '请输入 Y 确认退出,或输入 N 取消。';
12
+
8
13
  function distribution() {
9
14
  const { name, publishConfig } = require('../package.json');
10
15
  if (!/^@[a-z0-9-]+\/[a-z0-9-]+$/.test(name || '') ||
@@ -63,6 +68,89 @@ function newer(candidate, installed) {
63
68
  return false;
64
69
  }
65
70
 
71
+ function canPrompt() {
72
+ return process.stdin.isTTY === true && process.stderr.isTTY === true;
73
+ }
74
+
75
+ function supportsRuntimeControl(version) {
76
+ return !!parseVersion(version) && !newer('2.37.3', version);
77
+ }
78
+
79
+ function confirmUpdate(prompt = '是否现在更新?[Y/N] ',
80
+ invalidAnswer = '请输入 Y 开始更新,或输入 N 跳过并继续。') {
81
+ return new Promise((resolve) => {
82
+ const input = readline.createInterface({ input: process.stdin, output: process.stderr });
83
+ input.once('close', () => {
84
+ process.stdin.pause();
85
+ process.stdin.unref();
86
+ resolve(null);
87
+ });
88
+ input.on('SIGINT', () => input.close());
89
+ const ask = () => input.question(prompt, (answer) => {
90
+ const choice = answer.trim().toLowerCase();
91
+ if (choice !== 'y' && choice !== 'n') {
92
+ console.error(invalidAnswer);
93
+ ask();
94
+ return;
95
+ }
96
+ resolve(choice === 'y');
97
+ input.close();
98
+ });
99
+ ask();
100
+ });
101
+ }
102
+
103
+ function runRuntimeCommand(executable, args, timeout, execute = spawnSync) {
104
+ const cwd = path.dirname(executable);
105
+ const directory = fs.lstatSync(cwd, { throwIfNoEntry: false });
106
+ const info = directory?.isDirectory()
107
+ ? fs.lstatSync(executable, { throwIfNoEntry: false }) : null;
108
+ if (!info?.isFile() || info.nlink !== 1) {
109
+ throw new Error('当前运行时程序缺失或无效。');
110
+ }
111
+ return execute(executable, args, { cwd, encoding: 'utf8', timeout,
112
+ stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
113
+ }
114
+
115
+ function shouldConfirmExit(root, installed, {
116
+ executable = path.join(root, 'current', runtime.updaterName),
117
+ version
118
+ } = {}, execute = spawnSync) {
119
+ if (!canPrompt() || !supportsRuntimeControl(installed) ||
120
+ (version !== undefined && !supportsRuntimeControl(version))) {
121
+ return false;
122
+ }
123
+ try {
124
+ const result = runRuntimeCommand(executable, ['--app-root=' + root, '--check-runtime-lock'],
125
+ 3000, execute);
126
+ if (result.error) throw result.error;
127
+ if (result.status !== 0) {
128
+ console.error(result.stderr?.trim() || '无法检查豆包 CLI 是否可以更新。');
129
+ return false;
130
+ }
131
+ const status = result.stdout.trim();
132
+ if (status === 'busy') return true;
133
+ if (status === 'free') return false;
134
+ throw new Error('更新程序返回了无效的检查结果。');
135
+ } catch (error) {
136
+ // A failed probe cannot authorize shutdown. Keep the updater's lock check.
137
+ console.error('无法检查豆包 CLI 是否可以更新:' + error.message);
138
+ return false;
139
+ }
140
+ }
141
+
142
+ function exitInstances(root) {
143
+ // The installed runtime may have changed while the user was answering.
144
+ if (!supportsRuntimeControl(runtime.readCurrentVersion(root))) return false;
145
+ const binary = path.join(root, 'current', process.platform === 'win32' ? 'doubao.exe' : 'doubao');
146
+ const result = runRuntimeCommand(binary, ['exit', '--yes'], 5000);
147
+ if (result.status !== 0) {
148
+ throw new Error(result.stderr?.trim() ||
149
+ '无法退出豆包 CLI 实例。请手动退出后重试。', { cause: result.error });
150
+ }
151
+ return true;
152
+ }
153
+
66
154
  function latest({ packageName, registry, tag }, timeout = 15000) {
67
155
  const output = execFileSync(process.execPath, [npmCli(), 'view', `${packageName}@${tag}`, 'version',
68
156
  '--json', '--prefer-online', `--registry=${registry}`], { encoding: 'utf8', timeout, maxBuffer: 16384,
@@ -72,7 +160,7 @@ function latest({ packageName, registry, tag }, timeout = 15000) {
72
160
  return version;
73
161
  }
74
162
 
75
- async function update(root = runtime.appRoot()) {
163
+ async function update(root = runtime.appRoot(), { exitConfirmed } = {}) {
76
164
  const installed = runtime.checkCurrent(root);
77
165
  const config = distribution();
78
166
  const { packageName, registry } = config;
@@ -92,9 +180,20 @@ async function update(root = runtime.appRoot()) {
92
180
  : `当前版本 ${installed} 不低于远端版本 (${version}),无需更新。`);
93
181
  return 0;
94
182
  }
95
- const child = spawn(process.execPath, [npmCli(), 'install', '-g', `${packageName}@${version}`,
96
- '--prefix', prefix, `--registry=${registry}`], { stdio: 'inherit', windowsHide: true,
97
- env: { ...process.env, DOUBAO_CLI_INSTALL_OPERATION: 'update' } });
183
+ if (exitConfirmed === undefined && shouldConfirmExit(root, installed)) {
184
+ const answer = await confirmUpdate(exitForUpdatePrompt, invalidExitAnswer);
185
+ if (answer !== true) {
186
+ console.error(answer === null ? '已取消本次操作。' : '已取消豆包 CLI 更新。');
187
+ return answer === null ? 130 : 0;
188
+ }
189
+ exitConfirmed = true;
190
+ }
191
+ const waitForRuntime = exitConfirmed && exitInstances(root);
192
+ const args = [npmCli(), 'install', '-g', `${packageName}@${version}`,
193
+ '--prefix', prefix, `--registry=${registry}`];
194
+ const child = spawn(process.execPath, args, { stdio: 'inherit', windowsHide: true,
195
+ env: { ...process.env, DOUBAO_CLI_INSTALL_OPERATION: 'update',
196
+ DOUBAO_CLI_WAIT_FOR_RUNTIME: waitForRuntime ? '1' : '' } });
98
197
  return new Promise((resolve, reject) => {
99
198
  child.once('error', reject);
100
199
  child.once('exit', (code) => {
@@ -118,4 +217,5 @@ function notifier(installed) {
118
217
  } catch { return null; }
119
218
  }
120
219
 
121
- module.exports = { parseVersion, newer, notifier, update };
220
+ module.exports = { parseVersion, newer, notifier, update, confirmUpdate, shouldConfirmExit,
221
+ exitInstances, exitForInstallPrompt, exitForUpdatePrompt, invalidExitAnswer };