dsh-bagu 0.2.0 → 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/client.js CHANGED
@@ -1,10 +1,12 @@
1
1
  /**
2
- * dsh-bagu —— 浏览器半端:设置页里的一页(「八股检测」)
2
+ * dsh-bagu —— 浏览器半端:设置页「八股检测」
3
3
  *
4
- * 约定(抄 dsh-fish-tone 的写法):
5
- * 1. client bundle 不是 ESM,是自注册脚本:window.__ModuleLoader__.load({ id, factory })
4
+ * 约定:
5
+ * 1. client bundle 不是 ESM,是自注册脚本
6
6
  * 2. 进「设置」靠 slots.inject('settings.section', ...)
7
- * 3. 宿主那边开 /api/bagu,这一页只做 fetch
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-page]{display:flex;flex-direction:column;gap:18px;padding:2px 2px 8px;max-width:640px;}
32
- [data-bg-sec]{display:flex;flex-direction:column;gap:8px;}
33
- [data-bg-h]{font-size:11px;font-weight:600;letter-spacing:.04em;color:var(--dsw-alias-label-tertiary,#9aa0a6);}
34
- [data-bg-row]{display:flex;align-items:center;gap:10px;}
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-note]{font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary,#9aa0a6);}
37
- [data-bg-note][data-warn]{color:#d97706;}
38
- [data-bg-sw]{flex:none;width:38px;height:22px;border-radius:11px;border:0;cursor:pointer;position:relative;
39
- background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.35));transition:background .15s;padding:0;}
40
- [data-bg-sw][data-on]{background:#3b82f6;}
41
- [data-bg-sw]::after{content:'';position:absolute;top:3px;left:3px;width:16px;height:16px;border-radius:8px;
42
- background:#fff;transition:transform .15s;}
43
- [data-bg-sw][data-on]::after{transform:translateX(16px);}
44
- [data-bg-num]{width:96px;padding:6px 10px;border-radius:8px;font:inherit;font-size:13px;color:inherit;
45
- border:1px solid var(--dsw-alias-border-default,rgba(128,128,128,.28));
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-in]{width:100%;box-sizing:border-box;resize:vertical;min-height:90px;padding:10px 12px;
48
- border-radius:10px;font:inherit;font-size:13px;line-height:20px;color:inherit;
49
- border:1px solid var(--dsw-alias-border-default,rgba(128,128,128,.28));
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-btn]{padding:7px 14px;border-radius:8px;cursor:pointer;font:inherit;font-size:13px;
52
- border:1px solid var(--dsw-alias-border-default,rgba(128,128,128,.28));
53
- background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.14));color:inherit;}
54
- [data-bg-btn][disabled]{opacity:.5;cursor:default;}
55
- [data-bg-out]{padding:12px 14px;border-radius:10px;font-size:12px;line-height:20px;white-space:pre-wrap;
56
- font-family:ui-monospace,SFMono-Regular,Menlo,monospace;
57
- background:var(--dsw-alias-bg-hover,rgba(128,128,128,.10));}
58
- [data-bg-meta]{font-size:11px;color:var(--dsw-alias-label-tertiary,#9aa0a6);}
59
- @media (prefers-color-scheme:dark){[data-bg-sw][data-on]{background:#2563eb;}}
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
- setBad(true)
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
- setBad(true)
95
- setMsg('保存失败:' + (e && e.message ? e.message : String(e)))
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 { setBad(true); setMsg(r.error || '没查出结果') }
175
+ else setMsg({ err: true, text: r.error || '没查出结果' })
109
176
  } catch (e) {
110
- setBad(true)
111
- setMsg('查不了:' + (e && e.message ? e.message : String(e)))
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-page': '' },
119
- h('div', { 'data-bg-note': '' }, msg || '正在读配置……'))
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-page': '' },
125
- h('div', { 'data-bg-sec': '' },
126
- h('div', { 'data-bg-h': '' }, '八股检测'),
127
- h('div', { 'data-bg-note': '' },
128
- '给一段话数几样东西:具体物、撑场面的话、留白词、结构腔密度。只读不改写,给坐标不给成品。')),
129
-
130
- h('div', { 'data-bg-sec': '' },
131
- h('div', { 'data-bg-row': '' },
132
- h('button', {
133
- 'data-bg-sw': '',
134
- 'data-on': on ? '' : undefined,
135
- 'aria-label': on ? '关闭八股检测' : '打开八股检测',
136
- disabled: busy === 'save',
137
- onClick: () => save({ enabled: !on }),
138
- }),
139
- h('div', { 'data-bg-grow': '' },
140
- h('div', { style: { fontSize: '13px' } }, on ? '已开启' : '已关闭'),
141
- h('div', { 'data-bg-note': '' },
142
- on
143
- ? (st && st.promptActive
144
- ? '「说话的念头」那一节已经挂进系统提示,现在生效。'
145
- : '已开启,但那一节没挂上(关了 prompt 开关,或重载后生效)。')
146
- : '关掉以后整节从系统提示里撤掉,两个工具还在,只是不再往提示里塞话。')))),
147
-
148
- h('div', { 'data-bg-sec': '' },
149
- h('div', { 'data-bg-row': '' },
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
- h('div', { 'data-bg-sec': '' },
226
+ // ── 阈值 ─────────────────────────────
227
+ h('div', null,
164
228
  h('div', { 'data-bg-h': '' }, '阈值'),
165
- h('div', { 'data-bg-row': '' },
166
- h('div', { 'data-bg-grow': '' },
167
- h('div', { style: { fontSize: '13px' } }, '留白词下限'),
168
- h('div', { 'data-bg-note': '' }, '每千字有几个「好像 / 应该 / 大概」才算够。低于这个就报「句句在下断言」。')),
169
- h('input', {
170
- 'data-bg-num': '', type: 'number', step: '0.1', min: '0',
171
- value: view.hedgeFloor,
172
- disabled: busy === 'save',
173
- onChange: (e) => setView({ ...view, hedgeFloor: e.target.value === '' ? '' : Number(e.target.value) }),
174
- onBlur: () => { if (view.hedgeFloor !== st.config.hedgeFloor) save({ hedgeFloor: view.hedgeFloor }) },
175
- })),
176
-
177
- h('div', { 'data-bg-row': '' },
178
- h('div', { 'data-bg-grow': '' },
179
- h('div', { style: { fontSize: '13px' } }, '结构腔报警倍数'),
180
- h('div', { 'data-bg-note': '' }, '密度超过同文体基线的几倍才报。调大更宽容,调小更敏感。')),
181
- h('input', {
182
- 'data-bg-num': '', type: 'number', step: '0.5', min: '1',
183
- value: view.structureTimes,
184
- disabled: busy === 'save',
185
- onChange: (e) => setView({ ...view, structureTimes: e.target.value === '' ? '' : Number(e.target.value) }),
186
- onBlur: () => { if (view.structureTimes !== st.config.structureTimes) save({ structureTimes: view.structureTimes }) },
187
- })),
188
-
189
- h('div', { 'data-bg-row': '' },
190
- h('div', { 'data-bg-grow': '' },
191
- h('div', { style: { fontSize: '13px' } }, '具体物下限'),
192
- h('div', { 'data-bg-note': '' }, '每百字至少几个数字、时间、经历、原话、名字。低于这个就报「这段话你看见的,还是听说的」。')),
193
- h('input', {
194
- 'data-bg-num': '', type: 'number', step: '0.1', min: '0',
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('textarea', {
215
- 'data-bg-in': '',
216
- value: text,
217
- onChange: (e) => setText(e.target.value),
218
- rows: 4,
219
- }),
220
- h('div', { 'data-bg-row': '' },
221
- h('button', { 'data-bg-btn': '', disabled: busy === 'preview', onClick: preview },
222
- busy === 'preview' ? '查着……' : '查一下'),
223
- h('div', { 'data-bg-grow': '' }),
224
- h('div', { 'data-bg-meta': '' }, '这段是他验自己用的,不会发出去'))),
225
-
226
- out ? h('div', { 'data-bg-out': '' }, out) : null,
227
-
228
- msg ? h('div', { 'data-bg-note': '', 'data-warn': bad ? '' : undefined }, msg) : null,
229
- h('div', { 'data-bg-note': '' },
230
- '改完立刻生效,不用重启。配置存在 ' + String((st && st.configFile) || 'config.json'))
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
@@ -3,7 +3,7 @@
3
3
  "manifestVersion": "0.15",
4
4
  "id": "dsh-bagu",
5
5
  "name": "dsh-bagu",
6
- "version": "0.2.0",
6
+ "version": "0.3.0",
7
7
  "license": "MIT",
8
8
  "description": "八股检测:数具体物、撑场面的话、留白词、结构腔密度。只读不改写。",
9
9
  "facets": {
package/lib/analyze.js CHANGED
@@ -28,6 +28,8 @@ import {
28
28
  EVAL_ADJECTIVES,
29
29
  HEDGE_WORDS,
30
30
  CONCRETE_MARKERS,
31
+ CONCRETE_WEIGHTS,
32
+ SYNONYM_GROUPS,
31
33
  STRUCTURE_FRAMES,
32
34
  REGISTERS,
33
35
  HEDGE_BASELINE,
@@ -91,14 +93,17 @@ export function registerOf(text) {
91
93
  export function concreteness(text) {
92
94
  const src = String(text ?? '');
93
95
  const hits = [];
96
+ let weighted = 0;
94
97
  for (const [kind, re] of Object.entries(CONCRETE_MARKERS)) {
95
98
  const g = new RegExp(re.source, 'g');
99
+ const w = CONCRETE_WEIGHTS[kind] ?? 1;
96
100
  for (const m of src.matchAll(g)) {
97
- hits.push({ kind, text: m[0], at: m.index });
101
+ hits.push({ kind, text: m[0], at: m.index, weight: w });
102
+ weighted += w;
98
103
  }
99
104
  }
100
- const per100 = src.length ? (hits.length / src.length) * 100 : 0;
101
- return { hits, per100: Math.round(per100 * 100) / 100 };
105
+ const per100 = src.length ? (weighted / src.length) * 100 : 0;
106
+ return { hits, weighted, per100: Math.round(per100 * 100) / 100 };
102
107
  }
103
108
 
104
109
  /** 结构腔扫描。 */
