@twinsearth/dsh-fang 3.2.1 → 3.2.2
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/client.js +40 -18
- package/package.json +1 -1
- package/src/kernel/types.mjs +1 -1
- package/src/lib/decision-policy.mjs +22 -4
- package/src/plugins/decision-center.mjs +72 -12
package/client.js
CHANGED
|
@@ -1269,6 +1269,7 @@ window.__ModuleLoader__.load({
|
|
|
1269
1269
|
.fang-inbox-item-actions .fang-inbox-btn{height:24px;padding:0 7px;font-size:11.5px}
|
|
1270
1270
|
.fang-inbox-ai-advice{font-size:11.5px;color:#0857B8;background:rgba(10,107,224,.06);border-radius:6px;padding:4px 6px;margin-top:4px;white-space:pre-wrap}
|
|
1271
1271
|
.fang-inbox-empty{padding:28px 16px;text-align:center;color:#86868B;font-size:12px}
|
|
1272
|
+
.fang-inbox-empty-group{padding:10px 12px;color:#86868B;font-size:11.5px;background:rgba(127,127,127,.03)}
|
|
1272
1273
|
.fang-inbox-err{margin:8px 10px;padding:8px 10px;border-radius:8px;background:rgba(200,16,46,.07);color:#C8102E;font-size:12px}
|
|
1273
1274
|
.fang-inbox-seat{display:inline-flex;align-items:center;justify-content:center;position:relative;width:28px;height:28px;border:0;border-radius:8px;background:transparent;color:inherit;cursor:pointer}
|
|
1274
1275
|
.fang-inbox-seat:hover{background:rgba(127,127,127,.1)}
|
|
@@ -3705,10 +3706,10 @@ window.__ModuleLoader__.load({
|
|
|
3705
3706
|
collapsed: new Set(['green', 'gray']),
|
|
3706
3707
|
}
|
|
3707
3708
|
const LEVELS_MINI = [
|
|
3708
|
-
{ level: 'red', label: '红色 ·
|
|
3709
|
-
{ level: 'yellow', label: '黄色', tone: 'yellow' },
|
|
3710
|
-
{ level: 'blue', label: '蓝色', tone: 'blue' },
|
|
3711
|
-
{ level: 'green', label: '绿色', tone: 'green' },
|
|
3709
|
+
{ level: 'red', label: '红色 · P0/高', tone: 'red' },
|
|
3710
|
+
{ level: 'yellow', label: '黄色 · P1/中', tone: 'yellow' },
|
|
3711
|
+
{ level: 'blue', label: '蓝色 · P2/低', tone: 'blue' },
|
|
3712
|
+
{ level: 'green', label: '绿色 · P3/信息', tone: 'green' },
|
|
3712
3713
|
{ level: 'gray', label: '灰色归档', tone: 'gray' },
|
|
3713
3714
|
]
|
|
3714
3715
|
const remaining = (expiresAt) => {
|
|
@@ -3783,8 +3784,8 @@ window.__ModuleLoader__.load({
|
|
|
3783
3784
|
else if (state.error) body.append(h('div', { class: 'notice notice--bad', role: 'alert' }, '决策中心不可用:' + failureHint(state.error)))
|
|
3784
3785
|
else {
|
|
3785
3786
|
for (const meta of LEVELS_MINI) {
|
|
3787
|
+
// v3.2.2:右栏也常驻五组,0 条也显示等级与优先级/风险说明。
|
|
3786
3788
|
const items = itemsFor(meta.level)
|
|
3787
|
-
if (!items.length) continue
|
|
3788
3789
|
const collapsed = state.collapsed.has(meta.level)
|
|
3789
3790
|
const group = h('div', { class: 'fang-decision-mini-group', 'data-level': meta.level },
|
|
3790
3791
|
h('button', {
|
|
@@ -3798,6 +3799,7 @@ window.__ModuleLoader__.load({
|
|
|
3798
3799
|
}, h('b', null, meta.label), h('span', null, `${items.length} 项 · ${collapsed ? '展开' : '收起'}`)))
|
|
3799
3800
|
if (!collapsed) {
|
|
3800
3801
|
const list = h('div', { class: 'fang-decision-mini-list' })
|
|
3802
|
+
if (!items.length) list.append(h('div', { class: 'fang-inbox-empty-group', 'data-empty-level': meta.level }, `暂无${meta.label}记录`))
|
|
3801
3803
|
for (const item of items.slice(0, 30)) {
|
|
3802
3804
|
const actions = h('div', { class: 'fang-decision-mini-actions' })
|
|
3803
3805
|
for (const option of (item.options || []).slice(0, 4)) {
|
|
@@ -3815,7 +3817,7 @@ window.__ModuleLoader__.load({
|
|
|
3815
3817
|
}
|
|
3816
3818
|
list.append(h('div', { class: 'fang-decision-mini-item', 'data-inbox-id': item.id, 'data-level': item.level },
|
|
3817
3819
|
h('div', { class: 'fang-decision-mini-title' }, inboxText(item.title) || item.id),
|
|
3818
|
-
h('div', { class: 'fang-decision-mini-meta' }, `${sourceLabel(item)} · ${miniDecisionState(item)}`),
|
|
3820
|
+
h('div', { class: 'fang-decision-mini-meta' }, `${sourceLabel(item)} · ${miniDecisionState(item)} · ${item.priority || DECISION_PRIORITY_RISK[item.level]?.priority || '—'} · 风险 ${DECISION_RISK_LABEL[item.risk || DECISION_PRIORITY_RISK[item.level]?.risk] || '—'}`),
|
|
3819
3821
|
item.context ? h('div', { class: 'fang-decision-mini-context' }, inboxText(item.context, 240)) : null,
|
|
3820
3822
|
actions))
|
|
3821
3823
|
}
|
|
@@ -5047,12 +5049,20 @@ window.__ModuleLoader__.load({
|
|
|
5047
5049
|
/** 插件 apply 时注入;主面板 Header 用它兜底打开收件箱(侧栏 Slot 不可用时)。 */
|
|
5048
5050
|
let openInboxExternally = null
|
|
5049
5051
|
const INBOX_LEVELS = Object.freeze([
|
|
5050
|
-
{ level: 'red', label: '紧急决策', hint: '
|
|
5051
|
-
{ level: 'yellow', label: '建议决策', hint: '
|
|
5052
|
-
{ level: 'blue', label: '日常建议', hint: '
|
|
5053
|
-
{ level: 'green', label: '通知与汇报', hint: '
|
|
5052
|
+
{ level: 'red', label: '紧急决策', hint: 'P0 · 高风险 · 阻塞 Agent' },
|
|
5053
|
+
{ level: 'yellow', label: '建议决策', hint: 'P1 · 中风险 · 3 分钟后继续可补选' },
|
|
5054
|
+
{ level: 'blue', label: '日常建议', hint: 'P2 · 低风险 · 1 分钟后按推荐执行' },
|
|
5055
|
+
{ level: 'green', label: '通知与汇报', hint: 'P3 · 信息 · 自动执行留底' },
|
|
5054
5056
|
{ level: 'gray', label: '已归档 / 过期', hint: '只读' },
|
|
5055
5057
|
])
|
|
5058
|
+
const DECISION_PRIORITY_RISK = Object.freeze({
|
|
5059
|
+
red: { priority: 'P0', risk: 'high' },
|
|
5060
|
+
yellow: { priority: 'P1', risk: 'medium' },
|
|
5061
|
+
blue: { priority: 'P2', risk: 'low' },
|
|
5062
|
+
green: { priority: 'P3', risk: 'info' },
|
|
5063
|
+
gray: { priority: '—', risk: 'info' },
|
|
5064
|
+
})
|
|
5065
|
+
const DECISION_RISK_LABEL = Object.freeze({ high: '高', medium: '中', low: '低', info: '信息' })
|
|
5056
5066
|
const INBOX_POLL_MS = 5000
|
|
5057
5067
|
const inboxText = (value, max = 420) => {
|
|
5058
5068
|
const text = String(value ?? '').trim()
|
|
@@ -5861,7 +5871,15 @@ window.__ModuleLoader__.load({
|
|
|
5861
5871
|
class: 'chip', style: { marginLeft: 6, fontSize: 10 },
|
|
5862
5872
|
title: `注意力配额不足(${item.attentionQuota?.scope === 'source' ? '来源' : '全库'} ${item.attentionQuota?.used ?? '?'}/${item.attentionQuota?.limit ?? '?'}),已降一级`,
|
|
5863
5873
|
}, '注意力降级')
|
|
5864
|
-
: null
|
|
5874
|
+
: null,
|
|
5875
|
+
(() => {
|
|
5876
|
+
const defaults = DECISION_PRIORITY_RISK[item.level] || DECISION_PRIORITY_RISK.gray
|
|
5877
|
+
const priority = item.priority || defaults.priority
|
|
5878
|
+
const risk = item.risk || defaults.risk
|
|
5879
|
+
return h('span', { style: { marginLeft: 6, display: 'inline-flex', gap: 4, verticalAlign: 'middle' } },
|
|
5880
|
+
h('span', { class: 'chip', 'data-decision-priority': priority, title: '优先级' }, priority),
|
|
5881
|
+
h('span', { class: 'chip', 'data-decision-risk': risk, title: '风险程度' }, `风险 ${DECISION_RISK_LABEL[risk] || risk}`))
|
|
5882
|
+
})()),
|
|
5865
5883
|
item.context ? h('div', { class: 'fang-inbox-item-context' }, inboxText(item.context)) : null,
|
|
5866
5884
|
h('div', { class: 'fang-inbox-meta' }, `${sourceText(item)} · ${fmtRelative(item.createdAt)}${item.expiresAt ? ' · 到期 ' + fmtRelative(item.expiresAt) : ''}`),
|
|
5867
5885
|
h('div', {
|
|
@@ -5965,7 +5983,7 @@ window.__ModuleLoader__.load({
|
|
|
5965
5983
|
const pendingDelta = Number(b.status === 'pending') - Number(a.status === 'pending')
|
|
5966
5984
|
return pendingDelta || Number(b.createdAt || 0) - Number(a.createdAt || 0)
|
|
5967
5985
|
})
|
|
5968
|
-
|
|
5986
|
+
// v3.2.2:四种颜色分组常驻显示(0 条也给入口),避免“没有记录就完全看不到该等级”。
|
|
5969
5987
|
const collapsed = state.collapsed.has(level)
|
|
5970
5988
|
const unread = archived ? 0 : items.filter(item => item.status === 'pending').length
|
|
5971
5989
|
const pendingItems = items.filter(item => item.status === 'pending')
|
|
@@ -5999,7 +6017,9 @@ window.__ModuleLoader__.load({
|
|
|
5999
6017
|
h('b', null, levelMeta.label),
|
|
6000
6018
|
h('span', { style: { fontSize: 11, color: 'inherit', opacity: .8 } }, levelMeta.hint),
|
|
6001
6019
|
h('span', { class: 'n' }, `${unread} 项 · ${collapsed ? '展开' : '收起'}`))),
|
|
6002
|
-
collapsed ? null :
|
|
6020
|
+
collapsed ? null : (items.length
|
|
6021
|
+
? h('div', { role: 'list' }, ...items.slice(0, archived ? 80 : 200).map(item => itemNode(item, archived || item.status !== 'pending')))
|
|
6022
|
+
: h('div', { class: 'fang-inbox-empty-group', 'data-empty-level': level }, `暂无${levelMeta.label}记录`)))
|
|
6003
6023
|
}
|
|
6004
6024
|
|
|
6005
6025
|
/** 批量确认弹窗:返回 Promise<boolean>;Esc/取消/点遮罩 = false。 */
|
|
@@ -6081,13 +6101,15 @@ window.__ModuleLoader__.load({
|
|
|
6081
6101
|
if (state.state === 'loading' && !state.items.length) body.append(h('div', { class: 'fang-inbox-empty' }, icon('spinner', 16), ' 正在读取收件箱…'))
|
|
6082
6102
|
else if (state.state === 'error' && !state.items.length) {
|
|
6083
6103
|
body.append(h('div', { class: 'fang-inbox-err', role: 'alert' }, `收件箱不可用:${failureHint(state.error || 'network')}`))
|
|
6084
|
-
} else if (!state.items.length) {
|
|
6085
|
-
body.append(h('div', { class: 'fang-inbox-empty' },
|
|
6086
|
-
'收件箱是空的。', h('br'), '决策中心创建的红/黄/蓝/绿 ticket 会出现在这里。'))
|
|
6087
6104
|
} else {
|
|
6105
|
+
if (!state.items.length) {
|
|
6106
|
+
body.append(h('div', { class: 'fang-inbox-empty' },
|
|
6107
|
+
'收件箱是空的;四个等级的分组仍然保留,用于确认决策中心可用。', h('br'),
|
|
6108
|
+
'红=P0/高,黄=P1/中,蓝=P2/低,绿=P3/信息。'))
|
|
6109
|
+
}
|
|
6110
|
+
// v3.2.2:分组常驻(含 0 条),不再因为无记录而整组消失。
|
|
6088
6111
|
for (const meta of INBOX_LEVELS) {
|
|
6089
|
-
|
|
6090
|
-
if (node) body.append(node)
|
|
6112
|
+
body.append(groupNode(meta))
|
|
6091
6113
|
}
|
|
6092
6114
|
}
|
|
6093
6115
|
if (state.error && state.items.length) body.prepend(h('div', { class: 'fang-inbox-err', role: 'status' }, `刷新失败:${failureHint(state.error)}(显示上次结果)`))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/dsh-fang",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "dsh-Fang (瓮城) — mother/fork plugin development environment for DeepSeek Harness: one readonly mother, a disposable child dsh-Web per task.",
|
package/src/kernel/types.mjs
CHANGED
|
@@ -4,12 +4,30 @@
|
|
|
4
4
|
// v3.2.0 四色决策状态机(唯一事实来源)。
|
|
5
5
|
// `expiresAt` 是归档期限;`waitDeadlineAt` 只是 Agent 的流程等待窗口,二者不可混用。
|
|
6
6
|
export const DECISION_LEVEL_POLICY = Object.freeze({
|
|
7
|
-
red: Object.freeze({ waitMode: 'human', graceMs: null, afterWait: 'keep-waiting', label: '必须人工选择' }),
|
|
8
|
-
yellow: Object.freeze({ waitMode: 'grace-defer', graceMs: 3 * 60_000, afterWait: 'defer', label: '3 分钟后继续,可补选' }),
|
|
9
|
-
blue: Object.freeze({ waitMode: 'grace-recommended', graceMs: 60_000, afterWait: 'recommended', label: '1 分钟后按推荐执行' }),
|
|
10
|
-
green: Object.freeze({ waitMode: 'immediate', graceMs: 0, afterWait: 'recommended', label: '自动执行并留底' }),
|
|
7
|
+
red: Object.freeze({ waitMode: 'human', graceMs: null, afterWait: 'keep-waiting', label: '必须人工选择', priority: 'P0', risk: 'high' }),
|
|
8
|
+
yellow: Object.freeze({ waitMode: 'grace-defer', graceMs: 3 * 60_000, afterWait: 'defer', label: '3 分钟后继续,可补选', priority: 'P1', risk: 'medium' }),
|
|
9
|
+
blue: Object.freeze({ waitMode: 'grace-recommended', graceMs: 60_000, afterWait: 'recommended', label: '1 分钟后按推荐执行', priority: 'P2', risk: 'low' }),
|
|
10
|
+
green: Object.freeze({ waitMode: 'immediate', graceMs: 0, afterWait: 'recommended', label: '自动执行并留底', priority: 'P3', risk: 'info' }),
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
+
export const DECISION_PRIORITIES = Object.freeze(['P0', 'P1', 'P2', 'P3'])
|
|
14
|
+
export const DECISION_RISKS = Object.freeze(['high', 'medium', 'low', 'info'])
|
|
15
|
+
|
|
16
|
+
/** 调用方可以覆盖默认优先级/风险(例如低等级但高风险的安全票)。 */
|
|
17
|
+
export function normalizeDecisionPriority(value, level) {
|
|
18
|
+
const raw = String(value ?? '').trim().toUpperCase()
|
|
19
|
+
if (DECISION_PRIORITIES.includes(raw)) return raw
|
|
20
|
+
return decisionPolicy(level).priority
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function normalizeDecisionRisk(value, level) {
|
|
24
|
+
const raw = String(value ?? '').trim().toLowerCase()
|
|
25
|
+
const alias = { critical: 'high', high: 'high', medium: 'medium', med: 'medium', low: 'low', info: 'info', none: 'info' }
|
|
26
|
+
const mapped = alias[raw]
|
|
27
|
+
if (mapped) return mapped
|
|
28
|
+
return decisionPolicy(level).risk
|
|
29
|
+
}
|
|
30
|
+
|
|
13
31
|
export function decisionPolicy(level) {
|
|
14
32
|
return DECISION_LEVEL_POLICY[level] ?? DECISION_LEVEL_POLICY.yellow
|
|
15
33
|
}
|
|
@@ -34,7 +34,16 @@ import { createAiSecretStore } from '../lib/ai-secret-store.mjs'
|
|
|
34
34
|
import { createDecisionOutbox, resolveMotherTarget } from '../lib/decision-outbox.mjs'
|
|
35
35
|
import { producerCatalog } from '../lib/producer-contract.mjs'
|
|
36
36
|
import { assertEndpointSafe, classifyEndpointHost } from '../lib/ssrf-guard.mjs'
|
|
37
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
DECISION_LEVEL_POLICY,
|
|
39
|
+
DECISION_PRIORITIES,
|
|
40
|
+
DECISION_RISKS,
|
|
41
|
+
decisionPolicy,
|
|
42
|
+
decisionWaitMs,
|
|
43
|
+
normalizeDecisionPriority,
|
|
44
|
+
normalizeDecisionRisk,
|
|
45
|
+
recommendedDecisionOption,
|
|
46
|
+
} from '../lib/decision-policy.mjs'
|
|
38
47
|
|
|
39
48
|
export const name = 'fang-decision-center'
|
|
40
49
|
export const inject = []
|
|
@@ -76,7 +85,8 @@ export const PM_DECISION_POLICY = Object.freeze({
|
|
|
76
85
|
'一次只问一个决定点,问题要具体到「选哪个」或「能不能做」',
|
|
77
86
|
'必须给出 2-4 个可执行选项,推荐项放第一个并把标签后缀 "(推荐)"',
|
|
78
87
|
'context 里写清:为什么需要人决定、每个选项的代价与风险、不决定的后果',
|
|
79
|
-
'red
|
|
88
|
+
'red 只用于真正阻塞(人不在就没法继续);yellow 用于影响方向/进度的建议(3 分钟后继续但可补选);blue 用于低风险日常建议(1 分钟后按推荐执行);green 用于阶段完成/自动执行留底(不提醒)',
|
|
89
|
+
'优先级与风险默认随等级:red=P0/high,yellow=P1/medium,blue=P2/low,green=P3/info;确实不符时显式传 priority/risk 覆盖',
|
|
80
90
|
'绝对不要因为「不确定」而把问题原样抛回给开发者——先把能自己查的查清',
|
|
81
91
|
],
|
|
82
92
|
})
|
|
@@ -306,6 +316,9 @@ function publicTicket(ticket) {
|
|
|
306
316
|
autoReason: ticket.autoReason ?? null,
|
|
307
317
|
lateResponse: ticket.lateResponse === true,
|
|
308
318
|
policyTimeoutMs: ticket.policyTimeoutMs ?? null,
|
|
319
|
+
// v3.2.2:优先级与风险程度是正式字段,默认由等级推导,调用方可覆盖。
|
|
320
|
+
priority: ticket.priority ?? decisionPolicy(ticket.level).priority,
|
|
321
|
+
risk: ticket.risk ?? decisionPolicy(ticket.level).risk,
|
|
309
322
|
}
|
|
310
323
|
}
|
|
311
324
|
|
|
@@ -393,7 +406,9 @@ function applyForkDecisionCenter(ctx, config, gate) {
|
|
|
393
406
|
type: 'object',
|
|
394
407
|
additionalProperties: false,
|
|
395
408
|
properties: {
|
|
396
|
-
level: { type: 'string', enum: ['red', 'yellow', 'blue', 'green'], description: '
|
|
409
|
+
level: { type: 'string', enum: ['red', 'yellow', 'blue', 'green'], description: '注意力等级;默认优先级/风险:红=P0/high,黄=P1/medium,蓝=P2/low,绿=P3/info' },
|
|
410
|
+
priority: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'], description: '可选:覆盖默认优先级' },
|
|
411
|
+
risk: { type: 'string', enum: ['high', 'medium', 'low', 'info'], description: '可选:覆盖默认风险' },
|
|
397
412
|
title: { type: 'string' },
|
|
398
413
|
context: { type: 'string' },
|
|
399
414
|
options: {
|
|
@@ -445,6 +460,7 @@ function applyForkDecisionCenter(ctx, config, gate) {
|
|
|
445
460
|
ticketId: ticket.id, level: ticket.level, blocking: false,
|
|
446
461
|
status: 'pending', outcome: 'deferred', deferred: true,
|
|
447
462
|
continueWithoutDecision: true, canAnswerLater: true, queued: false,
|
|
463
|
+
priority: ticket.priority, risk: ticket.risk,
|
|
448
464
|
}
|
|
449
465
|
}
|
|
450
466
|
throw new Error(`fork 决策未在时限内完成(${settled.reason})`)
|
|
@@ -456,6 +472,7 @@ function applyForkDecisionCenter(ctx, config, gate) {
|
|
|
456
472
|
status: 'pending', outcome: 'deferred', deferred: true,
|
|
457
473
|
continueWithoutDecision: true, canAnswerLater: true,
|
|
458
474
|
deferredAt: resolved.deferredAt ?? undefined, queued: false,
|
|
475
|
+
priority: resolved.priority, risk: resolved.risk,
|
|
459
476
|
}
|
|
460
477
|
}
|
|
461
478
|
if (resolved.status !== 'resolved' && resolved.status !== 'abandoned' && resolved.status !== 'expired' && resolved.status !== 'acked') {
|
|
@@ -468,6 +485,7 @@ function applyForkDecisionCenter(ctx, config, gate) {
|
|
|
468
485
|
selectedActionId: resolved.selectedActionId ?? undefined,
|
|
469
486
|
autoResolved: resolved.autoResolved === true,
|
|
470
487
|
autoReason: resolved.autoReason ?? undefined,
|
|
488
|
+
priority: resolved.priority, risk: resolved.risk,
|
|
471
489
|
queued: false,
|
|
472
490
|
}
|
|
473
491
|
}
|
|
@@ -1154,6 +1172,8 @@ export function apply(ctx, config) {
|
|
|
1154
1172
|
autoReason: null,
|
|
1155
1173
|
lateResponse: false,
|
|
1156
1174
|
policyTimeoutMs,
|
|
1175
|
+
priority: normalizeDecisionPriority(raw.priority, level),
|
|
1176
|
+
risk: normalizeDecisionRisk(raw.risk, level),
|
|
1157
1177
|
}
|
|
1158
1178
|
ticket.rev = nextRevision()
|
|
1159
1179
|
tickets.set(ticket.id, ticket)
|
|
@@ -1297,6 +1317,8 @@ export function apply(ctx, config) {
|
|
|
1297
1317
|
autoReason: item.autoReason ?? null,
|
|
1298
1318
|
lateResponse: item.lateResponse === true,
|
|
1299
1319
|
policyTimeoutMs: Number(item.policyTimeoutMs) || null,
|
|
1320
|
+
priority: normalizeDecisionPriority(item.priority, normalizeLevel(item.level, 'gray')),
|
|
1321
|
+
risk: normalizeDecisionRisk(item.risk, normalizeLevel(item.level, 'gray')),
|
|
1300
1322
|
}
|
|
1301
1323
|
if (ticket.status === 'pending') {
|
|
1302
1324
|
// v3.1.24:进程重启后 pending 仍保留给人回答(浮窗/收件箱可见),
|
|
@@ -2232,6 +2254,8 @@ export function apply(ctx, config) {
|
|
|
2232
2254
|
statuses: [...STATUSES],
|
|
2233
2255
|
blockingLevels: [...BLOCKING_LEVELS],
|
|
2234
2256
|
levelPolicies: DECISION_LEVEL_POLICY,
|
|
2257
|
+
priorities: [...DECISION_PRIORITIES],
|
|
2258
|
+
risks: [...DECISION_RISKS],
|
|
2235
2259
|
maxTickets: cfg.maxTickets,
|
|
2236
2260
|
maxPendingRed: cfg.maxPendingRed,
|
|
2237
2261
|
defaultTimeoutMinutes: cfg.defaultTimeoutMinutes,
|
|
@@ -2286,12 +2310,14 @@ export function apply(ctx, config) {
|
|
|
2286
2310
|
if (!tools || typeof tools.register !== 'function') return
|
|
2287
2311
|
const unregister = tools.register({
|
|
2288
2312
|
name: 'request_human_decision',
|
|
2289
|
-
description: '当需要人类授权、选择方案、或汇报重要结果时,创建一张决策中心 ticket
|
|
2313
|
+
description: '当需要人类授权、选择方案、或汇报重要结果时,创建一张决策中心 ticket。红色强制等待人工(P0/高);黄色最多等 3 分钟后继续且可补选(P1/中);蓝色最多等 1 分钟后按推荐自动执行(P2/低);绿色自动执行并留底(P3/信息)。必须按风险选等级,不要全部用红色。\n' + PM_PROACTIVE_HINT,
|
|
2290
2314
|
parameters: {
|
|
2291
2315
|
type: 'object',
|
|
2292
2316
|
additionalProperties: false,
|
|
2293
2317
|
properties: {
|
|
2294
|
-
level: { type: 'string', enum: ['red', 'yellow', 'blue', 'green'], description: '
|
|
2318
|
+
level: { type: 'string', enum: ['red', 'yellow', 'blue', 'green'], description: '注意力等级(默认优先级/风险:红=P0/high,黄=P1/medium,蓝=P2/low,绿=P3/info);red 会阻塞 Agent' },
|
|
2319
|
+
priority: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'], description: '可选:覆盖等级默认优先级' },
|
|
2320
|
+
risk: { type: 'string', enum: ['high', 'medium', 'low', 'info'], description: '可选:覆盖等级默认风险程度' },
|
|
2295
2321
|
title: { type: 'string', description: '一句话标题' },
|
|
2296
2322
|
context: { type: 'string', description: '为什么需要人类介入' },
|
|
2297
2323
|
options: {
|
|
@@ -2329,6 +2355,11 @@ export function apply(ctx, config) {
|
|
|
2329
2355
|
outcome: { type: 'string' },
|
|
2330
2356
|
selectedValue: { type: 'string' },
|
|
2331
2357
|
selectedActionId: { type: 'string' },
|
|
2358
|
+
priority: { type: 'string' },
|
|
2359
|
+
risk: { type: 'string' },
|
|
2360
|
+
autoResolved: { type: 'boolean' },
|
|
2361
|
+
lateResponse: { type: 'boolean' },
|
|
2362
|
+
continueWithoutDecision: { type: 'boolean' },
|
|
2332
2363
|
},
|
|
2333
2364
|
},
|
|
2334
2365
|
render(_args, value) {
|
|
@@ -2370,6 +2401,7 @@ export function apply(ctx, config) {
|
|
|
2370
2401
|
status: 'pending', outcome: 'deferred', deferred: true,
|
|
2371
2402
|
continueWithoutDecision: true, canAnswerLater: true,
|
|
2372
2403
|
deferredAt: result.deferredAt ?? undefined,
|
|
2404
|
+
priority: result.priority, risk: result.risk,
|
|
2373
2405
|
}
|
|
2374
2406
|
}
|
|
2375
2407
|
if (outcome !== 'resolved' && outcome !== 'acked') {
|
|
@@ -2384,6 +2416,7 @@ export function apply(ctx, config) {
|
|
|
2384
2416
|
autoResolved: result.autoResolved === true,
|
|
2385
2417
|
autoReason: result.autoReason ?? undefined,
|
|
2386
2418
|
lateResponse: result.lateResponse === true,
|
|
2419
|
+
priority: result.priority, risk: result.risk,
|
|
2387
2420
|
}
|
|
2388
2421
|
}
|
|
2389
2422
|
return {
|
|
@@ -2392,13 +2425,14 @@ export function apply(ctx, config) {
|
|
|
2392
2425
|
autoResolved: ticket.autoResolved === true,
|
|
2393
2426
|
selectedValue: ticket.resolvedOption ?? undefined,
|
|
2394
2427
|
selectedActionId: ticket.selectedActionId ?? undefined,
|
|
2428
|
+
priority: ticket.priority, risk: ticket.risk,
|
|
2395
2429
|
}
|
|
2396
2430
|
},
|
|
2397
2431
|
})
|
|
2398
2432
|
// PM 交互式选择:独立工具名,语义 = 红色决策 ticket(默认红、阻塞等待选择)。
|
|
2399
2433
|
const unregisterChoice = tools.register({
|
|
2400
2434
|
name: 'ask_user_choice',
|
|
2401
|
-
description: 'PM
|
|
2435
|
+
description: 'PM 交互式选择:向人类提出一个带选项的问题。默认红色阻塞;但**必须按风险选等级**:只有人不在就没法继续时才用 red,方向/进度建议用 yellow,低风险日常建议用 blue,阶段完成汇报用 green。不要所有问题都用红色。'
|
|
2402
2436
|
+ '\n凡属下列情形,PM 必须用本工具开票而不是自行决定或把问题丢回给开发者:'
|
|
2403
2437
|
+ PM_DECISION_POLICY.mustAsk.join(';')
|
|
2404
2438
|
+ '。每次只问一个决定点,给 2-4 个选项并标出推荐项。',
|
|
@@ -2418,7 +2452,9 @@ export function apply(ctx, config) {
|
|
|
2418
2452
|
},
|
|
2419
2453
|
description: '可选项(至少一个)',
|
|
2420
2454
|
},
|
|
2421
|
-
level: { type: 'string', enum: ['red', 'yellow', 'blue'], description: '
|
|
2455
|
+
level: { type: 'string', enum: ['red', 'yellow', 'blue', 'green'], description: '可选;默认 red(真正阻塞才用红)。yellow=3 分钟可补选,blue=1 分钟按推荐执行,green=自动留底' },
|
|
2456
|
+
priority: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'], description: '可选:覆盖等级默认优先级' },
|
|
2457
|
+
risk: { type: 'string', enum: ['high', 'medium', 'low', 'info'], description: '可选:覆盖等级默认风险' },
|
|
2422
2458
|
timeoutMinutes: { type: 'number' },
|
|
2423
2459
|
},
|
|
2424
2460
|
required: ['question', 'choices'],
|
|
@@ -2439,9 +2475,14 @@ export function apply(ctx, config) {
|
|
|
2439
2475
|
}))
|
|
2440
2476
|
.filter((option) => option.value.length > 0)
|
|
2441
2477
|
if (!options.length) throw new Error('ask_user_choice requires at least one choice')
|
|
2478
|
+
const level = ['red', 'yellow', 'blue', 'green'].includes(String(input.level))
|
|
2479
|
+
? String(input.level)
|
|
2480
|
+
: 'red'
|
|
2442
2481
|
const created = create({
|
|
2443
|
-
//
|
|
2444
|
-
level
|
|
2482
|
+
// 默认红;只有真正阻塞才用红,常规建议应显式传 yellow/blue,完成汇报传 green。
|
|
2483
|
+
level,
|
|
2484
|
+
priority: input.priority,
|
|
2485
|
+
risk: input.risk,
|
|
2445
2486
|
title: input.question ?? input.title,
|
|
2446
2487
|
context: input.context ?? input.question,
|
|
2447
2488
|
options,
|
|
@@ -2457,15 +2498,34 @@ export function apply(ctx, config) {
|
|
|
2457
2498
|
})
|
|
2458
2499
|
if (!created.ok) throw new Error(`decision center rejected choice: ${created.reason}`)
|
|
2459
2500
|
const ticket = created.ticket
|
|
2460
|
-
if (
|
|
2501
|
+
if (ticket.status !== 'pending') {
|
|
2502
|
+
return {
|
|
2503
|
+
ticketId: ticket.id, level: ticket.level, blocking: false,
|
|
2504
|
+
status: ticket.status, outcome: ticket.outcome,
|
|
2505
|
+
autoResolved: ticket.autoResolved === true,
|
|
2506
|
+
selectedValue: ticket.resolvedOption ?? undefined,
|
|
2507
|
+
priority: ticket.priority, risk: ticket.risk,
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2461
2510
|
const result = await wait(ticket.id, exec?.signal)
|
|
2462
|
-
const outcome = String(result?.outcome ?? 'expired')
|
|
2511
|
+
const outcome = String(result?.outcome ?? (result.status === 'pending' ? 'deferred' : 'expired'))
|
|
2512
|
+
if (result.status === 'pending' && result.level === 'yellow') {
|
|
2513
|
+
return {
|
|
2514
|
+
ticketId: result.id, level: result.level, blocking: false,
|
|
2515
|
+
status: 'pending', outcome: 'deferred', deferred: true,
|
|
2516
|
+
continueWithoutDecision: true, canAnswerLater: true,
|
|
2517
|
+
priority: result.priority, risk: result.risk,
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2463
2520
|
if (outcome !== 'resolved' && outcome !== 'acked') {
|
|
2464
2521
|
throw new Error(`用户未处理该选择(outcome=${outcome})`)
|
|
2465
2522
|
}
|
|
2466
2523
|
return {
|
|
2467
|
-
ticketId:
|
|
2524
|
+
ticketId: result.id, level: result.level, blocking: result.level === 'red',
|
|
2468
2525
|
outcome, selectedValue: result.resolvedOption ?? undefined,
|
|
2526
|
+
autoResolved: result.autoResolved === true,
|
|
2527
|
+
lateResponse: result.lateResponse === true,
|
|
2528
|
+
priority: result.priority, risk: result.risk,
|
|
2469
2529
|
}
|
|
2470
2530
|
},
|
|
2471
2531
|
})
|