dsh-workplan 3.0.6 → 3.0.9
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 +22 -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/lib/comm-format.js +5 -5
- package/lib/{three-phase.js → five-step.js} +204 -132
- package/lib/host.js +120 -75
- package/lib/lessons.js +4 -4
- package/lib/llm-rules.js +22 -80
- package/lib/plan.js +155 -65
- package/lib/runtime.js +307 -133
- package/lib/v3-contract.js +3 -3
- package/package.json +2 -3
- package/src/comm-format.ts +5 -5
- package/src/{three-phase.ts → five-step.ts} +230 -167
- package/src/host.ts +120 -75
- package/src/lessons.ts +4 -4
- package/src/llm-rules.ts +27 -99
- package/src/plan.ts +152 -63
- package/src/runtime.ts +318 -133
- package/src/v3-contract.ts +3 -3
|
@@ -1,56 +1,53 @@
|
|
|
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
33
|
|
|
40
|
-
import { type Retrospective, validateRetrospective } from './lessons.js'
|
|
34
|
+
import { type Retrospective, MIN_RETRO_PREVENTION_CHARS, MIN_RETRO_PROBLEM_CHARS, MIN_RETRO_RESOLUTION_CHARS, validateRetrospective } from './lessons.js'
|
|
41
35
|
// [3.0.0] Dice 单一真源在 v3-contract(零依赖,无循环):
|
|
42
36
|
// plan.ts#criterionSimilarity 与这里的 missingCriteria 都用它。
|
|
43
37
|
import { diceSimilarity } from './v3-contract.js'
|
|
44
38
|
|
|
45
|
-
/**
|
|
46
|
-
export const
|
|
47
|
-
/**
|
|
48
|
-
|
|
39
|
+
/** 五步证据四组键(结果块里 `phases` 的键名);第五步由 report/departmentSummary 承载。 */
|
|
40
|
+
export const FIVE_STEP_EVIDENCE_KEYS = Object.freeze(['planning', 'preparation', 'execution', 'verification'] as const)
|
|
41
|
+
/**
|
|
42
|
+
* [3.0.8] 契约版本 4:单框架收口——废除 deepThink 两轮开工门禁,开工闸升级为
|
|
43
|
+
* 第 1/2/3 步证据(planning+preparation),结算新增开工-结算一致性比对。
|
|
44
|
+
*/
|
|
45
|
+
export const FIVE_STEP_CONTRACT_VERSION = 4
|
|
49
46
|
|
|
50
47
|
/**
|
|
51
48
|
* 「全面、全盘、深入」无法由代码度量,但可以给一个不可忽略的下限:
|
|
52
|
-
*
|
|
53
|
-
*
|
|
49
|
+
* 第一步任务梳理与第二步方法、流程、步骤各至少 40 个字符,避免一个词就冒充
|
|
50
|
+
* 规划;第二步依据(approachBasis)至少 20 个字符,避免一句空话冒充依赖对应。
|
|
54
51
|
*/
|
|
55
52
|
export const MIN_PLANNING_PROBLEM_CHARS = 40
|
|
56
53
|
export const MIN_PLANNING_APPROACH_CHARS = 40
|
|
@@ -63,6 +60,13 @@ export const MAX_PHASE_LIST_ITEMS = 20
|
|
|
63
60
|
export const MAX_PHASE_ITEM_CHARS = 800
|
|
64
61
|
export const MAX_PHASE_TOTAL_CHARS = 6000
|
|
65
62
|
|
|
63
|
+
/**
|
|
64
|
+
* [修复] 七项字数下限的完整简报(由上方常量渲染,提示词与校验器同一事实源)。
|
|
65
|
+
* 旧文案只写「40/40/20 字判据」,遮蔽了 resources/tools/prepared/evidence 四项下限,
|
|
66
|
+
* 导致子 Agent 照提示词写却仍然被开工闸/结算闸打回。此处一处定义、各处引用。
|
|
67
|
+
*/
|
|
68
|
+
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} 字`
|
|
69
|
+
|
|
66
70
|
export type PhaseCheck = {
|
|
67
71
|
criterion: string
|
|
68
72
|
method: string
|
|
@@ -70,20 +74,20 @@ export type PhaseCheck = {
|
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
export type PlanningPhase = {
|
|
73
|
-
/**
|
|
77
|
+
/** 第一步 · 任务梳理:全面、全盘、深入梳理、研究、思考自己的任务的结果。 */
|
|
74
78
|
problemAnalysis: string[]
|
|
75
79
|
constraints: string[]
|
|
76
80
|
unknowns: string[]
|
|
77
|
-
/**
|
|
81
|
+
/** 第二步 · 资源研究:完成本任务需要哪些资源(数据、文件、权限、人、知识、时间)。 */
|
|
78
82
|
resources: string[]
|
|
79
|
-
/**
|
|
83
|
+
/** 第二步 · 工具研究:完成本任务需要哪些工具,以及每个工具用来做什么。 */
|
|
80
84
|
tools: string[]
|
|
81
|
-
/**
|
|
85
|
+
/** 第二步 · 基于第一步全部结果理清的方法、流程、步骤(一步步执行的路径)。 */
|
|
82
86
|
approach: string[]
|
|
83
87
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
88
|
+
* 第二步依据(必填):第二步的资源/工具/方案如何「基于第一步完成好的所有
|
|
89
|
+
* 结果」——逐条写清第一步的哪些事实/约束/矛盾决定了第二步的哪些资源/工具/
|
|
90
|
+
* 步骤。缺它则两步之间的依赖不可审计,规划阶段判未完成。
|
|
87
91
|
*/
|
|
88
92
|
approachBasis: string[]
|
|
89
93
|
}
|
|
@@ -109,16 +113,17 @@ export type VerificationPhase = {
|
|
|
109
113
|
checks: PhaseCheck[]
|
|
110
114
|
requirementCheck: string
|
|
111
115
|
/**
|
|
112
|
-
* [2.0.0]
|
|
116
|
+
* [2.0.0] 第四步收尾的自我学习复盘(用户 2026-11-05 强制要求)。
|
|
113
117
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
118
|
+
* 复盘不是第五步,而是第四步验证收尾的必填项——完成之后、报 done 之前,
|
|
119
|
+
* 必须把本次全过程遇到的问题、弯路、解决方式与防再犯规则说清楚,并由
|
|
120
|
+
* lessons.ts 落盘成永久记忆。
|
|
117
121
|
*/
|
|
118
122
|
retrospective: Retrospective
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
|
|
125
|
+
/** 结果块里的 `phases` 对象(五步证据的第 1–4 组;第 5 步由 report 承载)。 */
|
|
126
|
+
export type FiveStepPhases = {
|
|
122
127
|
version: number
|
|
123
128
|
planning: PlanningPhase
|
|
124
129
|
preparation: PreparationPhase
|
|
@@ -128,9 +133,9 @@ export type ThreePhases = {
|
|
|
128
133
|
|
|
129
134
|
export type PhaseValidation = {
|
|
130
135
|
ok: boolean
|
|
131
|
-
phases:
|
|
136
|
+
phases: FiveStepPhases | null
|
|
132
137
|
errors: string[]
|
|
133
|
-
/**
|
|
138
|
+
/** 错误落在哪一组:'planning' | 'preparation' | 'execution' | 'verification' | 'shape' */
|
|
134
139
|
failedPhase: 'planning' | 'preparation' | 'execution' | 'verification' | 'shape' | null
|
|
135
140
|
}
|
|
136
141
|
|
|
@@ -219,97 +224,107 @@ function missingCriteria(expected: any, checks: PhaseCheck[]) {
|
|
|
219
224
|
return missing
|
|
220
225
|
}
|
|
221
226
|
|
|
222
|
-
/**
|
|
223
|
-
|
|
224
|
-
*
|
|
225
|
-
* `expectedAcceptance` is the plan's own acceptance table. When present, every
|
|
226
|
-
* criterion must have a verification check; a shorter list is treated as an
|
|
227
|
-
* incomplete phase-3 verification rather than "some checks are better than none".
|
|
228
|
-
*/
|
|
229
|
-
export function validatePhaseEvidence(value: any, expectedAcceptance: any = []): PhaseValidation {
|
|
230
|
-
const errors: string[] = []
|
|
231
|
-
let failedPhase: PhaseValidation['failedPhase'] = null
|
|
232
|
-
const fail = (phase: NonNullable<PhaseValidation['failedPhase']>, message: string) => {
|
|
233
|
-
errors.push(message)
|
|
234
|
-
if (failedPhase === null) failedPhase = phase
|
|
235
|
-
}
|
|
236
|
-
if (!isRecord(value)) {
|
|
237
|
-
return {
|
|
238
|
-
ok: false,
|
|
239
|
-
phases: null,
|
|
240
|
-
errors: ['phases 缺失:必须提交 planning(第一、二步)/ preparation(第三步)/ execution(第四步)/ verification(第四步验证)四组证据,第五步用 report / departmentSummary 交付'],
|
|
241
|
-
failedPhase: 'shape',
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const planningRaw = isRecord(value.planning) ? value.planning : null
|
|
245
|
-
if (!planningRaw) fail('planning', 'phases.planning 缺失(第一步 · 任务梳理 + 第二步 · 资源/工具/实施方案研究:先全面、全盘、深入梳理研究自己的任务,再基于其结果研究需要哪些资源、哪些工具、具体实施方案)')
|
|
246
|
-
const preparationRaw = isRecord(value.preparation) ? value.preparation : null
|
|
247
|
-
if (!preparationRaw) fail('preparation', 'phases.preparation 缺失(第三步 · 准备:把第二步研究出的资源、工具、实施方案真正备齐,并给出就绪证据)')
|
|
248
|
-
const executionRaw = isRecord(value.execution) ? value.execution : null
|
|
249
|
-
if (!executionRaw) fail('execution', 'phases.execution 缺失(阶段二:基于第二轮理清的方法、流程、步骤执行)')
|
|
250
|
-
const verificationRaw = isRecord(value.verification) ? value.verification : null
|
|
251
|
-
if (!verificationRaw) fail('verification', 'phases.verification 缺失(阶段三:逐条验证)')
|
|
252
|
-
|
|
227
|
+
/** 解析并校验 planning 组(第 1、2 步证据);required=false 时全部字段 optional。 */
|
|
228
|
+
function parsePlanningPhase(planningRaw: any, errors: string[], required: boolean): PlanningPhase {
|
|
253
229
|
const planning: PlanningPhase = {
|
|
254
230
|
problemAnalysis: readTextList(planningRaw?.problemAnalysis, 'phases.planning.problemAnalysis', errors, {
|
|
255
|
-
required
|
|
231
|
+
required,
|
|
256
232
|
minItems: 1,
|
|
257
233
|
}),
|
|
258
234
|
constraints: readTextList(planningRaw?.constraints, 'phases.planning.constraints', errors, { required: false }),
|
|
259
235
|
unknowns: readTextList(planningRaw?.unknowns, 'phases.planning.unknowns', errors, { required: false }),
|
|
260
236
|
approach: readTextList(planningRaw?.approach, 'phases.planning.approach', errors, {
|
|
261
|
-
required
|
|
237
|
+
required,
|
|
262
238
|
minItems: 1,
|
|
263
239
|
}),
|
|
264
240
|
approachBasis: readTextList(planningRaw?.approachBasis, 'phases.planning.approachBasis', errors, {
|
|
265
|
-
required
|
|
241
|
+
required,
|
|
266
242
|
minItems: 1,
|
|
267
243
|
}),
|
|
268
244
|
resources: readTextList(planningRaw?.resources, 'phases.planning.resources', errors, {
|
|
269
|
-
required
|
|
245
|
+
required,
|
|
270
246
|
minItems: 1,
|
|
271
247
|
}),
|
|
272
248
|
tools: readTextList(planningRaw?.tools, 'phases.planning.tools', errors, {
|
|
273
|
-
required
|
|
249
|
+
required,
|
|
274
250
|
minItems: 1,
|
|
275
251
|
}),
|
|
276
252
|
}
|
|
277
|
-
if (errors.some((item) => item.startsWith('phases.planning.problemAnalysis'))) failedPhase ||= 'planning'
|
|
278
|
-
if (errors.some((item) => item.startsWith('phases.planning.approach'))) failedPhase ||= 'planning'
|
|
279
253
|
if (planning.problemAnalysis.length > 0 && totalChars(planning.problemAnalysis) < MIN_PLANNING_PROBLEM_CHARS) {
|
|
280
|
-
|
|
254
|
+
errors.push(`phases.planning.problemAnalysis 太薄(合计 ${totalChars(planning.problemAnalysis)} 字,至少 ${MIN_PLANNING_PROBLEM_CHARS} 字):第一步要全面、全盘、深入梳理、研究、思考自己的任务,逐条写清目标与验收、现状、约束、未知、主要矛盾与边界`)
|
|
281
255
|
}
|
|
282
256
|
if (planning.approach.length > 0 && totalChars(planning.approach) < MIN_PLANNING_APPROACH_CHARS) {
|
|
283
|
-
|
|
257
|
+
errors.push(`phases.planning.approach 太薄(合计 ${totalChars(planning.approach)} 字,至少 ${MIN_PLANNING_APPROACH_CHARS} 字):第二步要基于第一步全部结果理清具体一步步执行、完美完成任务的方法、流程和步骤,而不是一句目标`)
|
|
284
258
|
}
|
|
285
259
|
if (planning.approachBasis.length > 0 && totalChars(planning.approachBasis) < MIN_PLANNING_BASIS_CHARS) {
|
|
286
|
-
|
|
260
|
+
errors.push(`phases.planning.approachBasis 太薄(合计 ${totalChars(planning.approachBasis)} 字,至少 ${MIN_PLANNING_BASIS_CHARS} 字):要写清第二步的方法、流程、步骤如何基于第一步梳理、研究、思考完成好的所有结果`)
|
|
287
261
|
}
|
|
288
|
-
|
|
289
262
|
if (planning.resources.length > 0 && totalChars(planning.resources) < MIN_RESOURCE_CHARS) {
|
|
290
|
-
|
|
263
|
+
errors.push(`phases.planning.resources 太薄(合计 ${totalChars(planning.resources)} 字,至少 ${MIN_RESOURCE_CHARS} 字):第二步要逐项写清完成本任务需要哪些资源(数据/文件/权限/人/知识/时间),缺一项就会在执行中卡住`)
|
|
291
264
|
}
|
|
292
265
|
if (planning.tools.length > 0 && totalChars(planning.tools) < MIN_TOOL_CHARS) {
|
|
293
|
-
|
|
266
|
+
errors.push(`phases.planning.tools 太薄(合计 ${totalChars(planning.tools)} 字,至少 ${MIN_TOOL_CHARS} 字):第二步要逐项写清需要哪些工具、每个工具用来做什么、为什么选它`)
|
|
294
267
|
}
|
|
268
|
+
return planning
|
|
269
|
+
}
|
|
295
270
|
|
|
271
|
+
/** 解析并校验 preparation 组(第 3 步证据);required=false 时全部字段 optional。 */
|
|
272
|
+
function parsePreparationPhase(preparationRaw: any, errors: string[], required: boolean): PreparationPhase {
|
|
296
273
|
const preparation: PreparationPhase = {
|
|
297
274
|
prepared: readTextList(preparationRaw?.prepared, 'phases.preparation.prepared', errors, {
|
|
298
|
-
required
|
|
275
|
+
required,
|
|
299
276
|
minItems: 1,
|
|
300
277
|
}),
|
|
301
278
|
evidence: readTextList(preparationRaw?.evidence, 'phases.preparation.evidence', errors, {
|
|
302
|
-
required
|
|
279
|
+
required,
|
|
303
280
|
minItems: 1,
|
|
304
281
|
}),
|
|
305
282
|
}
|
|
306
|
-
if (errors.some((item) => item.startsWith('phases.preparation'))) failedPhase ||= 'preparation'
|
|
307
283
|
if (preparation.prepared.length > 0 && totalChars(preparation.prepared) < MIN_PREPARATION_CHARS) {
|
|
308
|
-
|
|
284
|
+
errors.push(`phases.preparation.prepared 太薄(合计 ${totalChars(preparation.prepared)} 字,至少 ${MIN_PREPARATION_CHARS} 字):第三步要把第二步研究出的资源与工具真正备齐,逐项写清准备了什么、在哪里、是否可用`)
|
|
309
285
|
}
|
|
310
286
|
if (preparation.evidence.length > 0 && totalChars(preparation.evidence) < MIN_PREPARATION_CHARS) {
|
|
311
|
-
|
|
287
|
+
errors.push(`phases.preparation.evidence 太薄(合计 ${totalChars(preparation.evidence)} 字,至少 ${MIN_PREPARATION_CHARS} 字):每一项就绪状态都要有可复核的证据(命令输出/文件路径/配置项/版本号/引用)`)
|
|
312
288
|
}
|
|
289
|
+
return preparation
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Parse + validate the `phases` object from a child's evidence block(结算闸:五步全量)。
|
|
294
|
+
*
|
|
295
|
+
* `expectedAcceptance` is the plan's own acceptance table. When present, every
|
|
296
|
+
* criterion must have a verification check; a shorter list is treated as an
|
|
297
|
+
* incomplete 第四步 verification rather than "some checks are better than none".
|
|
298
|
+
*/
|
|
299
|
+
export function validateFiveStepEvidence(value: any, expectedAcceptance: any = []): PhaseValidation {
|
|
300
|
+
const errors: string[] = []
|
|
301
|
+
let failedPhase: PhaseValidation['failedPhase'] = null
|
|
302
|
+
const fail = (phase: NonNullable<PhaseValidation['failedPhase']>, message: string) => {
|
|
303
|
+
errors.push(message)
|
|
304
|
+
if (failedPhase === null) failedPhase = phase
|
|
305
|
+
}
|
|
306
|
+
if (!isRecord(value)) {
|
|
307
|
+
return {
|
|
308
|
+
ok: false,
|
|
309
|
+
phases: null,
|
|
310
|
+
errors: ['phases 缺失:必须提交 planning(第一、二步)/ preparation(第三步)/ execution(第四步)/ verification(第四步验证)四组证据,第五步用 report / departmentSummary 交付'],
|
|
311
|
+
failedPhase: 'shape',
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const planningRaw = isRecord(value.planning) ? value.planning : null
|
|
315
|
+
if (!planningRaw) fail('planning', 'phases.planning 缺失(第一步 · 任务梳理 + 第二步 · 资源/工具/实施方案研究:先全面、全盘、深入梳理研究自己的任务,再基于其结果研究需要哪些资源、哪些工具、具体实施方案)')
|
|
316
|
+
const preparationRaw = isRecord(value.preparation) ? value.preparation : null
|
|
317
|
+
if (!preparationRaw) fail('preparation', 'phases.preparation 缺失(第三步 · 准备:把第二步研究出的资源、工具、实施方案真正备齐,并给出就绪证据)')
|
|
318
|
+
const executionRaw = isRecord(value.execution) ? value.execution : null
|
|
319
|
+
if (!executionRaw) fail('execution', 'phases.execution 缺失(第四步:基于第二步理清的方法、流程、步骤执行)')
|
|
320
|
+
const verificationRaw = isRecord(value.verification) ? value.verification : null
|
|
321
|
+
if (!verificationRaw) fail('verification', 'phases.verification 缺失(第四步收尾:逐条验证)')
|
|
322
|
+
|
|
323
|
+
const planning = parsePlanningPhase(planningRaw, errors, !!planningRaw)
|
|
324
|
+
if (errors.some((item) => item.startsWith('phases.planning'))) failedPhase ||= 'planning'
|
|
325
|
+
|
|
326
|
+
const preparation = parsePreparationPhase(preparationRaw, errors, !!preparationRaw)
|
|
327
|
+
if (errors.some((item) => item.startsWith('phases.preparation'))) failedPhase ||= 'preparation'
|
|
313
328
|
|
|
314
329
|
const execution: ExecutionPhase = {
|
|
315
330
|
steps: readTextList(executionRaw?.steps, 'phases.execution.steps', errors, {
|
|
@@ -374,8 +389,8 @@ export function validatePhaseEvidence(value: any, expectedAcceptance: any = []):
|
|
|
374
389
|
}
|
|
375
390
|
}
|
|
376
391
|
|
|
377
|
-
const phases:
|
|
378
|
-
version:
|
|
392
|
+
const phases: FiveStepPhases = {
|
|
393
|
+
version: FIVE_STEP_CONTRACT_VERSION,
|
|
379
394
|
planning,
|
|
380
395
|
preparation,
|
|
381
396
|
execution,
|
|
@@ -404,17 +419,17 @@ export function validatePhaseEvidence(value: any, expectedAcceptance: any = []):
|
|
|
404
419
|
/**
|
|
405
420
|
* Which stage a caller is allowed to be in, judged only by the evidence it sent.
|
|
406
421
|
*
|
|
407
|
-
* Used by `dsh_workplan_verify`: planning/execution gaps mean the caller is
|
|
408
|
-
* still in
|
|
422
|
+
* Used by `dsh_workplan_verify`: planning/preparation/execution gaps mean the caller is
|
|
423
|
+
* still in steps 1–3, where verify returns PHASE_GATE with the missing items.
|
|
409
424
|
*/
|
|
410
|
-
export function phaseGateFromErrors(errors: string[]): '
|
|
425
|
+
export function phaseGateFromErrors(errors: string[]): 'steps-1-3' | 'verification' {
|
|
411
426
|
return errors.some((item) => /^phases(\.| 缺失)/.test(item) && /planning|preparation|execution/.test(item))
|
|
412
|
-
? '
|
|
427
|
+
? 'steps-1-3'
|
|
413
428
|
: 'verification'
|
|
414
429
|
}
|
|
415
430
|
|
|
416
|
-
/** One-line, model-readable summary of what the
|
|
417
|
-
export function phaseSummaryLine(phases:
|
|
431
|
+
/** One-line, model-readable summary of what the five-step evidence contains. */
|
|
432
|
+
export function phaseSummaryLine(phases: FiveStepPhases): string {
|
|
418
433
|
const deviations = phases.execution.deviations.length
|
|
419
434
|
return [
|
|
420
435
|
`第一步 任务梳理(${phases.planning.problemAnalysis.length} 条)`,
|
|
@@ -431,15 +446,15 @@ export function phaseSummaryLine(phases: ThreePhases): string {
|
|
|
431
446
|
/**
|
|
432
447
|
* Prompt paragraphs injected into every department child.
|
|
433
448
|
*
|
|
434
|
-
* Kept in this module so the wording and the
|
|
449
|
+
* Kept in this module so the wording and the validators above are one contract:
|
|
435
450
|
* changing what is demanded without changing what is checked would make the
|
|
436
451
|
* prompt lie about completion.
|
|
437
452
|
*/
|
|
438
|
-
export function
|
|
453
|
+
export function fiveStepPromptLines(): string[] {
|
|
439
454
|
return [
|
|
440
|
-
'五步工作法(用户 2026-11-17
|
|
455
|
+
'五步工作法(用户 2026-11-17 强制要求;五个步骤必须按顺序执行,前一步没有完成并写好证据之前,禁止进入下一步):',
|
|
441
456
|
'【第一步 · 任务梳理(部门负责人、相关领域全球顶尖专家执行自己的任务时同一口径)】',
|
|
442
|
-
' 先全面、全盘、深入梳理、研究、思考自己的任务:逐条写清任务目标与验收标准、现状与已知事实、约束条件、未知/待确认项、主要矛盾、工作边界与依赖,结果写入 phases.planning.problemAnalysis
|
|
457
|
+
' 先全面、全盘、深入梳理、研究、思考自己的任务:逐条写清任务目标与验收标准、现状与已知事实、约束条件、未知/待确认项、主要矛盾、工作边界与依赖,结果写入 phases.planning.problemAnalysis;约束与未知项若在开工登记(startPhases)里请一并写进 problemAnalysis 条目内(startPhases 的 planning 只收 problemAnalysis/resources/tools/approach/approachBasis 五个字段),收尾结果块的 phases.planning 可以另写 constraints / unknowns 两个可选清单。',
|
|
443
458
|
'【第二步 · 资源、工具与实施方案研究】',
|
|
444
459
|
' 基于第一步完成好的所有结果,再全面、全盘、深入地梳理、研究、思考:完成本任务需要哪些资源(数据/文件/权限/人/知识/时间)写入 phases.planning.resources;需要哪些工具、每个工具用来做什么写入 phases.planning.tools;具体实施方案写成自己该具体如何一步步以最高效率执行、确保完美完成自己任务的方法、流程和步骤(每一步做什么、产出什么、依赖什么、风险与对策、如何证明做对了,以及全程如何少走弯路:先查历史教训、先验证再动手、不重复试错)写入 phases.planning.approach;同时把第二步如何基于第一步全部结果逐条对应写入 phases.planning.approachBasis。',
|
|
445
460
|
' 自检:任何一条验收标准或用户原要求没有落在第二步的资源、工具与实施方案上,就回到第一步重做。',
|
|
@@ -447,7 +462,7 @@ export function threePhasePromptLines(): string[] {
|
|
|
447
462
|
' 基于第二步的全部结果,把需要的资源、工具、实施方案真正准备到位,而不是「打算用」:逐项写清准备了什么、在哪里、是否可用,写入 phases.preparation.prepared;每一项就绪状态都必须给出可复核的证据(命令输出/文件路径/配置项/版本号/引用),写入 phases.preparation.evidence。缺资源、缺工具、缺证据时,先补齐或如实上报受阻,不得带着缺口进入第四步。',
|
|
448
463
|
'【第四步 · 执行与验证】',
|
|
449
464
|
' 基于第三步备齐的成果和既定实施方案,开始具体执行,严格按 phases.planning.approach 落地;出现新事实需要偏离时,必须记录偏离原因、证据与调整后的做法,不得静默改道,执行步骤写入 phases.execution.steps。',
|
|
450
|
-
' 执行完成后逐条验证验收标准与用户原要求:每条都要有可复核的证据(命令输出/文件/引用);验证未通过不得报 done
|
|
465
|
+
' 执行完成后逐条验证验收标准与用户原要求:每条都要有可复核的证据(命令输出/文件/引用);验证未通过不得报 done;确实无法确认的验收项,在结果块顶层 acceptance[] 对应条目的 result 写 "unverified"(evidence 写已核到的事实),不要写 pass——phases.verification.checks 里只写已验证条目(criterion/method/evidence 齐全),且 allPassed 必须为 true;结果写入 phases.verification。',
|
|
451
466
|
'【第四步收尾 · 自我学习复盘(强制)】',
|
|
452
467
|
' 报 done 之前必须把 phases.verification.retrospective 写全,四项缺一不可:',
|
|
453
468
|
' 1) problems:本次全过程遇到的所有问题(现象 + 根因),至少 1 条;',
|
|
@@ -456,85 +471,133 @@ export function threePhasePromptLines(): string[] {
|
|
|
456
471
|
' 4) prevention:以后如何预防再犯,至少 1 条,必须写成「遇到…先…」的可执行硬规则。',
|
|
457
472
|
'【第五步 · JSON mode 结构化交付给本部门负责人】',
|
|
458
473
|
' 执行完美完成后,必须把成果以 JSON mode 结构化交回本部门负责人:专家写入 report 对象(只允许 keyResults / keyInfo / importantInfo / leadRequirements 四个字符串数组字段,只写关键信息、关键成果、重要信息和负责人要求的东西,禁止过程流水账与重复表述);部门负责人写入 departmentSummary 对象(keyResults / keyInfo / importantInfo / sources,汇总本部门全部专家汇报,sources 必须覆盖全部已派发专家)。成果块必须放在 <!-- WORKPLAN_EVIDENCE:START --> 与 <!-- WORKPLAN_EVIDENCE:END --> 之间,且是合法 JSON,不得用散文代替。',
|
|
459
|
-
'
|
|
474
|
+
'开工闸与结算闸(五步证据门禁):',
|
|
475
|
+
' - 开工前:第一、二、三步证据(phases.planning + phases.preparation)必须经开工工具随附提交(主 Agent 随 dsh_workplan_dispatch 的 startPhases,负责人随 dsh_workplan_delegate 的 startPhases,专家随 self_effort 的 startPhases),未交/不合格会被硬拒(START_EVIDENCE_MISSING / START_EVIDENCE_INCOMPLETE),不登记、不接续正式执行。',
|
|
460
476
|
' - 第一、二、三步:先把问题梳理、资源/工具/实施方案、准备与就绪证据写全;此时不要调用 dsh_workplan_verify,它会因缺少前几步证据返回 PHASE_GATE 与待补项(这是证据门禁,不是禁用插件)。',
|
|
461
477
|
' - 第四步:可以调用 dsh_workplan_verify 让插件做最终核验:提交 planning / preparation / execution / verification 证据,插件返回 passed 或仍需补齐的 gaps;未通过先修复再回报。遇阻时可用 dsh_workplan_escalate 上报,它是安全通道,不属于五步产物。',
|
|
462
|
-
' - 结果块里的 phases 是必填项:缺 planning / preparation / execution / verification 任一组、内容为空、或验证未全部通过,插件都会判为未完成,不能用 done 收尾;第五步缺 report / departmentSummary
|
|
478
|
+
' - 结果块里的 phases 是必填项:缺 planning / preparation / execution / verification 任一组、内容为空、或验证未全部通过,插件都会判为未完成,不能用 done 收尾;第五步缺 report / departmentSummary 同样判为未完成;开工时登记的第 1/2/3 步证据不允许在收尾时变薄(一致性比对,变薄即退回)。',
|
|
479
|
+
/*
|
|
480
|
+
* [修复] 校验器同源的下限/上限全量披露:旧提示词只口头要求「写全、写深」,
|
|
481
|
+
* 从不公布具体数字(40/40/20/10、20 条/800 字/6000 字、复盘 20/20/16),
|
|
482
|
+
* 子 Agent 只能靠猜,猜错即被开工闸/结算闸打回(「五步证据不完整」「小于
|
|
483
|
+
* 20 个字符」的高频根因)。此处渲染的每个数字都与本文件校验器常量一致。
|
|
484
|
+
*/
|
|
485
|
+
`硬下限(校验器逐字执行,缺一即退回):${START_EVIDENCE_MIN_CHARS_BRIEF}。`,
|
|
486
|
+
`硬上限(校验器逐字执行,超出即退回):每个清单(数组)最多 ${MAX_PHASE_LIST_ITEMS} 条、每条最多 ${MAX_PHASE_ITEM_CHARS} 字;phases 四组(planning+preparation+execution+verification)全部条目合计最多 ${MAX_PHASE_TOTAL_CHARS} 字;phases.verification.checks 至少 1 条、且条数不得少于验收标准条数、必须逐条覆盖验收标准。`,
|
|
487
|
+
`复盘硬下限(校验器逐字执行):retrospective.problems 至少 1 条、合计 ≥${MIN_RETRO_PROBLEM_CHARS} 字;resolutions 至少 1 条、合计 ≥${MIN_RETRO_RESOLUTION_CHARS} 字;prevention 至少 1 条、合计 ≥${MIN_RETRO_PREVENTION_CHARS} 字;detours 确实没有可写空数组 []。`,
|
|
463
488
|
]
|
|
464
489
|
}
|
|
465
490
|
|
|
466
491
|
/**
|
|
467
|
-
* [
|
|
468
|
-
*
|
|
469
|
-
* 用户要求:插件底层机制必须确保主 Agent 自己也做到同一协议——执行自己的
|
|
470
|
-
* 任务时,先全面、全盘、深入梳理、研究、思考自己的任务(第一轮),再基于
|
|
471
|
-
* 第一轮完成好的所有结果,再全面、全盘、深入地开展梳理、研究和思考,理清
|
|
472
|
-
* 自己的思路,理清自己该具体如何一步步执行、达到最终完美完成自己任务的
|
|
473
|
-
* 方法、流程和步骤(第二轮),最后基于第二轮理清楚的所有方法、流程、步骤
|
|
474
|
-
* 开始具体的执行工作。
|
|
492
|
+
* [3.0.8] 开工证据 = 五步第 1、2、3 步(planning + preparation)。
|
|
475
493
|
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
* 提示词(PROMPT_SECTION)与工具 schema 同步告知,代码守住边界——与部门
|
|
481
|
-
* 层「提示词说服模型,门禁不可绕过」同一设计哲学。
|
|
494
|
+
* 每个执行者(主 Agent / 部门负责人 / 全球顶尖专家)在开工前必须随开工工具
|
|
495
|
+
* 提交:问题梳理、资源/工具/实施方案研究、准备与就绪证据。缺交/不合格硬拒
|
|
496
|
+
* (START_EVIDENCE_MISSING / START_EVIDENCE_INCOMPLETE),不登记、不接续;
|
|
497
|
+
* 登记后 durable 持久化,续跑/重试/重启回放读档放行,无需重复提交。
|
|
482
498
|
*/
|
|
483
|
-
export type
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
/** 第二轮 · 基于第一轮全部结果理清的方法、流程、步骤。 */
|
|
487
|
-
approach: string[]
|
|
488
|
-
/** 第二轮依据:第二轮如何基于第一轮完成好的所有结果(逐条对应)。 */
|
|
489
|
-
approachBasis: string[]
|
|
499
|
+
export type StartPhaseEvidence = {
|
|
500
|
+
planning: PlanningPhase
|
|
501
|
+
preparation: PreparationPhase
|
|
490
502
|
}
|
|
491
503
|
|
|
492
|
-
export type
|
|
504
|
+
export type StartPhaseValidation = {
|
|
493
505
|
ok: boolean
|
|
494
|
-
code?: '
|
|
506
|
+
code?: 'START_EVIDENCE_MISSING' | 'START_EVIDENCE_INCOMPLETE'
|
|
495
507
|
error?: string
|
|
496
|
-
|
|
508
|
+
evidence: StartPhaseEvidence | null
|
|
497
509
|
}
|
|
498
510
|
|
|
499
511
|
/**
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
* 纯函数:dispatchTool 与测试同口径消费,门禁不能被提示词绕过。
|
|
512
|
+
* 开工证据校验(dispatch / review / self_effort / direct 四个开工闸同一判据)。
|
|
513
|
+
* 纯函数:工具层与测试同口径消费,门禁不能被提示词绕过。
|
|
503
514
|
*/
|
|
504
|
-
export function
|
|
515
|
+
export function validateStartPhaseEvidence(value: any): StartPhaseValidation {
|
|
505
516
|
if (!isRecord(value)) {
|
|
506
517
|
return {
|
|
507
518
|
ok: false,
|
|
508
|
-
code: '
|
|
509
|
-
error: '
|
|
510
|
-
|
|
519
|
+
code: 'START_EVIDENCE_MISSING',
|
|
520
|
+
error: '开工证据缺失:执行自己的任务必须先完成五步前三步——第一步全面、全盘、深入梳理、研究、思考自己的任务;第二步基于第一步全部结果研究资源、工具与具体实施方案(方法、流程、步骤,含依据);第三步把资源与工具真正备齐并给出就绪证据——然后随开工工具提交 startPhases={ planning{ problemAnalysis[], approach[], approachBasis[], resources[], tools[] }, preparation{ prepared[], evidence[] } }。未提交或不合格会被硬拒,不登记、不接续正式执行。',
|
|
521
|
+
evidence: null,
|
|
511
522
|
}
|
|
512
523
|
}
|
|
513
524
|
const errors: string[] = []
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
const
|
|
517
|
-
if (
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
errors.push(`deepThink.approachBasis 太薄(合计 ${totalChars(approachBasis)} 字,至少 ${MIN_PLANNING_BASIS_CHARS} 字):要写清第二轮的方法、流程、步骤如何基于第一轮完成好的所有结果`)
|
|
525
|
-
}
|
|
526
|
-
if (errors.length > 0) {
|
|
527
|
-
return { ok: false, code: 'MAIN_DEEP_THINK_INCOMPLETE', error: errors.join(';'), deepThink: null }
|
|
525
|
+
const planningRaw = isRecord(value.planning) ? value.planning : null
|
|
526
|
+
if (!planningRaw) errors.push('startPhases.planning 缺失(第一步 · 任务梳理 + 第二步 · 资源/工具/实施方案研究)')
|
|
527
|
+
const preparationRaw = isRecord(value.preparation) ? value.preparation : null
|
|
528
|
+
if (!preparationRaw) errors.push('startPhases.preparation 缺失(第三步 · 准备:把资源、工具、实施方案真正备齐并给出就绪证据)')
|
|
529
|
+
const planning = parsePlanningPhase(planningRaw, errors, !!planningRaw)
|
|
530
|
+
const preparation = parsePreparationPhase(preparationRaw, errors, !!preparationRaw)
|
|
531
|
+
const prefix = (field: string) => field.replace(/^phases\./, 'startPhases.')
|
|
532
|
+
const renamed = errors.map((item) => prefix(item))
|
|
533
|
+
if (renamed.length > 0) {
|
|
534
|
+
return { ok: false, code: 'START_EVIDENCE_INCOMPLETE', error: renamed.join(';'), evidence: null }
|
|
528
535
|
}
|
|
529
|
-
return { ok: true,
|
|
536
|
+
return { ok: true, evidence: { planning, preparation } }
|
|
530
537
|
}
|
|
531
538
|
|
|
532
539
|
/**
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
540
|
+
* 回放侧消毒(写入与消费双侧同一判据):durable 日志里的开工证据重新过一遍
|
|
541
|
+
* 校验,非法/被篡改 ⇒ null(门禁要求重新提交),合法 ⇒ 归一化后的证据。
|
|
542
|
+
* 旧日志无该字段 ⇒ undefined 进、null 出,零迁移不报错。
|
|
536
543
|
*/
|
|
537
|
-
export function
|
|
538
|
-
const check =
|
|
539
|
-
return check.ok ? check.
|
|
544
|
+
export function sanitizeStartPhaseEvidence(value: any): StartPhaseEvidence | null {
|
|
545
|
+
const check = validateStartPhaseEvidence(value)
|
|
546
|
+
return check.ok ? check.evidence : null
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* [3.0.8] 开工-结算一致性比对:结算时的 phases 不允许比开工登记的证据变薄。
|
|
551
|
+
*
|
|
552
|
+
* 机制动机:开工闸登记的第 1/2/3 步证据与结果块里的 phases.planning/preparation
|
|
553
|
+
* 是同一份内容的两处载体;若无比对,执行者可以开工时写一套、收尾时另写一套
|
|
554
|
+
* (甚至把薄的换成厚的、把厚的换成薄的)。规则(宽容新增、禁止变薄):
|
|
555
|
+
* 对开工登记过的每一个清单字段,结算对应清单的条数与合计字符数都必须
|
|
556
|
+
* ≥ 开工登记值;违反即返回可读的违规描述(结算闸据此退回)。
|
|
557
|
+
*/
|
|
558
|
+
export function checkStartEvidenceCarryover(registered: StartPhaseEvidence, settlement: any): string[] {
|
|
559
|
+
const violations: string[] = []
|
|
560
|
+
if (!isRecord(settlement)) {
|
|
561
|
+
return ['结果块缺少 phases 对象,无法与开工登记的第 1/2/3 步证据比对']
|
|
562
|
+
}
|
|
563
|
+
const groups: Array<{ key: 'planning' | 'preparation'; label: string; fields: Array<[string, string]> }> = [
|
|
564
|
+
{
|
|
565
|
+
key: 'planning',
|
|
566
|
+
label: '第 1/2 步(任务梳理 + 资源/工具/方案研究)',
|
|
567
|
+
fields: [
|
|
568
|
+
['problemAnalysis', '任务梳理'],
|
|
569
|
+
['approach', '方法流程步骤'],
|
|
570
|
+
['approachBasis', '第二步依据'],
|
|
571
|
+
['resources', '资源研究'],
|
|
572
|
+
['tools', '工具研究'],
|
|
573
|
+
],
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
key: 'preparation',
|
|
577
|
+
label: '第 3 步(准备)',
|
|
578
|
+
fields: [
|
|
579
|
+
['prepared', '已备清单'],
|
|
580
|
+
['evidence', '就绪证据'],
|
|
581
|
+
],
|
|
582
|
+
},
|
|
583
|
+
]
|
|
584
|
+
for (const group of groups) {
|
|
585
|
+
const registeredGroup: any = (registered as any)[group.key] ?? {}
|
|
586
|
+
const settlementGroup: any = isRecord(settlement[group.key]) ? settlement[group.key] : null
|
|
587
|
+
for (const [field, label] of group.fields) {
|
|
588
|
+
const want: string[] = Array.isArray(registeredGroup[field]) ? registeredGroup[field] : []
|
|
589
|
+
if (want.length === 0) continue
|
|
590
|
+
const got: string[] = settlementGroup && Array.isArray(settlementGroup[field])
|
|
591
|
+
? settlementGroup[field].filter((item: any) => typeof item === 'string' && item.trim())
|
|
592
|
+
: []
|
|
593
|
+
const wantChars = totalChars(want)
|
|
594
|
+
const gotChars = totalChars(got)
|
|
595
|
+
if (got.length < want.length || gotChars < wantChars) {
|
|
596
|
+
violations.push(
|
|
597
|
+
`${group.label}的${label}变薄:开工登记 ${want.length} 条/${wantChars} 字,结算仅 ${got.length} 条/${gotChars} 字——收尾证据不得稀释开工时登记的第 1/2/3 步证据(可在执行中补充完善,不得减少)`,
|
|
598
|
+
)
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return violations
|
|
540
603
|
}
|