dsh-reconcile 0.1.4 → 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 CHANGED
@@ -42,7 +42,12 @@ DeepSeek Harness 插件:**先核事实、再决定问不问、收工对账**
42
42
 
43
43
  - **先核事实**:查 git 最近改动 / mtime 前 10 / 本会话引用过的路径 / 页面目录与路由表,给 2~3 个带证据的候选;
44
44
  查不到才退化成开放问题(选项最后一项固定「我不知道,你替我定」)。
45
- - **含糊度打分**:9 条信号固定加减分,夹到 0~100;`<40` 不打断、`40~70` 轻提示、`>70` 先问再动手。
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)」;
@@ -135,12 +140,13 @@ TASK.evidence.json
135
140
  ## 自检(离线,不联网、不启宿主)
136
141
 
137
142
  ```sh
138
- node test/selfcheck.mjs # 82 项:打分表 / TASK.md / 三种证据判定 / 覆盖与防伪造 / 跨站 / 候选 / 客户端打分器对拍 / 作用域护栏
143
+ node test/selfcheck.mjs # 90 项:打分表 / TASK.md / 三种证据判定 / 覆盖与防伪造 / 跨站 / 候选 / 对拍 / 护栏 / 任务维度提问
144
+ node test/acceptance-intake.mjs # 乱码信号 + 维度提问的独立验收(TASK.md 用它当 command 证据)
139
145
  node test/client-smoke.mjs # 客户端冒烟:桩 React 里真渲染三个组件(抓「组件体引用未定义变量」这类运行时崩溃)
140
146
  ```
141
147
 
142
- 当前:**82/82 全绿**,客户端冒烟 **10/10 场景**通过。覆盖打分表 16 项、TASK.md 解析/回写 14 项、三种证据判定 16 项、
143
- evidence 覆盖与防伪造 13 项、骨架与返工 4 项、跨站拒绝 8 项、候选排序 7 项、客户端打分器对拍 2 项、作用域护栏 1 项。
148
+ 当前:**90/90 全绿**,客户端冒烟 **10/10 场景**通过。覆盖打分表 16 项、TASK.md 解析/回写 14 项、三种证据判定 16 项、
149
+ evidence 覆盖与防伪造 13 项、骨架与返工 4 项、跨站拒绝 8 项、候选排序 7 项、客户端打分器对拍 2 项、作用域护栏 1 项、任务维度提问 8 项。
144
150
 
145
151
  没有 `node` 的机器上,可以用 DSH 自带的 Electron 当 node:
146
152
 
@@ -171,7 +177,7 @@ $env:ELECTRON_RUN_AS_NODE='1'
171
177
  | 路由挂载成功 | info | `routes mounted (N)` + 路由路径列表 |
172
178
  | `connection.fetch` 不可用 | warn | 面板按钮会退化成只读 |
173
179
  | 每轮打分 | info | `scored` —— raw / band / 字数 / 是否写操作 |
174
- | `probe_intent` | info | 候选数量;事实收集失败记 `probe facts failed` |
180
+ | `probe_intent` | info | 候选数量;`probe ask`(任务类型 + 问题数)、`probe ask done`(维度答案数 + 选中目标);事实收集失败记 `probe facts failed` |
175
181
  | 写操作被 gate 拦下 | info | `write gated` + 工具名 + 分值 |
176
182
  | 收尾对账 | info | `auto-check start` / `auto-check skipped`(本轮模型已对过账) |
