@yeaft/webchat-agent 0.0.168 → 0.0.169
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/connection.js +5 -1
- package/crew.js +26 -2
- package/package.json +1 -1
package/connection.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
createCrewSession, handleCrewHumanInput, handleCrewControl,
|
|
25
25
|
addRoleToSession, removeRoleFromSession,
|
|
26
|
-
handleListCrewSessions, handleCheckCrewExists, resumeCrewSession, removeFromCrewIndex
|
|
26
|
+
handleListCrewSessions, handleCheckCrewExists, handleDeleteCrewDir, resumeCrewSession, removeFromCrewIndex
|
|
27
27
|
} from './crew.js';
|
|
28
28
|
|
|
29
29
|
// 需要在断连期间缓冲的消息类型(Claude 输出相关的关键消息)
|
|
@@ -304,6 +304,10 @@ async function handleMessage(msg) {
|
|
|
304
304
|
await handleCheckCrewExists(msg);
|
|
305
305
|
break;
|
|
306
306
|
|
|
307
|
+
case 'delete_crew_dir':
|
|
308
|
+
await handleDeleteCrewDir(msg);
|
|
309
|
+
break;
|
|
310
|
+
|
|
307
311
|
case 'resume_crew_session':
|
|
308
312
|
await resumeCrewSession(msg);
|
|
309
313
|
break;
|
package/crew.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import { query, Stream } from './sdk/index.js';
|
|
16
16
|
import { promises as fs } from 'fs';
|
|
17
|
-
import { join } from 'path';
|
|
17
|
+
import { join, isAbsolute } from 'path';
|
|
18
18
|
import { homedir } from 'os';
|
|
19
19
|
import { execFile as execFileCb } from 'child_process';
|
|
20
20
|
import { promisify } from 'util';
|
|
@@ -383,12 +383,22 @@ export async function handleListCrewSessions(msg) {
|
|
|
383
383
|
});
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
+
/**
|
|
387
|
+
* 验证 projectDir 路径安全性:必须是绝对路径且不包含路径遍历
|
|
388
|
+
*/
|
|
389
|
+
function isValidProjectDir(dir) {
|
|
390
|
+
if (!dir || typeof dir !== 'string') return false;
|
|
391
|
+
if (!isAbsolute(dir)) return false;
|
|
392
|
+
if (/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(dir)) return false;
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
|
|
386
396
|
/**
|
|
387
397
|
* 检查工作目录下是否存在 .crew 目录
|
|
388
398
|
*/
|
|
389
399
|
export async function handleCheckCrewExists(msg) {
|
|
390
400
|
const { projectDir, requestId, _requestClientId } = msg;
|
|
391
|
-
if (!projectDir) {
|
|
401
|
+
if (!projectDir || !isValidProjectDir(projectDir)) {
|
|
392
402
|
ctx.sendToServer({
|
|
393
403
|
type: 'crew_exists_result',
|
|
394
404
|
requestId,
|
|
@@ -440,6 +450,20 @@ export async function handleCheckCrewExists(msg) {
|
|
|
440
450
|
}
|
|
441
451
|
}
|
|
442
452
|
|
|
453
|
+
/**
|
|
454
|
+
* 删除工作目录下的 .crew 目录
|
|
455
|
+
*/
|
|
456
|
+
export async function handleDeleteCrewDir(msg) {
|
|
457
|
+
const { projectDir, _requestClientId } = msg;
|
|
458
|
+
if (!isValidProjectDir(projectDir)) return;
|
|
459
|
+
const crewDir = join(projectDir, '.crew');
|
|
460
|
+
try {
|
|
461
|
+
await fs.rm(crewDir, { recursive: true, force: true });
|
|
462
|
+
} catch {
|
|
463
|
+
// ignore errors (dir may not exist)
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
443
467
|
/**
|
|
444
468
|
* 恢复已停止的 crew session
|
|
445
469
|
*/
|