dsh-qqbot-muu 0.1.15 → 0.1.21

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.
Files changed (171) hide show
  1. package/CHANGELOG.md +168 -85
  2. package/client/qqbot-settings.js +13401 -12024
  3. package/config/modules.json +212 -0
  4. package/dist/channel-tools.js +21 -10
  5. package/dist/config.d.ts +14 -0
  6. package/dist/config.js +573 -449
  7. package/dist/features/contextless-store.js +247 -247
  8. package/dist/features/contextless-trim.js +455 -34
  9. package/dist/features/four-source.js +338 -336
  10. package/dist/features/group-join-request.js +289 -287
  11. package/dist/features/local-models.js +1494 -0
  12. package/dist/features/rotate-summarizer.js +438 -0
  13. package/dist/features/scenario-detect.js +321 -0
  14. package/dist/features/scheduler.js +8 -1
  15. package/dist/features/session-rotate.js +499 -0
  16. package/dist/features/session-title.js +199 -0
  17. package/dist/features/style-layer.js +501 -0
  18. package/dist/features/thinking-log.js +71 -69
  19. package/dist/gateway/bootstrap.js +1704 -1388
  20. package/dist/gateway/data-root.js +77 -3
  21. package/dist/gateway/middleware-setup.js +6 -3
  22. package/dist/index.js +4 -2
  23. package/dist/model/settings-reader.js +193 -102
  24. package/dist/session/session-manager.js +1730 -1587
  25. package/dist/shared/paths.js +128 -0
  26. package/dist/shared/settings-io.js +79 -0
  27. package/dist/transport/inbound.js +20 -1
  28. package/dist/transport/outbound.js +56 -4
  29. package/docs/RELEASE_CHECKLIST.md +24 -2
  30. package/dshqqbot/.qqbot-extensions/hooks/interview-panel.mjs +41 -1
  31. package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
  32. package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -689
  33. package/dshqqbot/.qqbot-extensions/inbound/ac-image-see.mjs +1 -1
  34. package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
  35. package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
  36. package/dshqqbot/.qqbot-extensions/lib/.pet-form.json +1 -1
  37. package/dshqqbot/.qqbot-extensions/lib/draw-core.mjs +238 -7
  38. package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -394
  39. package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
  40. package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
  41. package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
  42. package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
  43. package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
  44. package/dshqqbot/.qqbot-extensions/lib/plugin-dir.mjs +14 -4
  45. package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
  46. package/dshqqbot/.qqbot-extensions/lib/vision.mjs +1 -1
  47. package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
  48. package/dshqqbot/.qqbot-extensions/outbound/ac-media-fix.mjs +5 -1
  49. package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
  50. package/dshqqbot/.qqbot-extensions/outbound/split-reply.mjs +18 -2
  51. package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
  52. package/dshqqbot/.qqbot-extensions/tools/draw.mjs +22 -1
  53. package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
  54. package/dshqqbot/.qqbot-extensions/tools/pet_card.mjs +3 -2
  55. package/dshqqbot/.qqbot-extensions/tools/storyboard.mjs +3 -1
  56. package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
  57. package/package.json +119 -111
  58. package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
  59. package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
  60. package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
  61. package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
  62. package/scripts/_add_maintenance_cfg.py +20 -0
  63. package/scripts/_bench_keeplease.sh +10 -0
  64. package/scripts/_dbg_purge.py +15 -0
  65. package/scripts/_elev.sh +6 -0
  66. package/scripts/_fix_all_admin.cmd +16 -0
  67. package/scripts/_livecheck-image.mjs +33 -0
  68. package/scripts/_livecheck-llm.mjs +34 -0
  69. package/scripts/_livecheck-tts.mjs +37 -0
  70. package/scripts/_patch_curve.py +88 -0
  71. package/scripts/_patch_fan_thermal.py +24 -0
  72. package/scripts/_tag_tmp.py +13 -0
  73. package/scripts/adb-broker-client.mjs +87 -0
  74. package/scripts/adb-broker.mjs +205 -0
  75. package/scripts/ai-mode.cmd +6 -0
  76. package/scripts/ai-mode.py +387 -0
  77. package/scripts/ai-toolkit.py +607 -0
  78. package/scripts/apply-fan-gpu45.py +51 -0
  79. package/scripts/bench-fans.py +515 -0
  80. package/scripts/bench-load-direct.py +63 -0
  81. package/scripts/boot-tasks-hidden.vbs +20 -0
  82. package/scripts/boot-tasks.cmd +277 -0
  83. package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
  84. package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
  85. package/scripts/chat-archive/build-sft-v4.py +566 -0
  86. package/scripts/chat-archive/build-sft.py +390 -0
  87. package/scripts/chat-archive/eval-sft.py +155 -0
  88. package/scripts/chat-archive/extract-memory.py +143 -0
  89. package/scripts/chat-archive/inventory.py +182 -0
  90. package/scripts/chat-archive/merge-sft.py +114 -0
  91. package/scripts/chat-archive/qce-pull.py +217 -0
  92. package/scripts/chat-archive/qqheader.py +110 -0
  93. package/scripts/chat-archive/qqkey2.py +113 -0
  94. package/scripts/chat-archive/qqprobe.py +153 -0
  95. package/scripts/chat-archive/screen-collect.py +163 -0
  96. package/scripts/chat-archive/sqlcipher_probe.py +444 -0
  97. package/scripts/comfy_gen.py +209 -0
  98. package/scripts/compose-video.py +168 -0
  99. package/scripts/dl_models.py +45 -0
  100. package/scripts/draw-now.cmd +18 -0
  101. package/scripts/dsh-instance-guard.mjs +20 -2
  102. package/scripts/elev-extra.cmd +25 -0
  103. package/scripts/episode.py +529 -0
  104. package/scripts/fan-curve.py +218 -0
  105. package/scripts/fan-guard.cmd +8 -0
  106. package/scripts/fan-mode.py +380 -0
  107. package/scripts/fan_manual_safe.py +33 -0
  108. package/scripts/fan_restore_manual.py +46 -0
  109. package/scripts/fc_curves.py +359 -0
  110. package/scripts/fix-fan-and-timers.cmd +39 -0
  111. package/scripts/fix_admin_all.py +94 -0
  112. package/scripts/flows.mjs +224 -0
  113. package/scripts/gateway.cmd +126 -0
  114. package/scripts/gen-image.py +420 -0
  115. package/scripts/gen-video.py +186 -0
  116. package/scripts/git-askpass.cmd +2 -2
  117. package/scripts/gpu-mode.py +195 -0
  118. package/scripts/hw-profile.py +175 -0
  119. package/scripts/install-schedule.cmd +37 -0
  120. package/scripts/install-watch.cmd +29 -0
  121. package/scripts/matte-cutout.py +106 -0
  122. package/scripts/media-enhance.py +402 -0
  123. package/scripts/memory-audit.py +581 -0
  124. package/scripts/migrate-scope.mjs +140 -139
  125. package/scripts/model-registry.py +519 -0
  126. package/scripts/openid-audit.mjs +219 -0
  127. package/scripts/pull-gguf.py +127 -0
  128. package/scripts/purge-standby.py +151 -0
  129. package/scripts/qq-connect-login.py +133 -0
  130. package/scripts/qq-ip-sync-hidden.vbs +5 -0
  131. package/scripts/qq-ip-sync.py +300 -0
  132. package/scripts/qq-login-once.cmd +20 -0
  133. package/scripts/qq-login-qr.py +72 -0
  134. package/scripts/qq-whitelist-fix.cmd +27 -0
  135. package/scripts/qq-whitelist-login.cmd +26 -0
  136. package/scripts/qq-whitelist.cmd +12 -0
  137. package/scripts/qq-whitelist.py +1452 -0
  138. package/scripts/quality-compare.py +134 -0
  139. package/scripts/release-all.mjs +636 -430
  140. package/scripts/release-check.mjs +244 -226
  141. package/scripts/resume-coder.cmd +38 -0
  142. package/scripts/secure-room/index.html +334 -0
  143. package/scripts/secure-room/server.py +582 -0
  144. package/scripts/security-check.mjs +164 -0
  145. package/scripts/selftest-local-llm.mjs +20 -0
  146. package/scripts/selftest-local-models.mjs +754 -0
  147. package/scripts/selftest-rotate-style.mjs +308 -0
  148. package/scripts/shutdown-s5-optional.cmd +21 -0
  149. package/scripts/sleep-2325.cmd +75 -0
  150. package/scripts/start-comfyui.cmd +5 -0
  151. package/scripts/start-strata.cmd +17 -0
  152. package/scripts/start-strata.vbs +11 -0
  153. package/scripts/start-watch-hidden.vbs +3 -0
  154. package/scripts/stickers/auto-tag.mjs +161 -0
  155. package/scripts/storage.mjs +236 -0
  156. package/scripts/sync-plugin-copies.mjs +98 -23
  157. package/scripts/tests/test-qq-whitelist.py +192 -0
  158. package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
  159. package/scripts/train/gguf-quantize.py +92 -0
  160. package/scripts/train/gguf-to-hf.py +112 -0
  161. package/scripts/train/merge-lora.py +51 -0
  162. package/scripts/train/probe-mirrors.sh +12 -0
  163. package/scripts/train/probe-mirrors2.sh +20 -0
  164. package/scripts/train/setup-wsl.sh +23 -0
  165. package/scripts/train/setup-wsl2.sh +25 -0
  166. package/scripts/train/setup-wsl3.sh +22 -0
  167. package/scripts/train/setup-wsl4.sh +22 -0
  168. package/scripts/train/train-lora.py +319 -0
  169. package/scripts/vram-free.py +104 -0
  170. package/scripts/wechat-full-pull.mjs +1 -1
  171. package/settings-host.js +1047 -12
