dsh-workplan 1.12.0 → 1.12.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.
@@ -62,6 +62,22 @@ export const MAX_AUDITED_SUBTASKS = 15;
62
62
  * that a single incidental word cannot trigger it.
63
63
  */
64
64
  export const MISMATCH_BLOCKING_SCORE = 3;
65
+ /**
66
+ * [P0-1] Domain coverage threshold.
67
+ *
68
+ * The MS2 run (2026-11-03) measured 11/29 required departments present: plans
69
+ * silently dropped whole domains (design/legal/security/devops) the user's own
70
+ * request names. A single incidental keyword is not evidence of a domain, so a
71
+ * department counts as *implied by the request* only when at least two of its
72
+ * catalogue keywords occur in the user text. Named so tests pin it.
73
+ */
74
+ export const REQUIRED_DEPARTMENT_MIN_HITS = 2;
75
+ /**
76
+ * Wording that turns a missing department into a deliberate exclusion. The plan
77
+ * must say 「不安排<部门>:理由」 in taskUnderstanding.assumptions; silence is
78
+ * what the gate rejects.
79
+ */
80
+ export const DEPARTMENT_EXCLUSION_CUES = /(?:不安排|不需要|未涉及|不涉及|排除|不含|无需|不启用)/;
65
81
  const NEGATION_PATTERN = /(?:不要|禁止|不得|严禁|不能|不可|切勿|避免)\s*([^\s,。;、,.;:!?!?\n]{1,28})/g;
66
82
  const QUANTITY_PATTERN = /(?:最多|至少|不超过|不能超过|上限|下限|必须|只能|只允许|仅)\s*([^,。;;!?!?\n]{1,40})/g;
67
83
  const HARD_QUANTITY_PREFIX = /^(?:最多|至少|不超过|不能超过|上限|下限)/;
@@ -284,21 +300,185 @@ function extractReferences(text) {
284
300
  });
285
301
  }
286
302
  }
287
- // Option letters are only references when the text also talks about options.
288
- if (/(?:选|选项|方案|可选|建议)/.test(text)) {
289
- const option = /(?:^|[^A-Za-z])([A-D])(?![A-Za-z])/.exec(text);
290
- if (option && !seen.has(option[1])) {
291
- seen.add(option[1]);
292
- references.push({
293
- token: option[1],
294
- resolvedBy: 'none',
295
- resolved: false,
296
- evidence: clauseOf(text, option.index, option[0].length),
297
- });
298
- }
303
+ /*
304
+ * [P0-2] Option letters are references only when a choice cue selects one.
305
+ *
306
+ * The old rule fired on any A-D letter as soon as the text said 建议/方案
307
+ * anywhere: MS2 case T05-04 ("A/B 探针…建议移入") was blocked as an unresolved
308
+ * pronoun it never contained, and Markdown list markers "A." would do the
309
+ * same. A letter now counts only when it directly follows a selection verb,
310
+ * which is the only structure that can actually mean "choose this option".
311
+ */
312
+ const option = /(?:选|选项|方案|可选|建议|采用|按)\s*(?:用\s*)?([A-D])(?![A-Za-z\/])/.exec(text);
313
+ if (option && !seen.has(option[1])) {
314
+ seen.add(option[1]);
315
+ references.push({
316
+ token: option[1],
317
+ resolvedBy: 'none',
318
+ resolved: false,
319
+ evidence: clauseOf(text, option.index, option[0].length),
320
+ });
299
321
  }
300
322
  return references;
301
323
  }
