@sshirkit/dsh-orchestrator 0.8.4 → 0.8.7
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/README.md +165 -93
- package/README.zh.md +236 -0
- package/docs/images/dispatch-panel.png +0 -0
- package/lib/client.js +1 -110
- package/lib/delegate.js +4 -1
- package/lib/gate.js +43 -3
- package/lib/index.js +470 -57
- package/lib/rules.js +5 -2
- package/lib/supervise.js +45 -9
- package/package.json +3 -4
- package/README.en.md +0 -164
- package/lib/stage.js +0 -62
package/lib/client.js
CHANGED
|
@@ -18,17 +18,6 @@ window.__ModuleLoader__.load({
|
|
|
18
18
|
const NS = 'orchestrator'
|
|
19
19
|
|
|
20
20
|
const zh = {
|
|
21
|
-
'toggle.label': '计划',
|
|
22
|
-
'toggle.on': '计划模式已开启,点击关闭 (/plan off)',
|
|
23
|
-
'toggle.off': '计划模式已关闭,点击开启 (/plan)',
|
|
24
|
-
'toggle.pending': ',将在下一步生效',
|
|
25
|
-
'toggle.failed': '切换计划模式失败',
|
|
26
|
-
'stage.idle': '默认',
|
|
27
|
-
'stage.clarify': '澄清',
|
|
28
|
-
'stage.planning': '规划',
|
|
29
|
-
'stage.awaiting': '待确认',
|
|
30
|
-
'stage.executing': '执行',
|
|
31
|
-
'stage.na': '不适用',
|
|
32
21
|
'route.button': '调度模式',
|
|
33
22
|
'route.title': '主代理与子代理的默认模型',
|
|
34
23
|
'route.main': '主代理',
|
|
@@ -64,17 +53,6 @@ window.__ModuleLoader__.load({
|
|
|
64
53
|
'supervise.countInvalid': '请输入 0–20 之间的整数',
|
|
65
54
|
}
|
|
66
55
|
const en = {
|
|
67
|
-
'toggle.label': 'Plan',
|
|
68
|
-
'toggle.on': 'Plan mode is on, click to turn off (/plan off)',
|
|
69
|
-
'toggle.off': 'Plan mode is off, click to turn on (/plan)',
|
|
70
|
-
'toggle.pending': ', applies from the next step',
|
|
71
|
-
'toggle.failed': 'Could not switch plan mode',
|
|
72
|
-
'stage.idle': 'Default',
|
|
73
|
-
'stage.clarify': 'Clarify',
|
|
74
|
-
'stage.planning': 'Planning',
|
|
75
|
-
'stage.awaiting': 'Review',
|
|
76
|
-
'stage.executing': 'Executing',
|
|
77
|
-
'stage.na': 'N/A',
|
|
78
56
|
'route.button': 'Dispatch',
|
|
79
57
|
'route.title': 'Default models for the main agent and subagents',
|
|
80
58
|
'route.main': 'Main agent',
|
|
@@ -131,75 +109,6 @@ window.__ModuleLoader__.load({
|
|
|
131
109
|
borderColor: 'var(--dsw-alias-brand-primary, #4d8dff)',
|
|
132
110
|
background: 'var(--dsw-alias-button-ghost-active-fill, color-mix(in srgb, #4d8dff 16%, transparent))',
|
|
133
111
|
}
|
|
134
|
-
const dot = (on) => ({
|
|
135
|
-
width: '6px',
|
|
136
|
-
height: '6px',
|
|
137
|
-
borderRadius: '999px',
|
|
138
|
-
background: on ? 'var(--dsw-alias-brand-primary, #4d8dff)' : 'var(--dsw-alias-label-tertiary, color-mix(in srgb, currentColor 45%, transparent))',
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Plan-mode toggle. The native plan projection folds the host's committed
|
|
143
|
-
* state; `/plan` during an open turn is queued, so `pending` means the shown
|
|
144
|
-
* target differs from what the host has applied so far.
|
|
145
|
-
*/
|
|
146
|
-
function PlanToggle({ useProjection, locked, setPlan, t }) {
|
|
147
|
-
// A blank new conversation has no folded plan state yet; that is plan mode off.
|
|
148
|
-
const plan = useProjection('plan') ?? { active: false, pending: false }
|
|
149
|
-
// Derived by the host from logged events; absent until the first projection arrives.
|
|
150
|
-
const stage = useProjection('orchestrator')?.stage ?? 'idle'
|
|
151
|
-
const [busy, setBusy] = React.useState(false)
|
|
152
|
-
const [error, setError] = React.useState(null)
|
|
153
|
-
const alive = React.useRef(true)
|
|
154
|
-
React.useEffect(() => {
|
|
155
|
-
alive.current = true
|
|
156
|
-
return () => {
|
|
157
|
-
alive.current = false
|
|
158
|
-
}
|
|
159
|
-
}, [])
|
|
160
|
-
|
|
161
|
-
const target = plan.pending ? !plan.active : plan.active
|
|
162
|
-
const base = target ? t('toggle.on') : t('toggle.off')
|
|
163
|
-
// The button face only says "Plan" and is lit when on; the stage lives in the hover text.
|
|
164
|
-
const title = error ?? (plan.pending ? base + t('toggle.pending') : base) + ' · ' + t('stage.' + stage)
|
|
165
|
-
|
|
166
|
-
const onClick = () => {
|
|
167
|
-
if (busy || locked) return
|
|
168
|
-
setBusy(true)
|
|
169
|
-
setError(null)
|
|
170
|
-
setPlan(!target).then(
|
|
171
|
-
(failure) => {
|
|
172
|
-
if (!alive.current) return
|
|
173
|
-
setBusy(false)
|
|
174
|
-
setError(failure)
|
|
175
|
-
},
|
|
176
|
-
(reason) => {
|
|
177
|
-
if (!alive.current) return
|
|
178
|
-
setBusy(false)
|
|
179
|
-
setError(typeof reason?.message === 'string' && reason.message !== '' ? reason.message : t('toggle.failed'))
|
|
180
|
-
},
|
|
181
|
-
)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return React.createElement(
|
|
185
|
-
'button',
|
|
186
|
-
{
|
|
187
|
-
type: 'button',
|
|
188
|
-
style: Object.assign({}, baseStyle, target ? onStyle : null, busy || locked ? { opacity: 0.6 } : null),
|
|
189
|
-
disabled: busy || locked,
|
|
190
|
-
onClick,
|
|
191
|
-
title,
|
|
192
|
-
'aria-label': title,
|
|
193
|
-
'aria-pressed': target,
|
|
194
|
-
'data-plan': target ? 'on' : 'off',
|
|
195
|
-
'data-pending': plan.pending ? 'true' : 'false',
|
|
196
|
-
'data-stage': stage,
|
|
197
|
-
},
|
|
198
|
-
React.createElement('span', { style: dot(target), 'aria-hidden': true }),
|
|
199
|
-
React.createElement('span', null, t('toggle.label')),
|
|
200
|
-
)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
112
|
// ---- Default routes -------------------------------------------------------------------
|
|
204
113
|
// Two stored routes, each a { provider, model, effort } triple under different field names.
|
|
205
114
|
// The main agent's lives in the host's `agent-default-model` entry (read when an agent is
|
|
@@ -1684,29 +1593,11 @@ window.__ModuleLoader__.load({
|
|
|
1684
1593
|
}
|
|
1685
1594
|
|
|
1686
1595
|
/** Service names, not package names: these are the `ctx.*` members used below. */
|
|
1687
|
-
const inject = ['slots', 'locale', 'remote', 'remote.
|
|
1596
|
+
const inject = ['slots', 'locale', 'remote', 'remote.session', 'configForms']
|
|
1688
1597
|
|
|
1689
1598
|
function apply(ctx) {
|
|
1690
1599
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'orchestrator: dictionaries')
|
|
1691
1600
|
|
|
1692
|
-
// Same command channel the native plan chip uses to leave plan mode.
|
|
1693
|
-
const setPlanFor = (sessionId) => async (active) => {
|
|
1694
|
-
const command = active ? '/plan' : '/plan off'
|
|
1695
|
-
const result = await ctx.remote.commands.execute(sessionId, command, [])
|
|
1696
|
-
if (!result.ok) return result.error.message + ' (' + result.error.code + ')'
|
|
1697
|
-
if (result.value === undefined) return 'unknown command: ' + command
|
|
1698
|
-
return null
|
|
1699
|
-
}
|
|
1700
|
-
// `conversation.input.plan` is a single-occupant slot and the shipped plan package claims
|
|
1701
|
-
// it: a second registration makes that package's activation throw, which fails the whole
|
|
1702
|
-
// web boot. The toggle takes a seat in the left list slot instead, next to the plan chip.
|
|
1703
|
-
ctx.slots.inject('conversation.input.left', () =>
|
|
1704
|
-
ctx.slots.register(
|
|
1705
|
-
{ name: 'conversation.input.left', id: 'orchestrator-plan-toggle', order: 20, locale: NS },
|
|
1706
|
-
(props) => h(PlanToggle, Object.assign({}, props, { setPlan: setPlanFor(props.sessionId) })),
|
|
1707
|
-
),
|
|
1708
|
-
)
|
|
1709
|
-
|
|
1710
1601
|
const scopes = { main: ctx.configForms.get(MAIN.ns), worker: ctx.configForms.get(WORKER.ns), orch: ctx.configForms.get(NS) }
|
|
1711
1602
|
ctx.slots.inject('conversation.input.right', () =>
|
|
1712
1603
|
ctx.slots.register(
|
package/lib/delegate.js
CHANGED
|
@@ -69,7 +69,10 @@ export function createDelegateTool({
|
|
|
69
69
|
'省略该字段或声明为空数组都会被拒绝,插件会在派发前拒绝与其他写者重叠的声明。' +
|
|
70
70
|
'子代理仍在运行时可用 send_message 纠偏,已结束的可用 send_message ' +
|
|
71
71
|
'追加任务(它保留自己的上下文)。长时间运行的子代理会被插件每隔几分钟巡检:收到「【插件巡检…】」' +
|
|
72
|
-
'
|
|
72
|
+
'消息(来自插件,不是用户)时,所列子代理均仍在运行且尚未交付,巡检回合禁止修改 todo_write;' +
|
|
73
|
+
'巡检例外仅指不自动推进主任务与禁止调用 todo_write,巡检回合仍受当前工具白名单(allowedTools)制约;' +
|
|
74
|
+
'需干预时禁止回复「巡检:正常」,请用白名单允许的调研或 send_message 等工具纠偏;' +
|
|
75
|
+
'无需干预时严禁调用任何工具,只回复一行「巡检:正常」并立即结束回合。'
|
|
73
76
|
const descriptionOf = () => (enabled() ? rule() + body : body)
|
|
74
77
|
|
|
75
78
|
// A provisional id lets the lease be registered before the host names the child: the
|
package/lib/gate.js
CHANGED
|
@@ -38,6 +38,41 @@ import { RUN_CODE_TOOL, runCodeRefusal } from './run-code-guard.js'
|
|
|
38
38
|
|
|
39
39
|
export { DELEGATE_TOOL }
|
|
40
40
|
|
|
41
|
+
export const SUPERVISION_TODO_DENIAL = '[dsh-orchestrator] 当前为定时巡检回合,已禁止调用 todo_write。子代理仍在运行,请勿推进主任务清单状态;如需纠偏请直接通过调研或 send_message / interrupt_agent 等方式处理,无需干预请仅回复「巡检:正常」。任务进度请在子代理交付结算(subagent-settled)或正常用户回合再更新。'
|
|
42
|
+
export const SUPERVISION_NORMAL_DENIAL = '[dsh-orchestrator] 本回合已输出「巡检:正常」确认无需干预,已锁定后续工具调用,请立即结束本回合,勿再调用任何工具。'
|
|
43
|
+
const SUPERVISION_WHITELIST_DENIAL = 'orchestrator: The requested tool is not in allowedTools for the current supervision turn. Use currently allowed tools to handle existing workers, or reply "巡检:正常" and end the turn.'
|
|
44
|
+
|
|
45
|
+
/** Bind supervision restrictions to one root agent and one exact turn. */
|
|
46
|
+
export function createSupervisionTurnState() {
|
|
47
|
+
const turns = new Map()
|
|
48
|
+
const isTurnActive = (agentId, turn) => turns.has(agentId) && turns.get(agentId).turn === turn
|
|
49
|
+
return {
|
|
50
|
+
bindTurn(agentId, turn) {
|
|
51
|
+
turns.set(agentId, { turn, normalDeclared: false })
|
|
52
|
+
},
|
|
53
|
+
markNormalDeclared(agentId, turn) {
|
|
54
|
+
if (isTurnActive(agentId, turn)) turns.get(agentId).normalDeclared = true
|
|
55
|
+
},
|
|
56
|
+
isTurnActive,
|
|
57
|
+
clearTurn(agentId, turn) {
|
|
58
|
+
if (isTurnActive(agentId, turn)) turns.delete(agentId)
|
|
59
|
+
},
|
|
60
|
+
clearAgent: (agentId) => turns.delete(agentId),
|
|
61
|
+
checkTool(agentId, currentTurn, toolName, { whitelistMiss = false } = {}) {
|
|
62
|
+
const record = turns.get(agentId)
|
|
63
|
+
if (record === undefined) return undefined
|
|
64
|
+
if (currentTurn !== undefined && record.turn !== currentTurn) {
|
|
65
|
+
turns.delete(agentId)
|
|
66
|
+
return undefined
|
|
67
|
+
}
|
|
68
|
+
if (toolName === 'todo_write') return SUPERVISION_TODO_DENIAL
|
|
69
|
+
if (record.normalDeclared) return SUPERVISION_NORMAL_DENIAL
|
|
70
|
+
if (whitelistMiss) return SUPERVISION_WHITELIST_DENIAL
|
|
71
|
+
return undefined
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
41
76
|
/**
|
|
42
77
|
* Whether an agent is a delegated child. Mirrors the host's `delegationDepthOf`
|
|
43
78
|
* (`Math.max(header.delegationDepth ?? 0, options.subagentDepth ?? 0)`): the
|
|
@@ -160,7 +195,7 @@ export function allowGuard(allowed) {
|
|
|
160
195
|
* or a `run_code` program that would reach the host. A guard failure is reported, not
|
|
161
196
|
* thrown: a broken gate must not break agent creation.
|
|
162
197
|
*/
|
|
163
|
-
export function installGate({ agent, allowed, enabled = () => true }) {
|
|
198
|
+
export function installGate({ agent, allowed, enabled = () => true, checkSupervision }) {
|
|
164
199
|
const liveAllowed = typeof allowed === 'function' ? allowed : () => allowed ?? []
|
|
165
200
|
let guardError
|
|
166
201
|
let guardDispose
|
|
@@ -168,6 +203,10 @@ export function installGate({ agent, allowed, enabled = () => true }) {
|
|
|
168
203
|
guardDispose = agent.ctx.tools.guard((exec) => {
|
|
169
204
|
const tool = exec?.name
|
|
170
205
|
if (typeof tool !== 'string' || tool === '') return undefined
|
|
206
|
+
const caller = exec?.agent ?? agent
|
|
207
|
+
if (isDelegatedChild(caller)) return undefined
|
|
208
|
+
const supervisionDenial = checkSupervision?.(caller, tool)
|
|
209
|
+
if (typeof supervisionDenial === 'string' && supervisionDenial !== '') return supervisionDenial
|
|
171
210
|
if (!enabled()) {
|
|
172
211
|
if (tool === DELEGATE_TOOL || tool === ORCHESTRATE_TOOL) {
|
|
173
212
|
return disabledToolMessage(tool)
|
|
@@ -178,8 +217,9 @@ export function installGate({ agent, allowed, enabled = () => true }) {
|
|
|
178
217
|
if (list.includes(tool)) return undefined
|
|
179
218
|
// `run_code` is the PTC transport: it stays callable unless the panel checks it, and
|
|
180
219
|
// the arguments that would escape the gate are refused instead.
|
|
181
|
-
|
|
182
|
-
|
|
220
|
+
const refusal = tool === RUN_CODE_TOOL ? runCodeRefusal(exec?.arguments, true) : refusalFor(tool)
|
|
221
|
+
if (refusal === undefined) return undefined
|
|
222
|
+
return checkSupervision?.(caller, tool, { whitelistMiss: true }) ?? refusal
|
|
183
223
|
})
|
|
184
224
|
} catch (error) {
|
|
185
225
|
guardError = error instanceof Error ? error.message : String(error)
|