dsh-workplan 3.0.6 → 3.1.0
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 +27 -0
- package/README.en.md +2 -2
- package/README.md +16 -14
- package/README.zh.md +2 -2
- package/docs/release-notes-3.0.9.md +7 -0
- package/docs/release-notes-3.1.0.md +7 -0
- package/lib/caps.js +43 -0
- package/lib/comm-format.js +7 -7
- package/lib/{three-phase.js → five-step.js} +204 -132
- package/lib/host.js +124 -77
- package/lib/lessons.js +4 -4
- package/lib/llm-rules.js +71 -104
- package/lib/plan.js +186 -80
- package/lib/runtime.js +367 -139
- package/lib/v3-contract.js +10 -7
- package/package.json +2 -3
- package/src/caps.ts +49 -0
- package/src/comm-format.ts +7 -6
- package/src/{three-phase.ts → five-step.ts} +230 -167
- package/src/host.ts +124 -77
- package/src/lessons.ts +4 -4
- package/src/llm-rules.ts +83 -127
- package/src/plan.ts +181 -76
- package/src/runtime.ts +373 -137
- package/src/v3-contract.ts +10 -7
|
@@ -1,53 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* [
|
|
2
|
+
* [3.0.8] 五步工作法:部门 Agent 的强制执行顺序(单一框架)。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* 1.
|
|
6
|
-
* 2.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* [
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* 依赖成为可审计的结构化证据,而不是一句提示词——缺依据的结果无法记 done。
|
|
22
|
-
* 本协议对三层执行者同一口径:二级任务书(buildChildPrompt)与三级任务书
|
|
23
|
-
* (buildDelegateePrompt)都注入本模块的 threePhasePromptLines,结算门禁
|
|
24
|
-
* (validatePhaseEvidence)与负责人再分配门禁(planDelegations)同判据。
|
|
25
|
-
* 阶段三允许用 dsh_workplan_verify 核验;缺 planning/execution 证据时返回 PHASE_GATE。
|
|
26
|
-
* 注意(2.0.2 更正):2026-11-05 的「第一、二阶段禁用插件」只是当次优化会话的
|
|
27
|
-
* 过程约束,不是对所有后续会话的产品规则;插件不全局禁用。
|
|
28
|
-
*
|
|
29
|
-
* 这个模块只做纯函数与常量,不依赖 harness 服务:
|
|
30
|
-
* - 校验子 Agent 回报的 `phases` 证据(缺一阶段就判未完成);
|
|
31
|
-
* - 生成阶段摘要(写进结果与日志);
|
|
32
|
-
* - 生成提示词段落(由 `buildChildPrompt` 拼进子 Agent 的提示词)。
|
|
4
|
+
* 历史口径(本文件是三次强制要求的收口):
|
|
5
|
+
* 1. [1.13.0] 三阶段工作法(2026-11-05):规划 → 执行 → 验证;
|
|
6
|
+
* 2. [2.5.1] 两轮深度思考协议(2026-11-11):第一轮任务深研 + 第二轮方法流程
|
|
7
|
+
* 步骤(含依据 approachBasis),deepThink 开工硬门禁;
|
|
8
|
+
* 3. [3.1.0] 五步工作法(2026-11-17):第一步任务梳理 → 第二步资源/工具/实施
|
|
9
|
+
* 方案研究 → 第三步准备 → 第四步执行与验证 → 第五步 JSON 交付。
|
|
10
|
+
* 4. [3.0.8] 单框架收口(用户裁决):废除独立的两轮深度思考 deepThink 门禁——
|
|
11
|
+
* 两轮思考的实质内容(problemAnalysis/approach/approachBasis)本就是五步法
|
|
12
|
+
* 第 1、2 步的子集,保留两套框架造成同一内容双份提交、编号口径互相矛盾。
|
|
13
|
+
* 现在全系统只有一套五步契约:
|
|
14
|
+
* - 开工闸(dispatch/review/self_effort/direct):必须随附第 1、2、3 步
|
|
15
|
+
* 证据(phases.planning + phases.preparation,validateStartPhaseEvidence),
|
|
16
|
+
* 未交/不合格硬拒(START_EVIDENCE_MISSING / START_EVIDENCE_INCOMPLETE);
|
|
17
|
+
* - 结算闸(adjudicateResult):第 4、5 步证据(execution/verification/
|
|
18
|
+
* report)+ 与开工登记的一致性比对(checkStartEvidenceCarryover),
|
|
19
|
+
* 防止「开工登记一套、收尾另写一套」;
|
|
20
|
+
* - verify 工具:第四步验证前的分步自检(PHASE_GATE 语义不变)。
|
|
33
21
|
*
|
|
34
22
|
* 为什么用「结构化证据」而不是只写一句提示:
|
|
35
23
|
* 只写提示词时,模型可以直接动手、最后补一句「我已规划」。把规划内容变成
|
|
36
24
|
* 收尾证据的一部分后,缺规划/缺验证的结果无法被记成 done,主 Agent 和
|
|
37
25
|
* 回放日志都能看到每个部门到底梳理了什么、按什么思路做、验证了什么。
|
|
26
|
+
*
|
|
27
|
+
* 这个模块只做纯函数与常量,不依赖 harness 服务:
|
|
28
|
+
* - 校验开工证据(第 1/2/3 步)与结算证据(全部五步);
|
|
29
|
+
* - 开工-结算一致性比对(carryover);
|
|
30
|
+
* - 生成阶段摘要(写进结果与日志);
|
|
31
|
+
* - 生成提示词段落(由 buildChildPrompt/buildDelegateePrompt 拼进任务书)。
|
|
38
32
|
*/
|
|
39
|
-
import { validateRetrospective } from './lessons.js';
|
|
33
|
+
import { MIN_RETRO_PREVENTION_CHARS, MIN_RETRO_PROBLEM_CHARS, MIN_RETRO_RESOLUTION_CHARS, validateRetrospective } from './lessons.js';
|
|
40
34
|
// [3.0.0] Dice 单一真源在 v3-contract(零依赖,无循环):
|
|
41
35
|
// plan.ts#criterionSimilarity 与这里的 missingCriteria 都用它。
|
|
42
36
|
import { diceSimilarity } from './v3-contract.js';
|
|
43
|
-
/**
|
|
44
|
-
export const
|
|
45
|
-
/**
|
|
46
|
-
|
|
37
|
+
/** 五步证据四组键(结果块里 `phases` 的键名);第五步由 report/departmentSummary 承载。 */
|
|
38
|
+
export const FIVE_STEP_EVIDENCE_KEYS = Object.freeze(['planning', 'preparation', 'execution', 'verification']);
|
|
39
|
+
/**
|
|
40
|
+
* [3.0.8] 契约版本 4:单框架收口——废除 deepThink 两轮开工门禁,开工闸升级为
|
|
41
|
+
* 第 1/2/3 步证据(planning+preparation),结算新增开工-结算一致性比对。
|
|
42
|
+
*/
|
|
43
|
+
export const FIVE_STEP_CONTRACT_VERSION = 4;
|
|
47
44
|
/**
|
|
48
45
|
* 「全面、全盘、深入」无法由代码度量,但可以给一个不可忽略的下限:
|
|
49
|
-
*
|
|
50
|
-
*
|
|
46
|
+
* 第一步任务梳理与第二步方法、流程、步骤各至少 40 个字符,避免一个词就冒充
|
|
47
|
+
* 规划;第二步依据(approachBasis)至少 20 个字符,避免一句空话冒充依赖对应。
|
|
51
48
|
*/
|
|
52
49
|
export const MIN_PLANNING_PROBLEM_CHARS = 40;
|
|
53
50
|
export const MIN_PLANNING_APPROACH_CHARS = 40;
|
|
@@ -59,6 +56,12 @@ export const MIN_PREPARATION_CHARS = 20;
|
|
|
59
56
|
export const MAX_PHASE_LIST_ITEMS = 20;
|
|
60
57
|
export const MAX_PHASE_ITEM_CHARS = 800;
|
|
61
58
|
export const MAX_PHASE_TOTAL_CHARS = 6000;
|
|
59
|
+
/**
|
|
60
|
+
* [修复] 七项字数下限的完整简报(由上方常量渲染,提示词与校验器同一事实源)。
|
|
61
|
+
* 旧文案只写「40/40/20 字判据」,遮蔽了 resources/tools/prepared/evidence 四项下限,
|
|
62
|
+
* 导致子 Agent 照提示词写却仍然被开工闸/结算闸打回。此处一处定义、各处引用。
|
|
63
|
+
*/
|
|
64
|
+
export const START_EVIDENCE_MIN_CHARS_BRIEF = `problemAnalysis 合计 ≥${MIN_PLANNING_PROBLEM_CHARS} 字、approach 合计 ≥${MIN_PLANNING_APPROACH_CHARS} 字、approachBasis 合计 ≥${MIN_PLANNING_BASIS_CHARS} 字、resources 合计 ≥${MIN_RESOURCE_CHARS} 字、tools 合计 ≥${MIN_TOOL_CHARS} 字、prepared 合计 ≥${MIN_PREPARATION_CHARS} 字、evidence 合计 ≥${MIN_PREPARATION_CHARS} 字`;
|
|
62
65
|
function isRecord(value) {
|
|
63
66
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
64
67
|
}
|
|
@@ -142,102 +145,110 @@ function missingCriteria(expected, checks) {
|
|
|
142
145
|
}
|
|
143
146
|
return missing;
|
|
144
147
|
}
|
|
145
|
-
/**
|
|
146
|
-
|
|
147
|
-
*
|
|
148
|
-
* `expectedAcceptance` is the plan's own acceptance table. When present, every
|
|
149
|
-
* criterion must have a verification check; a shorter list is treated as an
|
|
150
|
-
* incomplete phase-3 verification rather than "some checks are better than none".
|
|
151
|
-
*/
|
|
152
|
-
export function validatePhaseEvidence(value, expectedAcceptance = []) {
|
|
153
|
-
const errors = [];
|
|
154
|
-
let failedPhase = null;
|
|
155
|
-
const fail = (phase, message) => {
|
|
156
|
-
errors.push(message);
|
|
157
|
-
if (failedPhase === null)
|
|
158
|
-
failedPhase = phase;
|
|
159
|
-
};
|
|
160
|
-
if (!isRecord(value)) {
|
|
161
|
-
return {
|
|
162
|
-
ok: false,
|
|
163
|
-
phases: null,
|
|
164
|
-
errors: ['phases 缺失:必须提交 planning(第一、二步)/ preparation(第三步)/ execution(第四步)/ verification(第四步验证)四组证据,第五步用 report / departmentSummary 交付'],
|
|
165
|
-
failedPhase: 'shape',
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
const planningRaw = isRecord(value.planning) ? value.planning : null;
|
|
169
|
-
if (!planningRaw)
|
|
170
|
-
fail('planning', 'phases.planning 缺失(第一步 · 任务梳理 + 第二步 · 资源/工具/实施方案研究:先全面、全盘、深入梳理研究自己的任务,再基于其结果研究需要哪些资源、哪些工具、具体实施方案)');
|
|
171
|
-
const preparationRaw = isRecord(value.preparation) ? value.preparation : null;
|
|
172
|
-
if (!preparationRaw)
|
|
173
|
-
fail('preparation', 'phases.preparation 缺失(第三步 · 准备:把第二步研究出的资源、工具、实施方案真正备齐,并给出就绪证据)');
|
|
174
|
-
const executionRaw = isRecord(value.execution) ? value.execution : null;
|
|
175
|
-
if (!executionRaw)
|
|
176
|
-
fail('execution', 'phases.execution 缺失(阶段二:基于第二轮理清的方法、流程、步骤执行)');
|
|
177
|
-
const verificationRaw = isRecord(value.verification) ? value.verification : null;
|
|
178
|
-
if (!verificationRaw)
|
|
179
|
-
fail('verification', 'phases.verification 缺失(阶段三:逐条验证)');
|
|
148
|
+
/** 解析并校验 planning 组(第 1、2 步证据);required=false 时全部字段 optional。 */
|
|
149
|
+
function parsePlanningPhase(planningRaw, errors, required) {
|
|
180
150
|
const planning = {
|
|
181
151
|
problemAnalysis: readTextList(planningRaw?.problemAnalysis, 'phases.planning.problemAnalysis', errors, {
|
|
182
|
-
required
|
|
152
|
+
required,
|
|
183
153
|
minItems: 1,
|
|
184
154
|
}),
|
|
185
155
|
constraints: readTextList(planningRaw?.constraints, 'phases.planning.constraints', errors, { required: false }),
|
|
186
156
|
unknowns: readTextList(planningRaw?.unknowns, 'phases.planning.unknowns', errors, { required: false }),
|
|
187
157
|
approach: readTextList(planningRaw?.approach, 'phases.planning.approach', errors, {
|
|
188
|
-
required
|
|
158
|
+
required,
|
|
189
159
|
minItems: 1,
|
|
190
160
|
}),
|
|
191
161
|
approachBasis: readTextList(planningRaw?.approachBasis, 'phases.planning.approachBasis', errors, {
|
|
192
|
-
required
|
|
162
|
+
required,
|
|
193
163
|
minItems: 1,
|
|
194
164
|
}),
|
|
195
165
|
resources: readTextList(planningRaw?.resources, 'phases.planning.resources', errors, {
|
|
196
|
-
required
|
|
166
|
+
required,
|
|
197
167
|
minItems: 1,
|
|
198
168
|
}),
|
|
199
169
|
tools: readTextList(planningRaw?.tools, 'phases.planning.tools', errors, {
|
|
200
|
-
required
|
|
170
|
+
required,
|
|
201
171
|
minItems: 1,
|
|
202
172
|
}),
|
|
203
173
|
};
|
|
204
|
-
if (errors.some((item) => item.startsWith('phases.planning.problemAnalysis')))
|
|
205
|
-
failedPhase ||= 'planning';
|
|
206
|
-
if (errors.some((item) => item.startsWith('phases.planning.approach')))
|
|
207
|
-
failedPhase ||= 'planning';
|
|
208
174
|
if (planning.problemAnalysis.length > 0 && totalChars(planning.problemAnalysis) < MIN_PLANNING_PROBLEM_CHARS) {
|
|
209
|
-
|
|
175
|
+
errors.push(`phases.planning.problemAnalysis 太薄(合计 ${totalChars(planning.problemAnalysis)} 字,至少 ${MIN_PLANNING_PROBLEM_CHARS} 字):第一步要全面、全盘、深入梳理、研究、思考自己的任务,逐条写清目标与验收、现状、约束、未知、主要矛盾与边界`);
|
|
210
176
|
}
|
|
211
177
|
if (planning.approach.length > 0 && totalChars(planning.approach) < MIN_PLANNING_APPROACH_CHARS) {
|
|
212
|
-
|
|
178
|
+
errors.push(`phases.planning.approach 太薄(合计 ${totalChars(planning.approach)} 字,至少 ${MIN_PLANNING_APPROACH_CHARS} 字):第二步要基于第一步全部结果理清具体一步步执行、完美完成任务的方法、流程和步骤,而不是一句目标`);
|
|
213
179
|
}
|
|
214
180
|
if (planning.approachBasis.length > 0 && totalChars(planning.approachBasis) < MIN_PLANNING_BASIS_CHARS) {
|
|
215
|
-
|
|
181
|
+
errors.push(`phases.planning.approachBasis 太薄(合计 ${totalChars(planning.approachBasis)} 字,至少 ${MIN_PLANNING_BASIS_CHARS} 字):要写清第二步的方法、流程、步骤如何基于第一步梳理、研究、思考完成好的所有结果`);
|
|
216
182
|
}
|
|
217
183
|
if (planning.resources.length > 0 && totalChars(planning.resources) < MIN_RESOURCE_CHARS) {
|
|
218
|
-
|
|
184
|
+
errors.push(`phases.planning.resources 太薄(合计 ${totalChars(planning.resources)} 字,至少 ${MIN_RESOURCE_CHARS} 字):第二步要逐项写清完成本任务需要哪些资源(数据/文件/权限/人/知识/时间),缺一项就会在执行中卡住`);
|
|
219
185
|
}
|
|
220
186
|
if (planning.tools.length > 0 && totalChars(planning.tools) < MIN_TOOL_CHARS) {
|
|
221
|
-
|
|
187
|
+
errors.push(`phases.planning.tools 太薄(合计 ${totalChars(planning.tools)} 字,至少 ${MIN_TOOL_CHARS} 字):第二步要逐项写清需要哪些工具、每个工具用来做什么、为什么选它`);
|
|
222
188
|
}
|
|
189
|
+
return planning;
|
|
190
|
+
}
|
|
191
|
+
/** 解析并校验 preparation 组(第 3 步证据);required=false 时全部字段 optional。 */
|
|
192
|
+
function parsePreparationPhase(preparationRaw, errors, required) {
|
|
223
193
|
const preparation = {
|
|
224
194
|
prepared: readTextList(preparationRaw?.prepared, 'phases.preparation.prepared', errors, {
|
|
225
|
-
required
|
|
195
|
+
required,
|
|
226
196
|
minItems: 1,
|
|
227
197
|
}),
|
|
228
198
|
evidence: readTextList(preparationRaw?.evidence, 'phases.preparation.evidence', errors, {
|
|
229
|
-
required
|
|
199
|
+
required,
|
|
230
200
|
minItems: 1,
|
|
231
201
|
}),
|
|
232
202
|
};
|
|
233
|
-
if (errors.some((item) => item.startsWith('phases.preparation')))
|
|
234
|
-
failedPhase ||= 'preparation';
|
|
235
203
|
if (preparation.prepared.length > 0 && totalChars(preparation.prepared) < MIN_PREPARATION_CHARS) {
|
|
236
|
-
|
|
204
|
+
errors.push(`phases.preparation.prepared 太薄(合计 ${totalChars(preparation.prepared)} 字,至少 ${MIN_PREPARATION_CHARS} 字):第三步要把第二步研究出的资源与工具真正备齐,逐项写清准备了什么、在哪里、是否可用`);
|
|
237
205
|
}
|
|
238
206
|
if (preparation.evidence.length > 0 && totalChars(preparation.evidence) < MIN_PREPARATION_CHARS) {
|
|
239
|
-
|
|
207
|
+
errors.push(`phases.preparation.evidence 太薄(合计 ${totalChars(preparation.evidence)} 字,至少 ${MIN_PREPARATION_CHARS} 字):每一项就绪状态都要有可复核的证据(命令输出/文件路径/配置项/版本号/引用)`);
|
|
208
|
+
}
|
|
209
|
+
return preparation;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Parse + validate the `phases` object from a child's evidence block(结算闸:五步全量)。
|
|
213
|
+
*
|
|
214
|
+
* `expectedAcceptance` is the plan's own acceptance table. When present, every
|
|
215
|
+
* criterion must have a verification check; a shorter list is treated as an
|
|
216
|
+
* incomplete 第四步 verification rather than "some checks are better than none".
|
|
217
|
+
*/
|
|
218
|
+
export function validateFiveStepEvidence(value, expectedAcceptance = []) {
|
|
219
|
+
const errors = [];
|
|
220
|
+
let failedPhase = null;
|
|
221
|
+
const fail = (phase, message) => {
|
|
222
|
+
errors.push(message);
|
|
223
|
+
if (failedPhase === null)
|
|
224
|
+
failedPhase = phase;
|
|
225
|
+
};
|
|
226
|
+
if (!isRecord(value)) {
|
|
227
|
+
return {
|
|
228
|
+
ok: false,
|
|
229
|
+
phases: null,
|
|
230
|
+
errors: ['phases 缺失:必须提交 planning(第一、二步)/ preparation(第三步)/ execution(第四步)/ verification(第四步验证)四组证据,第五步用 report / departmentSummary 交付'],
|
|
231
|
+
failedPhase: 'shape',
|
|
232
|
+
};
|
|
240
233
|
}
|
|
234
|
+
const planningRaw = isRecord(value.planning) ? value.planning : null;
|
|
235
|
+
if (!planningRaw)
|
|
236
|
+
fail('planning', 'phases.planning 缺失(第一步 · 任务梳理 + 第二步 · 资源/工具/实施方案研究:先全面、全盘、深入梳理研究自己的任务,再基于其结果研究需要哪些资源、哪些工具、具体实施方案)');
|
|
237
|
+
const preparationRaw = isRecord(value.preparation) ? value.preparation : null;
|
|
238
|
+
if (!preparationRaw)
|
|
239
|
+
fail('preparation', 'phases.preparation 缺失(第三步 · 准备:把第二步研究出的资源、工具、实施方案真正备齐,并给出就绪证据)');
|
|
240
|
+
const executionRaw = isRecord(value.execution) ? value.execution : null;
|
|
241
|
+
if (!executionRaw)
|
|
242
|
+
fail('execution', 'phases.execution 缺失(第四步:基于第二步理清的方法、流程、步骤执行)');
|
|
243
|
+
const verificationRaw = isRecord(value.verification) ? value.verification : null;
|
|
244
|
+
if (!verificationRaw)
|
|
245
|
+
fail('verification', 'phases.verification 缺失(第四步收尾:逐条验证)');
|
|
246
|
+
const planning = parsePlanningPhase(planningRaw, errors, !!planningRaw);
|
|
247
|
+
if (errors.some((item) => item.startsWith('phases.planning')))
|
|
248
|
+
failedPhase ||= 'planning';
|
|
249
|
+
const preparation = parsePreparationPhase(preparationRaw, errors, !!preparationRaw);
|
|
250
|
+
if (errors.some((item) => item.startsWith('phases.preparation')))
|
|
251
|
+
failedPhase ||= 'preparation';
|
|
241
252
|
const execution = {
|
|
242
253
|
steps: readTextList(executionRaw?.steps, 'phases.execution.steps', errors, {
|
|
243
254
|
required: !!executionRaw,
|
|
@@ -301,7 +312,7 @@ export function validatePhaseEvidence(value, expectedAcceptance = []) {
|
|
|
301
312
|
}
|
|
302
313
|
}
|
|
303
314
|
const phases = {
|
|
304
|
-
version:
|
|
315
|
+
version: FIVE_STEP_CONTRACT_VERSION,
|
|
305
316
|
planning,
|
|
306
317
|
preparation,
|
|
307
318
|
execution,
|
|
@@ -329,15 +340,15 @@ export function validatePhaseEvidence(value, expectedAcceptance = []) {
|
|
|
329
340
|
/**
|
|
330
341
|
* Which stage a caller is allowed to be in, judged only by the evidence it sent.
|
|
331
342
|
*
|
|
332
|
-
* Used by `dsh_workplan_verify`: planning/execution gaps mean the caller is
|
|
333
|
-
* still in
|
|
343
|
+
* Used by `dsh_workplan_verify`: planning/preparation/execution gaps mean the caller is
|
|
344
|
+
* still in steps 1–3, where verify returns PHASE_GATE with the missing items.
|
|
334
345
|
*/
|
|
335
346
|
export function phaseGateFromErrors(errors) {
|
|
336
347
|
return errors.some((item) => /^phases(\.| 缺失)/.test(item) && /planning|preparation|execution/.test(item))
|
|
337
|
-
? '
|
|
348
|
+
? 'steps-1-3'
|
|
338
349
|
: 'verification';
|
|
339
350
|
}
|
|
340
|
-
/** One-line, model-readable summary of what the
|
|
351
|
+
/** One-line, model-readable summary of what the five-step evidence contains. */
|
|
341
352
|
export function phaseSummaryLine(phases) {
|
|
342
353
|
const deviations = phases.execution.deviations.length;
|
|
343
354
|
return [
|
|
@@ -354,15 +365,15 @@ export function phaseSummaryLine(phases) {
|
|
|
354
365
|
/**
|
|
355
366
|
* Prompt paragraphs injected into every department child.
|
|
356
367
|
*
|
|
357
|
-
* Kept in this module so the wording and the
|
|
368
|
+
* Kept in this module so the wording and the validators above are one contract:
|
|
358
369
|
* changing what is demanded without changing what is checked would make the
|
|
359
370
|
* prompt lie about completion.
|
|
360
371
|
*/
|
|
361
|
-
export function
|
|
372
|
+
export function fiveStepPromptLines() {
|
|
362
373
|
return [
|
|
363
|
-
'五步工作法(用户 2026-11-17
|
|
374
|
+
'五步工作法(用户 2026-11-17 强制要求;五个步骤必须按顺序执行,前一步没有完成并写好证据之前,禁止进入下一步):',
|
|
364
375
|
'【第一步 · 任务梳理(部门负责人、相关领域全球顶尖专家执行自己的任务时同一口径)】',
|
|
365
|
-
' 先全面、全盘、深入梳理、研究、思考自己的任务:逐条写清任务目标与验收标准、现状与已知事实、约束条件、未知/待确认项、主要矛盾、工作边界与依赖,结果写入 phases.planning.problemAnalysis
|
|
376
|
+
' 先全面、全盘、深入梳理、研究、思考自己的任务:逐条写清任务目标与验收标准、现状与已知事实、约束条件、未知/待确认项、主要矛盾、工作边界与依赖,结果写入 phases.planning.problemAnalysis;约束与未知项若在开工登记(startPhases)里请一并写进 problemAnalysis 条目内(startPhases 的 planning 只收 problemAnalysis/resources/tools/approach/approachBasis 五个字段),收尾结果块的 phases.planning 可以另写 constraints / unknowns 两个可选清单。',
|
|
366
377
|
'【第二步 · 资源、工具与实施方案研究】',
|
|
367
378
|
' 基于第一步完成好的所有结果,再全面、全盘、深入地梳理、研究、思考:完成本任务需要哪些资源(数据/文件/权限/人/知识/时间)写入 phases.planning.resources;需要哪些工具、每个工具用来做什么写入 phases.planning.tools;具体实施方案写成自己该具体如何一步步以最高效率执行、确保完美完成自己任务的方法、流程和步骤(每一步做什么、产出什么、依赖什么、风险与对策、如何证明做对了,以及全程如何少走弯路:先查历史教训、先验证再动手、不重复试错)写入 phases.planning.approach;同时把第二步如何基于第一步全部结果逐条对应写入 phases.planning.approachBasis。',
|
|
368
379
|
' 自检:任何一条验收标准或用户原要求没有落在第二步的资源、工具与实施方案上,就回到第一步重做。',
|
|
@@ -370,7 +381,7 @@ export function threePhasePromptLines() {
|
|
|
370
381
|
' 基于第二步的全部结果,把需要的资源、工具、实施方案真正准备到位,而不是「打算用」:逐项写清准备了什么、在哪里、是否可用,写入 phases.preparation.prepared;每一项就绪状态都必须给出可复核的证据(命令输出/文件路径/配置项/版本号/引用),写入 phases.preparation.evidence。缺资源、缺工具、缺证据时,先补齐或如实上报受阻,不得带着缺口进入第四步。',
|
|
371
382
|
'【第四步 · 执行与验证】',
|
|
372
383
|
' 基于第三步备齐的成果和既定实施方案,开始具体执行,严格按 phases.planning.approach 落地;出现新事实需要偏离时,必须记录偏离原因、证据与调整后的做法,不得静默改道,执行步骤写入 phases.execution.steps。',
|
|
373
|
-
' 执行完成后逐条验证验收标准与用户原要求:每条都要有可复核的证据(命令输出/文件/引用);验证未通过不得报 done
|
|
384
|
+
' 执行完成后逐条验证验收标准与用户原要求:每条都要有可复核的证据(命令输出/文件/引用);验证未通过不得报 done;确实无法确认的验收项,在结果块顶层 acceptance[] 对应条目的 result 写 "unverified"(evidence 写已核到的事实),不要写 pass——phases.verification.checks 里只写已验证条目(criterion/method/evidence 齐全),且 allPassed 必须为 true;结果写入 phases.verification。',
|
|
374
385
|
'【第四步收尾 · 自我学习复盘(强制)】',
|
|
375
386
|
' 报 done 之前必须把 phases.verification.retrospective 写全,四项缺一不可:',
|
|
376
387
|
' 1) problems:本次全过程遇到的所有问题(现象 + 根因),至少 1 条;',
|
|
@@ -379,50 +390,111 @@ export function threePhasePromptLines() {
|
|
|
379
390
|
' 4) prevention:以后如何预防再犯,至少 1 条,必须写成「遇到…先…」的可执行硬规则。',
|
|
380
391
|
'【第五步 · JSON mode 结构化交付给本部门负责人】',
|
|
381
392
|
' 执行完美完成后,必须把成果以 JSON mode 结构化交回本部门负责人:专家写入 report 对象(只允许 keyResults / keyInfo / importantInfo / leadRequirements 四个字符串数组字段,只写关键信息、关键成果、重要信息和负责人要求的东西,禁止过程流水账与重复表述);部门负责人写入 departmentSummary 对象(keyResults / keyInfo / importantInfo / sources,汇总本部门全部专家汇报,sources 必须覆盖全部已派发专家)。成果块必须放在 <!-- WORKPLAN_EVIDENCE:START --> 与 <!-- WORKPLAN_EVIDENCE:END --> 之间,且是合法 JSON,不得用散文代替。',
|
|
382
|
-
'
|
|
393
|
+
'开工闸与结算闸(五步证据门禁):',
|
|
394
|
+
' - 开工前:第一、二、三步证据(phases.planning + phases.preparation)必须经开工工具随附提交(主 Agent 随 dsh_workplan_dispatch 的 startPhases,负责人随 dsh_workplan_delegate 的 startPhases,专家随 self_effort 的 startPhases),未交/不合格会被硬拒(START_EVIDENCE_MISSING / START_EVIDENCE_INCOMPLETE),不登记、不接续正式执行。',
|
|
383
395
|
' - 第一、二、三步:先把问题梳理、资源/工具/实施方案、准备与就绪证据写全;此时不要调用 dsh_workplan_verify,它会因缺少前几步证据返回 PHASE_GATE 与待补项(这是证据门禁,不是禁用插件)。',
|
|
384
396
|
' - 第四步:可以调用 dsh_workplan_verify 让插件做最终核验:提交 planning / preparation / execution / verification 证据,插件返回 passed 或仍需补齐的 gaps;未通过先修复再回报。遇阻时可用 dsh_workplan_escalate 上报,它是安全通道,不属于五步产物。',
|
|
385
|
-
' - 结果块里的 phases 是必填项:缺 planning / preparation / execution / verification 任一组、内容为空、或验证未全部通过,插件都会判为未完成,不能用 done 收尾;第五步缺 report / departmentSummary
|
|
397
|
+
' - 结果块里的 phases 是必填项:缺 planning / preparation / execution / verification 任一组、内容为空、或验证未全部通过,插件都会判为未完成,不能用 done 收尾;第五步缺 report / departmentSummary 同样判为未完成;开工时登记的第 1/2/3 步证据不允许在收尾时变薄(一致性比对,变薄即退回)。',
|
|
398
|
+
/*
|
|
399
|
+
* [修复] 校验器同源的下限/上限全量披露:旧提示词只口头要求「写全、写深」,
|
|
400
|
+
* 从不公布具体数字(40/40/20/10、20 条/800 字/6000 字、复盘 20/20/16),
|
|
401
|
+
* 子 Agent 只能靠猜,猜错即被开工闸/结算闸打回(「五步证据不完整」「小于
|
|
402
|
+
* 20 个字符」的高频根因)。此处渲染的每个数字都与本文件校验器常量一致。
|
|
403
|
+
*/
|
|
404
|
+
`硬下限(校验器逐字执行,缺一即退回):${START_EVIDENCE_MIN_CHARS_BRIEF}。`,
|
|
405
|
+
`硬上限(校验器逐字执行,超出即退回):每个清单(数组)最多 ${MAX_PHASE_LIST_ITEMS} 条、每条最多 ${MAX_PHASE_ITEM_CHARS} 字;phases 四组(planning+preparation+execution+verification)全部条目合计最多 ${MAX_PHASE_TOTAL_CHARS} 字;phases.verification.checks 至少 1 条、且条数不得少于验收标准条数、必须逐条覆盖验收标准。`,
|
|
406
|
+
`复盘硬下限(校验器逐字执行):retrospective.problems 至少 1 条、合计 ≥${MIN_RETRO_PROBLEM_CHARS} 字;resolutions 至少 1 条、合计 ≥${MIN_RETRO_RESOLUTION_CHARS} 字;prevention 至少 1 条、合计 ≥${MIN_RETRO_PREVENTION_CHARS} 字;detours 确实没有可写空数组 []。`,
|
|
386
407
|
];
|
|
387
408
|
}
|
|
388
409
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* 纯函数:dispatchTool 与测试同口径消费,门禁不能被提示词绕过。
|
|
410
|
+
* 开工证据校验(dispatch / review / self_effort / direct 四个开工闸同一判据)。
|
|
411
|
+
* 纯函数:工具层与测试同口径消费,门禁不能被提示词绕过。
|
|
392
412
|
*/
|
|
393
|
-
export function
|
|
413
|
+
export function validateStartPhaseEvidence(value) {
|
|
394
414
|
if (!isRecord(value)) {
|
|
395
415
|
return {
|
|
396
416
|
ok: false,
|
|
397
|
-
code: '
|
|
398
|
-
error: '
|
|
399
|
-
|
|
417
|
+
code: 'START_EVIDENCE_MISSING',
|
|
418
|
+
error: '开工证据缺失:执行自己的任务必须先完成五步前三步——第一步全面、全盘、深入梳理、研究、思考自己的任务;第二步基于第一步全部结果研究资源、工具与具体实施方案(方法、流程、步骤,含依据);第三步把资源与工具真正备齐并给出就绪证据——然后随开工工具提交 startPhases={ planning{ problemAnalysis[], approach[], approachBasis[], resources[], tools[] }, preparation{ prepared[], evidence[] } }。未提交或不合格会被硬拒,不登记、不接续正式执行。',
|
|
419
|
+
evidence: null,
|
|
400
420
|
};
|
|
401
421
|
}
|
|
402
422
|
const errors = [];
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (errors.length > 0) {
|
|
416
|
-
return { ok: false, code: 'MAIN_DEEP_THINK_INCOMPLETE', error: errors.join(';'), deepThink: null };
|
|
423
|
+
const planningRaw = isRecord(value.planning) ? value.planning : null;
|
|
424
|
+
if (!planningRaw)
|
|
425
|
+
errors.push('startPhases.planning 缺失(第一步 · 任务梳理 + 第二步 · 资源/工具/实施方案研究)');
|
|
426
|
+
const preparationRaw = isRecord(value.preparation) ? value.preparation : null;
|
|
427
|
+
if (!preparationRaw)
|
|
428
|
+
errors.push('startPhases.preparation 缺失(第三步 · 准备:把资源、工具、实施方案真正备齐并给出就绪证据)');
|
|
429
|
+
const planning = parsePlanningPhase(planningRaw, errors, !!planningRaw);
|
|
430
|
+
const preparation = parsePreparationPhase(preparationRaw, errors, !!preparationRaw);
|
|
431
|
+
const prefix = (field) => field.replace(/^phases\./, 'startPhases.');
|
|
432
|
+
const renamed = errors.map((item) => prefix(item));
|
|
433
|
+
if (renamed.length > 0) {
|
|
434
|
+
return { ok: false, code: 'START_EVIDENCE_INCOMPLETE', error: renamed.join(';'), evidence: null };
|
|
417
435
|
}
|
|
418
|
-
return { ok: true,
|
|
436
|
+
return { ok: true, evidence: { planning, preparation } };
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* 回放侧消毒(写入与消费双侧同一判据):durable 日志里的开工证据重新过一遍
|
|
440
|
+
* 校验,非法/被篡改 ⇒ null(门禁要求重新提交),合法 ⇒ 归一化后的证据。
|
|
441
|
+
* 旧日志无该字段 ⇒ undefined 进、null 出,零迁移不报错。
|
|
442
|
+
*/
|
|
443
|
+
export function sanitizeStartPhaseEvidence(value) {
|
|
444
|
+
const check = validateStartPhaseEvidence(value);
|
|
445
|
+
return check.ok ? check.evidence : null;
|
|
419
446
|
}
|
|
420
447
|
/**
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
448
|
+
* [3.0.8] 开工-结算一致性比对:结算时的 phases 不允许比开工登记的证据变薄。
|
|
449
|
+
*
|
|
450
|
+
* 机制动机:开工闸登记的第 1/2/3 步证据与结果块里的 phases.planning/preparation
|
|
451
|
+
* 是同一份内容的两处载体;若无比对,执行者可以开工时写一套、收尾时另写一套
|
|
452
|
+
* (甚至把薄的换成厚的、把厚的换成薄的)。规则(宽容新增、禁止变薄):
|
|
453
|
+
* 对开工登记过的每一个清单字段,结算对应清单的条数与合计字符数都必须
|
|
454
|
+
* ≥ 开工登记值;违反即返回可读的违规描述(结算闸据此退回)。
|
|
424
455
|
*/
|
|
425
|
-
export function
|
|
426
|
-
const
|
|
427
|
-
|
|
456
|
+
export function checkStartEvidenceCarryover(registered, settlement) {
|
|
457
|
+
const violations = [];
|
|
458
|
+
if (!isRecord(settlement)) {
|
|
459
|
+
return ['结果块缺少 phases 对象,无法与开工登记的第 1/2/3 步证据比对'];
|
|
460
|
+
}
|
|
461
|
+
const groups = [
|
|
462
|
+
{
|
|
463
|
+
key: 'planning',
|
|
464
|
+
label: '第 1/2 步(任务梳理 + 资源/工具/方案研究)',
|
|
465
|
+
fields: [
|
|
466
|
+
['problemAnalysis', '任务梳理'],
|
|
467
|
+
['approach', '方法流程步骤'],
|
|
468
|
+
['approachBasis', '第二步依据'],
|
|
469
|
+
['resources', '资源研究'],
|
|
470
|
+
['tools', '工具研究'],
|
|
471
|
+
],
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
key: 'preparation',
|
|
475
|
+
label: '第 3 步(准备)',
|
|
476
|
+
fields: [
|
|
477
|
+
['prepared', '已备清单'],
|
|
478
|
+
['evidence', '就绪证据'],
|
|
479
|
+
],
|
|
480
|
+
},
|
|
481
|
+
];
|
|
482
|
+
for (const group of groups) {
|
|
483
|
+
const registeredGroup = registered[group.key] ?? {};
|
|
484
|
+
const settlementGroup = isRecord(settlement[group.key]) ? settlement[group.key] : null;
|
|
485
|
+
for (const [field, label] of group.fields) {
|
|
486
|
+
const want = Array.isArray(registeredGroup[field]) ? registeredGroup[field] : [];
|
|
487
|
+
if (want.length === 0)
|
|
488
|
+
continue;
|
|
489
|
+
const got = settlementGroup && Array.isArray(settlementGroup[field])
|
|
490
|
+
? settlementGroup[field].filter((item) => typeof item === 'string' && item.trim())
|
|
491
|
+
: [];
|
|
492
|
+
const wantChars = totalChars(want);
|
|
493
|
+
const gotChars = totalChars(got);
|
|
494
|
+
if (got.length < want.length || gotChars < wantChars) {
|
|
495
|
+
violations.push(`${group.label}的${label}变薄:开工登记 ${want.length} 条/${wantChars} 字,结算仅 ${got.length} 条/${gotChars} 字——收尾证据不得稀释开工时登记的第 1/2/3 步证据(可在执行中补充完善,不得减少)`);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return violations;
|
|
428
500
|
}
|