v1.1.0: 支持 Windows 服务端部署

- 新增跨平台进程终止 killProcess(),Windows 使用 taskkill,Linux 使用 SIGTERM/SIGKILL
- spawn 增加 windowsHide 参数,HOME 路径增加 USERPROFILE fallback
- 新增 start.bat 一键启动脚本
- README 快速开始分 Linux/Windows 两部分,新增 Windows 部署章节

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel
2026-03-08 12:03:25 +00:00
parent 500c6cf9a7
commit 9485581f90
4 changed files with 78 additions and 17 deletions

View File

@@ -284,6 +284,8 @@ function modelShortName(fullModel) {
return entry ? entry[0] : null;
}
const IS_WIN = process.platform === 'win32';
function isProcessRunning(pid) {
try {
process.kill(pid, 0);
@@ -293,6 +295,18 @@ function isProcessRunning(pid) {
}
}
function killProcess(pid, force = false) {
try {
if (IS_WIN) {
const args = ['/T', '/PID', String(pid)];
if (force) args.unshift('/F');
spawn('taskkill', args, { windowsHide: true });
} else {
process.kill(pid, force ? 'SIGKILL' : 'SIGTERM');
}
} catch {}
}
function cleanRunDir(sessionId) {
const dir = runDir(sessionId);
try {
@@ -731,7 +745,7 @@ function handleSlashCommand(ws, text, sessionId) {
if (session) {
if (activeProcesses.has(sessionId)) {
const entry = activeProcesses.get(sessionId);
try { process.kill(entry.pid, 'SIGTERM'); } catch {}
killProcess(entry.pid);
if (entry.tailer) entry.tailer.stop();
activeProcesses.delete(sessionId);
cleanRunDir(sessionId);
@@ -899,7 +913,7 @@ function handleLoadSession(ws, sessionId) {
function handleDeleteSession(ws, sessionId) {
if (activeProcesses.has(sessionId)) {
const entry = activeProcesses.get(sessionId);
try { process.kill(entry.pid, 'SIGTERM'); } catch {}
try { killProcess(entry.pid); } catch {}
if (entry.tailer) entry.tailer.stop();
activeProcesses.delete(sessionId);
if (entry.ws) wsSend(entry.ws, { type: 'done', sessionId });
@@ -961,9 +975,9 @@ function handleAbort(ws) {
if (!entry) return;
plog('INFO', 'user_abort', { sessionId: sessionId.slice(0, 8), pid: entry.pid });
try { process.kill(entry.pid, 'SIGTERM'); } catch {}
killProcess(entry.pid);
setTimeout(() => {
try { process.kill(entry.pid, 'SIGKILL'); } catch {}
killProcess(entry.pid, true);
}, 3000);
// handleProcessComplete will be triggered by the PID monitor
}
@@ -1061,9 +1075,10 @@ function handleMessage(ws, msg) {
try {
proc = spawn(CLAUDE_PATH, args, {
env,
cwd: process.env.HOME || process.cwd(),
cwd: process.env.HOME || process.env.USERPROFILE || process.cwd(),
stdio: [inputFd, outputFd, errorFd],
detached: true,
windowsHide: true,
});
} catch (err) {
fs.closeSync(inputFd);