324
+ /**
325
+ * [P0-2] Pronoun antecedent extraction.
326
+ *
327
+ * Before this, any non-empty conversation turned every pronoun into
328
+ * `resolvedBy: 'context'` — the audit claimed "它 was resolved" even when the
329
+ * context was "进展到哪一步了" or talked about something else entirely, so a
330
+ * plan could be dispatched on a guess. Resolution now requires an actual noun
331
+ * phrase in the recent conversation:
332
+ *
333
+ * - a cue (`用户…:` / `使用` / `针对` / `把`…) followed by the phrase, or
334
+ * - a topic sentence (`我们在聊…`, `讨论了…`);
335
+ *
336
+ * and phrases made only of function words (`把` / `问题` / `这个`…) are refused,
337
+ * so an empty promise cannot be manufactured. When nothing qualifies the
338
+ * reference stays unresolved and the plan is blocked as `needs-context`
339
+ * (strict mode) or recorded as a warning (rollback switch).
340
+ */
341
+ const ANTECEDENT_CUES = [
342
+ /(?:^|[::。;;\n])\s*(?:用户|需求|任务|要求|目标|对象)?\s*(?:上一轮|上一条|刚才|之前|前面)?\s*[说讲提]:?\s*/g,
343
+ /(?:使用|针对|关于|围绕|涉及|改造|修改|调整|优化|修复|处理|把|将|对)\s*/g,
344
+ /(?:和|与|同|跟)\s*[\u4e00-\u9fffA-Za-z0-9_\-\.]{2,12}?(?:相关|有关|有关联)/g,
345
+ // Options: "给出 A 方案(…)与 B 方案(只跑增量)", "我们在聊 X"/"讨论了 X".
346
+ /(?:在聊|聊到|讨论了|商量了|谈到了|提到|列出|提供|给出|可选)\s*/g,
347
+ ];
348
+ const FUNCTION_WORD_ONLY = /^(?:那|这|些|个|位|次|样|里|边|面|中|上|下|我们|你们|他们|它|他|她|是|的|了|在|有|做|干|弄|搞|看|说|问|聊|讨论|事情|东西|问题|内容|功能|东西|部分|那块|这块)+$/;
349
+ const ANTECEDENT_MAX_LENGTH = 12;
350
+ /** Refuse function-word-only fragments: they carry no referent. */
351
+ function isMeaningfulAntecedent(candidate) {
352
+ const value = candidate.trim();
353
+ if (value.length < 2 || value.length > ANTECEDENT_MAX_LENGTH)
354
+ return false;
355
+ // An option label ("A 方案") is a referent: it points at a lettered choice.
356
+ if (/^[A-D](?:方案|选项)$/.test(value))
357
+ return true;
358
+ /*
359
+ * A pronoun is not its own antecedent: "把它改一下" leaves "它" behind at the
360
+ * start of the clause, and accepting that would resolve 它 to itself.
361
+ */
362
+ if (/^(?:它|他|她|这|那|其)(?:们)?$/.test(value) || /^(?:它|他|她|这|那|其)/.test(value))
363
+ return false;
364
+ if (!/[\u4e00-\u9fffA-Za-z]/.test(value))
365
+ return false;
366
+ return !FUNCTION_WORD_ONLY.test(value);
367
+ }
368
+ /**
369
+ * Find the phrase a pronoun points at in the recent conversation.
370
+ *
371
+ * Returns `null` — never a fabricated phrase — when the conversation names no
372
+ * candidate. Callers must treat `null` as "still ambiguous".
373
+ */
374
+ export function resolvePronounAntecedent(token, conversationContext) {
375
+ const text = String(conversationContext ?? '').trim();
376
+ if (!text || text.length > 20000)
377
+ return null;
378
+ for (const pattern of ANTECEDENT_CUES) {
379
+ pattern.lastIndex = 0;
380
+ for (const match of text.matchAll(pattern)) {
381
+ const start = (match.index ?? 0) + match[0].length;
382
+ const found = antecedentAfterCue(text, start);
383
+ if (found)
384
+ return found;
385
+ }
386
+ }
387
+ return null;
388
+ }
389
+ /**
390
+ * Split one clause into candidate noun phrases.
391
+ *
392
+ * Whitespace, 、 and the connectors 与/和/及 separate phrases — but an option
393
+ * letter is a prefix, not a phrase of its own: "A 方案" must stay one candidate,
394
+ * otherwise the letter is lost and the option cannot be matched.
395
+ */
396
+ export function splitAntecedentCandidates(clause) {
397
+ const parts = [];
398
+ let current = '';
399
+ const isWordChar = (char) => !!char && /[\u4e00-\u9fffA-Za-z0-9_]/.test(char);
400
+ for (let index = 0; index < clause.length; index += 1) {
401
+ const char = clause[index];
402
+ if (',,、'.includes(char)) {
403
+ parts.push(current);
404
+ current = '';
405
+ continue;
406
+ }
407
+ if ('与和及'.includes(char)) {
408
+ // "A 方案与 B 方案": a connector right after an option label is a separator.
409
+ const soFar = current.trim();
410
+ if (/[A-D](?:方案|选项)$/.test(soFar)) {
411
+ parts.push(current);
412
+ current = '';
413
+ continue;
414
+ }
415
+ }
416
+ if (/s/.test(char) || char === ' ') {
417
+ const soFar = current.trim();
418
+ const next = clause.slice(index).trimStart();
419
+ // Glue an option letter to the word that follows it.
420
+ if (/^[A-D]$/.test(soFar) && /^(?:方案|选项)/.test(next)) {
421
+ current += char;
422
+ continue;
423
+ }
424
+ if (isWordChar(clause[index - 1]) || isWordChar(next[0])) {
425
+ parts.push(current);
426
+ current = '';
427
+ continue;
428
+ }
429
+ continue;
430
+ }
431
+ if ('()()'.includes(char)) {
432
+ // Parentheses are skipped entirely; their content is not the referent.
433
+ const close = clause.indexOf(char === '(' ? ')' : char === '(' ? ')' : char, index + 1);
434
+ if (close >= 0) {
435
+ index = close;
436
+ parts.push(current);
437
+ current = '';
438
+ continue;
439
+ }
440
+ }
441
+ current += char;
442
+ }
443
+ parts.push(current);
444
+ return parts
445
+ .map((part) => part.replace(/[(())]/g, '').trim())
446
+ .filter((part) => part.length > 0);
447
+ }
448
+ function cleanAntecedentCandidate(part) {
449
+ return part
450
+ .replace(/\u0000/g, '')
451
+ .replace(/^(?:把|将|对|使用|针对|关于|围绕|涉及|改造|修改|调整|优化|修复|处理)\s*/, '')
452
+ .replace(/(?:改成|改为|修正成|调整成|设成|变为|换成|变成|默认为|默认|保持|不用|不要|可以|需要|看看|检查一下|是什么|怎么样|如何).*$/, '')
453
+ // Parentheticals are not part of the referent: "B 方案(只跑增量)" -> "B 方案".
454
+ .replace(/[((][^))]*[))]/g, '')
455
+ .replace(/[,,。!?!?;;::、\s]+$/, '')
456
+ .trim();
457
+ }
458
+ /**
459
+ * Read the clause that starts at `start` and return the first meaningful noun
460
+ * phrase in it. A verb left at the start (`把…`) is dropped by
461
+ * `cleanAntecedentCandidate`; the clause never crosses a sentence boundary.
462
+ */
463
+ function antecedentAfterCue(text, start) {
464
+ const tail = text.slice(start);
465
+ const stop = tail.search(/[。!?!?\n;;]/);
466
+ const clause = (stop >= 0 ? tail.slice(0, stop) : tail).trim();
467
+ if (!clause)
468
+ return null;
469
+ /*
470
+ * The clause may chain several noun phrases ("A 方案…与 B 方案…"). Split at
471
+ * the connector and at whitespace so each candidate is one noun phrase; the
472
+ * caller compares them to the pronoun token and picks the matching one.
473
+ */
474
+ const parts = splitAntecedentCandidates(clause);
475
+ for (const part of parts) {
476
+ const cleaned = cleanAntecedentCandidate(part).replace(/^[((]|[))]$/g, '');
477
+ if (isMeaningfulAntecedent(cleaned))
478
+ return { antecedent: cleaned, source: clause.slice(0, 80) };
479
+ }
480
+ return null;
481
+ }
302
482
  function extractConflicts(text) {
303
483
  const conflicts = [];
304
484
  const seen = new Set();
@@ -405,6 +585,56 @@ function flattenPlanSubtasks(plan) {
405
585
  }
406
586
  return subtasks;
407
587
  }
