dsh-workplan 1.11.1 → 1.12.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.
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Department capability catalog (T10 / M2).
3
+ *
4
+ * Before 1.12.0 a department was nothing but a `{zh, en}` label: the planner
5
+ * prompt listed twelve names and `validatePlan` only checked that the value was
6
+ * one of the twelve keys. Nothing described what a department is responsible
7
+ * for, what it produces, or which task vocabulary belongs to it — so "部门分配
8
+ * 是否偏离" was not a question the code could answer.
9
+ *
10
+ * This module is the single source of truth for that missing semantic layer:
11
+ *
12
+ * - `responsibilities` — what the department owns (used by the planner prompt
13
+ * and by the child-agent prompt, so a department actually changes execution);
14
+ * - `outputs` — the typical deliverables (used to explain a match);
15
+ * - `keywords` — the vocabulary that identifies the department's work. These
16
+ * are deliberately concrete nouns/verbs, not generic words, because the
17
+ * matcher must be explainable and must not fire on every task.
18
+ *
19
+ * The catalog is pure data: no model call, no I/O, no configuration. That keeps
20
+ * the audit deterministic and testable, which is exactly what the acceptance
21
+ * criterion ("分配理由可追溯、可复跑") requires.
22
+ *
23
+ * Important boundary: a match is *evidence*, not authority. The model still
24
+ * chooses the department. The runtime only uses this catalog to detect a
25
+ * contradiction that is strong enough to be worth a retry (e.g. a picture-book
26
+ * task growing a penetration-testing subtask).
27
+ */
28
+ /**
29
+ * Twelve departments, same ids and labels as `DEPARTMENTS` in plan.ts.
30
+ * A unit test asserts the two tables never drift.
31
+ */
32
+ export const DEPARTMENT_CAPABILITIES = Object.freeze([
33
+ {
34
+ id: 'engineering',
35
+ zh: '工程研发',
36
+ en: 'Engineering',
37
+ responsibilities: ['代码实现与缺陷修复', '构建、编译与静态检查', '补丁应用与回归用例'],
38
+ outputs: ['代码或补丁', '构建产物', '回归测试结果'],
39
+ keywords: [
40
+ '代码', '实现', '修复', '补丁', 'patch', 'rebase', '构建', '编译', '重构',
41
+ '函数', '接口', '模块', '依赖', '提交', '合并', '分支', 'bug', 'tsc', '单元测试',
42
+ ],
43
+ },
44
+ {
45
+ id: 'research',
46
+ zh: '研究分析',
47
+ en: 'Research',
48
+ responsibilities: ['调研与根因分析', '证据收集与交叉核对', '结论评估与方案对比'],
49
+ outputs: ['诊断报告', '证据索引', '分析与结论'],
50
+ keywords: [
51
+ '调研', '研究', '分析', '诊断', '证据', '评估', '根因', '审计', '对比',
52
+ '假设', '梳理', '阅读', '排查', '定性', '判定', '走查',
53
+ ],
54
+ },
55
+ {
56
+ id: 'design',
57
+ zh: '设计',
58
+ en: 'Design',
59
+ responsibilities: ['交互与信息架构设计', '视觉、布局与样式', '原型与可用性验证'],
60
+ outputs: ['设计稿或原型', '交互说明', '视觉规范'],
61
+ keywords: [
62
+ '设计', '交互', '视觉', '布局', '原型', '样式', '配色', 'UI', 'UX',
63
+ '截图', '红圈', '折叠', '展开', '收起', '点击', '按钮', '页面', '组件', '渲染',
64
+ ],
65
+ },
66
+ {
67
+ id: 'product',
68
+ zh: '产品',
69
+ en: 'Product',
70
+ responsibilities: ['需求澄清与范围界定', '优先级与取舍', '验收标准与用户问题'],
71
+ outputs: ['需求单', '验收标准', '决策问题单'],
72
+ keywords: [
73
+ '需求', '范围', '优先级', '验收标准', '产品', '决策', '用户问题', '方案',
74
+ '取舍', '边界', '排期', '目标',
75
+ ],
76
+ },
77
+ {
78
+ id: 'data',
79
+ zh: '数据',
80
+ en: 'Data',
81
+ responsibilities: ['数据采集与清洗', '指标定义与统计', '数据集与可复现口径'],
82
+ outputs: ['数据集', '指标表', '统计脚本'],
83
+ keywords: [
84
+ '数据', '指标', '统计', '采集', '清洗', 'CSV', '行情', '回测', '量化',
85
+ '数据集', '样本', '口径', '权重', '收益率',
86
+ ],
87
+ },
88
+ {
89
+ id: 'qa',
90
+ zh: '质量验证',
91
+ en: 'QA',
92
+ responsibilities: ['测试设计与执行', '回归与验收证据', '缺陷复现与质量门禁'],
93
+ outputs: ['测试报告', '用例集', '缺陷清单'],
94
+ keywords: [
95
+ '测试', '用例', '回归', '验收', '复现', '缺陷', '质量', '断言',
96
+ '通过率', '门禁', 'npm test', 'fail', '端到端', '推演', '演练',
97
+ ],
98
+ },
99
+ {
100
+ id: 'security',
101
+ zh: '安全',
102
+ en: 'Security',
103
+ responsibilities: ['安全审计与威胁建模', '漏洞与越权验证', '密钥与权限加固'],
104
+ outputs: ['安全报告', '漏洞清单', '加固建议'],
105
+ keywords: [
106
+ '安全', '漏洞', '渗透', '攻击', '越权', '权限', '密钥', '加密',
107
+ '威胁', '加固', '审计日志',
108
+ // [P0-1 recall] Naming an evaluation standard (ISO/IEC 15408 = CC) is a
109
+ // security ask the catalog could not see: MS2 T05-05 was planned without
110
+ // any security subtask.
111
+ 'ISO', '15408', 'CC', '等保', '安全评估',
112
+ ],
113
+ },
114
+ {
115
+ id: 'devops',
116
+ zh: '运维',
117
+ en: 'DevOps',
118
+ responsibilities: ['构建发布与制品管理', '流水线与部署', '监控与回滚'],
119
+ outputs: ['发布记录', '流水线配置', '回滚方案'],
120
+ keywords: [
121
+ '发布', '部署', '上线', 'CI', '流水线', '监控', '回滚', '镜像', '制品',
122
+ 'npm', 'registry', 'tag', 'release', 'publish', '索引源',
123
+ // [P0-1 recall] Release nouns: the Chinese word for a release tag was
124
+ // missing entirely, so MS2 T05-06 ("打 v1.5.1 标签") named devops work
125
+ // the catalog could not see.
126
+ '标签', '打标签', '发版', '打…标签',
127
+ ],
128
+ },
129
+ {
130
+ id: 'writing',
131
+ zh: '文档写作',
132
+ en: 'Writing',
133
+ responsibilities: ['文档与报告撰写', '结构、措辞与排版', '版本说明与对外文案'],
134
+ outputs: ['文档或报告', 'README 或 CHANGELOG', '对外说明'],
135
+ keywords: [
136
+ '文档', '报告', '说明', '写作', '润色', 'README', 'CHANGELOG',
137
+ '排版', '措辞', '摘要', '变更说明', '对账', '对照表', '验收表',
138
+ ],
139
+ },
140
+ {
141
+ id: 'operations',
142
+ zh: '运营',
143
+ en: 'Operations',
144
+ responsibilities: ['运营方案与活动策划', '用户增长与渠道', '客服与留存'],
145
+ outputs: ['运营方案', '活动计划', '渠道分析'],
146
+ keywords: ['运营', '活动', '增长', '渠道', '客服', '留存', '拉新', '转化'],
147
+ },
148
+ {
149
+ id: 'legal',
150
+ zh: '法务合规',
151
+ en: 'Legal',
152
+ responsibilities: ['合同与条款审查', '版权、许可与合规', '隐私与授权风险'],
153
+ outputs: ['法务意见', '合同条款', '合规清单'],
154
+ // [P0-2 recall] An evaluation/certification standard is a compliance claim,
155
+ // not just a security one: MS2 T05-05 named 「ISO/IEC 15408(CC)国际标准」
156
+ // and got legal as a single incidental hit. These add the standard-level
157
+ // wording only — no single CJK character, so 「法」 alone still matches nothing.
158
+ //
159
+ // No ordered pair here on purpose: '国际…标准' was tried and removed because it
160
+ // fires on the same span as the existing '国际标准' (「参考国际标准做一下排版」
161
+ // went from 1 hit to 2 and crossed REQUIRED_DEPARTMENT_MIN_HITS). T05-05 still
162
+ // hits 5 keywords without it.
163
+ keywords: [
164
+ '法务', '合同', '版权', '许可', '合规', '条款', '法律', '隐私', '授权', '侵权', '国际标准',
165
+ 'ISO/IEC 15408', '15408', 'ISO/IEC', 'ISO 标准', 'CC 标准',
166
+ ],
167
+ },
168
+ {
169
+ id: 'finance',
170
+ zh: '财务',
171
+ en: 'Finance',
172
+ responsibilities: ['预算与成本核算', '结算与资金管理', '财务合规与凭证'],
173
+ outputs: ['预算表', '成本核算', '结算记录'],
174
+ keywords: ['财务', '预算', '成本', '结算', '发票', '报销', '资金', '利润', '现金流'],
175
+ },
176
+ ]);
177
+ /** Departments whose domain keywords are strong enough to detect intrusion. */
178
+ export const DEPARTMENT_INTRUSION_GUARDED = Object.freeze([
179
+ 'security',
180
+ 'legal',
181
+ 'finance',
182
+ 'operations',
183
+ ]);
184
+ const CAPABILITY_MAP = Object.freeze(Object.fromEntries(DEPARTMENT_CAPABILITIES.map((entry) => [entry.id, entry])));
185
+ export const DEPARTMENT_CAPABILITY_IDS = Object.freeze(DEPARTMENT_CAPABILITIES.map((entry) => entry.id));
186
+ export function departmentCapability(id) {
187
+ if (typeof id !== 'string')
188
+ return null;
189
+ return CAPABILITY_MAP[id] ?? null;
190
+ }
191
+ /** Max characters allowed between the two halves of an ordered-pair keyword. */
192
+ const KEYWORD_PAIR_MAX_GAP = 12;
193
+ function escapeRegExp(value) {
194
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
195
+ }
196
+ /**
197
+ * Keyword match that understands the difference between a CJK substring and a
198
+ * short ASCII token. `ui` must not match inside `build`; `rebase` may match
199
+ * inside `rebased` because that is still the same concept.
200
+ */
201
+ export function keywordHit(text, keyword) {
202
+ if (typeof text !== 'string' || typeof keyword !== 'string')
203
+ return false;
204
+ const haystack = text.toLowerCase();
205
+ const needle = keyword.trim().toLowerCase();
206
+ if (!needle)
207
+ return false;
208
+ // Ordered pair ("打…标签"): CJK inserts objects between verb and noun, so a
209
+ // substring match cannot see 「打 v1.5.1 标签」. Both parts must occur in
210
+ // order and within a short window, otherwise it is not the same sentence.
211
+ if (needle.includes('…')) {
212
+ const parts = needle.split('…').filter(Boolean);
213
+ if (parts.length < 2)
214
+ return false;
215
+ let from = 0;
216
+ for (const [index, part] of parts.entries()) {
217
+ const at = haystack.indexOf(part, from);
218
+ if (at < 0)
219
+ return false;
220
+ if (index > 0 && at - from > KEYWORD_PAIR_MAX_GAP)
221
+ return false;
222
+ from = at + part.length;
223
+ }
224
+ return true;
225
+ }
226
+ if (/^[a-z0-9+#./-]+$/.test(needle) && needle.length <= 3) {
227
+ return new RegExp(`(^|[^a-z0-9])${escapeRegExp(needle)}([^a-z0-9]|$)`).test(haystack);
228
+ }
229
+ return haystack.includes(needle);
230
+ }
231
+ /** All catalog keywords of one department that occur in `text`, in catalog order. */
232
+ export function matchDepartmentKeywords(text, departmentId) {
233
+ const capability = departmentCapability(departmentId);
234
+ if (!capability)
235
+ return [];
236
+ return capability.keywords.filter((keyword) => keywordHit(text, keyword));
237
+ }
238
+ /**
239
+ * Rank every department against one piece of text.
240
+ *
241
+ * The score is the number of distinct catalog keywords found. It is a
242
+ * deliberately simple, explainable number: every point maps to a keyword the
243
+ * reader can see in the output. No weights are hidden.
244
+ */
245
+ export function scoreDepartments(text) {
246
+ return DEPARTMENT_CAPABILITIES
247
+ .map((capability) => {
248
+ const matched = capability.keywords.filter((keyword) => keywordHit(text, keyword));
249
+ return {
250
+ id: capability.id,
251
+ zh: capability.zh,
252
+ en: capability.en,
253
+ score: matched.length,
254
+ matched,
255
+ };
256
+ })
257
+ .sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
258
+ }
package/lib/host.js CHANGED
@@ -12,7 +12,7 @@ import { fileURLToPath } from 'node:url';
12
12
  * - the read-only dashboard route.
13
13
  */
14
14
  import { applyHardeningHeaders, cancelToolOutputSchema, createWorkplanRuntime, dispatchToolOutputSchema, plannerOutputSchema, replanToolOutputSchema, statusToolOutputSchema, updateToolOutputSchema, } from './runtime.js';
15
- import { isRecord } from './plan.js';
15
+ import { DEPARTMENT_IDS, isRecord } from './plan.js';
16
16
  import { autoResumeEnabledFrom } from './auto-resume.js';
17
17
  /*
18
18
  * [1.8.14] Identity of the modules this process actually loaded (N1).
@@ -234,6 +234,17 @@ function createUpdateTool(runtime) {
234
234
  type: 'string',
235
235
  description: '补充说明;会显示在任务卡片中。',
236
236
  },
237
+ /*
238
+ * [1.12.0][D-28] 结果消息指引的 `update + instruction` 必须真的能通过
239
+ * schema 校验。runtime 的 updateStatus 一直读 args.instruction,但这里
240
+ * 因 additionalProperties:false 从未声明该字段:严格宿主会直接拒绝,
241
+ * 模型只能看到「该动作不存在」。与 dsh_workplan_instruct 等价,二选一。
242
+ */
243
+ instruction: {
244
+ type: 'string',
245
+ description: '待指示项(closure=escalated)的答复文本:与 status="in_progress" 一起使用,'
246
+ + '会投递给子会话并把该行恢复为执行中。等价于 dsh_workplan_instruct。',
247
+ },
237
248
  },
