dsh-workplan 2.3.2 → 2.3.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 +8 -0
- package/README.en.md +2 -2
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/client.js +40 -0
- package/docs/cc/ADV-FSP-FUNCTIONAL-SPEC.md +1 -0
- package/docs/cc/AVA-VULNERABILITY-ANALYSIS.md +10 -0
- package/docs/cc/SECURITY-TARGET.md +1 -0
- package/docs/release-record-2.3.2-20261110.md +25 -0
- package/lib/client.js +40 -0
- package/lib/host.js +134 -2
- package/lib/llm-rules.js +221 -0
- package/lib/plan.js +158 -4
- package/lib/replan.js +16 -5
- package/lib/runtime.js +384 -13
- package/package.json +1 -1
- package/src/client.ts +47 -0
- package/src/host.ts +142 -2
- package/src/llm-rules.ts +345 -0
- package/src/plan.ts +178 -3
- package/src/replan.ts +16 -5
- package/src/runtime.ts +392 -13
package/src/host.ts
CHANGED
|
@@ -772,6 +772,140 @@ function createEscalateTool(runtime: any) {
|
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
774
|
|
|
775
|
+
/**
|
|
776
|
+
* [2.3.9][T4b] 第三层派发工具(用户强制要求 4/5):部门负责人专用。
|
|
777
|
+
*
|
|
778
|
+
* 用户要求 4 原文:「分到相关任务的相关部门的负责人,必须再将你分配的任务,
|
|
779
|
+
* 通过自己全面、全盘、深入开展梳理、研究、思考后,再合理分配相关任务给本部门
|
|
780
|
+
* 相关领域全球顶尖专家、本部门的几个组员。」
|
|
781
|
+
*
|
|
782
|
+
* 落地为两步硬流程(服务端校验,提示词绕不过):
|
|
783
|
+
* - `review`:提交「全面梳理产物 + 分工表」(问题梳理/约束/未知/思路 +
|
|
784
|
+
* 每位下级的 member/role/task/reasoningEffort);分工表必须同时含
|
|
785
|
+
* ≥1 名 expert(顶尖专家)与 ≥1 名 member(组员)。
|
|
786
|
+
* - `dispatch`:未登记 review 产物 ⇒ 硬门禁拒绝;登记后为每位下级派生
|
|
787
|
+
* 第三层子会话(叶子层,第四层被宿主绝对深度上限硬拒),推理等级按
|
|
788
|
+
* 当前模型家族合法集合(qwen→low/medium/xhigh;非qwen→low/high/max)
|
|
789
|
+
* 钳制并留痕,随 agentOptions 全程生效(要求 5)。
|
|
790
|
+
*
|
|
791
|
+
* 权限模型与 escalate 同款:注册在插件根、对所有会话可见,`execute` 内部由
|
|
792
|
+
* runtime.delegateTool 按「调用者必须是计划内某行的部门负责人子会话」硬校验。
|
|
793
|
+
*/
|
|
794
|
+
function createDelegateTool(runtime: any) {
|
|
795
|
+
return {
|
|
796
|
+
name: 'dsh_workplan_delegate',
|
|
797
|
+
description:
|
|
798
|
+
'部门负责人专用的第三层派发(用户要求 4/5):先 action="review" 提交全面梳理产物'
|
|
799
|
+
+ '(问题梳理 + 分工表:每位下级的 member/role/task/reasoningEffort,至少 1 名 expert 顶尖专家 + 1 名 member 组员),'
|
|
800
|
+
+ '再 action="dispatch" 把任务派给本部门相关领域全球顶尖专家与本部门组员(固定一层下级、叶子层,第四层一律被拒)。'
|
|
801
|
+
+ 'review 未提交前 dispatch 被硬门禁拒绝。每位下级的推理等级必须按其任务复杂度配置'
|
|
802
|
+
+ '(轻度=low;qwen 中等=medium、非 qwen 中等=high;qwen 非常复杂=xhigh、非 qwen 非常复杂=max),'
|
|
803
|
+
+ '平台按当前模型家族合法集合自动钳制越界档并留痕,等级在其任务全生命周期生效。'
|
|
804
|
+
+ 'action="status" 查看梳理登记与下级进度。',
|
|
805
|
+
parameters: {
|
|
806
|
+
type: 'object',
|
|
807
|
+
properties: {
|
|
808
|
+
action: {
|
|
809
|
+
type: 'string',
|
|
810
|
+
enum: ['review', 'dispatch', 'status'],
|
|
811
|
+
description: 'review=提交全面梳理产物与分工表;dispatch=正式派发给专家/组员;status=查看登记与进度。',
|
|
812
|
+
},
|
|
813
|
+
consolidation: {
|
|
814
|
+
type: 'object',
|
|
815
|
+
description: 'action="review" 必填:负责人「全面、全盘、深入梳理」的产物 + 第三层分工表。',
|
|
816
|
+
properties: {
|
|
817
|
+
problemAnalysis: {
|
|
818
|
+
type: 'array',
|
|
819
|
+
items: { type: 'string' },
|
|
820
|
+
description: '问题梳理(现状/事实/约束/未知/主要矛盾逐条写清),至少 1 条。',
|
|
821
|
+
},
|
|
822
|
+
constraints: { type: 'array', items: { type: 'string' }, description: '约束条件。' },
|
|
823
|
+
unknowns: { type: 'array', items: { type: 'string' }, description: '未知或待确认项。' },
|
|
824
|
+
approach: { type: 'array', items: { type: 'string' }, description: '可执行思路:每步做什么、产出什么、如何证明。' },
|
|
825
|
+
assignments: {
|
|
826
|
+
type: 'array',
|
|
827
|
+
description: '分工表:至少 1 名 expert(全球顶尖专家)+ 1 名 member(部门组员),最多 6 人。',
|
|
828
|
+
items: {
|
|
829
|
+
type: 'object',
|
|
830
|
+
properties: {
|
|
831
|
+
member: { type: 'string', description: '专家/组员的姓名或代号。' },
|
|
832
|
+
role: { type: 'string', enum: ['expert', 'member'], description: 'expert=本部门相关领域全球顶尖专家;member=本部门组员。' },
|
|
833
|
+
task: { type: 'string', description: '分配给该下级的任务(完整、自包含)。' },
|
|
834
|
+
reasoningEffort: {
|
|
835
|
+
type: 'string',
|
|
836
|
+
enum: ['low', 'medium', 'high', 'xhigh', 'max'],
|
|
837
|
+
description: '按该任务复杂度配置:轻度=low;比较复杂的任务 qwen 系=medium、非 qwen 系=high;非常复杂的任务 qwen 系=xhigh、非 qwen 系=max。越界档会被平台钳制并留痕。',
|
|
838
|
+
},
|
|
839
|
+
},
|
|
840
|
+
required: ['member', 'role', 'task'],
|
|
841
|
+
additionalProperties: false,
|
|
842
|
+
},
|
|
843
|
+
},
|
|
844
|
+
},
|
|
845
|
+
required: ['problemAnalysis', 'assignments'],
|
|
846
|
+
additionalProperties: false,
|
|
847
|
+
},
|
|
848
|
+
},
|
|
849
|
+
required: ['action'],
|
|
850
|
+
additionalProperties: false,
|
|
851
|
+
},
|
|
852
|
+
output: {
|
|
853
|
+
schema: {
|
|
854
|
+
type: 'object',
|
|
855
|
+
properties: {
|
|
856
|
+
ok: { type: 'boolean' },
|
|
857
|
+
planId: { type: 'string' },
|
|
858
|
+
subtaskId: { type: 'string' },
|
|
859
|
+
action: { type: 'string' },
|
|
860
|
+
code: { type: 'string' },
|
|
861
|
+
error: { type: 'string' },
|
|
862
|
+
hint: { type: 'string' },
|
|
863
|
+
consolidation: { type: 'object' },
|
|
864
|
+
members: { type: 'array', items: { type: 'object' } },
|
|
865
|
+
delegates: { type: 'array', items: { type: 'object' } },
|
|
866
|
+
clamped: { type: 'array', items: { type: 'object' } },
|
|
867
|
+
},
|
|
868
|
+
required: ['ok'],
|
|
869
|
+
additionalProperties: true,
|
|
870
|
+
},
|
|
871
|
+
render(_args: any, value: any) {
|
|
872
|
+
const result = isRecord(value) ? value : {}
|
|
873
|
+
if (!result.ok) {
|
|
874
|
+
return textContent(`第三层派发未执行:${String(result.error ?? result.code ?? '未知原因')}`)
|
|
875
|
+
}
|
|
876
|
+
if (result.action === 'review') {
|
|
877
|
+
const members = Array.isArray(result.members) ? result.members : []
|
|
878
|
+
const clamped = Array.isArray(result.clamped) ? result.clamped : []
|
|
879
|
+
return textContent(
|
|
880
|
+
`梳理产物已登记(${String(result.subtaskId ?? '')}):分工 ${members.length} 人`
|
|
881
|
+
+ `(expert ${members.filter((m: any) => m?.role === 'expert').length} / member ${members.filter((m: any) => m?.role === 'member').length})`
|
|
882
|
+
+ (clamped.length ? `;越界等级已钳制 ${clamped.length} 条(${clamped.map((c: any) => `${c.member}:${c.requested}→${c.corrected}`).join('、')})` : '')
|
|
883
|
+
+ '|下一步:action="dispatch" 正式派发。',
|
|
884
|
+
)
|
|
885
|
+
}
|
|
886
|
+
if (result.action === 'dispatch') {
|
|
887
|
+
const delegates = Array.isArray(result.delegates) ? result.delegates : []
|
|
888
|
+
return textContent(
|
|
889
|
+
`第三层已派发 ${delegates.length} 人:`
|
|
890
|
+
+ delegates.map((d: any) => `${d?.member ?? '?'}(${d?.role === 'expert' ? '专家' : '组员'}/${d?.effort ?? '?'}/${d?.status ?? '?'})`).join('、')
|
|
891
|
+
+ '|下级结论会送回本会话;收齐汇总核验后再写最终结果块。action="status" 可查看进度。',
|
|
892
|
+
)
|
|
893
|
+
}
|
|
894
|
+
const delegates = Array.isArray(result.delegates) ? result.delegates : []
|
|
895
|
+
return textContent(
|
|
896
|
+
`${String(result.subtaskId ?? '')} 第三层状态:梳理${result.consolidation ? '已登记' : '未登记'};下级 ${delegates.length} 人`
|
|
897
|
+
+ (delegates.length ? `(${delegates.map((d: any) => `${d?.member ?? '?'}:${d?.status ?? '?'}`).join('、')})` : '')
|
|
898
|
+
+ `|${String(result.hint ?? '')}`,
|
|
899
|
+
)
|
|
900
|
+
},
|
|
901
|
+
},
|
|
902
|
+
async execute(args: any, exec: any) {
|
|
903
|
+
const parsed = asObject(args) ?? {}
|
|
904
|
+
return runtime.delegateTool(exec.agent, parsed, exec?.signal)
|
|
905
|
+
},
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
775
909
|
/**
|
|
776
910
|
* [1.13.0] 阶段三(验证阶段)的插件核验工具(用户 2026-11-05)。
|
|
777
911
|
*
|
|
@@ -1484,6 +1618,12 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
1484
1618
|
* 侧不做过滤;权限判断一律落在 execute 内部。
|
|
1485
1619
|
*/
|
|
1486
1620
|
ctx.effect(() => ctx.tools.register(createEscalateTool(runtime)))
|
|
1621
|
+
/*
|
|
1622
|
+
* [2.3.9][T4b] 第三层派发(用户要求 4/5):与 escalate 同款权限模型——
|
|
1623
|
+
* 注册在插件根、对所有会话可见,runtime.delegateTool 内部按「调用者必须是
|
|
1624
|
+
* 计划内某行的部门负责人子会话」硬校验;根会话与第三层叶子会话都会被拒。
|
|
1625
|
+
*/
|
|
1626
|
+
ctx.effect(() => ctx.tools.register(createDelegateTool(runtime)))
|
|
1487
1627
|
/* [1.13.0] 阶段三核验:子会话唯一可用的插件工作能力,阶段一/二会被 PHASE_GATE 拒绝。 */
|
|
1488
1628
|
ctx.effect(() => ctx.tools.register(createVerifyTool(runtime)))
|
|
1489
1629
|
/* [2.0.0] 永久教训记忆的只读复核入口(阶段三验证用)。 */
|
|
@@ -1581,12 +1721,12 @@ export function apply(ctx: any, config: WorkplanConfig = {}) {
|
|
|
1581
1721
|
|
|
1582
1722
|
export const meta = {
|
|
1583
1723
|
name,
|
|
1584
|
-
version: '2.3.
|
|
1724
|
+
version: '2.3.9',
|
|
1585
1725
|
promptOrder: PROMPT_ORDER,
|
|
1586
1726
|
routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
|
|
1587
1727
|
}
|
|
1588
1728
|
|
|
1589
|
-
export { PROMPT_SECTION, createCancelTool, createDispatchTool, createEscalateTool, createHandoffTool, createInstructTool, createLessonsTool, createReplanTool, createStatusTool, createUpdateTool, plannerOutputSchema }
|
|
1729
|
+
export { PROMPT_SECTION, createCancelTool, createDelegateTool, createDispatchTool, createEscalateTool, createHandoffTool, createInstructTool, createLessonsTool, createReplanTool, createStatusTool, createUpdateTool, plannerOutputSchema }
|
|
1590
1730
|
|
|
1591
1731
|
/**
|
|
1592
1732
|
* [1.8.18] 写工具的路径级闸门(T7-N2),与 `toolGuardReason` 分开注册。
|
package/src/llm-rules.ts
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [2.3.9][T3] LLM 家族检测与推理等级约束——执行工具层。
|
|
3
|
+
*
|
|
4
|
+
* 单一事实源在 src/plan.ts(REASONING_EFFORTS 五档存储全集旁:classifyModelFamily /
|
|
5
|
+
* allowedEffortsForModel / COMPLEXITY_EFFORT_BY_FAMILY,含用户要求 1/2 原文与
|
|
6
|
+
* 「不得删档/模型未知不约束」的完整语义注释)。本模块只做两件事:
|
|
7
|
+
* 1) 转发真源符号(保持 runtime/replan/tests 的引用面稳定,兼容别名
|
|
8
|
+
* detectLlmType ≡ classifyModelFamily);
|
|
9
|
+
* 2) 提供「事前约束」需要的两个执行函数:validateReasoningEffort(集合校验,
|
|
10
|
+
* 给明确错误信息=A3 报错轨)与 correctEffortForModel(越界自动降级修正
|
|
11
|
+
* =A3 修正轨,绝不抛错中断派发)。
|
|
12
|
+
*
|
|
13
|
+
* 与 [2.2.7] 宿主能力钳制(clampEffortToSupported/resolveSupportedEfforts)的
|
|
14
|
+
* 时序关系:检测(入口) → 静态集合收窄(本模块) → 宿主能力交集钳制 → 发送;
|
|
15
|
+
* 两道闸各自留痕(U7 裁决:静态表权威 + 能力面交集钳制留痕)。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
allowedEffortsForModel,
|
|
20
|
+
classifyModelFamily,
|
|
21
|
+
defuseSessionReferenceText,
|
|
22
|
+
effortForComplexity,
|
|
23
|
+
EVIDENCE_MARKER_BEGIN,
|
|
24
|
+
EVIDENCE_MARKER_END,
|
|
25
|
+
effortsForModelFamily,
|
|
26
|
+
highestEffortOf,
|
|
27
|
+
OTHER_MODEL_EFFORTS,
|
|
28
|
+
QWEN_MODEL_EFFORTS,
|
|
29
|
+
REASONING_EFFORTS,
|
|
30
|
+
truncate,
|
|
31
|
+
type ModelFamily,
|
|
32
|
+
type TaskComplexity,
|
|
33
|
+
} from './plan.js'
|
|
34
|
+
import { threePhasePromptLines } from './three-phase.js'
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
allowedEffortsForModel,
|
|
38
|
+
classifyModelFamily,
|
|
39
|
+
effortForComplexity,
|
|
40
|
+
effortsForModelFamily,
|
|
41
|
+
highestEffortOf,
|
|
42
|
+
OTHER_MODEL_EFFORTS,
|
|
43
|
+
QWEN_MODEL_EFFORTS,
|
|
44
|
+
}
|
|
45
|
+
export type { ModelFamily, TaskComplexity }
|
|
46
|
+
/** 兼容别名:T3 计划文本中的 detectLlmType ≡ 真源 classifyModelFamily。 */
|
|
47
|
+
export const detectLlmType = classifyModelFamily
|
|
48
|
+
/** 兼容别名:T3 计划文本中的 getAllowedEffortLevels(llmType) ≡ 真源 effortsForModelFamily。 */
|
|
49
|
+
export const getAllowedEffortLevels = effortsForModelFamily
|
|
50
|
+
|
|
51
|
+
/** 校验结果:ok=在集合内;error=集合外的明确错误文案(A3 报错轨)。 */
|
|
52
|
+
export interface EffortValidation {
|
|
53
|
+
ok: boolean
|
|
54
|
+
error?: string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 集合校验(用户要求 1/2 的硬白名单判定)。
|
|
59
|
+
* @param effort 待校验档位
|
|
60
|
+
* @param allowed 等级集合(null=模型未知,不施加约束,任何值都 ok)
|
|
61
|
+
*/
|
|
62
|
+
export function validateReasoningEffort(
|
|
63
|
+
effort: unknown,
|
|
64
|
+
allowed: readonly string[] | null,
|
|
65
|
+
): EffortValidation {
|
|
66
|
+
if (allowed === null) return { ok: true }
|
|
67
|
+
if (typeof effort !== 'string' || !allowed.includes(effort)) {
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
error: `reasoningEffort "${String(effort)}" 不在当前模型家族的推理等级集合 {${allowed.join(', ')}} 内(qwen 系仅 low/medium/xhigh;非 qwen 系仅 low/high/max)——请改用集合内档位`,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { ok: true }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 自动修正结果:effort=修正后档位;adjusted=是否改动;reason=可审计留痕文案。 */
|
|
77
|
+
export interface EffortCorrection {
|
|
78
|
+
effort: string
|
|
79
|
+
adjusted: boolean
|
|
80
|
+
requested: string
|
|
81
|
+
reason?: string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 静态强度序(与 runtime.ts EFFORT_STRENGTH_ORDER 同源语义)。 */
|
|
85
|
+
const STATIC_STRENGTH_ORDER: readonly string[] = Object.freeze(
|
|
86
|
+
['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 越界自动降级修正(A3 修正轨):请求档不在家族集合内时,钳到集合内「不高于
|
|
91
|
+
* 请求档」的最近档(按强度序逐级下探:qwen 下 max→xhigh、high→medium;非 qwen
|
|
92
|
+
* 下 xhigh→high、medium→low),全部更弱则取最弱档;集合未知(模型名缺失)
|
|
93
|
+
* ⇒ 原样透传。派发绝不因档位问题中断。
|
|
94
|
+
*/
|
|
95
|
+
export function correctEffortForModel(
|
|
96
|
+
effort: string,
|
|
97
|
+
modelId?: string | null,
|
|
98
|
+
): EffortCorrection {
|
|
99
|
+
const allowed = allowedEffortsForModel(modelId)
|
|
100
|
+
if (allowed === null) return { effort, adjusted: false, requested: effort }
|
|
101
|
+
if (allowed.includes(effort)) return { effort, adjusted: false, requested: effort }
|
|
102
|
+
const rank = (id: string) => STATIC_STRENGTH_ORDER.indexOf(id)
|
|
103
|
+
const ranked = [...allowed].sort((a, b) => rank(a) - rank(b))
|
|
104
|
+
const target = rank(effort)
|
|
105
|
+
const corrected = target < 0
|
|
106
|
+
? ranked[0]
|
|
107
|
+
: (() => {
|
|
108
|
+
const atOrBelow = ranked.filter((id) => rank(id) >= 0 && rank(id) <= target)
|
|
109
|
+
return atOrBelow.length > 0 ? atOrBelow[atOrBelow.length - 1] : ranked[0]
|
|
110
|
+
})()
|
|
111
|
+
const family = classifyModelFamily(modelId)
|
|
112
|
+
return {
|
|
113
|
+
effort: corrected,
|
|
114
|
+
adjusted: true,
|
|
115
|
+
requested: effort,
|
|
116
|
+
reason: `${family === 'qwen' ? 'qwen-rule' : 'non-qwen-rule'}:${effort}→${corrected}(模型家族等级集合为 {${allowed.join(', ')}},越界档按强度序自动降级)`,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 要求 1/2 的规则全文(供 T4/T4b 部门告知注入引用同一事实源,避免文案漂移)。
|
|
122
|
+
*/
|
|
123
|
+
export const LLM_REASONING_RULES_TEXT = [
|
|
124
|
+
'1. 分配任务前先判断用户此刻使用的大模型:字母 qwen 开头的模型,推理等级只包括 low、medium、xhigh——轻度任务使用 low,比较复杂的任务使用 medium,非常复杂的任务使用 xhigh。',
|
|
125
|
+
'2. 非 qwen 开头的其他大模型,推理等级只包括 low、high、max——轻度任务使用 low,比较复杂的任务使用 high,非常复杂的任务使用 max。',
|
|
126
|
+
].join('\n')
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* [2.3.9][T4b] 部门告知块(用户强制要求 3:分配任务时必须把要求 1/2 全文告知相关部门)。
|
|
130
|
+
*
|
|
131
|
+
* 派发链路上唯一的注入事实源:二级部门任务书(buildChildPrompt 的 llmRulesBrief
|
|
132
|
+
* 参数)与三级专家/组员任务书(buildDelegateePrompt)都调用本函数生成,文案
|
|
133
|
+
* 不可能分叉。信息缺失(模型未知)时如实写明「不施加静态约束」,不编造等级集。
|
|
134
|
+
*/
|
|
135
|
+
export interface LlmRulesBriefInfo {
|
|
136
|
+
model?: string | null
|
|
137
|
+
family?: ModelFamily | null
|
|
138
|
+
allowed?: readonly string[] | null
|
|
139
|
+
effort?: string | null
|
|
140
|
+
requested?: string | null
|
|
141
|
+
correctionReason?: string | null
|
|
142
|
+
tier?: 'department' | 'delegate'
|
|
143
|
+
memberName?: string
|
|
144
|
+
memberRole?: 'expert' | 'member'
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function buildLlmRulesBrief(info: LlmRulesBriefInfo = {}): string {
|
|
148
|
+
const family = info.family ?? classifyModelFamily(info.model ?? null)
|
|
149
|
+
const allowed = info.allowed ?? allowedEffortsForModel(info.model ?? null)
|
|
150
|
+
const lines = [
|
|
151
|
+
'[2.3.9][LLM 推理等级强制规则——用户要求 1/2 全文(部门、专家、组员全员告知,必须遵守)]',
|
|
152
|
+
LLM_REASONING_RULES_TEXT,
|
|
153
|
+
`- 本会话模型:${info.model || '(未知,不施加静态等级约束)'}`
|
|
154
|
+
+ (info.model ? `(家族:${family === 'qwen' ? 'qwen 系' : '非 qwen 系'})` : '')
|
|
155
|
+
+ (allowed ? `;可用推理等级集合:{${allowed.join(', ')}}` : ''),
|
|
156
|
+
]
|
|
157
|
+
if (info.effort) {
|
|
158
|
+
const adjusted = Boolean(info.requested) && info.requested !== info.effort
|
|
159
|
+
lines.push(`- 本任务的推理等级已按任务复杂度配置为 \`${info.effort}\`,必须全程应用(开工预告、执行、验证、复盘全生命周期生效)`
|
|
160
|
+
+ (adjusted
|
|
161
|
+
? `;请求档 \`${info.requested}\` 越出当前模型家族等级集合,已按规则自动钳制修正${info.correctionReason ? `(${info.correctionReason})` : ''}。`
|
|
162
|
+
: '。'))
|
|
163
|
+
}
|
|
164
|
+
if (info.tier === 'delegate') {
|
|
165
|
+
lines.push(`- 你是部门第三层执行者(${info.memberRole === 'expert' ? '本部门相关领域全球顶尖专家' : '本部门组员'}${info.memberName ? `:${info.memberName}` : ''})。你的等级由部门负责人按你分到任务的复杂度配置并经平台按上述等级集合强制约束;越界档会被钳制并留痕。必须确保自身任务完成品质非常高的前提下,完美、超高效率地执行。`)
|
|
166
|
+
} else {
|
|
167
|
+
lines.push('- 部门负责人(本任务书的直接接收者)强制流程(用户要求 4/5):接到任务后必须先全面、全盘、深入梳理与研究,再用 dsh_workplan_delegate(action="review") 提交梳理产物(问题梳理 + 分工表 + 每位专家/组员的推理等级配置);梳理产物未提交前,dsh_workplan_delegate(action="dispatch") 会被平台拒绝(硬门禁)。梳理完成后再把任务合理分配给本部门相关领域全球顶尖专家与本部门组员;每位下级必须按自己分到任务的复杂度配置相应推理等级(轻度=low;qwen 中等=medium、非 qwen 中等=high;qwen 非常复杂=xhigh、非 qwen 非常复杂=max),全程应用;平台会按上述等级集合自动钳制越界档并留痕,等级在其任务全生命周期生效且不可被覆盖。第三层为叶子层:任何第四层派发一律被拒绝。')
|
|
168
|
+
}
|
|
169
|
+
return lines.join('\n')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* [2.3.9][T4b] 部门负责人「先全面梳理、再分配」硬门禁 + 第三层分工的纯逻辑核。
|
|
174
|
+
*
|
|
175
|
+
* 为什么放这里而不是 runtime.ts:这段判定是用户要求 4/5 的完整语义
|
|
176
|
+
* (梳理产物齐全 → 才允许派发;顶尖专家 + 至少 1 名组员 → 才算分工成立;
|
|
177
|
+
* 每位下级的推理等级 → 必须在当前模型家族等级集合内,越界按要求 1/2
|
|
178
|
+
* 自动钳制并留痕),不依赖宿主会话/子会话服务,可被 delegateTool 与测试
|
|
179
|
+
* 同口径消费——门禁不能被提示词绕过,只能被这段代码绕过,而这段代码是
|
|
180
|
+
* 唯一入口。
|
|
181
|
+
*/
|
|
182
|
+
export interface ConsolidationInput {
|
|
183
|
+
problemAnalysis?: unknown
|
|
184
|
+
constraints?: unknown
|
|
185
|
+
unknowns?: unknown
|
|
186
|
+
approach?: unknown
|
|
187
|
+
assignments?: unknown
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface DelegationAssignment {
|
|
191
|
+
member: string
|
|
192
|
+
role: 'expert' | 'member'
|
|
193
|
+
task: string
|
|
194
|
+
effort: string
|
|
195
|
+
requested?: string
|
|
196
|
+
correctionReason?: string
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface DelegationPlan {
|
|
200
|
+
ok: boolean
|
|
201
|
+
code?: string
|
|
202
|
+
error?: string
|
|
203
|
+
members: DelegationAssignment[]
|
|
204
|
+
clamped: Array<{ member: string; requested: string; corrected: string; reason: string }>
|
|
205
|
+
consolidation?: {
|
|
206
|
+
problemAnalysis: string[]
|
|
207
|
+
constraints: string[]
|
|
208
|
+
unknowns: string[]
|
|
209
|
+
approach: string[]
|
|
210
|
+
assignments: number
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const MAX_DELEGATE_MEMBERS = 6
|
|
215
|
+
|
|
216
|
+
function readTrimmedStrings(value: unknown, limit: number): string[] {
|
|
217
|
+
return (Array.isArray(value) ? value : [])
|
|
218
|
+
.map((item: any) => String(item ?? '').trim())
|
|
219
|
+
.filter(Boolean)
|
|
220
|
+
.slice(0, limit)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 梳理产物校验 + 分工表校验 + 等级钳制,三合一(一次调用给出全部拒因)。
|
|
225
|
+
* @param input.consolidation 部门负责人提交的梳理产物(review 阶段写入行,
|
|
226
|
+
* dispatch 阶段从行读回;两处都走这里,门禁与派发同一判据)
|
|
227
|
+
* @param input.model 当前会话模型 id(未知 ⇒ allowed=null ⇒ 不施加静态收窄,
|
|
228
|
+
* 但仍必须落在五档存储全集内——枚举校验永不放松)
|
|
229
|
+
*/
|
|
230
|
+
export function planDelegations(input: {
|
|
231
|
+
consolidation?: ConsolidationInput | null
|
|
232
|
+
model?: string | null
|
|
233
|
+
}): DelegationPlan {
|
|
234
|
+
const empty = { ok: false as const, code: 'DELEGATE_CONSOLIDATION_MISSING', members: [], clamped: [] }
|
|
235
|
+
const consolidation = input?.consolidation
|
|
236
|
+
if (!consolidation || typeof consolidation !== 'object') {
|
|
237
|
+
return { ...empty, error: '尚未提交「全面梳理」产物:先用 dsh_workplan_delegate(action="review") 提交问题梳理与分工表,派发才会放行(用户要求 4 的硬门禁)。' }
|
|
238
|
+
}
|
|
239
|
+
const problemAnalysis = readTrimmedStrings(consolidation.problemAnalysis, 12)
|
|
240
|
+
if (problemAnalysis.length === 0) {
|
|
241
|
+
return { ...empty, code: 'DELEGATE_CONSOLIDATION_INCOMPLETE', error: '梳理产物不完整:problemAnalysis 至少 1 条(现状/事实/约束/未知/主要矛盾逐条写清),未梳理完不得进入再分配。' }
|
|
242
|
+
}
|
|
243
|
+
const assignments = (Array.isArray(consolidation.assignments) ? consolidation.assignments : []).slice(0, MAX_DELEGATE_MEMBERS)
|
|
244
|
+
if (assignments.length === 0) {
|
|
245
|
+
return { ...empty, code: 'DELEGATE_CONSOLIDATION_INCOMPLETE', error: '梳理产物不完整:分工表 assignments 至少 1 条(member/role/task/reasoningEffort 四项齐全)。' }
|
|
246
|
+
}
|
|
247
|
+
const allowed = allowedEffortsForModel(input.model ?? null)
|
|
248
|
+
const members: DelegationAssignment[] = []
|
|
249
|
+
const clamped: DelegationPlan['clamped'] = []
|
|
250
|
+
let experts = 0
|
|
251
|
+
let regular = 0
|
|
252
|
+
for (let index = 0; index < assignments.length; index += 1) {
|
|
253
|
+
const item: any = assignments[index] ?? {}
|
|
254
|
+
const member = truncate(String(item.member ?? '').trim(), 80)
|
|
255
|
+
const role = item.role === 'expert' ? 'expert' : item.role === 'member' ? 'member' : ''
|
|
256
|
+
const task = truncate(String(item.task ?? '').trim(), 1500)
|
|
257
|
+
if (!member || !role || !task) {
|
|
258
|
+
return {
|
|
259
|
+
ok: false,
|
|
260
|
+
code: 'DELEGATE_ASSIGNMENT_INVALID',
|
|
261
|
+
members: [],
|
|
262
|
+
clamped: [],
|
|
263
|
+
error: `分工表第 ${index + 1} 条不完整:member(姓名/代号)、role(expert|member)、task(分到的任务)三者都必须非空。`,
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const requested = REASONING_EFFORTS.includes(item.reasoningEffort)
|
|
267
|
+
? String(item.reasoningEffort)
|
|
268
|
+
: (allowed === null ? 'low' : (highestEffortOf(allowed) ?? 'low'))
|
|
269
|
+
const outOfSet = allowed !== null && !allowed.includes(requested)
|
|
270
|
+
const correction = outOfSet ? correctEffortForModel(requested, input.model ?? null) : null
|
|
271
|
+
const effort = correction ? correction.effort : requested
|
|
272
|
+
if (correction) {
|
|
273
|
+
clamped.push({ member, requested, corrected: correction.effort, reason: correction.reason ?? '' })
|
|
274
|
+
}
|
|
275
|
+
if (role === 'expert') experts += 1
|
|
276
|
+
else regular += 1
|
|
277
|
+
members.push({
|
|
278
|
+
member,
|
|
279
|
+
role,
|
|
280
|
+
task,
|
|
281
|
+
effort,
|
|
282
|
+
...(outOfSet ? { requested, correctionReason: correction?.reason } : {}),
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
if (experts === 0 || regular === 0) {
|
|
286
|
+
return {
|
|
287
|
+
ok: false,
|
|
288
|
+
code: 'DELEGATE_ROLE_MIX_REQUIRED',
|
|
289
|
+
members: [],
|
|
290
|
+
clamped: [],
|
|
291
|
+
error: '分工表必须同时覆盖「本部门相关领域全球顶尖专家」与「本部门组员」(各至少 1 名,用户要求 4):当前 expert=' + experts + '、member=' + regular + '。',
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
ok: true,
|
|
296
|
+
members,
|
|
297
|
+
clamped,
|
|
298
|
+
consolidation: {
|
|
299
|
+
problemAnalysis,
|
|
300
|
+
constraints: readTrimmedStrings(consolidation.constraints, 12),
|
|
301
|
+
unknowns: readTrimmedStrings(consolidation.unknowns, 12),
|
|
302
|
+
approach: readTrimmedStrings(consolidation.approach, 12),
|
|
303
|
+
assignments: members.length,
|
|
304
|
+
},
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* [2.3.9][T4b] 第三层任务书:部门负责人 → 顶尖专家/组员子会话。
|
|
310
|
+
*
|
|
311
|
+
* 与二级任务书(buildChildPrompt)共享同一注入事实源 buildLlmRulesBrief
|
|
312
|
+
* (tier='delegate'),要求 1/2 全文与「等级全程应用、越界钳制留痕」的
|
|
313
|
+
* 口径不可能在两处漂移;叶子层禁令(不得再派生第四层)直接写进任务书,
|
|
314
|
+
* 服务端 delegateTool 另有一道硬拒——提示词说服模型,代码守住边界。
|
|
315
|
+
*/
|
|
316
|
+
export function buildDelegateePrompt(input: {
|
|
317
|
+
departmentLabel?: string
|
|
318
|
+
leaderSubtaskId?: string
|
|
319
|
+
leaderSubtaskTitle?: string
|
|
320
|
+
member: DelegationAssignment
|
|
321
|
+
rulesBrief: string
|
|
322
|
+
cwd?: string
|
|
323
|
+
leadSessionId?: string
|
|
324
|
+
extraContext?: string
|
|
325
|
+
}): string {
|
|
326
|
+
const roleLabel = input.member.role === 'expert' ? '本部门相关领域全球顶尖专家' : '本部门组员'
|
|
327
|
+
return defuseSessionReferenceText([
|
|
328
|
+
`你是「${input.departmentLabel ?? '部门'}」的${roleLabel}(${input.member.member}),由部门负责人直接分配,只负责下面这一项分配到的工作。`,
|
|
329
|
+
`负责人任务:${input.leaderSubtaskId ?? ''} ${input.leaderSubtaskTitle ?? ''}`,
|
|
330
|
+
`你的任务:${input.member.task}`,
|
|
331
|
+
`工作目录:${input.cwd || '(未知)'}`,
|
|
332
|
+
...(input.extraContext ? ['', input.extraContext] : []),
|
|
333
|
+
'',
|
|
334
|
+
input.rulesBrief,
|
|
335
|
+
'',
|
|
336
|
+
'执行要求(用户强制要求 5 原文口径):',
|
|
337
|
+
'- 你分到的推理等级已按任务复杂度配置并由平台按当前模型等级集合钳制生效:必须全程应用(规划、执行、验证、复盘全生命周期),不得自行换档。',
|
|
338
|
+
'- 必须在确保自身任务完成品质非常高的前提下,完美、超高效率地执行;严禁低效执行与浪费 token。',
|
|
339
|
+
'- 你是第三层叶子执行者:不得派生任何第四层 Agent/子会话;无法完成时在结论首行写 BLOCKED: 原因 并说明缺什么,不要空转。',
|
|
340
|
+
'- 完成后把结论与逐项证据(命令输出/文件/引用)用简洁中文回报给部门负责人会话;同时把同一份结构化结论写入 reports/wp-member-<你的成员名>-<任务代号>.json(相对工作目录,目录不存在就创建)作为结算兜底。',
|
|
341
|
+
`- 结果块契约:以 ${EVIDENCE_MARKER_BEGIN} 开头、${EVIDENCE_MARKER_END} 结尾,内含合法 JSON(status ∈ done/blocked/partial、phases 三阶段、acceptance 逐条带证据)。`,
|
|
342
|
+
'',
|
|
343
|
+
...threePhasePromptLines(),
|
|
344
|
+
].filter(Boolean).join('\n'))
|
|
345
|
+
}
|