dsh-workplan 1.12.1 → 1.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/README.en.md +2 -2
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/docs/decision-clarify-gate-20261104.md +41 -0
- package/lib/departments.js +7 -0
- package/lib/host.js +70 -3
- package/lib/plan.js +25 -0
- package/lib/runtime.js +160 -8
- package/lib/understanding.js +258 -2
- package/package.json +1 -1
- package/src/departments.ts +7 -0
- package/src/host.ts +81 -4
- package/src/plan.ts +26 -0
- package/src/runtime.ts +182 -7
- package/src/understanding.ts +256 -6
package/lib/understanding.js
CHANGED
|
@@ -386,6 +386,245 @@ export function resolvePronounAntecedent(token, conversationContext) {
|
|
|
386
386
|
}
|
|
387
387
|
return null;
|
|
388
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* [T3] Resolve a pronoun from the task text itself, in the sentence that holds
|
|
391
|
+
* it or the sentence immediately before it.
|
|
392
|
+
*
|
|
393
|
+
* MS2 T05-08 read 「…159667工业母机ETF国泰,下月全月…?准确预判后…告诉我,它每天…」
|
|
394
|
+
* — the name sits in the PREVIOUS sentence while the pronoun's own sentence is
|
|
395
|
+
* pure prose, so conversation-only resolution rejected the task as "no
|
|
396
|
+
* antecedent". A name the user wrote in the task is the strongest possible
|
|
397
|
+
* antecedent, so the task text is searched too:
|
|
398
|
+
*
|
|
399
|
+
* 1. the current sentence, before the pronoun;
|
|
400
|
+
* 2. only if that has no referent, the sentence right before it.
|
|
401
|
+
*
|
|
402
|
+
* Only explicit referents qualify: a quoted name, or an identifier-like span
|
|
403
|
+
* (「159667工业母机ETF国泰」/「159667」/「dsh-workplan」) — the boundaries a reader
|
|
404
|
+
* would use. Ordinary prose never qualifies, so a pronoun with no real referent
|
|
405
|
+
* still blocks (`needs-context`) instead of being resolved to filler.
|
|
406
|
+
*
|
|
407
|
+
* The scope is deliberately narrow: reaching further produced wrong antecedents
|
|
408
|
+
* in replay ("…昨天涨了" taken as a name). A blocked plan is recoverable; a plan
|
|
409
|
+
* dispatched on a guessed referent is not.
|
|
410
|
+
*/
|
|
411
|
+
const INLINE_SENTENCE_BOUNDARY = /[。!?!?\n]/;
|
|
412
|
+
const INLINE_NAME_CHAR = /[\u4e00-\u9fffA-Za-z0-9._-]/;
|
|
413
|
+
const INLINE_ENTITY_STOP = new Set('的是了在有我你他她它们这那吗呢吧啊呀就都也还又很太更最把被让给从到与和及或而但却则其该此每各么怎如何走涨跌买卖加减看好'.split(''));
|
|
414
|
+
const LEADING_REQUEST = /^(?:看一下|看下|看看|帮我|帮忙|麻烦|给我|我们|必须|需要|想要|关注|推荐|分析|预判|预测|研究|介绍|说说|告诉|查一下|查查|对比|比较|关于|针对|请|我|你|想|要|把|将|对)\s*/;
|
|
415
|
+
function isInlineSentenceBoundary(char) {
|
|
416
|
+
return !!char && INLINE_SENTENCE_BOUNDARY.test(char);
|
|
417
|
+
}
|
|
418
|
+
function isInlineNameChar(char) {
|
|
419
|
+
return !!char && INLINE_NAME_CHAR.test(char);
|
|
420
|
+
}
|
|
421
|
+
/** Drop request lead-ins so "我关注159667…" reads as the name, not the sentence. */
|
|
422
|
+
function stripRequestPrefixes(fragment) {
|
|
423
|
+
let value = fragment;
|
|
424
|
+
for (let round = 0; round < 3; round += 1) {
|
|
425
|
+
const next = value.replace(LEADING_REQUEST, '');
|
|
426
|
+
if (next === value)
|
|
427
|
+
break;
|
|
428
|
+
value = next;
|
|
429
|
+
}
|
|
430
|
+
return value.trim();
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Is this span an explicit referent rather than a piece of prose?
|
|
434
|
+
*
|
|
435
|
+
* An explicit referent carries an identifier signal (a 4+ digit code such as
|
|
436
|
+
* 159667, or a Latin run such as ETF / dsh-workplan) and contains no function
|
|
437
|
+
* word. That keeps 「159667工业母机ETF国泰」 and drops 「是我重点关注的基金」.
|
|
438
|
+
* Dates (「11月」/「2026年」) and bare numbers are not referents.
|
|
439
|
+
*/
|
|
440
|
+
function isExplicitEntityToken(value) {
|
|
441
|
+
const token = value.trim();
|
|
442
|
+
if (token.length < 2 || token.length > 24)
|
|
443
|
+
return false;
|
|
444
|
+
if (/^(?:它|他|她|其)(?:们)?$/.test(token))
|
|
445
|
+
return false;
|
|
446
|
+
if (/^\d{1,4}(?:年|月|日|号)/.test(token))
|
|
447
|
+
return false;
|
|
448
|
+
if (/^\d{1,2}$/.test(token))
|
|
449
|
+
return false;
|
|
450
|
+
// A bare instrument category names a class, not one instrument.
|
|
451
|
+
if (/^(?:ETF|LOF|QDII|A股|港股|美股)$/.test(token))
|
|
452
|
+
return false;
|
|
453
|
+
const hasCode = /\d{4,}/.test(token);
|
|
454
|
+
const hasLatin = /[A-Za-z]{2,}/.test(token);
|
|
455
|
+
const mixedSignal = /[A-Za-z]\d|\d[A-Za-z]/.test(token);
|
|
456
|
+
if (!hasCode && !hasLatin && !mixedSignal)
|
|
457
|
+
return false;
|
|
458
|
+
for (const char of token) {
|
|
459
|
+
if (INLINE_ENTITY_STOP.has(char))
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
return !FUNCTION_WORD_ONLY.test(token);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Take the explicit referent out of one punctuation/space-delimited fragment.
|
|
466
|
+
*
|
|
467
|
+
* A clean fragment is kept whole; otherwise the identifier and the name
|
|
468
|
+
* characters attached to it are cut out, stopping at the first function word
|
|
469
|
+
* or verb ("159667工业母机ETF国泰是我重点…" -> "159667工业母机ETF国泰").
|
|
470
|
+
*/
|
|
471
|
+
function inlineEntityCore(fragment) {
|
|
472
|
+
const raw = stripRequestPrefixes(fragment).replace(/[。!?!?…]+$/, '').trim();
|
|
473
|
+
if (!raw)
|
|
474
|
+
return null;
|
|
475
|
+
if (isExplicitEntityToken(raw))
|
|
476
|
+
return raw;
|
|
477
|
+
const anchor = /\d{2,}|[A-Za-z]{2,}/.exec(raw);
|
|
478
|
+
if (!anchor)
|
|
479
|
+
return null;
|
|
480
|
+
let start = anchor.index;
|
|
481
|
+
while (start > 0 && isInlineNameChar(raw[start - 1]) && !INLINE_ENTITY_STOP.has(raw[start - 1]))
|
|
482
|
+
start -= 1;
|
|
483
|
+
let end = anchor.index + anchor[0].length;
|
|
484
|
+
while (end < raw.length && isInlineNameChar(raw[end]) && !INLINE_ENTITY_STOP.has(raw[end]))
|
|
485
|
+
end += 1;
|
|
486
|
+
const value = raw.slice(start, end).replace(/[.\-_]+$/, '').trim();
|
|
487
|
+
return isExplicitEntityToken(value) ? value : null;
|
|
488
|
+
}
|
|
489
|
+
/** Find the last explicit referent inside one sentence span. */
|
|
490
|
+
function findExplicitEntity(span) {
|
|
491
|
+
const text = span.trim();
|
|
492
|
+
if (!text)
|
|
493
|
+
return null;
|
|
494
|
+
const quoted = [...text.matchAll(/[「『“"《]([^」』”"》\n]{2,24})[」』”"》]/g)];
|
|
495
|
+
for (let i = quoted.length - 1; i >= 0; i -= 1) {
|
|
496
|
+
const value = quoted[i][1].trim();
|
|
497
|
+
if (isExplicitEntityToken(value))
|
|
498
|
+
return { antecedent: value, source: text.slice(-80) };
|
|
499
|
+
}
|
|
500
|
+
const fragments = text.split(/[,,、;;::\s]+/);
|
|
501
|
+
for (let i = fragments.length - 1; i >= 0; i -= 1) {
|
|
502
|
+
const value = inlineEntityCore(fragments[i]);
|
|
503
|
+
if (value)
|
|
504
|
+
return { antecedent: value, source: text.slice(-80) };
|
|
505
|
+
}
|
|
506
|
+
return null;
|
|
507
|
+
}
|
|
508
|
+
/** Bounds of the sentence around `index`, plus the sentence immediately before. */
|
|
509
|
+
function inlineSentenceBounds(text, index) {
|
|
510
|
+
let start = 0;
|
|
511
|
+
for (let i = index - 1; i >= 0; i -= 1) {
|
|
512
|
+
if (isInlineSentenceBoundary(text[i])) {
|
|
513
|
+
start = i + 1;
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
let prevEnd = start;
|
|
518
|
+
while (prevEnd > 0 && isInlineSentenceBoundary(text[prevEnd - 1]))
|
|
519
|
+
prevEnd -= 1;
|
|
520
|
+
let prevStart = 0;
|
|
521
|
+
for (let i = prevEnd - 1; i >= 0; i -= 1) {
|
|
522
|
+
if (isInlineSentenceBoundary(text[i])) {
|
|
523
|
+
prevStart = i + 1;
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return { start, prevStart, prevEnd };
|
|
528
|
+
}
|
|
529
|
+
/** 「其它」 is a word, not a pronoun: skip it and use the real occurrence. */
|
|
530
|
+
function lastInlineReferenceIndex(text, token) {
|
|
531
|
+
let index = text.lastIndexOf(token);
|
|
532
|
+
while (index > 0 && token === '它' && text[index - 1] === '其') {
|
|
533
|
+
index = text.lastIndexOf(token, index - 1);
|
|
534
|
+
}
|
|
535
|
+
return index;
|
|
536
|
+
}
|
|
537
|
+
export function resolvePronounAntecedentInline(token, taskText) {
|
|
538
|
+
const text = String(taskText ?? '');
|
|
539
|
+
if (!text || text.length > MAX_TASK_ANCHOR_CHARS)
|
|
540
|
+
return null;
|
|
541
|
+
const index = lastInlineReferenceIndex(text, token);
|
|
542
|
+
if (index <= 0)
|
|
543
|
+
return null;
|
|
544
|
+
const bounds = inlineSentenceBounds(text, index);
|
|
545
|
+
const current = findExplicitEntity(text.slice(bounds.start, index));
|
|
546
|
+
if (current)
|
|
547
|
+
return current;
|
|
548
|
+
if (bounds.prevEnd > bounds.prevStart) {
|
|
549
|
+
const previous = findExplicitEntity(text.slice(bounds.prevStart, bounds.prevEnd));
|
|
550
|
+
if (previous)
|
|
551
|
+
return previous;
|
|
552
|
+
}
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* [P0-2c] Decide whether a task is missing information the user must supply.
|
|
557
|
+
*
|
|
558
|
+
* MS2's four clarify cases (T05-04/09/13/20) were planned and dispatched anyway.
|
|
559
|
+
* Each failed for a *checkable* reason, so each gets a deterministic rule instead
|
|
560
|
+
* of a vibe:
|
|
561
|
+
*
|
|
562
|
+
* C1 bare agreement — the text is an answer to a question the model never saw
|
|
563
|
+
* (「同意移入」) and carries an identifier it never defines (R-W5-01).
|
|
564
|
+
* C2 dangling artifact — an internal reference (T4 草稿, W5) that is not defined
|
|
565
|
+
* in the task and not present in the conversation.
|
|
566
|
+
* C3 missing target — a forecast/trend request with no identifiable subject
|
|
567
|
+
* (「准确预测11月全月详细、具体走势」: which instrument? which year?).
|
|
568
|
+
* C4 missing UI object — a display change (折叠/展开/按钮…) that names no surface
|
|
569
|
+
* (左侧栏/截图/插件…), so any implementation would be a guess.
|
|
570
|
+
*/
|
|
571
|
+
export function auditClarifyNeed(taskText, conversationContext = '') {
|
|
572
|
+
const text = String(taskText ?? '').trim();
|
|
573
|
+
const conversation = String(conversationContext ?? '');
|
|
574
|
+
if (!text)
|
|
575
|
+
return { needed: false, rule: '', reason: '', question: '' };
|
|
576
|
+
const both = text + '\n' + conversation;
|
|
577
|
+
const AGREEMENT = /(?:^|[。;;!!\n])\s*(?:同意|赞成|可以|好的|没问题|就按|按你说的|确认)/;
|
|
578
|
+
// No trailing \b: a CJK char is a non-word char, so 「T4 草稿」 has no word
|
|
579
|
+
// boundary after 稿 and the id would silently never match.
|
|
580
|
+
const DANGLING_ID = /(?:R-[A-Z]{1,4}-\d{1,4}|W\d{1,3}\b|T\d{1,3}\s*草稿)/;
|
|
581
|
+
if (AGREEMENT.test(text) && (DANGLING_ID.test(text) || text.length <= 24) && !DANGLING_ID.test(conversation)) {
|
|
582
|
+
return {
|
|
583
|
+
needed: true,
|
|
584
|
+
rule: 'C1',
|
|
585
|
+
reason: '任务只是对上文问题的表态,且引用了任务里没有定义的编号,缺上文',
|
|
586
|
+
question: '你这句话是在回答哪个问题?请把上文的问题、或你要「同意/移入」的具体对象说清楚。',
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
const dangling = text.match(DANGLING_ID);
|
|
590
|
+
if (dangling && !conversation.includes(dangling[0])) {
|
|
591
|
+
return {
|
|
592
|
+
needed: true,
|
|
593
|
+
rule: 'C2',
|
|
594
|
+
reason: '任务引用了「' + dangling[0] + '」这一内部编号/草稿,但任务原文没有定义它,也找不到上文',
|
|
595
|
+
question: '「' + dangling[0] + '」指的是什么?请给出文件路径、链接或把内容贴进来。',
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
const FORECAST = /(预测|预判|走势|涨跌|行情)/;
|
|
599
|
+
const SUBJECT = /(?:\d{6}|[A-Z]{2,}\d+|[「『“"《][^」』”"》]{2,20}[」』”"》])/;
|
|
600
|
+
// The missing subject may already be named in the conversation (「它走势如何」 after
|
|
601
|
+
// the user quoted a ticker). Only the task's own words make it a forecast request.
|
|
602
|
+
if (FORECAST.test(text) && !SUBJECT.test(both)) {
|
|
603
|
+
return {
|
|
604
|
+
needed: true,
|
|
605
|
+
rule: 'C3',
|
|
606
|
+
reason: '要求预测走势,但任务里没有可识别标的(股票代码/名称),也没有年份,缺关键输入',
|
|
607
|
+
question: '要预测哪只标的(股票代码或名称)?看哪个时间段?',
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
const UI_VERB = /(折叠|展开|按钮|显示|布局|样式|颜色|排序|置顶|收起)/;
|
|
611
|
+
// 红圈/红框/圈出 name a surface the same way 截图 does: the user has pointed at
|
|
612
|
+
// something concrete. Without them 「把红圈处改为默认收起」 was C4-blocked even
|
|
613
|
+
// though the sentence is unambiguous (caught by department-fit.test.ts).
|
|
614
|
+
const UI_OBJECT = /(左侧栏|右侧栏|侧边栏|侧栏|面板|对话框|弹窗|菜单|工具栏|页面|截图|画圈|红圈|红框|圈出|插件|顶栏|底栏|任务进度)/;
|
|
615
|
+
// Same rule as C3: 「把它改成默认收起」 is not missing a surface when the previous
|
|
616
|
+
// turn said 「截图红圈处的分步进度」. The verb must be in the task, the object may
|
|
617
|
+
// come from either side (plan-anchor.test.ts 'strict mode blocks…' covers this).
|
|
618
|
+
if (UI_VERB.test(text) && !UI_OBJECT.test(both)) {
|
|
619
|
+
return {
|
|
620
|
+
needed: true,
|
|
621
|
+
rule: 'C4',
|
|
622
|
+
reason: '要求改动界面显示,但没有说明改哪个界面/哪个板块,缺指代对象',
|
|
623
|
+
question: '要改的是哪个界面/哪个板块?(例如左侧栏、任务进度面板、某个按钮;有截图更好)',
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
return { needed: false, rule: '', reason: '', question: '' };
|
|
627
|
+
}
|
|
389
628
|
/**
|
|
390
629
|
* Split one clause into candidate noun phrases.
|
|
391
630
|
*
|
|
@@ -836,15 +1075,24 @@ export function auditTaskUnderstanding(plan, context = {}) {
|
|
|
836
1075
|
const resolvedByContext = extracted.references.map((reference) => {
|
|
837
1076
|
if (reference.resolved)
|
|
838
1077
|
return reference;
|
|
839
|
-
const
|
|
1078
|
+
const fromConversation = resolvePronounAntecedent(reference.token, conversation);
|
|
1079
|
+
const found = fromConversation ?? resolvePronounAntecedentInline(reference.token, taskText);
|
|
840
1080
|
if (!found)
|
|
841
1081
|
return reference;
|
|
842
1082
|
// Option letters are resolved only when the conversation lists that option
|
|
843
1083
|
// as a listed choice ("A 方案" / "B 选项"), not a bare letter in a word.
|
|
1084
|
+
// Task-text entities never satisfy this rule on their own: the option must
|
|
1085
|
+
// be defined where the user chose it, i.e. in the conversation.
|
|
844
1086
|
const listedOption = new RegExp('(?:^|[^A-Za-z])' + reference.token + '\\s*(?:方案|选项)');
|
|
845
1087
|
if (/^[A-D]$/.test(reference.token) && !listedOption.test(conversation))
|
|
846
1088
|
return reference;
|
|
847
|
-
|
|
1089
|
+
/*
|
|
1090
|
+
* [T3] Record where the referent came from. Reusing 'context' for an
|
|
1091
|
+
* antecedent found inside the task text would misreport an empty
|
|
1092
|
+
* conversation as the source, so the audit keeps the two apart.
|
|
1093
|
+
*/
|
|
1094
|
+
const resolvedBy = fromConversation ? 'context' : 'task-text';
|
|
1095
|
+
return { ...reference, resolved: true, resolvedBy, antecedent: found.antecedent };
|
|
848
1096
|
});
|
|
849
1097
|
const unresolved = resolvedByContext.filter((reference) => !reference.resolved);
|
|
850
1098
|
const reasons = [];
|
|
@@ -938,6 +1186,14 @@ export function validatePlanContext(plan, context = {}) {
|
|
|
938
1186
|
if (audit.stage3.verdict === 'needs-clarification') {
|
|
939
1187
|
errors.push(`CLARIFY: ${audit.stage3.reasons.find((reason) => reason.includes('自相矛盾')) ?? '用户要求存在矛盾,必须先向用户确认'}`);
|
|
940
1188
|
}
|
|
1189
|
+
/*
|
|
1190
|
+
* [P0-2c] Missing inputs must stop the plan before any department agent runs:
|
|
1191
|
+
* MS2 T05-04/09/13/20 were all planned and dispatched with the key input absent.
|
|
1192
|
+
*/
|
|
1193
|
+
const clarify = auditClarifyNeed(context.taskText ?? audit.anchor?.text ?? '', context.conversationContext ?? '');
|
|
1194
|
+
if (clarify.needed) {
|
|
1195
|
+
errors.push('CLARIFY: ' + clarify.reason + '(规则 ' + clarify.rule + ')');
|
|
1196
|
+
}
|
|
941
1197
|
if (audit.stage3.verdict === 'needs-context') {
|
|
942
1198
|
errors.push(`CONTEXT: ${audit.stage3.reasons.find((reason) => reason.includes('指代')) ?? '任务含指代但在最近对话中找不到先行词,必须先向用户确认'}`);
|
|
943
1199
|
}
|
package/package.json
CHANGED
package/src/departments.ts
CHANGED
|
@@ -173,6 +173,13 @@ export const DEPARTMENT_CAPABILITIES: readonly DepartmentCapability[] = Object.f
|
|
|
173
173
|
keywords: [
|
|
174
174
|
'法务', '合同', '版权', '许可', '合规', '条款', '法律', '隐私', '授权', '侵权', '国际标准',
|
|
175
175
|
'ISO/IEC 15408', '15408', 'ISO/IEC', 'ISO 标准', 'CC 标准',
|
|
176
|
+
// [P0-4 recall] T05-12 「会不会窃取用户电脑和移动终端里的文件和数据」 is a
|
|
177
|
+
// privacy/authorisation claim and matched nothing: the list had 隐私/授权 but
|
|
178
|
+
// not the verbs a user actually writes. These are plain words, so the
|
|
179
|
+
// intrusion guard keeps legal out of unrelated plans.
|
|
180
|
+
// 「泄露」 alone would also fire on 「内存泄露」 (a memory leak is engineering,
|
|
181
|
+
// not legal); 「信息泄露」 keeps the privacy sense and the keyword count at 22.
|
|
182
|
+
'窃取', '信息泄露', '个人信息', '数据安全', '隐私风险', '移动终端',
|
|
176
183
|
],
|
|
177
184
|
},
|
|
178
185
|
{
|
package/src/host.ts
CHANGED
|
@@ -194,6 +194,16 @@ export type WorkplanConfig = {
|
|
|
194
194
|
* 关闭方式:`autoDispatch: false` 或环境变量 `DSH_WORKPLAN_AUTO_DISPATCH=0`。
|
|
195
195
|
*/
|
|
196
196
|
autoDispatch?: boolean
|
|
197
|
+
/**
|
|
198
|
+
* [1.12.3] headless「未完成不得成功收尾」硬闸门。
|
|
199
|
+
*
|
|
200
|
+
* `'auto'`(不配置时的默认):只在 headless 运行中启用,交互式 web/tui 会话
|
|
201
|
+
* 行为完全不变。`true` 强制开启(任何运行方式都硬失败),`false` 关闭并回到
|
|
202
|
+
* 1.12.2 的「steer 用尽即放行」。
|
|
203
|
+
*
|
|
204
|
+
* 环境变量:`DSH_WORKPLAN_FAIL_CLOSED_ON_INCOMPLETE=1|0`。
|
|
205
|
+
*/
|
|
206
|
+
failClosedOnIncomplete?: boolean
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
function createUpdateTool(runtime: any) {
|
|
@@ -1060,6 +1070,23 @@ function strictCompletionEnabledFrom(configValue: any, envValue: any) {
|
|
|
1060
1070
|
return true
|
|
1061
1071
|
}
|
|
1062
1072
|
|
|
1073
|
+
/**
|
|
1074
|
+
* [1.12.3] `failClosedOnIncomplete` 的三态解析:显式配置 > 显式环境变量 > 'auto'。
|
|
1075
|
+
*
|
|
1076
|
+
* 与 `strictCompletionEnabledFrom` 的区别只在默认值:这里未配置时返回 `'auto'`,
|
|
1077
|
+
* 语义是「headless 才硬失败」,不能退化成 `false`(那等于默认关闭,事故会复发),
|
|
1078
|
+
* 也不能退化成 `true`(那会让交互式会话在收尾时抛错)。
|
|
1079
|
+
*/
|
|
1080
|
+
function failClosedOnIncompleteFrom(configValue: any, envValue: any): boolean | 'auto' {
|
|
1081
|
+
if (typeof configValue === 'boolean') return configValue
|
|
1082
|
+
const raw = envValue === undefined || envValue === null ? '' : String(envValue).trim()
|
|
1083
|
+
if (raw !== '') {
|
|
1084
|
+
if (/^(1|true|yes|on)$/i.test(raw)) return true
|
|
1085
|
+
if (/^(0|false|no|off)$/i.test(raw)) return false
|
|
1086
|
+
}
|
|
1087
|
+
return 'auto'
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1063
1090
|
function booleanSetting(configValue: any, envName: string) {
|
|
1064
1091
|
if (typeof configValue === 'boolean') return configValue
|
|
1065
1092
|
const raw = typeof process !== 'undefined' ? process.env?.[envName] : undefined
|
|
@@ -1139,6 +1166,14 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
1139
1166
|
* 与 autoResume / strictCompletion 同一写法,避免「没配置就等于关闭」。
|
|
1140
1167
|
*/
|
|
1141
1168
|
autoDispatch: strictCompletionEnabledFrom(config.autoDispatch, settingEnv('DSH_WORKPLAN_AUTO_DISPATCH')),
|
|
1169
|
+
/*
|
|
1170
|
+
* [1.12.3] headless「未完成不得成功收尾」。默认 'auto':只有 headless
|
|
1171
|
+
* 运行上下文(提供 `headlessStartup` 服务)才硬失败,交互式会话不受影响。
|
|
1172
|
+
*/
|
|
1173
|
+
failClosedOnIncomplete: failClosedOnIncompleteFrom(
|
|
1174
|
+
config.failClosedOnIncomplete,
|
|
1175
|
+
settingEnv('DSH_WORKPLAN_FAIL_CLOSED_ON_INCOMPLETE'),
|
|
1176
|
+
),
|
|
1142
1177
|
})
|
|
1143
1178
|
|
|
1144
1179
|
ctx.effect(() =>
|
|
@@ -1255,7 +1290,7 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
1255
1290
|
|
|
1256
1291
|
export const meta = {
|
|
1257
1292
|
name,
|
|
1258
|
-
version: '1.12.
|
|
1293
|
+
version: '1.12.3',
|
|
1259
1294
|
promptOrder: PROMPT_ORDER,
|
|
1260
1295
|
routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
|
|
1261
1296
|
}
|
|
@@ -1271,8 +1306,50 @@ export { PROMPT_SECTION, createCancelTool, createDispatchTool, createEscalateToo
|
|
|
1271
1306
|
*/
|
|
1272
1307
|
export function fileWriteGuardReason(
|
|
1273
1308
|
exec: any,
|
|
1274
|
-
runtime: {
|
|
1309
|
+
runtime: {
|
|
1310
|
+
presentedWriteDenialReason(agent: any, args: any): string | undefined
|
|
1311
|
+
writeTargets(agent: any, args: any): string[]
|
|
1312
|
+
},
|
|
1275
1313
|
) {
|
|
1276
|
-
if (exec
|
|
1277
|
-
|
|
1314
|
+
if (!isWriteShapedCall(exec)) return undefined
|
|
1315
|
+
// The three historical write tools pass their arguments through untouched, so
|
|
1316
|
+
// their behaviour stays exactly as before (argument-shape matching is only an
|
|
1317
|
+
// EXTENSION: a tool that used to be denied is still denied the same way).
|
|
1318
|
+
const direct = exec?.name === 'write' || exec?.name === 'edit' || exec?.name === 'str_replace_editor'
|
|
1319
|
+
const reason = direct ? runtime.presentedWriteDenialReason(exec?.agent, exec?.arguments) : undefined
|
|
1320
|
+
if (typeof reason === 'string') return reason
|
|
1321
|
+
// [1.12.2] G2: a single call can touch several files (apply_patch hunks).
|
|
1322
|
+
// Deny the call as a whole if any of its targets is a protected deliverable.
|
|
1323
|
+
for (const target of runtime.writeTargets(exec?.agent, exec?.arguments) ?? []) {
|
|
1324
|
+
const extra = runtime.presentedWriteDenialReason(exec?.agent, { file_path: target })
|
|
1325
|
+
if (typeof extra === 'string') return extra
|
|
1326
|
+
}
|
|
1327
|
+
return undefined
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
/**
|
|
1331
|
+
* [1.12.2] G2: recognise write calls by their argument shape, not by a tool-name
|
|
1332
|
+
* allow-list. The 1.8.18 version named write/edit/str_replace_editor only, so a
|
|
1333
|
+
* fourth write tool such as apply_patch never reached the guard at all.
|
|
1334
|
+
*
|
|
1335
|
+
* Shape rule: a path/first positional argument PLUS a content-bearing argument
|
|
1336
|
+
* (content, file_text, new_str, old_string, patch, input). read/read_image/
|
|
1337
|
+
* present/glob/grep carry no such pair, so they stay untouched.
|
|
1338
|
+
*/
|
|
1339
|
+
const READ_ONLY_TOOLS = new Set([
|
|
1340
|
+
'read', 'read_image', 'glob', 'grep', 'ls', 'list', 'list_dir',
|
|
1341
|
+
'present', 'todo_write', 'ask_user_question',
|
|
1342
|
+
])
|
|
1343
|
+
|
|
1344
|
+
function isWriteShapedCall(exec: any) {
|
|
1345
|
+
const name = exec?.name
|
|
1346
|
+
if (typeof name !== 'string' || !name) return false
|
|
1347
|
+
const args = exec?.arguments
|
|
1348
|
+
if (!args || typeof args !== 'object') return false
|
|
1349
|
+
// Read-only tools also carry file_path/path; the guard must never touch them.
|
|
1350
|
+
if (READ_ONLY_TOOLS.has(name)) return false
|
|
1351
|
+
// A patch tool names its target(s) inside the patch text, not in an argument.
|
|
1352
|
+
if (typeof args.input === 'string' && /\*\*\* (Update|Add|Delete|Move) File/.test(args.input)) return true
|
|
1353
|
+
// Every other write form names a single target: file_path or path.
|
|
1354
|
+
return typeof args.file_path === 'string' || typeof args.path === 'string'
|
|
1278
1355
|
}
|
package/src/plan.ts
CHANGED
|
@@ -1224,6 +1224,32 @@ export function buildDegradedMessage(options: any) {
|
|
|
1224
1224
|
return makeUserMessage(text, { kind: 'workplan', form: 'notice', summary })
|
|
1225
1225
|
}
|
|
1226
1226
|
|
|
1227
|
+
/**
|
|
1228
|
+
* [1.12.3] 信息不足时先问,不做计划也不派发。
|
|
1229
|
+
*
|
|
1230
|
+
* 2026-11-04 MS2 的真实数据:T05-04/09/13/20 这四条本来需要澄清,插件却照样拆出
|
|
1231
|
+
* 计划并(自动)派发,部门 Agent 于是对着一个并不存在的目标开工。用户在同一天拍板:
|
|
1232
|
+
* 自动派发只在「信息不足」这一类上拦截,其余一律照旧。所以这里不是关掉自动派发,
|
|
1233
|
+
* 而是在规划**之前**把缺的东西变成一句能给用户看的话。
|
|
1234
|
+
*
|
|
1235
|
+
* 这条消息不带计划信封:没有计划就没有 planId,也不该出现在计划列表里。
|
|
1236
|
+
*/
|
|
1237
|
+
export function buildClarifyMessage(options: any) {
|
|
1238
|
+
const rule = String(options.rule ?? '')
|
|
1239
|
+
const reason = truncate(options.reason ?? '', 600)
|
|
1240
|
+
const question = String(options.question ?? '').trim()
|
|
1241
|
+
const summary = truncate(`【先澄清,未生成计划】${reason}`, 300)
|
|
1242
|
+
const text = [
|
|
1243
|
+
`【先澄清,未生成计划】任务信息不足:${reason}(规则 ${rule})`,
|
|
1244
|
+
'',
|
|
1245
|
+
`请把这句话原样问用户:${question || '请补充这个任务缺的关键信息。'}`,
|
|
1246
|
+
'',
|
|
1247
|
+
'本条没有生成任务分解,也没有派发任何部门 Agent——缺信息时拆出来的计划只能靠猜。',
|
|
1248
|
+
'等用户回答后,用户的下一条消息会重新触发计划生成;在那之前不要调用 dsh_workplan_dispatch,也不要开始执行。',
|
|
1249
|
+
].join('\n')
|
|
1250
|
+
return makeUserMessage(text, { kind: 'workplan', form: 'notice', summary })
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1227
1253
|
export function buildResultSummary(result: any) {
|
|
1228
1254
|
const stats = result.stats ?? { done: 0, total: 0, blocked: 0 }
|
|
1229
1255
|
const done = Number(stats.done ?? 0)
|