238
249
  required: ['subtaskId', 'status'],
239
250
  additionalProperties: false,
@@ -323,7 +334,12 @@ function createReplanTool(runtime) {
323
334
  properties: {
324
335
  id: { type: 'string', description: '接替行 ID(默认在旧 ID 后加 b);最长 16 字符,不能与现有 ID 重复。' },
325
336
  title: { type: 'string' },
326
- department: { type: 'string' },
337
+ department: {
338
+ type: 'string',
339
+ /* [1.12.0][D-07] 与规划入口同源:模型先选合法 key,而不是先写自由文本再被运行期拒绝。 */
340
+ enum: [...DEPARTMENT_IDS],
341
+ description: '受影响的部门 key(必须是规划器枚举之一)。',
342
+ },
327
343
  role: { type: 'string' },
328
344
  objective: { type: 'string' },
329
345
  method: { type: 'array', items: { type: 'string' } },
@@ -341,7 +357,12 @@ function createReplanTool(runtime) {
341
357
  id: { type: 'string', description: '新行 ID;省略时自动生成 R<修订号>-<序号>。' },
342
358
  title: { type: 'string' },
343
359
  objective: { type: 'string' },
344
- department: { type: 'string' },
360
+ department: {
361
+ type: 'string',
362
+ /* [1.12.0][D-07] 同 replacement.department:枚举与规划入口同源。 */
363
+ enum: [...DEPARTMENT_IDS],
364
+ description: '新行所属部门 key(必须是规划器枚举之一)。',
365
+ },
345
366
  role: { type: 'string' },
346
367
  method: { type: 'array', items: { type: 'string' } },
347
368
  inputs: { type: 'array', items: { type: 'string' } },
@@ -1016,6 +1037,11 @@ export function apply(ctx, config = {}) {
1016
1037
  * 与 autoResume 用同一种写法:未配置时走默认值,而不是悄悄等于 false。
1017
1038
  */
1018
1039
  strictEvidence: strictCompletionEnabledFrom(config.strictCompletion, settingEnv('DSH_WORKPLAN_STRICT_COMPLETION')),
1040
+ /*
1041
+ * [1.12.0] 自动派发三态:显式配置 > 显式环境变量 > 默认 true。
1042
+ * 与 autoResume / strictCompletion 同一写法,避免「没配置就等于关闭」。
1043
+ */
1044
+ autoDispatch: strictCompletionEnabledFrom(config.autoDispatch, settingEnv('DSH_WORKPLAN_AUTO_DISPATCH')),
1019
1045
  });
1020
1046
  ctx.effect(() => ctx.systemPrompt.section({
1021
1047
  name: 'dsh-workplan',
@@ -1120,7 +1146,7 @@ export function apply(ctx, config = {}) {
1120
1146
  }
1121
1147
  export const meta = {
1122
1148
  name,
1123
- version: '1.11.1',
1149
+ version: '1.12.1',
1124
1150
  promptOrder: PROMPT_ORDER,
1125
1151
  routes: ['/dsh-workplan/plans', '/dsh-workplan/vendor/chart.umd.js'],
1126
1152
  };