@@ -130,6 +135,25 @@ export function cluster(hits, width = 100) {
130
135
  return { width, maxHits, maxDistinct, at };
131
136
  }
132
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
+
133
157
  /**
134
158
  * 主入口。
135
159
  * @returns 结构化判断结果,不含任何改写建议的原句
@@ -162,7 +186,6 @@ export function analyze(input, opts = {}) {
162
186
  const structures = scanStructures(text);
163
187
  const totalStructures = structures.reduce((a, r) => a + r.count, 0);
164
188
  const structurePer1k = per1k(totalStructures);
165
- const allowed = Math.max(chars >= 200 ? 1 : 0, Math.round((baseline * chars) / 1000));
166
189
  const overTimes = baseline ? Math.round((structurePer1k / baseline) * 10) / 10 : 0;
167
190
 
168
191
  const flatHits = [];
@@ -170,6 +193,7 @@ export function analyze(input, opts = {}) {
170
193
  for (const s of row.spans) flatHits.push({ id: row.id, name: row.name, at: s.at, span: s.text });
171
194
  }
172
195
  const cl = cluster(flatHits);
196
+ const synRot = synonymRotation(text);
173
197
 
174
198
  // ── 判档 ─────────────────────────────────────
175
199
  // 可替换度:六个信号,各算一分。用密度不用绝对数 —— 五十个字里出一个「意义」,
@@ -179,18 +203,58 @@ export function analyze(input, opts = {}) {
179
203
  const evalPer100 = per100(evalHits.length);
180
204
  const aiWordPer100 = per100(aiWordHits.length);
181
205
 
182
- const replaceable =
206
+ // 六项坏信号相加,另加一个减分位:具体物足够多时往回拉一格。
207
+ // 否则「讲了十件亲手做过的事 + 用了两个抽象词」和「全是空话 + 两个抽象词」
208
+ // 在第 2 项上完全同分(issue #1 第 4 条)。
209
+ const raw1 =
183
210
  (conc.per100 < concreteFloor ? 1 : 0) +
184
211
  (abstractPer100 + evalPer100 >= 2 ? 1 : 0) +
185
212
  (aiWordPer100 >= 1 || aiWordHits.length >= 2 ? 1 : 0) +
186
213
  (structurePer1k > baseline * structureTimes ? 1 : 0) +
187
214
  (hedgePer1k < hedgeFloor && chars > 40 ? 1 : 0) +
188
215
  (summaryHits.length + fakeHits.length > 0 ? 1 : 0);
216
+ const credit = (conc.per100 >= concreteFloor * 2 ? 1 : 0);
217
+ const replaceable = Math.max(0, Math.min(6, raw1 - credit));
189
218
 
190
219
  let band;
191
220
  let bandLabel;
192
221
  let bandNote;
193
- if (replaceable >= 4) {
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
+
239
+ if (chars < 60) {
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
+ }
257
+ } else if (replaceable >= 4) {
194
258
  band = 'heavy';
195
259
  bandLabel = '换谁都行';
196
260
  bandNote = '把这些句子搬到另一个人嘴里,读起来不会有差别。';
@@ -255,6 +319,7 @@ export function analyze(input, opts = {}) {
255
319
  hedgePer1k,
256
320
  structurePer1k,
257
321
  overTimes,
322
+ shortScore,
258
323
  clusterDistinct: cl.maxDistinct,
259
324
  clusterMax: cl.maxHits,
260
325
  },
@@ -270,6 +335,8 @@ export function analyze(input, opts = {}) {
270
335
  },
271
336
  asks,
272
337
  baselineHedge: HEDGE_BASELINE,
338
+ synonyms: synRot,
339
+ duplicateSynonym: synRot,
273
340
  thresholds: { hedgeFloor, structureTimes, concreteFloor },
274
341
  blind: '这一步只认字面和句式。同一件事换个说法又说一遍、每段都收个小结论、通篇一个调子 —— 这些它看不见,得你自己读。',
275
342
  };
package/lib/config.js CHANGED
@@ -19,7 +19,7 @@ export const DEFAULTS = {
19
19
  /** prompt 节的 order,越大越靠后 */
20
20
  order: 921,
21
21
  /** 留白词低于这个密度(每千字)就报「句句在下断言」 */
22
- hedgeFloor: 0.5,
22
+ hedgeFloor: 0.2,
23
23
  /** 结构腔超过基线几倍才报 */
24
24
  structureTimes: 3,
25
25
  /** 具体物低于每百字这个数就报 */