@@ -0,0 +1,195 @@
1
+ # -*- coding: utf-8 -*-
2
+ """gpu-mode.py —— 显卡「任务内 / 任务后」两种状态切换(风扇档位 + 显存回收)。
3
+
4
+ 风扇由 FanControl 管理(GPU 日常 22%、CPU 55%、进风 30%、出风 31%)。跑本地任务时
5
+ 88C 只吹 22% 会过热降频,所以这里在任务开始切「任务档」(GPU 80%),任务结束切回
6
+ 「日常档」,并卸掉模型等温度回落。档位实现在 scripts/fan-mode.py。
7
+ 可选:--pl 改功耗墙(需要管理员,没有权限就只提示,不改)。
8
+
9
+ 用法:
10
+ python scripts/gpu-mode.py --status # 看温度/风扇/功耗/显存 + 谁占着卡
11
+ python scripts/gpu-mode.py --cool # 卸模型 + 等降温(任务结束后调用)
12
+ python scripts/gpu-mode.py --cool --idle-temp 50 --timeout 180
13
+ python scripts/gpu-mode.py --watch 60 # 采样 60 秒,打印峰值(任务内用)
14
+ python scripts/gpu-mode.py --pl 200 # 改功耗墙(需管理员,可回 250)
15
+ """
16
+ import argparse
17
+ import json
18
+ import os
19
+ import subprocess
20
+ import sys
21
+ import time
22
+
23
+ ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
24
+ CREATE_NO_WINDOW = 0x08000000
25
+ WARN_TEMP = 83
26
+ SAFE_TEMP = 88
27
+
28
+
29
+ def smi(*fields):
30
+ try:
31
+ out = subprocess.run(
32
+ ["nvidia-smi", "--query-gpu=" + ",".join(fields), "--format=csv,noheader,nounits"],
33
+ capture_output=True, text=True, timeout=15, creationflags=CREATE_NO_WINDOW)
34
+ line = (out.stdout or "").strip().splitlines()
35
+ if not line:
36
+ return None
37
+ return [x.strip() for x in line[0].split(",")]
38
+ except Exception:
39
+ return None
40
+
41
+
42
+ def status():
43
+ row = smi("name", "temperature.gpu", "fan.speed", "power.draw", "power.limit",
44
+ "memory.used", "memory.total", "utilization.gpu")
45
+ if not row:
46
+ print("nvidia-smi 不可用")
47
+ return 1
48
+ name, temp, fan, power, plimit, used, total, util = row
49
+ print("gpu : %s" % name)
50
+ print("temp : %s C fan: %s%% power: %s / %s W util: %s%%" %
51
+ (temp, fan, power, plimit, util))
52
+ print("vram : %s / %s MiB" % (used, total))
53
+ try:
54
+ temp_i = int(float(temp))
55
+ if temp_i >= SAFE_TEMP:
56
+ print("WARN : 温度 %dC 已超过安全线 %dC,建议停掉任务" % (temp_i, SAFE_TEMP))
57
+ elif temp_i >= WARN_TEMP:
58
+ print("WARN : 温度 %dC 偏高(>=%dC)" % (temp_i, WARN_TEMP))
59
+ except ValueError:
60
+ pass
61
+ return 0
62
+
63
+
64
+ def cool(idle_temp=55, timeout=180):
65
+ """任务后回归:先卸显存,再等温度降下来。"""
66
+ vf = os.path.join(ROOT, "scripts", "vram-free.py")
67
+ if os.path.exists(vf):
68
+ try:
69
+ subprocess.run([sys.executable, vf, "--all"], timeout=90,
70
+ creationflags=CREATE_NO_WINDOW,
71
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
72
+ except Exception:
73
+ pass
74
+ t0 = time.time()
75
+ last = None
76
+ while time.time() - t0 < timeout:
77
+ row = smi("temperature.gpu", "fan.speed", "memory.used")
78
+ if not row:
79
+ return 1
80
+ try:
81
+ temp = int(float(row[0]))
82
+ except ValueError:
83
+ time.sleep(5)
84
+ continue
85
+ if temp != last:
86
+ print("[gpu-mode] %ds: %dC fan=%s%% vram=%s MiB" %
87
+ (int(time.time() - t0), temp, row[1], row[2]))
88
+ last = temp
89
+ if temp <= idle_temp:
90
+ print("[gpu-mode] 已降温到 %dC(目标 <= %dC),显存 %s MiB" % (temp, idle_temp, row[2]))
91
+ return 0
92
+ time.sleep(5)
93
+ print("[gpu-mode] 超时 %ds 仍未降到 %dC(当前 %sC),风扇会继续自转" % (timeout, idle_temp, last))
94
+ return 2
95
+
96
+
97
+ def watch(seconds):
98
+ peak_t = peak_f = 0
99
+ peak_p = 0.0
100
+ t0 = time.time()
101
+ while time.time() - t0 < seconds:
102
+ row = smi("temperature.gpu", "fan.speed", "power.draw")
103
+ if row:
104
+ try:
105
+ t, f, p = int(float(row[0])), int(float(row[1])), float(row[2])
106
+ peak_t, peak_f = max(peak_t, t), max(peak_f, f)
107
+ peak_p = max(peak_p, p)
108
+ if t >= WARN_TEMP:
109
+ print("WARN: %dC fan=%d%% power=%.0fW" % (t, f, p), flush=True)
110
+ except ValueError:
111
+ pass
112
+ time.sleep(5)
113
+ print("[gpu-mode] %ds 峰值: %dC fan=%d%% power=%.0fW" % (seconds, peak_t, peak_f, peak_p))
114
+ return 0
115
+
116
+
117
+ def set_pl(watts):
118
+ p = subprocess.run(["nvidia-smi", "-pl", str(watts)], capture_output=True, text=True,
119
+ creationflags=CREATE_NO_WINDOW)
120
+ ok = p.returncode == 0
121
+ print((p.stdout or "").strip() or (p.stderr or "").strip())
122
+ if not ok:
123
+ print("[gpu-mode] 改功耗墙需要管理员权限;不装 Afterburner 时直接用 BIOS 风扇曲线即可")
124
+ return 1
125
+ print("[gpu-mode] 功耗墙已设为 %dW" % watts)
126
+ return 0
127
+
128
+
129
+ FANMODE = os.path.join(ROOT, "scripts", "fan-mode.py")
130
+
131
+
132
+ def set_fan(restore=False):
133
+ """风扇档位:交给 fan-mode.py(FanControl --config 热切换 日常档/任务档)。
134
+
135
+ 背景:Windows 下 NVIDIA 不开放 fan control,nvidia-smi 只能读不能写;用户的风扇
136
+ 由 FanControl 统一管理(GPU 日常 22%、CPU 55%)。fan-mode.py 生成两份 FanControl
137
+ 配置,任务开始切「任务档」(GPU 80%),结束切回「日常档」。
138
+ """
139
+ if not os.path.exists(FANMODE):
140
+ print("[gpu-mode] 缺少 scripts/fan-mode.py,无法切风扇档")
141
+ return 3
142
+ args = [sys.executable, FANMODE, "--daily" if restore else "--task"]
143
+ try:
144
+ p = subprocess.run(args, timeout=90, creationflags=CREATE_NO_WINDOW)
145
+ return 0 if p.returncode == 0 else 4
146
+ except Exception as e:
147
+ print("[gpu-mode] fan-mode 调用失败: %s" % e)
148
+ return 1
149
+
150
+
151
+ def task_mode():
152
+ """任务开始:风扇拉高(有 Afterburner 时)+ 记录基线。"""
153
+ set_fan()
154
+ return status()
155
+
156
+
157
+ def restore_mode(idle_temp=55):
158
+ """任务结束:风扇回自动 + 卸显存 + 等降温。"""
159
+ set_fan(restore=True)
160
+ return cool(idle_temp)
161
+
162
+
163
+ def main():
164
+ ap = argparse.ArgumentParser()
165
+ ap.add_argument("--status", action="store_true")
166
+ ap.add_argument("--cool", action="store_true")
167
+ ap.add_argument("--fan", action="store_true", help="切换到 Afterburner 的「任务」风扇档")
168
+ ap.add_argument("--task", action="store_true", help="任务开始:提风扇 + 打印状态")
169
+ ap.add_argument("--restore", action="store_true", help="任务结束:风扇回自动 + 降温")
170
+ ap.add_argument("--watch", type=int, default=0)
171
+ ap.add_argument("--pl", type=int, default=0)
172
+ ap.add_argument("--idle-temp", type=int, default=55)
173
+ ap.add_argument("--timeout", type=int, default=180)
174
+ ap.add_argument("--json", action="store_true")
175
+ a = ap.parse_args()
176
+
177
+ if a.status:
178
+ return status()
179
+ if a.task:
180
+ return task_mode()
181
+ if a.restore:
182
+ return restore_mode(a.idle_temp)
183
+ if a.fan:
184
+ return set_fan()
185
+ if a.cool:
186
+ return cool(a.idle_temp, a.timeout)
187
+ if a.watch:
188
+ return watch(a.watch)
189
+ if a.pl:
190
+ return set_pl(a.pl)
191
+ return status()
192
+
193
+
194
+ if __name__ == "__main__":
195
+ sys.exit(main())
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ hw-profile.py — 这台机器到底能跑到多大的本地模型?(小白也能看懂的上限推荐)
5
+
6
+ 为什么要有(2026-12-02 主人要求):
7
+ "有的用户拿核显 + 16G 内存跑 7B,理论能跑但也就那样" —— 所以不能只给"能/不能",
8
+ 要给「推荐档位 + 预期速度 + 不建议的原因」,并能一键写进 local-llm-config.json。
9
+
10
+ 用法:
11
+ python scripts/hw-profile.py # 只诊断 + 推荐
12
+ python scripts/hw-profile.py --write # 顺便把推荐写进扩展配置(自动备份)
13
+ python scripts/hw-profile.py --json # 机器可读
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import argparse
18
+ import ctypes
19
+ import json
20
+ import os
21
+ import shutil
22
+ import subprocess
23
+ import sys
24
+ import time
25
+
26
+ ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
27
+ CFG = os.path.join(ROOT, 'dshqqbot', '.qqbot-extensions', 'local-llm-config.json')
28
+
29
+
30
+ def sh(cmd: list[str], timeout=8) -> str:
31
+ try:
32
+ r = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout,
33
+ creationflags=0x08000000)
34
+ return (r.stdout or '').strip()
35
+ except Exception:
36
+ return ''
37
+
38
+
39
+ def gpu_info() -> list[dict]:
40
+ out = []
41
+ txt = sh(['nvidia-smi', '--query-gpu=name,memory.total,memory.used', '--format=csv,noheader,nounits'])
42
+ for line in txt.splitlines():
43
+ parts = [p.strip() for p in line.split(',')]
44
+ if len(parts) >= 2:
45
+ try:
46
+ out.append({'name': parts[0], 'vram_mb': int(float(parts[1])),
47
+ 'used_mb': int(float(parts[2])) if len(parts) > 2 else None})
48
+ except ValueError:
49
+ pass
50
+ if not out:
51
+ # 没有 nvidia-smi:看看是不是 AMD/Intel/核显
52
+ w = sh(['powershell', '-NoProfile', '-Command',
53
+ "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name"])
54
+ out = [{'name': n.strip(), 'vram_mb': 0, 'used_mb': None, 'integrated': True}
55
+ for n in w.splitlines() if n.strip()]
56
+ return out
57
+
58
+
59
+ def ram_gb() -> float:
60
+ class MEMORYSTATUSEX(ctypes.Structure):
61
+ _fields_ = [('dwLength', ctypes.c_ulong), ('dwMemoryLoad', ctypes.c_ulong),
62
+ ('ullTotalPhys', ctypes.c_ulonglong), ('ullAvailPhys', ctypes.c_ulonglong),
63
+ ('ullTotalPageFile', ctypes.c_ulonglong), ('ullAvailPageFile', ctypes.c_ulonglong),
64
+ ('ullTotalVirtual', ctypes.c_ulonglong), ('ullAvailVirtual', ctypes.c_ulonglong),
65
+ ('ullAvailExtendedVirtual', ctypes.c_ulonglong)]
66
+ m = MEMORYSTATUSEX()
67
+ m.dwLength = ctypes.sizeof(MEMORYSTATUSEX)
68
+ ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(m))
69
+ return round(m.ullTotalPhys / 1024 ** 3, 1)
70
+
71
+
72
+ def ollama_models() -> list[str]:
73
+ try:
74
+ import urllib.request
75
+ j = json.loads(urllib.request.urlopen('http://127.0.0.1:11434/api/tags', timeout=3).read())
76
+ return [m['name'] for m in j.get('models', [])]
77
+ except Exception:
78
+ return []
79
+
80
+
81
+ def recommend(vram_gb: float, ram: float, integrated: bool) -> dict:
82
+ """返回推荐档位。经验值,按 Q4_K_M 量化、2048 上下文估。"""
83
+ if integrated or vram_gb <= 0:
84
+ if ram >= 32:
85
+ return dict(tier='CPU/核显·保守', params='3B', quant='Q4_K_M',
86
+ speed='约 4~8 tok/s(纯 CPU)', model_hint='qwen2.5:3b',
87
+ note='核显/无独显:7B 也能"跑起来",但 2~4 tok/s、风扇狂转、聊两句就卡;建议 3B 或直接用云')
88
+ if ram >= 16:
89
+ return dict(tier='CPU/核显·最低', params='1.5B~3B', quant='Q4_K_M',
90
+ speed='约 2~5 tok/s', model_hint='qwen2.5:1.5b',
91
+ note='16G 内存 + 核显:7B 理论可跑但体验很差(每次回复 30s+),只适合极简短句')
92
+ return dict(tier='不建议本地', params='—', quant='—', speed='—', model_hint='',
93
+ note='内存 <16G:本地 7B 会频繁换页,建议直接用云端')
94
+ if vram_gb >= 20:
95
+ return dict(tier='旗舰', params='32B~35B(MoE)', quant='Q4', speed='约 20~40 tok/s',
96
+ model_hint='qwen3.6-35b-a3b', note='可常驻大模型;注意与 TTS/出图抢显存')
97
+ if vram_gb >= 14:
98
+ return dict(tier='高', params='14B', quant='Q4_K_M', speed='约 15~25 tok/s',
99
+ model_hint='qwen2.5:14b', note='14B 性价比最高的一档,性格/常识都不错')
100
+ if vram_gb >= 10:
101
+ return dict(tier='中高', params='8B~9B', quant='Q5_K_M', speed='约 25~40 tok/s',
102
+ model_hint='qwen3:8b', note='8B Q5 比 Q4 更稳,显存刚好够')
103
+ if vram_gb >= 7:
104
+ return dict(tier='中', params='7B~8B', quant='Q4_K_M', speed='约 25~45 tok/s',
105
+ model_hint='qwen3:8b', note='7/8B Q4 是甜点档,聊天足够')
106
+ if vram_gb >= 5:
107
+ return dict(tier='入门', params='3B~4B', quant='Q4_K_M', speed='约 30~50 tok/s',
108
+ model_hint='qwen2.5:3b', note='显存 5~7G:4B 刚好,7B 会溢出到内存变慢')
109
+ return dict(tier='入门', params='1.5B~3B', quant='Q4_K_M', speed='约 40~60 tok/s',
110
+ model_hint='qwen2.5:1.5b', note='显存 <5G:只建议 3B 以下')
111
+
112
+
113
+ def main():
114
+ ap = argparse.ArgumentParser()
115
+ ap.add_argument('--json', action='store_true')
116
+ ap.add_argument('--write', action='store_true')
117
+ a = ap.parse_args()
118
+
119
+ gpus = gpu_info()
120
+ ram = ram_gb()
121
+ best = max(gpus, key=lambda g: g.get('vram_mb') or 0) if gpus else {'name': '未知', 'vram_mb': 0}
122
+ vram = round((best.get('vram_mb') or 0) / 1024, 1)
123
+ rec = recommend(vram, ram, bool(best.get('integrated')) or vram <= 0)
124
+ models = ollama_models()
125
+ rep = {
126
+ 'at': time.strftime('%Y-%m-%d %H:%M:%S'),
127
+ 'cpu_cores': os.cpu_count(),
128
+ 'ram_gb': ram,
129
+ 'gpus': gpus,
130
+ 'vram_gb': vram,
131
+ 'recommend': rec,
132
+ 'ollama_models': models,
133
+ 'fits': [m for m in models if rec.get('model_hint') and rec['model_hint'].split(':')[0] in m],
134
+ }
135
+ if a.json:
136
+ print(json.dumps(rep, ensure_ascii=False, indent=2))
137
+ else:
138
+ print('=' * 56)
139
+ print('本机硬件画像 ' + rep['at'])
140
+ print('=' * 56)
141
+ print(f"CPU 核心 {rep['cpu_cores']} | 内存 {ram} GB")
142
+ for g in gpus:
143
+ print(f"显卡 {g.get('name')} " + (f"{round((g.get('vram_mb') or 0)/1024,1)} GB 显存" if g.get('vram_mb') else '(共享/核显)'))
144
+ r = rec
145
+ print('\n推荐档位:' + r['tier'] + f" → {r['params']} {r['quant']}")
146
+ print('预期速度:' + r['speed'])
147
+ print('参考模型:' + (r['model_hint'] or '—'))
148
+ print('说明:' + r['note'])
149
+ if models:
150
+ print('\n本机 ollama 已有:' + ', '.join(models[:10]))
151
+ if a.write:
152
+ try:
153
+ cfg = json.load(open(CFG, encoding='utf-8'))
154
+ except Exception:
155
+ cfg = {}
156
+ bak = CFG + '.bak-' + time.strftime('%Y%m%d-%H%M%S')
157
+ try:
158
+ shutil.copy2(CFG, bak)
159
+ except Exception:
160
+ pass
161
+ cfg['_hw_recommend'] = rec
162
+ cfg['_hw_checked_at'] = rep['at']
163
+ if models and rec.get('model_hint'):
164
+ hit = [m for m in models if rec['model_hint'].split(':')[0] in m]
165
+ if hit:
166
+ cfg['provider'] = 'ollama'
167
+ cfg['baseUrl'] = 'http://127.0.0.1:11434'
168
+ cfg['model'] = hit[0]
169
+ json.dump(cfg, open(CFG, 'w', encoding='utf-8'), ensure_ascii=False, indent=2)
170
+ print('\n已写入配置(备份 ' + os.path.basename(bak) + '):model=' + str(cfg.get('model')))
171
+ return 0
172
+
173
+
174
+ if __name__ == '__main__':
175
+ sys.exit(main())
@@ -0,0 +1,37 @@
1
+ @echo off
2
+ setlocal EnableExtensions
3
+ chcp 936 >nul
4
+
5
+ REM ############################################################################
6
+ REM # install-schedule.cmd ���� һ�� UAC װ�����ж�ʱ����
7
+ REM #
8
+ REM # ˫�� / �������������Ȼ���ڵ����ϵ㡸�ǣ�����������
9
+ REM # ��Ȩ���� install-schedule-tasks.ps1 ����
10
+ REM # 1) powercfg /hibernate on �����ߣ�S4����û���� shutdown /h ��ʧ��
11
+ REM # 2) �������Ѷ�ʱ�� RTCWAKE(AC/DC)=1 ���� 07:30 �� WakeToRun �����滽��
12
+ REM # 3) �� QQBootWake ÿ�� 07:30 + ��¼ʱ��WakeToRun=true -> boot-tasks.cmd
13
+ REM # 4) �� QQSleepReminder ÿ�� 23:20 -> sleep-reminder.ps1
14
+ REM # 5) �� QQSleep2325 ÿ�� 23:25 -> sleep-2325.cmd��shutdown /h /f��
15
+ REM # 6) ͣ�þ����� DSH_Shutdown_2325 / DSH_Remind_2320��ֻ Disable��ûɾ��
16
+ REM # 7) ���� powercfg /a �� /waketimers �� F:\qqbot\logs\
17
+ REM #
18
+ REM # ��־��F:\qqbot\logs\install-schedule.log��UTF-8������Լ 30~90 �룬
19
+ REM # hiberfil.sys Ҫ���ڴ����ռ�̣���һ�λ�����
20
+ REM ############################################################################
21
+
22
+ echo.
23
+ echo �������� UAC ��Ȩ���� ���� ��㡸�ǡ�����������
24
+ echo.
25
+ echo ��Ȩ�ű��᣺������(S4) + �������Ѷ�ʱ�� + �� 3 ���ƻ����� + ͣ�� 2 ��������
26
+ echo ��־��F:\qqbot\logs\install-schedule.log
27
+ echo.
28
+
29
+ powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -Verb RunAs -FilePath powershell -ArgumentList '-NoProfile','-ExecutionPolicy','Bypass','-File','F:\qqbot\scripts\install-schedule-tasks.ps1' -WindowStyle Hidden"
30
+
31
+ echo [�ѷ���] ��Ȩ�������������еģ������Լ�ð������
32
+ echo û���� UAC ����������������Ķ���ͼ�꣨���ܱ���Ĵ��ڵ�ס����
33
+ echo ���꿴 F:\qqbot\logs\install-schedule.log ���һ���Dz��� INSTALL_DONE��
34
+ echo.
35
+
36
+ endlocal
37
+ exit /b 0
@@ -0,0 +1,29 @@
1
+ @echo off
2
+ REM Register/unregister the network watcher (HKCU Run, current user, NO admin).
3
+ REM Usage: install-watch.cmd -> register + start hidden watcher
4
+ REM install-watch.cmd remove -> remove autostart
5
+ chcp 65001 >nul
6
+ setlocal
7
+ set "RUNKEY=HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
8
+ set "VAL=QQWhitelistWatch"
9
+ set "CMD=wscript.exe \"F:\qqbot\scripts\start-watch-hidden.vbs\""
10
+
11
+ if /I "%~1"=="remove" goto remove
12
+ if /I "%~1"=="uninstall" goto remove
13
+
14
+ reg add "%RUNKEY%" /v %VAL% /t REG_SZ /d "%CMD%" /f
15
+ if errorlevel 1 (
16
+ echo [FAILED] reg add failed
17
+ exit /b 1
18
+ )
19
+ echo [OK] autostart registered: %VAL%
20
+ echo value: %CMD%
21
+ echo starting watcher now (hidden window) ...
22
+ start "" wscript.exe "F:\qqbot\scripts\start-watch-hidden.vbs"
23
+ echo [OK] watcher start attempted, log: F:\qqbot\logs\watch-network.log
24
+ exit /b 0
25
+
26
+ :remove
27
+ reg delete "%RUNKEY%" /v %VAL% /f >nul 2>&1
28
+ echo [OK] autostart removed: %VAL%
29
+ exit /b 0
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env python3
2
+ """matte-cutout.py — 把「纯色背景生成图」抠成透明 PNG(桌宠皮肤用)。
3
+
4
+ 为什么要它:本地生图(krea/qwen)出来的人物图背景是纯色(黑或白),
5
+ 桌宠是浮在桌面上的,带一块底色会非常丑;而 build-pet-outfits.py 那套派生流程
6
+ 要求输入本身带 alpha。所以生图之后统一走一遍这里:从四边泛洪,容差内判为背景。
7
+
8
+ 用法:
9
+ python scripts/matte-cutout.py in.png out.png [--tol 26] [--feather 1]
10
+ python scripts/matte-cutout.py in.png out.png --bg #ffffff
11
+
12
+ 只从**边缘**开始泛洪,角色内部的深色(深蓝头发、深色裙子)不会被误删。
13
+ """
14
+ import argparse
15
+ import sys
16
+ from collections import deque
17
+
18
+ try:
19
+ from PIL import Image
20
+ except Exception as e: # pragma: no cover
21
+ print("[matte] 需要 Pillow: %s" % e)
22
+ sys.exit(3)
23
+
24
+
25
+ def hex_rgb(s):
26
+ s = (s or "").strip().lstrip("#")
27
+ if len(s) == 3:
28
+ s = "".join(c * 2 for c in s)
29
+ return (int(s[0:2], 16), int(s[2:4], 16), int(s[4:6], 16))
30
+
31
+
32
+ def matte(src, dst, tol=26, feather=1, bg=None):
33
+ im = Image.open(src).convert("RGBA")
34
+ w, h = im.size
35
+ px = im.load()
36
+ bgc = bg if bg else px[0, 0]
37
+ # 四边颜色不一致(渐变背景)时,用每条边的中点各自取样,取"最接近纯色"的那个
38
+ samples = [px[0, 0], px[w - 1, 0], px[0, h - 1], px[w - 1, h - 1]]
39
+ # 以角落为准(生成图基本都是纯色);如果角落差异大,退化为逐像素判断
40
+ uniform = all(sum(abs(a[i] - bgc[i]) for i in range(3)) <= tol * 2 for a in samples)
41
+ if uniform:
42
+ bgc = samples[0]
43
+
44
+ def is_bg(c):
45
+ return sum(abs(c[i] - bgc[i]) for i in range(3)) <= tol * 3
46
+
47
+ seen = bytearray(w * h)
48
+ q = deque()
49
+ for x in range(w):
50
+ for y in (0, h - 1):
51
+ if not seen[y * w + x] and is_bg(px[x, y]):
52
+ seen[y * w + x] = 1
53
+ q.append((x, y))
54
+ for y in range(h):
55
+ for x in (0, w - 1):
56
+ if not seen[y * w + x] and is_bg(px[x, y]):
57
+ seen[y * w + x] = 1
58
+ q.append((x, y))
59
+ while q:
60
+ x, y = q.popleft()
61
+ px[x, y] = (px[x, y][0], px[x, y][1], px[x, y][2], 0)
62
+ for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
63
+ nx, ny = x + dx, y + dy
64
+ if 0 <= nx < w and 0 <= ny < h and not seen[ny * w + nx] and is_bg(px[nx, ny]):
65
+ seen[ny * w + nx] = 1
66
+ q.append((nx, ny))
67
+
68
+ if feather:
69
+ # 边缘羽化:只把"紧贴透明区"的半亮像素做一次 50% 透明,消锯齿硬边
70
+ for _ in range(feather):
71
+ edge = []
72
+ for y in range(h):
73
+ for x in range(w):
74
+ if px[x, y][3] != 0:
75
+ continue
76
+ for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
77
+ nx, ny = x + dx, y + dy
78
+ if 0 <= nx < w and 0 <= ny < h and px[nx, ny][3] == 255:
79
+ edge.append((nx, ny))
80
+ break
81
+ for (x, y) in edge:
82
+ r, g, b, a = px[x, y]
83
+ px[x, y] = (r, g, b, 150)
84
+
85
+ bbox = im.getbbox()
86
+ im.save(dst)
87
+ cleared = sum(1 for i in range(0, w * h) if seen[i])
88
+ return {"ok": True, "out": dst, "size": [w, h], "cleared_px": cleared,
89
+ "cleared_pct": round(cleared * 100.0 / (w * h), 1), "bg": list(bgc[:3]), "bbox": list(bbox) if bbox else None}
90
+
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("src")
95
+ ap.add_argument("dst")
96
+ ap.add_argument("--tol", type=int, default=26)
97
+ ap.add_argument("--feather", type=int, default=1)
98
+ ap.add_argument("--bg", default="")
99
+ a = ap.parse_args()
100
+ r = matte(a.src, a.dst, a.tol, a.feather, hex_rgb(a.bg) if a.bg else None)
101
+ print("[matte] %(out)s %(size)s 背景%(bg)s 去掉%(cleared_pct)s%%" % r)
102
+ return 0
103
+
104
+
105
+ if __name__ == "__main__":
106
+ sys.exit(main())