cc-viewer 1.4.16 → 1.4.17
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/cli.js +69 -3
- package/dist/assets/{index-CwFfGP5V.js → index-DdzkBF7P.js} +145 -136
- package/dist/index.html +1 -1
- package/i18n.js +3 -3
- package/interceptor.js +121 -16
- package/package.json +1 -1
- package/pty-manager.js +12 -1
- package/server.js +202 -24
package/cli.js
CHANGED
|
@@ -232,7 +232,7 @@ async function runProxyCommand(args) {
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
async function runCliMode(extraClaudeArgs = []) {
|
|
235
|
+
async function runCliMode(extraClaudeArgs = [], cwd) {
|
|
236
236
|
const nativePath = resolveNativePath();
|
|
237
237
|
if (!nativePath) {
|
|
238
238
|
console.error(t('cli.cMode.notFound'));
|
|
@@ -241,14 +241,22 @@ async function runCliMode(extraClaudeArgs = []) {
|
|
|
241
241
|
|
|
242
242
|
console.log(t('cli.cMode.starting'));
|
|
243
243
|
|
|
244
|
+
const workingDir = cwd || process.cwd();
|
|
245
|
+
|
|
246
|
+
// 注册工作区
|
|
247
|
+
const { registerWorkspace } = await import('./workspace-registry.js');
|
|
248
|
+
registerWorkspace(workingDir);
|
|
249
|
+
|
|
244
250
|
// 2. 设置 CLI 模式标记(必须在 import proxy.js 之前,
|
|
245
251
|
// 因为 proxy.js → interceptor.js 可能触发 server.js 加载,
|
|
246
252
|
// server.js 的 isCliMode 在模块顶层求值且只执行一次)
|
|
247
253
|
process.env.CCV_CLI_MODE = '1';
|
|
254
|
+
process.env.CCV_PROJECT_DIR = workingDir;
|
|
248
255
|
|
|
249
256
|
// 1. 启动代理
|
|
250
257
|
const { startProxy } = await import('./proxy.js');
|
|
251
258
|
const proxyPort = await startProxy();
|
|
259
|
+
process.env.CCV_PROXY_PORT = String(proxyPort);
|
|
252
260
|
|
|
253
261
|
// 3. 启动 HTTP 服务器
|
|
254
262
|
const serverMod = await import('./server.js');
|
|
@@ -267,7 +275,7 @@ async function runCliMode(extraClaudeArgs = []) {
|
|
|
267
275
|
|
|
268
276
|
// 3. 启动 PTY 中的 claude
|
|
269
277
|
const { spawnClaude, killPty } = await import('./pty-manager.js');
|
|
270
|
-
await spawnClaude(proxyPort,
|
|
278
|
+
await spawnClaude(proxyPort, workingDir, extraClaudeArgs);
|
|
271
279
|
|
|
272
280
|
// 4. 自动打开浏览器
|
|
273
281
|
const url = `http://127.0.0.1:${port}`;
|
|
@@ -289,6 +297,55 @@ async function runCliMode(extraClaudeArgs = []) {
|
|
|
289
297
|
process.on('SIGTERM', cleanup);
|
|
290
298
|
}
|
|
291
299
|
|
|
300
|
+
async function runCliModeWorkspaceSelector(extraClaudeArgs = []) {
|
|
301
|
+
const nativePath = resolveNativePath();
|
|
302
|
+
if (!nativePath) {
|
|
303
|
+
console.error(t('cli.cMode.notFound'));
|
|
304
|
+
process.exit(1);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
console.log(t('cli.cMode.starting'));
|
|
308
|
+
|
|
309
|
+
process.env.CCV_CLI_MODE = '1';
|
|
310
|
+
process.env.CCV_WORKSPACE_MODE = '1';
|
|
311
|
+
|
|
312
|
+
// 启动代理
|
|
313
|
+
const { startProxy } = await import('./proxy.js');
|
|
314
|
+
const proxyPort = await startProxy();
|
|
315
|
+
process.env.CCV_PROXY_PORT = String(proxyPort);
|
|
316
|
+
|
|
317
|
+
// 启动 HTTP 服务器(工作区模式,不初始化 interceptor 日志)
|
|
318
|
+
const serverMod = await import('./server.js');
|
|
319
|
+
|
|
320
|
+
// 工作区模式下 server.js 跳过了自动启动,需要手动调用
|
|
321
|
+
await serverMod.startViewer();
|
|
322
|
+
|
|
323
|
+
const port = serverMod.getPort();
|
|
324
|
+
|
|
325
|
+
// 保存 extraClaudeArgs 供后续 launch 使用
|
|
326
|
+
serverMod.setWorkspaceClaudeArgs(extraClaudeArgs);
|
|
327
|
+
|
|
328
|
+
// 自动打开浏览器
|
|
329
|
+
const url = `http://127.0.0.1:${port}`;
|
|
330
|
+
try {
|
|
331
|
+
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
|
|
332
|
+
const { execSync } = await import('node:child_process');
|
|
333
|
+
execSync(`${cmd} ${url}`, { stdio: 'ignore', timeout: 5000 });
|
|
334
|
+
} catch {}
|
|
335
|
+
|
|
336
|
+
console.log(`CC Viewer (Workspace): ${url}`);
|
|
337
|
+
|
|
338
|
+
// 注册退出处理
|
|
339
|
+
const { killPty } = await import('./pty-manager.js');
|
|
340
|
+
const cleanup = () => {
|
|
341
|
+
killPty();
|
|
342
|
+
serverMod.stopViewer();
|
|
343
|
+
process.exit();
|
|
344
|
+
};
|
|
345
|
+
process.on('SIGINT', cleanup);
|
|
346
|
+
process.on('SIGTERM', cleanup);
|
|
347
|
+
}
|
|
348
|
+
|
|
292
349
|
// === 主逻辑 ===
|
|
293
350
|
|
|
294
351
|
const args = process.argv.slice(2);
|
|
@@ -315,7 +372,16 @@ if (isVersion) {
|
|
|
315
372
|
|
|
316
373
|
if (isCliMode || isDangerousMode) {
|
|
317
374
|
const extraArgs = isDangerousMode ? ['--dangerously-skip-permissions'] : [];
|
|
318
|
-
|
|
375
|
+
|
|
376
|
+
// 解析 -d/-c 后的可选路径参数
|
|
377
|
+
const flagIndex = args.findIndex(a => a === '-d' || a === '--d' || a === '-c' || a === '--c');
|
|
378
|
+
let workspacePath = null;
|
|
379
|
+
if (flagIndex >= 0 && flagIndex + 1 < args.length && !args[flagIndex + 1].startsWith('-')) {
|
|
380
|
+
workspacePath = resolve(args[flagIndex + 1]);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// 默认用 cwd 启动,支持可选路径参数
|
|
384
|
+
runCliMode(extraArgs, workspacePath || process.cwd()).catch(err => {
|
|
319
385
|
console.error('CLI mode error:', err);
|
|
320
386
|
process.exit(1);
|
|
321
387
|
});
|