dsh-bagu 0.2.1 → 0.3.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/README.md +97 -77
- package/client.js +214 -162
- package/dsh-plugin.json +1 -1
- package/lib/analyze.js +58 -4
- package/lib/index.js +31 -50
- package/lib/lexicon.js +20 -1
- package/lib/render.js +83 -0
- package/package.json +5 -2
- package/test/analyze.test.mjs +18 -7
- package/test/client.test.mjs +52 -26
package/README.md
CHANGED
|
@@ -1,117 +1,137 @@
|
|
|
1
1
|
# dsh-bagu
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> 名字来自「八股文」——那种格式对仗、内容空洞、谁都能写的东西。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 一句话:它是干什么的
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
这些东西只有真的在场的人才给得出。
|
|
9
|
-
2. **撑场面的话** —— 意义、价值、本质、趋势这类抽象词,「重要、关键、深刻」这类评价词。
|
|
10
|
-
说得越多,越是在说事之外加光。
|
|
11
|
-
3. **留白词** —— 好像、应该、大概、可能。一个都没有,说明全篇没有一处不确定。
|
|
7
|
+
**你把一段话粘进去,它告诉你这段话里有没有「谁都能说」的成分。**
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
跟同一文体的真人基线比,超三倍就报。
|
|
9
|
+
不改你的字,不给分数,只指出哪几处可疑,然后问你几个问题。
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
## 什么是「八股」
|
|
12
|
+
|
|
13
|
+
一句话,换个人说,还成不成立?
|
|
14
|
+
|
|
15
|
+
- 成立 → 就是八股。谁都能说的话,慢慢就没人想看了。
|
|
16
|
+
- 不成立 → 这段话里有只有你才给得出的东西。
|
|
17
|
+
|
|
18
|
+
看两个例子就懂了:
|
|
17
19
|
|
|
18
20
|
```text
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
差的:「本次修改已完成。首先调整了章节结构,其次新增了规则条款,最后优化了可读性。
|
|
22
|
+
综上所述,这次改动具有重要意义。」
|
|
23
|
+
|
|
24
|
+
好的:「改了 AGENTS.md,加了 §4。第七页那个表我删了,因为原来那三列一直是空的。」
|
|
23
25
|
```
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
第一段把「AGENTS.md」换成任何文件名都通顺,所以它是八股。
|
|
28
|
+
第二段提到了第七页、提到了一个空表——别人编不出来。
|
|
27
29
|
|
|
28
|
-
##
|
|
30
|
+
## 它看哪四样东西
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
| 看什么 | 具体抓什么 | 为什么算数 |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| **具体物** | 数字、时间点、「我试过」、原话、专有名字 | 只有真在场的人才给得出 |
|
|
35
|
+
| **撑场面的话** | 意义 / 价值 / 本质 / 趋势,重要 / 关键 / 深刻 | 说得越多,越是在给事加光 |
|
|
36
|
+
| **留白词** | 好像 / 应该 / 大概 / 可能 | 一个都没有 = 句句在下断言 |
|
|
37
|
+
| **结构腔** | 不是A而是B、先…再…、三段并列、破折号 | 真人用,但密度极低,超基线才报 |
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
通篇一个调子、每段都收个小结论、同一件事换个说法又说一遍 —— 这些它看不见。
|
|
39
|
+
外加一个**同义轮换**:同一段里「使用 / 采用 / 运用」挑了两个以上。真人会反复用同一个词,换着说是心虚。
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
真实经验、只有当事人知道的细节、真的想说的观点。这三样插件给不了,模型也自己长不出来。
|
|
41
|
+
## 装
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
```sh
|
|
44
|
+
dsh plugin --profile web add dsh-bagu
|
|
45
|
+
```
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
接着被新写法绕过。这是个止血带。
|
|
47
|
+
装完重启一次 dsh。然后在**设置 → 八股检测**里能看到这一页。
|
|
43
48
|
|
|
44
|
-
##
|
|
49
|
+
## 怎么用
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
事也跟着丢了,而且改出来的东西有它自己的均匀。
|
|
51
|
+
**方式一 · 让它自己查。** 你写完一段话,跟它说:
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
```
|
|
54
|
+
帮我查查这段有没有八股味
|
|
55
|
+
```
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
它会调 `bagu_check`,回三行:
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
```text
|
|
60
|
+
可疑 具体0 抽象1 评价1 留白0 结构0/千
|
|
61
|
+
· 综上所述
|
|
62
|
+
问 「综上所述」—— 这几个词,换成平时说话你会怎么讲?
|
|
63
|
+
```
|
|
58
64
|
|
|
59
|
-
|
|
65
|
+
想要详细报告,加一句「完整报告」,它传 `full: true`,会给逐处的命中位置和六条问句。
|
|
60
66
|
|
|
61
|
-
|
|
67
|
+
**方式二 · 只要问句。**
|
|
62
68
|
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
bagu_ask({ text: "……" }) // 只要问句
|
|
69
|
+
```
|
|
70
|
+
用 bagu_ask 问问我这段话
|
|
66
71
|
```
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
它只给问句,不给结论。答得上就留着,答不上来那处就是摆设。
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
- **系统提示那一节开关**:关掉只留工具,不往提示里塞话 —— 想手动查、不想被改说话习惯的人用这个
|
|
72
|
-
- **三个阈值**:留白词下限、结构腔报警倍数、具体物下限,都能调
|
|
73
|
-
- **试一下**:粘一段话,当场看结果,不发送、不落盘
|
|
75
|
+
**方式三 · 设置页里当场试。** 粘一段话点「查一下」,不发送、不落盘。
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
提供 `status` / `config` / `preview` 三个接口。
|
|
77
|
+
## 它不干什么
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
这几条先说清楚,免得期待错位。
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
```
|
|
81
|
+
**它不改写。** 一个字都不动。改是人的事,工具只把材料摆出来。
|
|
82
|
+
|
|
83
|
+
**它不给分数。** 没有「人味 62 分」这种东西。分数会让人只盯数字,不看句子。
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
85
|
+
**它不是体检报告。** 它管不了「整段是不是人写的」。通篇一个调子、每段都收个小结论、
|
|
86
|
+
同一件事换个说法又说一遍——这些它看不见,得你自己读。
|
|
87
|
+
|
|
88
|
+
**它是体温计,不是退烧药。** 测出来 49/千字,不会让你的话变好。真要让一段话立起来的是
|
|
89
|
+
真实经历、只有你知道的细节、真的想说的观点。这三样插件给不了,模型也长不出来。
|
|
90
|
+
|
|
91
|
+
**规则会过期。** 今天有效的识别特征,被写成规则之后,就成了可以绕过去的东西。
|
|
92
|
+
这是个止血带。
|
|
93
|
+
|
|
94
|
+
## 省 token 是怎么做的
|
|
95
|
+
|
|
96
|
+
这个插件从设计上就在控制上下文开销:
|
|
97
|
+
|
|
98
|
+
| 项 | 大小 |
|
|
99
|
+
|---|---|
|
|
100
|
+
| 系统提示注入 | 124 字(每次会话) |
|
|
101
|
+
| 两个工具的描述 | 62 字 |
|
|
102
|
+
| 默认输出 | 约 60 字(三行) |
|
|
103
|
+
|
|
104
|
+
所有判断都在本地正则里跑完,**不调模型**——这是零 token 成本的那一半。
|
|
105
|
+
要看详细报告才传 `full: true`,那时候才有几百字。
|
|
106
|
+
|
|
107
|
+
## 短句也能查
|
|
108
|
+
|
|
109
|
+
大部分「AI 味检测」靠密度(每百字几个),短句分母太小,等于废掉。
|
|
110
|
+
|
|
111
|
+
这个插件在六十字以下切换成**绝对计数**:不看密度,看命中了什么。
|
|
112
|
+
「不是A而是B」这种句式,出现在一句话里就已经可疑了,跟字数无关。
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
「这不是技术问题,而是认知问题。」 → 可疑
|
|
116
|
+
「卖卡卖完了随便写了」 → 正常
|
|
101
117
|
```
|
|
102
118
|
|
|
103
|
-
##
|
|
119
|
+
## 数据从哪来
|
|
120
|
+
|
|
121
|
+
权重和基线不是拍的。主要依据:
|
|
122
|
+
|
|
123
|
+
- 两轮对照实验,1169 篇 / 520 万字 / 100+ 项指标([lieflat-less-ai-tone](https://github.com/larashero3-dotcom/lieflat-less-ai-tone))
|
|
124
|
+
- 10 万条真人评论 vs 2180 条 AI 评论的密度实测
|
|
125
|
+
- [sloplint](https://github.com/DW-Studio/sloplint) 的评分公式(绝对命中 + 权重,短文本可用)
|
|
126
|
+
|
|
127
|
+
## 开发
|
|
104
128
|
|
|
105
129
|
```sh
|
|
106
|
-
npm test
|
|
130
|
+
npm test # 41 个
|
|
131
|
+
node preview.html # 需要起个本地服务器看 UI
|
|
107
132
|
```
|
|
108
133
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
- 中文为主,英文没专门校过
|
|
112
|
-
- 基线取自中文评论语料,写长文和文档时会偏严 —— 那类文体本来就该有结构
|
|
113
|
-
- 不给总分。分数会让人只盯数字,不看句子
|
|
114
|
-
- 设置页在 headless 环境里没有,插件照样跑
|
|
134
|
+
设置页的样稿在 `preview.html`,起个 `python -m http.server` 打开就能看,不用装 DSH。
|
|
115
135
|
|
|
116
136
|
## 许可
|
|
117
137
|
|
package/client.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-bagu ——
|
|
2
|
+
* dsh-bagu —— 浏览器半端:设置页「八股检测」
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* 1. client bundle 不是 ESM
|
|
4
|
+
* 约定:
|
|
5
|
+
* 1. client bundle 不是 ESM,是自注册脚本
|
|
6
6
|
* 2. 进「设置」靠 slots.inject('settings.section', ...)
|
|
7
|
-
* 3.
|
|
7
|
+
* 3. 宿主开 /api/bagu,这页只做 fetch
|
|
8
|
+
*
|
|
9
|
+
* 视觉全部走 --dsw-alias-* 设计变量,跟随主题,不写死颜色。
|
|
8
10
|
*/
|
|
9
11
|
window.__ModuleLoader__.load({
|
|
10
12
|
id: 'dsh-bagu',
|
|
@@ -25,48 +27,121 @@ window.__ModuleLoader__.load({
|
|
|
25
27
|
body: JSON.stringify(body || {}),
|
|
26
28
|
}))
|
|
27
29
|
|
|
28
|
-
const SAMPLE = '
|
|
30
|
+
const SAMPLE = '这不是技术问题,而是认知问题。我们使用了新方法,采用了更好的方式,通过提升效率来优化流程。'
|
|
29
31
|
|
|
30
32
|
const CSS = `
|
|
31
|
-
[data-bg
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
[data-bg]{display:flex;flex-direction:column;gap:20px;padding:4px 2px 12px;max-width:660px;
|
|
34
|
+
color:var(--dsw-alias-label-primary,inherit);font-size:13px;line-height:1.5;}
|
|
35
|
+
|
|
36
|
+
/* 头部 */
|
|
37
|
+
[data-bg-head]{display:flex;flex-direction:column;gap:6px;}
|
|
38
|
+
[data-bg-title]{font-size:15px;font-weight:600;letter-spacing:-.01em;}
|
|
39
|
+
[data-bg-sub]{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-tertiary,#9aa0a6);}
|
|
40
|
+
|
|
41
|
+
/* 卡片 */
|
|
42
|
+
[data-bg-card]{display:flex;flex-direction:column;
|
|
43
|
+
border:1px solid var(--dsw-alias-border-l,rgba(128,128,128,.2));
|
|
44
|
+
border-radius:12px;overflow:hidden;
|
|
45
|
+
background:var(--dsw-alias-bg-elevated,transparent);}
|
|
46
|
+
[data-bg-row]{display:flex;align-items:center;gap:12px;padding:12px 14px;}
|
|
47
|
+
[data-bg-row]+[data-bg-row]{border-top:1px solid var(--dsw-alias-border-l,rgba(128,128,128,.12));}
|
|
35
48
|
[data-bg-grow]{flex:1;min-width:0;}
|
|
36
|
-
[data-bg-
|
|
37
|
-
[data-bg-note]
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
[data-bg-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
[data-bg-
|
|
45
|
-
|
|
49
|
+
[data-bg-label]{font-size:13px;font-weight:500;}
|
|
50
|
+
[data-bg-note]{font-size:11.5px;line-height:1.55;color:var(--dsw-alias-label-tertiary,#9aa0a6);margin-top:2px;}
|
|
51
|
+
|
|
52
|
+
/* 分区标题 */
|
|
53
|
+
[data-bg-h]{font-size:11px;font-weight:600;letter-spacing:.05em;text-transform:uppercase;
|
|
54
|
+
color:var(--dsw-alias-label-caption,#8b8b8b);margin-bottom:8px;}
|
|
55
|
+
|
|
56
|
+
/* 开关 */
|
|
57
|
+
[data-bg-sw]{flex:none;width:40px;height:23px;border-radius:12px;border:0;cursor:pointer;position:relative;
|
|
58
|
+
background:var(--dsw-alias-fill-secondary,rgba(128,128,128,.3));transition:background .16s;padding:0;}
|
|
59
|
+
[data-bg-sw][data-on]{background:var(--dsw-alias-state-business-primary,#3b82f6);}
|
|
60
|
+
[data-bg-sw]::after{content:'';position:absolute;top:3px;left:3px;width:17px;height:17px;border-radius:9px;
|
|
61
|
+
background:#fff;transition:transform .16s;}
|
|
62
|
+
[data-bg-sw][data-on]::after{transform:translateX(17px);}
|
|
63
|
+
[data-bg-sw][disabled]{opacity:.45;cursor:default;}
|
|
64
|
+
|
|
65
|
+
/* 数字输入 */
|
|
66
|
+
[data-bg-num]{width:88px;padding:6px 9px;border-radius:8px;font:inherit;font-size:13px;
|
|
67
|
+
font-variant-numeric:tabular-nums;text-align:right;color:inherit;
|
|
68
|
+
border:1px solid var(--dsw-alias-border-l,rgba(128,128,128,.28));
|
|
46
69
|
background:var(--dsw-alias-bg-base,transparent);}
|
|
47
|
-
[data-bg-
|
|
48
|
-
|
|
49
|
-
|
|
70
|
+
[data-bg-num]:focus{outline:2px solid var(--dsw-alias-state-business-primary,#3b82f6);outline-offset:-1px;}
|
|
71
|
+
|
|
72
|
+
/* 文本域 */
|
|
73
|
+
[data-bg-in]{width:100%;box-sizing:border-box;resize:vertical;min-height:86px;padding:11px 13px;border:0;
|
|
74
|
+
font:inherit;font-size:13px;line-height:1.65;color:inherit;
|
|
50
75
|
background:var(--dsw-alias-bg-base,transparent);}
|
|
51
|
-
[data-bg-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
[data-bg-btn]
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
background
|
|
58
|
-
[data-bg-
|
|
59
|
-
|
|
76
|
+
[data-bg-in]:focus{outline:none;}
|
|
77
|
+
|
|
78
|
+
/* 按钮 */
|
|
79
|
+
[data-bg-btn]{padding:7px 15px;border-radius:8px;cursor:pointer;font:inherit;font-size:12.5px;font-weight:500;
|
|
80
|
+
border:1px solid var(--dsw-alias-border-l,rgba(128,128,128,.28));
|
|
81
|
+
background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:inherit;
|
|
82
|
+
transition:background .12s;}
|
|
83
|
+
[data-bg-btn]:hover:not([disabled]){background:var(--dsw-alias-interactive-bg-selected,rgba(128,128,128,.2));}
|
|
84
|
+
[data-bg-btn][disabled]{opacity:.45;cursor:default;}
|
|
85
|
+
[data-bg-btn][data-primary]{background:var(--dsw-alias-state-business-primary,#3b82f6);
|
|
86
|
+
border-color:transparent;color:#fff;}
|
|
87
|
+
[data-bg-btn][data-primary]:hover:not([disabled]){filter:brightness(1.08);}
|
|
88
|
+
|
|
89
|
+
/* 结果 */
|
|
90
|
+
[data-bg-out]{padding:12px 14px;white-space:pre-wrap;word-break:break-word;
|
|
91
|
+
font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
|
|
92
|
+
font-size:11.5px;line-height:1.75;
|
|
93
|
+
background:var(--dsw-alias-bg-base,rgba(128,128,128,.06));
|
|
94
|
+
border-top:1px solid var(--dsw-alias-border-l,rgba(128,128,128,.12));}
|
|
95
|
+
|
|
96
|
+
/* 状态条 */
|
|
97
|
+
[data-bg-msg]{font-size:12px;padding:9px 13px;border-radius:8px;display:flex;gap:8px;align-items:flex-start;
|
|
98
|
+
background:var(--dsw-alias-fill-secondary,rgba(128,128,128,.1));}
|
|
99
|
+
[data-bg-msg][data-err]{background:color-mix(in srgb,var(--dsw-alias-state-error-secondary,#dc2626) 12%,transparent);
|
|
100
|
+
color:var(--dsw-alias-state-error-secondary,#dc2626);}
|
|
101
|
+
[data-bg-msg][data-ok]{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#3b82f6) 12%,transparent);
|
|
102
|
+
color:var(--dsw-alias-state-business-tertiary,inherit);}
|
|
103
|
+
|
|
104
|
+
/* 脚注 */
|
|
105
|
+
[data-bg-foot]{font-size:11px;color:var(--dsw-alias-label-dimmed,#7a7a7a);
|
|
106
|
+
font-family:ui-monospace,SFMono-Regular,Menlo,monospace;word-break:break-all;}
|
|
107
|
+
|
|
108
|
+
/* 加载 */
|
|
109
|
+
[data-bg-skel]{height:64px;border-radius:12px;
|
|
110
|
+
background:linear-gradient(90deg,var(--dsw-alias-fill-secondary,rgba(128,128,128,.08)) 25%,
|
|
111
|
+
var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.14)) 37%,
|
|
112
|
+
var(--dsw-alias-fill-secondary,rgba(128,128,128,.08)) 63%);
|
|
113
|
+
background-size:400% 100%;animation:bg-shimmer 1.4s ease infinite;}
|
|
114
|
+
@keyframes bg-shimmer{0%{background-position:100% 50%}100%{background-position:0 50%}}
|
|
60
115
|
`
|
|
61
116
|
|
|
117
|
+
function Row(props) {
|
|
118
|
+
return h('div', { 'data-bg-row': '' },
|
|
119
|
+
h('div', { 'data-bg-grow': '' },
|
|
120
|
+
h('div', { 'data-bg-label': '' }, props.label),
|
|
121
|
+
props.note ? h('div', { 'data-bg-note': '' }, props.note) : null),
|
|
122
|
+
props.children)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function Switch(props) {
|
|
126
|
+
return h('button', {
|
|
127
|
+
'data-bg-sw': '',
|
|
128
|
+
'data-on': props.on ? '' : undefined,
|
|
129
|
+
'aria-checked': props.on ? 'true' : 'false',
|
|
130
|
+
role: 'switch',
|
|
131
|
+
'aria-label': props.label,
|
|
132
|
+
disabled: props.disabled,
|
|
133
|
+
onClick: props.onChange,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
62
137
|
function Panel() {
|
|
63
138
|
const [st, setSt] = React.useState(null)
|
|
64
139
|
const [view, setView] = React.useState(null)
|
|
65
140
|
const [busy, setBusy] = React.useState('')
|
|
66
|
-
const [msg, setMsg] = React.useState(
|
|
67
|
-
const [bad, setBad] = React.useState(false)
|
|
141
|
+
const [msg, setMsg] = React.useState(null)
|
|
68
142
|
const [text, setText] = React.useState(SAMPLE)
|
|
69
143
|
const [out, setOut] = React.useState('')
|
|
144
|
+
const [full, setFull] = React.useState(false)
|
|
70
145
|
|
|
71
146
|
const load = React.useCallback(async () => {
|
|
72
147
|
try {
|
|
@@ -74,161 +149,139 @@ window.__ModuleLoader__.load({
|
|
|
74
149
|
setSt(s)
|
|
75
150
|
setView(s.config)
|
|
76
151
|
} catch (e) {
|
|
77
|
-
|
|
78
|
-
setMsg('读不到配置:' + (e && e.message ? e.message : String(e)))
|
|
152
|
+
setMsg({ err: true, text: '读不到配置:' + (e && e.message ? e.message : String(e)) })
|
|
79
153
|
}
|
|
80
154
|
}, [])
|
|
81
155
|
|
|
82
156
|
React.useEffect(() => { load() }, [load])
|
|
83
157
|
|
|
84
158
|
const save = async (patch) => {
|
|
85
|
-
setBusy('save')
|
|
86
|
-
setMsg('')
|
|
87
|
-
setBad(false)
|
|
159
|
+
setBusy('save'); setMsg(null)
|
|
88
160
|
try {
|
|
89
161
|
const r = await jpost('/config', patch)
|
|
90
162
|
setView(r.config)
|
|
91
163
|
setSt((old) => (old ? { ...old, config: r.config, promptActive: r.config.enabled && r.config.prompt } : old))
|
|
92
|
-
setMsg('已保存,立刻生效。')
|
|
164
|
+
setMsg({ ok: true, text: '已保存,立刻生效。' })
|
|
93
165
|
} catch (e) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
} finally {
|
|
97
|
-
setBusy('')
|
|
98
|
-
}
|
|
166
|
+
setMsg({ err: true, text: '保存失败:' + (e && e.message ? e.message : String(e)) })
|
|
167
|
+
} finally { setBusy('') }
|
|
99
168
|
}
|
|
100
169
|
|
|
101
170
|
const preview = async () => {
|
|
102
|
-
setBusy('preview')
|
|
103
|
-
setMsg('')
|
|
104
|
-
setBad(false)
|
|
171
|
+
setBusy('preview'); setMsg(null)
|
|
105
172
|
try {
|
|
106
|
-
const r = await jpost('/preview', { text })
|
|
173
|
+
const r = await jpost('/preview', { text, full })
|
|
107
174
|
if (r.ok) setOut(r.text)
|
|
108
|
-
else {
|
|
175
|
+
else setMsg({ err: true, text: r.error || '没查出结果' })
|
|
109
176
|
} catch (e) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
} finally {
|
|
113
|
-
setBusy('')
|
|
114
|
-
}
|
|
177
|
+
setMsg({ err: true, text: '查不了:' + (e && e.message ? e.message : String(e)) })
|
|
178
|
+
} finally { setBusy('') }
|
|
115
179
|
}
|
|
116
180
|
|
|
181
|
+
const num = (key) => h('input', {
|
|
182
|
+
'data-bg-num': '', type: 'number', step: '0.1', min: '0',
|
|
183
|
+
value: view[key], disabled: busy === 'save',
|
|
184
|
+
onChange: (e) => setView({ ...view, [key]: e.target.value === '' ? '' : Number(e.target.value) }),
|
|
185
|
+
onBlur: () => { if (view[key] !== st.config[key]) save({ [key]: view[key] }) },
|
|
186
|
+
})
|
|
187
|
+
|
|
117
188
|
if (!view) {
|
|
118
|
-
return h('div', { 'data-bg
|
|
119
|
-
h('div', { 'data-bg-
|
|
189
|
+
return h('div', { 'data-bg': '' },
|
|
190
|
+
h('div', { 'data-bg-head': '' },
|
|
191
|
+
h('div', { 'data-bg-title': '' }, '八股检测')),
|
|
192
|
+
msg ? h('div', { 'data-bg-msg': '', 'data-err': msg.err ? '' : undefined }, msg.text) : null,
|
|
193
|
+
h('div', { 'data-bg-skel': '' }),
|
|
194
|
+
h('div', { 'data-bg-skel': '' }))
|
|
120
195
|
}
|
|
121
196
|
|
|
122
197
|
const on = view.enabled !== false
|
|
123
198
|
|
|
124
|
-
return h('div', { 'data-bg
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
h('button', {
|
|
151
|
-
'data-bg-sw': '',
|
|
152
|
-
'data-on': view.prompt !== false ? '' : undefined,
|
|
153
|
-
disabled: busy === 'save',
|
|
154
|
-
'aria-label': '开关系统提示那一节',
|
|
155
|
-
onClick: () => save({ prompt: view.prompt === false }),
|
|
156
|
-
}),
|
|
157
|
-
h('div', { 'data-bg-grow': '' },
|
|
158
|
-
h('div', { style: { fontSize: '13px' } },
|
|
159
|
-
view.prompt !== false ? '系统提示那一节:开' : '系统提示那一节:关'),
|
|
160
|
-
h('div', { 'data-bg-note': '' },
|
|
161
|
-
'关掉只留工具,不往提示里塞「说话的念头」。有些人只想手动查,不想被改说话习惯。')))),
|
|
199
|
+
return h('div', { 'data-bg': '' },
|
|
200
|
+
|
|
201
|
+
// ── 头部 ─────────────────────────────
|
|
202
|
+
h('div', { 'data-bg-head': '' },
|
|
203
|
+
h('div', { 'data-bg-title': '' }, '八股检测'),
|
|
204
|
+
h('div', { 'data-bg-sub': '' },
|
|
205
|
+
'一句话换个人说还成不成立?成立,就是八股。只读不改写,给坐标不给成品。')),
|
|
206
|
+
|
|
207
|
+
// ── 开关 ─────────────────────────────
|
|
208
|
+
h('div', null,
|
|
209
|
+
h('div', { 'data-bg-h': '' }, '开关'),
|
|
210
|
+
h('div', { 'data-bg-card': '' },
|
|
211
|
+
h(Row, {
|
|
212
|
+
label: on ? '已开启' : '已关闭',
|
|
213
|
+
note: on
|
|
214
|
+
? (st.promptActive ? '提示那一节挂上了,现在生效。' : '已开启,但提示那一节没挂上。')
|
|
215
|
+
: '关掉后整节从系统提示里撤掉,两个工具还在。',
|
|
216
|
+
}, h(Switch, { on, label: '总开关', disabled: busy === 'save', onChange: () => save({ enabled: !on }) })),
|
|
217
|
+
|
|
218
|
+
h(Row, {
|
|
219
|
+
label: view.prompt !== false ? '提示那一节:开' : '提示那一节:关',
|
|
220
|
+
note: '关掉只留工具,不往提示里塞话。只想手动查的人用这个。',
|
|
221
|
+
}, h(Switch, {
|
|
222
|
+
on: view.prompt !== false, label: '提示节', disabled: busy === 'save' || !on,
|
|
223
|
+
onChange: () => save({ prompt: view.prompt === false }),
|
|
224
|
+
})))),
|
|
162
225
|
|
|
163
|
-
|
|
226
|
+
// ── 阈值 ─────────────────────────────
|
|
227
|
+
h('div', null,
|
|
164
228
|
h('div', { 'data-bg-h': '' }, '阈值'),
|
|
165
|
-
h('div', { 'data-bg-
|
|
166
|
-
h(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
h('
|
|
182
|
-
'
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
value: view.concreteFloor,
|
|
196
|
-
disabled: busy === 'save',
|
|
197
|
-
onChange: (e) => setView({ ...view, concreteFloor: e.target.value === '' ? '' : Number(e.target.value) }),
|
|
198
|
-
onBlur: () => { if (view.concreteFloor !== st.config.concreteFloor) save({ concreteFloor: view.concreteFloor }) },
|
|
199
|
-
})),
|
|
200
|
-
|
|
201
|
-
h('div', { 'data-bg-row': '' },
|
|
202
|
-
h('button', {
|
|
203
|
-
'data-bg-btn': '',
|
|
204
|
-
disabled: busy === 'save',
|
|
205
|
-
onClick: () => save({
|
|
206
|
-
hedgeFloor: st.defaults.hedgeFloor,
|
|
207
|
-
structureTimes: st.defaults.structureTimes,
|
|
208
|
-
concreteFloor: st.defaults.concreteFloor,
|
|
209
|
-
}),
|
|
210
|
-
}, '恢复默认'))),
|
|
211
|
-
|
|
212
|
-
h('div', { 'data-bg-sec': '' },
|
|
229
|
+
h('div', { 'data-bg-card': '' },
|
|
230
|
+
h(Row, {
|
|
231
|
+
label: '留白词下限',
|
|
232
|
+
note: '每千字几个「好像 / 应该 / 大概」才算够。低于这个就报句句在下断言。',
|
|
233
|
+
}, num('hedgeFloor')),
|
|
234
|
+
|
|
235
|
+
h(Row, {
|
|
236
|
+
label: '结构腔倍数',
|
|
237
|
+
note: '超过同文体基线的几倍才报。调大更宽容。',
|
|
238
|
+
}, num('structureTimes')),
|
|
239
|
+
|
|
240
|
+
h(Row, {
|
|
241
|
+
label: '具体物下限',
|
|
242
|
+
note: '每百字至少几个数字、时间、经历、原话、名字。',
|
|
243
|
+
}, num('concreteFloor')),
|
|
244
|
+
|
|
245
|
+
h('div', { 'data-bg-row': '' },
|
|
246
|
+
h('div', { 'data-bg-grow': '' },
|
|
247
|
+
h('div', { 'data-bg-note': '' }, '恢复研究给出的默认值。')),
|
|
248
|
+
h('button', {
|
|
249
|
+
'data-bg-btn': '', disabled: busy === 'save',
|
|
250
|
+
onClick: () => save({
|
|
251
|
+
hedgeFloor: st.defaults.hedgeFloor,
|
|
252
|
+
structureTimes: st.defaults.structureTimes,
|
|
253
|
+
concreteFloor: st.defaults.concreteFloor,
|
|
254
|
+
}),
|
|
255
|
+
}, '恢复默认')))),
|
|
256
|
+
|
|
257
|
+
// ── 试一下 ───────────────────────────
|
|
258
|
+
h('div', null,
|
|
213
259
|
h('div', { 'data-bg-h': '' }, '试一下'),
|
|
214
|
-
h('
|
|
215
|
-
'
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
260
|
+
h('div', { 'data-bg-card': '' },
|
|
261
|
+
h('textarea', {
|
|
262
|
+
'data-bg-in': '', value: text, rows: 3,
|
|
263
|
+
placeholder: '粘一段话,短句也行。',
|
|
264
|
+
onChange: (e) => setText(e.target.value),
|
|
265
|
+
}),
|
|
266
|
+
h('div', { 'data-bg-row': '' },
|
|
267
|
+
h('button', {
|
|
268
|
+
'data-bg-btn': '', 'data-primary': '',
|
|
269
|
+
disabled: busy === 'preview', onClick: preview,
|
|
270
|
+
}, busy === 'preview' ? '查着…' : '查一下'),
|
|
271
|
+
h('div', { 'data-bg-grow': '' },
|
|
272
|
+
h('div', { 'data-bg-note': '' }, full ? '完整报告' : '三行摘要')),
|
|
273
|
+
h(Switch, { on: full, label: '完整报告', disabled: false, onChange: () => setFull(!full) })),
|
|
274
|
+
out ? h('div', { 'data-bg-out': '' }, out) : null)),
|
|
275
|
+
|
|
276
|
+
// ── 状态 ─────────────────────────────
|
|
277
|
+
msg ? h('div', {
|
|
278
|
+
'data-bg-msg': '',
|
|
279
|
+
'data-err': msg.err ? '' : undefined,
|
|
280
|
+
'data-ok': msg.ok ? '' : undefined,
|
|
281
|
+
}, msg.text) : null,
|
|
282
|
+
|
|
283
|
+
// ── 脚注 ─────────────────────────────
|
|
284
|
+
h('div', { 'data-bg-foot': '' }, String(st.configFile || 'config.json')))
|
|
232
285
|
}
|
|
233
286
|
|
|
234
287
|
return {
|
|
@@ -241,7 +294,6 @@ window.__ModuleLoader__.load({
|
|
|
241
294
|
ctx.effect(() => () => style.remove(), 'dsh-bagu: 设置页样式')
|
|
242
295
|
|
|
243
296
|
const slots = (typeof ctx.get === 'function' ? ctx.get('slots') : undefined) || ctx.slots
|
|
244
|
-
// 宿主不保证 slots 上有 inject:拿到的可能是个空壳,先探一下再用
|
|
245
297
|
if (!slots || typeof slots.inject !== 'function' || typeof slots.register !== 'function') return
|
|
246
298
|
slots.inject('settings.section', () => slots.register(
|
|
247
299
|
{ name: 'settings.section', id: 'bagu', order: 35, label: '八股检测' },
|
package/dsh-plugin.json
CHANGED
package/lib/analyze.js
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
HEDGE_WORDS,
|
|
30
30
|
CONCRETE_MARKERS,
|
|
31
31
|
CONCRETE_WEIGHTS,
|
|
32
|
+
SYNONYM_GROUPS,
|
|
32
33
|
STRUCTURE_FRAMES,
|
|
33
34
|
REGISTERS,
|
|
34
35
|
HEDGE_BASELINE,
|
|
@@ -134,6 +135,25 @@ export function cluster(hits, width = 100) {
|
|
|
134
135
|
return { width, maxHits, maxDistinct, at };
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
/**
|
|
139
|
+
* 同义轮换:同一段里从同一组同义词挑了 ≥2 个。
|
|
140
|
+
*
|
|
141
|
+
* lieflat 实测 mtld δ +0.91,是全表第二强信号;真人会反复用同一个词。
|
|
142
|
+
* @returns {Array<string[]>} 每项是一组被轮换的词
|
|
143
|
+
*/
|
|
144
|
+
export function synonymRotation(text) {
|
|
145
|
+
const src = String(text ?? '');
|
|
146
|
+
const paras = src.split(/\n\s*\n|\n(?=[^\n]{0,20}[::])/).filter(Boolean);
|
|
147
|
+
const out = [];
|
|
148
|
+
for (const para of paras) {
|
|
149
|
+
for (const group of SYNONYM_GROUPS) {
|
|
150
|
+
const used = group.filter((w) => para.includes(w));
|
|
151
|
+
if (used.length >= 2) out.push(used);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
|
|
137
157
|
/**
|
|
138
158
|
* 主入口。
|
|
139
159
|
* @returns 结构化判断结果,不含任何改写建议的原句
|
|
@@ -173,6 +193,7 @@ export function analyze(input, opts = {}) {
|
|
|
173
193
|
for (const s of row.spans) flatHits.push({ id: row.id, name: row.name, at: s.at, span: s.text });
|
|
174
194
|
}
|
|
175
195
|
const cl = cluster(flatHits);
|
|
196
|
+
const synRot = synonymRotation(text);
|
|
176
197
|
|
|
177
198
|
// ── 判档 ─────────────────────────────────────
|
|
178
199
|
// 可替换度:六个信号,各算一分。用密度不用绝对数 —— 五十个字里出一个「意义」,
|
|
@@ -198,11 +219,41 @@ export function analyze(input, opts = {}) {
|
|
|
198
219
|
let band;
|
|
199
220
|
let bandLabel;
|
|
200
221
|
let bandNote;
|
|
222
|
+
|
|
223
|
+
// ── 短文本:绝对计数,不看密度 ────────────────────────
|
|
224
|
+
// 密度在短句上分母太小,一两个词就跨阈值。但「这个句式出现了一次」
|
|
225
|
+
// 本身就是信号,跟字数无关。权重按 lieflat 的 δ 排:
|
|
226
|
+
// 同义轮换 +0.91 > 不是A而是B +0.88 > 顿号并列 +0.56 > 破折号 分模型
|
|
227
|
+
// 分数用 sloplint 的写法:100 × 权重 / (权重 + 6),短句和长文同一把尺。
|
|
228
|
+
const shortWeight =
|
|
229
|
+
(synRot.length >= 2 ? 3 : synRot.length === 1 ? 2 : 0) +
|
|
230
|
+
(aiWordHits.length >= 2 ? 3 : aiWordHits.length === 1 ? 2 : 0) +
|
|
231
|
+
(structures.find((x) => x.id === 'negation') ? 3 : 0) +
|
|
232
|
+
(structures.find((x) => x.id === 'triple') ? 2 : 0) +
|
|
233
|
+
(structures.find((x) => x.id === 'emdash') ? 1 : 0) +
|
|
234
|
+
(abstractPer100 + evalPer100 >= 4 ? 2 : 0);
|
|
235
|
+
const shortScore = Math.round((100 * shortWeight) / (shortWeight + 6));
|
|
236
|
+
|
|
237
|
+
const hasNegationFrame = structures.some((x) => x.id === 'negation');
|
|
238
|
+
|
|
201
239
|
if (chars < 60) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
240
|
+
if (hasNegationFrame && shortScore >= 40) {
|
|
241
|
+
band = 'heavy';
|
|
242
|
+
bandLabel = '可疑';
|
|
243
|
+
bandNote = '「不是A而是B」是全表最强的单句信号(δ+0.88)。这么短的句子用上,基本不是随口说的。';
|
|
244
|
+
} else if (shortScore >= 55) {
|
|
245
|
+
band = 'heavy';
|
|
246
|
+
bandLabel = '可疑';
|
|
247
|
+
bandNote = '这么短就有这些,不太像随口说的。';
|
|
248
|
+
} else if (shortScore >= 30) {
|
|
249
|
+
band = 'mid';
|
|
250
|
+
bandLabel = '有点';
|
|
251
|
+
bandNote = '够短,但能指认的东西一个没有。';
|
|
252
|
+
} else {
|
|
253
|
+
band = 'low';
|
|
254
|
+
bandLabel = '正常';
|
|
255
|
+
bandNote = '没扫到。';
|
|
256
|
+
}
|
|
206
257
|
} else if (replaceable >= 4) {
|
|
207
258
|
band = 'heavy';
|
|
208
259
|
bandLabel = '换谁都行';
|
|
@@ -268,6 +319,7 @@ export function analyze(input, opts = {}) {
|
|
|
268
319
|
hedgePer1k,
|
|
269
320
|
structurePer1k,
|
|
270
321
|
overTimes,
|
|
322
|
+
shortScore,
|
|
271
323
|
clusterDistinct: cl.maxDistinct,
|
|
272
324
|
clusterMax: cl.maxHits,
|
|
273
325
|
},
|
|
@@ -283,6 +335,8 @@ export function analyze(input, opts = {}) {
|
|
|
283
335
|
},
|
|
284
336
|
asks,
|
|
285
337
|
baselineHedge: HEDGE_BASELINE,
|
|
338
|
+
synonyms: synRot,
|
|
339
|
+
duplicateSynonym: synRot,
|
|
286
340
|
thresholds: { hedgeFloor, structureTimes, concreteFloor },
|
|
287
341
|
blind: '这一步只认字面和句式。同一件事换个说法又说一遍、每段都收个小结论、通篇一个调子 —— 这些它看不见,得你自己读。',
|
|
288
342
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,57 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* dsh-bagu · 宿主半侧
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* 1. 往系统提示里挂一节「说什么」,讲的是念头不是词表(可在设置页关掉)
|
|
6
|
-
* 2. 挂两个只读工具:bagu_check、bagu_ask
|
|
7
|
-
* 3. 开 /api/bagu,给设置页用
|
|
4
|
+
* 三件事:挂一节提示、挂两个只读工具、开 /api/bagu。
|
|
8
5
|
*
|
|
9
|
-
*
|
|
6
|
+
* 省 token 是这个插件的设计约束,不是优化项:
|
|
7
|
+
* - 提示词压到 150 字以内,每次会话都要烧
|
|
8
|
+
* - 工具描述压到 60 字以内,每次调用都在上下文里
|
|
9
|
+
* - 默认输出三行以内;要看细节传 full: true
|
|
10
|
+
*
|
|
11
|
+
* 所有判断都在本地正则里做完,不调模型 —— 这是零 token 成本的那一半。
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
|
-
import { analyze
|
|
14
|
+
import { analyze } from './analyze.js';
|
|
15
|
+
import { render, renderBrief } from './render.js';
|
|
13
16
|
import { readConfig, writeConfig, CONFIG_FILE, DEFAULTS } from './config.js';
|
|
14
17
|
|
|
15
18
|
export const name = 'dsh-bagu';
|
|
16
19
|
|
|
17
|
-
export { analyze, render };
|
|
20
|
+
export { analyze, render, renderBrief };
|
|
18
21
|
|
|
19
|
-
/** 当前生效的配置。设置页改了立刻换掉。 */
|
|
20
22
|
let live = readConfig();
|
|
21
|
-
|
|
22
|
-
/** 已挂上去的 prompt 节,改了要先撤再挂。 */
|
|
23
23
|
const syncers = new Set();
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
开口前先问的不是「这么答对不对」,是「我要说什么」。
|
|
28
|
-
|
|
29
|
-
两者差得远。前一个问题让你去猜对方想听什么,后一个问题让你去想自己要给什么。
|
|
30
|
-
|
|
31
|
-
一句话换个人说,还成不成立?成立,就是八股。谁都能说的话,慢慢就没人想看了。
|
|
32
|
-
问题不在礼貌,在可替换。
|
|
33
|
-
|
|
34
|
-
几个具体的:
|
|
35
|
-
|
|
36
|
-
- **别急着认错。**对方只是问一句,不一定是在说你错。对就说是,别为了顺着改口,把对的也改错了。
|
|
37
|
-
- **留一处不确定。**一个「好像 / 应该 / 大概」都没有的段落,是在下断言,不是在说话。
|
|
38
|
-
- **具体压过评价。**「挺好的」谁都能说;「骨架在推所以有点飘」只有看过的人才说得出。
|
|
39
|
-
- **篇幅别总一样齐。**每段都三句、每句都差不多长,整齐本身就是痕迹。
|
|
40
|
-
- **说七分。**话别一次说完。留点让人问。
|
|
41
|
-
|
|
42
|
-
不硬塞语气词,不为了显得像人而加口癖。加进去的是另一种假。`;
|
|
43
|
-
|
|
44
|
-
const TOOL_CHECK = `查一段话有多「可替换」。给几个分开的指标和一个判档,不给单一总分,也不自动改写。
|
|
25
|
+
/** 150 字。每次会话注入,多一个字都是白烧。 */
|
|
26
|
+
const PROMPT = `一句话换个人说还成不成立?成立,就是八股。
|
|
45
27
|
|
|
46
|
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
- 结构腔(不是X而是Y 等),以及同一百字里几种句式扎堆
|
|
28
|
+
- 别急着认错。对方问一句,不等于你在说错。
|
|
29
|
+
- 留一处不确定。全篇一个「大概」都没有,是在下断言。
|
|
30
|
+
- 具体压过评价。「骨架在推所以有点飘」只有看过的人才说得出。
|
|
31
|
+
- 别每句一样长。整齐本身就是痕迹。`;
|
|
51
32
|
|
|
52
|
-
|
|
33
|
+
/** 60 字。 */
|
|
34
|
+
const TOOL_CHECK = `查一段话有多可替换:具体物、抽象词、留白、同义轮换、结构腔。只报不给改。默认三行,full 给详细报告。`;
|
|
53
35
|
|
|
54
|
-
const TOOL_ASK =
|
|
36
|
+
const TOOL_ASK = `只要问句,不要结论。`;
|
|
55
37
|
|
|
56
38
|
function toolOutput() {
|
|
57
39
|
return {
|
|
@@ -62,7 +44,6 @@ function toolOutput() {
|
|
|
62
44
|
properties: {
|
|
63
45
|
ok: { type: 'boolean' },
|
|
64
46
|
text: { type: 'string' },
|
|
65
|
-
detail: { type: 'object' },
|
|
66
47
|
},
|
|
67
48
|
},
|
|
68
49
|
render: (_args, value) => [{ type: 'text', text: String(value?.text ?? '') }],
|
|
@@ -77,7 +58,6 @@ function thresholdsOf(cfg) {
|
|
|
77
58
|
};
|
|
78
59
|
}
|
|
79
60
|
|
|
80
|
-
/** 配置变了以后,让已经挂上的 prompt 节跟着换。 */
|
|
81
61
|
function applyLive(next) {
|
|
82
62
|
live = next;
|
|
83
63
|
for (const sync of syncers) {
|
|
@@ -105,7 +85,6 @@ function readBody(req) {
|
|
|
105
85
|
}
|
|
106
86
|
|
|
107
87
|
export function apply(root, config = {}) {
|
|
108
|
-
// cordis.patch.yml 里的初始值,只在 config.json 还没写过时作底
|
|
109
88
|
live = readConfig();
|
|
110
89
|
if (config && typeof config === 'object') {
|
|
111
90
|
for (const k of Object.keys(DEFAULTS)) {
|
|
@@ -139,16 +118,17 @@ export function apply(root, config = {}) {
|
|
|
139
118
|
parameters: {
|
|
140
119
|
type: 'object',
|
|
141
120
|
properties: {
|
|
142
|
-
text: { type: 'string', description: '
|
|
121
|
+
text: { type: 'string', description: '整段话。' },
|
|
122
|
+
full: { type: 'boolean', description: 'true 给详细报告。默认三行。' },
|
|
143
123
|
},
|
|
144
124
|
required: ['text'],
|
|
145
125
|
},
|
|
146
126
|
output: toolOutput(),
|
|
147
127
|
execute: async (args) => {
|
|
148
128
|
const src = String(args?.text ?? '');
|
|
149
|
-
if (!src.trim()) return { ok: false, text: '
|
|
129
|
+
if (!src.trim()) return { ok: false, text: '没有文字。' };
|
|
150
130
|
const r = analyze(src, thresholdsOf(live));
|
|
151
|
-
return { ok: true, text: render(r
|
|
131
|
+
return { ok: true, text: render(r, { full: args?.full === true }) };
|
|
152
132
|
},
|
|
153
133
|
});
|
|
154
134
|
|
|
@@ -158,17 +138,18 @@ export function apply(root, config = {}) {
|
|
|
158
138
|
parameters: {
|
|
159
139
|
type: 'object',
|
|
160
140
|
properties: {
|
|
161
|
-
text: { type: 'string', description: '
|
|
141
|
+
text: { type: 'string', description: '整段话。' },
|
|
142
|
+
n: { type: 'number', description: '几条,默认 3,最多 6。' },
|
|
162
143
|
},
|
|
163
144
|
required: ['text'],
|
|
164
145
|
},
|
|
165
146
|
output: toolOutput(),
|
|
166
147
|
execute: async (args) => {
|
|
167
148
|
const src = String(args?.text ?? '');
|
|
168
|
-
if (!src.trim()) return { ok: false, text: '
|
|
149
|
+
if (!src.trim()) return { ok: false, text: '没有文字。' };
|
|
169
150
|
const r = analyze(src, thresholdsOf(live));
|
|
170
|
-
const
|
|
171
|
-
return { ok: true, text,
|
|
151
|
+
const n = Math.min(6, Math.max(1, Number(args?.n) || 3));
|
|
152
|
+
return { ok: true, text: r.asks.slice(0, n).map((a, i) => `${i + 1}. ${a}`).join('\n') };
|
|
172
153
|
},
|
|
173
154
|
});
|
|
174
155
|
});
|
|
@@ -200,7 +181,7 @@ export function apply(root, config = {}) {
|
|
|
200
181
|
const src = String(body?.text ?? '');
|
|
201
182
|
if (!src.trim()) return sendJson(res, 200, { ok: false, error: '没有文字' });
|
|
202
183
|
const r = analyze(src, thresholdsOf(live));
|
|
203
|
-
return sendJson(res, 200, { ok: true, text: render(r
|
|
184
|
+
return sendJson(res, 200, { ok: true, text: render(r, { full: body?.full === true }), band: r.band });
|
|
204
185
|
}
|
|
205
186
|
|
|
206
187
|
return sendJson(res, 404, { ok: false, error: `unknown ${req.method} ${path}` });
|
|
@@ -214,10 +195,10 @@ export function apply(root, config = {}) {
|
|
|
214
195
|
path: '/api/bagu',
|
|
215
196
|
handler: (req, res) => {
|
|
216
197
|
Promise.resolve(handler(req, res)).catch((e) => {
|
|
217
|
-
try { sendJson(res, 500, { ok: false, error: e?.message ?? String(e) }) } catch { /*
|
|
198
|
+
try { sendJson(res, 500, { ok: false, error: e?.message ?? String(e) }) } catch { /* 已走 */ }
|
|
218
199
|
});
|
|
219
200
|
},
|
|
220
201
|
}), 'dsh-bagu: /api/bagu');
|
|
221
|
-
} catch { /* headless
|
|
202
|
+
} catch { /* headless 没有 webServer 正常 */ }
|
|
222
203
|
});
|
|
223
204
|
}
|
package/lib/lexicon.js
CHANGED
|
@@ -167,8 +167,27 @@ export const STRUCTURE_FRAMES = [
|
|
|
167
167
|
{ id: 'firstThen', name: '先…再…', per1k: 0.01, re: /先[^,。\n]{1,10}再/g },
|
|
168
168
|
{ id: 'triple', name: '三段并列', per1k: 0.23, re: /[^,。、\s]{2,8}、[^,。、\s]{2,8}、[^,。、\s]{2,8}/g },
|
|
169
169
|
{ id: 'emdash', name: '破折号', per1k: 0.22, re: /——+|—/g },
|
|
170
|
-
{ id: 'roadmap', name: '首先/其次/综上', per1k: 0.5, re: /(?:首先|其次|综上所述|总而言之)/g },
|
|
171
170
|
{ id: 'yue', name: '越…越', per1k: 0.16, re: /越[^,。\n]{1,8}越/g },
|
|
171
|
+
// 「首先/其次/综上」曾在这里,per1k 0.5。已移出:
|
|
172
|
+
// lieflat 520 万字配对复测 δ +0.02,对当代模型彻底失效(人类和 AI 用的一样多)。
|
|
173
|
+
// 还留在 AI_WORDS 里当提示,不进判档。
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 同义词轮换组。同一段里从一组里挑两个以上,就是在「不敢重复」。
|
|
178
|
+
*
|
|
179
|
+
* lieflat 实测:词汇多样性 mtld δ +0.91 / mattr +0.75,是全表第二强的信号。
|
|
180
|
+
* 真人会反复用同一个词,AI 换着说。
|
|
181
|
+
*/
|
|
182
|
+
export const SYNONYM_GROUPS = [
|
|
183
|
+
['使用', '采用', '运用', '利用', '借助'],
|
|
184
|
+
['方法', '方式', '途径', '路径', '做法'],
|
|
185
|
+
['提升', '提高', '增强', '强化', '优化'],
|
|
186
|
+
['显示', '表明', '揭示', '反映', '说明'],
|
|
187
|
+
['重要', '关键', '核心', '至关重要'],
|
|
188
|
+
['问题', '难题', '挑战', '困境', '痛点'],
|
|
189
|
+
['帮助', '协助', '助力', '支持'],
|
|
190
|
+
['显著', '大幅', '明显', '卓有成效'],
|
|
172
191
|
];
|
|
173
192
|
|
|
174
193
|
/** 文体基线与判定词,按真人评论语料实测。 */
|
package/lib/render.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 输出渲染。默认紧凑,full 才给完整报告。
|
|
3
|
+
*
|
|
4
|
+
* 设计约束:这是要进上下文的文本,每一个字都在烧 token。
|
|
5
|
+
* 默认输出压到三行以内;需要细节的人自己传 full。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const BAND = {
|
|
9
|
+
heavy: '可疑',
|
|
10
|
+
mid: '有点',
|
|
11
|
+
low: '正常',
|
|
12
|
+
'too-short': '太短',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function pct(n) {
|
|
16
|
+
return Number.isFinite(n) ? n : 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {object} r analyze() 的结果
|
|
21
|
+
* @param {{full?: boolean}} opts
|
|
22
|
+
*/
|
|
23
|
+
export function render(r, opts = {}) {
|
|
24
|
+
const full = opts.full === true;
|
|
25
|
+
|
|
26
|
+
// 三行紧凑模式
|
|
27
|
+
if (!full) {
|
|
28
|
+
const head = BAND[r.band] || r.bandLabel;
|
|
29
|
+
const nums = `具体${pct(r.scores.concretePer100)} 抽象${r.scores.abstract} ` +
|
|
30
|
+
`评价${r.scores.evaluation} 留白${pct(r.scores.hedgePer1k)} 结构${pct(r.scores.structurePer1k)}/千`;
|
|
31
|
+
const hits = [];
|
|
32
|
+
for (const row of r.hits.structures) {
|
|
33
|
+
for (const s of row.spans.slice(0, 2)) hits.push(`「${s.text}」`);
|
|
34
|
+
if (row.spans.length > 2) hits[hits.length - 1] += `×${row.spans.length}`;
|
|
35
|
+
}
|
|
36
|
+
for (const h of r.hits.aiWords.slice(0, 3)) hits.push(h.word);
|
|
37
|
+
if (r.synonyms && r.synonyms.length) hits.push(`同义轮换${r.synonyms.length}组`);
|
|
38
|
+
|
|
39
|
+
const lines = [head];
|
|
40
|
+
if (nums.length > 4) lines[0] += ` ${nums}`;
|
|
41
|
+
if (hits.length) lines.push('· ' + hits.slice(0, 6).join(' '));
|
|
42
|
+
if (r.asks && r.asks.length) lines.push('问 ' + r.asks[0]);
|
|
43
|
+
return lines.join('\n');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 完整模式(原样保留详细版,供人看)
|
|
47
|
+
const L = [];
|
|
48
|
+
L.push(`[判断] ${r.bandLabel} · ${r.bandNote}`);
|
|
49
|
+
L.push(`[文体] ${r.registerLabel} · 真人同文体结构腔基线 ${r.baseline}/千字`);
|
|
50
|
+
L.push(
|
|
51
|
+
`[具体] 每百字 ${r.scores.concretePer100} 个 · 抽象词 ${r.scores.abstract} · 评价词 ${r.scores.evaluation}`
|
|
52
|
+
);
|
|
53
|
+
L.push(
|
|
54
|
+
`[留白] ${r.scores.hedges} 个(${r.scores.hedgePer1k}/千字,真人约 ${r.baselineHedge})` +
|
|
55
|
+
(r.scores.hedgePer1k < (r.thresholds?.hedgeFloor ?? 0.2) ? ' —— 句句在下断言' : '')
|
|
56
|
+
);
|
|
57
|
+
L.push(
|
|
58
|
+
`[结构腔] ${r.scores.structurePer1k}/千字 · 基线的 ${r.scores.overTimes} 倍 · ` +
|
|
59
|
+
`同百字最多 ${r.scores.clusterDistinct} 种句式`
|
|
60
|
+
);
|
|
61
|
+
if (r.synonyms && r.synonyms.length) {
|
|
62
|
+
L.push(`[同义轮换] ${r.synonyms.map((g) => g.join('/')).join(' · ')}`);
|
|
63
|
+
}
|
|
64
|
+
if (r.hits.structures.length) {
|
|
65
|
+
L.push('[逐处]');
|
|
66
|
+
for (const row of r.hits.structures) {
|
|
67
|
+
L.push(` · ${row.name} ×${row.count}:${row.spans.map((s) => `「${s.text}」`).join(' ')}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
L.push('[要你自己答]');
|
|
71
|
+
for (const a of r.asks) L.push(` - ${a}`);
|
|
72
|
+
L.push(`[看不见] ${r.blind}`);
|
|
73
|
+
return L.join('\n');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 只要一句结论,最省。 */
|
|
77
|
+
export function renderBrief(r) {
|
|
78
|
+
const head = BAND[r.band] || r.bandLabel;
|
|
79
|
+
const bits = [];
|
|
80
|
+
if (r.hits.structures.length) bits.push(r.hits.structures[0].name);
|
|
81
|
+
if (r.hits.aiWords.length) bits.push(r.hits.aiWords[0].word);
|
|
82
|
+
return bits.length ? `${head}:${bits.join('、')}` : head;
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-bagu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "八股检测:判断一句话是不是谁都能说。AI 味不是礼貌问题,是可替换问题。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -66,5 +66,8 @@
|
|
|
66
66
|
"AI味",
|
|
67
67
|
"八股",
|
|
68
68
|
"写作"
|
|
69
|
-
]
|
|
69
|
+
],
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"happy-dom": "^21.0.4"
|
|
72
|
+
}
|
|
70
73
|
}
|
package/test/analyze.test.mjs
CHANGED
|
@@ -12,9 +12,14 @@ test('典型八股判成 heavy', () => {
|
|
|
12
12
|
'本次修改已完成。首先调整了章节结构,其次新增了规则条款,最后优化了可读性。' +
|
|
13
13
|
'综上所述,这次改动具有重要意义,希望对你有帮助。'
|
|
14
14
|
);
|
|
15
|
-
assert.
|
|
16
|
-
assert.ok(r.scores.aiWords >= 1);
|
|
17
|
-
|
|
15
|
+
assert.ok(r.band === 'heavy' || r.band === 'mid', '实际 ' + r.band);
|
|
16
|
+
assert.ok(r.scores.aiWords >= 1, '该认出「综上所述」这类词');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('「首先/其次」单独不再算结构腔(lieflat δ+0.02 失效)', () => {
|
|
20
|
+
const r = analyze('首先备份,其次改配置,最后重启。数据库密码记得先换掉,不然白改。');
|
|
21
|
+
const hasRoadmap = r.hits.structures.some((x) => x.id === 'roadmap');
|
|
22
|
+
assert.equal(hasRoadmap, false, 'roadmap 不该再出现在结构腔里');
|
|
18
23
|
});
|
|
19
24
|
|
|
20
25
|
test('具体的现场描述判成 low', () => {
|
|
@@ -132,10 +137,16 @@ test('#1.4 具体物充足时往回减一格', () => {
|
|
|
132
137
|
`具体的那段不该比空话更可疑: rich=${rich.scores.replaceable} empty=${empty.scores.replaceable}`);
|
|
133
138
|
});
|
|
134
139
|
|
|
135
|
-
test('
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
assert.
|
|
140
|
+
test('短句走绝对计数,不看密度', () => {
|
|
141
|
+
const ai = analyze('这不是技术问题,而是认知问题。');
|
|
142
|
+
const human = analyze('卖卡卖完了随便写了');
|
|
143
|
+
assert.equal(ai.band, 'heavy', 'AI 对举应判可疑,实际 ' + ai.band);
|
|
144
|
+
assert.equal(human.band, 'low', '真人短评应判正常,实际 ' + human.band);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('短句:同义轮换能被抓到', () => {
|
|
148
|
+
const r = analyze('我们使用了新方法,采用了更好的方式,通过提升效率来优化流程。');
|
|
149
|
+
assert.ok(r.synonyms.length >= 2, '应抓到多组轮换,实际 ' + JSON.stringify(r.synonyms));
|
|
139
150
|
});
|
|
140
151
|
|
|
141
152
|
test('#1.8 六十字以上照常判档', () => {
|
package/test/client.test.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import vm from 'node:vm'
|
|
|
8
8
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
9
9
|
const code = readFileSync(join(here, '..', 'client.js'), 'utf8')
|
|
10
10
|
|
|
11
|
-
/**
|
|
11
|
+
/** 假沙箱:document + React + __ModuleLoader__ 都是假的。 */
|
|
12
12
|
function boot() {
|
|
13
13
|
const loaded = []
|
|
14
14
|
const styles = []
|
|
@@ -17,7 +17,7 @@ function boot() {
|
|
|
17
17
|
createElement: () => ({ setAttribute() {}, remove() {}, textContent: '' }),
|
|
18
18
|
}
|
|
19
19
|
const React = {
|
|
20
|
-
createElement: (type, props, ...kids) => ({ type, props, kids }),
|
|
20
|
+
createElement: (type, props, ...kids) => ({ type, props: props || {}, kids }),
|
|
21
21
|
useState: (v) => [v, () => {}],
|
|
22
22
|
useRef: (v) => ({ current: v }),
|
|
23
23
|
useCallback: (f) => f,
|
|
@@ -34,41 +34,32 @@ function boot() {
|
|
|
34
34
|
return { loaded, styles, React, document }
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
test('
|
|
37
|
+
test('自注册:id 等于包名', () => {
|
|
38
38
|
const { loaded } = boot()
|
|
39
|
-
assert.equal(loaded.length, 1
|
|
39
|
+
assert.equal(loaded.length, 1)
|
|
40
40
|
assert.equal(loaded[0].id, 'dsh-bagu')
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
test('有 factory,且是函数', () => {
|
|
44
|
-
const { loaded } = boot()
|
|
45
|
-
assert.equal(typeof loaded[0].factory, 'function')
|
|
46
|
-
})
|
|
47
|
-
|
|
48
43
|
test('factory 返回 inject + apply', () => {
|
|
49
44
|
const { loaded, React } = boot()
|
|
50
|
-
const def = loaded[0].factory((
|
|
51
|
-
if (m === 'react') return React
|
|
52
|
-
throw new Error('unexpected require: ' + m)
|
|
53
|
-
})
|
|
54
|
-
// vm 沙箱里的数组原型和外面不同,逐项比
|
|
45
|
+
const def = loaded[0].factory(() => React)
|
|
55
46
|
assert.equal(Array.from(def.inject).join(','), 'slots')
|
|
56
47
|
assert.equal(typeof def.apply, 'function')
|
|
57
48
|
})
|
|
58
49
|
|
|
59
|
-
test('apply
|
|
50
|
+
test('apply 注入 CSS 并注册 settings.section', () => {
|
|
60
51
|
const { loaded, React, styles } = boot()
|
|
61
52
|
const def = loaded[0].factory(() => React)
|
|
62
53
|
const registered = []
|
|
63
54
|
const ctx = {
|
|
64
55
|
get: () => ({
|
|
65
|
-
inject: (
|
|
56
|
+
inject: (_s, fn) => fn(),
|
|
66
57
|
register: (meta, fn) => { registered.push({ meta, fn }); return () => {} },
|
|
67
58
|
}),
|
|
68
59
|
effect: (fn) => fn,
|
|
69
60
|
}
|
|
70
61
|
def.apply(ctx)
|
|
71
|
-
assert.equal(styles.length, 1
|
|
62
|
+
assert.equal(styles.length, 1)
|
|
72
63
|
assert.equal(registered.length, 1)
|
|
73
64
|
assert.equal(registered[0].meta.name, 'settings.section')
|
|
74
65
|
assert.equal(registered[0].meta.id, 'bagu')
|
|
@@ -80,10 +71,36 @@ test('没有 slots 时不炸', () => {
|
|
|
80
71
|
const def = loaded[0].factory(() => React)
|
|
81
72
|
const ctx = { get: () => ({}), effect: (fn) => fn }
|
|
82
73
|
assert.doesNotThrow(() => def.apply(ctx))
|
|
83
|
-
assert.equal(styles.length, 1
|
|
74
|
+
assert.equal(styles.length, 1)
|
|
84
75
|
})
|
|
85
76
|
|
|
86
|
-
test('
|
|
77
|
+
test('CSS 只引用真实存在的 --dsw-alias-* 变量', () => {
|
|
78
|
+
const { loaded, React } = boot()
|
|
79
|
+
const def = loaded[0].factory(() => React)
|
|
80
|
+
const ctx = { get: () => ({}), effect: (fn) => fn }
|
|
81
|
+
def.apply(ctx)
|
|
82
|
+
// 从 dsh-m 的 client bundle 里核对过的可用变量
|
|
83
|
+
const KNOWN = new Set([
|
|
84
|
+
'--dsw-alias-bg-base', '--dsw-alias-bg-elevated', '--dsw-alias-bg-hover',
|
|
85
|
+
'--dsw-alias-fill-secondary', '--dsw-alias-interactive-bg-hover',
|
|
86
|
+
'--dsw-alias-interactive-bg-selected', '--dsw-alias-border-l',
|
|
87
|
+
'--dsw-alias-border-default', '--dsw-alias-label-primary',
|
|
88
|
+
'--dsw-alias-label-secondary', '--dsw-alias-label-tertiary',
|
|
89
|
+
'--dsw-alias-label-caption', '--dsw-alias-label-dimmed',
|
|
90
|
+
'--dsw-alias-state-business-primary', '--dsw-alias-state-business-tertiary',
|
|
91
|
+
'--dsw-alias-state-error-primary', '--dsw-alias-state-error-secondary',
|
|
92
|
+
])
|
|
93
|
+
const used = [...code.matchAll(/var\((--dsw-alias-[a-z-]+)/g)].map((m) => m[1])
|
|
94
|
+
const unknown = [...new Set(used)].filter((v) => !KNOWN.has(v))
|
|
95
|
+
assert.deepEqual(unknown, [], '用到了不存在的变量: ' + unknown.join(', '))
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('CSS 每个 var() 都有回退值', () => {
|
|
99
|
+
const bad = [...code.matchAll(/var\((--[a-z-]+)\)/g)].map((m) => m[1])
|
|
100
|
+
assert.deepEqual(bad, [], '缺回退值: ' + bad.join(', '))
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('槽里渲染的是 Panel', () => {
|
|
87
104
|
const { loaded, React } = boot()
|
|
88
105
|
const def = loaded[0].factory(() => React)
|
|
89
106
|
const registered = []
|
|
@@ -96,16 +113,25 @@ test('register 的槽函数返回 Panel 元素', () => {
|
|
|
96
113
|
}
|
|
97
114
|
def.apply(ctx)
|
|
98
115
|
const el = registered[0].fn()
|
|
99
|
-
assert.equal(
|
|
100
|
-
assert.equal(el.type.name, 'Panel', '槽里渲染的应该是 Panel')
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
test('API 前缀是 /api/bagu', () => {
|
|
104
|
-
assert.ok(code.includes("'/api/bagu'"), 'client 必须打 /api/bagu')
|
|
116
|
+
assert.equal(el.type.name, 'Panel')
|
|
105
117
|
})
|
|
106
118
|
|
|
107
|
-
test('
|
|
119
|
+
test('接口是 /api/bagu 的三条', () => {
|
|
120
|
+
assert.ok(code.includes("'/api/bagu'"))
|
|
108
121
|
assert.ok(code.includes("jget('/status')"))
|
|
109
122
|
assert.ok(code.includes("jpost('/config'"))
|
|
110
123
|
assert.ok(code.includes("jpost('/preview'"))
|
|
111
124
|
})
|
|
125
|
+
|
|
126
|
+
test('preview 会带 full 开关', () => {
|
|
127
|
+
assert.ok(code.includes('{ text, full }'), 'preview 请求体里要带 full')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('没写死颜色值,只允许纯白', () => {
|
|
131
|
+
// DSH 的设计变量里没有反色文字(没有 --dsw-alias-label-inverse 之类),
|
|
132
|
+
// 所以蓝底按钮上的白字和开关圆点的白点只能写 #fff。白是唯一安全的中性色。
|
|
133
|
+
const stray = [...code.matchAll(/(?:^|[;\s])(?:color|background)\s*:\s*(#[0-9a-fA-F]{3,8})/g)]
|
|
134
|
+
.map((m) => m[1].toLowerCase())
|
|
135
|
+
.filter((hex) => hex !== '#fff' && hex !== '#ffffff')
|
|
136
|
+
assert.deepEqual(stray, [], '写死的颜色: ' + stray.join(', '))
|
|
137
|
+
})
|