Files
cindy/scripts/kill-port.mjs
Lizi bb3f71d084 chore: Cindy 首次开源提交 / initial open-source release
Cindy 是心动网络 (X.D. Network Inc.) 的跨端 AI Agent 客户端。
本次提交包含 Desktop(Electron)、Mobile(Expo)及全部共享 packages
的完整源码,以 Apache-2.0 协议开源。

This is the first public release of Cindy, X.D. Network's cross-platform
AI agent client: the Electron desktop app, the Expo mobile app, and all
shared workspace packages, licensed under Apache-2.0.

- 许可与合规:根 LICENSE(Apache-2.0)+ NOTICE;第三方组件归属声明与
  SPDX SBOM 收口在 docs/legal/notices/,由 pnpm licenses:generate 生成。
- 社区文件:README / CONTRIBUTING / CODE_OF_CONDUCT / SECURITY / SUPPORT
  中英双语;issue / PR 模板与 CI workflow 在 .github/。
- 协议层以公开 submodule 引入:github.com/makecindy/cindy-protocol。
- 提交前已通过仓库门禁:全量 pnpm test:unit 与涉及 package 的 typecheck。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 08:30:44 +08:00

52 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
// 本地 E2E 清理服务端端口;默认 3333,也可通过 PORT 覆盖。
import { execFileSync, execSync } from 'node:child_process';
const port = Number(process.env.PORT) || 3333;
const isWindows = process.platform === 'win32';
function getPidsWindows(targetPort) {
let output = '';
try {
output = execSync('netstat -ano -p tcp', { encoding: 'utf8' });
} catch {
return [];
}
const pids = new Set();
for (const line of output.split(/\r?\n/)) {
const match = line.match(/\s+\S+:(\d+)\s+\S+\s+LISTENING\s+(\d+)/);
if (match && Number(match[1]) === targetPort && match[2] !== '0') pids.add(match[2]);
}
return [...pids];
}
function getPidsUnix(targetPort) {
try {
return execFileSync('lsof', ['-ti', `tcp:${targetPort}`, '-sTCP:LISTEN'], {
encoding: 'utf8',
}).split(/\s+/).filter(Boolean);
} catch {
return [];
}
}
const pids = isWindows ? getPidsWindows(port) : getPidsUnix(port);
if (pids.length === 0) {
console.log(`[kill-port] port ${port} is free`);
process.exit(0);
}
for (const pid of pids) {
try {
if (isWindows) {
execFileSync('taskkill', ['/F', '/PID', pid], { stdio: 'ignore' });
} else {
execFileSync('kill', ['-9', pid], { stdio: 'ignore' });
}
console.log(`[kill-port] killed pid ${pid} on port ${port}`);
} catch (error) {
console.warn(`[kill-port] failed to kill pid ${pid}: ${error.message}`);
}
}