dsh-reconcile 0.1.0 → 0.1.1
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 +231 -229
- package/client.js +186 -23
- package/package.json +7 -3
- package/src/score-copy.js +161 -0
- package/test/selfcheck.mjs +57 -1
package/README.md
CHANGED
|
@@ -1,229 +1,231 @@
|
|
|
1
|
-
# 交账 · dsh-reconcile
|
|
2
|
-
|
|
3
|
-
DeepSeek Harness 插件:**先核事实、再决定问不问、收工对账**。
|
|
4
|
-
|
|
5
|
-
中文名「交账」,包名 `dsh-reconcile`(reconcile = 对账)。插件行 id 同名。
|
|
6
|
-
|
|
7
|
-
## 长什么样
|
|
8
|
-
|
|
9
|
-
输入框下面实时打分。零模型调用,命中的信号逐条列出来,点一下就带证据问你:
|
|
10
|
-
|
|
11
|
-

|
|
12
|
-
|
|
13
|
-
点「先查再问」后,候选全部带证据(git / mtime / 本会话引用 / 页面路由),最后一项固定「我不知道,你替我定」:
|
|
14
|
-
|
|
15
|
-

|
|
16
|
-
|
|
17
|
-
每个 turn 收尾时,插件在会话里单独渲染一行对账结果——这行不在模型输出里,模型删不掉:
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
交账 未达标:2 项 对账:3/5 通过 [重新对账]
|
|
21
|
-
✗ A2 首页 375px 无横向滚动 —— 未验证:找不到截图
|
|
22
|
-
✗ A4 单测通过 —— command `pnpm test` 退出码 1(3 failed)
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
## 为什么做这个
|
|
29
|
-
|
|
30
|
-
这条赛道上已经有十来个「先问几个问题再改写」的同类插件。所以本插件**不把「问得更好」当卖点**:
|
|
31
|
-
先核事实与含糊度打分都只做到够用,真正投入在**收工时的验收对账**——
|
|
32
|
-
把「什么算做完」在开工时写成清单,收工时由插件自己跑的判定结果逐条核,模型不能自己宣布通过。
|
|
33
|
-
|
|
34
|
-
## 和现有 13 个插件的差别
|
|
35
|
-
|
|
36
|
-
1. 它们把「问」当终点,我们把它当起点:问之前先在 git / mtime / 会话日志里核事实,候选必须带证据。
|
|
37
|
-
2. 它们优化问题措辞,我们只管「该不该打断」——一张固定分值表 + 两个可调阈值,零模型调用。
|
|
38
|
-
3. 它们没有收工时的那一下:我们把清单写进 `TASK.md`,判定与证据只由插件写 `TASK.evidence.json`,
|
|
39
|
-
收尾的 `未达标:N 项` 由插件渲染,模型删不掉。
|
|
40
|
-
|
|
41
|
-
## 三个机制
|
|
42
|
-
|
|
43
|
-
- **先核事实**:查 git 最近改动 / mtime 前 10 / 本会话引用过的路径 / 页面目录与路由表,给 2~3 个带证据的候选;
|
|
44
|
-
查不到才退化成开放问题(选项最后一项固定「我不知道,你替我定」)。
|
|
45
|
-
- **含糊度打分**:9 条信号固定加减分,夹到 0~100;`<40` 不打断、`40~70` 轻提示、`>70` 先问再动手。
|
|
46
|
-
每次打分把命中的信号与分值写进会话日志。
|
|
47
|
-
上一轮对账有未达标、这一轮又提同一件事(bigram 相似 ≥ 0.34)时记一次返工,供 `+15 同类请求曾返工` 使用。
|
|
48
|
-
- **收工对账**:`TASK.md` 写「目标 / 关键约束 / 3~7 条可判定真假的验收项(command / file / manual)」;
|
|
49
|
-
插件自己跑判定,写 `TASK.evidence.json`;三态只有通过 / 未通过 / 未验证;收尾一行 `未达标:N 项` 由插件渲染。
|
|
50
|
-
|
|
51
|
-
### 清单未建 ≠ 全通过
|
|
52
|
-
|
|
53
|
-
写操作 + 含糊度高于面板阈值 + 还没有真实验收项时,**插件自己在第一步之前就落一份占位骨架**
|
|
54
|
-
(`TASK.md` 里写满 `[待补充]`),并在收尾行显示 `未达标:清单未建`。
|
|
55
|
-
这条的作用是把「模型能拖」从「可拖」降成「拖不掉一半」:骨架已经在磁盘上,模型没法假装没有清单;
|
|
56
|
-
占位项也不会被真的执行(不会去跑 `echo TODO`)。
|
|
57
|
-
|
|
58
|
-
### 人工确认太多要自曝
|
|
59
|
-
|
|
60
|
-
`manual` 项占比超过一半时,报告里会多一行:
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
⚠ 4 条里 3 条靠人工确认,对账质量偏低
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
## 安装
|
|
68
|
-
|
|
69
|
-
**从
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
dsh plugin --profile web add
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
|
156
|
-
|
|
157
|
-
|
|
|
158
|
-
| `
|
|
159
|
-
| `
|
|
160
|
-
| `
|
|
161
|
-
|
|
|
162
|
-
|
|
|
163
|
-
|
|
|
164
|
-
|
|
|
165
|
-
|
|
|
166
|
-
|
|
|
167
|
-
|
|
|
168
|
-
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
|
201
|
-
|
|
202
|
-
|
|
|
203
|
-
|
|
|
204
|
-
|
|
|
205
|
-
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
|
215
|
-
|
|
216
|
-
| `
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
1
|
+
# 交账 · dsh-reconcile
|
|
2
|
+
|
|
3
|
+
DeepSeek Harness 插件:**先核事实、再决定问不问、收工对账**。
|
|
4
|
+
|
|
5
|
+
中文名「交账」,包名 `dsh-reconcile`(reconcile = 对账)。插件行 id 同名。
|
|
6
|
+
|
|
7
|
+
## 长什么样
|
|
8
|
+
|
|
9
|
+
输入框下面实时打分。零模型调用,命中的信号逐条列出来,点一下就带证据问你:
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
点「先查再问」后,候选全部带证据(git / mtime / 本会话引用 / 页面路由),最后一项固定「我不知道,你替我定」:
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
每个 turn 收尾时,插件在会话里单独渲染一行对账结果——这行不在模型输出里,模型删不掉:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
交账 未达标:2 项 对账:3/5 通过 [重新对账]
|
|
21
|
+
✗ A2 首页 375px 无横向滚动 —— 未验证:找不到截图
|
|
22
|
+
✗ A4 单测通过 —— command `pnpm test` 退出码 1(3 failed)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 为什么做这个
|
|
29
|
+
|
|
30
|
+
这条赛道上已经有十来个「先问几个问题再改写」的同类插件。所以本插件**不把「问得更好」当卖点**:
|
|
31
|
+
先核事实与含糊度打分都只做到够用,真正投入在**收工时的验收对账**——
|
|
32
|
+
把「什么算做完」在开工时写成清单,收工时由插件自己跑的判定结果逐条核,模型不能自己宣布通过。
|
|
33
|
+
|
|
34
|
+
## 和现有 13 个插件的差别
|
|
35
|
+
|
|
36
|
+
1. 它们把「问」当终点,我们把它当起点:问之前先在 git / mtime / 会话日志里核事实,候选必须带证据。
|
|
37
|
+
2. 它们优化问题措辞,我们只管「该不该打断」——一张固定分值表 + 两个可调阈值,零模型调用。
|
|
38
|
+
3. 它们没有收工时的那一下:我们把清单写进 `TASK.md`,判定与证据只由插件写 `TASK.evidence.json`,
|
|
39
|
+
收尾的 `未达标:N 项` 由插件渲染,模型删不掉。
|
|
40
|
+
|
|
41
|
+
## 三个机制
|
|
42
|
+
|
|
43
|
+
- **先核事实**:查 git 最近改动 / mtime 前 10 / 本会话引用过的路径 / 页面目录与路由表,给 2~3 个带证据的候选;
|
|
44
|
+
查不到才退化成开放问题(选项最后一项固定「我不知道,你替我定」)。
|
|
45
|
+
- **含糊度打分**:9 条信号固定加减分,夹到 0~100;`<40` 不打断、`40~70` 轻提示、`>70` 先问再动手。
|
|
46
|
+
每次打分把命中的信号与分值写进会话日志。
|
|
47
|
+
上一轮对账有未达标、这一轮又提同一件事(bigram 相似 ≥ 0.34)时记一次返工,供 `+15 同类请求曾返工` 使用。
|
|
48
|
+
- **收工对账**:`TASK.md` 写「目标 / 关键约束 / 3~7 条可判定真假的验收项(command / file / manual)」;
|
|
49
|
+
插件自己跑判定,写 `TASK.evidence.json`;三态只有通过 / 未通过 / 未验证;收尾一行 `未达标:N 项` 由插件渲染。
|
|
50
|
+
|
|
51
|
+
### 清单未建 ≠ 全通过
|
|
52
|
+
|
|
53
|
+
写操作 + 含糊度高于面板阈值 + 还没有真实验收项时,**插件自己在第一步之前就落一份占位骨架**
|
|
54
|
+
(`TASK.md` 里写满 `[待补充]`),并在收尾行显示 `未达标:清单未建`。
|
|
55
|
+
这条的作用是把「模型能拖」从「可拖」降成「拖不掉一半」:骨架已经在磁盘上,模型没法假装没有清单;
|
|
56
|
+
占位项也不会被真的执行(不会去跑 `echo TODO`)。
|
|
57
|
+
|
|
58
|
+
### 人工确认太多要自曝
|
|
59
|
+
|
|
60
|
+
`manual` 项占比超过一半时,报告里会多一行:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
⚠ 4 条里 3 条靠人工确认,对账质量偏低
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
## 安装
|
|
68
|
+
|
|
69
|
+
**从 npm 装(已发布 0.1.0):**
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
dsh plugin --profile web add dsh-reconcile
|
|
73
|
+
dsh plugin --profile web add dsh-reconcile@0.1.0 # 钉版本
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
npm 包页:<https://www.npmjs.com/package/dsh-reconcile>
|
|
77
|
+
|
|
78
|
+
**从 GitHub 装(不走 npm):**
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
dsh plugin --profile web add github:abcdefg592/dsh-reconcile
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**图形界面:** 插件 → 添加插件 → 粘贴 `dsh-reconcile` 或 `github:abcdefg592/dsh-reconcile`。
|
|
85
|
+
|
|
86
|
+
**本地目录:** 插件 → 添加插件 → 选本目录;或 `plugin_manager action=install_bundle target=<本目录绝对路径>`。
|
|
87
|
+
|
|
88
|
+
**进插件市场(自建索引):** 在市场设置里添加索引
|
|
89
|
+
`https://raw.githubusercontent.com/abcdefg592/dsh-reconcile/main/market/index.json`
|
|
90
|
+
(format 1,已用官方校验器 `parseMarketIndex` 验证;索引文件见 `market/index.json`,发布流程见 `docs/PUBLISH.md`)
|
|
91
|
+
|
|
92
|
+
- 本目录就是 bundle 包:`package.json` 的 `dsh.bundle.patch` 指向 `cordis.patch.yml`。
|
|
93
|
+
- 装完重启(替换已安装版本需要重启才会加载新的 JS 模块代)。
|
|
94
|
+
- **零配置可用**:不需要 API key、不需要 provider 设置页、无安装期脚本、无埋点、无对外请求。
|
|
95
|
+
|
|
96
|
+
仓库:<https://github.com/abcdefg592/dsh-reconcile> · MIT
|
|
97
|
+
|
|
98
|
+
## 配置(可选)
|
|
99
|
+
|
|
100
|
+
在 profile 的 `cordis.patch.yml` 里覆盖 `dsh-reconcile` 行的 `config`:
|
|
101
|
+
|
|
102
|
+
```yaml
|
|
103
|
+
- id: dsh-reconcile
|
|
104
|
+
config:
|
|
105
|
+
hintThreshold: 40 # 轻提示阈值
|
|
106
|
+
panelThreshold: 70 # 先问再动手阈值
|
|
107
|
+
zeroTargetEscalation: true # 零目标写操作升级为「先问再动手」
|
|
108
|
+
deicticEscalation: true # 指代 + 已过提示线升级为「先核事实再问」
|
|
109
|
+
logScores: true # 把分值构成写进会话日志
|
|
110
|
+
scoreLogMode: threshold # threshold | always:什么时候把分值写进会话日志
|
|
111
|
+
autoCheckCommands: true # 收尾自动对账要不要真跑 command 证据(清单里有 pnpm test 时可关)
|
|
112
|
+
gateWrites: false # 打开后:高含糊度的写操作在提问前会被挡住
|
|
113
|
+
commandTimeoutMs: 120000 # command 证据的超时
|
|
114
|
+
autoCheck: true # 每个 turn 收尾自动对账
|
|
115
|
+
routesEnabled: true # 面板按钮所需的 loopback 路由
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`gateWrites` 默认关:挡工具是强干预,容易被误伤;默认只做提示与面板。
|
|
119
|
+
|
|
120
|
+
## 文件与状态
|
|
121
|
+
|
|
122
|
+
- 工作区明文:`TASK.md`(意图)、`TASK.evidence.json`(判定与证据镜像)。
|
|
123
|
+
- 会话日志:分值构成通过 `agent.inject` 记录。
|
|
124
|
+
- 不建私有数据库。
|
|
125
|
+
|
|
126
|
+
**建议的仓库约定**(插件不会去改你的 `.gitignore`,只在 `reconcile action=open` 的返回里提醒一句):
|
|
127
|
+
|
|
128
|
+
```gitignore
|
|
129
|
+
# 机器产物:每次对账都整份重写,进 git 只会把 diff 弄脏
|
|
130
|
+
TASK.evidence.json
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`TASK.md` 应该进 git——它是「这次要交付什么」的唯一人读记录,改了它旧判定就作废,正好配合 code review。
|
|
134
|
+
|
|
135
|
+
## 自检(离线,不联网、不启宿主)
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
node test/selfcheck.mjs
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
当前:**78/78 全绿**。覆盖打分表 16 项、TASK.md 解析/回写 14 项、三种证据判定 16 项、
|
|
142
|
+
evidence 覆盖与防伪造 13 项、骨架与返工 4 项、跨站拒绝 8 项、候选排序 7 项。
|
|
143
|
+
|
|
144
|
+
没有 `node` 的机器上,可以用 DSH 自带的 Electron 当 node:
|
|
145
|
+
|
|
146
|
+
```powershell
|
|
147
|
+
$env:ELECTRON_RUN_AS_NODE='1'
|
|
148
|
+
& "$env:DSH_NODE_EXECUTABLE" test/selfcheck.mjs
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 实测记录(在真实会话里跑过什么)
|
|
152
|
+
|
|
153
|
+
装到本机 Desktop profile 后,用一个真实的 git 工作区(`probe/demo-workspace`)跑过:
|
|
154
|
+
|
|
155
|
+
| 实测项 | 结果 |
|
|
156
|
+
|---|---|
|
|
157
|
+
| 安装 + 重启生效 | `install_bundle` → `application: applied`;system prompt 段与两个工具当场出现 |
|
|
158
|
+
| `probe_intent`(机制一) | 真实返回 3 个带证据候选:`src/pages/index.tsx`(git 最近改动、mtime 第 5、本会话被引用 13 次)、`src/pages/about.tsx`、`data/report.csv`(未提交改动、mtime 第 1) |
|
|
159
|
+
| `reconcile action=open/check`(机制三) | 真跑命令、真读文件:`对账:2/3 通过,未达标 1 项` + `✗ A3 … command … 退出码 2` |
|
|
160
|
+
| `command` 证据的精确退出码 | `node -e "process.exit(7)"` → 记录 `exitCode: 7`,尾部含 stdout/stderr |
|
|
161
|
+
| `file` 证据 | 报告 `路径:行号` 与逐条断言结果(`README.md:3` 含 `## 安装`) |
|
|
162
|
+
| `manual` 证据 | 默认「未验证」,不进通过 |
|
|
163
|
+
| 伪造 `TASK.evidence.json` | 对账整份重写;`status` 读内存,不信文件 |
|
|
164
|
+
| 改 `TASK.md` 句子后 | 旧判定立即作废,标记「清单已变更,需重新对账」 |
|
|
165
|
+
| 清单未建(新) | 占位骨架 → `check` 报 `NO_REAL_ITEMS`,`status` 的 headline 是 `未达标:清单未建`;占位项不会被真的执行 |
|
|
166
|
+
| 人工占比告警(新) | 4 条里 3 条 manual → 报告多出 `⚠ 4 条里 3 条靠人工确认,对账质量偏低` |
|
|
167
|
+
| 客户端挂载 | `conversation.chat.turnTail` 与 `conversation.composer.dock` 两个槽里都出现了 `dsh-reconcile`(active) |
|
|
168
|
+
| 客户端真实渲染 | 输入 `改一下那个页面` → 输入框下真的出现 `含糊度 55 + 四条构成 + 两个按钮`;点「先查再问」→ 真的弹出带证据的候选面板(见上面的截图,真机截屏) |
|
|
169
|
+
| 收尾行真实渲染 | 亲眼看页面渲染出 `交账 · 未达标:0 项 · 对账:3/3 通过 · [重新对账]`(截图没抢到,见下) |
|
|
170
|
+
| 跨站 / 非 loopback | 无认证 `401`;`Host: evil.example.com`、`sec-fetch-site: cross-site`、外站 `Origin` 全部 `403` |
|
|
171
|
+
|
|
172
|
+
**实测抓出并修掉的三个真缺陷**(不是设计推测):
|
|
173
|
+
|
|
174
|
+
1. 伪造 `TASK.evidence.json` 里的 `manual` 判定,会让下一次对账把人工项判成通过。
|
|
175
|
+
→ 改成「人工通过只认本进程内存,永不读文件」;代价是重启后要重新点一次。
|
|
176
|
+
2. 这台机器没有 `pwsh`,插件回落到 Windows PowerShell 5.1,而 5.1 的 `-Command`
|
|
177
|
+
把任何非零退出码压成 1(`process.exit(7)` 报成 1)。→ 用 `exit $LASTEXITCODE` 精确透传。
|
|
178
|
+
3. 改了 `TASK.md` 的验收项句子后,内存里的旧判定仍在冒充当前结果(digest 校验只做在文件回放路径上)。
|
|
179
|
+
→ 抽出 `currentVerdict()` 统一判「内存是否还配当当前结果」,并补了离线用例。
|
|
180
|
+
|
|
181
|
+
**这一轮补上的实测缺口**:
|
|
182
|
+
|
|
183
|
+
- 轻提示那一行的实际渲染:已在真实 GUI 里用真草稿触发并截屏(上面两张图是真机截屏,不是设计稿)。
|
|
184
|
+
- 收尾行的截图**没抢到**:它每轮只在回答结束后渲染,而流式输出会把滚动位置自动拉回底部,
|
|
185
|
+
自动化截图拿不到那一帧的静态画面。渲染本身已经用肉眼验证(内容与样式都正确),
|
|
186
|
+
但 README 里这一块暂时只有文字示意,没有图——这是已知缺口。
|
|
187
|
+
- 仍然只在代码/离线层面成立、没在真实会话里跑过:`probe_intent action=ask` 的问答闭环(需要真人点一次)、
|
|
188
|
+
`gateWrites` 拦截(默认关)、只读沙箱下的降级(实测中途环境被切成了 danger-full-access)、
|
|
189
|
+
「补成一句能执行的话」按钮(会调 `ctx.llm.stream`)。
|
|
190
|
+
|
|
191
|
+
**没做的设计**:多任务(一个工作区同时挂多张清单)。做法可以考虑「保留单文件 + frontmatter 里多段任务」,
|
|
192
|
+
但 UI 要加清单选择器、收尾行要按任务分组、`planDigest` 要按任务切分——这不是加个字段,是加一层模型。
|
|
193
|
+
当前单文件单任务是刻意的:一个工作区任何时刻只有一个「这次要交付什么」,历史靠 git(`TASK.md` 进版本库)。
|
|
194
|
+
真需要多任务,更轻的路子是按任务开子目录,而不是把多份清单塞进一个文件。
|
|
195
|
+
|
|
196
|
+
## 三个必须回答的问题
|
|
197
|
+
|
|
198
|
+
### 模型能不能绕过对账?
|
|
199
|
+
|
|
200
|
+
| 绕法 | 堵住了吗 | 怎么堵 / 为什么堵不住 |
|
|
201
|
+
|---|---|---|
|
|
202
|
+
| 不生成清单,直接宣布完成 | **大部分** | 写操作 + 含糊度高 + 没有真清单时,插件在第一步之前就自己落一份占位骨架,收尾行写 `未达标:清单未建`;占位项不会被真的执行。堵不住的部分:模型仍然可以无视契约继续干,但它没法让「没有清单」这件事看起来像做完了 |
|
|
203
|
+
| 伪造证据(自己写 `TASK.evidence.json`) | **大部分** | 每次对账整份重写;`status`/UI 读插件内存而非文件;条目 digest + planDigest 让手改 `TASK.md` 使旧判定作废。堵不住的部分:有 shell 权限的模型仍可在两次对账之间改文件,只是下一次对账会冲掉 |
|
|
204
|
+
| 伪造「用户已点通过」的 manual 记录 | **是** | 人工判定只认本进程内存(只由 UI 路由写入),**从不读** `evidence.json` 里的 manual。这条是实测抓到的漏洞,已修 |
|
|
205
|
+
| 删掉「未达标:N 项」那行 | **是** | 那行不在模型输出里,是 `conversation.chat.turnTail` 里插件渲染的组件,模型没有写入通道 |
|
|
206
|
+
| 把未通过项改成「通过」再交 | **是** | `TASK.md` 的勾选由插件按判定回写;实测类项(command/file)人工不能改判;`reconcile` 工具没有 manual 动作 |
|
|
207
|
+
| 把断言改宽松(比如把「不出现横向滚动」改成「大致可用」) | **是** | `TASK.md` 内容一变,planDigest 与单条 digest 都对不上,旧判定整体作废、要求重新对账 |
|
|
208
|
+
|
|
209
|
+
**一句话**:模型能拖(不建清单、不调工具),但拖不掉「看起来做完了」;改不了证据与结论。
|
|
210
|
+
判定结果由插件算,产物由插件渲染。
|
|
211
|
+
|
|
212
|
+
### 只读沙箱下对账能力退化到什么程度?
|
|
213
|
+
|
|
214
|
+
| 证据类型 | 只读沙箱下的行为 |
|
|
215
|
+
|---|---|
|
|
216
|
+
| `command` | **不执行**,一律判「未验证」,原因写「当前会话是只读沙箱(read-only),命令未执行」 |
|
|
217
|
+
| `file` | 照常读、照常判(读不受限) |
|
|
218
|
+
| `manual` | 照常交给用户点通过 |
|
|
219
|
+
|
|
220
|
+
所以只读沙箱下剩下的能力是「文件断言 + 人工确认」。另外 `TASK.evidence.json` 也写不进去,
|
|
221
|
+
判定只留在本会话内存里,刷新页面后需要重新对账(这是刻意的:不写就是没证据,不是自动通过)。
|
|
222
|
+
|
|
223
|
+
### 零模型调用的边界
|
|
224
|
+
|
|
225
|
+
- 打分、候选、判定:**全部零模型调用**(纯函数 + 本地命令/文件读)。
|
|
226
|
+
- 唯一会调模型的是输入框旁「补成一句能执行的话」按钮:你点它才调,用当前会话的 `agentDefaultModel`,
|
|
227
|
+
走 `ctx.llm.stream`,结果只写回草稿(`inputActions.setDraft`),**从不替你发送**。
|
|
228
|
+
|
|
229
|
+
## 许可与来源
|
|
230
|
+
|
|
231
|
+
图标与文案为本插件原创。不含第三方素材。
|
package/client.js
CHANGED
|
@@ -16,6 +16,168 @@ window.__ModuleLoader__.load({
|
|
|
16
16
|
const { useCallback, useEffect, useMemo, useRef, useState } = React
|
|
17
17
|
|
|
18
18
|
const NS = 'reconcile'
|
|
19
|
+
|
|
20
|
+
// ==== score-copy:begin ====
|
|
21
|
+
// 客户端内联版含糊度打分:与 src/ambiguity.js 逻辑逐行等价(test/selfcheck.mjs 有对照测试守住)。
|
|
22
|
+
// 为什么要内联:这版宿主给插件 HTTP 路由套了会话鉴权,裸 fetch 会被 401,
|
|
23
|
+
// 而「输入框下面那一行」是零模型、零网络的纯计算,不该受鉴权影响。
|
|
24
|
+
const SIGNALS = Object.freeze([
|
|
25
|
+
{ id: 'deictic', delta: 18, label: '含指代词' },
|
|
26
|
+
{ id: 'noCriterion', delta: 15, label: '缺可判定标准' },
|
|
27
|
+
{ id: 'wideWrite', delta: 12, label: '写操作且目标文件数>3或不确定' },
|
|
28
|
+
{ id: 'topicShift', delta: 8, label: '与近期请求主题重合但目标不同' },
|
|
29
|
+
{ id: 'reworkHistory', delta: 15, label: '同类请求曾返工' },
|
|
30
|
+
{ id: 'tooShort', delta: 10, label: '请求极短(<12字)' },
|
|
31
|
+
{ id: 'namedDeliverable', delta: -10, label: '点名了交付物' },
|
|
32
|
+
{ id: 'acceptanceWords', delta: -20, label: '自带验收词' },
|
|
33
|
+
{ id: 'readOnly', delta: -15, label: '纯只读查询' },
|
|
34
|
+
])
|
|
35
|
+
const SIGNAL_BY_ID = new Map(SIGNALS.map((s) => [s.id, s]))
|
|
36
|
+
const RE_DEICTIC = /(那个|这个|那次|这次|上次|上回|老样子|同上|还是那个|还是上次|还是原来|那份|那条|那篇|那张|之前那|刚才那|原来那个|就那个文件)/u
|
|
37
|
+
const RE_WRITE = /(改成|改为|换成|替换|删掉|删除|去掉|加上|增加|新增|新建|创建|生成|实现|重构|迁移|拆分|合并|优化|调整|更新|修改|补充|接入|搭建|做个|做一个|做一下|写个|写一个|画个|整理|清理|修好|修复|跑一遍|跑一下|建个|弄个|搞个|改一?下|写一?下|加一?下)/u
|
|
38
|
+
const RE_WRITE_BARE = /(改|写|加|删|修|做|弄|搞|画|建|换|拆|补|跑)/u
|
|
39
|
+
const RE_READONLY = /(是什么|为什么|怎么|如何|在哪|哪里|有没有|是不是|能不能|解释|说明一下|看看|看一下|查一下|找一下|是多少|哪些|区别|对比一下|分析一下|总结一下|评估一下|评审|review|原理|工作方式|怎么用)/iu
|
|
40
|
+
const RE_IMPERATIVE = /(改成|改为|换成|替换成|删掉|删除|去掉|新增|生成|重构|创建|新建|搭建|合并|整理|清理|修复|补充|更新|调整|接入|做个|做一个|写个|写一个|画个|帮我把|请把|麻烦把|^把|^将)/u
|
|
41
|
+
const RE_DELIVERABLE = /(\.(md|markdown|txt|tsx?|jsx?|mjs|cjs|css|scss|less|json|ya?ml|toml|py|go|rs|java|kt|vue|svelte|html?|sql|sh|ps1|bat|png|jpe?g|webp|svg|pdf|docx?|xlsx?|pptx?)\b)/iu
|
|
42
|
+
const RE_DELIVERABLE_ZH = /(表格|幻灯片|演示文稿|截图|流程图|示意图|架构图|思维导图|简历|合同|周报|月报|报告|手册|说明书)/u
|
|
43
|
+
const RE_ACCEPTANCE = /(能跑通|跑得通|跑通|通过测试|测试通过|全部通过|不报错|不超过\s*\d+|不少于\s*\d+|至少\s*\d+|最多\s*\d+|必须包含|必须含|不得出现|不能出现|不要出现|验收|断言|覆盖率|无警告|零警告|可复现|可回滚)/u
|
|
44
|
+
const RE_TARGET_NUMBER = /\d/u
|
|
45
|
+
const RE_TARGET_PATH = /([A-Za-z0-9_.\-]+[\\/])?[A-Za-z0-9_.\-]+\.(md|markdown|txt|tsx?|jsx?|mjs|cjs|css|scss|less|json|ya?ml|toml|py|go|rs|java|kt|vue|svelte|html?|sql|sh|ps1|bat|png|jpe?g|webp|svg|pdf|docx?|xlsx?|pptx?)\b/iu
|
|
46
|
+
const RE_TARGET_QUOTED = /「[^」]{1,60}」|"[^"\n]{1,60}"|`[^`\n]{1,60}`/u
|
|
47
|
+
const RE_TARGET_CHANGE = /(改成|改为|换成|替换成|变成|写成|输出为|的格式|第\s*[一二三四五六七八九十百\d]+\s*(行|条|段|章|节|个))/u
|
|
48
|
+
const RE_BATCH = /(那批|这批|一批|所有|全部|每个|各个|这些文件|那些文件|都改|全改|批量|遍历|整个目录)/u
|
|
49
|
+
|
|
50
|
+
function scoreContentLength(text) {
|
|
51
|
+
return Array.from(String(text ?? '').replace(/[\s\u3000]/gu, '').replace(/[,。!?、;:""''()《》【】,.;:!?'"()<>\[\]]/gu, '')).length
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function scoreExtractTargets(text) {
|
|
55
|
+
const s = String(text ?? '')
|
|
56
|
+
const targets = []
|
|
57
|
+
for (const m of s.matchAll(new RegExp(RE_TARGET_PATH, 'giu'))) targets.push({ kind: 'path', value: m[0] })
|
|
58
|
+
for (const m of s.matchAll(new RegExp(RE_TARGET_QUOTED, 'gu'))) targets.push({ kind: 'quoted', value: m[0] })
|
|
59
|
+
if (RE_TARGET_NUMBER.test(s)) targets.push({ kind: 'number', value: (s.match(/\d+(?:\.\d+)?/u) ?? [''])[0] })
|
|
60
|
+
if (RE_TARGET_CHANGE.test(s)) targets.push({ kind: 'change', value: (s.match(RE_TARGET_CHANGE) ?? [''])[0] })
|
|
61
|
+
return targets
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function scoreTargetFileCount(text) {
|
|
65
|
+
const paths = new Set()
|
|
66
|
+
for (const m of String(text ?? '').matchAll(new RegExp(RE_TARGET_PATH, 'giu'))) paths.add(m[0].toLowerCase())
|
|
67
|
+
return paths.size
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function scoreBigrams(text) {
|
|
71
|
+
const s = String(text ?? '').replace(/[\s\u3000,。!?、;:""''()《》【】,.;:!?'"()<>]/gu, '')
|
|
72
|
+
const chars = Array.from(s)
|
|
73
|
+
const out = new Set()
|
|
74
|
+
for (let i = 0; i < chars.length - 1; i++) out.add(chars[i] + chars[i + 1])
|
|
75
|
+
return out
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function scoreJaccard(a, b) {
|
|
79
|
+
if (a.size === 0 || b.size === 0) return 0
|
|
80
|
+
let inter = 0
|
|
81
|
+
for (const v of a) if (b.has(v)) inter++
|
|
82
|
+
return inter / (a.size + b.size - inter)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function scoreNumberOr(value, fallback) {
|
|
86
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : fallback
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function scoreClamp(n, lo, hi) {
|
|
90
|
+
return Math.max(lo, Math.min(hi, n))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function scoreTopicShift(text, recentTexts) {
|
|
94
|
+
if (!Array.isArray(recentTexts) || recentTexts.length === 0) return false
|
|
95
|
+
const mine = scoreBigrams(text)
|
|
96
|
+
if (mine.size < 2) return false
|
|
97
|
+
for (const prev of recentTexts.slice(-4)) {
|
|
98
|
+
if (typeof prev !== 'string' || prev.length === 0) continue
|
|
99
|
+
if (scoreJaccard(mine, scoreBigrams(prev)) < 0.34) continue
|
|
100
|
+
const prevTargets = new Set(scoreExtractTargets(prev).map((t) => `${t.kind}:${t.value}`))
|
|
101
|
+
const mineTargets = new Set(scoreExtractTargets(text).map((t) => `${t.kind}:${t.value}`))
|
|
102
|
+
if (prevTargets.size === 0 && mineTargets.size === 0) continue
|
|
103
|
+
let same = 0
|
|
104
|
+
for (const t of mineTargets) if (prevTargets.has(t)) same++
|
|
105
|
+
if (same === 0) return true
|
|
106
|
+
}
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function scoreRequest(text, context = {}) {
|
|
111
|
+
const source = String(text ?? '')
|
|
112
|
+
const hits = []
|
|
113
|
+
const escalations = []
|
|
114
|
+
const hintThreshold = scoreNumberOr(context.hintThreshold, 40)
|
|
115
|
+
const panelThreshold = scoreNumberOr(context.panelThreshold, 70)
|
|
116
|
+
|
|
117
|
+
if (source.trim() === '') {
|
|
118
|
+
return {
|
|
119
|
+
raw: 0, value: 0, band: 'none', hits: [], escalations: [], chars: 0,
|
|
120
|
+
write: false, readOnly: false, zeroTargetWrite: false, deicticReference: false,
|
|
121
|
+
targets: [], hintThreshold, panelThreshold,
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const readonlyQuery = RE_READONLY.test(source) && !RE_IMPERATIVE.test(source)
|
|
126
|
+
const write = !readonlyQuery && (RE_WRITE.test(source) || RE_WRITE_BARE.test(source))
|
|
127
|
+
const readOnly = !write && RE_READONLY.test(source)
|
|
128
|
+
const targets = scoreExtractTargets(source)
|
|
129
|
+
const fileCount = scoreTargetFileCount(source)
|
|
130
|
+
const hasCriterion = targets.some((t) => t.kind === 'path' || t.kind === 'number' || t.kind === 'change')
|
|
131
|
+
const chars = scoreContentLength(source)
|
|
132
|
+
const deicticReference = RE_DEICTIC.test(source)
|
|
133
|
+
|
|
134
|
+
const push = (id, when) => {
|
|
135
|
+
if (!when) return
|
|
136
|
+
const s = SIGNAL_BY_ID.get(id)
|
|
137
|
+
hits.push({ id, label: s.label, delta: s.delta })
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
push('deictic', deicticReference)
|
|
141
|
+
push('noCriterion', !hasCriterion)
|
|
142
|
+
const batch = RE_BATCH.test(source)
|
|
143
|
+
push('wideWrite', write && (batch || fileCount > 3 || (fileCount === 0 && !hasCriterion)))
|
|
144
|
+
push('topicShift', scoreTopicShift(source, context.recentTexts ?? []))
|
|
145
|
+
push('reworkHistory', (context.reworkCount ?? 0) > 0)
|
|
146
|
+
push('tooShort', chars > 0 && chars < 12)
|
|
147
|
+
push('namedDeliverable', RE_DELIVERABLE.test(source) || RE_DELIVERABLE_ZH.test(source))
|
|
148
|
+
push('acceptanceWords', RE_ACCEPTANCE.test(source))
|
|
149
|
+
push('readOnly', readOnly)
|
|
150
|
+
|
|
151
|
+
const raw = scoreClamp(hits.reduce((sum, h) => sum + h.delta, 0), 0, 100)
|
|
152
|
+
const zeroTargetWrite = write && !hasCriterion && fileCount === 0
|
|
153
|
+
const esEnabled = context.escalations ?? { zeroTargetWrite: true, deicticReference: true }
|
|
154
|
+
if (esEnabled.zeroTargetWrite !== false && zeroTargetWrite && !deicticReference) {
|
|
155
|
+
escalations.push({ id: 'zeroTargetWrite', label: '零目标写操作', reason: '是写操作,但没点名任何文件/数字/「改成X」形式的具体目标' })
|
|
156
|
+
}
|
|
157
|
+
if (esEnabled.deicticReference !== false && deicticReference && raw >= hintThreshold) {
|
|
158
|
+
escalations.push({ id: 'deicticReference', label: '指代 + 已达提示线', reason: '用指代词指向某个东西,且含糊度已过提示线:必须先核事实再问,不能直接动手' })
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let band = 'none'
|
|
162
|
+
if (raw > panelThreshold) band = 'panel'
|
|
163
|
+
else if (raw >= hintThreshold) band = 'hint'
|
|
164
|
+
if (escalations.length > 0) band = 'panel'
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
raw, value: raw, band, hits, escalations, chars, write, readOnly,
|
|
168
|
+
zeroTargetWrite, deicticReference, targets, hintThreshold, panelThreshold,
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function formatScore(result) {
|
|
173
|
+
if (!result) return '含糊度:无'
|
|
174
|
+
const parts = result.hits.map((h) => `${h.delta > 0 ? '+' : ''}${h.delta} ${h.label}`)
|
|
175
|
+
const body = parts.length > 0 ? parts.join(' · ') : '无信号'
|
|
176
|
+
const esc = result.escalations.length > 0 ? ` 〔升级:${result.escalations.map((e) => e.label).join('、')}〕` : ''
|
|
177
|
+
const band = { none: '不打断', hint: '轻提示', panel: '弹面板' }[result.band] ?? result.band
|
|
178
|
+
return `含糊度 ${result.raw}(${body})${esc} → ${band}`
|
|
179
|
+
}
|
|
180
|
+
// ==== score-copy:end ====
|
|
19
181
|
const API = '/api/dsh-reconcile'
|
|
20
182
|
|
|
21
183
|
const zh = {
|
|
@@ -39,6 +201,8 @@ window.__ModuleLoader__.load({
|
|
|
39
201
|
skeletonPending: '清单只有占位项,补 1 条真实验收项才算开始。',
|
|
40
202
|
stale: '清单已变更,需重新对账',
|
|
41
203
|
scoreLabel: '含糊度',
|
|
204
|
+
scoreFailed: '评分请求失败',
|
|
205
|
+
stateFailed: '读取对账状态失败',
|
|
42
206
|
bandNone: '不打断',
|
|
43
207
|
hintAsk: '帮我问清楚',
|
|
44
208
|
probeAndAsk: '先查再问',
|
|
@@ -75,6 +239,8 @@ window.__ModuleLoader__.load({
|
|
|
75
239
|
skeletonPending: 'The ledger only has placeholders; add at least one real acceptance item to begin.',
|
|
76
240
|
stale: 'The ledger changed; re-check required',
|
|
77
241
|
scoreLabel: 'Ambiguity',
|
|
242
|
+
scoreFailed: 'scoring request failed',
|
|
243
|
+
stateFailed: 'could not read reconciliation state',
|
|
78
244
|
bandNone: 'no interruption',
|
|
79
245
|
hintAsk: 'Help me clarify',
|
|
80
246
|
probeAndAsk: 'Look first, then ask',
|
|
@@ -341,7 +507,12 @@ window.__ModuleLoader__.load({
|
|
|
341
507
|
}
|
|
342
508
|
}, [sessionId, load, state])
|
|
343
509
|
|
|
344
|
-
if (!state)
|
|
510
|
+
if (!state) {
|
|
511
|
+
// 读取失败时不能再静默:否则「交账那一行不见了」和「没有清单」长得一样
|
|
512
|
+
return error
|
|
513
|
+
? h('div', { style: S.error, 'data-dsh-plugin': 'dsh-reconcile' }, `${t('stateFailed')}:${error}`)
|
|
514
|
+
: null
|
|
515
|
+
}
|
|
345
516
|
const verdict = state.verdict
|
|
346
517
|
const task = state.task
|
|
347
518
|
if (!task && !(state.score && state.score.band === 'panel')) return null
|
|
@@ -456,13 +627,8 @@ window.__ModuleLoader__.load({
|
|
|
456
627
|
useEffect(() => {
|
|
457
628
|
const text = draft.trim()
|
|
458
629
|
if (text === '') { setScore(null); setProbe(null); setError(null); return }
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
void postJson('/score', { text, sessionId })
|
|
462
|
-
.then((data) => { if (!cancelled && alive.current) { setScore(data?.score ?? null); setError(null) } })
|
|
463
|
-
.catch(() => { /* 打分失败就静默:绝不打断输入 */ })
|
|
464
|
-
}, 320)
|
|
465
|
-
return () => { cancelled = true; clearTimeout(timer) }
|
|
630
|
+
// 纯本地计算:不依赖 HTTP(宿主对插件路由套了会话鉴权,裸 fetch 会 401)
|
|
631
|
+
if (alive.current) { setScore(scoreRequest(text)); setError(null) }
|
|
466
632
|
}, [draft, sessionId])
|
|
467
633
|
|
|
468
634
|
const runProbe = useCallback(async () => {
|
|
@@ -526,14 +692,13 @@ window.__ModuleLoader__.load({
|
|
|
526
692
|
if (!hasText) return null
|
|
527
693
|
const showScore = Boolean(score && score.band !== 'none' && score.raw > 0)
|
|
528
694
|
if (!showScore) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
695
|
+
const label = error
|
|
696
|
+
? `${t('scoreFailed')}:${error}`
|
|
697
|
+
: score
|
|
698
|
+
? `${t('scoreLabel')} ${score.raw} · ${t('bandNone')}`
|
|
699
|
+
: `${t('scoreLabel')} …`
|
|
532
700
|
return h('div', { style: S.hintRow, 'data-dsh-plugin': 'dsh-reconcile' },
|
|
533
|
-
|
|
534
|
-
? h('span', { style: { color: T.muted, fontSize: 11 } },
|
|
535
|
-
`${t('scoreLabel')} ${score.raw} · ${t('bandNone')}`)
|
|
536
|
-
: null,
|
|
701
|
+
h('span', { style: { color: error ? T.danger : T.muted, fontSize: 11 } }, label),
|
|
537
702
|
notice ? h('span', { style: { color: T.ok, fontSize: 11.5 } }, `✓ ${notice}`) : null,
|
|
538
703
|
)
|
|
539
704
|
}
|
|
@@ -607,13 +772,7 @@ window.__ModuleLoader__.load({
|
|
|
607
772
|
useEffect(() => {
|
|
608
773
|
const text = draft.trim()
|
|
609
774
|
if (text === '') { setScore(null); return }
|
|
610
|
-
|
|
611
|
-
const timer = setTimeout(() => {
|
|
612
|
-
void postJson('/score', { text, sessionId })
|
|
613
|
-
.then((data) => { if (!cancelled && alive.current) setScore(data?.score ?? null) })
|
|
614
|
-
.catch(() => { /* 打分失败静默 */ })
|
|
615
|
-
}, 320)
|
|
616
|
-
return () => { cancelled = true; clearTimeout(timer) }
|
|
775
|
+
if (alive.current) setScore(scoreRequest(text))
|
|
617
776
|
}, [draft, sessionId])
|
|
618
777
|
|
|
619
778
|
const rewrite = useCallback(async () => {
|
|
@@ -633,7 +792,11 @@ window.__ModuleLoader__.load({
|
|
|
633
792
|
}
|
|
634
793
|
}, [draft, inputActions, sessionId])
|
|
635
794
|
|
|
636
|
-
if (!score)
|
|
795
|
+
if (!score) {
|
|
796
|
+
return hasText
|
|
797
|
+
? h('span', { style: { color: T.muted, fontSize: 11 }, 'data-dsh-plugin': 'dsh-reconcile' }, `${t('scoreLabel')} …`)
|
|
798
|
+
: null
|
|
799
|
+
}
|
|
637
800
|
// 与输入框下方那排保持同一规则:有文字就一定有一行读数,只是分数低时不带按钮。
|
|
638
801
|
if (score.band === 'none' || score.raw <= 0) {
|
|
639
802
|
return h('span', { style: { color: T.muted, fontSize: 11 }, 'data-dsh-plugin': 'dsh-reconcile' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-reconcile",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "交账 — fact-first clarification, heuristic ambiguity scoring, and an evidence-backed end-of-task reconciliation ledger",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,11 +52,15 @@
|
|
|
52
52
|
"test": "node test/selfcheck.mjs"
|
|
53
53
|
},
|
|
54
54
|
"dsh": {
|
|
55
|
-
"bundle": {
|
|
55
|
+
"bundle": {
|
|
56
|
+
"patch": "./cordis.patch.yml"
|
|
57
|
+
},
|
|
56
58
|
"client": {
|
|
57
59
|
"platform": "web",
|
|
58
60
|
"immediately": true,
|
|
59
|
-
"inject": [
|
|
61
|
+
"inject": [
|
|
62
|
+
"@deepseek-ai/dsh-client-ui-conversation"
|
|
63
|
+
]
|
|
60
64
|
}
|
|
61
65
|
},
|
|
62
66
|
"publishConfig": {
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// ==== score-copy:begin ====
|
|
2
|
+
// 客户端内联版含糊度打分:与 src/ambiguity.js 逻辑逐行等价(test/selfcheck.mjs 有对照测试守住)。
|
|
3
|
+
// 为什么要内联:这版宿主给插件 HTTP 路由套了会话鉴权,裸 fetch 会被 401,
|
|
4
|
+
// 而「输入框下面那一行」是零模型、零网络的纯计算,不该受鉴权影响。
|
|
5
|
+
const SIGNALS = Object.freeze([
|
|
6
|
+
{ id: 'deictic', delta: 18, label: '含指代词' },
|
|
7
|
+
{ id: 'noCriterion', delta: 15, label: '缺可判定标准' },
|
|
8
|
+
{ id: 'wideWrite', delta: 12, label: '写操作且目标文件数>3或不确定' },
|
|
9
|
+
{ id: 'topicShift', delta: 8, label: '与近期请求主题重合但目标不同' },
|
|
10
|
+
{ id: 'reworkHistory', delta: 15, label: '同类请求曾返工' },
|
|
11
|
+
{ id: 'tooShort', delta: 10, label: '请求极短(<12字)' },
|
|
12
|
+
{ id: 'namedDeliverable', delta: -10, label: '点名了交付物' },
|
|
13
|
+
{ id: 'acceptanceWords', delta: -20, label: '自带验收词' },
|
|
14
|
+
{ id: 'readOnly', delta: -15, label: '纯只读查询' },
|
|
15
|
+
])
|
|
16
|
+
const SIGNAL_BY_ID = new Map(SIGNALS.map((s) => [s.id, s]))
|
|
17
|
+
const RE_DEICTIC = /(那个|这个|那次|这次|上次|上回|老样子|同上|还是那个|还是上次|还是原来|那份|那条|那篇|那张|之前那|刚才那|原来那个|就那个文件)/u
|
|
18
|
+
const RE_WRITE = /(改成|改为|换成|替换|删掉|删除|去掉|加上|增加|新增|新建|创建|生成|实现|重构|迁移|拆分|合并|优化|调整|更新|修改|补充|接入|搭建|做个|做一个|做一下|写个|写一个|画个|整理|清理|修好|修复|跑一遍|跑一下|建个|弄个|搞个|改一?下|写一?下|加一?下)/u
|
|
19
|
+
const RE_WRITE_BARE = /(改|写|加|删|修|做|弄|搞|画|建|换|拆|补|跑)/u
|
|
20
|
+
const RE_READONLY = /(是什么|为什么|怎么|如何|在哪|哪里|有没有|是不是|能不能|解释|说明一下|看看|看一下|查一下|找一下|是多少|哪些|区别|对比一下|分析一下|总结一下|评估一下|评审|review|原理|工作方式|怎么用)/iu
|
|
21
|
+
const RE_IMPERATIVE = /(改成|改为|换成|替换成|删掉|删除|去掉|新增|生成|重构|创建|新建|搭建|合并|整理|清理|修复|补充|更新|调整|接入|做个|做一个|写个|写一个|画个|帮我把|请把|麻烦把|^把|^将)/u
|
|
22
|
+
const RE_DELIVERABLE = /(\.(md|markdown|txt|tsx?|jsx?|mjs|cjs|css|scss|less|json|ya?ml|toml|py|go|rs|java|kt|vue|svelte|html?|sql|sh|ps1|bat|png|jpe?g|webp|svg|pdf|docx?|xlsx?|pptx?)\b)/iu
|
|
23
|
+
const RE_DELIVERABLE_ZH = /(表格|幻灯片|演示文稿|截图|流程图|示意图|架构图|思维导图|简历|合同|周报|月报|报告|手册|说明书)/u
|
|
24
|
+
const RE_ACCEPTANCE = /(能跑通|跑得通|跑通|通过测试|测试通过|全部通过|不报错|不超过\s*\d+|不少于\s*\d+|至少\s*\d+|最多\s*\d+|必须包含|必须含|不得出现|不能出现|不要出现|验收|断言|覆盖率|无警告|零警告|可复现|可回滚)/u
|
|
25
|
+
const RE_TARGET_NUMBER = /\d/u
|
|
26
|
+
const RE_TARGET_PATH = /([A-Za-z0-9_.\-]+[\\/])?[A-Za-z0-9_.\-]+\.(md|markdown|txt|tsx?|jsx?|mjs|cjs|css|scss|less|json|ya?ml|toml|py|go|rs|java|kt|vue|svelte|html?|sql|sh|ps1|bat|png|jpe?g|webp|svg|pdf|docx?|xlsx?|pptx?)\b/iu
|
|
27
|
+
const RE_TARGET_QUOTED = /「[^」]{1,60}」|"[^"\n]{1,60}"|`[^`\n]{1,60}`/u
|
|
28
|
+
const RE_TARGET_CHANGE = /(改成|改为|换成|替换成|变成|写成|输出为|的格式|第\s*[一二三四五六七八九十百\d]+\s*(行|条|段|章|节|个))/u
|
|
29
|
+
const RE_BATCH = /(那批|这批|一批|所有|全部|每个|各个|这些文件|那些文件|都改|全改|批量|遍历|整个目录)/u
|
|
30
|
+
|
|
31
|
+
function scoreContentLength(text) {
|
|
32
|
+
return Array.from(String(text ?? '').replace(/[\s\u3000]/gu, '').replace(/[,。!?、;:""''()《》【】,.;:!?'"()<>\[\]]/gu, '')).length
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function scoreExtractTargets(text) {
|
|
36
|
+
const s = String(text ?? '')
|
|
37
|
+
const targets = []
|
|
38
|
+
for (const m of s.matchAll(new RegExp(RE_TARGET_PATH, 'giu'))) targets.push({ kind: 'path', value: m[0] })
|
|
39
|
+
for (const m of s.matchAll(new RegExp(RE_TARGET_QUOTED, 'gu'))) targets.push({ kind: 'quoted', value: m[0] })
|
|
40
|
+
if (RE_TARGET_NUMBER.test(s)) targets.push({ kind: 'number', value: (s.match(/\d+(?:\.\d+)?/u) ?? [''])[0] })
|
|
41
|
+
if (RE_TARGET_CHANGE.test(s)) targets.push({ kind: 'change', value: (s.match(RE_TARGET_CHANGE) ?? [''])[0] })
|
|
42
|
+
return targets
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function scoreTargetFileCount(text) {
|
|
46
|
+
const paths = new Set()
|
|
47
|
+
for (const m of String(text ?? '').matchAll(new RegExp(RE_TARGET_PATH, 'giu'))) paths.add(m[0].toLowerCase())
|
|
48
|
+
return paths.size
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function scoreBigrams(text) {
|
|
52
|
+
const s = String(text ?? '').replace(/[\s\u3000,。!?、;:""''()《》【】,.;:!?'"()<>]/gu, '')
|
|
53
|
+
const chars = Array.from(s)
|
|
54
|
+
const out = new Set()
|
|
55
|
+
for (let i = 0; i < chars.length - 1; i++) out.add(chars[i] + chars[i + 1])
|
|
56
|
+
return out
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function scoreJaccard(a, b) {
|
|
60
|
+
if (a.size === 0 || b.size === 0) return 0
|
|
61
|
+
let inter = 0
|
|
62
|
+
for (const v of a) if (b.has(v)) inter++
|
|
63
|
+
return inter / (a.size + b.size - inter)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function scoreNumberOr(value, fallback) {
|
|
67
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : fallback
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function scoreClamp(n, lo, hi) {
|
|
71
|
+
return Math.max(lo, Math.min(hi, n))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function scoreTopicShift(text, recentTexts) {
|
|
75
|
+
if (!Array.isArray(recentTexts) || recentTexts.length === 0) return false
|
|
76
|
+
const mine = scoreBigrams(text)
|
|
77
|
+
if (mine.size < 2) return false
|
|
78
|
+
for (const prev of recentTexts.slice(-4)) {
|
|
79
|
+
if (typeof prev !== 'string' || prev.length === 0) continue
|
|
80
|
+
if (scoreJaccard(mine, scoreBigrams(prev)) < 0.34) continue
|
|
81
|
+
const prevTargets = new Set(scoreExtractTargets(prev).map((t) => `${t.kind}:${t.value}`))
|
|
82
|
+
const mineTargets = new Set(scoreExtractTargets(text).map((t) => `${t.kind}:${t.value}`))
|
|
83
|
+
if (prevTargets.size === 0 && mineTargets.size === 0) continue
|
|
84
|
+
let same = 0
|
|
85
|
+
for (const t of mineTargets) if (prevTargets.has(t)) same++
|
|
86
|
+
if (same === 0) return true
|
|
87
|
+
}
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function scoreRequest(text, context = {}) {
|
|
92
|
+
const source = String(text ?? '')
|
|
93
|
+
const hits = []
|
|
94
|
+
const escalations = []
|
|
95
|
+
const hintThreshold = scoreNumberOr(context.hintThreshold, 40)
|
|
96
|
+
const panelThreshold = scoreNumberOr(context.panelThreshold, 70)
|
|
97
|
+
|
|
98
|
+
if (source.trim() === '') {
|
|
99
|
+
return {
|
|
100
|
+
raw: 0, value: 0, band: 'none', hits: [], escalations: [], chars: 0,
|
|
101
|
+
write: false, readOnly: false, zeroTargetWrite: false, deicticReference: false,
|
|
102
|
+
targets: [], hintThreshold, panelThreshold,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const readonlyQuery = RE_READONLY.test(source) && !RE_IMPERATIVE.test(source)
|
|
107
|
+
const write = !readonlyQuery && (RE_WRITE.test(source) || RE_WRITE_BARE.test(source))
|
|
108
|
+
const readOnly = !write && RE_READONLY.test(source)
|
|
109
|
+
const targets = scoreExtractTargets(source)
|
|
110
|
+
const fileCount = scoreTargetFileCount(source)
|
|
111
|
+
const hasCriterion = targets.some((t) => t.kind === 'path' || t.kind === 'number' || t.kind === 'change')
|
|
112
|
+
const chars = scoreContentLength(source)
|
|
113
|
+
const deicticReference = RE_DEICTIC.test(source)
|
|
114
|
+
|
|
115
|
+
const push = (id, when) => {
|
|
116
|
+
if (!when) return
|
|
117
|
+
const s = SIGNAL_BY_ID.get(id)
|
|
118
|
+
hits.push({ id, label: s.label, delta: s.delta })
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
push('deictic', deicticReference)
|
|
122
|
+
push('noCriterion', !hasCriterion)
|
|
123
|
+
const batch = RE_BATCH.test(source)
|
|
124
|
+
push('wideWrite', write && (batch || fileCount > 3 || (fileCount === 0 && !hasCriterion)))
|
|
125
|
+
push('topicShift', scoreTopicShift(source, context.recentTexts ?? []))
|
|
126
|
+
push('reworkHistory', (context.reworkCount ?? 0) > 0)
|
|
127
|
+
push('tooShort', chars > 0 && chars < 12)
|
|
128
|
+
push('namedDeliverable', RE_DELIVERABLE.test(source) || RE_DELIVERABLE_ZH.test(source))
|
|
129
|
+
push('acceptanceWords', RE_ACCEPTANCE.test(source))
|
|
130
|
+
push('readOnly', readOnly)
|
|
131
|
+
|
|
132
|
+
const raw = scoreClamp(hits.reduce((sum, h) => sum + h.delta, 0), 0, 100)
|
|
133
|
+
const zeroTargetWrite = write && !hasCriterion && fileCount === 0
|
|
134
|
+
const esEnabled = context.escalations ?? { zeroTargetWrite: true, deicticReference: true }
|
|
135
|
+
if (esEnabled.zeroTargetWrite !== false && zeroTargetWrite && !deicticReference) {
|
|
136
|
+
escalations.push({ id: 'zeroTargetWrite', label: '零目标写操作', reason: '是写操作,但没点名任何文件/数字/「改成X」形式的具体目标' })
|
|
137
|
+
}
|
|
138
|
+
if (esEnabled.deicticReference !== false && deicticReference && raw >= hintThreshold) {
|
|
139
|
+
escalations.push({ id: 'deicticReference', label: '指代 + 已达提示线', reason: '用指代词指向某个东西,且含糊度已过提示线:必须先核事实再问,不能直接动手' })
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let band = 'none'
|
|
143
|
+
if (raw > panelThreshold) band = 'panel'
|
|
144
|
+
else if (raw >= hintThreshold) band = 'hint'
|
|
145
|
+
if (escalations.length > 0) band = 'panel'
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
raw, value: raw, band, hits, escalations, chars, write, readOnly,
|
|
149
|
+
zeroTargetWrite, deicticReference, targets, hintThreshold, panelThreshold,
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function formatScore(result) {
|
|
154
|
+
if (!result) return '含糊度:无'
|
|
155
|
+
const parts = result.hits.map((h) => `${h.delta > 0 ? '+' : ''}${h.delta} ${h.label}`)
|
|
156
|
+
const body = parts.length > 0 ? parts.join(' · ') : '无信号'
|
|
157
|
+
const esc = result.escalations.length > 0 ? ` 〔升级:${result.escalations.map((e) => e.label).join('、')}〕` : ''
|
|
158
|
+
const band = { none: '不打断', hint: '轻提示', panel: '弹面板' }[result.band] ?? result.band
|
|
159
|
+
return `含糊度 ${result.raw}(${body})${esc} → ${band}`
|
|
160
|
+
}
|
|
161
|
+
// ==== score-copy:end ====
|
package/test/selfcheck.mjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import assert from 'node:assert/strict'
|
|
7
7
|
import path from 'node:path'
|
|
8
|
+
import { readFileSync } from 'node:fs'
|
|
8
9
|
|
|
9
10
|
import { SIGNALS, scoreRequest, formatScore, contentLength, extractTargets, bandOf, textSimilarity } from '../src/ambiguity.js'
|
|
10
11
|
import {
|
|
@@ -854,6 +855,61 @@ x
|
|
|
854
855
|
})
|
|
855
856
|
}
|
|
856
857
|
|
|
858
|
+
/* --------------------- 8. 客户端内联打分器与宿主一致 --------------------- */
|
|
859
|
+
{
|
|
860
|
+
// client.js 里的 score-copy 块是宿主打分器的镜像(因为宿主给插件路由套了会话鉴权,
|
|
861
|
+
// 裸 fetch 会 401,输入框下面那行不能依赖 HTTP)。这里现场求值并逐项对拍,防止两份漂移。
|
|
862
|
+
const clientSource = readFileSync(new URL('../client.js', import.meta.url), 'utf8')
|
|
863
|
+
const begin = clientSource.indexOf('// ==== score-copy:begin ====')
|
|
864
|
+
const end = clientSource.indexOf('// ==== score-copy:end ====')
|
|
865
|
+
test('客户端打分器:标记块存在', () => {
|
|
866
|
+
assert.ok(begin >= 0 && end > begin, 'client.js 缺少 score-copy 标记块')
|
|
867
|
+
})
|
|
868
|
+
const loadClientScorer = () => {
|
|
869
|
+
const block = clientSource.slice(begin, end)
|
|
870
|
+
// eslint-disable-next-line no-new-func -- 测试里现场求值,正是为了比对两份实现
|
|
871
|
+
return new Function(`${block}\nreturn { scoreRequest, formatScore }`)()
|
|
872
|
+
}
|
|
873
|
+
const CORPUS = [
|
|
874
|
+
'改一下那个页面',
|
|
875
|
+
'ui咋成这样了改一下',
|
|
876
|
+
'A,ui咋成这样了改一下',
|
|
877
|
+
'帮我做个页面',
|
|
878
|
+
'打开那个页面',
|
|
879
|
+
'帮我打开页面',
|
|
880
|
+
'把 src/pages/index.tsx 第 12 行的 minWidth 改成 0',
|
|
881
|
+
'把 src 下面那批文件都改成新结构',
|
|
882
|
+
'生成一份 README.md',
|
|
883
|
+
'生成一份表格',
|
|
884
|
+
'这个模块是怎么工作的',
|
|
885
|
+
'这个函数是怎么实现的',
|
|
886
|
+
'加个按钮,要求不超过 200 字并且必须包含图标',
|
|
887
|
+
'再来一次',
|
|
888
|
+
'改吧',
|
|
889
|
+
'老样子,同上',
|
|
890
|
+
'把上次那份数据整理一下导出成 xlsx',
|
|
891
|
+
'重构整个项目',
|
|
892
|
+
'解释一下「零模型调用」是什么意思',
|
|
893
|
+
'',
|
|
894
|
+
]
|
|
895
|
+
test('客户端打分器:与宿主逐项一致(raw / band / hits / escalations / chars)', () => {
|
|
896
|
+
const client = loadClientScorer()
|
|
897
|
+
for (const text of CORPUS) {
|
|
898
|
+
for (const ctx of [{}, { reworkCount: 2 }, { recentTexts: ['改一下那个页面'] }]) {
|
|
899
|
+
const a = scoreRequest(text, ctx)
|
|
900
|
+
const b = client.scoreRequest(text, ctx)
|
|
901
|
+
const label = `${JSON.stringify(text)} ctx=${JSON.stringify(ctx)}`
|
|
902
|
+
assert.equal(b.raw, a.raw, `raw 不一致:${label}`)
|
|
903
|
+
assert.equal(b.band, a.band, `band 不一致:${label}`)
|
|
904
|
+
assert.equal(b.chars, a.chars, `chars 不一致:${label}`)
|
|
905
|
+
assert.deepEqual(b.hits, a.hits, `hits 不一致:${label}`)
|
|
906
|
+
assert.deepEqual(b.escalations, a.escalations, `escalations 不一致:${label}`)
|
|
907
|
+
assert.equal(client.formatScore(b), formatScore(a), `formatScore 不一致:${label}`)
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
})
|
|
911
|
+
}
|
|
912
|
+
|
|
857
913
|
/* -------------------------------- 汇总 -------------------------------- */
|
|
858
914
|
const total = passed + failed
|
|
859
915
|
console.log(`\n自检:${passed}/${total} 通过${failed > 0 ? `,${failed} 失败` : ''}`)
|
|
@@ -863,4 +919,4 @@ if (failed > 0) {
|
|
|
863
919
|
}
|
|
864
920
|
process.exit(1)
|
|
865
921
|
}
|
|
866
|
-
console.log('全绿。覆盖:打分表 16 项 · TASK.md 解析/回写 14 项 · 证据判定 16 项 · 覆盖与防伪造 13 项 · 骨架与返工 4 项 · 跨站 8 项 · 候选排序 7 项')
|
|
922
|
+
console.log('全绿。覆盖:打分表 16 项 · TASK.md 解析/回写 14 项 · 证据判定 16 项 · 覆盖与防伪造 13 项 · 骨架与返工 4 项 · 跨站 8 项 · 候选排序 7 项 · 客户端打分器对拍 2 项')
|