dsh-wdx-relief 0.5.0 → 0.5.2

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,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.2 — 2026-11-14
4
+
5
+ - 修掉「预测看不到提问框」:输入框灰字预测的上下文里现在会带上 `ask_user_question` 的问答,
6
+ 渲染成「助手(提问)…」「用户(回答)…」两行。
7
+ - 前台回答写在工具结果的 `{"answers":[…]}` 里,排队回答是 `source.kind === 'user-question-reply'`
8
+ 的用户消息;这两种记录以前都被当成工具噪音丢掉,预测只能看到助手最后的「已写入…」,
9
+ 看起来就像助手没问过就把事做完了。
10
+ - 同一题只保留一条回答;坏 JSON、失败的工具结果和 `isError` 结果直接跳过。
11
+ - 预测 prompt 里补了一句说明,让模型把这两行当成已经发生的确认,而不是待确认。
12
+
13
+ ## 0.5.1 — 2026-11-12
14
+
15
+ - 修掉「又问了一轮,输入框上面那一行还是上一轮的」:摘要默认改成每轮都更新(`recapCooldownTurns` 默认 1,原来是 3),沿用旧行的相似度阈值从 0.7 提到 0.9,只有几乎没变化时才不动。
16
+ - 原来 `cooldownTurns: 3` 会让第 4、5 轮继续显示第 3 轮的摘要,看起来像没更新。
17
+ - 模型调用仍然是终局后一次便宜模型;不想每轮更新可以在设置页把间隔调回 3。
18
+
3
19
  ## 0.5.0 — 2026-11-12
4
20
 
5
21
  - 右侧栏默认 Tab 从「没接住的事」改名为「待跟进」:范围不变,仍是过去会话里等你拍板、你还没回答、明确留给你的动作;英文界面同步改为 Follow-ups。
