dsh-bagu 0.12.0 → 0.13.0
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/NOTICE +52 -52
- package/README.md +231 -231
- package/client.js +526 -526
- package/dsh-plugin.json +1 -1
- package/lib/bridge.js +104 -104
- package/lib/config.js +91 -91
- package/lib/guard.js +46 -1
- package/lib/index.js +475 -475
- package/lib/layers.js +70 -0
- package/lib/memes.js +251 -251
- package/lib/session-bridge.js +90 -90
- package/lib/update.js +230 -230
- package/package.json +2 -2
- package/test/deepseek-voice.test.mjs +66 -0
- package/test/fragment.test.mjs +82 -82
- package/test/memes.test.mjs +60 -60
- package/test/prefetch.test.mjs +176 -176
- package/test/realtime.test.mjs +53 -53
- package/test/session-bridge.test.mjs +74 -74
- package/test/update.test.mjs +50 -50
package/dsh-plugin.json
CHANGED
package/lib/bridge.js
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 接梗:不是查「这是什么意思」,是找「顺着这个能接什么」。
|
|
3
|
-
*
|
|
4
|
-
* 数据里现成的结构是:keywords 在梗之间重叠。
|
|
5
|
-
* 「瞎问虾猜」→ 反向空耳 / 握着我的抱枕 / 七岁舔地砖 / 第四种速度
|
|
6
|
-
* 「福本伸行」→ 超智游戏 / 斗牌传说 / 末世路
|
|
7
|
-
* 这就是族。对方提了一个,从族里挑别的接上去。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/** 泛用词,不能当族锚点。和 memes.js 里那份同源。 */
|
|
11
|
-
const STOP = new Set([
|
|
12
|
-
'感谢', '分享', '推荐', '喜欢', '支持', '关注', '点赞', '评论',
|
|
13
|
-
'视频', '内容', '这个', '那个', '什么', '怎么', '可以', '不能',
|
|
14
|
-
'我们', '你们', '他们', '自己', '现在', '以后', '之前', '后来',
|
|
15
|
-
'开始', '结束', '问题', '东西', '时间', '地方', '时候',
|
|
16
|
-
'b站', '网络', '二次创作', '文字梗', '游戏梗', '动画梗', '梗',
|
|
17
|
-
]);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 找能接的梗。
|
|
21
|
-
*
|
|
22
|
-
* @param {string} text 对方说的话
|
|
23
|
-
* @param {Array} memes 梗库
|
|
24
|
-
* @param {{max?: number}} opts
|
|
25
|
-
* @returns {{by: string[], same: string[], tags: string[]}}
|
|
26
|
-
*/
|
|
27
|
-
export function bridge(text, memes, opts = {}) {
|
|
28
|
-
const src = String(text ?? '');
|
|
29
|
-
const max = opts.max || 4;
|
|
30
|
-
if (!src || !memes || !memes.length) return { by: [], same: [], tags: [] };
|
|
31
|
-
|
|
32
|
-
// 1. 这段话里提到了哪些梗
|
|
33
|
-
const idx = new Map();
|
|
34
|
-
for (const m of memes) {
|
|
35
|
-
for (const k of [m.slug, m.title, ...(m.aliases || []), ...(m.keywords || [])]) {
|
|
36
|
-
if (!k) continue;
|
|
37
|
-
const key = String(k).toLowerCase();
|
|
38
|
-
if (STOP.has(key) || key.length < 2) continue;
|
|
39
|
-
if (!idx.has(key)) idx.set(key, []);
|
|
40
|
-
idx.get(key).push(m);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const hitWords = [];
|
|
45
|
-
const srcLow = src.toLowerCase();
|
|
46
|
-
for (const k of idx.keys()) {
|
|
47
|
-
if (srcLow.includes(k)) hitWords.push(k);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// 2. 先算「真的提到了」—— 按 slug / title / alias 直接命中,不靠 keyword
|
|
51
|
-
const same = new Set();
|
|
52
|
-
for (const m of memes) {
|
|
53
|
-
const names = [m.slug, m.title, ...(m.aliases || [])]
|
|
54
|
-
.filter(Boolean)
|
|
55
|
-
.map((x) => String(x).toLowerCase());
|
|
56
|
-
if (names.some((n) => n.length >= 2 && src.toLowerCase().includes(n))) same.add(m.slug);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 3. 再算「同族里还有什么」—— 顺着 hitWords 找别的梗,排除已提到的
|
|
60
|
-
const by = new Set();
|
|
61
|
-
for (const k of hitWords) {
|
|
62
|
-
for (const m of idx.get(k) || []) {
|
|
63
|
-
if (same.has(m.slug)) continue;
|
|
64
|
-
by.add(m.slug);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 4. 标签也带上 —— 有时候接的不是具体梗,是同一类
|
|
69
|
-
const tags = new Set();
|
|
70
|
-
for (const slug of same) {
|
|
71
|
-
const m = memes.find((x) => x.slug === slug);
|
|
72
|
-
for (const t of (m && m.tags) || []) tags.add(t);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 再兜一道:by 里不许出现 same 已提到的
|
|
76
|
-
const byClean = [...by].filter((x) => !same.has(x));
|
|
77
|
-
return {
|
|
78
|
-
by: byClean.slice(0, max),
|
|
79
|
-
same: [...same].slice(0, max),
|
|
80
|
-
tags: [...tags].slice(0, max),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* 给一句人看的接梗提示。
|
|
86
|
-
*
|
|
87
|
-
* 不是替人写回复 —— 是告诉他「对方在说这一族,可以往这个方向接」。
|
|
88
|
-
*/
|
|
89
|
-
export function bridgeHint(text, memes, opts = {}) {
|
|
90
|
-
const r = bridge(text, memes, opts);
|
|
91
|
-
if (!r.same.length && !r.by.length) return null;
|
|
92
|
-
|
|
93
|
-
const parts = [];
|
|
94
|
-
if (r.same.length) {
|
|
95
|
-
parts.push(`对方提的是 ${r.same.join('、')}`);
|
|
96
|
-
if (r.by.length) parts.push(`同族还有 ${r.by.join('、')}`);
|
|
97
|
-
} else if (r.by.length) {
|
|
98
|
-
// 正文没提梗名,但提到了同一族的东西(作者、作品、系列)
|
|
99
|
-
parts.push(`没提具体梗名,但这一族有 ${r.by.join('、')}`);
|
|
100
|
-
}
|
|
101
|
-
if (r.tags.length && !parts.length) parts.push(`这一类是 ${r.tags.slice(0, 3).join('/')}`);
|
|
102
|
-
|
|
103
|
-
return parts.length ? parts.join(';') : null;
|
|
104
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 接梗:不是查「这是什么意思」,是找「顺着这个能接什么」。
|
|
3
|
+
*
|
|
4
|
+
* 数据里现成的结构是:keywords 在梗之间重叠。
|
|
5
|
+
* 「瞎问虾猜」→ 反向空耳 / 握着我的抱枕 / 七岁舔地砖 / 第四种速度
|
|
6
|
+
* 「福本伸行」→ 超智游戏 / 斗牌传说 / 末世路
|
|
7
|
+
* 这就是族。对方提了一个,从族里挑别的接上去。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** 泛用词,不能当族锚点。和 memes.js 里那份同源。 */
|
|
11
|
+
const STOP = new Set([
|
|
12
|
+
'感谢', '分享', '推荐', '喜欢', '支持', '关注', '点赞', '评论',
|
|
13
|
+
'视频', '内容', '这个', '那个', '什么', '怎么', '可以', '不能',
|
|
14
|
+
'我们', '你们', '他们', '自己', '现在', '以后', '之前', '后来',
|
|
15
|
+
'开始', '结束', '问题', '东西', '时间', '地方', '时候',
|
|
16
|
+
'b站', '网络', '二次创作', '文字梗', '游戏梗', '动画梗', '梗',
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 找能接的梗。
|
|
21
|
+
*
|
|
22
|
+
* @param {string} text 对方说的话
|
|
23
|
+
* @param {Array} memes 梗库
|
|
24
|
+
* @param {{max?: number}} opts
|
|
25
|
+
* @returns {{by: string[], same: string[], tags: string[]}}
|
|
26
|
+
*/
|
|
27
|
+
export function bridge(text, memes, opts = {}) {
|
|
28
|
+
const src = String(text ?? '');
|
|
29
|
+
const max = opts.max || 4;
|
|
30
|
+
if (!src || !memes || !memes.length) return { by: [], same: [], tags: [] };
|
|
31
|
+
|
|
32
|
+
// 1. 这段话里提到了哪些梗
|
|
33
|
+
const idx = new Map();
|
|
34
|
+
for (const m of memes) {
|
|
35
|
+
for (const k of [m.slug, m.title, ...(m.aliases || []), ...(m.keywords || [])]) {
|
|
36
|
+
if (!k) continue;
|
|
37
|
+
const key = String(k).toLowerCase();
|
|
38
|
+
if (STOP.has(key) || key.length < 2) continue;
|
|
39
|
+
if (!idx.has(key)) idx.set(key, []);
|
|
40
|
+
idx.get(key).push(m);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const hitWords = [];
|
|
45
|
+
const srcLow = src.toLowerCase();
|
|
46
|
+
for (const k of idx.keys()) {
|
|
47
|
+
if (srcLow.includes(k)) hitWords.push(k);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 2. 先算「真的提到了」—— 按 slug / title / alias 直接命中,不靠 keyword
|
|
51
|
+
const same = new Set();
|
|
52
|
+
for (const m of memes) {
|
|
53
|
+
const names = [m.slug, m.title, ...(m.aliases || [])]
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
.map((x) => String(x).toLowerCase());
|
|
56
|
+
if (names.some((n) => n.length >= 2 && src.toLowerCase().includes(n))) same.add(m.slug);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 3. 再算「同族里还有什么」—— 顺着 hitWords 找别的梗,排除已提到的
|
|
60
|
+
const by = new Set();
|
|
61
|
+
for (const k of hitWords) {
|
|
62
|
+
for (const m of idx.get(k) || []) {
|
|
63
|
+
if (same.has(m.slug)) continue;
|
|
64
|
+
by.add(m.slug);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 4. 标签也带上 —— 有时候接的不是具体梗,是同一类
|
|
69
|
+
const tags = new Set();
|
|
70
|
+
for (const slug of same) {
|
|
71
|
+
const m = memes.find((x) => x.slug === slug);
|
|
72
|
+
for (const t of (m && m.tags) || []) tags.add(t);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 再兜一道:by 里不许出现 same 已提到的
|
|
76
|
+
const byClean = [...by].filter((x) => !same.has(x));
|
|
77
|
+
return {
|
|
78
|
+
by: byClean.slice(0, max),
|
|
79
|
+
same: [...same].slice(0, max),
|
|
80
|
+
tags: [...tags].slice(0, max),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 给一句人看的接梗提示。
|
|
86
|
+
*
|
|
87
|
+
* 不是替人写回复 —— 是告诉他「对方在说这一族,可以往这个方向接」。
|
|
88
|
+
*/
|
|
89
|
+
export function bridgeHint(text, memes, opts = {}) {
|
|
90
|
+
const r = bridge(text, memes, opts);
|
|
91
|
+
if (!r.same.length && !r.by.length) return null;
|
|
92
|
+
|
|
93
|
+
const parts = [];
|
|
94
|
+
if (r.same.length) {
|
|
95
|
+
parts.push(`对方提的是 ${r.same.join('、')}`);
|
|
96
|
+
if (r.by.length) parts.push(`同族还有 ${r.by.join('、')}`);
|
|
97
|
+
} else if (r.by.length) {
|
|
98
|
+
// 正文没提梗名,但提到了同一族的东西(作者、作品、系列)
|
|
99
|
+
parts.push(`没提具体梗名,但这一族有 ${r.by.join('、')}`);
|
|
100
|
+
}
|
|
101
|
+
if (r.tags.length && !parts.length) parts.push(`这一类是 ${r.tags.slice(0, 3).join('/')}`);
|
|
102
|
+
|
|
103
|
+
return parts.length ? parts.join(';') : null;
|
|
104
|
+
}
|
package/lib/config.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 配置:读写插件目录的 config.json,热生效。
|
|
3
|
-
*
|
|
4
|
-
* 存在插件自己的目录里(不放全局 settings.yaml),这样插件删了配置也跟着走。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
8
|
-
import { dirname, join } from 'node:path';
|
|
9
|
-
import { fileURLToPath } from 'node:url';
|
|
10
|
-
|
|
11
|
-
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
export const CONFIG_FILE = join(HERE, '..', 'config.json');
|
|
13
|
-
|
|
14
|
-
export const DEFAULTS = {
|
|
15
|
-
/** 整节系统提示挂不挂 */
|
|
16
|
-
enabled: true,
|
|
17
|
-
/** 只要「查」,不挂 prompt 那一节的话设 false */
|
|
18
|
-
prompt: true,
|
|
19
|
-
/** 严格模式:破折号、只有评价没有具体东西,这些也打回 */
|
|
20
|
-
strict: false,
|
|
21
|
-
/** prompt 节的 order,越大越靠后 */
|
|
22
|
-
order: 921,
|
|
23
|
-
/** 留白词低于这个密度(每千字)就报「句句在下断言」 */
|
|
24
|
-
hedgeFloor: 0.2,
|
|
25
|
-
/** 结构腔超过基线几倍才报 */
|
|
26
|
-
structureTimes: 3,
|
|
27
|
-
/** 具体物低于每百字这个数就报 */
|
|
28
|
-
concreteFloor: 0.6,
|
|
29
|
-
/** 梗库:内置 6792 条,默认开 —— 这是「会玩梗」的底座 */
|
|
30
|
-
memes: true,
|
|
31
|
-
/** 每轮请求前自动查词库并注入。关掉就只在主动调工具时查。 */
|
|
32
|
-
autoMeme: true,
|
|
33
|
-
/** 词库每天自动更新。关掉就不再联网。 */
|
|
34
|
-
autoUpdate: true,
|
|
35
|
-
/** 每天几点更新,0-23。默认凌晨 4 点。 */
|
|
36
|
-
updateHour: 4,
|
|
37
|
-
/** 手动接管玩梗尺度。关着时交给模型自己判断。 */
|
|
38
|
-
toneSwitch: false,
|
|
39
|
-
/** 玩梗尺度 0-100。toneSwitch 关着时不生效。 */
|
|
40
|
-
toneLevel: 50,
|
|
41
|
-
/**
|
|
42
|
-
* AI 接梗:让模型根据族提示拼一句具体的接话。
|
|
43
|
-
*
|
|
44
|
-
* 默认关 —— 开了就每条都要调一次模型,要 API key、要付 token。
|
|
45
|
-
* 养鱼那种要质量的场景可以开;日常聊天不值得。
|
|
46
|
-
*/
|
|
47
|
-
aiBridge: false,
|
|
48
|
-
/** 另配接口开关:默认走会话模型,这个开着才用下面三项 */
|
|
49
|
-
aiUseOwn: false,
|
|
50
|
-
/** AI 接梗用的 baseUrl/model/key。aiUseOwn 关着时不看这些。 */
|
|
51
|
-
aiBaseUrl: '',
|
|
52
|
-
aiModel: '',
|
|
53
|
-
aiApiKey: '',
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export function readConfig() {
|
|
57
|
-
try {
|
|
58
|
-
const raw = readFileSync(CONFIG_FILE, 'utf8');
|
|
59
|
-
const saved = JSON.parse(raw);
|
|
60
|
-
return { ...DEFAULTS, ...saved };
|
|
61
|
-
} catch {
|
|
62
|
-
return { ...DEFAULTS };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function writeConfig(patch) {
|
|
67
|
-
const cur = readConfig();
|
|
68
|
-
const next = { ...cur };
|
|
69
|
-
for (const [k, v] of Object.entries(patch || {})) {
|
|
70
|
-
if (!(k in DEFAULTS)) continue;
|
|
71
|
-
if (typeof DEFAULTS[k] === 'boolean') next[k] = Boolean(v);
|
|
72
|
-
else if (typeof DEFAULTS[k] === 'number') {
|
|
73
|
-
const n = Number(v);
|
|
74
|
-
if (Number.isFinite(n)) next[k] = n;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// order 夹一下,别把别人的节顶飞
|
|
78
|
-
next.order = Math.min(999, Math.max(1, Math.round(next.order)));
|
|
79
|
-
// 阈值不许为负
|
|
80
|
-
next.hedgeFloor = Math.max(0, next.hedgeFloor);
|
|
81
|
-
next.structureTimes = Math.max(1, next.structureTimes);
|
|
82
|
-
next.concreteFloor = Math.max(0, next.concreteFloor);
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
mkdirSync(dirname(CONFIG_FILE), { recursive: true });
|
|
86
|
-
writeFileSync(CONFIG_FILE, JSON.stringify(next, null, 2) + '\n', 'utf8');
|
|
87
|
-
} catch {
|
|
88
|
-
/* 只读环境就只在内存里生效 */
|
|
89
|
-
}
|
|
90
|
-
return next;
|
|
91
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 配置:读写插件目录的 config.json,热生效。
|
|
3
|
+
*
|
|
4
|
+
* 存在插件自己的目录里(不放全局 settings.yaml),这样插件删了配置也跟着走。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
export const CONFIG_FILE = join(HERE, '..', 'config.json');
|
|
13
|
+
|
|
14
|
+
export const DEFAULTS = {
|
|
15
|
+
/** 整节系统提示挂不挂 */
|
|
16
|
+
enabled: true,
|
|
17
|
+
/** 只要「查」,不挂 prompt 那一节的话设 false */
|
|
18
|
+
prompt: true,
|
|
19
|
+
/** 严格模式:破折号、只有评价没有具体东西,这些也打回 */
|
|
20
|
+
strict: false,
|
|
21
|
+
/** prompt 节的 order,越大越靠后 */
|
|
22
|
+
order: 921,
|
|
23
|
+
/** 留白词低于这个密度(每千字)就报「句句在下断言」 */
|
|
24
|
+
hedgeFloor: 0.2,
|
|
25
|
+
/** 结构腔超过基线几倍才报 */
|
|
26
|
+
structureTimes: 3,
|
|
27
|
+
/** 具体物低于每百字这个数就报 */
|
|
28
|
+
concreteFloor: 0.6,
|
|
29
|
+
/** 梗库:内置 6792 条,默认开 —— 这是「会玩梗」的底座 */
|
|
30
|
+
memes: true,
|
|
31
|
+
/** 每轮请求前自动查词库并注入。关掉就只在主动调工具时查。 */
|
|
32
|
+
autoMeme: true,
|
|
33
|
+
/** 词库每天自动更新。关掉就不再联网。 */
|
|
34
|
+
autoUpdate: true,
|
|
35
|
+
/** 每天几点更新,0-23。默认凌晨 4 点。 */
|
|
36
|
+
updateHour: 4,
|
|
37
|
+
/** 手动接管玩梗尺度。关着时交给模型自己判断。 */
|
|
38
|
+
toneSwitch: false,
|
|
39
|
+
/** 玩梗尺度 0-100。toneSwitch 关着时不生效。 */
|
|
40
|
+
toneLevel: 50,
|
|
41
|
+
/**
|
|
42
|
+
* AI 接梗:让模型根据族提示拼一句具体的接话。
|
|
43
|
+
*
|
|
44
|
+
* 默认关 —— 开了就每条都要调一次模型,要 API key、要付 token。
|
|
45
|
+
* 养鱼那种要质量的场景可以开;日常聊天不值得。
|
|
46
|
+
*/
|
|
47
|
+
aiBridge: false,
|
|
48
|
+
/** 另配接口开关:默认走会话模型,这个开着才用下面三项 */
|
|
49
|
+
aiUseOwn: false,
|
|
50
|
+
/** AI 接梗用的 baseUrl/model/key。aiUseOwn 关着时不看这些。 */
|
|
51
|
+
aiBaseUrl: '',
|
|
52
|
+
aiModel: '',
|
|
53
|
+
aiApiKey: '',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export function readConfig() {
|
|
57
|
+
try {
|
|
58
|
+
const raw = readFileSync(CONFIG_FILE, 'utf8');
|
|
59
|
+
const saved = JSON.parse(raw);
|
|
60
|
+
return { ...DEFAULTS, ...saved };
|
|
61
|
+
} catch {
|
|
62
|
+
return { ...DEFAULTS };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function writeConfig(patch) {
|
|
67
|
+
const cur = readConfig();
|
|
68
|
+
const next = { ...cur };
|
|
69
|
+
for (const [k, v] of Object.entries(patch || {})) {
|
|
70
|
+
if (!(k in DEFAULTS)) continue;
|
|
71
|
+
if (typeof DEFAULTS[k] === 'boolean') next[k] = Boolean(v);
|
|
72
|
+
else if (typeof DEFAULTS[k] === 'number') {
|
|
73
|
+
const n = Number(v);
|
|
74
|
+
if (Number.isFinite(n)) next[k] = n;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// order 夹一下,别把别人的节顶飞
|
|
78
|
+
next.order = Math.min(999, Math.max(1, Math.round(next.order)));
|
|
79
|
+
// 阈值不许为负
|
|
80
|
+
next.hedgeFloor = Math.max(0, next.hedgeFloor);
|
|
81
|
+
next.structureTimes = Math.max(1, next.structureTimes);
|
|
82
|
+
next.concreteFloor = Math.max(0, next.concreteFloor);
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
mkdirSync(dirname(CONFIG_FILE), { recursive: true });
|
|
86
|
+
writeFileSync(CONFIG_FILE, JSON.stringify(next, null, 2) + '\n', 'utf8');
|
|
87
|
+
} catch {
|
|
88
|
+
/* 只读环境就只在内存里生效 */
|
|
89
|
+
}
|
|
90
|
+
return next;
|
|
91
|
+
}
|
package/lib/guard.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import { analyze } from './analyze.js';
|
|
16
16
|
import { STOCK_PHRASES, GIT_STOCK, GIT_TEMPLATE_ROWS, countTemplateRows, REVIEW_STOCK, VIDEO_STOCK } from './lexicon.js';
|
|
17
|
-
import { HOLLOW_ACTIONS, HOLLOW_ADJECTIVES, LEARNED_TONE, CODE_COMMENT_NARRATION, MOTIVATIONAL_SLOP, UNIVERSAL_FILLER } from './layers.js';
|
|
17
|
+
import { HOLLOW_ACTIONS, HOLLOW_ADJECTIVES, LEARNED_TONE, CODE_COMMENT_NARRATION, MOTIVATIONAL_SLOP, UNIVERSAL_FILLER, EMPTY_REFERENCE, CONCRETE_HINT, ECHO_COMMAND, PROMISE_TAIL } from './layers.js';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* 打回原因按严重度排。谁先命中谁负责,只报一条 —— 报三条 agent 会挑最轻的改。
|
|
@@ -51,6 +51,51 @@ const REASONS = [
|
|
|
51
51
|
},
|
|
52
52
|
hint: '删掉这句,直接说事',
|
|
53
53
|
},
|
|
54
|
+
{
|
|
55
|
+
id: 'echo-command',
|
|
56
|
+
// 把一句话拆两截,再把球弹回去或者下个令。
|
|
57
|
+
// 「你想说啥」→「你这话是在问别人,还是问自己?」
|
|
58
|
+
test: (r, text) => {
|
|
59
|
+
const t = String(text ?? '').trim();
|
|
60
|
+
if (!t || t.length > 60) return false;
|
|
61
|
+
if (!ECHO_COMMAND.some((re) => re.test(t))) return false;
|
|
62
|
+
return !CONCRETE_HINT.test(t);
|
|
63
|
+
},
|
|
64
|
+
why: '拆句弹回',
|
|
65
|
+
hint: '一句能说完就说完,别把球弹回去',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: 'promise-tail',
|
|
69
|
+
// 把道别升格成守护。「晚安」→「睡吧,我守着。」
|
|
70
|
+
test: (r, text) => {
|
|
71
|
+
const t = String(text ?? '').trim();
|
|
72
|
+
if (!t || t.length > 40) return false;
|
|
73
|
+
if (!PROMISE_TAIL.some((re) => re.test(t))) return false;
|
|
74
|
+
return !CONCRETE_HINT.test(t);
|
|
75
|
+
},
|
|
76
|
+
why: '承诺式收尾',
|
|
77
|
+
hint: '该道晚安就道晚安,不用加重',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'empty-reference',
|
|
81
|
+
// 空指代撑分量:「好的」写成「这话我记下了」。
|
|
82
|
+
// 两个条件同时成立才算:开头是空指代,且整句没给任何具体东西。
|
|
83
|
+
test: (r, text) => {
|
|
84
|
+
const t = String(text ?? '').trim();
|
|
85
|
+
if (!t) return false;
|
|
86
|
+
const hit = EMPTY_REFERENCE.find((re) => re.test(t));
|
|
87
|
+
if (!hit) return false;
|
|
88
|
+
// 后面给了数字、专名、时间点就不算空
|
|
89
|
+
return !CONCRETE_HINT.test(t);
|
|
90
|
+
},
|
|
91
|
+
why: (r, text) => {
|
|
92
|
+
const t = String(text ?? '').trim();
|
|
93
|
+
const hit = EMPTY_REFERENCE.find((re) => re.test(t));
|
|
94
|
+
const m = hit ? t.match(hit) : null;
|
|
95
|
+
return m ? `空指代「${m[0].slice(0, 12)}」` : '空指代';
|
|
96
|
+
},
|
|
97
|
+
hint: '把该说的那件事直接说出来',
|
|
98
|
+
},
|
|
54
99
|
{
|
|
55
100
|
id: 'hollow-action',
|
|
56
101
|
// 动词 + 宏观名词:说了动作,没说改哪一行。不分场景。
|