@linjz/opencode-qqbot 0.3.0 → 0.3.1

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/README.md CHANGED
@@ -71,6 +71,8 @@ openqq # npm 全局安装后
71
71
 
72
72
  Windows 常驻:`deploy/` 目录内有任务计划(开机自启、看门狗心跳守护)脚本与说明。
73
73
 
74
+ > **跨平台**:bot 本体零 OS 分支(纯 TS/Bun + HTTP/WS,与 QQ 官方 SDK 同形态)。Linux/macOS 常驻用 `systemd --user` 或 `nohup bun run src/index.ts &` 即可;端口自动发现在三个系统都可用(Linux 走 `ss -tln`,macOS 走 `netstat -an -p tcp`,Windows 走 `netstat -ano -p tcp`)。
75
+
74
76
  ## 指令一览
75
77
 
76
78
  | 指令 | 说明 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linjz/opencode-qqbot",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "QQ Bot for OpenCode AI - chat with AI coding assistant via QQ",
6
6
  "bin": {
@@ -20,7 +20,13 @@
20
20
  "src",
21
21
  "tsconfig.json"
22
22
  ],
23
- "keywords": ["qq", "bot", "opencode", "ai", "coding-assistant"],
23
+ "keywords": [
24
+ "qq",
25
+ "bot",
26
+ "opencode",
27
+ "ai",
28
+ "coding-assistant"
29
+ ],
24
30
  "license": "MIT",
25
31
  "repository": {
26
32
  "type": "git",
@@ -40,31 +40,49 @@ export function isOpencodeInfo(body: unknown): boolean {
40
40
  )
41
41
  }
42
42
 
43
- // netstat 输出 → 本机监听口列表(去重,保持首次出现序)。
44
- // 兼容 IPv4(127.0.0.1:P / 0.0.0.0:P)、IPv6([::1]:P / [::]:P)与 TCPv6 行;
45
- // 非监听态(ESTABLISHED/TIME_WAIT/…)与表头噪声一律忽略。
43
+ // netstat/ss 输出 → 本机监听口列表(去重,保持首次出现序)。
44
+ // 跨平台兼容三形态(QQ 官方插件纯 TS 零 OS 分支为参照——我们也要不挑系统):
45
+ // Windows: TCP 127.0.0.1:28894 0.0.0.0:0 LISTENING 44152
46
+ // Linux ss: LISTEN 0 128 127.0.0.1:28894 0.0.0.0:*
47
+ // macOS: tcp4 0 0 127.0.0.1.28894 *.* LISTEN(注意 macOS 是点分隔)
48
+ // 规则:LISTEN(ING) 行内,取含 : 或 . 分隔的地址列,末段数字即端口;
49
+ // 裸 IP 末段可能误当端口(如 127.0.0.1 → 1),无害——探测时签名不符即跳过。
46
50
  export function parseListenPorts(output: string): number[] {
47
51
  const ports = new Set<number>()
48
52
  for (const raw of output.split(/\r?\n/)) {
49
53
  const line = raw.trim()
50
- if (!/^(TCP|TCPv6)\s/i.test(line) || !/LISTENING/i.test(line)) continue
51
- const cols = line.split(/\s+/)
52
- if (cols.length < 4) continue
53
- const local = cols[1] ?? ""
54
- const port = Number(local.slice(local.lastIndexOf(":") + 1))
55
- if (Number.isInteger(port) && port > 0 && port < 65536) ports.add(port)
54
+ if (!/\bLISTEN(?:ING)?\b/i.test(line)) continue
55
+ for (const col of line.split(/\s+/)) {
56
+ const m = /^[\w.[\]:%*]*[:.](\d+)$/.exec(col)
57
+ if (!m) continue
58
+ const port = Number(m[1])
59
+ if (Number.isInteger(port) && port > 0 && port < 65536) ports.add(port)
60
+ }
56
61
  }
57
62
  return [...ports]
58
63
  }
59
64
 
65
+ // 跨平台监听口枚举:Windows=netstat -ano -p tcp;Linux=ss -tln(兜底 netstat -tln);
66
+ // macOS=netstat -an -p tcp(兜底 ss)。命令失败→换备选→全灭则记日志返回空。
60
67
  async function listListenPorts(): Promise<number[]> {
61
- try {
62
- const { stdout } = await execAsync("netstat -ano -p tcp", { maxBuffer: 10 * 1024 * 1024, timeout: 10_000 })
63
- return parseListenPorts(stdout)
64
- } catch (error) {
65
- console.log(`[discovery] netstat 不可用,跳过端口扫描: ${error instanceof Error ? error.message : error}`)
66
- return []
68
+ const platform = process.platform
69
+ const candidates: string[] =
70
+ platform === "win32"
71
+ ? ["netstat -ano -p tcp"]
72
+ : platform === "darwin"
73
+ ? ["netstat -an -p tcp", "ss -tln"]
74
+ : ["ss -tln", "netstat -tln"]
75
+ for (const cmd of candidates) {
76
+ try {
77
+ const { stdout } = await execAsync(cmd, { maxBuffer: 10 * 1024 * 1024, timeout: 10_000 })
78
+ const ports = parseListenPorts(stdout)
79
+ if (ports.length > 0) return ports
80
+ } catch (error) {
81
+ console.log(`[discovery] ${cmd.split(" ")[0]} 不可用: ${error instanceof Error ? error.message : error}`)
82
+ }
67
83
  }
84
+ console.log("[discovery] 监听口枚举工具全部不可用,跳过端口扫描")
85
+ return []
68
86
  }
69
87
 
70
88
  // 探测单个 /api/info URL;命中签名返回版本号,否则 null