dsh-workplan 1.12.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -0
- package/README.en.md +17 -2
- package/README.md +41 -3
- package/README.zh.md +2 -2
- package/docs/cc/ADV-FSP-FUNCTIONAL-SPEC.md +3 -1
- package/docs/cc/AVA-VULNERABILITY-ANALYSIS.md +9 -0
- package/docs/cc/SECURITY-TARGET.md +3 -1
- package/docs/collaboration.md +27 -2
- package/docs/decision-clarify-gate-20261104.md +41 -0
- package/docs/release-notes-2.0.1.md +56 -0
- package/lib/departments.js +7 -0
- package/lib/host.js +219 -2
- package/lib/lessons.js +378 -0
- package/lib/plan.js +62 -5
- package/lib/runtime.js +263 -4
- package/lib/three-phase.js +287 -0
- package/lib/understanding.js +258 -2
- package/package.json +1 -1
- package/src/departments.ts +7 -0
- package/src/host.ts +237 -2
- package/src/lessons.ts +445 -0
- package/src/plan.ts +63 -4
- package/src/runtime.ts +295 -3
- package/src/three-phase.ts +342 -0
- package/src/understanding.ts +256 -6
package/lib/plan.js
CHANGED
|
@@ -10,6 +10,7 @@ import { createHash, randomUUID } from 'node:crypto';
|
|
|
10
10
|
import { DEPARTMENT_CAPABILITIES, departmentCapability } from './departments.js';
|
|
11
11
|
import { MAX_TASK_ANCHOR_CHARS } from './understanding.js';
|
|
12
12
|
import { isMappingDigest, verifyMappingDigest } from './supersede-digest.js';
|
|
13
|
+
import { phaseSummaryLine, threePhasePromptLines, validatePhaseEvidence } from './three-phase.js';
|
|
13
14
|
export const PLAN_VERSION = 1;
|
|
14
15
|
/**
|
|
15
16
|
* [1.9.0] 处置终态:cancelled(用户撤销)与 superseded(责任已转移)。
|
|
@@ -84,7 +85,7 @@ export const UPDATE_MARKER_END = '<!-- DSH-WORKPLAN-UPDATE:END -->';
|
|
|
84
85
|
/** Upper bound for the run-time conversation window (single truncation point). */
|
|
85
86
|
export const MAX_CONVERSATION_CHARS = 7000;
|
|
86
87
|
/** Upper bound for one child evidence block; longer blocks are truncated. */
|
|
87
|
-
export const MAX_EVIDENCE_BLOCK_CHARS =
|
|
88
|
+
export const MAX_EVIDENCE_BLOCK_CHARS = 12000;
|
|
88
89
|
export const MAX_EVIDENCE_ACCEPTANCE = 20;
|
|
89
90
|
export const MAX_EVIDENCE_ARTIFACTS = 20;
|
|
90
91
|
export const MAX_EVIDENCE_NEEDS = 10;
|
|
@@ -1149,6 +1150,31 @@ export function buildDegradedMessage(options) {
|
|
|
1149
1150
|
].join('\n');
|
|
1150
1151
|
return makeUserMessage(text, { kind: 'workplan', form: 'notice', summary });
|
|
1151
1152
|
}
|
|
1153
|
+
/**
|
|
1154
|
+
* [1.12.3] 信息不足时先问,不做计划也不派发。
|
|
1155
|
+
*
|
|
1156
|
+
* 2026-11-04 MS2 的真实数据:T05-04/09/13/20 这四条本来需要澄清,插件却照样拆出
|
|
1157
|
+
* 计划并(自动)派发,部门 Agent 于是对着一个并不存在的目标开工。用户在同一天拍板:
|
|
1158
|
+
* 自动派发只在「信息不足」这一类上拦截,其余一律照旧。所以这里不是关掉自动派发,
|
|
1159
|
+
* 而是在规划**之前**把缺的东西变成一句能给用户看的话。
|
|
1160
|
+
*
|
|
1161
|
+
* 这条消息不带计划信封:没有计划就没有 planId,也不该出现在计划列表里。
|
|
1162
|
+
*/
|
|
1163
|
+
export function buildClarifyMessage(options) {
|
|
1164
|
+
const rule = String(options.rule ?? '');
|
|
1165
|
+
const reason = truncate(options.reason ?? '', 600);
|
|
1166
|
+
const question = String(options.question ?? '').trim();
|
|
1167
|
+
const summary = truncate(`【先澄清,未生成计划】${reason}`, 300);
|
|
1168
|
+
const text = [
|
|
1169
|
+
`【先澄清,未生成计划】任务信息不足:${reason}(规则 ${rule})`,
|
|
1170
|
+
'',
|
|
1171
|
+
`请把这句话原样问用户:${question || '请补充这个任务缺的关键信息。'}`,
|
|
1172
|
+
'',
|
|
1173
|
+
'本条没有生成任务分解,也没有派发任何部门 Agent——缺信息时拆出来的计划只能靠猜。',
|
|
1174
|
+
'等用户回答后,用户的下一条消息会重新触发计划生成;在那之前不要调用 dsh_workplan_dispatch,也不要开始执行。',
|
|
1175
|
+
].join('\n');
|
|
1176
|
+
return makeUserMessage(text, { kind: 'workplan', form: 'notice', summary });
|
|
1177
|
+
}
|
|
1152
1178
|
export function buildResultSummary(result) {
|
|
1153
1179
|
const stats = result.stats ?? { done: 0, total: 0, blocked: 0 };
|
|
1154
1180
|
const done = Number(stats.done ?? 0);
|
|
@@ -1847,7 +1873,7 @@ const BLOCKED_LINE = /^\s*(BLOCKED|受阻|无法完成)\s*[::]\s*/i;
|
|
|
1847
1873
|
* the acceptance table cannot drift apart between the runtime and the replay.
|
|
1848
1874
|
* It never invents evidence and never upgrades a failed self-check to done.
|
|
1849
1875
|
*/
|
|
1850
|
-
export function adjudicateResult({ output, strict = true, expectedAcceptance = [] }) {
|
|
1876
|
+
export function adjudicateResult({ output, strict = true, expectedAcceptance = [], requirePhases = true }) {
|
|
1851
1877
|
const text = typeof output === 'string' ? output : '';
|
|
1852
1878
|
const parsed = parseEvidenceBlock(text);
|
|
1853
1879
|
if (!strict) {
|
|
@@ -1988,6 +2014,30 @@ export function adjudicateResult({ output, strict = true, expectedAcceptance = [
|
|
|
1988
2014
|
.map((item) => truncate(String(item), 120)).slice(0, 5).join(';')}。请按计划验收逐条给出证据后再回报。`,
|
|
1989
2015
|
};
|
|
1990
2016
|
}
|
|
2017
|
+
/*
|
|
2018
|
+
* [1.13.0] 完成前必须交出三阶段证据(用户 2026-11-05 的强制要求)。
|
|
2019
|
+
*
|
|
2020
|
+
* 这是「先规划后执行」从口号变成契约的唯一落点:子 Agent 只在提示词里
|
|
2021
|
+
* 被要求时,仍可以先动手、最后补一句「已规划」;只有把规划内容做成
|
|
2022
|
+
* 收尾证据的一部分并在这里校验,缺规划/缺验证的结果才不可能被记成 done。
|
|
2023
|
+
*
|
|
2024
|
+
* 兼容边界:`requirePhases:false` 保留给历史回放与明确关闭该门禁的部署;
|
|
2025
|
+
* `strict:false` 的旧语义不受影响(前面已经返回)。
|
|
2026
|
+
*/
|
|
2027
|
+
const phaseCheck = requirePhases === false
|
|
2028
|
+
? null
|
|
2029
|
+
: validatePhaseEvidence(payload.phases, expectedAcceptance);
|
|
2030
|
+
if (phaseCheck && !phaseCheck.ok) {
|
|
2031
|
+
return {
|
|
2032
|
+
status: 'blocked',
|
|
2033
|
+
verification: 'unverified',
|
|
2034
|
+
acceptance,
|
|
2035
|
+
artifacts,
|
|
2036
|
+
needs,
|
|
2037
|
+
error: `三阶段证据不完整(未按「规划→执行→验证」回报):${phaseCheck.errors.slice(0, 6).join(';')}`,
|
|
2038
|
+
phases: null,
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
1991
2041
|
return {
|
|
1992
2042
|
status: 'done',
|
|
1993
2043
|
verification: hasUnverified ? 'unverified' : 'structured',
|
|
@@ -1995,6 +2045,8 @@ export function adjudicateResult({ output, strict = true, expectedAcceptance = [
|
|
|
1995
2045
|
artifacts,
|
|
1996
2046
|
needs,
|
|
1997
2047
|
error: null,
|
|
2048
|
+
phases: phaseCheck?.phases ?? null,
|
|
2049
|
+
phaseSummary: phaseCheck?.phases ? phaseSummaryLine(phaseCheck.phases) : null,
|
|
1998
2050
|
};
|
|
1999
2051
|
}
|
|
2000
2052
|
export function buildUpdateMessage(update) {
|
|
@@ -3521,7 +3573,7 @@ export function findSubtask(plan, subtaskId) {
|
|
|
3521
3573
|
}
|
|
3522
3574
|
return null;
|
|
3523
3575
|
}
|
|
3524
|
-
export function buildChildPrompt({ plan, subtask, stage, dependencyResults, cwd, conversationContext = '', statuses = null, previousFailure = null, }) {
|
|
3576
|
+
export function buildChildPrompt({ plan, subtask, stage, dependencyResults, cwd, conversationContext = '', statuses = null, previousFailure = null, lessonsBrief = '', }) {
|
|
3525
3577
|
/*
|
|
3526
3578
|
* Every field below is read defensively.
|
|
3527
3579
|
*
|
|
@@ -3684,6 +3736,11 @@ export function buildChildPrompt({ plan, subtask, stage, dependencyResults, cwd,
|
|
|
3684
3736
|
...(resumeHint ? [resumeHint] : []),
|
|
3685
3737
|
...(pendingInstruction ? [pendingInstruction] : []),
|
|
3686
3738
|
'',
|
|
3739
|
+
...threePhasePromptLines(),
|
|
3740
|
+
...(typeof lessonsBrief === 'string' && lessonsBrief.trim() !== ''
|
|
3741
|
+
? ['', lessonsBrief.trim(), '']
|
|
3742
|
+
: []),
|
|
3743
|
+
'',
|
|
3687
3744
|
'执行要求:',
|
|
3688
3745
|
'- 只完成本子任务,不擅自扩大范围;不要派生新的 Agent。',
|
|
3689
3746
|
'- 你没有派发权限,也不能重启或安装任何服务;遇到这类步骤,必须先上报(见下方「遇阻上报」),再停止推进等待指示,不要空转。',
|
|
@@ -3703,13 +3760,13 @@ export function buildChildPrompt({ plan, subtask, stage, dependencyResults, cwd,
|
|
|
3703
3760
|
'',
|
|
3704
3761
|
'结果回传(必填):在汇报的最后附上一个结构化结果块,主 Agent 会按它逐项核对,不再只依赖自述。',
|
|
3705
3762
|
EVIDENCE_MARKER_BEGIN,
|
|
3706
|
-
'{"status":"done","blockedReason":"","acceptance":[{"criterion":"A1 把上面的验收标准原文抄在这里","result":"pass","evidence":"用命令输出、文件路径或引用证明"}],"artifacts":[{"kind":"file","ref":"相对工作目录的路径"}],"needs":[],"question":"","options":[]}',
|
|
3763
|
+
'{"status":"done","blockedReason":"","phases":{"planning":{"problemAnalysis":["要解决的问题 1(含现状/约束/未知/主要矛盾)"],"constraints":["..."],"unknowns":["..."],"approach":["第 1 步:做什么 → 产出什么 → 如何证明"]},"execution":{"steps":["实际执行的步骤"],"deviations":[]},"verification":{"allPassed":true,"checks":[{"criterion":"A1","method":"怎么验证","evidence":"命令输出/文件/引用"}],"requirementCheck":"逐条核对用户原要求的结果","retrospective":{"problems":["本次遇到的问题(现象+根因)"],"detours":["走过的弯路/返工/无效尝试;确实没有就写 []"],"resolutions":["最终是如何解决的"],"prevention":["以后如何预防再犯:遇到…先…"]}}},"acceptance":[{"criterion":"A1 把上面的验收标准原文抄在这里","result":"pass","evidence":"用命令输出、文件路径或引用证明"}],"artifacts":[{"kind":"file","ref":"相对工作目录的路径"}],"needs":[],"question":"","options":[]}',
|
|
3707
3764
|
EVIDENCE_MARKER_END,
|
|
3708
3765
|
'- status 只能是 done / blocked / partial;partial 会被当作受阻处理。',
|
|
3709
3766
|
'- acceptance 必须逐条覆盖上面的验收标准:criterion 以 A1、A2… 开头对号入座(编号不可省略);result 只能是 pass / fail / unverified。无法确认就写 unverified,不要写 pass。',
|
|
3710
3767
|
'- artifacts 写你实际产出或修改的文件(kind=file,ref 用相对路径)、链接(kind=url)或说明(kind=note)。',
|
|
3711
3768
|
'- needs 写需要其他部门配合的事项,每条写清「哪个部门 + 需要什么 + 用来做什么」;它会被登记为待处理需求,主 Agent 必须处置后计划才能交付。不要直连其他子 Agent。',
|
|
3712
3769
|
'- question/options 只在受阻上报时填写;done 时保持空字符串/空数组。',
|
|
3713
|
-
'- 整块不超过
|
|
3770
|
+
'- 整块不超过 12000 字符;不要把这段模板本身抄进结果块。',
|
|
3714
3771
|
].join('\n'));
|
|
3715
3772
|
}
|
package/lib/runtime.js
CHANGED
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
import { randomUUID } from 'node:crypto';
|
|
15
15
|
import { existsSync, realpathSync, statSync } from 'node:fs';
|
|
16
16
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
17
|
-
import { MAX_CONCURRENT, PlanError, aggregateInvariantViolations, applyStatus, attachPlanMeta, blockCancelledDependents, buildChildPrompt, buildCancelMessage, buildDegradedMessage, buildPlanMessage, buildPlannerPrompt, buildResultMessage, buildStopSteerText, createStatuses, deliveryReadiness, derivePlanSnapshot, extractJson, flattenSubtasks, isRecord, isSocialMessage, isTerminalPhase, isStatusQuestion, isVagueContinuation, makeUserMessage, markDependentsBlocked, messageText, readySubtasks, MAX_PLAN_RESUMES, PRESENT_DENY_CODES, canResumePlan, resetBlockedStatuses, parseCancelMessage, parseResultMessage, parseWorkplanMessage, planPhase, reconcilePhase, truncate, validatePlan, applyResultStatuses, adjudicateResult, activeDenyCode, MAX_CONVERSATION_CHARS, MAX_ESCALATION_OPTIONS, MAX_INSTRUCTION_CHARS, MAX_QUESTION_CHARS, parseUpdateMessage, buildUpdateMessage, normaliseHandoffs, openHandoffs, DEPARTMENTS, DEPARTMENT_IDS, MAX_HANDOFF_RESPONSE_CHARS, } from './plan.js';
|
|
18
|
-
import { compactUnderstandingAudit, validatePlanContext } from './understanding.js';
|
|
17
|
+
import { MAX_CONCURRENT, PlanError, aggregateInvariantViolations, applyStatus, attachPlanMeta, blockCancelledDependents, buildChildPrompt, buildCancelMessage, buildClarifyMessage, buildDegradedMessage, buildPlanMessage, buildPlannerPrompt, buildResultMessage, buildStopSteerText, createStatuses, deliveryReadiness, derivePlanSnapshot, extractJson, flattenSubtasks, isRecord, isSocialMessage, isTerminalPhase, isStatusQuestion, isVagueContinuation, makeUserMessage, markDependentsBlocked, messageText, readySubtasks, MAX_PLAN_RESUMES, PRESENT_DENY_CODES, canResumePlan, resetBlockedStatuses, parseCancelMessage, parseResultMessage, parseWorkplanMessage, planPhase, reconcilePhase, truncate, validatePlan, applyResultStatuses, adjudicateResult, activeDenyCode, MAX_CONVERSATION_CHARS, MAX_ESCALATION_OPTIONS, MAX_INSTRUCTION_CHARS, MAX_QUESTION_CHARS, parseUpdateMessage, buildUpdateMessage, normaliseHandoffs, openHandoffs, DEPARTMENTS, DEPARTMENT_IDS, MAX_HANDOFF_RESPONSE_CHARS, findSubtask, } from './plan.js';
|
|
18
|
+
import { auditClarifyNeed, compactUnderstandingAudit, validatePlanContext } from './understanding.js';
|
|
19
|
+
import { phaseGateFromErrors, phaseSummaryLine, validatePhaseEvidence } from './three-phase.js';
|
|
20
|
+
import { lessonStats, rankLessons, readLessons, recordLesson, renderLessonsBrief, resolveLessonsFile, } from './lessons.js';
|
|
19
21
|
import { computeMappingDigest, verifyMappingDigest } from './supersede-digest.js';
|
|
20
22
|
import { supersedePlanRecord } from './supersede.js';
|
|
21
23
|
import { createProgressWatchdog, describeError } from './watchdog.js';
|
|
@@ -773,11 +775,40 @@ function settleFromOutput(record, subtask, output, guard, options) {
|
|
|
773
775
|
const checked = checkArtifacts(verdict.artifacts, options.cwd, options.artifactExists);
|
|
774
776
|
const escalated = verdict.status === 'blocked'
|
|
775
777
|
&& typeof verdict.question === 'string' && verdict.question.trim() !== '';
|
|
778
|
+
/*
|
|
779
|
+
* [2.0.0] 自我学习闭环的出口:完成且带复盘证据时,立刻写入永久记忆。
|
|
780
|
+
*
|
|
781
|
+
* 写入失败不改变本次判定(教训没记住是记忆层的问题,不能把已经做完的工作
|
|
782
|
+
* 判成未完成),但会把失败原因写进本条状态,避免「以为记住了其实没写」。
|
|
783
|
+
*/
|
|
784
|
+
let lessonNote = '';
|
|
785
|
+
if (verdict.status === 'done' && verdict.phases?.verification?.retrospective) {
|
|
786
|
+
try {
|
|
787
|
+
const saved = recordLesson({
|
|
788
|
+
file: resolveLessonsFile(),
|
|
789
|
+
planId: String(record.plan?.planId ?? ''),
|
|
790
|
+
subtaskId: subtask.id,
|
|
791
|
+
department: String(subtask.department ?? ''),
|
|
792
|
+
title: `${subtask.id} ${subtask.title}`,
|
|
793
|
+
cwd: typeof options.cwd === 'string' ? options.cwd : '',
|
|
794
|
+
retrospective: verdict.phases.verification.retrospective,
|
|
795
|
+
now: Date.now(),
|
|
796
|
+
});
|
|
797
|
+
if (saved) {
|
|
798
|
+
lessonNote = saved.mode === 'repeated'
|
|
799
|
+
? `已记住同类教训(第 ${saved.record.occurrences} 次,永久记忆)`
|
|
800
|
+
: '复盘已写入永久教训记忆';
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
catch (error) {
|
|
804
|
+
lessonNote = `复盘记忆写入失败:${truncate(error instanceof Error ? error.message : String(error), 120)}`;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
776
807
|
writeSubtaskStatus(record, subtask.id, {
|
|
777
808
|
status: verdict.status,
|
|
778
809
|
progress: 100,
|
|
779
810
|
finishedAt: Date.now(),
|
|
780
|
-
summary: truncate(output, 3000),
|
|
811
|
+
summary: truncate(lessonNote ? `${output}\n[自我学习] ${lessonNote}` : output, 3000),
|
|
781
812
|
error: verdict.error,
|
|
782
813
|
verification: verdict.verification,
|
|
783
814
|
acceptance: verdict.acceptance,
|
|
@@ -912,6 +943,24 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
912
943
|
if (child.controller.signal.aborted) {
|
|
913
944
|
throw child.controller.signal.reason ?? abortError();
|
|
914
945
|
}
|
|
946
|
+
/*
|
|
947
|
+
* [2.0.0] 自我学习闭环的入口:把与本子任务最相关的历史教训注入提示词。
|
|
948
|
+
*
|
|
949
|
+
* 记忆读取失败不能影响本次派发(宁可不带教训,也不能因此不做任务),
|
|
950
|
+
* 所以整段用 try/catch 兜底;文件不存在时 renderLessonsBrief 返回空串。
|
|
951
|
+
*/
|
|
952
|
+
let lessonsBrief = '';
|
|
953
|
+
try {
|
|
954
|
+
lessonsBrief = renderLessonsBrief({
|
|
955
|
+
department: subtask.department,
|
|
956
|
+
title: subtask.title,
|
|
957
|
+
objective: subtask.objective,
|
|
958
|
+
cwd: options.cwd,
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
catch {
|
|
962
|
+
lessonsBrief = '';
|
|
963
|
+
}
|
|
915
964
|
activation = await ctx.subagents.startActivation({
|
|
916
965
|
provider: 'spawn',
|
|
917
966
|
label: `${subtask.department}:${subtask.id} ${subtask.title}`.slice(0, 120),
|
|
@@ -944,6 +993,7 @@ async function executeSubtask(ctx, record, stage, subtask, options) {
|
|
|
944
993
|
conversationContext,
|
|
945
994
|
statuses: record.statuses,
|
|
946
995
|
previousFailure: attempt > 1 ? lastFailure : null,
|
|
996
|
+
lessonsBrief,
|
|
947
997
|
}),
|
|
948
998
|
}],
|
|
949
999
|
parent: options.agent,
|
|
@@ -2713,6 +2763,20 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
2713
2763
|
* resume, cancel, the host's tool timeout) agrees on the same numbers.
|
|
2714
2764
|
*/
|
|
2715
2765
|
const pluginVersion = typeof options.version === 'string' && options.version ? options.version : 'unknown';
|
|
2766
|
+
/*
|
|
2767
|
+
* [1.12.3] fail-closed 解析:显式值优先;'auto' 只在 headless 运行中生效。
|
|
2768
|
+
* `ctx.get` 在普通对象(测试)上不存在,可选链保证降级为「非 headless」。
|
|
2769
|
+
*/
|
|
2770
|
+
const failClosedMode = options.failClosedOnIncomplete ?? 'auto';
|
|
2771
|
+
const headlessRun = (() => {
|
|
2772
|
+
try {
|
|
2773
|
+
return ctx?.get?.('headlessStartup') !== undefined;
|
|
2774
|
+
}
|
|
2775
|
+
catch {
|
|
2776
|
+
return false;
|
|
2777
|
+
}
|
|
2778
|
+
})();
|
|
2779
|
+
const failClosedActive = failClosedMode === true || (failClosedMode === 'auto' && headlessRun);
|
|
2716
2780
|
/*
|
|
2717
2781
|
* [1.8.14] Build identity, captured once.
|
|
2718
2782
|
*
|
|
@@ -3926,6 +3990,87 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
3926
3990
|
};
|
|
3927
3991
|
}
|
|
3928
3992
|
}
|
|
3993
|
+
/**
|
|
3994
|
+
* [1.13.0] 阶段三(验证阶段)的插件核验入口(用户 2026-11-05)。
|
|
3995
|
+
*
|
|
3996
|
+
* 用户规则:第一、二阶段禁用 dsh-workplan 插件,第三阶段才可以用插件验证
|
|
3997
|
+
* 是否成功、是否完全满足要求。这里的实现方式是「按提交内容判阶段」:
|
|
3998
|
+
* - 只有 planning + execution 证据齐全,才会进入阶段三核验;
|
|
3999
|
+
* - 缺 planning/execution 的调用直接以 PHASE_GATE 拒绝,并说明插件在
|
|
4000
|
+
* 阶段一、二禁用 —— 子 Agent 无法用插件跳过梳理与规划;
|
|
4001
|
+
* - 阶段三核验会逐条检查:问题梳理/可执行思路是否有实质内容、执行步骤
|
|
4002
|
+
* 是否记录、验证是否全部通过、验证记录是否覆盖全部验收标准。
|
|
4003
|
+
*
|
|
4004
|
+
* 它不写状态、不替子 Agent 宣称完成:最终是否 done 仍由 `adjudicateResult`
|
|
4005
|
+
* 对同一份 phases 再判一次,避免「核验工具说通过」与「结果块没写」两套真相。
|
|
4006
|
+
*/
|
|
4007
|
+
async function verifySubtask(agent, args) {
|
|
4008
|
+
const childSession = agent?.session;
|
|
4009
|
+
if (!childSession?.id) {
|
|
4010
|
+
return { ok: false, code: 'NO_SESSION', passed: false, error: '只能在部门子会话内做阶段三核验' };
|
|
4011
|
+
}
|
|
4012
|
+
const parentId = childSession.header?.parentSession;
|
|
4013
|
+
if (!parentId) {
|
|
4014
|
+
return {
|
|
4015
|
+
ok: false,
|
|
4016
|
+
code: 'NOT_CHILD_SESSION',
|
|
4017
|
+
passed: false,
|
|
4018
|
+
error: '当前不是子会话,无法反查父计划;三阶段核验只对已派发的部门子任务开放',
|
|
4019
|
+
};
|
|
4020
|
+
}
|
|
4021
|
+
let record = state.records.get(parentId);
|
|
4022
|
+
if (!record?.plan) {
|
|
4023
|
+
const parent = ctx.sessions?.get?.(parentId);
|
|
4024
|
+
if (parent) {
|
|
4025
|
+
try {
|
|
4026
|
+
record = reconstructFromSession(parent);
|
|
4027
|
+
}
|
|
4028
|
+
catch (error) {
|
|
4029
|
+
pushRecordError({ errors: [] }, error);
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
}
|
|
4033
|
+
if (!record?.plan) {
|
|
4034
|
+
return { ok: false, code: 'NO_PLAN', passed: false, error: '父会话没有可关联的计划,无法核验' };
|
|
4035
|
+
}
|
|
4036
|
+
const row = (record.statuses ?? []).find((item) => item?.childId === childSession.id);
|
|
4037
|
+
if (!row) {
|
|
4038
|
+
return { ok: false, code: 'NO_SUBTASK', passed: false, error: '计划里找不到与本子会话关联的子任务(childId 未登记)' };
|
|
4039
|
+
}
|
|
4040
|
+
if (row.status === 'done') {
|
|
4041
|
+
return { ok: false, code: 'ALREADY_DONE', passed: false, subtaskId: row.subtaskId, error: '该子任务已标记完成,无需再次核验' };
|
|
4042
|
+
}
|
|
4043
|
+
const found = findSubtask(record.plan, row.subtaskId);
|
|
4044
|
+
const expectedAcceptance = Array.isArray(found?.subtask?.acceptance) ? found.subtask.acceptance : [];
|
|
4045
|
+
const rawPhases = isRecord(args?.phases)
|
|
4046
|
+
? args.phases
|
|
4047
|
+
: { planning: args?.planning, execution: args?.execution, verification: args?.verification };
|
|
4048
|
+
const check = validatePhaseEvidence(rawPhases, expectedAcceptance);
|
|
4049
|
+
if (!check.ok || !check.phases) {
|
|
4050
|
+
const gate = phaseGateFromErrors(check.errors);
|
|
4051
|
+
return {
|
|
4052
|
+
ok: false,
|
|
4053
|
+
passed: false,
|
|
4054
|
+
code: gate === 'phase-1-2' ? 'PHASE_GATE' : 'VERIFICATION_INCOMPLETE',
|
|
4055
|
+
phase: gate,
|
|
4056
|
+
planId: record.plan.planId,
|
|
4057
|
+
subtaskId: row.subtaskId,
|
|
4058
|
+
gaps: check.errors,
|
|
4059
|
+
error: gate === 'phase-1-2'
|
|
4060
|
+
? `插件在阶段一、二禁用:先完成「梳理问题 → 形成可执行思路」并实际执行,阶段三才能用插件核验。${check.errors.slice(0, 5).join(';')}`
|
|
4061
|
+
: `阶段三核验未通过:${check.errors.slice(0, 5).join(';')}`,
|
|
4062
|
+
};
|
|
4063
|
+
}
|
|
4064
|
+
return {
|
|
4065
|
+
ok: true,
|
|
4066
|
+
passed: true,
|
|
4067
|
+
phase: 'verification',
|
|
4068
|
+
planId: record.plan.planId,
|
|
4069
|
+
subtaskId: row.subtaskId,
|
|
4070
|
+
summary: phaseSummaryLine(check.phases),
|
|
4071
|
+
message: '插件核验通过:三阶段证据齐全、验证全部通过。现在把同一份 phases 写进结果块并提交。',
|
|
4072
|
+
};
|
|
4073
|
+
}
|
|
3929
4074
|
/**
|
|
3930
4075
|
* [1.11.0] 子 → 父的唯一反向通道(T4 C-09 / T6 M5)。
|
|
3931
4076
|
*
|
|
@@ -5010,8 +5155,30 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5010
5155
|
const book = record.stopSteers && record.stopSteers.turn === turn
|
|
5011
5156
|
? record.stopSteers
|
|
5012
5157
|
: { turn, count: 0 };
|
|
5013
|
-
if (book.count >= STOP_STEER_LIMIT)
|
|
5158
|
+
if (book.count >= STOP_STEER_LIMIT) {
|
|
5159
|
+
/*
|
|
5160
|
+
* [1.12.3] steer 用尽后不再沉默放行。
|
|
5161
|
+
*
|
|
5162
|
+
* 旧行为(1.8.7–1.12.2):达到上限就 `return`,回合正常收尾。对交互式
|
|
5163
|
+
* 会话这是「避免死循环」;对 headless 却是事故复现路径——官方 runner 只
|
|
5164
|
+
* 看 `turn/end reason.kind==='completed'`,它会把「计划未完成但回合正常
|
|
5165
|
+
* 结束」打印成结果并 exit 0(session-99984ebd… 的最终现场)。
|
|
5166
|
+
*
|
|
5167
|
+
* 现在:headless(或显式开启)时抛 WORKPLAN_INCOMPLETE。turn-stopping
|
|
5168
|
+
* 是 serial 事件,抛错 ⇒ 该回合以 error 收尾 ⇒ runner 走 fail():
|
|
5169
|
+
* 不打印正文、非零退出。交互式会话维持原样(只 steer,不抛错)。
|
|
5170
|
+
*/
|
|
5171
|
+
if (failClosedActive) {
|
|
5172
|
+
const stuck = derivePlanSnapshot(record.statuses);
|
|
5173
|
+
const remaining = (stuck.statuses ?? [])
|
|
5174
|
+
.filter((item) => item.status !== 'done')
|
|
5175
|
+
.map((item) => String(item.subtaskId));
|
|
5176
|
+
throw new PlanError(`未完成:剩余 ${remaining.length} 项(${remaining.join(', ')})与原因——计划 ${record.plan.planId} `
|
|
5177
|
+
+ `仅完成 ${stuck.stats.done}/${stuck.stats.total},本回合已连续 ${book.count} 次被要求续跑/补证,`
|
|
5178
|
+
+ '仍未通过交付就绪检查。headless 以非零退出码结束,不输出「已完成」结果。', 'WORKPLAN_INCOMPLETE', { planId: record.plan.planId, stats: stuck.stats, remaining });
|
|
5179
|
+
}
|
|
5014
5180
|
return;
|
|
5181
|
+
}
|
|
5015
5182
|
book.count += 1;
|
|
5016
5183
|
record.stopSteers = book;
|
|
5017
5184
|
const snapshot = derivePlanSnapshot(record.statuses);
|
|
@@ -5032,6 +5199,12 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5032
5199
|
+ `已在回合收尾前要求继续/如实收尾(第 ${book.count} 次)`);
|
|
5033
5200
|
}
|
|
5034
5201
|
catch (error) {
|
|
5202
|
+
/*
|
|
5203
|
+
* [1.12.3] fail-closed 的硬失败必须穿过这层日志包装:
|
|
5204
|
+
* 这里原本把任何异常降级成一条 warn,等于把上面的抛错又吃掉。
|
|
5205
|
+
*/
|
|
5206
|
+
if (error instanceof PlanError && error.code === 'WORKPLAN_INCOMPLETE')
|
|
5207
|
+
throw error;
|
|
5035
5208
|
ctx.logger?.warn?.(`dsh-workplan: 回合收尾检查失败:${error instanceof Error ? error.message : String(error)}`);
|
|
5036
5209
|
}
|
|
5037
5210
|
}
|
|
@@ -5611,6 +5784,49 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5611
5784
|
});
|
|
5612
5785
|
}
|
|
5613
5786
|
}
|
|
5787
|
+
/**
|
|
5788
|
+
* [2.0.0] 只读的「永久教训记忆」入口。
|
|
5789
|
+
*
|
|
5790
|
+
* 用户要求这些经验必须能被复核。主 Agent 在阶段三可以用它查:记住了什么、
|
|
5791
|
+
* 哪些同类错误在重复发生、文件到底写在哪。它只读文件,不改任何计划状态。
|
|
5792
|
+
*/
|
|
5793
|
+
async function lessonsTool(_agent, args) {
|
|
5794
|
+
const parsed = isRecord(args) ? args : {};
|
|
5795
|
+
const action = String(parsed.action ?? 'list');
|
|
5796
|
+
const file = resolveLessonsFile();
|
|
5797
|
+
try {
|
|
5798
|
+
if (action === 'stats') {
|
|
5799
|
+
return { ok: true, ...lessonStats(file) };
|
|
5800
|
+
}
|
|
5801
|
+
if (action === 'search') {
|
|
5802
|
+
const query = String(parsed.query ?? '').trim();
|
|
5803
|
+
const rows = query
|
|
5804
|
+
? readLessons(file).filter((item) => `${item.title} ${item.problems.join(' ')} ${item.detours.join(' ')} ${item.prevention.join(' ')}`
|
|
5805
|
+
.toLowerCase()
|
|
5806
|
+
.includes(query.toLowerCase()))
|
|
5807
|
+
: readLessons(file);
|
|
5808
|
+
const limit = Math.min(Math.max(Number(parsed.limit) || 10, 1), 50);
|
|
5809
|
+
return { ok: true, file, total: rows.length, lessons: rows.slice(-limit).reverse() };
|
|
5810
|
+
}
|
|
5811
|
+
const department = typeof parsed.department === 'string' ? parsed.department.trim() : '';
|
|
5812
|
+
const limit = Math.min(Math.max(Number(parsed.limit) || 10, 1), 50);
|
|
5813
|
+
const lessons = department
|
|
5814
|
+
? readLessons(file).filter((item) => item.department === department)
|
|
5815
|
+
: readLessons(file);
|
|
5816
|
+
const ranked = department
|
|
5817
|
+
? rankLessons(lessons, { department, limit, now: Date.now() })
|
|
5818
|
+
: lessons.slice(-limit).reverse();
|
|
5819
|
+
return { ok: true, file, total: lessons.length, lessons: ranked };
|
|
5820
|
+
}
|
|
5821
|
+
catch (error) {
|
|
5822
|
+
return {
|
|
5823
|
+
ok: false,
|
|
5824
|
+
file,
|
|
5825
|
+
error: truncate(error instanceof Error ? error.message : String(error), 300),
|
|
5826
|
+
lessons: [],
|
|
5827
|
+
};
|
|
5828
|
+
}
|
|
5829
|
+
}
|
|
5614
5830
|
function dispose() {
|
|
5615
5831
|
// [1.10.4] 定时器不能吊住进程,也不能在记录清空后复活一个已销毁的计划。
|
|
5616
5832
|
for (const record of state.records.values())
|
|
@@ -5633,6 +5849,8 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5633
5849
|
statusTool,
|
|
5634
5850
|
followupTool,
|
|
5635
5851
|
escalateTool,
|
|
5852
|
+
verifyTool: verifySubtask,
|
|
5853
|
+
lessonsTool,
|
|
5636
5854
|
instructTool,
|
|
5637
5855
|
handoffTool,
|
|
5638
5856
|
replanPlan,
|
|
@@ -5642,6 +5860,14 @@ export function createWorkplanRuntime(ctx, options = {}) {
|
|
|
5642
5860
|
planModeActive: (session) => isPlanModeActive(ctx, session),
|
|
5643
5861
|
};
|
|
5644
5862
|
}
|
|
5863
|
+
/**
|
|
5864
|
+
* [1.12.3] 澄清闸门的退出口。默认开启;只有显式设成 0/false/off 才回到旧行为
|
|
5865
|
+
* (信息不足也照做计划、照派发)。
|
|
5866
|
+
*/
|
|
5867
|
+
function clarifyGateDisabled() {
|
|
5868
|
+
const raw = String(process.env.DSH_WORKPLAN_CLARIFY_GATE ?? '').trim().toLowerCase();
|
|
5869
|
+
return raw === '0' || raw === 'false' || raw === 'off';
|
|
5870
|
+
}
|
|
5645
5871
|
function resolveModelSelection(ctx, payload) {
|
|
5646
5872
|
const direct = payload.modelSelection;
|
|
5647
5873
|
if (direct?.provider && direct?.model) {
|
|
@@ -5790,6 +6016,39 @@ async function maybePlan(ctx, state, payload, downstream, options) {
|
|
|
5790
6016
|
}
|
|
5791
6017
|
return downstream;
|
|
5792
6018
|
}
|
|
6019
|
+
/*
|
|
6020
|
+
* [1.12.3] 信息不足就不做计划、不派发——只问一句。
|
|
6021
|
+
*
|
|
6022
|
+
* 用户在 2026-11-04 拍板:自动派发改成「只在信息不足这一类上拦截」,其余照旧。
|
|
6023
|
+
* 因此拦截点放在规划之前,而不是关掉自动派发:缺信息时连计划都不生成,
|
|
6024
|
+
* 免得部门 Agent 对着一个猜出来的目标开工。
|
|
6025
|
+
* 关闭方式:DSH_WORKPLAN_CLARIFY_GATE=0(保留给需要旧行为的自动化)。
|
|
6026
|
+
*/
|
|
6027
|
+
if (!clarifyGateDisabled()) {
|
|
6028
|
+
const clarify = auditClarifyNeed(taskText, conversationContext);
|
|
6029
|
+
if (clarify.needed) {
|
|
6030
|
+
const createdAt = Date.now();
|
|
6031
|
+
state.records.set(session.id, {
|
|
6032
|
+
planId: null,
|
|
6033
|
+
plan: null,
|
|
6034
|
+
title: '任务信息不足(先澄清)',
|
|
6035
|
+
degraded: false,
|
|
6036
|
+
clarify: true,
|
|
6037
|
+
error: clarify.reason,
|
|
6038
|
+
statuses: [],
|
|
6039
|
+
phase: 'clarify',
|
|
6040
|
+
errors: [truncate(clarify.reason, 1000)],
|
|
6041
|
+
createdAt,
|
|
6042
|
+
updatedAt: createdAt,
|
|
6043
|
+
createdTurn: payload.turn,
|
|
6044
|
+
});
|
|
6045
|
+
return enterDecision(downstream, [buildClarifyMessage({
|
|
6046
|
+
rule: clarify.rule,
|
|
6047
|
+
reason: clarify.reason,
|
|
6048
|
+
question: clarify.question,
|
|
6049
|
+
})]);
|
|
6050
|
+
}
|
|
6051
|
+
}
|
|
5793
6052
|
const modelSelection = resolveModelSelection(ctx, payload);
|
|
5794
6053
|
if (!modelSelection?.provider || !modelSelection?.model) {
|
|
5795
6054
|
const message = buildDegradedMessage({
|