dsh-qqbot-muu 0.1.20 → 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 (92) hide show
  1. package/CHANGELOG.md +168 -154
  2. package/client/qqbot-settings.js +13401 -13380
  3. package/dist/config.js +573 -581
  4. package/dist/features/contextless-store.js +247 -247
  5. package/dist/features/four-source.js +338 -336
  6. package/dist/features/group-join-request.js +289 -287
  7. package/dist/features/local-models.js +1494 -1467
  8. package/dist/features/style-layer.js +501 -498
  9. package/dist/features/thinking-log.js +71 -69
  10. package/dist/gateway/bootstrap.js +1704 -1652
  11. package/dist/model/settings-reader.js +193 -102
  12. package/dist/shared/paths.js +128 -0
  13. package/dist/shared/settings-io.js +79 -83
  14. package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
  15. package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -794
  16. package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
  17. package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
  18. package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -444
  19. package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
  20. package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
  21. package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
  22. package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
  23. package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
  24. package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
  25. package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
  26. package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
  27. package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
  28. package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
  29. package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
  30. package/package.json +119 -118
  31. package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
  32. package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
  33. package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
  34. package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
  35. package/scripts/ai-toolkit.py +607 -478
  36. package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
  37. package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
  38. package/scripts/chat-archive/build-sft-v4.py +566 -0
  39. package/scripts/chat-archive/build-sft.py +390 -0
  40. package/scripts/chat-archive/eval-sft.py +155 -0
  41. package/scripts/chat-archive/extract-memory.py +143 -0
  42. package/scripts/chat-archive/inventory.py +182 -0
  43. package/scripts/chat-archive/merge-sft.py +114 -0
  44. package/scripts/chat-archive/qce-pull.py +217 -0
  45. package/scripts/chat-archive/qqheader.py +110 -0
  46. package/scripts/chat-archive/qqkey2.py +113 -0
  47. package/scripts/chat-archive/qqprobe.py +153 -0
  48. package/scripts/chat-archive/screen-collect.py +163 -0
  49. package/scripts/chat-archive/sqlcipher_probe.py +444 -0
  50. package/scripts/episode.py +529 -0
  51. package/scripts/fan-curve.py +218 -0
  52. package/scripts/fan-guard.cmd +8 -0
  53. package/scripts/fan-mode.py +380 -263
  54. package/scripts/gen-image.py +420 -413
  55. package/scripts/gen-video.py +186 -178
  56. package/scripts/hw-profile.py +175 -0
  57. package/scripts/media-enhance.py +402 -0
  58. package/scripts/memory-audit.py +581 -0
  59. package/scripts/migrate-scope.mjs +140 -139
  60. package/scripts/qq-connect-login.py +133 -0
  61. package/scripts/qq-ip-sync-hidden.vbs +5 -0
  62. package/scripts/qq-ip-sync.py +300 -0
  63. package/scripts/qq-whitelist.py +71 -0
  64. package/scripts/release-all.mjs +636 -509
  65. package/scripts/release-check.mjs +244 -226
  66. package/scripts/secure-room/index.html +334 -0
  67. package/scripts/secure-room/server.py +582 -0
  68. package/scripts/stickers/auto-tag.mjs +161 -0
  69. package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
  70. package/scripts/train/gguf-quantize.py +92 -0
  71. package/scripts/train/gguf-to-hf.py +112 -0
  72. package/scripts/train/merge-lora.py +51 -0
  73. package/scripts/train/probe-mirrors.sh +12 -0
  74. package/scripts/train/probe-mirrors2.sh +20 -0
  75. package/scripts/train/setup-wsl.sh +23 -0
  76. package/scripts/train/setup-wsl2.sh +25 -0
  77. package/scripts/train/setup-wsl3.sh +22 -0
  78. package/scripts/train/setup-wsl4.sh +22 -0
  79. package/scripts/train/train-lora.py +319 -0
  80. package/dist/_backup_ctx_20261125_183653/dist/config.d.ts +0 -473
  81. package/dist/_backup_ctx_20261125_183653/dist/config.js +0 -450
  82. package/dist/_backup_ctx_20261125_183653/dist/features/contextless-trim.js +0 -304
  83. package/dist/_backup_ctx_20261125_183653/dist/session/session-manager.js +0 -1588
  84. package/dist/_backup_ctx_20261125_183653/dist/transport/inbound.js +0 -1567
  85. package/dist/_backup_ctx_20261125_183653/dist/transport/outbound.js +0 -647
  86. package/scripts/__pycache__/ai-mode.cpython-311.pyc +0 -0
  87. package/scripts/__pycache__/ai-toolkit.cpython-311.pyc +0 -0
  88. package/scripts/__pycache__/comfy_gen.cpython-311.pyc +0 -0
  89. package/scripts/__pycache__/gen-image.cpython-311.pyc +0 -0
  90. package/scripts/__pycache__/gen-video.cpython-311.pyc +0 -0
  91. package/scripts/__pycache__/model-registry.cpython-311.pyc +0 -0
  92. package/scripts/__pycache__/purge-standby.cpython-311.pyc +0 -0
