diff --git a/apps/cli/src/http/routes/ai.ts b/apps/cli/src/http/routes/ai.ts index 15706f26..132bf543 100644 --- a/apps/cli/src/http/routes/ai.ts +++ b/apps/cli/src/http/routes/ai.ts @@ -2,7 +2,7 @@ * AI Web API — /_web/ai/ routes * * 提供助手、技能、LLM 配置和工具目录的只读 HTTP 接口, - * 供 CLI serve Web 前端使用(对齐 Electron preload 的 window.*Api)。 + * 供 CLI Web 前端使用(对齐 Electron preload 的 window.*Api)。 * * - 助手/技能数据来自 ~/.chatlab/ai/{assistants,skills}/*.md * - LLM 配置来自 ~/.chatlab/ai/llm-config.json diff --git a/apps/cli/src/http/routes/nlp.ts b/apps/cli/src/http/routes/nlp.ts index 9ec1f32d..7cdb7f93 100644 --- a/apps/cli/src/http/routes/nlp.ts +++ b/apps/cli/src/http/routes/nlp.ts @@ -2,7 +2,7 @@ * NLP Web API — /_web/nlp/ routes * * 提供词频统计、词性标签、词库管理等 NLP 功能的 HTTP 接口, - * 供 CLI serve Web 前端使用(对齐 Electron preload 的 window.nlpApi)。 + * 供 CLI Web 前端使用(对齐 Electron preload 的 window.nlpApi)。 * * 业务逻辑全部来自 @openchatlab/core(类型/数据)和 * @openchatlab/node-runtime(分词引擎/词频计算/词库管理)。 diff --git a/apps/cli/src/http/routes/web/index.ts b/apps/cli/src/http/routes/web/index.ts index c6e7b952..eb9df35e 100644 --- a/apps/cli/src/http/routes/web/index.ts +++ b/apps/cli/src/http/routes/web/index.ts @@ -1,7 +1,7 @@ /** * ChatLab Internal Web API — /_web/ routes * - * 供 CLI serve Web 前端使用的内部 API(无认证、UI 友好的响应格式)。 + * 供 CLI Web 前端使用的内部 API(无认证、UI 友好的响应格式)。 * 数据格式直接对齐 QueryAdapter 接口,避免前端二次转换。 * * Route modules: diff --git a/scripts/dev-select.mjs b/scripts/dev-select.mjs index 148454ca..9d8c4f5a 100644 --- a/scripts/dev-select.mjs +++ b/scripts/dev-select.mjs @@ -19,7 +19,7 @@ const cacheFile = join(rootDir, 'node_modules', '.cache', 'dev-mode') const options = [ { key: 'desktop', label: 'Desktop (Electron)', command: 'pnpm run dev:desktop' }, - { key: 'web', label: 'Web (CLI serve + frontend)', command: 'pnpm run dev:web' }, + { key: 'web', label: 'Web (CLI start + frontend)', command: 'pnpm run dev:web' }, { key: 'server', label: 'Server Only (API backend)', command: 'pnpm run dev:serve' }, { key: 'frontend', label: 'Frontend (no backend)', command: 'pnpm run dev:app' }, ] diff --git a/scripts/dev-serve.sh b/scripts/dev-serve.sh index 8eb5f973..809a8785 100755 --- a/scripts/dev-serve.sh +++ b/scripts/dev-serve.sh @@ -7,4 +7,4 @@ pnpm run ensure:server-native exec tsx watch \ --include 'packages/core/src/**' \ --include 'packages/node-runtime/src/**' \ - apps/cli/src/cli.ts serve "$@" + apps/cli/src/cli.ts start --headless --no-open "$@" diff --git a/scripts/dev-server-command.mjs b/scripts/dev-server-command.mjs index 2329a3c4..4d03730c 100644 --- a/scripts/dev-server-command.mjs +++ b/scripts/dev-server-command.mjs @@ -1,7 +1,17 @@ -export function createChatlabServeCommand({ serverDir, backendPort, nodeExecutable = process.execPath }) { +export function createChatlabStartCommand({ serverDir, backendPort, nodeExecutable = process.execPath }) { return { command: nodeExecutable, - args: ['--watch', '--import', 'tsx', 'src/cli.ts', 'serve', '--port', String(backendPort)], + args: [ + '--watch', + '--import', + 'tsx', + 'src/cli.ts', + 'start', + '--headless', + '--no-open', + '--port', + String(backendPort), + ], options: { cwd: serverDir, stdio: ['ignore', 'pipe', 'pipe'], diff --git a/scripts/dev-server-command.test.mjs b/scripts/dev-server-command.test.mjs index 4ac0a2d6..c7fd3f44 100644 --- a/scripts/dev-server-command.test.mjs +++ b/scripts/dev-server-command.test.mjs @@ -1,10 +1,10 @@ import assert from 'node:assert/strict' import test from 'node:test' -import { createChatlabServeCommand } from './dev-server-command.mjs' +import { createChatlabStartCommand } from './dev-server-command.mjs' test('web dev backend runs through the current Node executable with the tsx loader', () => { - const command = createChatlabServeCommand({ + const command = createChatlabStartCommand({ rootDir: '/repo', serverDir: '/repo/apps/cli', coreDir: '/repo/packages/core/src', @@ -14,5 +14,15 @@ test('web dev backend runs through the current Node executable with the tsx load }) assert.equal(command.command, '/custom/node') - assert.deepEqual(command.args, ['--watch', '--import', 'tsx', 'src/cli.ts', 'serve', '--port', '3110']) + assert.deepEqual(command.args, [ + '--watch', + '--import', + 'tsx', + 'src/cli.ts', + 'start', + '--headless', + '--no-open', + '--port', + '3110', + ]) }) diff --git a/vite.web.config.mts b/vite.web.config.mts index e319c9d3..c9fdcd9f 100644 --- a/vite.web.config.mts +++ b/vite.web.config.mts @@ -1,8 +1,8 @@ /** * Web 版 Vite 构建配置 * - * 用于构建 CLI serve Web 的 SPA 前端(不含 Electron 依赖)。 - * 输出到 dist-web/,由 chatlab serve 托管。 + * 用于构建 CLI Web 的 SPA 前端(不含 Electron 依赖)。 + * 输出到 dist-web/,由 chatlab start 托管。 * * 与 Electron renderer 构建的关键区别: * - __IS_ELECTRON__ = false(使用 FetchAdapter 而非 window.chatApi) @@ -18,7 +18,7 @@ import { defineConfig, type Plugin } from 'vite' import vue from '@vitejs/plugin-vue' import ui from '@nuxt/ui/vite' import { DEFAULT_API_PORT } from './packages/config/src/schema' -import { createChatlabServeCommand } from './scripts/dev-server-command.mjs' +import { createChatlabStartCommand } from './scripts/dev-server-command.mjs' const BACKEND_PORT = DEFAULT_API_PORT @@ -35,41 +35,41 @@ function isPortInUse(port: number): Promise { } /** - * 自动启动 chatlab serve 后端的插件 + * 自动启动 chatlab start 后端的插件 * 仅在 CHATLAB_AUTO_SERVE=1 时生效(由 dev:web 脚本设置) */ function chatlabServePlugin(): Plugin { let serverProcess: ChildProcess | null = null return { - name: 'chatlab-serve', + name: 'chatlab-start', async configureServer() { if (process.env.CHATLAB_AUTO_SERVE !== '1') return const inUse = await isPortInUse(BACKEND_PORT) if (inUse) { - console.log(`[chatlab serve] Port ${BACKEND_PORT} already in use, skipping`) + console.log(`[chatlab start] Port ${BACKEND_PORT} already in use, skipping`) return } const serverDir = resolve(__dirname, 'apps/cli') - const serveCommand = createChatlabServeCommand({ + const startCommand = createChatlabStartCommand({ serverDir, backendPort: BACKEND_PORT, }) - serverProcess = spawn(serveCommand.command, serveCommand.args, serveCommand.options) + serverProcess = spawn(startCommand.command, startCommand.args, startCommand.options) serverProcess.stdout?.on('data', (data: Buffer) => { const line = data.toString().trim() - if (line) console.log(`[chatlab serve] ${line}`) + if (line) console.log(`[chatlab start] ${line}`) }) serverProcess.stderr?.on('data', (data: Buffer) => { const line = data.toString().trim() - if (line) console.error(`[chatlab serve] ${line}`) + if (line) console.error(`[chatlab start] ${line}`) }) serverProcess.on('exit', (code) => { if (code !== null && code !== 0) { - console.error(`[chatlab serve] exited with code ${code}`) + console.error(`[chatlab start] exited with code ${code}`) } serverProcess = null })