dsh-reconcile 0.1.3 → 0.1.5
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 +41 -6
- package/client.js +19 -0
- package/cordis.patch.yml +5 -1
- package/index.js +109 -20
- package/package.json +3 -1
- package/src/ambiguity.js +28 -0
- package/src/probe.js +191 -0
- package/test/acceptance-intake.mjs +90 -0
- package/test/client-smoke.mjs +176 -0
- package/test/selfcheck.mjs +59 -4
package/README.md
CHANGED
|
@@ -42,7 +42,12 @@ DeepSeek Harness 插件:**先核事实、再决定问不问、收工对账**
|
|
|
42
42
|
|
|
43
43
|
- **先核事实**:查 git 最近改动 / mtime 前 10 / 本会话引用过的路径 / 页面目录与路由表,给 2~3 个带证据的候选;
|
|
44
44
|
查不到才退化成开放问题(选项最后一项固定「我不知道,你替我定」)。
|
|
45
|
-
|
|
45
|
+
提问不只问「哪个目标」:`action=ask` 会按任务类型补问**效果维度**——动画问风格/节奏、页面问视觉方向/适配目标、
|
|
46
|
+
文档问受众/篇幅、代码问改动范围/验收方式(认不出类型就问交付物/验收标准),总共最多 3 个问题。
|
|
47
|
+
问完返回 `completedPrompt`:把用户原话 + 选中目标 + 维度答案拼成一段**可直接执行**的提示词,后续按它执行。
|
|
48
|
+
- **含糊度打分**:10 条信号固定加减分,夹到 0~100;`<40` 不打断、`40~70` 轻提示、`>70` 先问再动手。
|
|
49
|
+
第 10 条是 `疑似乱码/无实际意图 +15`:无中文、无常见英文词、字母 ≥ 8,且字符多样性 < 0.5 或元音比例 < 0.25 时命中。
|
|
50
|
+
它**只让读数诚实,不足以打断**(乱码 30 分仍在不打断区),也不会误伤 `fix the login bug` 这类正常英文或中文请求。
|
|
46
51
|
每次打分把命中的信号与分值写进会话日志。
|
|
47
52
|
上一轮对账有未达标、这一轮又提同一件事(bigram 相似 ≥ 0.34)时记一次返工,供 `+15 同类请求曾返工` 使用。
|
|
48
53
|
- **收工对账**:`TASK.md` 写「目标 / 关键约束 / 3~7 条可判定真假的验收项(command / file / manual)」;
|
|
@@ -66,11 +71,11 @@ DeepSeek Harness 插件:**先核事实、再决定问不问、收工对账**
|
|
|
66
71
|
|
|
67
72
|
## 安装
|
|
68
73
|
|
|
69
|
-
**从 npm 装(已发布 0.1.
|
|
74
|
+
**从 npm 装(已发布 0.1.3):**
|
|
70
75
|
|
|
71
76
|
```bash
|
|
72
77
|
dsh plugin --profile web add dsh-reconcile
|
|
73
|
-
dsh plugin --profile web add dsh-reconcile@0.1.
|
|
78
|
+
dsh plugin --profile web add dsh-reconcile@0.1.3 # 钉版本
|
|
74
79
|
```
|
|
75
80
|
|
|
76
81
|
npm 包页:<https://www.npmjs.com/package/dsh-reconcile>
|
|
@@ -135,11 +140,13 @@ TASK.evidence.json
|
|
|
135
140
|
## 自检(离线,不联网、不启宿主)
|
|
136
141
|
|
|
137
142
|
```sh
|
|
138
|
-
node test/selfcheck.mjs
|
|
143
|
+
node test/selfcheck.mjs # 90 项:打分表 / TASK.md / 三种证据判定 / 覆盖与防伪造 / 跨站 / 候选 / 对拍 / 护栏 / 任务维度提问
|
|
144
|
+
node test/acceptance-intake.mjs # 乱码信号 + 维度提问的独立验收(TASK.md 用它当 command 证据)
|
|
145
|
+
node test/client-smoke.mjs # 客户端冒烟:桩 React 里真渲染三个组件(抓「组件体引用未定义变量」这类运行时崩溃)
|
|
139
146
|
```
|
|
140
147
|
|
|
141
|
-
当前:**
|
|
142
|
-
evidence 覆盖与防伪造 13 项、骨架与返工 4 项、跨站拒绝 8 项、候选排序 7 项。
|
|
148
|
+
当前:**90/90 全绿**,客户端冒烟 **10/10 场景**通过。覆盖打分表 16 项、TASK.md 解析/回写 14 项、三种证据判定 16 项、
|
|
149
|
+
evidence 覆盖与防伪造 13 项、骨架与返工 4 项、跨站拒绝 8 项、候选排序 7 项、客户端打分器对拍 2 项、作用域护栏 1 项、任务维度提问 8 项。
|
|
143
150
|
|
|
144
151
|
没有 `node` 的机器上,可以用 DSH 自带的 Electron 当 node:
|
|
145
152
|
|
|
@@ -148,6 +155,34 @@ $env:ELECTRON_RUN_AS_NODE='1'
|
|
|
148
155
|
& "$env:DSH_NODE_EXECUTABLE" test/selfcheck.mjs
|
|
149
156
|
```
|
|
150
157
|
|
|
158
|
+
### 写 `command` 证据时注意(Windows)
|
|
159
|
+
|
|
160
|
+
插件起命令走 `ctx.subprocess`,Windows 上落到 **PowerShell 5.1**:**不支持 `&&`**,写了会直接报
|
|
161
|
+
`ParentContainsErrorRecordException`。要串多条命令用分号,并把退出码显式传出去:
|
|
162
|
+
|
|
163
|
+
```yaml
|
|
164
|
+
# ✅ PowerShell 5.1 可移植
|
|
165
|
+
- [ ] A1 语法检查通过 | 证据: command `node --check index.js; if ($LASTEXITCODE -ne 0) { exit 1 }; node --check client.js`
|
|
166
|
+
# ❌ 5.1 里 && 不是连接符
|
|
167
|
+
- [ ] A1 语法检查通过 | 证据: command `node --check index.js && node --check client.js`
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 日志
|
|
171
|
+
|
|
172
|
+
关键路径都有结构化日志(`ctx.logger`,缺省降级到 `warn`,日志失败绝不影响主流程):
|
|
173
|
+
|
|
174
|
+
| 时机 | 级别 | 内容 |
|
|
175
|
+
|---|---|---|
|
|
176
|
+
| `apply()` 结束 | info | `ready` —— 版本号、阈值、gateWrites/autoCheck/routes 开关 |
|
|
177
|
+
| 路由挂载成功 | info | `routes mounted (N)` + 路由路径列表 |
|
|
178
|
+
| `connection.fetch` 不可用 | warn | 面板按钮会退化成只读 |
|
|
179
|
+
| 每轮打分 | info | `scored` —— raw / band / 字数 / 是否写操作 |
|
|
180
|
+
| `probe_intent` | info | 候选数量;`probe ask`(任务类型 + 问题数)、`probe ask done`(维度答案数 + 选中目标);事实收集失败记 `probe facts failed` |
|
|
181
|
+
| 写操作被 gate 拦下 | info | `write gated` + 工具名 + 分值 |
|
|
182
|
+
| 收尾对账 | info | `auto-check start` / `auto-check skipped`(本轮模型已对过账) |
|
|
183
|
+
| `reconcile` 工具 | info/error | `reconcile start` / `reconcile done`(耗时、未达标数)/ `reconcile failed` |
|
|
184
|
+
| 卸载 | info | `disposed` + 跟踪的会话数 |
|
|
185
|
+
|
|
151
186
|
## 实测记录(在真实会话里跑过什么)
|
|
152
187
|
|
|
153
188
|
装到本机 Desktop profile 后,用一个真实的 git 工作区(`probe/demo-workspace`)跑过:
|
package/client.js
CHANGED
|
@@ -28,6 +28,7 @@ const SIGNALS = Object.freeze([
|
|
|
28
28
|
{ id: 'topicShift', delta: 8, label: '与近期请求主题重合但目标不同' },
|
|
29
29
|
{ id: 'reworkHistory', delta: 15, label: '同类请求曾返工' },
|
|
30
30
|
{ id: 'tooShort', delta: 10, label: '请求极短(<12字)' },
|
|
31
|
+
{ id: 'gibberish', delta: 15, label: '疑似乱码/无实际意图' },
|
|
31
32
|
{ id: 'namedDeliverable', delta: -10, label: '点名了交付物' },
|
|
32
33
|
{ id: 'acceptanceWords', delta: -20, label: '自带验收词' },
|
|
33
34
|
{ id: 'readOnly', delta: -15, label: '纯只读查询' },
|
|
@@ -46,6 +47,23 @@ const RE_TARGET_PATH = /([A-Za-z0-9_.\-]+[\\/])?[A-Za-z0-9_.\-]+\.(md|markdown|t
|
|
|
46
47
|
const RE_TARGET_QUOTED = /「[^」]{1,60}」|"[^"\n]{1,60}"|`[^`\n]{1,60}`/u
|
|
47
48
|
const RE_TARGET_CHANGE = /(改成|改为|换成|替换成|变成|写成|输出为|的格式|第\s*[一二三四五六七八九十百\d]+\s*(行|条|段|章|节|个))/u
|
|
48
49
|
const RE_BATCH = /(那批|这批|一批|所有|全部|每个|各个|这些文件|那些文件|都改|全改|批量|遍历|整个目录)/u
|
|
50
|
+
const RE_COMMON_WORD = /(?:^|[^a-z])(the|a|an|is|are|was|be|to|of|and|or|for|in|on|at|by|with|from|into|please|help|fix|add|remove|delete|update|change|make|create|build|test|run|check|find|show|open|close|explain|why|how|what|where|which|who|this|that|these|those|page|file|code|bug|error|feature|window|report|data|list|new|old|not|no|yes|do|does|can|should|need|want|use|using|let|get|set|put|it|its|my|your|our|we|you|i|me|he|she|they|them|when|then|than|also|just|only|more|less|all|any|some|one|two|three|first|last|next|now|after|before|about|over|under|between|through|during|because|but|if|else|so|as|up|down|out|off)(?![a-z])/iu
|
|
51
|
+
const RE_HAS_CJK = /[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]/u
|
|
52
|
+
|
|
53
|
+
function scoreLooksGibberish(text) {
|
|
54
|
+
if (RE_HAS_CJK.test(String(text ?? '').trim())) return false
|
|
55
|
+
const source = String(text ?? '').trim()
|
|
56
|
+
if (source === '') return false
|
|
57
|
+
if (RE_COMMON_WORD.test(source)) return false
|
|
58
|
+
const letters = source.replace(/[^A-Za-z]/gu, '')
|
|
59
|
+
if (letters.length < 8) return false
|
|
60
|
+
const lower = letters.toLowerCase()
|
|
61
|
+
const unique = new Set(lower).size
|
|
62
|
+
const vowels = (lower.match(/[aeiou]/gu) ?? []).length
|
|
63
|
+
const diversity = unique / lower.length
|
|
64
|
+
const vowelRatio = vowels / lower.length
|
|
65
|
+
return diversity < 0.5 || vowelRatio < 0.25
|
|
66
|
+
}
|
|
49
67
|
|
|
50
68
|
function scoreContentLength(text) {
|
|
51
69
|
return Array.from(String(text ?? '').replace(/[\s\u3000]/gu, '').replace(/[,。!?、;:""''()《》【】,.;:!?'"()<>\[\]]/gu, '')).length
|
|
@@ -144,6 +162,7 @@ function scoreRequest(text, context = {}) {
|
|
|
144
162
|
push('topicShift', scoreTopicShift(source, context.recentTexts ?? []))
|
|
145
163
|
push('reworkHistory', (context.reworkCount ?? 0) > 0)
|
|
146
164
|
push('tooShort', chars > 0 && chars < 12)
|
|
165
|
+
push('gibberish', scoreLooksGibberish(source))
|
|
147
166
|
push('namedDeliverable', RE_DELIVERABLE.test(source) || RE_DELIVERABLE_ZH.test(source))
|
|
148
167
|
push('acceptanceWords', RE_ACCEPTANCE.test(source))
|
|
149
168
|
push('readOnly', readOnly)
|
package/cordis.patch.yml
CHANGED
|
@@ -7,5 +7,9 @@
|
|
|
7
7
|
zeroTargetEscalation: true
|
|
8
8
|
deicticEscalation: true
|
|
9
9
|
logScores: true
|
|
10
|
-
|
|
10
|
+
scoreLogMode: threshold
|
|
11
|
+
# 写操作 gate 默认关(与 DEFAULT_CONFIG / README 一致)。
|
|
12
|
+
# 打开后:含糊度进 panel 档的写操作会先被挡住,直到 probe_intent action=ask 问过一次,
|
|
13
|
+
# 或用户下一条输入重新打分。
|
|
14
|
+
gateWrites: false
|
|
11
15
|
commandTimeoutMs: 120000
|
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import path from 'node:path'
|
|
12
12
|
import { readFile, writeFile, stat, readdir } from 'node:fs/promises'
|
|
13
|
+
import { readFileSync } from 'node:fs'
|
|
13
14
|
import { randomUUID, createHash } from 'node:crypto'
|
|
14
15
|
|
|
15
16
|
import { scoreRequest, formatScore, textSimilarity } from './src/ambiguity.js'
|
|
@@ -19,7 +20,10 @@ import {
|
|
|
19
20
|
import {
|
|
20
21
|
reconcile, readTask, readEvidence, writeSkeleton, setManual, currentVerdict,
|
|
21
22
|
} from './src/reconcile.js'
|
|
22
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
collectFacts, rankCandidates, buildQuestion, formatCandidates,
|
|
25
|
+
detectTaskKind, buildIntakeQuestions, composePrompt,
|
|
26
|
+
} from './src/probe.js'
|
|
23
27
|
import { admitLocalRequest, jsonHeaders } from './src/http-guard.js'
|
|
24
28
|
import { createIo } from './host/io.js'
|
|
25
29
|
|
|
@@ -50,12 +54,43 @@ const WRITE_TOOLS = new Set([
|
|
|
50
54
|
|
|
51
55
|
export function apply(ctx, rawConfig = {}) {
|
|
52
56
|
const config = { ...DEFAULT_CONFIG, ...(rawConfig && typeof rawConfig === 'object' ? rawConfig : {}) }
|
|
57
|
+
|
|
58
|
+
/** 插件版本(读 package.json,避免和发布版本漂移);读不到就 unknown。 */
|
|
59
|
+
const PLUGIN_VERSION = (() => {
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version ?? 'unknown'
|
|
62
|
+
} catch {
|
|
63
|
+
return 'unknown'
|
|
64
|
+
}
|
|
65
|
+
})()
|
|
66
|
+
|
|
67
|
+
/** 统一日志:字段序列化失败、logger 抛错都不影响主流程。 */
|
|
68
|
+
const log = (level, message, fields) => {
|
|
69
|
+
let line = message
|
|
70
|
+
if (fields !== undefined) {
|
|
71
|
+
try { line = `${message} ${JSON.stringify(fields)}` } catch { line = `${message} [fields 无法序列化]` }
|
|
72
|
+
}
|
|
73
|
+
const logger = ctx.logger
|
|
74
|
+
const sink = logger?.[level] ?? logger?.info ?? logger?.warn
|
|
75
|
+
if (typeof sink !== 'function') return
|
|
76
|
+
try { sink.call(logger, `dsh-reconcile: ${line}`) } catch { /* 日志失败绝不影响主流程 */ }
|
|
77
|
+
}
|
|
53
78
|
/** sessionId -> { cwd, score, probe, verdict, headline, checkedAt, evidenceDigest, tampered } */
|
|
54
79
|
const state = new Map()
|
|
80
|
+
/** 内存镜像上限:宿主长跑时 session 会一直增,超出就丢最老的(重算即可,不丢真数据)。 */
|
|
81
|
+
const MAX_TRACKED_SESSIONS = 200
|
|
55
82
|
const stateOf = (sessionId) => {
|
|
56
83
|
const key = String(sessionId ?? '')
|
|
57
|
-
|
|
58
|
-
|
|
84
|
+
let entry = state.get(key)
|
|
85
|
+
if (!entry) {
|
|
86
|
+
if (state.size >= MAX_TRACKED_SESSIONS) {
|
|
87
|
+
const oldest = state.keys().next().value
|
|
88
|
+
if (oldest !== undefined) state.delete(oldest)
|
|
89
|
+
}
|
|
90
|
+
entry = { sessionId: key }
|
|
91
|
+
state.set(key, entry)
|
|
92
|
+
}
|
|
93
|
+
return entry
|
|
59
94
|
}
|
|
60
95
|
|
|
61
96
|
/* ------------------------------------------------------------------ */
|
|
@@ -230,6 +265,9 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
230
265
|
const agent = exec.agent
|
|
231
266
|
if (!agent) throw new Error('reconcile 需要在一个会话里调用')
|
|
232
267
|
const action = String(args?.action ?? 'status')
|
|
268
|
+
const startedAt = Date.now()
|
|
269
|
+
log('info', 'reconcile start', { action })
|
|
270
|
+
try {
|
|
233
271
|
if (action === 'status') {
|
|
234
272
|
const current = await uiState(agent)
|
|
235
273
|
return textResult([current])
|
|
@@ -268,6 +306,12 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
268
306
|
}
|
|
269
307
|
// check
|
|
270
308
|
const result = await runCheck(agent)
|
|
309
|
+
log('info', 'reconcile done', {
|
|
310
|
+
action, ms: Date.now() - startedAt,
|
|
311
|
+
ok: Boolean(result?.ok),
|
|
312
|
+
unmet: result?.summary?.unmet ?? null,
|
|
313
|
+
total: result?.summary?.total ?? null,
|
|
314
|
+
})
|
|
271
315
|
if (!result?.ok) {
|
|
272
316
|
return textResult([{ ok: false, code: result?.code, message: result?.message, warnings: result?.warnings ?? [] }])
|
|
273
317
|
}
|
|
@@ -279,6 +323,10 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
279
323
|
checkedAt: result.checkedAt,
|
|
280
324
|
evidencePath: rel(cwdOf(agent), result.evidencePath ?? ''),
|
|
281
325
|
}
|
|
326
|
+
} catch (error) {
|
|
327
|
+
log('error', 'reconcile failed', { action, ms: Date.now() - startedAt, error: String(error?.message ?? error) })
|
|
328
|
+
throw error
|
|
329
|
+
}
|
|
282
330
|
},
|
|
283
331
|
})
|
|
284
332
|
|
|
@@ -288,7 +336,9 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
288
336
|
'交账:先核事实、再问意图。用户用指代词(那个页面/上次那份数据/老样子)时,先调 action=probe:'
|
|
289
337
|
+ '它会查 git 最近改动、按 mtime 排序的文件、本会话引用过的路径、页面目录与路由表,返回 2~3 个**带证据**的候选。'
|
|
290
338
|
+ '然后调 action=ask,把候选作为可点选项问用户(最后一项固定「我不知道,你替我定」)。'
|
|
291
|
-
+ '没有证据的候选不会出现;查不到会退化成开放问题。禁止自己编候选。'
|
|
339
|
+
+ '没有证据的候选不会出现;查不到会退化成开放问题。禁止自己编候选。'
|
|
340
|
+
+ 'action=ask 还会按任务类型补问「效果」维度(动画问风格/节奏、页面问视觉方向/适配目标、文档问受众/篇幅、代码问改动范围/验收方式),'
|
|
341
|
+
+ '总共最多 3 个问题;问完返回 completedPrompt —— 那是把原话和答案拼好的**可直接执行**的提示词,后续按它执行。',
|
|
292
342
|
parameters: {
|
|
293
343
|
type: 'object',
|
|
294
344
|
properties: {
|
|
@@ -310,13 +360,22 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
310
360
|
? args.request
|
|
311
361
|
: (entry.lastUserText ?? '')
|
|
312
362
|
const io = ioFor(agent)
|
|
313
|
-
|
|
363
|
+
let facts
|
|
364
|
+
try {
|
|
365
|
+
facts = await collectFacts({ ...io, sessionPaths: () => sessionPathCounts(agent) })
|
|
366
|
+
} catch (error) {
|
|
367
|
+
log('warn', 'probe facts failed', { error: String(error?.message ?? error) })
|
|
368
|
+
throw error
|
|
369
|
+
}
|
|
314
370
|
const candidates = rankCandidates(request, facts)
|
|
371
|
+
log('info', 'probe', { request: request.slice(0, 60), candidates: candidates.length })
|
|
315
372
|
entry.probe = { request, candidates, at: new Date().toISOString(), facts: summarizeFacts(facts) }
|
|
316
373
|
const action = String(args?.action ?? 'probe')
|
|
374
|
+
const intake = detectTaskKind(request)
|
|
317
375
|
if (action === 'probe') {
|
|
318
376
|
return textResult([{
|
|
319
377
|
request,
|
|
378
|
+
intake: { kind: intake.kind, label: intake.label, questions: buildIntakeQuestions(request) },
|
|
320
379
|
candidates: candidates.map((c) => ({ path: c.path, score: c.score, evidence: c.evidence })),
|
|
321
380
|
facts: summarizeFacts(facts),
|
|
322
381
|
message: candidates.length === 0
|
|
@@ -336,31 +395,42 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
336
395
|
}
|
|
337
396
|
const question = buildQuestion(request, candidates)
|
|
338
397
|
if (typeof args?.question === 'string' && args.question.trim() !== '') question.question = args.question.trim()
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
question: question.question,
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
398
|
+
// 目标 + 任务维度(效果/风格/时长…)一起问,最多 3 个问题;没有候选时只问维度。
|
|
399
|
+
const intakeQuestions = buildIntakeQuestions(request)
|
|
400
|
+
const asked = [
|
|
401
|
+
...(candidates.length > 0
|
|
402
|
+
? [{ id: 'target', header: question.header, question: question.question, options: question.options, multiSelect: false }]
|
|
403
|
+
: []),
|
|
404
|
+
...intakeQuestions.map((q) => ({ id: q.id, header: q.header, question: q.question, options: q.options, multiSelect: false })),
|
|
405
|
+
].slice(0, 3)
|
|
406
|
+
log('info', 'probe ask', { kind: intake.kind, questionCount: asked.length })
|
|
407
|
+
const answer = await questions.ask({ questions: asked, agent, signal: exec.signal })
|
|
408
|
+
// 模型按要求先问了 → 释放写操作 gate(下一轮用户输入会重新评估)
|
|
409
|
+
entry.gateReleased = true
|
|
410
|
+
log('info', 'probe asked, gate released', { candidates: candidates.length })
|
|
350
411
|
const item = answer?.answers?.find((a) => a.id === 'target')
|
|
351
412
|
const selected = item?.selected ?? []
|
|
352
413
|
const custom = item?.custom
|
|
353
414
|
const chosen = custom && custom.trim() !== '' ? custom.trim() : (selected[0] ?? '')
|
|
354
415
|
const picked = candidates.find((c, index) => chosen.startsWith(`${String.fromCharCode(65 + index)}.`) || chosen.includes(c.path))
|
|
416
|
+
// 维度答案 → 拼成一段可执行的补全提示词(这就是「问完把提示词补一下」)
|
|
417
|
+
const dimensionAnswers = (answer?.answers ?? [])
|
|
418
|
+
.filter((a) => a?.id && a.id !== 'target')
|
|
419
|
+
.map((a) => ({ id: a.id, answer: String(a.custom ?? (a.selected ?? [])[0] ?? '').trim() }))
|
|
420
|
+
.filter((a) => a.answer !== '')
|
|
421
|
+
const completedPrompt = composePrompt(request, dimensionAnswers, picked ? [picked] : [])
|
|
422
|
+
log('info', 'probe ask done', { kind: intake.kind, dims: dimensionAnswers.length, picked: picked?.path ?? null })
|
|
355
423
|
return textResult([{
|
|
356
424
|
ok: true,
|
|
357
|
-
answered: chosen !== '',
|
|
425
|
+
answered: chosen !== '' || dimensionAnswers.length > 0,
|
|
358
426
|
selected: chosen,
|
|
359
427
|
path: picked?.path ?? null,
|
|
360
428
|
evidence: picked?.evidence ?? [],
|
|
429
|
+
answers: dimensionAnswers,
|
|
430
|
+
completedPrompt,
|
|
361
431
|
candidates: candidates.map((c) => ({ path: c.path, evidence: c.evidence })),
|
|
362
|
-
message: chosen === ''
|
|
363
|
-
? '
|
|
432
|
+
message: (chosen === '' && dimensionAnswers.length === 0)
|
|
433
|
+
? '用户跳过了这些问题:不要当成同意。改为按最保守的假设做,并在答复末尾写「我按 X 理解做的」。'
|
|
364
434
|
: picked
|
|
365
435
|
? `用户指向 ${picked.path}(证据:${picked.evidence.join(';')})。接下来只对这个目标动手。`
|
|
366
436
|
: `用户回答了「${chosen}」,与候选不完全一致,按用户原话执行。`,
|
|
@@ -455,7 +525,10 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
455
525
|
panelThreshold: config.panelThreshold,
|
|
456
526
|
})
|
|
457
527
|
entry.lastUserText = text
|
|
528
|
+
// 新的一轮用户输入意味着重新评估:上一轮的 gate 释放作废
|
|
529
|
+
entry.gateReleased = false
|
|
458
530
|
entry.score = { ...score, text, turn, at: new Date().toISOString(), line: formatScore(score) }
|
|
531
|
+
log('info', 'scored', { raw: score.raw, band: score.band, chars: score.chars, write: score.write })
|
|
459
532
|
entry.recentTexts = [...recent.slice(-3), text]
|
|
460
533
|
// 降噪:只有过提示线时才把分值写进会话日志;同一分数不重复灌。
|
|
461
534
|
const logMode = config.scoreLogMode ?? 'threshold'
|
|
@@ -515,6 +588,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
515
588
|
if (entry.gateReleased) return undefined
|
|
516
589
|
const toolName = String(exec.name ?? '')
|
|
517
590
|
if (!WRITE_TOOLS.has(toolName)) return undefined
|
|
591
|
+
log('info', 'write gated', { tool: toolName, raw: score.raw })
|
|
518
592
|
return {
|
|
519
593
|
reason: `交账:这条请求含糊度 ${score.raw}(${score.hits.map((h) => `${h.delta > 0 ? '+' : ''}${h.delta} ${h.label}`).join('、')}),先确认意图再动手。用 probe_intent 带候选问,或让用户直接给出目标。`,
|
|
520
594
|
}
|
|
@@ -535,10 +609,14 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
535
609
|
try {
|
|
536
610
|
const entry = stateOf(agent.session?.id)
|
|
537
611
|
// 模型这一轮自己刚对过账(3s 内),别再跑一遍命令
|
|
538
|
-
if (entry.lastCheckAt && Date.now() - entry.lastCheckAt < 3000)
|
|
612
|
+
if (entry.lastCheckAt && Date.now() - entry.lastCheckAt < 3000) {
|
|
613
|
+
log('info', 'auto-check skipped', { reason: 'model already checked this turn' })
|
|
614
|
+
return
|
|
615
|
+
}
|
|
539
616
|
const io = ioFor(agent)
|
|
540
617
|
const read = await readTask(io)
|
|
541
618
|
if (!read) return
|
|
619
|
+
log('info', 'auto-check start', { skipCommands: config.autoCheckCommands === false })
|
|
542
620
|
await runCheck(agent, { skipCommands: config.autoCheckCommands === false })
|
|
543
621
|
} catch (error) {
|
|
544
622
|
ctx.logger?.warn?.(`dsh-reconcile: 收尾对账失败:${error?.message ?? error}`)
|
|
@@ -742,6 +820,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
742
820
|
return () => { void dispose?.() }
|
|
743
821
|
}, 'dsh-reconcile: route ' + routePath)
|
|
744
822
|
}
|
|
823
|
+
log('info', `routes mounted (${routes.length})`, { paths: routes.map(([p]) => p) })
|
|
745
824
|
return true
|
|
746
825
|
}
|
|
747
826
|
|
|
@@ -753,7 +832,17 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
753
832
|
}
|
|
754
833
|
}
|
|
755
834
|
|
|
835
|
+
log('info', 'ready', {
|
|
836
|
+
version: PLUGIN_VERSION,
|
|
837
|
+
hintThreshold: config.hintThreshold,
|
|
838
|
+
panelThreshold: config.panelThreshold,
|
|
839
|
+
gateWrites: Boolean(config.gateWrites),
|
|
840
|
+
autoCheck: config.autoCheck !== false,
|
|
841
|
+
routes: config.routesEnabled !== false,
|
|
842
|
+
})
|
|
843
|
+
|
|
756
844
|
return () => {
|
|
845
|
+
log('info', 'disposed', { sessions: state.size })
|
|
757
846
|
state.clear()
|
|
758
847
|
}
|
|
759
848
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-reconcile",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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",
|
|
@@ -49,6 +49,8 @@
|
|
|
49
49
|
],
|
|
50
50
|
"scripts": {
|
|
51
51
|
"selfcheck": "node test/selfcheck.mjs",
|
|
52
|
+
"smoke": "node test/client-smoke.mjs",
|
|
53
|
+
"accept": "node test/acceptance-intake.mjs",
|
|
52
54
|
"test": "node test/selfcheck.mjs"
|
|
53
55
|
},
|
|
54
56
|
"dsh": {
|
package/src/ambiguity.js
CHANGED
|
@@ -15,6 +15,7 @@ export const SIGNALS = Object.freeze([
|
|
|
15
15
|
{ id: 'topicShift', delta: 8, label: '与近期请求主题重合但目标不同' },
|
|
16
16
|
{ id: 'reworkHistory', delta: 15, label: '同类请求曾返工' },
|
|
17
17
|
{ id: 'tooShort', delta: 10, label: '请求极短(<12字)' },
|
|
18
|
+
{ id: 'gibberish', delta: 15, label: '疑似乱码/无实际意图' },
|
|
18
19
|
{ id: 'namedDeliverable', delta: -10, label: '点名了交付物' },
|
|
19
20
|
{ id: 'acceptanceWords', delta: -20, label: '自带验收词' },
|
|
20
21
|
{ id: 'readOnly', delta: -15, label: '纯只读查询' },
|
|
@@ -42,6 +43,32 @@ const RE_TARGET_PATH = /([A-Za-z0-9_.\-]+[\\/])?[A-Za-z0-9_.\-]+\.(md|markdown|t
|
|
|
42
43
|
const RE_TARGET_QUOTED = /「[^」]{1,60}」|"[^"\n]{1,60}"|`[^`\n]{1,60}`/u
|
|
43
44
|
const RE_TARGET_CHANGE = /(改成|改为|换成|替换成|变成|写成|输出为|的格式|第\s*[一二三四五六七八九十百\d]+\s*(行|条|段|章|节|个))/u
|
|
44
45
|
|
|
46
|
+
/** 常见英文词:命中任意一个就不判乱码,避免误伤 "fix the login bug" 这类正常英文请求。 */
|
|
47
|
+
const RE_COMMON_WORD = /(?:^|[^a-z])(the|a|an|is|are|was|be|to|of|and|or|for|in|on|at|by|with|from|into|please|help|fix|add|remove|delete|update|change|make|create|build|test|run|check|find|show|open|close|explain|why|how|what|where|which|who|this|that|these|those|page|file|code|bug|error|feature|window|report|data|list|new|old|not|no|yes|do|does|can|should|need|want|use|using|let|get|set|put|it|its|my|your|our|we|you|i|me|he|she|they|them|when|then|than|also|just|only|more|less|all|any|some|one|two|three|first|last|next|now|after|before|about|over|under|between|through|during|because|but|if|else|so|as|up|down|out|off)(?![a-z])/iu
|
|
48
|
+
|
|
49
|
+
const RE_HAS_CJK = /[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]/u
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 疑似乱码 / 无实际意图。
|
|
53
|
+
* 判据(全部满足才算):没有中文、没有常见英文词、字母数 ≥ 8,
|
|
54
|
+
* 且字符多样性 < 0.5 或元音比例 < 0.25。
|
|
55
|
+
* 目的只是让读数诚实(+15,不足以打断),不是替用户判断。
|
|
56
|
+
*/
|
|
57
|
+
export function looksGibberish(text) {
|
|
58
|
+
const source = String(text ?? '').trim()
|
|
59
|
+
if (source === '') return false
|
|
60
|
+
if (RE_HAS_CJK.test(source)) return false
|
|
61
|
+
if (RE_COMMON_WORD.test(source)) return false
|
|
62
|
+
const letters = source.replace(/[^A-Za-z]/gu, '')
|
|
63
|
+
if (letters.length < 8) return false
|
|
64
|
+
const lower = letters.toLowerCase()
|
|
65
|
+
const unique = new Set(lower).size
|
|
66
|
+
const vowels = (lower.match(/[aeiou]/gu) ?? []).length
|
|
67
|
+
const diversity = unique / lower.length
|
|
68
|
+
const vowelRatio = vowels / lower.length
|
|
69
|
+
return diversity < 0.5 || vowelRatio < 0.25
|
|
70
|
+
}
|
|
71
|
+
|
|
45
72
|
/** 记多少「字数」:去掉空白与纯标点。中文一个字算 1。 */
|
|
46
73
|
export function contentLength(text) {
|
|
47
74
|
return Array.from(String(text ?? '').replace(/[\s\u3000]/gu, '').replace(/[,。!?、;:""''()《》【】,.;:!?'"()<>\[\]]/gu, '')).length
|
|
@@ -147,6 +174,7 @@ export function scoreRequest(text, context = {}) {
|
|
|
147
174
|
push('topicShift', detectTopicShift(source, context.recentTexts ?? []))
|
|
148
175
|
push('reworkHistory', (context.reworkCount ?? 0) > 0)
|
|
149
176
|
push('tooShort', chars > 0 && chars < 12)
|
|
177
|
+
push('gibberish', looksGibberish(source))
|
|
150
178
|
push('namedDeliverable', RE_DELIVERABLE.test(source) || RE_DELIVERABLE_ZH.test(source))
|
|
151
179
|
push('acceptanceWords', RE_ACCEPTANCE.test(source))
|
|
152
180
|
push('readOnly', readOnly)
|
package/src/probe.js
CHANGED
|
@@ -321,3 +321,194 @@ export async function collectFacts(io) {
|
|
|
321
321
|
|
|
322
322
|
return facts
|
|
323
323
|
}
|
|
324
|
+
/* ------------------------------------------------------------------ */
|
|
325
|
+
/* 任务维度提问(intake):按任务类型问「效果」而不只问「哪个目标」 */
|
|
326
|
+
/* ------------------------------------------------------------------ */
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 任务类型与要问的维度。
|
|
330
|
+
* 目的:用户说「做一段一分钟的动画」时,真正卡住执行的不是文件路径,是**风格/节奏/用途**;
|
|
331
|
+
* 只问「你指哪个文件」等于没问。这里给每种类型固定 2 个高价值维度,最多问 3 个问题(含目标)。
|
|
332
|
+
*/
|
|
333
|
+
const TASK_KINDS = [
|
|
334
|
+
{
|
|
335
|
+
kind: 'animation',
|
|
336
|
+
label: '动画/视频',
|
|
337
|
+
test: /(动画|动画片|短片|宣传片|视频|mv|motion|animat|render|镜头|分镜)/iu,
|
|
338
|
+
dimensions: [
|
|
339
|
+
{
|
|
340
|
+
id: 'style',
|
|
341
|
+
label: '风格',
|
|
342
|
+
question: '风格上想要哪一种?',
|
|
343
|
+
options: [
|
|
344
|
+
{ label: '粗描边贴纸', description: '白底、粗黑边、撞色贴纸感,适合科普' },
|
|
345
|
+
{ label: '扁平矢量', description: '纯色块 + 几何形状,干净利落' },
|
|
346
|
+
{ label: '手绘线条', description: '线条逐笔生成,偏解释性' },
|
|
347
|
+
{ label: '写实质感', description: '接近实拍/CGI,成本最高' },
|
|
348
|
+
],
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
id: 'pacing',
|
|
352
|
+
label: '节奏与时长',
|
|
353
|
+
question: '节奏想怎么走?(时长按你原话,这里只定节奏)',
|
|
354
|
+
options: [
|
|
355
|
+
{ label: '轻快,多切点', description: '信息密度高,适合短视频' },
|
|
356
|
+
{ label: '张弛有度,几处长镜', description: '有呼吸,适合叙事' },
|
|
357
|
+
{ label: '一镜到底', description: '连续运镜,不切镜' },
|
|
358
|
+
],
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
kind: 'page',
|
|
364
|
+
label: '页面/界面',
|
|
365
|
+
test: /(页面|网页|首页|界面|ui|ux|布局|组件|表单|弹窗|看板|dashboard|landing)/iu,
|
|
366
|
+
dimensions: [
|
|
367
|
+
{
|
|
368
|
+
id: 'look',
|
|
369
|
+
label: '视觉方向',
|
|
370
|
+
question: '视觉上想往哪边靠?',
|
|
371
|
+
options: [
|
|
372
|
+
{ label: '留白极简', description: '大面积留白,弱边框' },
|
|
373
|
+
{ label: '信息密集', description: '表格/列表优先,工具感' },
|
|
374
|
+
{ label: '品牌感强', description: '有主色与图形语言' },
|
|
375
|
+
],
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
id: 'device',
|
|
379
|
+
label: '适配目标',
|
|
380
|
+
question: '主要在什么尺寸上验收?',
|
|
381
|
+
options: [
|
|
382
|
+
{ label: '375px 手机优先', description: '移动端先做,桌面跟随' },
|
|
383
|
+
{ label: '1440px 桌面优先', description: '桌面先做,移动端可用即可' },
|
|
384
|
+
{ label: '两者都要', description: '双端都要过验收' },
|
|
385
|
+
],
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
kind: 'doc',
|
|
391
|
+
label: '文档/内容',
|
|
392
|
+
test: /(文档|报告|周报|月报|简历|合同|手册|说明书|文案|文章|ppt|幻灯片|演示|doc|xlsx|表格)/iu,
|
|
393
|
+
dimensions: [
|
|
394
|
+
{
|
|
395
|
+
id: 'audience',
|
|
396
|
+
label: '受众',
|
|
397
|
+
question: '这份东西给谁看?',
|
|
398
|
+
options: [
|
|
399
|
+
{ label: '给同事/合作方', description: '简洁、结论先行' },
|
|
400
|
+
{ label: '给上级/客户', description: '正式、附依据' },
|
|
401
|
+
{ label: '给自己', description: '要点齐即可' },
|
|
402
|
+
],
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
id: 'length',
|
|
406
|
+
label: '篇幅',
|
|
407
|
+
question: '篇幅大概多少?',
|
|
408
|
+
options: [
|
|
409
|
+
{ label: '一页纸', description: '控制在一屏/单页' },
|
|
410
|
+
{ label: '3~5 页', description: '够展开论证' },
|
|
411
|
+
{ label: '不限,按内容来', description: '完整优先' },
|
|
412
|
+
],
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
kind: 'code',
|
|
418
|
+
label: '代码改动',
|
|
419
|
+
test: /(函数|方法|接口|api|重构|修|bug|报错|异常|测试|单测|依赖|性能|typescript|python|javascript|react)/iu,
|
|
420
|
+
dimensions: [
|
|
421
|
+
{
|
|
422
|
+
id: 'scope',
|
|
423
|
+
label: '改动范围',
|
|
424
|
+
question: '允许改多大范围?',
|
|
425
|
+
options: [
|
|
426
|
+
{ label: '只改这个文件', description: '尽量不扩散' },
|
|
427
|
+
{ label: '可以动相邻模块', description: '允许顺带整理调入点' },
|
|
428
|
+
{ label: '可以重构这一块', description: '结构性问题一次改干净' },
|
|
429
|
+
],
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
id: 'verify',
|
|
433
|
+
label: '验收方式',
|
|
434
|
+
question: '怎么算改好了?',
|
|
435
|
+
options: [
|
|
436
|
+
{ label: '现有测试跑通', description: '不新增测试' },
|
|
437
|
+
{ label: '补一条能复现的测试', description: '先红后绿' },
|
|
438
|
+
{ label: '我手动验证', description: '你给验证步骤即可' },
|
|
439
|
+
],
|
|
440
|
+
},
|
|
441
|
+
],
|
|
442
|
+
},
|
|
443
|
+
]
|
|
444
|
+
|
|
445
|
+
/** 通用兜底:认不出类型时问「交付物形态 + 验收标准」。 */
|
|
446
|
+
const GENERIC_DIMENSIONS = [
|
|
447
|
+
{
|
|
448
|
+
id: 'deliverable',
|
|
449
|
+
label: '交付物',
|
|
450
|
+
question: '最后要交给你什么?',
|
|
451
|
+
options: [
|
|
452
|
+
{ label: '直接改代码', description: '在工作区里动文件' },
|
|
453
|
+
{ label: '给我一份文档', description: 'Markdown / 表格' },
|
|
454
|
+
{ label: '只要结论/方案', description: '不落盘' },
|
|
455
|
+
],
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
id: 'accept',
|
|
459
|
+
label: '验收标准',
|
|
460
|
+
question: '做到什么程度算完成?',
|
|
461
|
+
options: [
|
|
462
|
+
{ label: '能跑通即可', description: '功能可用' },
|
|
463
|
+
{ label: '要过现有测试', description: '命令退出码 0' },
|
|
464
|
+
{ label: '要能复现验证', description: '我按你说的步骤能验' },
|
|
465
|
+
],
|
|
466
|
+
},
|
|
467
|
+
]
|
|
468
|
+
|
|
469
|
+
const DIMENSION_LABELS = new Map()
|
|
470
|
+
for (const kind of TASK_KINDS) for (const dim of kind.dimensions) DIMENSION_LABELS.set(dim.id, dim.label)
|
|
471
|
+
for (const dim of GENERIC_DIMENSIONS) DIMENSION_LABELS.set(dim.id, dim.label)
|
|
472
|
+
|
|
473
|
+
/** 识别任务类型;认不出返回 generic。 */
|
|
474
|
+
export function detectTaskKind(text) {
|
|
475
|
+
const source = String(text ?? '')
|
|
476
|
+
for (const kind of TASK_KINDS) {
|
|
477
|
+
if (kind.test.test(source)) return { kind: kind.kind, label: kind.label, dimensions: kind.dimensions }
|
|
478
|
+
}
|
|
479
|
+
return { kind: 'generic', label: '通用', dimensions: GENERIC_DIMENSIONS }
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** 该任务要问的维度问题(最多 2 个,加上目标问题总共不超过 3 个)。 */
|
|
483
|
+
export function buildIntakeQuestions(text) {
|
|
484
|
+
const detected = detectTaskKind(text)
|
|
485
|
+
return detected.dimensions.slice(0, 2).map((dim) => ({
|
|
486
|
+
id: dim.id,
|
|
487
|
+
header: dim.label,
|
|
488
|
+
question: dim.question,
|
|
489
|
+
options: dim.options.map((option) => ({ label: option.label, description: option.description })),
|
|
490
|
+
}))
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* 把「原始请求 + 用户答案 + 选中的候选目标」拼成一段可直接执行的补全提示词。
|
|
495
|
+
* @param {string} request 用户原话
|
|
496
|
+
* @param {Array<{id: string, answer: string}>} answers 维度答案
|
|
497
|
+
* @param {Array<{path: string}>} chosen 选中的目标(可为空)
|
|
498
|
+
* @returns {string}
|
|
499
|
+
*/
|
|
500
|
+
export function composePrompt(request, answers = [], chosen = []) {
|
|
501
|
+
const base = String(request ?? '').trim()
|
|
502
|
+
const parts = []
|
|
503
|
+
const target = chosen.map((c) => String(c?.path ?? '')).filter(Boolean)
|
|
504
|
+
if (target.length > 0) parts.push(`目标:${target.slice(0, 3).join('、')}`)
|
|
505
|
+
for (const item of answers) {
|
|
506
|
+
const answer = String(item?.answer ?? '').trim()
|
|
507
|
+
if (answer === '') continue
|
|
508
|
+
const label = DIMENSION_LABELS.get(String(item?.id ?? '')) ?? String(item?.id ?? '补充')
|
|
509
|
+
parts.push(`${label}:${answer}`)
|
|
510
|
+
}
|
|
511
|
+
if (parts.length === 0) return base
|
|
512
|
+
const body = base === '' ? '' : `${base}。`
|
|
513
|
+
return `${body}补充确认 —— ${parts.join(';')}。按以上要求执行;完成后逐条对照验收。`
|
|
514
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 验收脚本(给 TASK.md 的 command 证据用):乱码信号 + 任务维度提问。
|
|
3
|
+
*
|
|
4
|
+
* 单独成一个文件,是因为 `command` 证据里写 `node -e "..."` 会被引号/反引号绞死,
|
|
5
|
+
* 这里给两个稳定入口:
|
|
6
|
+
* node test/acceptance-intake.mjs --scoring 乱码命中且不误伤
|
|
7
|
+
* node test/acceptance-intake.mjs --intake 任务类型 → 维度问题 → 补全提示词
|
|
8
|
+
* 不带参数则两项都跑。
|
|
9
|
+
*/
|
|
10
|
+
import assert from 'node:assert/strict'
|
|
11
|
+
|
|
12
|
+
import { scoreRequest } from '../src/ambiguity.js'
|
|
13
|
+
import { detectTaskKind, buildIntakeQuestions, composePrompt } from '../src/probe.js'
|
|
14
|
+
|
|
15
|
+
const mode = process.argv[2] ?? '--all'
|
|
16
|
+
const failures = []
|
|
17
|
+
|
|
18
|
+
function check(name, fn) {
|
|
19
|
+
try {
|
|
20
|
+
fn()
|
|
21
|
+
console.log(` ✓ ${name}`)
|
|
22
|
+
} catch (error) {
|
|
23
|
+
failures.push(`${name}: ${error?.message ?? error}`)
|
|
24
|
+
console.error(` ✗ ${name}: ${error?.message ?? error}`)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (mode === '--scoring' || mode === '--all') {
|
|
29
|
+
console.log('乱码信号:')
|
|
30
|
+
check('乱码命中 gibberish 且分值 ≥ 30、仍不打断', () => {
|
|
31
|
+
const result = scoreRequest('adsadadsdaffeew')
|
|
32
|
+
assert.ok(result.hits.some((h) => h.id === 'gibberish'), '没命中 gibberish')
|
|
33
|
+
assert.ok(result.raw >= 30, `分值应 ≥ 30,实际 ${result.raw}`)
|
|
34
|
+
assert.equal(result.band, 'none', '乱码不应打断')
|
|
35
|
+
})
|
|
36
|
+
check('正常英文不误伤', () => {
|
|
37
|
+
for (const text of ['fix the login bug', 'refactor auth module to use hooks', 'userAgentHeaderName']) {
|
|
38
|
+
assert.ok(!scoreRequest(text).hits.some((h) => h.id === 'gibberish'), `误伤:${text}`)
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
check('中文不误伤', () => {
|
|
42
|
+
for (const text of ['把首页弄好看点', '做一段一分钟的动画片']) {
|
|
43
|
+
assert.ok(!scoreRequest(text).hits.some((h) => h.id === 'gibberish'), `误伤:${text}`)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (mode === '--intake' || mode === '--all') {
|
|
49
|
+
console.log('任务维度提问:')
|
|
50
|
+
const CASES = [
|
|
51
|
+
['做一段一分钟的动画片', 'animation', '风格'],
|
|
52
|
+
['改一下那个页面', 'page', '视觉方向'],
|
|
53
|
+
['写一份周报', 'doc', '受众'],
|
|
54
|
+
['修一下这个 bug', 'code', '改动范围'],
|
|
55
|
+
['随便弄点东西', 'generic', '交付物'],
|
|
56
|
+
]
|
|
57
|
+
for (const [request, kind, dimensionLabel] of CASES) {
|
|
58
|
+
check(`识别「${request}」为 ${kind},并问「${dimensionLabel}」`, () => {
|
|
59
|
+
const detected = detectTaskKind(request)
|
|
60
|
+
assert.equal(detected.kind, kind, `类型识别错了:${detected.kind}`)
|
|
61
|
+
const questions = buildIntakeQuestions(request)
|
|
62
|
+
assert.ok(questions.length >= 1 && questions.length <= 2, `维度问题数量异常:${questions.length}`)
|
|
63
|
+
assert.ok(questions.some((q) => q.header.includes(dimensionLabel)), `没有问到「${dimensionLabel}」:${JSON.stringify(questions.map((q) => q.header))}`)
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
check('问完能拼出可执行的补全提示词', () => {
|
|
68
|
+
const prompt = composePrompt(
|
|
69
|
+
'做一段一分钟的动画片',
|
|
70
|
+
[{ id: 'style', answer: '粗描边贴纸' }, { id: 'pacing', answer: '轻快,多切点' }],
|
|
71
|
+
[{ path: 'assets/anim/intro.tsx' }],
|
|
72
|
+
)
|
|
73
|
+
assert.match(prompt, /一分钟/, '丢了原始需求')
|
|
74
|
+
assert.match(prompt, /粗描边贴纸/, '丢了风格答案')
|
|
75
|
+
assert.match(prompt, /轻快,多切点/, '丢了节奏答案')
|
|
76
|
+
assert.match(prompt, /assets\/anim\/intro\.tsx/, '丢了目标')
|
|
77
|
+
assert.match(prompt, /按以上要求执行/, '没有收口指令')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
check('没有答案时原样返回原话(不长出空话)', () => {
|
|
81
|
+
assert.equal(composePrompt(' 做一段动画 ', [], []), '做一段动画')
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (failures.length > 0) {
|
|
86
|
+
console.error(`\n失败 ${failures.length} 项`)
|
|
87
|
+
process.exitCode = 1
|
|
88
|
+
} else {
|
|
89
|
+
console.log('\nOK')
|
|
90
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 客户端冒烟测试:在桩环境里执行 client.js 的 apply(),再把三个组件各渲染几遍。
|
|
3
|
+
*
|
|
4
|
+
* 存在的理由:`node --check` 只查语法,抓不到「组件体里引用了不存在的标识符」这种
|
|
5
|
+
* 运行时崩溃(上一轮 HeroHint 的 `hasText is not defined` 就是这样把面板打崩的)。
|
|
6
|
+
* 这里用最小 React 桩真正执行组件函数体,任何 ReferenceError / TypeError 都会让测试红。
|
|
7
|
+
*
|
|
8
|
+
* 不联网、不启宿主、不依赖 react 真包。
|
|
9
|
+
*/
|
|
10
|
+
import assert from 'node:assert/strict'
|
|
11
|
+
import path from 'node:path'
|
|
12
|
+
import { readFileSync } from 'node:fs'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
|
|
15
|
+
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
16
|
+
const source = readFileSync(path.join(here, '..', 'client.js'), 'utf8')
|
|
17
|
+
|
|
18
|
+
/* ---------------------------- 最小 React 桩 ---------------------------- */
|
|
19
|
+
let styleCalls = 0
|
|
20
|
+
function createElement(type, props, ...children) {
|
|
21
|
+
return { type, props: props ?? {}, children }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class FakeComponent {
|
|
25
|
+
constructor(props) { this.props = props }
|
|
26
|
+
setState() {}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let seeds = []
|
|
30
|
+
let seedIndex = 0
|
|
31
|
+
const React = {
|
|
32
|
+
Component: FakeComponent,
|
|
33
|
+
Fragment: 'Fragment',
|
|
34
|
+
createElement,
|
|
35
|
+
useState(initial) {
|
|
36
|
+
const seed = seeds[seedIndex++]
|
|
37
|
+
return [seed === undefined ? initial : seed, () => {}]
|
|
38
|
+
},
|
|
39
|
+
// 副作用一律不执行:录像请求、fetch、计时器都不该在冒烟里启动
|
|
40
|
+
useEffect() {},
|
|
41
|
+
useMemo(fn) { return fn() },
|
|
42
|
+
useRef(initial) { return { current: initial } },
|
|
43
|
+
useCallback(fn) { return fn },
|
|
44
|
+
useReducer(_reducer, initial) { return [initial, () => {}] },
|
|
45
|
+
}
|
|
46
|
+
const requireStub = (name) => {
|
|
47
|
+
if (name === 'react') return React
|
|
48
|
+
throw new Error(`冒烟测试不接受额外模块:${name}`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* --------------------- 载入 client.js(捕获 load 定义) --------------------- */
|
|
52
|
+
let definition
|
|
53
|
+
const fakeWindow = { __ModuleLoader__: { load: (def) => { definition = def } } }
|
|
54
|
+
// eslint-disable-next-line no-new-func -- 这里就是要执行客户端模块本身
|
|
55
|
+
new Function('window', source)(fakeWindow)
|
|
56
|
+
assert.ok(definition, 'client.js 没有调用 window.__ModuleLoader__.load')
|
|
57
|
+
assert.equal(definition.id, 'dsh-reconcile', '模块 id 变了')
|
|
58
|
+
assert.equal(typeof definition.factory, 'function', 'load 里没有 factory')
|
|
59
|
+
|
|
60
|
+
/* --------------------------- 桩 ctx:捕获挂点 --------------------------- */
|
|
61
|
+
const registered = new Map()
|
|
62
|
+
const warnings = []
|
|
63
|
+
const fakeCtx = {
|
|
64
|
+
effect(fn) { fn(); return () => {} },
|
|
65
|
+
locale: { register: () => () => {} },
|
|
66
|
+
slots: {
|
|
67
|
+
inject(_name, callback) { callback() },
|
|
68
|
+
register(config, Component) { registered.set(config.name, Component); return () => {} },
|
|
69
|
+
},
|
|
70
|
+
logger: { info() {}, warn: (m) => warnings.push(String(m)), error() {} },
|
|
71
|
+
get() { return undefined },
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const exported = definition.factory(requireStub)
|
|
75
|
+
assert.equal(typeof exported?.apply, 'function', 'factory 没有返回 apply()')
|
|
76
|
+
exported.apply(fakeCtx)
|
|
77
|
+
|
|
78
|
+
/* ------------------------------ 断言:挂点 ------------------------------ */
|
|
79
|
+
const EXPECTED_SLOTS = ['conversation.chat.turnTail', 'conversation.composer.dock', 'conversation.hero.options']
|
|
80
|
+
for (const slot of EXPECTED_SLOTS) {
|
|
81
|
+
assert.ok(registered.has(slot), `没有注册 ${slot}`)
|
|
82
|
+
}
|
|
83
|
+
assert.equal(registered.size, EXPECTED_SLOTS.length, `挂了预期外的槽位:${[...registered.keys()].join(', ')}`)
|
|
84
|
+
|
|
85
|
+
/* ------------- 把 guarded 包一层拆开,拿到真正的组件函数 ------------- */
|
|
86
|
+
const innerOf = (component) => {
|
|
87
|
+
const el = component({})
|
|
88
|
+
// guarded(Comp) 返回 h(SlotBoundary, null, h(Comp, props));这里顺藤摸到内层元素
|
|
89
|
+
const child = (el?.children ?? [])[0] ?? el?.props?.children
|
|
90
|
+
return child?.type ?? null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* ------------------------------ 渲染若干场景 ------------------------------ */
|
|
94
|
+
const scoreObject = {
|
|
95
|
+
raw: 55, band: 'panel',
|
|
96
|
+
hits: [
|
|
97
|
+
{ id: 'deictic', label: '含指代词', delta: 18 },
|
|
98
|
+
{ id: 'noCriterion', label: '缺可判定标准', delta: 15 },
|
|
99
|
+
{ id: 'wideWrite', label: '写操作且目标文件数>3或不确定', delta: 12 },
|
|
100
|
+
],
|
|
101
|
+
escalations: [{ id: 'deicticReference', label: '指代 + 已达提示线' }],
|
|
102
|
+
line: '含糊度 55(+18 含指代词 · +15 缺可判定标准) → 弹面板',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const taskState = {
|
|
106
|
+
ok: true,
|
|
107
|
+
sessionId: 'session-smoke',
|
|
108
|
+
cwd: 'C:\\tmp',
|
|
109
|
+
task: {
|
|
110
|
+
slug: 'smoke', status: 'doing', ambiguity: 55,
|
|
111
|
+
goal: '让首页不再横向滚动', constraints: ['不动 Header 结构'],
|
|
112
|
+
items: [
|
|
113
|
+
{ id: 'A1', text: 'README 有安装节', evidenceKind: 'file' },
|
|
114
|
+
{ id: 'A2', text: '首页无横向滚动', evidenceKind: 'file' },
|
|
115
|
+
],
|
|
116
|
+
warnings: [],
|
|
117
|
+
},
|
|
118
|
+
verdict: {
|
|
119
|
+
ok: true, headline: '未达标:1 项', checkedAt: new Date().toISOString(),
|
|
120
|
+
summary: { total: 2, pass: 1, fail: 1, unverified: 0, unmet: 1, manual: 0, manualShare: 0 },
|
|
121
|
+
results: [
|
|
122
|
+
{ id: 'A1', text: 'README 有安装节', verdict: 'pass', evidence: { kind: 'file', path: 'README.md', line: 3 } },
|
|
123
|
+
{ id: 'A2', text: '首页无横向滚动', verdict: 'fail', reason: '文件里不含「minWidth: 0」', evidence: { kind: 'file', path: 'src/index.tsx' } },
|
|
124
|
+
],
|
|
125
|
+
warnings: [],
|
|
126
|
+
},
|
|
127
|
+
headline: '未达标:1 项',
|
|
128
|
+
needsSkeleton: false,
|
|
129
|
+
band: 'task',
|
|
130
|
+
score: scoreObject,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const propsFor = (draft) => ({
|
|
134
|
+
sessionId: 'session-smoke',
|
|
135
|
+
useInput: () => ({ draft, phase: 'plain' }),
|
|
136
|
+
inputActions: { setDraft() {} },
|
|
137
|
+
t: undefined,
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const CASES = [
|
|
141
|
+
{ name: 'ScoreHint/空草稿', slot: 'conversation.composer.dock', draft: '', seed: [undefined] },
|
|
142
|
+
{ name: 'ScoreHint/含糊草稿(分数未到)', slot: 'conversation.composer.dock', draft: '改一下那个页面', seed: [undefined] },
|
|
143
|
+
{ name: 'ScoreHint/含糊草稿(面板档)', slot: 'conversation.composer.dock', draft: '改一下那个页面', seed: [scoreObject] },
|
|
144
|
+
{ name: 'ScoreHint/评分失败态', slot: 'conversation.composer.dock', draft: '改一下那个页面', seed: [undefined, undefined, undefined, undefined, 'unauthorized'] },
|
|
145
|
+
{ name: 'HeroHint/空草稿', slot: 'conversation.hero.options', draft: '', seed: [undefined] },
|
|
146
|
+
{ name: 'HeroHint/有草稿', slot: 'conversation.hero.options', draft: '帮我打开页面', seed: [undefined] },
|
|
147
|
+
{ name: 'HeroHint/有分数', slot: 'conversation.hero.options', draft: '改一下那个页面', seed: [scoreObject] },
|
|
148
|
+
{ name: 'ReconcileTail/无状态', slot: 'conversation.chat.turnTail', draft: '', seed: [undefined] },
|
|
149
|
+
{ name: 'ReconcileTail/完整状态', slot: 'conversation.chat.turnTail', draft: '', seed: [taskState] },
|
|
150
|
+
{ name: 'ReconcileTail/读取失败', slot: 'conversation.chat.turnTail', draft: '', seed: [undefined, false, false, 'not found'] },
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
let passed = 0
|
|
154
|
+
const failures = []
|
|
155
|
+
for (const testCase of CASES) {
|
|
156
|
+
seeds = testCase.seed
|
|
157
|
+
seedIndex = 0
|
|
158
|
+
try {
|
|
159
|
+
const guardedComponent = registered.get(testCase.slot)
|
|
160
|
+
const Component = innerOf(guardedComponent) ?? guardedComponent
|
|
161
|
+
assert.equal(typeof Component, 'function', `${testCase.name}: 拿不到组件函数`)
|
|
162
|
+
const out = Component(propsFor(testCase.draft))
|
|
163
|
+
assert.ok(out === null || typeof out === 'object', `${testCase.name}: 返回值既不是元素也不是 null(${typeof out})`)
|
|
164
|
+
passed++
|
|
165
|
+
} catch (error) {
|
|
166
|
+
failures.push(`${testCase.name}: ${error?.name ?? 'Error'}: ${error?.message ?? error}`)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (failures.length > 0) {
|
|
171
|
+
console.error('客户端冒烟失败:')
|
|
172
|
+
for (const failure of failures) console.error(' ✗ ' + failure)
|
|
173
|
+
process.exitCode = 1
|
|
174
|
+
} else {
|
|
175
|
+
console.log(`客户端冒烟:${passed}/${CASES.length} 场景渲染通过(槽位 ${registered.size} 个,无异常)`)
|
|
176
|
+
}
|
package/test/selfcheck.mjs
CHANGED
|
@@ -14,7 +14,10 @@ import {
|
|
|
14
14
|
} from '../src/taskfile.js'
|
|
15
15
|
import { judgeItem, judgeAll, summarize, formatReport } from '../src/evidence.js'
|
|
16
16
|
import { reconcile, overlay, setManual, readEvidence, readTask, WRITER, currentVerdict } from '../src/reconcile.js'
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
rankCandidates, buildQuestion, extractPaths, collectFacts, FALLBACK_OPTION, MAX_OPTIONS,
|
|
19
|
+
detectTaskKind, buildIntakeQuestions, composePrompt,
|
|
20
|
+
} from '../src/probe.js'
|
|
18
21
|
import { admitLocalRequest, hostnameOf } from '../src/http-guard.js'
|
|
19
22
|
|
|
20
23
|
let passed = 0
|
|
@@ -63,14 +66,28 @@ const NOW = Date.parse('2026-11-28T10:00:00.000Z')
|
|
|
63
66
|
})
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
test('
|
|
69
|
+
test('打分:十项分值表与规格一致', () => {
|
|
67
70
|
const map = Object.fromEntries(SIGNALS.map((s) => [s.id, s.delta]))
|
|
68
71
|
assert.deepEqual(map, {
|
|
69
72
|
deictic: 18, noCriterion: 15, wideWrite: 12, topicShift: 8, reworkHistory: 15,
|
|
70
|
-
tooShort: 10, namedDeliverable: -10, acceptanceWords: -20, readOnly: -15,
|
|
73
|
+
tooShort: 10, gibberish: 15, namedDeliverable: -10, acceptanceWords: -20, readOnly: -15,
|
|
71
74
|
})
|
|
72
75
|
})
|
|
73
76
|
|
|
77
|
+
test('打分:乱码命中 gibberish,且不误伤中文与正常英文', () => {
|
|
78
|
+
const gibberish = scoreRequest('adsadadsdaffeew')
|
|
79
|
+
assert.ok(gibberish.hits.some((h) => h.id === 'gibberish'), '乱码没被识别')
|
|
80
|
+
assert.ok(gibberish.raw >= 30, `乱码分值应 ≥ 30,实际 ${gibberish.raw}`)
|
|
81
|
+
assert.equal(gibberish.band, 'none', '乱码仍不该打断(只让读数诚实)')
|
|
82
|
+
|
|
83
|
+
for (const text of ['fix the login bug', 'refactor auth module to use hooks', 'userAgentHeaderName']) {
|
|
84
|
+
assert.ok(!scoreRequest(text).hits.some((h) => h.id === 'gibberish'), `误伤英文:${text}`)
|
|
85
|
+
}
|
|
86
|
+
for (const text of ['把首页弄好看点', '做一段一分钟的动画片']) {
|
|
87
|
+
assert.ok(!scoreRequest(text).hits.some((h) => h.id === 'gibberish'), `误伤中文:${text}`)
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
74
91
|
test('打分:夹到 0~100', () => {
|
|
75
92
|
assert.equal(scoreRequest('').raw, 0)
|
|
76
93
|
const heavy = scoreRequest('那个上次说的老样子那个', { reworkCount: 3 })
|
|
@@ -890,6 +907,9 @@ x
|
|
|
890
907
|
'把上次那份数据整理一下导出成 xlsx',
|
|
891
908
|
'重构整个项目',
|
|
892
909
|
'解释一下「零模型调用」是什么意思',
|
|
910
|
+
'adsadadsdaffeew',
|
|
911
|
+
'asdfghjkl',
|
|
912
|
+
'userAgentHeaderName',
|
|
893
913
|
'',
|
|
894
914
|
]
|
|
895
915
|
test('客户端打分器:与宿主逐项一致(raw / band / hits / escalations / chars)', () => {
|
|
@@ -929,6 +949,41 @@ x
|
|
|
929
949
|
})
|
|
930
950
|
}
|
|
931
951
|
|
|
952
|
+
/* --------------------- 10. 任务维度提问(intake) --------------------- */
|
|
953
|
+
{
|
|
954
|
+
const CASES = [
|
|
955
|
+
['做一段一分钟的动画片', 'animation', '风格'],
|
|
956
|
+
['改一下那个页面', 'page', '视觉方向'],
|
|
957
|
+
['写一份周报', 'doc', '受众'],
|
|
958
|
+
['修一下这个 bug', 'code', '改动范围'],
|
|
959
|
+
['随便弄点东西', 'generic', '交付物'],
|
|
960
|
+
]
|
|
961
|
+
for (const [request, kind, dimensionLabel] of CASES) {
|
|
962
|
+
test(`intake:识别「${request}」为 ${kind} 并问「${dimensionLabel}」`, () => {
|
|
963
|
+
assert.equal(detectTaskKind(request).kind, kind)
|
|
964
|
+
const questions = buildIntakeQuestions(request)
|
|
965
|
+
assert.ok(questions.length >= 1 && questions.length <= 2, `问题数异常:${questions.length}`)
|
|
966
|
+
assert.ok(questions.some((q) => q.header.includes(dimensionLabel)), JSON.stringify(questions.map((q) => q.header)))
|
|
967
|
+
})
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
test('intake:问完能拼出可执行的补全提示词', () => {
|
|
971
|
+
const prompt = composePrompt(
|
|
972
|
+
'做一段一分钟的动画片',
|
|
973
|
+
[{ id: 'style', answer: '粗描边贴纸' }],
|
|
974
|
+
[{ path: 'assets/anim/intro.tsx' }],
|
|
975
|
+
)
|
|
976
|
+
assert.match(prompt, /一分钟/)
|
|
977
|
+
assert.match(prompt, /粗描边贴纸/)
|
|
978
|
+
assert.match(prompt, /assets\/anim\/intro\.tsx/)
|
|
979
|
+
assert.match(prompt, /按以上要求执行/)
|
|
980
|
+
})
|
|
981
|
+
|
|
982
|
+
test('intake:没有答案时原样返回,不长出空话', () => {
|
|
983
|
+
assert.equal(composePrompt(' 做一段动画 ', [], []), '做一段动画')
|
|
984
|
+
})
|
|
985
|
+
}
|
|
986
|
+
|
|
932
987
|
/* -------------------------------- 汇总 -------------------------------- */
|
|
933
988
|
const total = passed + failed
|
|
934
989
|
console.log(`\n自检:${passed}/${total} 通过${failed > 0 ? `,${failed} 失败` : ''}`)
|
|
@@ -938,4 +993,4 @@ if (failed > 0) {
|
|
|
938
993
|
}
|
|
939
994
|
process.exit(1)
|
|
940
995
|
}
|
|
941
|
-
console.log('全绿。覆盖:打分表 16 项 · TASK.md 解析/回写 14 项 · 证据判定 16 项 · 覆盖与防伪造 13 项 · 骨架与返工 4 项 · 跨站 8 项 · 候选排序 7 项 · 客户端打分器对拍 2 项 · 作用域护栏 1 项')
|
|
996
|
+
console.log('全绿。覆盖:打分表 16 项 · TASK.md 解析/回写 14 项 · 证据判定 16 项 · 覆盖与防伪造 13 项 · 骨架与返工 4 项 · 跨站 8 项 · 候选排序 7 项 · 客户端打分器对拍 2 项 · 作用域护栏 1 项 · 任务维度提问 8 项')
|