@@ -1,103 +1,194 @@
1
- /**
2
- * SettingsReader — settings.yaml 只读解析
3
- *
4
- * 从 ~/.dsh/settings.yaml 中读取模型配置信息。
5
- * 只读,不修改 settings.yaml。
6
- */
7
- import { readFileSync, existsSync } from 'node:fs';
8
- import { resolve } from 'node:path';
9
- import { homedir } from 'node:os';
10
- import yaml from 'js-yaml';
11
- export class SettingsReader {
12
- /** settings.yaml 缓存 */
13
- settingsCache;
14
- /**
15
- * 从 settings.yaml 的 agent-default-model 字段读取默认模型路由
16
- */
17
- readDefaultRoute() {
18
- const settings = this.loadSettings();
19
- if (!settings)
20
- return undefined;
21
- const defaultModel = settings['agent-default-model'];
22
- if (defaultModel?.provider && defaultModel?.model) {
23
- return { provider: defaultModel.provider, model: defaultModel.model };
24
- }
25
- return undefined;
26
- }
27
- /**
28
- * 列出 settings.yaml 中配置的所有模型
29
- */
30
- readModels() {
31
- const settings = this.loadSettings();
32
- if (!settings)
33
- return [];
34
- const models = [];
35
- const llmPiAi = settings['llm-pi-ai'];
36
- if (llmPiAi?.providers) {
37
- for (const [providerName, providerConfig] of Object.entries(llmPiAi.providers)) {
38
- if (Array.isArray(providerConfig?.models)) {
39
- for (const m of providerConfig.models) {
40
- if (m.id) {
41
- models.push({ provider: providerName, id: m.id, name: m.name || undefined });
42
- }
43
- }
44
- }
45
- }
46
- }
47
- return models;
48
- }
49
- /**
50
- * 列出 settings.yaml 中配置的 provider 名称
51
- */
52
- readProviders() {
53
- const settings = this.loadSettings();
54
- const llmPiAi = settings?.['llm-pi-ai'];
55
- return llmPiAi?.providers ? Object.keys(llmPiAi.providers) : [];
56
- }
57
- /**
58
- * 从 settings.yaml 的 <ns> 段读取 groupAdmin 配置。
59
- * 解决"QQBot 构造时 intents 一次性读取"的时序坑: settings 服务的 Web 可视化配置
60
- * (写 settings.yaml)是异步注入, 晚于 gateway 构造 → 启动期读文件才能在构造前拿到值。
61
- * 返回 undefined = settings.yaml 无该 ns 或 ns 无 groupAdmin。
62
- */
63
- readGroupAdmin(ns) {
64
- const settings = this.loadSettings();
65
- if (!settings)
66
- return undefined;
67
- const nsBlock = settings[ns];
68
- const ga = nsBlock?.groupAdmin;
69
- return ga && typeof ga === 'object' ? ga : undefined;
70
- }
71
- /**
72
- * 从 settings.yaml 的 <ns> 段读取群守则 groupPrompt(热更新用)。
73
- * fresh=true 时绕过缓存现读磁盘(每次 system prompt 渲染调用, 使 Web 改完即时生效);
74
- * 返回 undefined = 无该 ns / 无 groupPrompt / 空串。
75
- */
76
- readGroupPrompt(ns, fresh = false) {
77
- const settings = this.loadSettings(fresh);
78
- if (!settings)
79
- return undefined;
80
- const nsBlock = settings[ns];
81
- const gp = nsBlock?.groupPrompt;
82
- return typeof gp === 'string' && gp.trim() ? gp.trim() : undefined;
83
- }
84
- loadSettings(fresh = false) {
85
- if (!fresh && this.settingsCache !== undefined)
86
- return this.settingsCache;
87
- try {
88
- const settingsPath = resolve(homedir(), '.dsh', 'settings.yaml');
89
- if (!existsSync(settingsPath)) {
90
- this.settingsCache = null;
91
- return null;
92
- }
93
- const content = readFileSync(settingsPath, 'utf8');
94
- this.settingsCache = yaml.load(content);
95
- return this.settingsCache;
96
- }
97
- catch {
98
- this.settingsCache = null;
99
- return null;
100
- }
101
- }
102
- }
1
+ /**
2
+ * SettingsReader — settings.yaml 只读解析
3
+ *
4
+ * 从 ~/.dsh/settings.yaml 中读取模型配置信息。
5
+ * 只读,不修改 settings.yaml。
6
+ */
7
+ import { readFileSync, existsSync, statSync } from 'node:fs';
8
+ import { resolve } from 'node:path';
9
+ import yaml from 'js-yaml';
10
+ import { dshHomeCandidates } from '../shared/paths.js';
11
+
12
+ /**
13
+ * 读 settings.yaml,并兼容 DSH 内核的「改名 + 搬家」行为。
14
+ *
15
+ * 2026-12-04(别的用户反馈的 bug):DSH 内核每次启动会把 settings.yaml 改名成
16
+ * settings.yaml.imported 再写一份新的;只认 settings.yaml 的插件就读不到
17
+ * im-qqbot.groupAdmin,owner/群管权限整体失效。
18
+ * 另一处变化:DSH 0.14 起设置根从 ~/.dsh 搬到 %APPDATA%/dsh-desktop/harness,
19
+ * 只认 ~/.dsh 的读法在新版上同样读不到。
20
+ *
21
+ * 现在的做法:把所有候选目录(paths.js dshHomeCandidates + DSH_CONFIG_DIR)里的
22
+ * settings.yaml / settings.yaml.imported / settings.imported / settings.yml 全收进来,
23
+ * 按文件修改时间从新到旧合并(新的优先,旧的只补缺的键)。
24
+ * 改名不改 mtime,所以「刚写的新 settings.yaml」自然排在「被改名的旧 .imported」前面。
25
+ */
26
+ export function settingsDir() {
27
+ // 目录本身也可能被宿主改:DSH_HOME / DSH_CONFIG_DIR 优先,其次 ~/.dsh。
28
+ const env = process.env;
29
+ const dir = String(env.DSH_HOME || env.DSH_CONFIG_DIR || '').trim();
30
+ if (dir)
31
+ return dir;
32
+ const cands = dshHomeCandidates();
33
+ for (const c of cands) {
34
+ try {
35
+ if (existsSync(c))
36
+ return c;
37
+ }
38
+ catch { /* ignore */ }
39
+ }
40
+ return cands[0] || resolve('.');
41
+ }
42
+ /** 所有候选目录(按新→旧),显式指定的环境变量排最前 */
43
+ function settingsDirs() {
44
+ const out = [];
45
+ const push = (p) => {
46
+ const v = String(p || '').trim();
47
+ if (v && !out.includes(v))
48
+ out.push(v);
49
+ };
50
+ push(process.env.DSH_CONFIG_DIR);
51
+ push(process.env.DSH_HOME);
52
+ for (const c of dshHomeCandidates())
53
+ push(c);
54
+ push(settingsDir());
55
+ return out;
56
+ }
57
+ const SETTINGS_NAMES = ['settings.yaml', 'settings.yaml.imported', 'settings.imported', 'settings.yml'];
58
+ /** 收集现存候选文件,按 mtime 新→旧 */
59
+ function settingsFiles() {
60
+ const list = [];
61
+ const seen = new Set();
62
+ for (const dir of settingsDirs()) {
63
+ for (const name of SETTINGS_NAMES) {
64
+ const f = resolve(dir, name);
65
+ if (seen.has(f))
66
+ continue;
67
+ seen.add(f);
68
+ try {
69
+ if (!existsSync(f))
70
+ continue;
71
+ list.push({ f, mtime: statSync(f).mtimeMs || 0 });
72
+ }
73
+ catch { /* 没权限 → 跳过 */ }
74
+ }
75
+ }
76
+ list.sort((a, b) => b.mtime - a.mtime);
77
+ return list.map((x) => x.f);
78
+ }
79
+ function readSettingsMerged() {
80
+ const files = settingsFiles();
81
+ let merged = null;
82
+ let found = false;
83
+ for (const f of files) {
84
+ try {
85
+ const j = yaml.load(readFileSync(f, 'utf8'));
86
+ if (!j || typeof j !== 'object')
87
+ continue;
88
+ found = true;
89
+ merged = merged ? mergeFill(merged, j) : j;
90
+ }
91
+ catch { /* 单个文件坏了不影响其它候选 */ }
92
+ }
93
+ return found ? merged : null;
94
+ }
95
+
96
+ /** 深合并:a 已有的键优先,b 只补 a 缺的(所以 settings.yaml 优先于 .imported) */
97
+ function mergeFill(a, b) {
98
+ if (!a || typeof a !== 'object' || !b || typeof b !== 'object' || Array.isArray(a) || Array.isArray(b))
99
+ return a;
100
+ for (const [k, v] of Object.entries(b)) {
101
+ if (a[k] === undefined)
102
+ a[k] = v;
103
+ else if (a[k] && typeof a[k] === 'object' && v && typeof v === 'object')
104
+ mergeFill(a[k], v);
105
+ }
106
+ return a;
107
+ }
108
+ export class SettingsReader {
109
+ /** settings.yaml 缓存 */
110
+ settingsCache;
111
+ /**
112
+ * 从 settings.yaml 的 agent-default-model 字段读取默认模型路由
113
+ */
114
+ readDefaultRoute() {
115
+ const settings = this.loadSettings();
116
+ if (!settings)
117
+ return undefined;
118
+ const defaultModel = settings['agent-default-model'];
119
+ if (defaultModel?.provider && defaultModel?.model) {
120
+ return { provider: defaultModel.provider, model: defaultModel.model };
121
+ }
122
+ return undefined;
123
+ }
124
+ /**
125
+ * 列出 settings.yaml 中配置的所有模型
126
+ */
127
+ readModels() {
128
+ const settings = this.loadSettings();
129
+ if (!settings)
130
+ return [];
131
+ const models = [];
132
+ const llmPiAi = settings['llm-pi-ai'];
133
+ if (llmPiAi?.providers) {
134
+ for (const [providerName, providerConfig] of Object.entries(llmPiAi.providers)) {
135
+ if (Array.isArray(providerConfig?.models)) {
136
+ for (const m of providerConfig.models) {
137
+ if (m.id) {
138
+ models.push({ provider: providerName, id: m.id, name: m.name || undefined });
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ return models;
145
+ }
146
+ /**
147
+ * 列出 settings.yaml 中配置的 provider 名称
148
+ */
149
+ readProviders() {
150
+ const settings = this.loadSettings();
151
+ const llmPiAi = settings?.['llm-pi-ai'];
152
+ return llmPiAi?.providers ? Object.keys(llmPiAi.providers) : [];
153
+ }
154
+ /**
155
+ * 从 settings.yaml 的 <ns> 段读取 groupAdmin 配置。
156
+ * 解决"QQBot 构造时 intents 一次性读取"的时序坑: settings 服务的 Web 可视化配置
157
+ * (写 settings.yaml)是异步注入, 晚于 gateway 构造 → 启动期读文件才能在构造前拿到值。
158
+ * 返回 undefined = settings.yaml 无该 ns 或 ns 无 groupAdmin。
159
+ */
160
+ readGroupAdmin(ns) {
161
+ const settings = this.loadSettings();
162
+ if (!settings)
163
+ return undefined;
164
+ const nsBlock = settings[ns];
165
+ const ga = nsBlock?.groupAdmin;
166
+ return ga && typeof ga === 'object' ? ga : undefined;
167
+ }
168
+ /**
169
+ * 从 settings.yaml 的 <ns> 段读取群守则 groupPrompt(热更新用)。
170
+ * fresh=true 时绕过缓存现读磁盘(每次 system prompt 渲染调用, 使 Web 改完即时生效);
171
+ * 返回 undefined = 无该 ns / 无 groupPrompt / 空串。
172
+ */
173
+ readGroupPrompt(ns, fresh = false) {
174
+ const settings = this.loadSettings(fresh);
175
+ if (!settings)
176
+ return undefined;
177
+ const nsBlock = settings[ns];
178
+ const gp = nsBlock?.groupPrompt;
179
+ return typeof gp === 'string' && gp.trim() ? gp.trim() : undefined;
180
+ }
181
+ loadSettings(fresh = false) {
182
+ if (!fresh && this.settingsCache !== undefined)
183
+ return this.settingsCache;
184
+ try {
185
+ this.settingsCache = readSettingsMerged();
186
+ return this.settingsCache;
187
+ }
188
+ catch {
189
+ this.settingsCache = null;
190
+ return null;
191
+ }
192
+ }
193
+ }
103
194
  //# sourceMappingURL=settings-reader.js.map
@@ -0,0 +1,128 @@
1
+ /**
2
+ * paths.js — 全项目「根目录 / 外部依赖位置」的唯一来源(路径中心化)
3
+ *
4
+ * 为什么要有这个文件(2026-12-04):
5
+ * 在这之前,"包根"和"真仓库根"至少被推导了三遍 ——
6
+ * dist/config.js、dist/features/local-models.js、dist/gateway/bootstrap.js
7
+ * 各写一套,改一处漏两处;出图脚本、模型目录、产物目录就分别指着不同的根。
8
+ * 这里把它们收成一个叶子模块(只依赖 node 内置),谁需要就 import,别再自己算。
9
+ *
10
+ * 语义(三种安装形态都要成立):
11
+ * ① 源码直跑:PKG_ROOT = REPO_ROOT = 仓库根
12
+ * ② pnpm 装进 DSH profile:PKG_ROOT = node_modules/<pkg>,REPO_ROOT 由 config/repo-root.json 指回真仓库
13
+ * ③ 纯 npm 发布包:没有真仓库,REPO_ROOT 回落到 PKG_ROOT(包内自带 scripts/**)
14
+ */
15
+ import { existsSync, readFileSync } from 'node:fs';
16
+ import { dirname, join, resolve } from 'node:path';
17
+ import { fileURLToPath } from 'node:url';
18
+ import { homedir } from 'node:os';
19
+
20
+ /** 包根。dist/shared → 上两级。 */
21
+ export const PKG_ROOT = (() => {
22
+ try {
23
+ return resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');
24
+ }
25
+ catch {
26
+ return process.cwd();
27
+ }
28
+ })();
29
+
30
+ /** 真仓库根:安装副本里 scripts/、.models/、.venv-draw/ 只在真仓库。 */
31
+ export const REPO_ROOT = (() => {
32
+ try {
33
+ const j = JSON.parse(readFileSync(join(PKG_ROOT, 'config', 'repo-root.json'), 'utf8'));
34
+ if (j && j.root && existsSync(String(j.root)))
35
+ return String(j.root);
36
+ }
37
+ catch { /* 没有指针就是源码直跑 / 纯发布包 */ }
38
+ // 环境变量兜底:容器/CI 里可以用 QQBOT_REPO_ROOT 指到挂载目录
39
+ const env = String(process.env.QQBOT_REPO_ROOT || '').trim();
40
+ if (env) {
41
+ try {
42
+ if (existsSync(env))
43
+ return env;
44
+ }
45
+ catch { /* ignore */ }
46
+ }
47
+ return PKG_ROOT;
48
+ })();
49
+
50
+ /** scripts/ 所在根:真仓库优先,其次包内(files 已包含 scripts/**)。 */
51
+ export const SCRIPTS_ROOT = (() => {
52
+ const cands = [String(process.env.QQBOT_REPO_ROOT || '').trim(), String(process.env.QQBOT_ROOT || '').trim(), REPO_ROOT, PKG_ROOT].filter(Boolean);
53
+ for (const c of cands) {
54
+ try {
55
+ if (existsSync(join(c, 'scripts')))
56
+ return c;
57
+ }
58
+ catch { /* ignore */ }
59
+ }
60
+ return REPO_ROOT;
61
+ })();
62
+
63
+ /**
64
+ * DSH 宿主的候选家目录(按新→旧)。
65
+ * 2026-12-04:DSH 0.14 把设置从 ~/.dsh 搬到 %APPDATA%/dsh-desktop/harness;
66
+ * 非 Windows 没有 %APPDATA%,之前会直接掉回 ~/.dsh 导致读不到设置。
67
+ * Go 版/自定义 harness 只要设 QQBOT_DSH_HOME 或 DSH_HOME 即可,不用改代码。
68
+ */
69
+ export function dshHomeCandidates() {
70
+ const out = [];
71
+ const push = (p) => {
72
+ const v = String(p || '').trim();
73
+ if (v && !out.includes(v))
74
+ out.push(v);
75
+ };
76
+ push(process.env.QQBOT_DSH_HOME);
77
+ const appData = String(process.env.APPDATA || '').trim();
78
+ if (appData)
79
+ push(join(appData, 'dsh-desktop', 'harness'));
80
+ push(process.env.DSH_HOME);
81
+ const xdg = String(process.env.XDG_CONFIG_HOME || '').trim();
82
+ if (xdg)
83
+ push(join(xdg, 'dsh-desktop', 'harness'));
84
+ try { push(join(homedir(), '.config', 'dsh-desktop', 'harness')); } catch { /* ignore */ }
85
+ try { push(join(homedir(), '.dsh')); } catch { /* ignore */ }
86
+ return out;
87
+ }
88
+
89
+ /** 第一个真实存在的 DSH 家目录(都不存在就交回仓库根,至少路径可拼) */
90
+ export function dshHome() {
91
+ for (const c of dshHomeCandidates()) {
92
+ try {
93
+ if (existsSync(c))
94
+ return c;
95
+ }
96
+ catch { /* ignore */ }
97
+ }
98
+ return PKG_ROOT;
99
+ }
100
+
101
+ /** 统一产出根:任何形式产出的图/视频/音频/文本只落这里,不再各占一块。 */
102
+ export const OUT_ROOT = join(PKG_ROOT, 'out');
103
+
104
+ /**
105
+ * Python 解释器候选(按顺序试,第一个存在的胜出)。
106
+ * 表里保留作者机器的 conda 路径只是"存在才用",别的用户机器上自动落到 python3 / python。
107
+ * 想指定自己的解释器:设环境变量 QQBOT_PYTHON。
108
+ */
109
+ export function pythonCandidates(extra = []) {
110
+ const env = String(process.env.QQBOT_PYTHON || '').trim();
111
+ const list = [env, ...extra, 'E:/Anaconda/envs/ai25/python.exe', 'python3', 'python'].filter(Boolean);
112
+ return [...new Set(list)];
113
+ }
114
+
115
+ /** 挑第一个存在的解释器(找不到就交回 python,让 spawn 报 ENOENT 而不是静默走错) */
116
+ export function pickPython(extra = []) {
117
+ for (const p of pythonCandidates(extra)) {
118
+ if (p === 'python' || p === 'python3')
119
+ continue;
120
+ try {
121
+ if (existsSync(p))
122
+ return p;
123
+ }
124
+ catch { /* ignore */ }
125
+ }
126
+ // Windows 上通常只有 python,Unix 上通常只有 python3
127
+ return process.platform === 'win32' ? 'python' : 'python3';
128
+ }
@@ -1,83 +1,79 @@
1
- /**
2
- * settings-io.js — 找到 dsh 的 qqbot 设置文件(2026-12-01)
3
- *
4
- * 背景:DSH Desktop 0.14 把 profile 从 `web` 换成 `desktop`,设置数据也从
5
- * `~/.dsh/qqbot-settings/<profile>/<ns>.json`
6
- * 搬到了
7
- * `%APPDATA%/dsh-desktop/harness/qqbot-settings/<profile>/<ns>.json`
8
- *
9
- * 插件里还有几处写死 `~/.dsh/.../web` 的读法(autoRecall 热读、autoRecall 工具),
10
- * 升级后全部读到"文件不存在"。这里统一解析:环境变量 > AppData harness > ~/.dsh。
11
- */
12
- import { existsSync, readdirSync, statSync } from 'node:fs';
13
- import { homedir } from 'node:os';
14
- import { join } from 'node:path';
15
-
16
- /**
17
- * dsh home(能直接拼 `qqbot-settings/…` 的那一层)。
18
- * DSH Desktop 0.14 的真实位置是 `%APPDATA%/dsh-desktop/harness`,而环境变量 DSH_HOME
19
- * 只在 shell/工具调用时临时注入,插件进程里通常是空 —— 以前这里回落 ~/.dsh 就永远读不到设置。
20
- */
21
- export function settingsHome() {
22
- const appData = String(process.env.APPDATA || '').trim();
23
- if (appData) {
24
- const h = join(appData, 'dsh-desktop', 'harness');
25
- try { if (existsSync(join(h, 'qqbot-settings'))) return h; } catch { /* ignore */ }
26
- }
27
- const dshHome = String(process.env.DSH_HOME || '').trim();
28
- if (dshHome) {
29
- try { if (existsSync(join(dshHome, 'qqbot-settings'))) return dshHome; } catch { /* ignore */ }
30
- }
31
- try { return join(homedir(), '.dsh'); } catch { return process.cwd(); }
32
- }
33
-
34
- /** 可能的 settings 根目录(按新→旧) */export function settingsRoots() {
35
- const out = [];
36
- const appData = String(process.env.APPDATA || '').trim();
37
- if (appData) out.push(join(appData, 'dsh-desktop', 'harness', 'qqbot-settings'));
38
- const dshHome = String(process.env.DSH_HOME || '').trim();
39
- if (dshHome) out.push(join(dshHome, 'qqbot-settings'));
40
- try { out.push(join(homedir(), '.dsh', 'qqbot-settings')); } catch { /* ignore */ }
41
- return out.filter((p) => { try { return existsSync(p); } catch { return false; } });
42
- }
43
-
44
- /** 该目录下最新修改的 im-qqbot-*.json(同一 profile 里可能有多个命名空间) */
45
- function newestNsFile(dir) {
46
- try {
47
- const cands = readdirSync(dir).filter((f) => /^im-qqbot-.*\.json$/.test(f));
48
- if (!cands.length) return '';
49
- cands.sort((a, b) => statSync(join(dir, b)).mtimeMs - statSync(join(dir, a)).mtimeMs);
50
- return join(dir, String(cands[0]));
51
- } catch { return ''; }
52
- }
53
-
54
- /**
55
- * 找设置文件:`ns` 精确命中优先;找不到再退到该 profile 下最新的 im-qqbot-*.json。
56
- * @param {string} ns 例如 'im-qqbot' / 'im-qqbot-2'
57
- * @returns {string} 绝对路径;找不到返回 ''
58
- */
59
- export function findSettingsFile(ns) {
60
- const name = String(ns || 'im-qqbot').replace(/\.json$/i, '');
61
- const profEnv = String(process.env.DSH_PROFILE || '').trim();
62
- for (const root of settingsRoots()) {
63
- let profiles = [];
64
- try { profiles = readdirSync(root).filter((p) => { try { return statSync(join(root, p)).isDirectory(); } catch { return false; } }); }
65
- catch { continue; }
66
- // 显式 DSH_PROFILE 优先,其余按“布局新→旧”:desktop 先于 web
67
- profiles.sort((a, b) => {
68
- const rank = (x) => (x === profEnv ? 0 : x === 'desktop' ? 1 : x === 'web' ? 2 : 3);
69
- return rank(a) - rank(b);
70
- });
71
- for (const p of profiles) {
72
- const dir = join(root, p);
73
- const exact = join(dir, name + '.json');
74
- if (existsSync(exact)) return exact;
75
- }
76
- // 没精确命中:取任意 profile 下最新的(老配置命名不稳定时兜底)
77
- for (const p of profiles) {
78
- const f = newestNsFile(join(root, p));
79
- if (f) return f;
80
- }
81
- }
82
- return '';
83
- }
1
+ /**
2
+ * settings-io.js — 找到 dsh 的 qqbot 设置文件(2026-12-01)
3
+ *
4
+ * 背景:DSH Desktop 0.14 把 profile 从 `web` 换成 `desktop`,设置数据也从
5
+ * `~/.dsh/qqbot-settings/<profile>/<ns>.json`
6
+ * 搬到了
7
+ * `%APPDATA%/dsh-desktop/harness/qqbot-settings/<profile>/<ns>.json`
8
+ *
9
+ * 插件里还有几处写死 `~/.dsh/.../web` 的读法(autoRecall 热读、autoRecall 工具),
10
+ * 升级后全部读到"文件不存在"。这里统一解析:环境变量 > AppData harness > ~/.dsh。
11
+ */
12
+ import { existsSync, readdirSync, statSync } from 'node:fs';
13
+ import { join } from 'node:path';
14
+ import { dshHome, dshHomeCandidates } from './paths.js';
15
+
16
+ /**
17
+ * dsh home(能直接拼 `qqbot-settings/…` 的那一层)。
18
+ * DSH Desktop 0.14 的真实位置是 `%APPDATA%/dsh-desktop/harness`,而环境变量 DSH_HOME
19
+ * 只在 shell/工具调用时临时注入,插件进程里通常是空 —— 以前这里回落 ~/.dsh 就永远读不到设置。
20
+ */
21
+ export function settingsHome() {
22
+ // 候选顺序统一由 shared/paths.js 给(含 QQBOT_DSH_HOME / APPDATA / DSH_HOME / XDG / ~/.dsh),
23
+ // 这里只多做一步:优先挑"真的有 qqbot-settings 子目录"的那一层。
24
+ for (const h of dshHomeCandidates()) {
25
+ try {
26
+ if (existsSync(join(h, 'qqbot-settings')))
27
+ return h;
28
+ }
29
+ catch { /* ignore */ }
30
+ }
31
+ return dshHome();
32
+ }
33
+
34
+ /** 可能的 settings 根目录(按新→旧) */
35
+ export function settingsRoots() {
36
+ const out = dshHomeCandidates().map((h) => join(h, 'qqbot-settings'));
37
+ return out.filter((p) => { try { return existsSync(p); } catch { return false; } });
38
+ }
39
+
40
+ /** 该目录下最新修改的 im-qqbot-*.json(同一 profile 里可能有多个命名空间) */
41
+ function newestNsFile(dir) {
42
+ try {
43
+ const cands = readdirSync(dir).filter((f) => /^im-qqbot-.*\.json$/.test(f));
44
+ if (!cands.length) return '';
45
+ cands.sort((a, b) => statSync(join(dir, b)).mtimeMs - statSync(join(dir, a)).mtimeMs);
46
+ return join(dir, String(cands[0]));
47
+ } catch { return ''; }
48
+ }
49
+
50
+ /**
51
+ * 找设置文件:`ns` 精确命中优先;找不到再退到该 profile 下最新的 im-qqbot-*.json。
52
+ * @param {string} ns 例如 'im-qqbot' / 'im-qqbot-2'
53
+ * @returns {string} 绝对路径;找不到返回 ''
54
+ */
55
+ export function findSettingsFile(ns) {
56
+ const name = String(ns || 'im-qqbot').replace(/\.json$/i, '');
57
+ const profEnv = String(process.env.DSH_PROFILE || '').trim();
58
+ for (const root of settingsRoots()) {
59
+ let profiles = [];
60
+ try { profiles = readdirSync(root).filter((p) => { try { return statSync(join(root, p)).isDirectory(); } catch { return false; } }); }
61
+ catch { continue; }
62
+ // 显式 DSH_PROFILE 优先,其余按“布局新→旧”:desktop 先于 web
63
+ profiles.sort((a, b) => {
64
+ const rank = (x) => (x === profEnv ? 0 : x === 'desktop' ? 1 : x === 'web' ? 2 : 3);
65
+ return rank(a) - rank(b);
66
+ });
67
+ for (const p of profiles) {
68
+ const dir = join(root, p);
69
+ const exact = join(dir, name + '.json');
70
+ if (existsSync(exact)) return exact;
71
+ }
72
+ // 没精确命中:取任意 profile 下最新的(老配置命名不稳定时兜底)
73
+ for (const p of profiles) {
74
+ const f = newestNsFile(join(root, p));
75
+ if (f) return f;
76
+ }
77
+ }
78
+ return '';
79
+ }