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/src/runtime.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
blockCancelledDependents,
|
|
26
26
|
buildChildPrompt,
|
|
27
27
|
buildCancelMessage,
|
|
28
|
+
buildClarifyMessage,
|
|
28
29
|
buildDegradedMessage,
|
|
29
30
|
buildPlanMessage,
|
|
30
31
|
buildPlannerPrompt,
|
|
@@ -69,9 +70,19 @@ import {
|
|
|
69
70
|
DEPARTMENTS,
|
|
70
71
|
DEPARTMENT_IDS,
|
|
71
72
|
MAX_HANDOFF_RESPONSE_CHARS,
|
|
73
|
+
findSubtask,
|
|
72
74
|
} from './plan.js'
|
|
73
75
|
import type { PresentDenialVerdict, PresentDenyCode } from './plan.js'
|
|
74
|
-
import { compactUnderstandingAudit, validatePlanContext } from './understanding.js'
|
|
76
|
+
import { auditClarifyNeed, compactUnderstandingAudit, validatePlanContext } from './understanding.js'
|
|
77
|
+
import { phaseGateFromErrors, phaseSummaryLine, validatePhaseEvidence } from './three-phase.js'
|
|
78
|
+
import {
|
|
79
|
+
lessonStats,
|
|
80
|
+
rankLessons,
|
|
81
|
+
readLessons,
|
|
82
|
+
recordLesson,
|
|
83
|
+
renderLessonsBrief,
|
|
84
|
+
resolveLessonsFile,
|
|
85
|
+
} from './lessons.js'
|
|
75
86
|
import { computeMappingDigest, verifyMappingDigest } from './supersede-digest.js'
|
|
76
87
|
import { supersedePlanRecord } from './supersede.js'
|
|
77
88
|
import { createProgressWatchdog, describeError } from './watchdog.js'
|
|
@@ -825,11 +836,39 @@ function settleFromOutput(record: any, subtask: any, output: any, guard: Subtask
|
|
|
825
836
|
const checked = checkArtifacts(verdict.artifacts, options.cwd, options.artifactExists)
|
|
826
837
|
const escalated = verdict.status === 'blocked'
|
|
827
838
|
&& typeof verdict.question === 'string' && verdict.question.trim() !== ''
|
|
839
|
+
/*
|
|
840
|
+
* [2.0.0] 自我学习闭环的出口:完成且带复盘证据时,立刻写入永久记忆。
|
|
841
|
+
*
|
|
842
|
+
* 写入失败不改变本次判定(教训没记住是记忆层的问题,不能把已经做完的工作
|
|
843
|
+
* 判成未完成),但会把失败原因写进本条状态,避免「以为记住了其实没写」。
|
|
844
|
+
*/
|
|
845
|
+
let lessonNote = ''
|
|
846
|
+
if (verdict.status === 'done' && verdict.phases?.verification?.retrospective) {
|
|
847
|
+
try {
|
|
848
|
+
const saved = recordLesson({
|
|
849
|
+
file: resolveLessonsFile(),
|
|
850
|
+
planId: String(record.plan?.planId ?? ''),
|
|
851
|
+
subtaskId: subtask.id,
|
|
852
|
+
department: String(subtask.department ?? ''),
|
|
853
|
+
title: `${subtask.id} ${subtask.title}`,
|
|
854
|
+
cwd: typeof options.cwd === 'string' ? options.cwd : '',
|
|
855
|
+
retrospective: verdict.phases.verification.retrospective,
|
|
856
|
+
now: Date.now(),
|
|
857
|
+
})
|
|
858
|
+
if (saved) {
|
|
859
|
+
lessonNote = saved.mode === 'repeated'
|
|
860
|
+
? `已记住同类教训(第 ${saved.record.occurrences} 次,永久记忆)`
|
|
861
|
+
: '复盘已写入永久教训记忆'
|
|
862
|
+
}
|
|
863
|
+
} catch (error) {
|
|
864
|
+
lessonNote = `复盘记忆写入失败:${truncate(error instanceof Error ? error.message : String(error), 120)}`
|
|
865
|
+
}
|
|
866
|
+
}
|
|
828
867
|
writeSubtaskStatus(record, subtask.id, {
|
|
829
868
|
status: verdict.status,
|
|
830
869
|
progress: 100,
|
|
831
870
|
finishedAt: Date.now(),
|
|
832
|
-
summary: truncate(output, 3000),
|
|
871
|
+
summary: truncate(lessonNote ? `${output}\n[自我学习] ${lessonNote}` : output, 3000),
|
|
833
872
|
error: verdict.error,
|
|
834
873
|
verification: verdict.verification,
|
|
835
874
|
acceptance: verdict.acceptance,
|
|
@@ -958,6 +997,23 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
|
|
|
958
997
|
if (child.controller.signal.aborted) {
|
|
959
998
|
throw child.controller.signal.reason ?? abortError()
|
|
960
999
|
}
|
|
1000
|
+
/*
|
|
1001
|
+
* [2.0.0] 自我学习闭环的入口:把与本子任务最相关的历史教训注入提示词。
|
|
1002
|
+
*
|
|
1003
|
+
* 记忆读取失败不能影响本次派发(宁可不带教训,也不能因此不做任务),
|
|
1004
|
+
* 所以整段用 try/catch 兜底;文件不存在时 renderLessonsBrief 返回空串。
|
|
1005
|
+
*/
|
|
1006
|
+
let lessonsBrief = ''
|
|
1007
|
+
try {
|
|
1008
|
+
lessonsBrief = renderLessonsBrief({
|
|
1009
|
+
department: subtask.department,
|
|
1010
|
+
title: subtask.title,
|
|
1011
|
+
objective: subtask.objective,
|
|
1012
|
+
cwd: options.cwd,
|
|
1013
|
+
})
|
|
1014
|
+
} catch {
|
|
1015
|
+
lessonsBrief = ''
|
|
1016
|
+
}
|
|
961
1017
|
activation = await ctx.subagents.startActivation({
|
|
962
1018
|
provider: 'spawn',
|
|
963
1019
|
label: `${subtask.department}:${subtask.id} ${subtask.title}`.slice(0, 120),
|
|
@@ -990,6 +1046,7 @@ async function executeSubtask(ctx: any, record: any, stage: any, subtask: any, o
|
|
|
990
1046
|
conversationContext,
|
|
991
1047
|
statuses: record.statuses,
|
|
992
1048
|
previousFailure: attempt > 1 ? lastFailure : null,
|
|
1049
|
+
lessonsBrief,
|
|
993
1050
|
}),
|
|
994
1051
|
}],
|
|
995
1052
|
parent: options.agent,
|
|
@@ -2770,6 +2827,27 @@ export type WorkplanRuntimeOptions = {
|
|
|
2770
2827
|
* 派发)。plan 模式、已有计划执行中、预算/取消/幂等/交付门禁不受影响。
|
|
2771
2828
|
*/
|
|
2772
2829
|
autoDispatch?: boolean
|
|
2830
|
+
/**
|
|
2831
|
+
* [1.12.3] headless「未完成不得成功收尾」硬闸门(fail-closed)。
|
|
2832
|
+
*
|
|
2833
|
+
* 事故(session-99984ebd…)暴露的最后一个缺口:`agent/turn-stopping` 的
|
|
2834
|
+
* steer 每个回合最多 2 次,用尽后闸门只能沉默放行;而官方 headless runner
|
|
2835
|
+
* 的完成判据是 `turn/end reason.kind === 'completed'`,它并不认识计划,
|
|
2836
|
+
* 于是「计划未完成但回合正常收尾」= 打印正文 + exit 0,自动化仍把它当成成功。
|
|
2837
|
+
*
|
|
2838
|
+
* 语义:
|
|
2839
|
+
* - `'auto'`(默认):只在 headless 运行中启用——判据是运行上下文提供了
|
|
2840
|
+
* 官方 headless 专属服务 `headlessStartup`(packages/bundle/headless/
|
|
2841
|
+
* src/startup.ts 提供,web/tui profile 不提供)。交互式会话行为不变。
|
|
2842
|
+
* - `true` / `false`:显式打开 / 关闭。
|
|
2843
|
+
*
|
|
2844
|
+
* 启用后:steer 次数用尽而计划仍未通过交付就绪检查时,闸门抛
|
|
2845
|
+
* `PlanError('WORKPLAN_INCOMPLETE')`。官方 `agent/turn-stopping` 是 serial
|
|
2846
|
+
* 事件(cordis `serial()` 逐个 await,监听器抛错会向上传播),因此该回合以
|
|
2847
|
+
* `error` 结束;headless runner 的 `failure` 非空 ⇒ 不打印「已完成」正文、
|
|
2848
|
+
* 以非零退出码结束(packages/bundle/headless/src/index.ts 的 fail())。
|
|
2849
|
+
*/
|
|
2850
|
+
failClosedOnIncomplete?: boolean | 'auto'
|
|
2773
2851
|
/**
|
|
2774
2852
|
* [1.8.13] Package version, supplied by the host from its `meta.version`.
|
|
2775
2853
|
*
|
|
@@ -2810,6 +2888,19 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
2810
2888
|
* resume, cancel, the host's tool timeout) agrees on the same numbers.
|
|
2811
2889
|
*/
|
|
2812
2890
|
const pluginVersion = typeof options.version === 'string' && options.version ? options.version : 'unknown'
|
|
2891
|
+
/*
|
|
2892
|
+
* [1.12.3] fail-closed 解析:显式值优先;'auto' 只在 headless 运行中生效。
|
|
2893
|
+
* `ctx.get` 在普通对象(测试)上不存在,可选链保证降级为「非 headless」。
|
|
2894
|
+
*/
|
|
2895
|
+
const failClosedMode: boolean | 'auto' = options.failClosedOnIncomplete ?? 'auto'
|
|
2896
|
+
const headlessRun = (() => {
|
|
2897
|
+
try {
|
|
2898
|
+
return ctx?.get?.('headlessStartup') !== undefined
|
|
2899
|
+
} catch {
|
|
2900
|
+
return false
|
|
2901
|
+
}
|
|
2902
|
+
})()
|
|
2903
|
+
const failClosedActive = failClosedMode === true || (failClosedMode === 'auto' && headlessRun)
|
|
2813
2904
|
/*
|
|
2814
2905
|
* [1.8.14] Build identity, captured once.
|
|
2815
2906
|
*
|
|
@@ -4009,6 +4100,87 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
4009
4100
|
}
|
|
4010
4101
|
}
|
|
4011
4102
|
|
|
4103
|
+
/**
|
|
4104
|
+
* [1.13.0] 阶段三(验证阶段)的插件核验入口(用户 2026-11-05)。
|
|
4105
|
+
*
|
|
4106
|
+
* 用户规则:第一、二阶段禁用 dsh-workplan 插件,第三阶段才可以用插件验证
|
|
4107
|
+
* 是否成功、是否完全满足要求。这里的实现方式是「按提交内容判阶段」:
|
|
4108
|
+
* - 只有 planning + execution 证据齐全,才会进入阶段三核验;
|
|
4109
|
+
* - 缺 planning/execution 的调用直接以 PHASE_GATE 拒绝,并说明插件在
|
|
4110
|
+
* 阶段一、二禁用 —— 子 Agent 无法用插件跳过梳理与规划;
|
|
4111
|
+
* - 阶段三核验会逐条检查:问题梳理/可执行思路是否有实质内容、执行步骤
|
|
4112
|
+
* 是否记录、验证是否全部通过、验证记录是否覆盖全部验收标准。
|
|
4113
|
+
*
|
|
4114
|
+
* 它不写状态、不替子 Agent 宣称完成:最终是否 done 仍由 `adjudicateResult`
|
|
4115
|
+
* 对同一份 phases 再判一次,避免「核验工具说通过」与「结果块没写」两套真相。
|
|
4116
|
+
*/
|
|
4117
|
+
async function verifySubtask(agent: any, args: any) {
|
|
4118
|
+
const childSession = agent?.session
|
|
4119
|
+
if (!childSession?.id) {
|
|
4120
|
+
return { ok: false, code: 'NO_SESSION', passed: false, error: '只能在部门子会话内做阶段三核验' }
|
|
4121
|
+
}
|
|
4122
|
+
const parentId = childSession.header?.parentSession
|
|
4123
|
+
if (!parentId) {
|
|
4124
|
+
return {
|
|
4125
|
+
ok: false,
|
|
4126
|
+
code: 'NOT_CHILD_SESSION',
|
|
4127
|
+
passed: false,
|
|
4128
|
+
error: '当前不是子会话,无法反查父计划;三阶段核验只对已派发的部门子任务开放',
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4131
|
+
let record = state.records.get(parentId)
|
|
4132
|
+
if (!record?.plan) {
|
|
4133
|
+
const parent = (ctx as any).sessions?.get?.(parentId)
|
|
4134
|
+
if (parent) {
|
|
4135
|
+
try {
|
|
4136
|
+
record = reconstructFromSession(parent)
|
|
4137
|
+
} catch (error) {
|
|
4138
|
+
pushRecordError({ errors: [] } as any, error)
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
4141
|
+
}
|
|
4142
|
+
if (!record?.plan) {
|
|
4143
|
+
return { ok: false, code: 'NO_PLAN', passed: false, error: '父会话没有可关联的计划,无法核验' }
|
|
4144
|
+
}
|
|
4145
|
+
const row = (record.statuses ?? []).find((item: any) => item?.childId === childSession.id)
|
|
4146
|
+
if (!row) {
|
|
4147
|
+
return { ok: false, code: 'NO_SUBTASK', passed: false, error: '计划里找不到与本子会话关联的子任务(childId 未登记)' }
|
|
4148
|
+
}
|
|
4149
|
+
if (row.status === 'done') {
|
|
4150
|
+
return { ok: false, code: 'ALREADY_DONE', passed: false, subtaskId: row.subtaskId, error: '该子任务已标记完成,无需再次核验' }
|
|
4151
|
+
}
|
|
4152
|
+
const found = findSubtask(record.plan, row.subtaskId)
|
|
4153
|
+
const expectedAcceptance = Array.isArray(found?.subtask?.acceptance) ? found.subtask.acceptance : []
|
|
4154
|
+
const rawPhases = isRecord(args?.phases)
|
|
4155
|
+
? args.phases
|
|
4156
|
+
: { planning: args?.planning, execution: args?.execution, verification: args?.verification }
|
|
4157
|
+
const check = validatePhaseEvidence(rawPhases, expectedAcceptance)
|
|
4158
|
+
if (!check.ok || !check.phases) {
|
|
4159
|
+
const gate = phaseGateFromErrors(check.errors)
|
|
4160
|
+
return {
|
|
4161
|
+
ok: false,
|
|
4162
|
+
passed: false,
|
|
4163
|
+
code: gate === 'phase-1-2' ? 'PHASE_GATE' : 'VERIFICATION_INCOMPLETE',
|
|
4164
|
+
phase: gate,
|
|
4165
|
+
planId: record.plan.planId,
|
|
4166
|
+
subtaskId: row.subtaskId,
|
|
4167
|
+
gaps: check.errors,
|
|
4168
|
+
error: gate === 'phase-1-2'
|
|
4169
|
+
? `插件在阶段一、二禁用:先完成「梳理问题 → 形成可执行思路」并实际执行,阶段三才能用插件核验。${check.errors.slice(0, 5).join(';')}`
|
|
4170
|
+
: `阶段三核验未通过:${check.errors.slice(0, 5).join(';')}`,
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
return {
|
|
4174
|
+
ok: true,
|
|
4175
|
+
passed: true,
|
|
4176
|
+
phase: 'verification',
|
|
4177
|
+
planId: record.plan.planId,
|
|
4178
|
+
subtaskId: row.subtaskId,
|
|
4179
|
+
summary: phaseSummaryLine(check.phases),
|
|
4180
|
+
message: '插件核验通过:三阶段证据齐全、验证全部通过。现在把同一份 phases 写进结果块并提交。',
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4012
4184
|
/**
|
|
4013
4185
|
* [1.11.0] 子 → 父的唯一反向通道(T4 C-09 / T6 M5)。
|
|
4014
4186
|
*
|
|
@@ -5033,7 +5205,34 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5033
5205
|
const book = record.stopSteers && record.stopSteers.turn === turn
|
|
5034
5206
|
? record.stopSteers
|
|
5035
5207
|
: { turn, count: 0 }
|
|
5036
|
-
if (book.count >= STOP_STEER_LIMIT)
|
|
5208
|
+
if (book.count >= STOP_STEER_LIMIT) {
|
|
5209
|
+
/*
|
|
5210
|
+
* [1.12.3] steer 用尽后不再沉默放行。
|
|
5211
|
+
*
|
|
5212
|
+
* 旧行为(1.8.7–1.12.2):达到上限就 `return`,回合正常收尾。对交互式
|
|
5213
|
+
* 会话这是「避免死循环」;对 headless 却是事故复现路径——官方 runner 只
|
|
5214
|
+
* 看 `turn/end reason.kind==='completed'`,它会把「计划未完成但回合正常
|
|
5215
|
+
* 结束」打印成结果并 exit 0(session-99984ebd… 的最终现场)。
|
|
5216
|
+
*
|
|
5217
|
+
* 现在:headless(或显式开启)时抛 WORKPLAN_INCOMPLETE。turn-stopping
|
|
5218
|
+
* 是 serial 事件,抛错 ⇒ 该回合以 error 收尾 ⇒ runner 走 fail():
|
|
5219
|
+
* 不打印正文、非零退出。交互式会话维持原样(只 steer,不抛错)。
|
|
5220
|
+
*/
|
|
5221
|
+
if (failClosedActive) {
|
|
5222
|
+
const stuck = derivePlanSnapshot(record.statuses)
|
|
5223
|
+
const remaining = (stuck.statuses ?? [])
|
|
5224
|
+
.filter((item: any) => item.status !== 'done')
|
|
5225
|
+
.map((item: any) => String(item.subtaskId))
|
|
5226
|
+
throw new PlanError(
|
|
5227
|
+
`未完成:剩余 ${remaining.length} 项(${remaining.join(', ')})与原因——计划 ${record.plan.planId} `
|
|
5228
|
+
+ `仅完成 ${stuck.stats.done}/${stuck.stats.total},本回合已连续 ${book.count} 次被要求续跑/补证,`
|
|
5229
|
+
+ '仍未通过交付就绪检查。headless 以非零退出码结束,不输出「已完成」结果。',
|
|
5230
|
+
'WORKPLAN_INCOMPLETE',
|
|
5231
|
+
{ planId: record.plan.planId, stats: stuck.stats, remaining },
|
|
5232
|
+
)
|
|
5233
|
+
}
|
|
5234
|
+
return
|
|
5235
|
+
}
|
|
5037
5236
|
book.count += 1
|
|
5038
5237
|
record.stopSteers = book
|
|
5039
5238
|
const snapshot = derivePlanSnapshot(record.statuses)
|
|
@@ -5058,6 +5257,11 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5058
5257
|
+ `已在回合收尾前要求继续/如实收尾(第 ${book.count} 次)`,
|
|
5059
5258
|
)
|
|
5060
5259
|
} catch (error) {
|
|
5260
|
+
/*
|
|
5261
|
+
* [1.12.3] fail-closed 的硬失败必须穿过这层日志包装:
|
|
5262
|
+
* 这里原本把任何异常降级成一条 warn,等于把上面的抛错又吃掉。
|
|
5263
|
+
*/
|
|
5264
|
+
if (error instanceof PlanError && error.code === 'WORKPLAN_INCOMPLETE') throw error
|
|
5061
5265
|
ctx.logger?.warn?.(`dsh-workplan: 回合收尾检查失败:${error instanceof Error ? error.message : String(error)}`)
|
|
5062
5266
|
}
|
|
5063
5267
|
}
|
|
@@ -5617,6 +5821,50 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5617
5821
|
}
|
|
5618
5822
|
}
|
|
5619
5823
|
|
|
5824
|
+
/**
|
|
5825
|
+
* [2.0.0] 只读的「永久教训记忆」入口。
|
|
5826
|
+
*
|
|
5827
|
+
* 用户要求这些经验必须能被复核。主 Agent 在阶段三可以用它查:记住了什么、
|
|
5828
|
+
* 哪些同类错误在重复发生、文件到底写在哪。它只读文件,不改任何计划状态。
|
|
5829
|
+
*/
|
|
5830
|
+
async function lessonsTool(_agent: any, args: any) {
|
|
5831
|
+
const parsed = isRecord(args) ? args : {}
|
|
5832
|
+
const action = String(parsed.action ?? 'list')
|
|
5833
|
+
const file = resolveLessonsFile()
|
|
5834
|
+
try {
|
|
5835
|
+
if (action === 'stats') {
|
|
5836
|
+
return { ok: true, ...lessonStats(file) }
|
|
5837
|
+
}
|
|
5838
|
+
if (action === 'search') {
|
|
5839
|
+
const query = String(parsed.query ?? '').trim()
|
|
5840
|
+
const rows = query
|
|
5841
|
+
? readLessons(file).filter((item) =>
|
|
5842
|
+
`${item.title} ${item.problems.join(' ')} ${item.detours.join(' ')} ${item.prevention.join(' ')}`
|
|
5843
|
+
.toLowerCase()
|
|
5844
|
+
.includes(query.toLowerCase()))
|
|
5845
|
+
: readLessons(file)
|
|
5846
|
+
const limit = Math.min(Math.max(Number(parsed.limit) || 10, 1), 50)
|
|
5847
|
+
return { ok: true, file, total: rows.length, lessons: rows.slice(-limit).reverse() }
|
|
5848
|
+
}
|
|
5849
|
+
const department = typeof parsed.department === 'string' ? parsed.department.trim() : ''
|
|
5850
|
+
const limit = Math.min(Math.max(Number(parsed.limit) || 10, 1), 50)
|
|
5851
|
+
const lessons = department
|
|
5852
|
+
? readLessons(file).filter((item) => item.department === department)
|
|
5853
|
+
: readLessons(file)
|
|
5854
|
+
const ranked = department
|
|
5855
|
+
? rankLessons(lessons, { department, limit, now: Date.now() })
|
|
5856
|
+
: lessons.slice(-limit).reverse()
|
|
5857
|
+
return { ok: true, file, total: lessons.length, lessons: ranked }
|
|
5858
|
+
} catch (error) {
|
|
5859
|
+
return {
|
|
5860
|
+
ok: false,
|
|
5861
|
+
file,
|
|
5862
|
+
error: truncate(error instanceof Error ? error.message : String(error), 300),
|
|
5863
|
+
lessons: [],
|
|
5864
|
+
}
|
|
5865
|
+
}
|
|
5866
|
+
}
|
|
5867
|
+
|
|
5620
5868
|
function dispose() {
|
|
5621
5869
|
// [1.10.4] 定时器不能吊住进程,也不能在记录清空后复活一个已销毁的计划。
|
|
5622
5870
|
for (const record of state.records.values()) clearAutoResumeTimer(record, 'dispose')
|
|
@@ -5639,6 +5887,8 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5639
5887
|
statusTool,
|
|
5640
5888
|
followupTool,
|
|
5641
5889
|
escalateTool,
|
|
5890
|
+
verifyTool: verifySubtask,
|
|
5891
|
+
lessonsTool,
|
|
5642
5892
|
instructTool,
|
|
5643
5893
|
handoffTool,
|
|
5644
5894
|
replanPlan,
|
|
@@ -5649,6 +5899,15 @@ export function createWorkplanRuntime(ctx: any, options: WorkplanRuntimeOptions
|
|
|
5649
5899
|
}
|
|
5650
5900
|
}
|
|
5651
5901
|
|
|
5902
|
+
/**
|
|
5903
|
+
* [1.12.3] 澄清闸门的退出口。默认开启;只有显式设成 0/false/off 才回到旧行为
|
|
5904
|
+
* (信息不足也照做计划、照派发)。
|
|
5905
|
+
*/
|
|
5906
|
+
function clarifyGateDisabled() {
|
|
5907
|
+
const raw = String(process.env.DSH_WORKPLAN_CLARIFY_GATE ?? '').trim().toLowerCase()
|
|
5908
|
+
return raw === '0' || raw === 'false' || raw === 'off'
|
|
5909
|
+
}
|
|
5910
|
+
|
|
5652
5911
|
function resolveModelSelection(ctx: any, payload: any) {
|
|
5653
5912
|
const direct = payload.modelSelection
|
|
5654
5913
|
if (direct?.provider && direct?.model) {
|
|
@@ -5786,6 +6045,39 @@ async function maybePlan(ctx: any, state: any, payload: any, downstream: any, op
|
|
|
5786
6045
|
}
|
|
5787
6046
|
return downstream
|
|
5788
6047
|
}
|
|
6048
|
+
/*
|
|
6049
|
+
* [1.12.3] 信息不足就不做计划、不派发——只问一句。
|
|
6050
|
+
*
|
|
6051
|
+
* 用户在 2026-11-04 拍板:自动派发改成「只在信息不足这一类上拦截」,其余照旧。
|
|
6052
|
+
* 因此拦截点放在规划之前,而不是关掉自动派发:缺信息时连计划都不生成,
|
|
6053
|
+
* 免得部门 Agent 对着一个猜出来的目标开工。
|
|
6054
|
+
* 关闭方式:DSH_WORKPLAN_CLARIFY_GATE=0(保留给需要旧行为的自动化)。
|
|
6055
|
+
*/
|
|
6056
|
+
if (!clarifyGateDisabled()) {
|
|
6057
|
+
const clarify = auditClarifyNeed(taskText, conversationContext)
|
|
6058
|
+
if (clarify.needed) {
|
|
6059
|
+
const createdAt = Date.now()
|
|
6060
|
+
state.records.set(session.id, {
|
|
6061
|
+
planId: null,
|
|
6062
|
+
plan: null,
|
|
6063
|
+
title: '任务信息不足(先澄清)',
|
|
6064
|
+
degraded: false,
|
|
6065
|
+
clarify: true,
|
|
6066
|
+
error: clarify.reason,
|
|
6067
|
+
statuses: [],
|
|
6068
|
+
phase: 'clarify',
|
|
6069
|
+
errors: [truncate(clarify.reason, 1000)],
|
|
6070
|
+
createdAt,
|
|
6071
|
+
updatedAt: createdAt,
|
|
6072
|
+
createdTurn: payload.turn,
|
|
6073
|
+
})
|
|
6074
|
+
return enterDecision(downstream, [buildClarifyMessage({
|
|
6075
|
+
rule: clarify.rule,
|
|
6076
|
+
reason: clarify.reason,
|
|
6077
|
+
question: clarify.question,
|
|
6078
|
+
})])
|
|
6079
|
+
}
|
|
6080
|
+
}
|
|
5789
6081
|
const modelSelection = resolveModelSelection(ctx, payload)
|
|
5790
6082
|
if (!modelSelection?.provider || !modelSelection?.model) {
|
|
5791
6083
|
const message = buildDegradedMessage({
|