@twinsearth/dsh-fang 3.2.0 → 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 +90 -18
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: {
|
|
@@ -432,7 +447,12 @@ function applyForkDecisionCenter(ctx, config, gate) {
|
|
|
432
447
|
const remoteWaitMs = ticket.level === 'red'
|
|
433
448
|
? waitTimeoutMs
|
|
434
449
|
: Math.max(1000, Number(ticket.waitDeadlineAt) - Date.now() + 5000)
|
|
435
|
-
|
|
450
|
+
let settled = await wait(ticket.id, { signal: exec?.signal, timeoutMs: remoteWaitMs })
|
|
451
|
+
if (!settled.ok && ticket.level === 'blue' && settled.reason === 'timeout') {
|
|
452
|
+
// v3.2.1:轮询窗口与母体自动执行存在毫秒级竞态,失败前再取一次最终状态。
|
|
453
|
+
const final = await getRemote(ticket.id)
|
|
454
|
+
if (final.ok && final.ticket && final.ticket.status !== 'pending') settled = { ok: true, ticket: final.ticket }
|
|
455
|
+
}
|
|
436
456
|
if (!settled.ok) {
|
|
437
457
|
// 黄色轮询超时仍允许流程继续;母体定时器会把 ticket 标成 deferred。
|
|
438
458
|
if (ticket.level === 'yellow' && settled.reason === 'timeout') {
|
|
@@ -440,6 +460,7 @@ function applyForkDecisionCenter(ctx, config, gate) {
|
|
|
440
460
|
ticketId: ticket.id, level: ticket.level, blocking: false,
|
|
441
461
|
status: 'pending', outcome: 'deferred', deferred: true,
|
|
442
462
|
continueWithoutDecision: true, canAnswerLater: true, queued: false,
|
|
463
|
+
priority: ticket.priority, risk: ticket.risk,
|
|
443
464
|
}
|
|
444
465
|
}
|
|
445
466
|
throw new Error(`fork 决策未在时限内完成(${settled.reason})`)
|
|
@@ -451,6 +472,7 @@ function applyForkDecisionCenter(ctx, config, gate) {
|
|
|
451
472
|
status: 'pending', outcome: 'deferred', deferred: true,
|
|
452
473
|
continueWithoutDecision: true, canAnswerLater: true,
|
|
453
474
|
deferredAt: resolved.deferredAt ?? undefined, queued: false,
|
|
475
|
+
priority: resolved.priority, risk: resolved.risk,
|
|
454
476
|
}
|
|
455
477
|
}
|
|
456
478
|
if (resolved.status !== 'resolved' && resolved.status !== 'abandoned' && resolved.status !== 'expired' && resolved.status !== 'acked') {
|
|
@@ -463,6 +485,7 @@ function applyForkDecisionCenter(ctx, config, gate) {
|
|
|
463
485
|
selectedActionId: resolved.selectedActionId ?? undefined,
|
|
464
486
|
autoResolved: resolved.autoResolved === true,
|
|
465
487
|
autoReason: resolved.autoReason ?? undefined,
|
|
488
|
+
priority: resolved.priority, risk: resolved.risk,
|
|
466
489
|
queued: false,
|
|
467
490
|
}
|
|
468
491
|
}
|
|
@@ -708,7 +731,9 @@ export function apply(ctx, config) {
|
|
|
708
731
|
// A waited ticket is a live promise; any blocking ticket (even yellow with
|
|
709
732
|
// isBlocking:true) is a live decision; a pending red is the most expensive
|
|
710
733
|
// attention object even when no one is currently awaited. Never evict them.
|
|
711
|
-
|
|
734
|
+
// v3.2.1:所有 pending 都仍可回答/等待自动闭环,不能被容量修剪静默删除。
|
|
735
|
+
// maxTickets 只淘汰已处理历史;黄票尤其必须保留到人工补选。
|
|
736
|
+
if (victim.status === 'pending' || waiters.has(victim.id) || victim.isBlocking === true) continue
|
|
712
737
|
tickets.delete(victim.id)
|
|
713
738
|
const record = { id: victim.id, level: victim.level, status: victim.status, reason: 'max-tickets', at: nowMs() }
|
|
714
739
|
evicted.push(record)
|
|
@@ -941,6 +966,11 @@ export function apply(ctx, config) {
|
|
|
941
966
|
const deferYellow = (id) => {
|
|
942
967
|
const ticket = tickets.get(String(id ?? ''))
|
|
943
968
|
if (!ticket || ticket.status !== 'pending' || ticket.level !== 'yellow') return false
|
|
969
|
+
// v3.2.1:调度定时器与 wait 定时器可同时到期;defer 必须幂等,不能重复审计/升 rev。
|
|
970
|
+
if (ticket.deferredAt) {
|
|
971
|
+
settleWaiter(ticket.id, publicTicket(ticket))
|
|
972
|
+
return false
|
|
973
|
+
}
|
|
944
974
|
if (ticket.waitDeadlineAt && Number(ticket.waitDeadlineAt) > nowMs()) return false
|
|
945
975
|
ticket.deferredAt = nowMs()
|
|
946
976
|
ticket.outcome = 'deferred'
|
|
@@ -1142,6 +1172,8 @@ export function apply(ctx, config) {
|
|
|
1142
1172
|
autoReason: null,
|
|
1143
1173
|
lateResponse: false,
|
|
1144
1174
|
policyTimeoutMs,
|
|
1175
|
+
priority: normalizeDecisionPriority(raw.priority, level),
|
|
1176
|
+
risk: normalizeDecisionRisk(raw.risk, level),
|
|
1145
1177
|
}
|
|
1146
1178
|
ticket.rev = nextRevision()
|
|
1147
1179
|
tickets.set(ticket.id, ticket)
|
|
@@ -1172,7 +1204,7 @@ export function apply(ctx, config) {
|
|
|
1172
1204
|
if (ticket.status !== 'pending') return Promise.resolve(publicTicket(ticket))
|
|
1173
1205
|
// v3.2.0:恢复/延迟调用时窗口可能已经过去,先按等级策略推进再返回。
|
|
1174
1206
|
if ((ticket.level === 'yellow' || ticket.level === 'blue')
|
|
1175
|
-
&& Number(ticket.waitDeadlineAt) <= nowMs()) {
|
|
1207
|
+
&& ticket.waitDeadlineAt && Number(ticket.waitDeadlineAt) <= nowMs()) {
|
|
1176
1208
|
settlePolicy(ticketId)
|
|
1177
1209
|
return Promise.resolve(publicTicket(tickets.get(ticketId) ?? ticket))
|
|
1178
1210
|
}
|
|
@@ -1194,9 +1226,9 @@ export function apply(ctx, config) {
|
|
|
1194
1226
|
const set = waiters.get(ticketId)
|
|
1195
1227
|
if (set) { set.delete(waiter); if (set.size === 0) waiters.delete(ticketId) }
|
|
1196
1228
|
const current = tickets.get(ticketId)
|
|
1197
|
-
if (current && current.status === 'pending' && (!set || set.size === 0)) {
|
|
1198
|
-
//
|
|
1199
|
-
//
|
|
1229
|
+
if (current && current.status === 'pending' && current.level === 'red' && (!set || set.size === 0)) {
|
|
1230
|
+
// v3.2.1:只有红色在调用方取消后转为 abandoned。
|
|
1231
|
+
// 黄/蓝只是取消本次流程等待,ticket 必须继续保留:黄色仍可补选,蓝色仍按窗口自动执行。
|
|
1200
1232
|
abandon(ticketId, { by: 'caller', note: 'caller-aborted' })
|
|
1201
1233
|
}
|
|
1202
1234
|
rejectPromise(new Error('decision wait aborted'))
|
|
@@ -1285,6 +1317,8 @@ export function apply(ctx, config) {
|
|
|
1285
1317
|
autoReason: item.autoReason ?? null,
|
|
1286
1318
|
lateResponse: item.lateResponse === true,
|
|
1287
1319
|
policyTimeoutMs: Number(item.policyTimeoutMs) || null,
|
|
1320
|
+
priority: normalizeDecisionPriority(item.priority, normalizeLevel(item.level, 'gray')),
|
|
1321
|
+
risk: normalizeDecisionRisk(item.risk, normalizeLevel(item.level, 'gray')),
|
|
1288
1322
|
}
|
|
1289
1323
|
if (ticket.status === 'pending') {
|
|
1290
1324
|
// v3.1.24:进程重启后 pending 仍保留给人回答(浮窗/收件箱可见),
|
|
@@ -2220,6 +2254,8 @@ export function apply(ctx, config) {
|
|
|
2220
2254
|
statuses: [...STATUSES],
|
|
2221
2255
|
blockingLevels: [...BLOCKING_LEVELS],
|
|
2222
2256
|
levelPolicies: DECISION_LEVEL_POLICY,
|
|
2257
|
+
priorities: [...DECISION_PRIORITIES],
|
|
2258
|
+
risks: [...DECISION_RISKS],
|
|
2223
2259
|
maxTickets: cfg.maxTickets,
|
|
2224
2260
|
maxPendingRed: cfg.maxPendingRed,
|
|
2225
2261
|
defaultTimeoutMinutes: cfg.defaultTimeoutMinutes,
|
|
@@ -2274,12 +2310,14 @@ export function apply(ctx, config) {
|
|
|
2274
2310
|
if (!tools || typeof tools.register !== 'function') return
|
|
2275
2311
|
const unregister = tools.register({
|
|
2276
2312
|
name: 'request_human_decision',
|
|
2277
|
-
description: '当需要人类授权、选择方案、或汇报重要结果时,创建一张决策中心 ticket
|
|
2313
|
+
description: '当需要人类授权、选择方案、或汇报重要结果时,创建一张决策中心 ticket。红色强制等待人工(P0/高);黄色最多等 3 分钟后继续且可补选(P1/中);蓝色最多等 1 分钟后按推荐自动执行(P2/低);绿色自动执行并留底(P3/信息)。必须按风险选等级,不要全部用红色。\n' + PM_PROACTIVE_HINT,
|
|
2278
2314
|
parameters: {
|
|
2279
2315
|
type: 'object',
|
|
2280
2316
|
additionalProperties: false,
|
|
2281
2317
|
properties: {
|
|
2282
|
-
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: '可选:覆盖等级默认风险程度' },
|
|
2283
2321
|
title: { type: 'string', description: '一句话标题' },
|
|
2284
2322
|
context: { type: 'string', description: '为什么需要人类介入' },
|
|
2285
2323
|
options: {
|
|
@@ -2317,6 +2355,11 @@ export function apply(ctx, config) {
|
|
|
2317
2355
|
outcome: { type: 'string' },
|
|
2318
2356
|
selectedValue: { type: 'string' },
|
|
2319
2357
|
selectedActionId: { type: 'string' },
|
|
2358
|
+
priority: { type: 'string' },
|
|
2359
|
+
risk: { type: 'string' },
|
|
2360
|
+
autoResolved: { type: 'boolean' },
|
|
2361
|
+
lateResponse: { type: 'boolean' },
|
|
2362
|
+
continueWithoutDecision: { type: 'boolean' },
|
|
2320
2363
|
},
|
|
2321
2364
|
},
|
|
2322
2365
|
render(_args, value) {
|
|
@@ -2358,6 +2401,7 @@ export function apply(ctx, config) {
|
|
|
2358
2401
|
status: 'pending', outcome: 'deferred', deferred: true,
|
|
2359
2402
|
continueWithoutDecision: true, canAnswerLater: true,
|
|
2360
2403
|
deferredAt: result.deferredAt ?? undefined,
|
|
2404
|
+
priority: result.priority, risk: result.risk,
|
|
2361
2405
|
}
|
|
2362
2406
|
}
|
|
2363
2407
|
if (outcome !== 'resolved' && outcome !== 'acked') {
|
|
@@ -2372,6 +2416,7 @@ export function apply(ctx, config) {
|
|
|
2372
2416
|
autoResolved: result.autoResolved === true,
|
|
2373
2417
|
autoReason: result.autoReason ?? undefined,
|
|
2374
2418
|
lateResponse: result.lateResponse === true,
|
|
2419
|
+
priority: result.priority, risk: result.risk,
|
|
2375
2420
|
}
|
|
2376
2421
|
}
|
|
2377
2422
|
return {
|
|
@@ -2380,13 +2425,14 @@ export function apply(ctx, config) {
|
|
|
2380
2425
|
autoResolved: ticket.autoResolved === true,
|
|
2381
2426
|
selectedValue: ticket.resolvedOption ?? undefined,
|
|
2382
2427
|
selectedActionId: ticket.selectedActionId ?? undefined,
|
|
2428
|
+
priority: ticket.priority, risk: ticket.risk,
|
|
2383
2429
|
}
|
|
2384
2430
|
},
|
|
2385
2431
|
})
|
|
2386
2432
|
// PM 交互式选择:独立工具名,语义 = 红色决策 ticket(默认红、阻塞等待选择)。
|
|
2387
2433
|
const unregisterChoice = tools.register({
|
|
2388
2434
|
name: 'ask_user_choice',
|
|
2389
|
-
description: 'PM
|
|
2435
|
+
description: 'PM 交互式选择:向人类提出一个带选项的问题。默认红色阻塞;但**必须按风险选等级**:只有人不在就没法继续时才用 red,方向/进度建议用 yellow,低风险日常建议用 blue,阶段完成汇报用 green。不要所有问题都用红色。'
|
|
2390
2436
|
+ '\n凡属下列情形,PM 必须用本工具开票而不是自行决定或把问题丢回给开发者:'
|
|
2391
2437
|
+ PM_DECISION_POLICY.mustAsk.join(';')
|
|
2392
2438
|
+ '。每次只问一个决定点,给 2-4 个选项并标出推荐项。',
|
|
@@ -2406,7 +2452,9 @@ export function apply(ctx, config) {
|
|
|
2406
2452
|
},
|
|
2407
2453
|
description: '可选项(至少一个)',
|
|
2408
2454
|
},
|
|
2409
|
-
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: '可选:覆盖等级默认风险' },
|
|
2410
2458
|
timeoutMinutes: { type: 'number' },
|
|
2411
2459
|
},
|
|
2412
2460
|
required: ['question', 'choices'],
|
|
@@ -2427,9 +2475,14 @@ export function apply(ctx, config) {
|
|
|
2427
2475
|
}))
|
|
2428
2476
|
.filter((option) => option.value.length > 0)
|
|
2429
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'
|
|
2430
2481
|
const created = create({
|
|
2431
|
-
//
|
|
2432
|
-
level
|
|
2482
|
+
// 默认红;只有真正阻塞才用红,常规建议应显式传 yellow/blue,完成汇报传 green。
|
|
2483
|
+
level,
|
|
2484
|
+
priority: input.priority,
|
|
2485
|
+
risk: input.risk,
|
|
2433
2486
|
title: input.question ?? input.title,
|
|
2434
2487
|
context: input.context ?? input.question,
|
|
2435
2488
|
options,
|
|
@@ -2445,15 +2498,34 @@ export function apply(ctx, config) {
|
|
|
2445
2498
|
})
|
|
2446
2499
|
if (!created.ok) throw new Error(`decision center rejected choice: ${created.reason}`)
|
|
2447
2500
|
const ticket = created.ticket
|
|
2448
|
-
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
|
+
}
|
|
2449
2510
|
const result = await wait(ticket.id, exec?.signal)
|
|
2450
|
-
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
|
+
}
|
|
2451
2520
|
if (outcome !== 'resolved' && outcome !== 'acked') {
|
|
2452
2521
|
throw new Error(`用户未处理该选择(outcome=${outcome})`)
|
|
2453
2522
|
}
|
|
2454
2523
|
return {
|
|
2455
|
-
ticketId:
|
|
2524
|
+
ticketId: result.id, level: result.level, blocking: result.level === 'red',
|
|
2456
2525
|
outcome, selectedValue: result.resolvedOption ?? undefined,
|
|
2526
|
+
autoResolved: result.autoResolved === true,
|
|
2527
|
+
lateResponse: result.lateResponse === true,
|
|
2528
|
+
priority: result.priority, risk: result.risk,
|
|
2457
2529
|
}
|
|
2458
2530
|
},
|
|
2459
2531
|
})
|