177
183
  | `reconcile` 工具 | info/error | `reconcile start` / `reconcile done`(耗时、未达标数)/ `reconcile failed` |
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/index.js CHANGED
@@ -20,7 +20,10 @@ import {
20
20
  import {
21
21
  reconcile, readTask, readEvidence, writeSkeleton, setManual, currentVerdict,
22
22
  } from './src/reconcile.js'
23
- import { collectFacts, rankCandidates, buildQuestion, formatCandidates } from './src/probe.js'
23
+ import {
24
+ collectFacts, rankCandidates, buildQuestion, formatCandidates,
25
+ detectTaskKind, buildIntakeQuestions, composePrompt,
26
+ } from './src/probe.js'
24
27
  import { admitLocalRequest, jsonHeaders } from './src/http-guard.js'
25
28
  import { createIo } from './host/io.js'
26
29
 
@@ -333,7 +336,9 @@ export function apply(ctx, rawConfig = {}) {
333
336
  '交账:先核事实、再问意图。用户用指代词(那个页面/上次那份数据/老样子)时,先调 action=probe:'
334
337
  + '它会查 git 最近改动、按 mtime 排序的文件、本会话引用过的路径、页面目录与路由表,返回 2~3 个**带证据**的候选。'
335
338
  + '然后调 action=ask,把候选作为可点选项问用户(最后一项固定「我不知道,你替我定」)。'
336
- + '没有证据的候选不会出现;查不到会退化成开放问题。禁止自己编候选。',
339
+ + '没有证据的候选不会出现;查不到会退化成开放问题。禁止自己编候选。'
340
+ + 'action=ask 还会按任务类型补问「效果」维度(动画问风格/节奏、页面问视觉方向/适配目标、文档问受众/篇幅、代码问改动范围/验收方式),'
341
+ + '总共最多 3 个问题;问完返回 completedPrompt —— 那是把原话和答案拼好的**可直接执行**的提示词,后续按它执行。',
337
342
  parameters: {
338
343
  type: 'object',
339
344
  properties: {
@@ -366,9 +371,11 @@ export function apply(ctx, rawConfig = {}) {
366
371
  log('info', 'probe', { request: request.slice(0, 60), candidates: candidates.length })
367
372
  entry.probe = { request, candidates, at: new Date().toISOString(), facts: summarizeFacts(facts) }
368
373
  const action = String(args?.action ?? 'probe')
374
+ const intake = detectTaskKind(request)
369
375
  if (action === 'probe') {
370
376
  return textResult([{
371
377
  request,
378
+ intake: { kind: intake.kind, label: intake.label, questions: buildIntakeQuestions(request) },
372
379
  candidates: candidates.map((c) => ({ path: c.path, score: c.score, evidence: c.evidence })),
373
380
  facts: summarizeFacts(facts),
374
381
  message: candidates.length === 0
@@ -388,17 +395,16 @@ export function apply(ctx, rawConfig = {}) {
388
395
  }
389
396
  const question = buildQuestion(request, candidates)
390
397
  if (typeof args?.question === 'string' && args.question.trim() !== '') question.question = args.question.trim()
391
- const answer = await questions.ask({
392
- questions: [{
393
- id: 'target',
394
- header: question.header,
395
- question: question.question,
396
- options: question.options,
397
- multiSelect: false,
398
- }],
399
- agent,
400
- signal: exec.signal,
401
- })
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 })
402
408
  // 模型按要求先问了 → 释放写操作 gate(下一轮用户输入会重新评估)
403
409
  entry.gateReleased = true
404
410
  log('info', 'probe asked, gate released', { candidates: candidates.length })
@@ -407,15 +413,24 @@ export function apply(ctx, rawConfig = {}) {
407
413
  const custom = item?.custom
408
414
  const chosen = custom && custom.trim() !== '' ? custom.trim() : (selected[0] ?? '')
409
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 })
410
423
  return textResult([{
411
424
  ok: true,
412
- answered: chosen !== '',
425
+ answered: chosen !== '' || dimensionAnswers.length > 0,
413
426
  selected: chosen,
414
427
  path: picked?.path ?? null,
415
428
  evidence: picked?.evidence ?? [],
429
+ answers: dimensionAnswers,
430
+ completedPrompt,
416
431
  candidates: candidates.map((c) => ({ path: c.path, evidence: c.evidence })),
417
- message: chosen === ''
418
- ? '用户跳过了这道题:不要当成同意。改为按最保守的假设做,并在答复末尾写「我按 X 理解做的」。'
432
+ message: (chosen === '' && dimensionAnswers.length === 0)
433
+ ? '用户跳过了这些问题:不要当成同意。改为按最保守的假设做,并在答复末尾写「我按 X 理解做的」。'
419
434
  : picked
420
435
  ? `用户指向 ${picked.path}(证据:${picked.evidence.join(';')})。接下来只对这个目标动手。`
421
436
  : `用户回答了「${chosen}」,与候选不完全一致,按用户原话执行。`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-reconcile",
3
- "version": "0.1.4",
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",
@@ -50,6 +50,7 @@
50
50
  "scripts": {
51
51
  "selfcheck": "node test/selfcheck.mjs",
52
52
  "smoke": "node test/client-smoke.mjs",
53
+ "accept": "node test/acceptance-intake.mjs",
53
54
  "test": "node test/selfcheck.mjs"
54
55
  },
55
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
+ }
@@ -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 { rankCandidates, buildQuestion, extractPaths, collectFacts, FALLBACK_OPTION, MAX_OPTIONS } from '../src/probe.js'
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 项')