dsh-plain-talk 0.1.17 → 0.1.18

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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.1.18
2
+
3
+ ### 真实宿主事件契约
4
+
5
+ - 修复:真实宿主用 `user/message`(`kind=user`)传用户输入,插件只监听 `agent/inbox/spliced`,导致当轮请求文本始终为空、词汇段落从未注入。两个来源现在都收。
6
+ - 修复:「解释一下 A 和 B」只抓到 A。并列项按连接词展开,每个都取。
7
+ - 并列展开补上否定前缀守卫,避免从「不用解释清单中」抠出假术语。
8
+ - 真实 headless 会话验证:开启时注入块与本地渲染逐字节一致;关闭时零注入。
1
9
  ## 0.1.17
2
10
 
3
11
  ### 产物判定的通用规则
package/dsh/index.js CHANGED
@@ -168,23 +168,25 @@ export function apply(ctx, config = {}) {
168
168
  const data = event?.data ?? {}
169
169
  const enabled = sessionEnabled(id)
170
170
  switch (event?.type) {
171
- case 'agent/inbox/spliced': {
172
- // 真实事件顺序是 splice 先于 turn/start:按“文本所属轮次”判断跨轮。
173
- if (entry.textsTurn !== undefined && entry.textsTurn !== entry.turn) {
174
- entry.texts = []
175
- entry.request = ''
176
- entry.pending = []
177
- }
178
- entry.textsTurn = entry.turn
179
- for (const message of data.inserted ?? []) {
171
+ case 'agent/inbox/spliced':
172
+ case 'user/message': {
173
+ // 两种来源:spliced 带 inserted 数组,user/message 直接是消息体。
174
+ const incoming = Array.isArray(data.inserted) ? data.inserted : [data]
175
+ for (const message of incoming) {
180
176
  const kind = message?.source?.kind
181
177
  if (kind && kind !== 'user') continue
182
178
  if (message?.role && message.role !== 'user') continue
183
179
  const text = textOf(message)
184
180
  if (!text || NOT_USER_TEXT.test(text)) continue
181
+ // 真实事件顺序是 splice 先于 turn/start:按“文本所属轮次”判断跨轮。
182
+ if (entry.textsTurn !== undefined && entry.textsTurn !== entry.turn) {
183
+ entry.texts = []
184
+ entry.request = ''
185
+ entry.pending = []
186
+ }
187
+ entry.textsTurn = entry.turn
185
188
  entry.texts.push(text)
186
189
  entry.request = text
187
- // 待解释层:本轮明确问到的词 + 本轮任务里出现的术语(只收拉丁术语,中文短语不进)。
188
190
  entry.pending = [...new Set([...detectExplainRequest(text), ...extractObservedTerms(text)])].filter(isSafeTerm)
189
191
  if (enabled) recordTurn(id, entry.turn, text)
190
192
  }
@@ -425,6 +425,28 @@ const STOP_TERMS = new Set([
425
425
  ])
426
426
 
427
427
  // 从一句请求里抽出“用户要求解释的术语”,保持首次出现的写法。
428
+ // 「解释一下 A 和 B」这类并列:取动词后面整段,按连接词切开,每段只取开头的术语。
429
+ function expandExplainList(source) {
430
+ const out = []
431
+ const verb = /(?:解释(?:一下|下)?|说明(?:一下|下)?|讲(?:一下|讲)?|什么是|啥是)/g
432
+ for (const m of source.matchAll(verb)) {
433
+ // 与主检测器一致:动词前紧贴否定词时跳过(「不用解释X」不是解释请求)。
434
+ const prefix = source.slice(Math.max(0, m.index - 3), m.index)
435
+ if (/(?:不|没|别|未|无)[\u4e00-\u9fa5]?$/.test(prefix)) continue
436
+ const from = m.index + m[0].length
437
+ let run = source.slice(from, from + 80)
438
+ const stop = run.search(/[。!?!?;;\n]/)
439
+ if (stop >= 0) run = run.slice(0, stop)
440
+ for (const chunk of run.split(/和|与|跟|及|以及|、|,|,|\/|\band\b/)) {
441
+ const head = /^\s*([A-Za-z][A-Za-z0-9_.\-+]*|[\u4e00-\u9fa5]{2,8})/.exec(chunk)
442
+ if (!head) continue
443
+ const term = cleanTerm(head[1])
444
+ if (term) out.push(term)
445
+ }
446
+ }
447
+ return out
448
+ }
449
+
428
450
  export function detectExplainRequest(text) {
429
451
  const source = String(text ?? '')
430
452
  if (!source.trim()) return []
@@ -447,6 +469,12 @@ export function detectExplainRequest(text) {
447
469
  found.push(raw)
448
470
  }
449
471
  }
472
+ for (const term of expandExplainList(source)) {
473
+ const key = termKey(term)
474
+ if (seen.has(key)) continue
475
+ seen.add(key)
476
+ found.push(term)
477
+ }
450
478
  return found
451
479
  }
452
480
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plain-talk",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "Composer toggle that shapes replies: conclusion first, inline quotes, no cross-turn references",
5
5
  "scripts": {
6
6
  "test": "node test/run-all.mjs"