@sshirkit/dsh-orchestrator 0.9.1 → 1.0.0
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 +153 -92
- package/README.zh.md +155 -94
- package/docs/images/dispatch-panel.png +0 -0
- package/docs/images/hero-banner.png +0 -0
- package/lib/api.js +1 -0
- package/lib/catalog.js +2 -1
- package/lib/client.js +212 -55
- package/lib/delegate-status.js +125 -0
- package/lib/delegate.js +299 -59
- package/lib/gate.js +57 -15
- package/lib/git-audit.js +383 -0
- package/lib/index.js +1185 -173
- package/lib/orchestrate.js +313 -89
- package/lib/reconcile.js +590 -0
- package/lib/retry.js +68 -5
- package/lib/rules.js +15 -2
- package/lib/state-store.js +455 -0
- package/lib/supervise.js +593 -87
- package/lib/timeline.js +464 -0
- package/lib/tool-surface.js +69 -21
- package/lib/worktree-manage.js +244 -0
- package/lib/worktree-tool.js +38 -0
- package/lib/worktree.js +687 -0
- package/lib/write-audit.js +333 -0
- package/lib/write-lease.js +161 -7
- package/lib/write-scope-tool.js +29 -0
- package/lib/write-scope.js +14 -18
- package/package.json +3 -3
package/lib/client.js
CHANGED
|
@@ -14,7 +14,6 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
ReactDOM = null
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/** Dictionary namespace owned by this plugin. */
|
|
18
17
|
const NS = 'orchestrator'
|
|
19
18
|
|
|
20
19
|
const zh = {
|
|
@@ -37,11 +36,15 @@ window.__ModuleLoader__.load({
|
|
|
37
36
|
'route.enable': '启用调度模式',
|
|
38
37
|
'route.enableNote': '开启后主代理只做规划、由子代理执行;已打开的会话也会立即生效。',
|
|
39
38
|
'route.enableFailed': '切换失败',
|
|
39
|
+
'worktreeIsolation.label': '默认启用 Git Worktree 隔离',
|
|
40
|
+
'worktreeIsolation.hint': 'Git 仓库中的写任务默认使用独立 Worktree,并用 git diff / git log 审计。delegate 按任务、orchestrate 按条目隔离;非 Git 目录自动使用逻辑快照审计。',
|
|
40
41
|
'allowed.title': 'Allowed Tools',
|
|
41
42
|
'allowed.search': '搜索工具…',
|
|
42
43
|
'allowed.empty': '没有匹配的工具',
|
|
43
44
|
'allowed.reset': '重置',
|
|
44
45
|
'allowed.hint': '白名单式驱动:勾选 = 允许主代理使用;未勾选(含新插件工具)= 自动禁用。',
|
|
46
|
+
'allowed.nativeBlocked': '按 ADR-0004 默认禁用;建议改用 delegate / orchestrate。显式勾选可覆盖。',
|
|
47
|
+
'allowed.teamDisabled': '当前配置已关闭原生 Team 共享任务板(allowAgentTeam: false)。',
|
|
45
48
|
'supervise.label': '子代理巡检间隔(秒)',
|
|
46
49
|
'supervise.hint': '默认 600 秒(10 分钟)。主代理会按此间隔检查运行中的子代理,运行中修改立即生效。范围 10–86400。',
|
|
47
50
|
'supervise.invalid': '请输入 10–86400 之间的整数',
|
|
@@ -72,11 +75,15 @@ window.__ModuleLoader__.load({
|
|
|
72
75
|
'route.enable': 'Enable dispatch mode',
|
|
73
76
|
'route.enableNote': 'The main agent only plans and delegates the work; an open conversation follows the switch immediately.',
|
|
74
77
|
'route.enableFailed': 'Could not switch',
|
|
78
|
+
'worktreeIsolation.label': 'Enable Git Worktree isolation by default',
|
|
79
|
+
'worktreeIsolation.hint': 'Write tasks in Git repositories use separate worktrees with git diff / git log audits: one per delegate task or orchestrate item. Non-Git directories fall back to snapshot audits.',
|
|
75
80
|
'allowed.title': 'Allowed Tools',
|
|
76
81
|
'allowed.search': 'Filter tools…',
|
|
77
82
|
'allowed.empty': 'No matching tools',
|
|
78
83
|
'allowed.reset': 'Reset',
|
|
79
84
|
'allowed.hint': 'Whitelist-driven: checked = allowed for the main agent; unchecked (including new plugin tools) = blocked automatically.',
|
|
85
|
+
'allowed.nativeBlocked': 'Disabled by default under ADR-0004; prefer delegate / orchestrate. Check explicitly to override.',
|
|
86
|
+
'allowed.teamDisabled': 'The native Team task board is disabled by configuration (allowAgentTeam: false).',
|
|
80
87
|
'supervise.label': 'Subagent check interval (seconds)',
|
|
81
88
|
'supervise.hint': 'Default 600 seconds (10 minutes). The main agent checks running subagents at this interval; changes apply immediately. Range 10–86400.',
|
|
82
89
|
'supervise.invalid': 'Enter an integer between 10 and 86400',
|
|
@@ -121,7 +128,7 @@ window.__ModuleLoader__.load({
|
|
|
121
128
|
fields: { provider: 'provider', model: 'model', effort: 'reasoningEffort', clear: 'unset' },
|
|
122
129
|
}
|
|
123
130
|
const WORKER = {
|
|
124
|
-
ns:
|
|
131
|
+
ns: NS,
|
|
125
132
|
fields: { provider: 'workerProvider', model: 'workerModel', effort: 'workerReasoningEffort', clear: 'empty' },
|
|
126
133
|
}
|
|
127
134
|
|
|
@@ -281,8 +288,8 @@ window.__ModuleLoader__.load({
|
|
|
281
288
|
}
|
|
282
289
|
|
|
283
290
|
// ---- Allowed tools --------------------------------------------------------------------
|
|
284
|
-
//
|
|
285
|
-
//
|
|
291
|
+
// The base whitelist mirrors DEFAULT_ALLOWED_TOOLS in lib/tool-surface.js. ADR-0004's
|
|
292
|
+
// optional Team tools and default-blocked native tools mirror lib/gate.js.
|
|
286
293
|
// A web client plugin has no API that enumerates host tools — the session remote offers
|
|
287
294
|
// session/model/skill methods only, and configForms exposes this plugin's own config — so
|
|
288
295
|
// the plugin's server half collects the live catalog and publishes it as the volatile
|
|
@@ -293,21 +300,24 @@ window.__ModuleLoader__.load({
|
|
|
293
300
|
const DEFAULT_ALLOWED_TOOLS = [
|
|
294
301
|
'delegate',
|
|
295
302
|
'orchestrate',
|
|
303
|
+
'delegate_status',
|
|
304
|
+
'worktree_manage',
|
|
296
305
|
'send_message',
|
|
297
306
|
'interrupt_agent',
|
|
298
307
|
'todo_write',
|
|
299
308
|
'ask_user_question',
|
|
300
309
|
'compress',
|
|
301
|
-
'session_search',
|
|
302
|
-
'session_trace',
|
|
303
|
-
'session_event_search',
|
|
304
|
-
'session_event_read',
|
|
305
|
-
'session_event_trace',
|
|
306
310
|
]
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
311
|
+
const NATIVE_TEAM_TOOLS = [
|
|
312
|
+
'team_task_create',
|
|
313
|
+
'team_task_list',
|
|
314
|
+
'team_task_get',
|
|
315
|
+
'team_task_update',
|
|
316
|
+
]
|
|
317
|
+
const DEFAULT_BLOCKED_NATIVE_TOOLS = ['subagent_fork', 'workflow']
|
|
318
|
+
/** The whitelist key the panel reads and writes, and the Team compatibility switch it reads. */
|
|
310
319
|
const ALLOW_KEY = 'allowedTools'
|
|
320
|
+
const ALLOW_AGENT_TEAM_KEY = 'allowAgentTeam'
|
|
311
321
|
/** The read-only config field the host publishes the live catalog into. */
|
|
312
322
|
const CATALOG_KEY = 'toolCatalog'
|
|
313
323
|
|
|
@@ -338,18 +348,20 @@ window.__ModuleLoader__.load({
|
|
|
338
348
|
return live.length > 0 ? live : remembered ?? []
|
|
339
349
|
}
|
|
340
350
|
|
|
351
|
+
function shippedToolsOf(catalog, allowAgentTeam = true) {
|
|
352
|
+
const team = allowAgentTeam === false ? [] : NATIVE_TEAM_TOOLS.filter((name) => catalog.includes(name))
|
|
353
|
+
return [...DEFAULT_ALLOWED_TOOLS, ...team]
|
|
354
|
+
}
|
|
355
|
+
|
|
341
356
|
/**
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
* when the shipped list does not know it, and starts unchecked — a tool the user never
|
|
345
|
-
* allowed, including one a plugin or MCP server registered later, stays blocked for the
|
|
346
|
-
* main agent until it is checked here.
|
|
357
|
+
* The base whitelist and registered Team support come first. Other catalog or profile
|
|
358
|
+
* names are listed alphabetically, including native tools a profile can opt in to.
|
|
347
359
|
*/
|
|
348
|
-
function toolListOf(value, catalog) {
|
|
349
|
-
const listed =
|
|
360
|
+
function toolListOf(value, catalog = catalogOf(value)) {
|
|
361
|
+
const listed = shippedToolsOf(catalog)
|
|
350
362
|
const seen = new Set(listed)
|
|
351
363
|
const extras = new Set()
|
|
352
|
-
for (const name of catalog
|
|
364
|
+
for (const name of catalog) {
|
|
353
365
|
if (seen.has(name)) continue
|
|
354
366
|
extras.add(name)
|
|
355
367
|
}
|
|
@@ -361,13 +373,15 @@ window.__ModuleLoader__.load({
|
|
|
361
373
|
}
|
|
362
374
|
|
|
363
375
|
/**
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
* stay distinct: `[]` means "allow nothing", `undefined` means "ship defaults".
|
|
376
|
+
* Mirrors the host's resolveEffectiveAllowedTools() for the settings catalog. An
|
|
377
|
+
* explicit array replaces the defaults (`[]` included); the Team switch can suppress
|
|
378
|
+
* Team names even when they were explicitly stored.
|
|
368
379
|
*/
|
|
369
|
-
function allowedSetOf(value) {
|
|
370
|
-
|
|
380
|
+
function allowedSetOf(value, catalog = catalogOf(value)) {
|
|
381
|
+
const allowAgentTeam = value?.[ALLOW_AGENT_TEAM_KEY]
|
|
382
|
+
if (!Array.isArray(value?.[ALLOW_KEY])) return new Set(shippedToolsOf(catalog, allowAgentTeam))
|
|
383
|
+
const names = namesOf(value, ALLOW_KEY)
|
|
384
|
+
return new Set(allowAgentTeam === false ? names.filter((name) => !NATIVE_TEAM_TOOLS.includes(name)) : names)
|
|
371
385
|
}
|
|
372
386
|
|
|
373
387
|
/** Case-insensitive substring match on the tool name; an empty query keeps every row. */
|
|
@@ -378,15 +392,20 @@ window.__ModuleLoader__.load({
|
|
|
378
392
|
}
|
|
379
393
|
|
|
380
394
|
/**
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* schema default instead of pinning a copy of this build's list; anything else — extra
|
|
384
|
-
* names, a removed name, or an emptied whitelist — is stored verbatim.
|
|
395
|
+
* A set equal to the current defaults clears the override. While Team is switched
|
|
396
|
+
* off, changing another checkbox must not discard a stored Team preference.
|
|
385
397
|
*/
|
|
386
|
-
function allowOps(checked) {
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
|
|
398
|
+
function allowOps(checked, value, catalog = catalogOf(value)) {
|
|
399
|
+
const allowAgentTeam = value?.[ALLOW_AGENT_TEAM_KEY]
|
|
400
|
+
const next = new Set(checked)
|
|
401
|
+
if (allowAgentTeam === false) {
|
|
402
|
+
for (const name of namesOf(value, ALLOW_KEY)) {
|
|
403
|
+
if (NATIVE_TEAM_TOOLS.includes(name)) next.add(name)
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const list = [...next]
|
|
407
|
+
const defaults = shippedToolsOf(catalog, allowAgentTeam)
|
|
408
|
+
const isDefault = list.length === defaults.length && defaults.every((name) => next.has(name))
|
|
390
409
|
return [isDefault ? { op: 'unset', path: [ALLOW_KEY] } : { op: 'set', path: [ALLOW_KEY], value: list }]
|
|
391
410
|
}
|
|
392
411
|
|
|
@@ -726,6 +745,49 @@ window.__ModuleLoader__.load({
|
|
|
726
745
|
return scope.getSnapshot()
|
|
727
746
|
}
|
|
728
747
|
|
|
748
|
+
/** Subscribe to a host snapshot store without requiring a newer React API. */
|
|
749
|
+
function useExternalSnapshot(store) {
|
|
750
|
+
const [, bump] = React.useReducer((n) => n + 1, 0)
|
|
751
|
+
React.useEffect(() => {
|
|
752
|
+
if (store === undefined || typeof store.subscribe !== 'function') return undefined
|
|
753
|
+
return store.subscribe(() => bump())
|
|
754
|
+
}, [store])
|
|
755
|
+
return store !== undefined && typeof store.getSnapshot === 'function' ? store.getSnapshot() : undefined
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/** Resolve a usable per-session host directory, or leave the caller on the RPC fallback. */
|
|
759
|
+
function resolveModelDirectory(modelDirectories, sessionId) {
|
|
760
|
+
if (
|
|
761
|
+
modelDirectories === undefined ||
|
|
762
|
+
sessionId === undefined ||
|
|
763
|
+
sessionId === null ||
|
|
764
|
+
sessionId === '' ||
|
|
765
|
+
typeof modelDirectories.directoryFor !== 'function'
|
|
766
|
+
) return undefined
|
|
767
|
+
try {
|
|
768
|
+
const directory = modelDirectories.directoryFor(sessionId)
|
|
769
|
+
const store = directory?.store
|
|
770
|
+
return store !== undefined && typeof store.subscribe === 'function' && typeof store.getSnapshot === 'function'
|
|
771
|
+
? directory
|
|
772
|
+
: undefined
|
|
773
|
+
} catch {
|
|
774
|
+
return undefined
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/** Read host model-directory lifecycle and groups. */
|
|
779
|
+
function useModelDirectory(directory) {
|
|
780
|
+
const snapshot = useExternalSnapshot(directory?.store)
|
|
781
|
+
if (directory === undefined || snapshot === undefined) {
|
|
782
|
+
return { groups: undefined, loading: false, error: null }
|
|
783
|
+
}
|
|
784
|
+
return {
|
|
785
|
+
groups: Array.isArray(snapshot.groups) ? snapshot.groups : [],
|
|
786
|
+
loading: snapshot.status === 'idle' || snapshot.status === 'loading',
|
|
787
|
+
error: typeof snapshot.error === 'string' && snapshot.error !== '' ? snapshot.error : null,
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
729
791
|
/**
|
|
730
792
|
* The subagent check interval. Edits stay local until blur or Enter; invalid input is
|
|
731
793
|
* rejected without writing and the shown value snaps back to the stored one. The panel's
|
|
@@ -1053,6 +1115,64 @@ window.__ModuleLoader__.load({
|
|
|
1053
1115
|
)
|
|
1054
1116
|
}
|
|
1055
1117
|
|
|
1118
|
+
function worktreeIsolationOf(config) {
|
|
1119
|
+
return config?.worktreeIsolationEnabled ?? true
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/** Toggle the default for future write dispatches without pinning any tool preferences. */
|
|
1123
|
+
function WorktreeIsolationField({ scope, t }) {
|
|
1124
|
+
const snapshot = useScope(scope)
|
|
1125
|
+
const checked = worktreeIsolationOf(snapshot.value)
|
|
1126
|
+
const editable = snapshot.status === 'ready' && snapshot.writable === true
|
|
1127
|
+
const [busy, setBusy] = React.useState(false)
|
|
1128
|
+
const [problem, setProblem] = React.useState(null)
|
|
1129
|
+
const alive = React.useRef(true)
|
|
1130
|
+
React.useEffect(() => {
|
|
1131
|
+
alive.current = true
|
|
1132
|
+
return () => {
|
|
1133
|
+
alive.current = false
|
|
1134
|
+
}
|
|
1135
|
+
}, [])
|
|
1136
|
+
|
|
1137
|
+
const toggle = async (on) => {
|
|
1138
|
+
if (busy) return
|
|
1139
|
+
const live = scope.getSnapshot()
|
|
1140
|
+
if (live.status !== 'ready' || live.writable !== true) {
|
|
1141
|
+
setProblem(t('route.readonly'))
|
|
1142
|
+
return
|
|
1143
|
+
}
|
|
1144
|
+
setBusy(true)
|
|
1145
|
+
setProblem(null)
|
|
1146
|
+
try {
|
|
1147
|
+
await scope.mutate([{ op: 'set', path: ['worktreeIsolationEnabled'], value: on }], live.revision)
|
|
1148
|
+
if (alive.current && worktreeIsolationOf(scope.getSnapshot().value) !== on) {
|
|
1149
|
+
setProblem(t('route.enableFailed'))
|
|
1150
|
+
}
|
|
1151
|
+
} catch {
|
|
1152
|
+
if (alive.current) setProblem(t('route.enableFailed'))
|
|
1153
|
+
} finally {
|
|
1154
|
+
if (alive.current) setBusy(false)
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
return h(
|
|
1159
|
+
'div',
|
|
1160
|
+
{ style: { display: 'grid', gap: '4px' } },
|
|
1161
|
+
h(
|
|
1162
|
+
'div',
|
|
1163
|
+
{ style: { display: 'flex', alignItems: 'center', gap: '10px' } },
|
|
1164
|
+
h(
|
|
1165
|
+
'div',
|
|
1166
|
+
{ style: { display: 'grid', gap: '2px', flex: '1 1 auto', minWidth: 0 } },
|
|
1167
|
+
h('span', { style: { fontWeight: 600 } }, t('worktreeIsolation.label')),
|
|
1168
|
+
h('span', { style: { color: 'var(--dsw-alias-label-tertiary, inherit)', lineHeight: 1.3 } }, t('worktreeIsolation.hint')),
|
|
1169
|
+
),
|
|
1170
|
+
h(EnableSwitch, { checked, disabled: busy || !editable, onChange: toggle, label: t('worktreeIsolation.label') }),
|
|
1171
|
+
),
|
|
1172
|
+
problem === null ? null : h('div', { role: 'alert', style: { color: 'var(--dsw-alias-label-error, #ff7b72)' } }, problem),
|
|
1173
|
+
)
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1056
1176
|
/**
|
|
1057
1177
|
* The right-hand column: one checkbox per tool the host offers, searched by name.
|
|
1058
1178
|
* Whitelist-driven — checked means the main agent may use the tool, and everything
|
|
@@ -1080,7 +1200,8 @@ window.__ModuleLoader__.load({
|
|
|
1080
1200
|
const live = catalogFor(snapshot.value, remembered.current)
|
|
1081
1201
|
if (live.length > 0) remembered.current = live
|
|
1082
1202
|
const names = toolListOf(snapshot.value, live)
|
|
1083
|
-
const allowed = allowedSetOf(snapshot.value)
|
|
1203
|
+
const allowed = allowedSetOf(snapshot.value, live)
|
|
1204
|
+
const teamEnabled = snapshot.value?.[ALLOW_AGENT_TEAM_KEY] !== false
|
|
1084
1205
|
const visible = filterTools(names, query)
|
|
1085
1206
|
const editable = snapshot.status === 'ready' && snapshot.writable === true
|
|
1086
1207
|
|
|
@@ -1108,7 +1229,7 @@ window.__ModuleLoader__.load({
|
|
|
1108
1229
|
const next = new Set(allowed)
|
|
1109
1230
|
if (on) next.add(name)
|
|
1110
1231
|
else next.delete(name)
|
|
1111
|
-
return write(allowOps(next))
|
|
1232
|
+
return write(allowOps(next, snapshot.value, live))
|
|
1112
1233
|
}
|
|
1113
1234
|
|
|
1114
1235
|
return h(
|
|
@@ -1152,21 +1273,26 @@ window.__ModuleLoader__.load({
|
|
|
1152
1273
|
{ style: { padding: '6px 8px', color: 'var(--dsw-alias-label-tertiary, inherit)', lineHeight: 1.4 } },
|
|
1153
1274
|
t('allowed.empty'),
|
|
1154
1275
|
)
|
|
1155
|
-
: visible.map((name) =>
|
|
1156
|
-
|
|
1276
|
+
: visible.map((name) => {
|
|
1277
|
+
const teamDisabled = !teamEnabled && NATIVE_TEAM_TOOLS.includes(name)
|
|
1278
|
+
const disabled = saving || !editable || teamDisabled
|
|
1279
|
+
const hint = teamDisabled
|
|
1280
|
+
? t('allowed.teamDisabled')
|
|
1281
|
+
: DEFAULT_BLOCKED_NATIVE_TOOLS.includes(name) ? t('allowed.nativeBlocked') : undefined
|
|
1282
|
+
return h(
|
|
1157
1283
|
'label',
|
|
1158
1284
|
{ key: name, style: allowedRowStyle(allowed.has(name)), 'data-tool': name },
|
|
1159
1285
|
h('input', {
|
|
1160
1286
|
type: 'checkbox',
|
|
1161
1287
|
checked: allowed.has(name),
|
|
1162
|
-
disabled
|
|
1288
|
+
disabled,
|
|
1163
1289
|
'aria-label': name,
|
|
1164
|
-
style: allowedCheckboxStyle(!
|
|
1290
|
+
style: allowedCheckboxStyle(!disabled),
|
|
1165
1291
|
onChange: (event) => toggle(name, event.target.checked),
|
|
1166
1292
|
}),
|
|
1167
|
-
h('span', { style: allowedNameStyle, title: name }, name),
|
|
1168
|
-
)
|
|
1169
|
-
),
|
|
1293
|
+
h('span', { style: allowedNameStyle, title: hint === undefined ? name : `${name}: ${hint}` }, name),
|
|
1294
|
+
)
|
|
1295
|
+
}),
|
|
1170
1296
|
),
|
|
1171
1297
|
),
|
|
1172
1298
|
problem === null ? null : h('div', { role: 'alert', style: { color: 'var(--dsw-alias-label-error, #ff7b72)' } }, problem),
|
|
@@ -1437,34 +1563,55 @@ window.__ModuleLoader__.load({
|
|
|
1437
1563
|
)
|
|
1438
1564
|
}
|
|
1439
1565
|
/** Button plus panel: pick the default model and effort for the main agent and for workers. */
|
|
1440
|
-
function RoutePicker({ t, scopes, orch, loadCatalog }) {
|
|
1566
|
+
function RoutePicker({ t, scopes, orch, loadCatalog, modelDirectories, sessionId }) {
|
|
1441
1567
|
const [open, setOpen] = React.useState(false)
|
|
1442
1568
|
const [room, setRoom] = React.useState(null)
|
|
1443
1569
|
const anchor = React.useRef(null)
|
|
1444
|
-
const [
|
|
1570
|
+
const [fallback, setFallback] = React.useState({ groups: undefined, loading: false })
|
|
1445
1571
|
const [problem, setProblem] = React.useState(null)
|
|
1446
1572
|
const [saving, setSaving] = React.useState(false)
|
|
1573
|
+
const request = React.useRef(0)
|
|
1574
|
+
const loader = React.useRef(loadCatalog)
|
|
1575
|
+
loader.current = loadCatalog
|
|
1447
1576
|
const main = useScope(scopes.main)
|
|
1448
1577
|
const worker = useScope(scopes.worker)
|
|
1449
1578
|
const plugin = useScope(orch)
|
|
1579
|
+
const directory = resolveModelDirectory(modelDirectories, sessionId)
|
|
1580
|
+
const directoryState = useModelDirectory(directory)
|
|
1581
|
+
const usingDirectory = directory !== undefined
|
|
1582
|
+
const groups = usingDirectory ? directoryState.groups : fallback.groups
|
|
1583
|
+
const catalogProblem = usingDirectory ? directoryState.error : problem
|
|
1450
1584
|
|
|
1451
1585
|
React.useEffect(() => {
|
|
1452
|
-
if (
|
|
1586
|
+
if (usingDirectory || !open) return undefined
|
|
1587
|
+
const current = request.current + 1
|
|
1588
|
+
request.current = current
|
|
1453
1589
|
let live = true
|
|
1454
|
-
|
|
1590
|
+
setProblem(null)
|
|
1591
|
+
setFallback((previous) => ({ ...previous, loading: true }))
|
|
1592
|
+
Promise.resolve().then(() => {
|
|
1593
|
+
if (typeof loader.current !== 'function') throw new Error('model catalog loader unavailable')
|
|
1594
|
+
return loader.current()
|
|
1595
|
+
}).then(
|
|
1455
1596
|
(response) => {
|
|
1456
|
-
if (!live) return
|
|
1457
|
-
if (response
|
|
1458
|
-
|
|
1597
|
+
if (!live || request.current !== current) return
|
|
1598
|
+
if (response?.ok === true && Array.isArray(response.value?.groups)) {
|
|
1599
|
+
setFallback({ groups: response.value.groups, loading: false })
|
|
1600
|
+
return
|
|
1601
|
+
}
|
|
1602
|
+
setFallback((previous) => ({ ...previous, loading: false }))
|
|
1603
|
+
setProblem(t('route.catalogFailed'))
|
|
1459
1604
|
},
|
|
1460
1605
|
() => {
|
|
1461
|
-
if (live
|
|
1606
|
+
if (!live || request.current !== current) return
|
|
1607
|
+
setFallback((previous) => ({ ...previous, loading: false }))
|
|
1608
|
+
setProblem(t('route.catalogFailed'))
|
|
1462
1609
|
},
|
|
1463
1610
|
)
|
|
1464
1611
|
return () => {
|
|
1465
1612
|
live = false
|
|
1466
1613
|
}
|
|
1467
|
-
}, [open,
|
|
1614
|
+
}, [open, usingDirectory])
|
|
1468
1615
|
|
|
1469
1616
|
const write = async (which, route) => {
|
|
1470
1617
|
setSaving(true)
|
|
@@ -1516,6 +1663,9 @@ window.__ModuleLoader__.load({
|
|
|
1516
1663
|
const close = () => {
|
|
1517
1664
|
setOpen(false)
|
|
1518
1665
|
}
|
|
1666
|
+
const showLoading = catalogProblem === null && (
|
|
1667
|
+
groups === undefined || (usingDirectory && directoryState.loading && groups.length === 0)
|
|
1668
|
+
)
|
|
1519
1669
|
return h(
|
|
1520
1670
|
'span',
|
|
1521
1671
|
{ ref: anchor, style: { position: 'relative', display: 'inline-flex' } },
|
|
@@ -1554,7 +1704,8 @@ window.__ModuleLoader__.load({
|
|
|
1554
1704
|
label: t('route.enable'),
|
|
1555
1705
|
}),
|
|
1556
1706
|
),
|
|
1557
|
-
|
|
1707
|
+
h(WorktreeIsolationField, { scope: scopes.orch, t }),
|
|
1708
|
+
showLoading
|
|
1558
1709
|
? h('div', null, t('route.loading'))
|
|
1559
1710
|
: groups === undefined
|
|
1560
1711
|
? null
|
|
@@ -1580,7 +1731,7 @@ window.__ModuleLoader__.load({
|
|
|
1580
1731
|
],
|
|
1581
1732
|
h(SuperviseIntervalField, { scope: scopes.orch, t }),
|
|
1582
1733
|
h(SuperviseCountField, { scope: scopes.orch, t }),
|
|
1583
|
-
|
|
1734
|
+
catalogProblem === null ? null : h('div', { style: { color: 'var(--dsw-alias-label-error, #ff7b72)' }, role: 'alert' }, catalogProblem),
|
|
1584
1735
|
!writable && groups !== undefined
|
|
1585
1736
|
? h('div', { style: { color: 'var(--dsw-alias-label-tertiary, inherit)' } }, t('route.readonly'))
|
|
1586
1737
|
: null,
|
|
@@ -1597,7 +1748,6 @@ window.__ModuleLoader__.load({
|
|
|
1597
1748
|
|
|
1598
1749
|
function apply(ctx) {
|
|
1599
1750
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'orchestrator: dictionaries')
|
|
1600
|
-
|
|
1601
1751
|
const scopes = { main: ctx.configForms.get(MAIN.ns), worker: ctx.configForms.get(WORKER.ns), orch: ctx.configForms.get(NS) }
|
|
1602
1752
|
ctx.slots.inject('conversation.input.right', () =>
|
|
1603
1753
|
ctx.slots.register(
|
|
@@ -1610,6 +1760,9 @@ window.__ModuleLoader__.load({
|
|
|
1610
1760
|
scopes,
|
|
1611
1761
|
orch: scopes.orch,
|
|
1612
1762
|
loadCatalog: () => ctx.remote.session.modelCatalog(),
|
|
1763
|
+
sessionId,
|
|
1764
|
+
// Cordis property access can throw for undeclared services.
|
|
1765
|
+
modelDirectories: typeof ctx.get === 'function' ? ctx.get('modelDirectories') : ctx.modelDirectories,
|
|
1613
1766
|
}),
|
|
1614
1767
|
},
|
|
1615
1768
|
RoutePicker,
|
|
@@ -1625,7 +1778,10 @@ window.__ModuleLoader__.load({
|
|
|
1625
1778
|
WORKER,
|
|
1626
1779
|
INTERVAL,
|
|
1627
1780
|
DEFAULT_ALLOWED_TOOLS,
|
|
1781
|
+
NATIVE_TEAM_TOOLS,
|
|
1782
|
+
DEFAULT_BLOCKED_NATIVE_TOOLS,
|
|
1628
1783
|
ALLOW_KEY,
|
|
1784
|
+
ALLOW_AGENT_TEAM_KEY,
|
|
1629
1785
|
CATALOG_KEY,
|
|
1630
1786
|
namesOf,
|
|
1631
1787
|
catalogOf,
|
|
@@ -1647,6 +1803,7 @@ window.__ModuleLoader__.load({
|
|
|
1647
1803
|
allowOps,
|
|
1648
1804
|
resetAllowOps,
|
|
1649
1805
|
EnableSwitch,
|
|
1806
|
+
WorktreeIsolationField,
|
|
1650
1807
|
AllowedToolsPanel,
|
|
1651
1808
|
RoutePicker,
|
|
1652
1809
|
routeKey,
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { formatInlineAuditNotice } from './timeline.js'
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_DELEGATE_STATUS_TOOL_NAME = 'delegate_status'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_LIMIT = 20
|
|
6
|
+
const MAX_LIMIT = 64
|
|
7
|
+
|
|
8
|
+
function renderStatus({ total, counts, items }) {
|
|
9
|
+
const lines = [
|
|
10
|
+
`委派验收状态:共 ${total} 条,本次显示 ${items.length} 条。`,
|
|
11
|
+
`运行中 ${counts.running};已结束待审计 ${counts.endedPendingAudit};审计通过 ${counts.auditPassed};` +
|
|
12
|
+
`审计失败 ${counts.auditFailed};未纳入审计 ${counts.auditUnmanaged}。`,
|
|
13
|
+
`工作树待评审 ${counts.worktreePendingReview}。`,
|
|
14
|
+
]
|
|
15
|
+
if (items.length === 0) {
|
|
16
|
+
lines.push('当前会话没有符合条件的委派记录;缺少记录不代表验收通过。')
|
|
17
|
+
}
|
|
18
|
+
for (const entry of items) {
|
|
19
|
+
const { childId, agentName, label, dispatchState, auditState, leaseState, baselineId, worktree } = entry
|
|
20
|
+
const delivery = worktree ? ` [wt:${worktree.id} ${worktree.state}]` : ''
|
|
21
|
+
const address = agentName ? `(${agentName})` : ''
|
|
22
|
+
lines.push(`【${childId}】${address}${label ?? '未命名任务'}:执行 ${dispatchState};审计 ${auditState};` +
|
|
23
|
+
`租约 ${leaseState};基线 ${baselineId ?? '无'}。${delivery}`)
|
|
24
|
+
if (auditState === 'failed') {
|
|
25
|
+
lines.push(formatInlineAuditNotice([{ childId, entry }]))
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return [{ type: 'text', text: lines.join('\n') }]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function summarizeWorktree(worktree) {
|
|
32
|
+
if (worktree == null) return null
|
|
33
|
+
const { id, branch, state, commits, dirty, locked, path } = worktree
|
|
34
|
+
return { id, branch, state, commits, dirty, locked, path }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createDelegateStatusTool({
|
|
38
|
+
timeline,
|
|
39
|
+
toolName = DEFAULT_DELEGATE_STATUS_TOOL_NAME,
|
|
40
|
+
isRootAgent,
|
|
41
|
+
defineTool = (definition) => definition,
|
|
42
|
+
} = {}) {
|
|
43
|
+
return defineTool({
|
|
44
|
+
name: toolName,
|
|
45
|
+
description: '只读查询当前根代理会话直接委派的子代理执行、写作用域审计、租约及工作树交付状态;验收前用于核验终态。',
|
|
46
|
+
parameters: {
|
|
47
|
+
childId: { type: 'string', description: '可选:只查询当前会话下此 ID 对应的子代理。' },
|
|
48
|
+
includeCompleted: { type: 'boolean', default: true, description: '是否包含执行已结束的子代理。' },
|
|
49
|
+
limit: {
|
|
50
|
+
type: 'integer',
|
|
51
|
+
// The host author schema supports enum, not minimum/maximum.
|
|
52
|
+
enum: Array.from({ length: MAX_LIMIT }, (_, index) => index + 1),
|
|
53
|
+
default: DEFAULT_LIMIT,
|
|
54
|
+
description: `最多返回条数(1..${MAX_LIMIT},默认 ${DEFAULT_LIMIT})。`,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
output: {
|
|
58
|
+
schema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
properties: {
|
|
62
|
+
content: {
|
|
63
|
+
type: 'array',
|
|
64
|
+
items: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
additionalProperties: false,
|
|
67
|
+
properties: { type: { type: 'string', const: 'text' }, text: { type: 'string' } },
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
details: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
additionalProperties: false,
|
|
73
|
+
properties: {
|
|
74
|
+
parentId: { type: 'string' },
|
|
75
|
+
total: { type: 'integer' },
|
|
76
|
+
counts: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
additionalProperties: false,
|
|
79
|
+
properties: {
|
|
80
|
+
running: { type: 'integer' },
|
|
81
|
+
endedPendingAudit: { type: 'integer' },
|
|
82
|
+
auditPassed: { type: 'integer' },
|
|
83
|
+
auditFailed: { type: 'integer' },
|
|
84
|
+
auditUnmanaged: { type: 'integer' },
|
|
85
|
+
worktreePendingReview: { type: 'integer' },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
items: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
render: (_args, value) => value.content,
|
|
94
|
+
},
|
|
95
|
+
isConcurrencySafe: () => true,
|
|
96
|
+
async execute(args, exec) {
|
|
97
|
+
const parent = exec?.agent
|
|
98
|
+
// The delegate path keys its records by exec.agent.id, not by a caller-supplied id.
|
|
99
|
+
const parentId = parent?.id
|
|
100
|
+
if (typeof parentId !== 'string' || parentId.trim() === '') {
|
|
101
|
+
throw new Error(`${toolName} 无法识别调用代理的会话 ID,拒绝查询。`)
|
|
102
|
+
}
|
|
103
|
+
if (isRootAgent !== undefined && (typeof isRootAgent !== 'function' || !isRootAgent(parent))) {
|
|
104
|
+
throw new Error(`${toolName} 仅限根代理调用,子代理不能查询委派验收状态。`)
|
|
105
|
+
}
|
|
106
|
+
if (Object.hasOwn(args ?? {}, 'parentId')) {
|
|
107
|
+
throw new Error(`${toolName} 不接受 parentId 参数,只能查询调用方自己的委派记录。`)
|
|
108
|
+
}
|
|
109
|
+
const { childId, includeCompleted = true, limit = DEFAULT_LIMIT } = args ?? {}
|
|
110
|
+
if (childId !== undefined && (typeof childId !== 'string' || childId.trim() === '')) {
|
|
111
|
+
throw new Error('childId 必须是非空字符串。')
|
|
112
|
+
}
|
|
113
|
+
if (typeof includeCompleted !== 'boolean') throw new Error('includeCompleted 必须是布尔值。')
|
|
114
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > MAX_LIMIT) {
|
|
115
|
+
throw new Error(`limit 必须是 1..${MAX_LIMIT} 之间的整数。`)
|
|
116
|
+
}
|
|
117
|
+
const report = timeline.queryParent(parentId, { childId, includeCompleted, limit })
|
|
118
|
+
const details = {
|
|
119
|
+
...report,
|
|
120
|
+
items: report.items.map((entry) => ({ ...entry, worktree: summarizeWorktree(entry.worktree) })),
|
|
121
|
+
}
|
|
122
|
+
return { content: renderStatus(report), details }
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
}
|