588
+ /**
589
+ * [P0-1] Which department domains the user's request itself implies, and which
590
+ * of them the plan never addresses.
591
+ *
592
+ * Root cause this closes: before 1.12.1 the audit only asked "does the chosen
593
+ * department fit?" — a plan could omit an entire domain the request names and
594
+ * still pass, because nothing asked "is a domain missing?". MS2 measured the
595
+ * consequence: 11/29 required departments covered.
596
+ *
597
+ * A missing department is forgiven only when the plan states the exclusion in
598
+ * `taskUnderstanding.assumptions` / `unknowns` with one of
599
+ * DEPARTMENT_EXCLUSION_CUES, so omission must be a written decision instead of
600
+ * silence. Pure and deterministic: no model, no I/O.
601
+ */
602
+ export function auditDepartmentCoverage(taskText, plan) {
603
+ const text = typeof taskText === 'string' ? taskText.trim() : '';
604
+ if (text === '')
605
+ return { required: [], missing: [], excluded: [] };
606
+ const used = new Set(flattenPlanSubtasks(plan)
607
+ .map((subtask) => (typeof subtask?.department === 'string' ? subtask.department : ''))
608
+ .filter((department) => department !== ''));
609
+ const statements = [];
610
+ for (const key of ['assumptions', 'unknowns']) {
611
+ const list = plan?.taskUnderstanding?.[key];
612
+ if (!Array.isArray(list))
613
+ continue;
614
+ for (const item of list)
615
+ if (typeof item === 'string' && item.trim() !== '')
616
+ statements.push(item.trim());
617
+ }
618
+ const required = [];
619
+ const missing = [];
620
+ const excluded = [];
621
+ for (const capability of DEPARTMENT_CAPABILITIES) {
622
+ const hits = matchDepartmentKeywords(text, capability.id);
623
+ if (hits.length < REQUIRED_DEPARTMENT_MIN_HITS)
624
+ continue;
625
+ const entry = { department: capability.id, departmentLabel: capability.zh, hits };
626
+ required.push(entry);
627
+ if (used.has(capability.id))
628
+ continue;
629
+ const reason = statements.find((statement) => ((statement.includes(capability.zh) || statement.includes(capability.id))
630
+ && DEPARTMENT_EXCLUSION_CUES.test(statement)));
631
+ if (reason)
632
+ excluded.push({ ...entry, reason: reason.slice(0, 300) });
633
+ else
634
+ missing.push(entry);
635
+ }
636
+ return { required, missing, excluded };
637
+ }
408
638
  /**
409
639
  * Explain one department choice with the catalog keywords that support it.
410
640
  *
@@ -540,7 +770,7 @@ function emptyAudit(anchor, reason) {
540
770
  version: UNDERSTANDING_AUDIT_VERSION,
541
771
  anchor,
542
772
  stage1: { elements: [], hardCount: 0, references: [], conflicts: [], deliverableClauses: [] },
543
- stage2: { assignments: [], departmentsUsed: [], mismatches: [] },
773
+ stage2: { assignments: [], departmentsUsed: [], mismatches: [], requiredDepartments: [], missingDepartments: [], excludedDepartments: [] },
544
774
  stage3: {
545
775
  verdict: 'degraded',
546
776
  rewritten: false,
@@ -569,6 +799,7 @@ export function auditTaskUnderstanding(plan, context = {}) {
569
799
  const planText = collectPlanText(plan);
570
800
  const assignments = flattenPlanSubtasks(plan).map((subtask) => departmentFit(subtask, taskText));
571
801
  const departmentsUsed = [...new Set(assignments.map((entry) => entry.department))];
802
+ const coverage = auditDepartmentCoverage(taskText, plan);
572
803
  const mismatches = assignments
573
804
  .filter((entry) => entry.verdict === 'mismatch')
574
805
  .map((entry) => `${entry.subtaskId || '(无 ID)'} → ${entry.departmentLabel}:${entry.reason}`);
@@ -594,19 +825,38 @@ export function auditTaskUnderstanding(plan, context = {}) {
594
825
  .map((element) => `${element.kind}:${element.value}`);
595
826
  const hardTotal = extracted.elements.filter((element) => element.hard).length;
596
827
  const summaryCoverage = hardTotal === 0 ? 1 : (hardTotal - droppedFromSummary.length) / hardTotal;
597
- const unresolved = extracted.references.filter((reference) => !reference.resolved
598
- && (typeof context.conversationContext !== 'string' || context.conversationContext.trim() === ''));
599
- const resolvedByContext = extracted.references.map((reference) => (!reference.resolved
600
- && typeof context.conversationContext === 'string'
601
- && context.conversationContext.trim() !== ''
602
- ? { ...reference, resolved: true, resolvedBy: 'context' }
603
- : reference));
828
+ /*
829
+ * [P0-2] Resolution requires an antecedent, not merely a non-empty context.
830
+ * The old rule marked every pronoun resolved as soon as any conversation
831
+ * existed, so "把它改成默认收起" passed with a context that talked about
832
+ * something else. Now the phrase is extracted and quoted; otherwise the
833
+ * reference stays unresolved and blocks (or warns in rollback mode).
834
+ */
835
+ const conversation = typeof context.conversationContext === 'string' ? context.conversationContext : '';
836
+ const resolvedByContext = extracted.references.map((reference) => {
837
+ if (reference.resolved)
838
+ return reference;
839
+ const found = resolvePronounAntecedent(reference.token, conversation);
840
+ if (!found)
841
+ return reference;
842
+ // Option letters are resolved only when the conversation lists that option
843
+ // as a listed choice ("A 方案" / "B 选项"), not a bare letter in a word.
844
+ const listedOption = new RegExp('(?:^|[^A-Za-z])' + reference.token + '\\s*(?:方案|选项)');
845
+ if (/^[A-D]$/.test(reference.token) && !listedOption.test(conversation))
846
+ return reference;
847
+ return { ...reference, resolved: true, resolvedBy: 'context', antecedent: found.antecedent };
848
+ });
849
+ const unresolved = resolvedByContext.filter((reference) => !reference.resolved);
604
850
  const reasons = [];