package/client/client.js CHANGED
@@ -2269,8 +2269,8 @@ window.__ModuleLoader__.load({
2269
2269
  { field: 'recapReasoning', format: booleanText, parse: parseBoolean },
2270
2270
  choiceField('recapPlacement', RECAP_PLACEMENTS, 'above'),
2271
2271
  numberField('recapMinTurns', 3, 1, 50, 1),
2272
- numberField('recapCooldownTurns', 3, 1, 50, 1),
2273
- numberField('recapSimilarityThreshold', 0.7, 0, 1, 0.05),
2272
+ numberField('recapCooldownTurns', 1, 1, 50, 1),
2273
+ numberField('recapSimilarityThreshold', 0.9, 0, 1, 0.05),
2274
2274
  numberField('recapMaxWords', 40, 5, 200, 1),
2275
2275
  textField('recapModelChain'),
2276
2276
  { field: 'today', format: booleanText, parse: parseBoolean },
package/docs/guide.md CHANGED
@@ -37,8 +37,8 @@ HMR 生效。
37
37
  | `recapReasoning` | `false` | 思考预览开关:折叠推理的第一行,本地生成 |
38
38
  | `recapPlacement` | `above` | `above` / `below`,这一行放在输入框上方还是下方 |
39
39
  | `recapMinTurns` | `3` | 至少几轮用户消息后才开始生成语义摘要 |
40
- | `recapCooldownTurns` | `3` | 每隔几轮更新一次语义摘要;`1` = 每轮 |
41
- | `recapSimilarityThreshold` | `0.7` | 新旧摘要相似度达到这个值就沿用旧的一行 |
40
+ | `recapCooldownTurns` | `1` | 每隔几轮更新一次语义摘要;`1` = 每轮(默认每轮都更新,问完下一轮就换新) |
41
+ | `recapSimilarityThreshold` | `0.9` | 新旧摘要相似度达到这个值才沿用旧的一行(调低会更容易出现「没更新」) |
42
42
  | `recapMaxWords` | `40` | 摘要词预算;中文按字算 |
43
43
  | `recapModelChain` | `''` | 摘要模型链,按顺序尝试 `provider/model`;留空自动挑便宜模型 |
44
44
  | `today` | `true` | 右侧栏 WDX Relief 页面里的「待跟进」清单 |
@@ -71,6 +71,9 @@ bundle 层只声明入口和输入层的开关,其余字段由 schema 默认
71
71
  空闲、空输入时以 350ms 防抖请求 `POST /api/wdx-relief/predict`。
72
72
  2. Host 用 `ctx.sessions.get(sessionId).deriveMessages()` 取最近几轮真人用户/助手文本,
73
73
  要求最后一条是助手消息;用 `agentDefaultModel` 的最低推理档位生成一条短句。
74
+ 提问框(`ask_user_question`)的问答会还原成「助手(提问)」「用户(回答)」两行:前台回答在
75
+ 工具结果的 `{"answers":[…]}` 里,排队回答是 `source.kind === 'user-question-reply'` 的用户消息;
76
+ 不还原的话,最近几轮看起来就像助手没问过就把事做完了(例如刚写完 11 条,预测却以为用户还没确认)。
74
77
  3. 结果按 `session.seq` 缓存;客户端把灰字绝对定位到 `[data-composer-input]` 的文字起点,
75
78
  Tab 通过标准 prop `inputActions.setDraft()` 写入 Lexical 编辑器。
76
79
  这条 Codex 式体验依赖 composer 的布局矩形,是本插件已知的 DOM 耦合点。
package/index.js CHANGED
@@ -69,13 +69,13 @@ export const Config = Schema.object({
69
69
  .volatile()
70
70
  .description('至少经过几轮用户消息后才开始生成语义摘要'),
71
71
  recapCooldownTurns: Schema.number()
72
- .default(3)
72
+ .default(1)
73
73
  .volatile()
74
- .description('每隔几轮才更新语义摘要;1 表示每轮'),
74
+ .description('每隔几轮才更新语义摘要;1 表示每轮(默认每轮都更新)'),
75
75
  recapSimilarityThreshold: Schema.number()
76
- .default(0.7)
76
+ .default(0.9)
77
77
  .volatile()
78
- .description('新旧摘要相似度达到这个值时沿用旧的一行(0–1)'),
78
+ .description('新旧摘要相似度达到这个值时才沿用旧的一行(0–1,默认 0.9)'),
79
79
  recapMaxWords: Schema.number()
80
80
  .default(40)
81
81
  .volatile()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-wdx-relief",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Take the friction out of daily DSH work: predicted next messages, a live one-line turn recap above the composer, and sidebar side questions with a composer-style model picker that stay out of the model context.",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/prediction.js CHANGED
@@ -22,6 +22,7 @@ export const SYSTEM_PROMPT = [
22
22
  '- 使用与用户最近消息相同的语言。',
23
23
  '- 优先给出具体动作、回答 agent 的提问、或确认下一步;不要泛泛地说「继续」。',
24
24
  '- 不要重复助手说过的话,也不要复述用户上一条消息。',
25
+ '- 「助手(提问)」/「用户(回答)」是助手用提问框向用户确认、用户点选的答案,按已经发生的对话处理。',
25
26
  '- 不要解释、不要引号、不要编号、不要加「预测:」之类的前缀。',
26
27
  '- 没有足够信息时只输出 <none>。',
27
28
  ].join('\n')
@@ -49,9 +50,71 @@ export function messageText(message) {
49
50
  return parts.join('\n').trim()
50
51
  }
51
52
 
53
+ /** 提问框工具:助手用它让用户点选答案,答案不会以用户消息的形式出现。 */
54
+ const QUESTION_TOOL = 'ask_user_question'
55
+ const MAX_QUESTION_CHARS = 400
56
+ const MAX_ANSWER_CHARS = 200
57
+
58
+ function parseObject(value) {
59
+ if (value !== null && typeof value === 'object' && !Array.isArray(value)) return value
60
+ if (typeof value !== 'string' || value.trim() === '') return null
61
+ try {
62
+ const parsed = JSON.parse(value)
63
+ return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null
64
+ } catch {
65
+ return null
66
+ }
67
+ }
68
+
69
+ /** 「要写入吗?(选项:可以、先别)」——把提问框的问题压成一行。 */
70
+ function questionLine(questions) {
71
+ const parts = []
72
+ for (const question of Array.isArray(questions) ? questions : []) {
73
+ if (question === null || typeof question !== 'object') continue
74
+ const text = typeof question.question === 'string' ? question.question.trim() : ''
75
+ if (text === '') continue
76
+ const labels = (Array.isArray(question.options) ? question.options : [])
77
+ .map((option) => (option !== null && typeof option === 'object' && typeof option.label === 'string' ? option.label.trim() : ''))
78
+ .filter((label) => label !== '')
79
+ .slice(0, 4)
80
+ parts.push(labels.length === 0 ? text : `${text}(选项:${labels.join('、')})`)
81
+ }
82
+ return parts.join(';')
83
+ }
84
+
85
+ /** 用户的点选结果;多问题时带上题目,单独一题时靠上一行提问就够。 */
86
+ function answerLine(answers, questions) {
87
+ const questionById = new Map()
88
+ let questionCount = 0
89
+ for (const question of Array.isArray(questions) ? questions : []) {
90
+ if (question === null || typeof question !== 'object') continue
91
+ questionCount += 1
92
+ const text = typeof question.question === 'string' ? question.question.trim() : ''
93
+ if (typeof question.id === 'string' && text !== '') questionById.set(question.id, text)
94
+ }
95
+
96
+ const parts = []
97
+ for (const answer of Array.isArray(answers) ? answers : []) {
98
+ if (answer === null || typeof answer !== 'object') continue
99
+ const selected = (Array.isArray(answer.selected) ? answer.selected : [])
100
+ .filter((value) => typeof value === 'string' && value.trim() !== '')
101
+ .map((value) => value.trim())
102
+ const custom = typeof answer.custom === 'string' ? answer.custom.trim() : ''
103
+ let picked
104
+ if (selected.length === 0) picked = custom === '' ? '跳过' : `自定义:${custom}`
105
+ else picked = custom === '' ? selected.join('、') : `${selected.join('、')}(补充:${custom})`
106
+ const prompt = questionCount > 1 && typeof answer.id === 'string' ? questionById.get(answer.id) : undefined
107
+ parts.push(prompt === undefined ? picked : `${prompt} → ${picked}`)
108
+ }
109
+ return parts.join(';')
110
+ }
111
+
52
112
  /**
53
113
  * 从 deriveMessages() 里截出最近几轮可读对话。
54
114
  * 只保留真人用户消息(source.kind === 'user',排除注入的上下文)和助手消息;
115
+ * 提问框的问答要单独还原:前台回答写在工具结果的 JSON 里,排队回答是
116
+ * `source.kind === 'user-question-reply'` 的用户消息,两者都不是普通用户文本。
117
+ * 少了这两行,最近几轮看起来就像助手没问过就直接把事做完了。
55
118
  * 最后一条必须是助手,否则说明当前轮次还没结束,不该预测。
56
119
  */
57
120
  export function extractConversation(messages, options = {}) {
@@ -60,12 +123,65 @@ export function extractConversation(messages, options = {}) {
60
123
  const maxPromptChars = options.maxPromptChars ?? MAX_PROMPT_CHARS
61
124
 
62
125
  const items = []
126
+ /** callId -> 这一问的问题列表,用来给回答补上题目。 */
127
+ const asked = new Map()
128
+ const answered = new Set()
129
+
130
+ const pushAnswer = (callId, answers, questions) => {
131
+ if (typeof callId === 'string') {
132
+ if (answered.has(callId)) return
133
+ answered.add(callId)
134
+ }
135
+ const text = answerLine(answers, questions)
136
+ if (text === '') return
137
+ items.push({ role: 'user', kind: 'answer', text: clipText(text, MAX_ANSWER_CHARS) })
138
+ }
139
+
63
140
  for (const message of messages ?? []) {
64
- if (!message || (message.role !== 'user' && message.role !== 'assistant')) continue
65
- if (message.role === 'user' && message.source && message.source.kind !== 'user') continue
141
+ if (!message || typeof message !== 'object') continue
142
+
143
+ // 前台回答:ask_user_question 的结果落在一条 role: 'tool' 的消息里。
144
+ if (message.role === 'tool') {
145
+ const source = message.source
146
+ const callId = typeof message.toolCallId === 'string'
147
+ ? message.toolCallId
148
+ : source && typeof source === 'object' && typeof source.callId === 'string' ? source.callId : undefined
149
+ if (callId === undefined || !asked.has(callId) || message.isError === true) continue
150
+ const result = parseObject(messageText(message))
151
+ if (result !== null && Array.isArray(result.answers)) pushAnswer(callId, result.answers, asked.get(callId))
152
+ continue
153
+ }
154
+
155
+ if (message.role === 'user') {
156
+ const source = message.source
157
+ // 排队回答:用户回答在等待窗口关闭后才到达时,DSH 会追加一条用户消息。
158
+ if (source && typeof source === 'object' && source.kind === 'user-question-reply') {
159
+ const reply = parseObject(messageText(message))
160
+ if (reply === null || !Array.isArray(reply.answers)) continue
161
+ const callId = typeof source.callId === 'string'
162
+ ? source.callId
163
+ : typeof reply.callId === 'string' ? reply.callId : undefined
164
+ pushAnswer(callId, reply.answers, Array.isArray(reply.questions) ? reply.questions : (callId === undefined ? undefined : asked.get(callId)))
165
+ continue
166
+ }
167
+ if (source && typeof source === 'object' && source.kind !== 'user') continue
168
+ } else if (message.role !== 'assistant') {
169
+ continue
170
+ }
171
+
66
172
  const raw = messageText(message)
67
- if (raw === '') continue
68
- items.push({ role: message.role, text: clipText(raw, maxMessageChars) })
173
+ if (raw !== '') items.push({ role: message.role, text: clipText(raw, maxMessageChars) })
174
+
175
+ const blocks = message.role === 'assistant' && Array.isArray(message.content) ? message.content : []
176
+ for (const block of blocks) {
177
+ if (!block || typeof block !== 'object' || block.type !== 'tool-call' || block.name !== QUESTION_TOOL) continue
178
+ const args = parseObject(block.arguments)
179
+ const questions = args === null ? [] : Array.isArray(args.questions) ? args.questions : []
180
+ const text = questionLine(questions)
181
+ if (text === '') continue
182
+ if (typeof block.id === 'string') asked.set(block.id, questions)
183
+ items.push({ role: 'assistant', kind: 'question', text: clipText(text, MAX_QUESTION_CHARS) })
184
+ }
69
185
  }
70
186
 
71
187
  if (items.length < 2) return null
@@ -83,10 +199,17 @@ export function extractConversation(messages, options = {}) {
83
199
  return tail
84
200
  }
85
201
 
202
+ /** 提问框的问答要标出来,模型才知道这是用户在弹窗里点的,不是随口说的。 */
203
+ function speakerOf(item) {
204
+ if (item.kind === 'question') return '助手(提问)'
205
+ if (item.kind === 'answer') return '用户(回答)'
206
+ return item.role === 'user' ? '用户' : '助手'
207
+ }
208
+
86
209
  /** 把对话尾段拼成给模型的 user prompt。 */
87
210
  export function buildPrompt(conversation) {
88
211
  const transcript = conversation
89
- .map((item) => `${item.role === 'user' ? '用户' : '助手'}:${item.text}`)
212
+ .map((item) => `${speakerOf(item)}:${item.text}`)
90
213
  .join('\n\n')
91
214
  return [
92
215
  '以下是用户与编码 agent 的最近对话:',
package/src/recap.js CHANGED
@@ -20,8 +20,8 @@ const MAX_OUTPUT_TOKENS = 512
20
20
  const SUMMARY_TIMEOUT_MS = 8000
21
21
 
22
22
  export const DEFAULT_MIN_TURNS = 3
23
- export const DEFAULT_COOLDOWN_TURNS = 3
24
- export const DEFAULT_SIMILARITY_THRESHOLD = 0.7
23
+ export const DEFAULT_COOLDOWN_TURNS = 1
24
+ export const DEFAULT_SIMILARITY_THRESHOLD = 0.9
25
25
  export const DEFAULT_MAX_WORDS = 40
26
26
 
27
27
  /** 便宜模型的名字通常带这些词;只用于自动挑选,不改变用户显式配置的顺序。 */