605
851
  let verdict = 'aligned';
606
852
  if (missingHardAnchors.length > 0) {
607
853
  verdict = 'deviation';
608
854
  reasons.push(`用户原要求中的 ${missingHardAnchors.length} 个硬要素在计划中完全缺失:${missingHardAnchors.slice(0, 6).join('、')}`);
609
855
  }
856
+ if (coverage.missing.length > 0) {
857
+ verdict = 'deviation';
858
+ reasons.push(`用户原要求涉及 ${coverage.missing.length} 个部门领域,计划既未安排也未写明排除理由:${coverage.missing.map((entry) => entry.departmentLabel).join('、')}`);
859
+ }
610
860
  if (mismatches.length > 0) {
611
861
  if (verdict === 'aligned')
612
862
  verdict = 'deviation';
@@ -620,7 +870,7 @@ export function auditTaskUnderstanding(plan, context = {}) {
620
870
  if (unresolved.length > 0) {
621
871
  if (verdict === 'aligned')
622
872
  verdict = 'needs-context';
623
- reasons.push(`含指代的任务缺少对话上下文:${unresolved.map((reference) => reference.token).join('、')},不应在未澄清前派发`);
873
+ reasons.push(`含指代的任务在最近对话里找不到先行词:${unresolved.map((reference) => reference.token).join('、')},不应在未澄清前派发`);
624
874
  }
625
875
  if (verdict === 'aligned') {
626
876
  reasons.push(`硬要素 ${hardTotal - missingHardAnchors.length}/${hardTotal} 全部保留;${assignments.length} 个子任务的部门有目录关键词支撑`);
@@ -635,7 +885,14 @@ export function auditTaskUnderstanding(plan, context = {}) {
635
885
  conflicts: extracted.conflicts,
636
886
  deliverableClauses: extracted.deliverableClauses,
637
887
  },
638
- stage2: { assignments, departmentsUsed, mismatches },
888
+ stage2: {
889
+ assignments,
890
+ departmentsUsed,
891
+ mismatches,
892
+ requiredDepartments: coverage.required,
893
+ missingDepartments: coverage.missing,
894
+ excludedDepartments: coverage.excluded,
895
+ },
639
896
  stage3: {
640
897
  verdict,
641
898
  rewritten: !verbatim,
@@ -682,11 +939,19 @@ export function validatePlanContext(plan, context = {}) {
682
939
  errors.push(`CLARIFY: ${audit.stage3.reasons.find((reason) => reason.includes('自相矛盾')) ?? '用户要求存在矛盾,必须先向用户确认'}`);
683
940
  }
684
941
  if (audit.stage3.verdict === 'needs-context') {
685
- errors.push(`CONTEXT: ${audit.stage3.reasons.find((reason) => reason.includes('指代')) ?? '任务含指代但缺少对话上下文,必须先向用户确认'}`);
942
+ errors.push(`CONTEXT: ${audit.stage3.reasons.find((reason) => reason.includes('指代')) ?? '任务含指代但在最近对话中找不到先行词,必须先向用户确认'}`);
686
943
  }
687
944
  for (const missing of audit.stage3.missingHardAnchors.slice(0, 6)) {
688
945
  errors.push(`DEVIATION: 用户原要求中的硬要素「${missing}」在计划中完全缺失,请补回或说明为什么可以省略`);
689
946
  }
947
+ /*
948
+ * [P0-1] Missing domain coverage is blocking, not a warning: MS2 showed a
949
+ * plan can look internally consistent while silently dropping design/legal/
950
+ * security/devops, which is exactly what "必须高" cannot tolerate.
951
+ */
952
+ for (const entry of audit.stage2.missingDepartments.slice(0, 6)) {
953
+ errors.push(`COVERAGE: 用户原要求涉及「${entry.departmentLabel}」领域(命中 ${entry.hits.slice(0, 4).join('、')}),计划既没有该部门的子任务,也没有在 taskUnderstanding.assumptions 写明「不安排${entry.departmentLabel}:理由」`);
954
+ }
690
955
  for (const assignment of audit.stage2.assignments) {
691
956
  if (assignment.verdict !== 'mismatch')
692
957
  continue;
@@ -730,6 +995,22 @@ export function compactUnderstandingAudit(audit) {
730
995
  })),
731
996
  departmentsUsed: audit.stage2.departmentsUsed,
732
997
  mismatches: audit.stage2.mismatches,
998
+ requiredDepartments: audit.stage2.requiredDepartments.map((entry) => ({
999
+ department: entry.department,
1000
+ departmentLabel: entry.departmentLabel,
1001
+ hits: entry.hits.slice(0, 4),
1002
+ })),
1003
+ missingDepartments: audit.stage2.missingDepartments.map((entry) => ({
1004
+ department: entry.department,
1005
+ departmentLabel: entry.departmentLabel,
1006
+ hits: entry.hits.slice(0, 4),
1007
+ })),
1008
+ excludedDepartments: audit.stage2.excludedDepartments.map((entry) => ({
1009
+ department: entry.department,
1010
+ departmentLabel: entry.departmentLabel,
1011
+ hits: entry.hits.slice(0, 4),
1012
+ reason: entry.reason,
1013
+ })),
733
1014
  },
734
1015
  stage3: {
735
1016
  verdict: audit.stage3.verdict,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-workplan",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "Automatic task decomposition, real department subagents, and a responsive workplan dashboard for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -115,6 +115,10 @@ export const DEPARTMENT_CAPABILITIES: readonly DepartmentCapability[] = Object.f
115
115
  keywords: [
116
116
  '安全', '漏洞', '渗透', '攻击', '越权', '权限', '密钥', '加密',
117
117
  '威胁', '加固', '审计日志',
118
+ // [P0-1 recall] Naming an evaluation standard (ISO/IEC 15408 = CC) is a
119
+ // security ask the catalog could not see: MS2 T05-05 was planned without
120
+ // any security subtask.
121
+ 'ISO', '15408', 'CC', '等保', '安全评估',
118
122
  ],
119
123
  },
120
124
  {
@@ -126,6 +130,10 @@ export const DEPARTMENT_CAPABILITIES: readonly DepartmentCapability[] = Object.f
126
130
  keywords: [
127
131
  '发布', '部署', '上线', 'CI', '流水线', '监控', '回滚', '镜像', '制品',
128
132
  'npm', 'registry', 'tag', 'release', 'publish', '索引源',
133
+ // [P0-1 recall] Release nouns: the Chinese word for a release tag was
134
+ // missing entirely, so MS2 T05-06 ("打 v1.5.1 标签") named devops work
135
+ // the catalog could not see.
136
+ '标签', '打标签', '发版', '打…标签',
129
137
  ],
130
138
  },
131
139
  {
@@ -153,7 +161,19 @@ export const DEPARTMENT_CAPABILITIES: readonly DepartmentCapability[] = Object.f
153
161
  en: 'Legal',
154
162
  responsibilities: ['合同与条款审查', '版权、许可与合规', '隐私与授权风险'],
155
163
  outputs: ['法务意见', '合同条款', '合规清单'],
156
- keywords: ['法务', '合同', '版权', '许可', '合规', '条款', '法律', '隐私', '授权', '侵权'],
164
+ // [P0-2 recall] An evaluation/certification standard is a compliance claim,
165
+ // not just a security one: MS2 T05-05 named 「ISO/IEC 15408(CC)国际标准」
166
+ // and got legal as a single incidental hit. These add the standard-level
167
+ // wording only — no single CJK character, so 「法」 alone still matches nothing.
168
+ //
169
+ // No ordered pair here on purpose: '国际…标准' was tried and removed because it
170
+ // fires on the same span as the existing '国际标准' (「参考国际标准做一下排版」
171
+ // went from 1 hit to 2 and crossed REQUIRED_DEPARTMENT_MIN_HITS). T05-05 still
172
+ // hits 5 keywords without it.
173
+ keywords: [
174
+ '法务', '合同', '版权', '许可', '合规', '条款', '法律', '隐私', '授权', '侵权', '国际标准',
175
+ 'ISO/IEC 15408', '15408', 'ISO/IEC', 'ISO 标准', 'CC 标准',
176
+ ],
157
177
  },
158
178
  {
159
179
  id: 'finance',
@@ -186,6 +206,9 @@ export function departmentCapability(id: unknown): DepartmentCapability | null {
186
206
  return CAPABILITY_MAP[id] ?? null
187
207
  }
188
208
 
209
+ /** Max characters allowed between the two halves of an ordered-pair keyword. */
210
+ const KEYWORD_PAIR_MAX_GAP = 12
211
+
189
212
  function escapeRegExp(value: string): string {
190
213
  return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
191
214
  }
@@ -200,6 +223,21 @@ export function keywordHit(text: string, keyword: string): boolean {
200
223
  const haystack = text.toLowerCase()
201
224
  const needle = keyword.trim().toLowerCase()
202
225
  if (!needle) return false
226
+ // Ordered pair ("打…标签"): CJK inserts objects between verb and noun, so a
227
+ // substring match cannot see 「打 v1.5.1 标签」. Both parts must occur in
228
+ // order and within a short window, otherwise it is not the same sentence.
229
+ if (needle.includes('…')) {
230
+ const parts = needle.split('…').filter(Boolean)
231
+ if (parts.length < 2) return false
232
+ let from = 0
233
+ for (const [index, part] of parts.entries()) {
234
+ const at = haystack.indexOf(part, from)
235
+ if (at < 0) return false
236
+ if (index > 0 && at - from > KEYWORD_PAIR_MAX_GAP) return false
237
+ from = at + part.length
238
+ }
239
+ return true
240
+ }
203
241
  if (/^[a-z0-9+#./-]+$/.test(needle) && needle.length <= 3) {
204
242
  return new RegExp(`(^|[^a-z0-9])${escapeRegExp(needle)}([^a-z0-9]|$)`).test(haystack)
205
243
  }
package/src/host.ts CHANGED
@@ -1255,7 +1255,7 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
1255
1255
 
1256
1256
  export const meta = {
1257
1257
  name,
1258
- version: '1.12.0',
1258
+ version: '1.12.1',
1259
1259
  promptOrder: PROMPT_ORDER,
1260
1260
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
1261
1261
  }
package/src/plan.ts CHANGED
@@ -988,6 +988,7 @@ export function buildPlannerPrompt(taskText: any, cwd: any, conversationContext:
988
988
  '1. 抽取要素:先从用户原文里逐项抽出硬要素——版本号、数量与单位、日期、文件路径、任务/缺陷编号(如 T11、U-15)、数值上限、显式否定(不要/禁止/不得)、指代(它/这个/B)。写进 taskUnderstanding.anchors,一条一项,不得改写数字与编号。',
989
989
  '2. 匹配部门:按「部门职责 + 典型产物」匹配,不要按名字熟悉度分配。每个子任务必须在 departmentRationale 里写清:命中该部门哪条职责、对应任务里的哪个要素。',
990
990
  '3. 偏离自检:逐条核对用户原要求是否被某个子任务的 objective/outputs/acceptance 覆盖。漏掉的必须写进 unknowns 或 assumptions 并说明;不得静默丢弃,也不得把一个要求拆成看似完成。',
991
+ '3.1 部门覆盖自检(硬性):若用户原文里某个部门的职责词命中 2 个以上(例如出现「截图」「红圈」「布局」即涉及 design),而你的计划没有该部门的子任务,就必须在 taskUnderstanding.assumptions 里写一条「不安排<部门中文名>:理由」。既不安排、也不写明理由的计划会被校验直接拒绝(COVERAGE)。',
991
992
  '4. 指代只在最近对话里解析;对话里没有答案时,写进 unknowns 并说明需要用户澄清,不要自行猜测。',
992
993
  '5. 若用户要求彼此冲突(例如同一对象既要求展开又要求收起、既要求只改 A 又要求同时改 B),写进 contradictions.secondary 并说明需要用户决定,不要擅自选一个执行。',
993
994
  '',
package/src/runtime.ts CHANGED
@@ -2443,7 +2443,12 @@ export function reconstructFromSession(session: any, targetPlanId?: string) {
2443
2443
  if (snap) {
2444
2444
  try {
2445
2445
  snap.statuses = applyStatus(snap.statuses, update.subtaskId, {
2446
- status: update.status,
2446
+ /*
2447
+ * handoff 的 durable 记录携带的是状态快照,不是一次状态迁移。
2448
+ * 重放时若再走 done 分支,会把已经 reported 的行打回 done 并抛
2449
+ * INVALID_TRANSITION(wp-79c31abf 的 H1 就是这样被丢掉的)。
2450
+ */
2451
+ status: update.handoffs === undefined ? update.status : undefined,
2447
2452
  progress: typeof update.progress === 'number' ? update.progress : undefined,
2448
2453
  summary: typeof update.note === 'string' ? update.note : undefined,
2449
2454
  // [1.8.13] Evidence written through the update tool must survive replay.
@@ -2451,6 +2456,7 @@ export function reconstructFromSession(session: any, targetPlanId?: string) {
2451
2456
  acceptance: update.acceptance,
2452
2457
  artifacts: update.artifacts,
2453
2458
  missingArtifacts: update.missingArtifacts,
2459
+ handoffs: update.handoffs,
2454
2460
  revision: Number.isInteger(update.revision) ? update.revision : undefined,
2455
2461
  updatedBy: 'agent',
2456
2462
  })