dsh-dispatch-board 0.2.3 → 0.2.4
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 +9 -1
- package/lib/client.js +266 -32
- package/lib/index.js +578 -11
- package/package.json +1 -1
- package/presets/taskboard.patch.yml +11 -7
package/README.md
CHANGED
|
@@ -70,7 +70,11 @@ v0.2.0 起不用再手动开「派单模式」对话,也不需要每个任务
|
|
|
70
70
|
|
|
71
71
|
- 左侧栏多一个「任务看板」面板图标(带 全部待开始+进行中 的数量角标)。
|
|
72
72
|
- 整页显示**全平台所有工作区**的任务;顶部有工作区过滤(全部 / 单个,**会记住上次的选择**,刷新页面 /
|
|
73
|
-
|
|
73
|
+
重启后自动恢复),卡片显示标题 + 一行工作区标签 + 操作按钮,备注 / 结论等其余信息仍在详情浮层里看。
|
|
74
|
+
- **工作区标签(v0.2.4)**:卡片标题与操作行之间一行小字,文本优先取工作区 `title`;工作区未注册 /
|
|
75
|
+
`title` 为空时回退目录名(`cwd` 路径尾段),任务没有 `cwd` 显示 `—`。标签**只加在平台看板**
|
|
76
|
+
(第五列「待你处理」的卡片同样有);右栏会话看板不重复显示,工作区只在详情浮层里看(右栏整块看板
|
|
77
|
+
本来就绑定单个工作区)。
|
|
74
78
|
- 头部同样有「派发到」选择器与**组长条**(全部工作区组长列表;缺失时可「创建组长」)。
|
|
75
79
|
- 新建任务**必须选工作区**(下拉来自 DSH 的工作区列表,**会记住上次选的工作区**,刷新页面 /
|
|
76
80
|
去别的会话再点回来都会自动恢复;与顶部过滤器各自记忆、互不串值):默认模式下任务投给该工作区的常驻组长;
|
|
@@ -129,6 +133,8 @@ dsh web
|
|
|
129
133
|
3. **组长自动派发**:宿主每 15s 轮询一次「待开始」,按任务工作区找到 / 创建常驻组长并投递
|
|
130
134
|
`【任务看板 · 待开始】t-3 …`;组长先把任务改成「进行中」,再派 worker 子 Agent 后台干活,
|
|
131
135
|
自己结束本轮(不占对话)。一个工作区只有一个组长,不会每个任务新建会话。
|
|
136
|
+
**派发前强制建卡**:宿主在 worker 启动前认领 / 新建看板卡片,卡片写不进 `board.json` 时会拒绝派发
|
|
137
|
+
(worker 不会启动),不会出现「派了活但看板看不到」。
|
|
132
138
|
4. **审核 + 完成回执**:worker 完成后,运行时把完成通知送回组长;组长对工作区取证审核:
|
|
133
139
|
- 通过 → 看板任务变「已完成」,`result` 里是结论;插件在主会话空闲时把一批结果合并成
|
|
134
140
|
「【任务看板 · 汇报】…」推给主会话,主会话向你汇总;
|
|
@@ -142,6 +148,8 @@ dsh web
|
|
|
142
148
|
**工作区组长模式(默认)**
|
|
143
149
|
|
|
144
150
|
- 按任务工作区路由到该工作区的常驻组长,**不会每任务新建会话**、也不跨工作区改派;
|
|
151
|
+
- **派发前强制建卡**:组长每次 `subagent` 派发都先认领 / 新建看板卡片(直聊派活也会自动出现
|
|
152
|
+
`doing` 卡片);建卡写盘失败 → 派发被拒绝、worker 不启动,不会出现「worker 在跑、看板没记录」;
|
|
145
153
|
- 组长忙 → 任务留在「待开始」等下一轮;组长离线 / 唤醒失败 → 跳过并提示「工作区组长不可用」
|
|
146
154
|
(点组长条的「创建组长」可修复);
|
|
147
155
|
- 只在组长会话**空闲**(idle)时投递;投递成功即自动置「进行中」;
|
package/lib/client.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* sidebar.right.pane.tab / .title 提供正文与 chip,conversation.session.header.actions
|
|
7
7
|
* 提供会话 header 入口按钮;只显示 cwd 与当前会话工作区相同的任务(窄栏 lane / 宽栏四列)。
|
|
8
8
|
* 2. 左侧栏「平台任务看板」—— sidebar.panellist 入口图标(todo+doing 角标)+ main
|
|
9
|
-
* (key: taskboard-platform)
|
|
10
|
-
*
|
|
9
|
+
* (key: taskboard-platform) 页面;显示全部工作区的任务(卡片显示标题 + 一行工作区标签 +
|
|
10
|
+
* 操作按钮,备注 / 结论等信息都在详情浮层;右栏看板没有这行标签,工作区只在详情里看),
|
|
11
11
|
* 新建任务必须选工作区(add-task 传 cwd,不传 sessionId)。
|
|
12
12
|
*
|
|
13
13
|
* 数据通道:Host 在 webServer 注册的 /taskboard 前缀路由,经 Connection RPC 信封调用
|
|
@@ -127,8 +127,14 @@ window.__ModuleLoader__.load({
|
|
|
127
127
|
// ── 卡片 ───────────────────────────────────────────────────
|
|
128
128
|
// 卡片正文只有标题 + 操作按钮:note / result / lastError / meta 全部收进详情浮层,
|
|
129
129
|
// 看板上只靠标题辨认任务(完整信息点标题看详情)。
|
|
130
|
+
// 唯一例外:全局平台看板多一行工作区标签(.tb-card-workspace,v0.2.4),
|
|
131
|
+
// 右栏看板不传 workspaceLabel,卡片结构维持「标题 + 操作按钮」不变。
|
|
130
132
|
'.tb-card{display:flex;flex-direction:column;gap:6px;padding:9px 10px;background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-l1);border-left:3px solid var(--tb-accent);border-radius:var(--dsw-radius-sm);min-width:0;box-sizing:border-box}',
|
|
131
133
|
'.tb-card-title{font:var(--dsw-font-xxs-strong-12);font-weight:600;line-height:1.45;word-break:break-word}',
|
|
134
|
+
// 平台看板卡片上的一行工作区标签(v0.2.4):单行、超长省略,标题仍是第一眼信息。
|
|
135
|
+
// 只有全局看板的 Col 传入 workspaceLabel 时才渲染(右栏看板绑定单个工作区,不重复显示)。
|
|
136
|
+
'.tb-card-workspace{display:block;min-width:0;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:var(--dsw-font-xxxs-11);color:var(--dsw-alias-label-tertiary);letter-spacing:0}',
|
|
137
|
+
'.tb-card-workspace[data-empty=true]{opacity:.65}',
|
|
132
138
|
'.tb-card-actions{display:flex;align-items:center;gap:4px;flex-wrap:wrap;padding-top:2px}',
|
|
133
139
|
'.tb-edit{display:flex;flex-direction:column;gap:6px}',
|
|
134
140
|
'.tb-edit-actions{display:flex;align-items:center;gap:6px;justify-content:flex-end}',
|
|
@@ -175,6 +181,8 @@ window.__ModuleLoader__.load({
|
|
|
175
181
|
'.tb-detail{width:100%;max-width:900px;max-height:calc(100vh - 48px);display:flex;flex-direction:column;overflow:hidden;background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-l1);border-radius:14px;box-shadow:0 28px 72px rgba(0,0,0,.42);animation:tb-pop-in .14s ease-out}',
|
|
176
182
|
'@keyframes tb-pop-in{from{transform:translateY(6px) scale(.99);opacity:.6}to{transform:none;opacity:1}}',
|
|
177
183
|
'.tb-detail-head{display:flex;align-items:flex-start;gap:10px;padding:13px 16px 10px;border-bottom:1px solid var(--dsw-alias-border-l1);flex:0 0 auto}',
|
|
184
|
+
// 浮层内提示条(t-71):遮罩 z-index:9000 会盖住看板顶部横幅,跳转失败必须就近显示在浮层里。
|
|
185
|
+
'.tb-detail-banner{flex:0 0 auto;padding:10px 16px 0}',
|
|
178
186
|
'.tb-detail-headline{flex:1 1 auto;min-width:0;display:flex;flex-direction:column;gap:6px}',
|
|
179
187
|
'.tb-detail-badges{display:flex;flex-wrap:wrap;align-items:center;gap:5px}',
|
|
180
188
|
'.tb-detail-title{margin:0;font:var(--dsw-font-sm-13);font-weight:600;line-height:1.4;color:var(--dsw-alias-label-primary);word-break:break-word}',
|
|
@@ -349,6 +357,7 @@ window.__ModuleLoader__.load({
|
|
|
349
357
|
'.tb-card{background:var(--tb-surface);border:1px solid var(--tb-hairline-soft);border-left:1px solid var(--tb-hairline-soft);border-radius:var(--dsw-radius-md,12px);padding:10px 11px;box-shadow:var(--tb-shadow-1);transition:box-shadow .18s ease,transform .18s ease,border-color .18s ease}',
|
|
350
358
|
'.tb-card:hover{box-shadow:var(--tb-shadow-2);border-color:var(--tb-hairline);transform:translateY(-1px)}',
|
|
351
359
|
'.tb-card-title{font:600 12.5px/1.45 var(--dsh-font-family-text-default,-apple-system,sans-serif);color:var(--tb-text);letter-spacing:0}',
|
|
360
|
+
'.tb-card-workspace{color:var(--tb-text-3);font-size:10px;line-height:1.45}',
|
|
352
361
|
'.tb-empty{color:var(--tb-text-3);font-size:11px;padding:12px 6px;text-align:center;border:0;background:transparent}',
|
|
353
362
|
'.tb-foot{color:var(--tb-text-3);font-size:10px;padding-top:2px;border-top:1px solid var(--tb-hairline-soft)}',
|
|
354
363
|
'.tb-foot code{background:var(--dsw-alias-bg-skeleton);border-radius:5px;padding:1px 5px;font-size:9.5px}',
|
|
@@ -502,6 +511,9 @@ window.__ModuleLoader__.load({
|
|
|
502
511
|
'card.deleteConfirmShort': '确认删除',
|
|
503
512
|
'card.detail': '详情',
|
|
504
513
|
'card.openChat': '对话',
|
|
514
|
+
// v0.2.4:点「对话」失败不再静默(服务缺失 / 目标会话已关闭或不存在)。
|
|
515
|
+
'openSession.failed': '无法打开对话:会话 {session} 已关闭或不存在',
|
|
516
|
+
'openSession.unavailable': '无法打开对话:会话导航服务未就绪,请稍后重试',
|
|
505
517
|
'detail.sessions': '关联对话',
|
|
506
518
|
'detail.creatorSession': '发起对话',
|
|
507
519
|
'detail.runSession': '执行对话',
|
|
@@ -685,6 +697,9 @@ window.__ModuleLoader__.load({
|
|
|
685
697
|
'card.deleteConfirmShort': 'Confirm delete',
|
|
686
698
|
'card.detail': 'Details',
|
|
687
699
|
'card.openChat': 'Chat',
|
|
700
|
+
// Unreleased (0.2.4 candidate): a failed 对话 click must never be silent.
|
|
701
|
+
'openSession.failed': 'Cannot open conversation: session {session} is closed or unavailable',
|
|
702
|
+
'openSession.unavailable': 'Cannot open conversation: session navigation is not ready yet, please retry',
|
|
688
703
|
'detail.sessions': 'Linked conversations',
|
|
689
704
|
'detail.creatorSession': 'Created in',
|
|
690
705
|
'detail.runSession': 'Dispatched to',
|
|
@@ -939,6 +954,23 @@ window.__ModuleLoader__.load({
|
|
|
939
954
|
return baseName(path)
|
|
940
955
|
}
|
|
941
956
|
|
|
957
|
+
/** 卡片工作区标签的兜底占位:任务没有 cwd(老任务 / 没归属)时显示。 */
|
|
958
|
+
const WORKSPACE_LABEL_NONE = '\u2014'
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* 平台看板卡片上的一行工作区标签(v0.2.4):只给**全局看板**用,
|
|
962
|
+
* 右栏看板不调用(那块看板绑定单个工作区,再标一遍是重复信息)。
|
|
963
|
+
* - `cwd` 命中 `snapshot.workspaces` → 用该工作区的 `title`;
|
|
964
|
+
* - `cwd` 未注册 / `title` 为空 → 回退路径尾段 `baseName(cwd)`(与下拉选项同一规则);
|
|
965
|
+
* - `cwd` 为空 / 非字符串 → `—` 占位(不抛错,渲染里不会出现 undefined)。
|
|
966
|
+
*/
|
|
967
|
+
function taskWorkspaceLabel(workspaces, task) {
|
|
968
|
+
const cwd = task && typeof task.cwd === 'string' ? task.cwd : ''
|
|
969
|
+
if (cwd === '') return WORKSPACE_LABEL_NONE
|
|
970
|
+
const label = workspaceTitleOf(workspaces, cwd)
|
|
971
|
+
return label !== '' ? label : WORKSPACE_LABEL_NONE
|
|
972
|
+
}
|
|
973
|
+
|
|
942
974
|
/**
|
|
943
975
|
* 右栏「本工作区看板」的过滤:
|
|
944
976
|
* - cwd 与当前工作区相同的任务;或
|
|
@@ -1894,20 +1926,55 @@ window.__ModuleLoader__.load({
|
|
|
1894
1926
|
// 用会话 header / 右栏看板渲染时记下的值当「当前对话」;拿不到就禁用主会话绑定并提示。
|
|
1895
1927
|
let lastConversationSessionId = ''
|
|
1896
1928
|
|
|
1897
|
-
/**
|
|
1929
|
+
/**
|
|
1930
|
+
* 在看板里直接跳到某个会话(发起对话 / 执行对话 / 组长对话)。
|
|
1931
|
+
* 返回 `{ ok, reason, sessionId }`,调用方据此给用户**可见**反馈——跳转失败绝不静默:
|
|
1932
|
+
* - `invalid`:没有目标 id;
|
|
1933
|
+
* - `unavailable`:宿主没注入 `uiWorkspace`(或它没有 `openSession`);
|
|
1934
|
+
* - `error`:`openSession` 同步抛错。典型是 `sessions.retain: unknown session <id>`
|
|
1935
|
+
* (目标会话已被移除 / 客户端此刻解析不到),也可能来自会话控制器已销毁。
|
|
1936
|
+
* `uiWorkspace.openSession` 是同步 void:能抛错就说明这次导航没有发生。
|
|
1937
|
+
*/
|
|
1898
1938
|
function openSessionById(sessionId) {
|
|
1899
|
-
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
1939
|
+
if (typeof sessionId !== 'string' || sessionId === '') return { ok: false, reason: 'invalid', sessionId: '' }
|
|
1900
1940
|
if (!uiWorkspaceService || typeof uiWorkspaceService.openSession !== 'function') {
|
|
1901
1941
|
console.warn('[dsh-dispatch-board] uiWorkspace 不可用,无法跳转会话:' + sessionId)
|
|
1902
|
-
return
|
|
1942
|
+
return { ok: false, reason: 'unavailable', sessionId }
|
|
1903
1943
|
}
|
|
1904
1944
|
try {
|
|
1905
1945
|
uiWorkspaceService.openSession(sessionId)
|
|
1946
|
+
return { ok: true, sessionId }
|
|
1906
1947
|
} catch (error) {
|
|
1907
1948
|
console.warn('[dsh-dispatch-board] 跳转会话失败:' + describeErr(error))
|
|
1949
|
+
return { ok: false, reason: 'error', sessionId, error }
|
|
1908
1950
|
}
|
|
1909
1951
|
}
|
|
1910
1952
|
|
|
1953
|
+
/**
|
|
1954
|
+
* 按顺序尝试多个候选会话(worker → 组长 → 发起 → poll 兜底):
|
|
1955
|
+
* 第一个能打开的立即返回;`unavailable` 时后面的目标必然同样打不开,直接停。
|
|
1956
|
+
*/
|
|
1957
|
+
function openFirstAvailable(candidates) {
|
|
1958
|
+
const list = Array.isArray(candidates) ? candidates : []
|
|
1959
|
+
let last = { ok: false, reason: 'invalid', sessionId: '' }
|
|
1960
|
+
for (const sessionId of list) {
|
|
1961
|
+
if (typeof sessionId !== 'string' || sessionId === '') continue
|
|
1962
|
+
const result = openSessionById(sessionId)
|
|
1963
|
+
if (result.ok) return result
|
|
1964
|
+
last = result
|
|
1965
|
+
if (result.reason === 'unavailable') break
|
|
1966
|
+
}
|
|
1967
|
+
return last
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
/** 跳转失败的顶部提示文案(两块看板共用;`t` 由组件传入,保持纯函数可测)。 */
|
|
1971
|
+
function sessionFailureText(t, result, candidates) {
|
|
1972
|
+
if (result && result.reason === 'unavailable') return t('openSession.unavailable')
|
|
1973
|
+
const list = Array.isArray(candidates) ? candidates : []
|
|
1974
|
+
const first = list.find((id) => typeof id === 'string' && id !== '') || ''
|
|
1975
|
+
return t('openSession.failed', { session: shortSession(first) })
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1911
1978
|
function openBoard(retry = 0) {
|
|
1912
1979
|
if (!sidebarRightService) {
|
|
1913
1980
|
console.warn('[dsh-dispatch-board] 打开右侧看板失败:右侧栏服务不可用(需要部署里的 ui-sidebar-right)')
|
|
@@ -2128,15 +2195,28 @@ window.__ModuleLoader__.load({
|
|
|
2128
2195
|
/**
|
|
2129
2196
|
* 任务关联的会话(卡片「对话」按钮的跳转目标),优先级:
|
|
2130
2197
|
* worker 子会话(真正执行任务的对话)→ 组长会话(dispatchedSessionId)→ 发起对话(sessionId)
|
|
2131
|
-
* → 老 Host 的 poll 兜底(doing
|
|
2198
|
+
* → 老 Host 的 poll 兜底(doing)。
|
|
2199
|
+
*
|
|
2200
|
+
* 返回**去重后的候选链**(v0.2.4):worker 子会话是子 Agent 会话,客户端未必解析得到
|
|
2201
|
+
* (侧栏隐藏、依赖父会话 catalog),打不开时不能连累整次点击——调用方按顺序试到第一个能打开的。
|
|
2132
2202
|
*/
|
|
2203
|
+
function sessionCandidatesOf(task) {
|
|
2204
|
+
if (!task) return []
|
|
2205
|
+
const out = []
|
|
2206
|
+
const push = (value) => {
|
|
2207
|
+
if (typeof value === 'string' && value !== '' && out.indexOf(value) < 0) out.push(value)
|
|
2208
|
+
}
|
|
2209
|
+
push(workerSessionOf(task))
|
|
2210
|
+
push(task.dispatchedSessionId)
|
|
2211
|
+
push(task.sessionId)
|
|
2212
|
+
push(pollFallbackSessionOf(task))
|
|
2213
|
+
return out
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
/** 卡片「对话」按钮显示的目标(候选链首个);没有关联会话返回空串(不渲染按钮)。 */
|
|
2133
2217
|
function sessionOf(task) {
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
if (worker !== '') return worker
|
|
2137
|
-
if (typeof task.dispatchedSessionId === 'string' && task.dispatchedSessionId !== '') return task.dispatchedSessionId
|
|
2138
|
-
if (typeof task.sessionId === 'string' && task.sessionId !== '') return task.sessionId
|
|
2139
|
-
return pollFallbackSessionOf(task)
|
|
2218
|
+
const candidates = sessionCandidatesOf(task)
|
|
2219
|
+
return candidates.length > 0 ? candidates[0] : ''
|
|
2140
2220
|
}
|
|
2141
2221
|
|
|
2142
2222
|
/* ── 子组件 ───────────────────────────────────────────── */
|
|
@@ -2153,6 +2233,25 @@ window.__ModuleLoader__.load({
|
|
|
2153
2233
|
)
|
|
2154
2234
|
}
|
|
2155
2235
|
|
|
2236
|
+
/**
|
|
2237
|
+
* 平台看板卡片上的一行工作区标签(v0.2.4):纯展示,不调 hooks。
|
|
2238
|
+
* 文本由调用方算好(`taskWorkspaceLabel`);`title` 兜完整工作区路径(过长时单行省略),
|
|
2239
|
+
* `data-empty` 让「没有 cwd」的占位(—)弱化一点。右栏看板不传 label → 整块不渲染。
|
|
2240
|
+
*/
|
|
2241
|
+
function WorkspaceTag(props) {
|
|
2242
|
+
const label = props && typeof props.label === 'string' ? props.label : ''
|
|
2243
|
+
if (label === '') return null
|
|
2244
|
+
return h(
|
|
2245
|
+
'div',
|
|
2246
|
+
{
|
|
2247
|
+
className: 'tb-card-workspace',
|
|
2248
|
+
'data-empty': props.empty === true ? 'true' : 'false',
|
|
2249
|
+
title: typeof props.path === 'string' && props.path !== '' ? props.path : undefined,
|
|
2250
|
+
},
|
|
2251
|
+
label,
|
|
2252
|
+
)
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2156
2255
|
function Col(props) {
|
|
2157
2256
|
const t = bind.t
|
|
2158
2257
|
const busy = bind.busy
|
|
@@ -2160,6 +2259,8 @@ window.__ModuleLoader__.load({
|
|
|
2160
2259
|
const status = props.status
|
|
2161
2260
|
const list = props.tasks
|
|
2162
2261
|
const compact = props.compact === true
|
|
2262
|
+
// 只有平台看板传 workspaceLabel((task) => 展示名);右栏看板不传 → 卡片不带工作区标签。
|
|
2263
|
+
const workspaceLabelOf = typeof props.workspaceLabel === 'function' ? props.workspaceLabel : null
|
|
2163
2264
|
return h(
|
|
2164
2265
|
'section',
|
|
2165
2266
|
{
|
|
@@ -2203,7 +2304,17 @@ window.__ModuleLoader__.load({
|
|
|
2203
2304
|
),
|
|
2204
2305
|
list.length === 0
|
|
2205
2306
|
? h('div', { className: 'tb-empty' }, t('column.empty.' + status))
|
|
2206
|
-
: h(
|
|
2307
|
+
: h(
|
|
2308
|
+
'div',
|
|
2309
|
+
{ className: 'tb-cards' },
|
|
2310
|
+
list.map((task) =>
|
|
2311
|
+
h(Card, {
|
|
2312
|
+
key: task.id,
|
|
2313
|
+
task,
|
|
2314
|
+
workspaceLabel: workspaceLabelOf ? workspaceLabelOf(task) : '',
|
|
2315
|
+
}),
|
|
2316
|
+
),
|
|
2317
|
+
),
|
|
2207
2318
|
)
|
|
2208
2319
|
}
|
|
2209
2320
|
|
|
@@ -2256,6 +2367,9 @@ window.__ModuleLoader__.load({
|
|
|
2256
2367
|
const t = bind.t
|
|
2257
2368
|
const list = props && Array.isArray(props.tasks) ? props.tasks : []
|
|
2258
2369
|
const actions = bind.actions
|
|
2370
|
+
// 第五列也是全局视角(只有平台看板渲染它):同样显示工作区标签;
|
|
2371
|
+
// 右栏的「待你处理」是顶部条(.tb-needs-item,不是卡片),不受影响。
|
|
2372
|
+
const workspaceLabelOf = props && typeof props.workspaceLabel === 'function' ? props.workspaceLabel : null
|
|
2259
2373
|
return h(
|
|
2260
2374
|
'section',
|
|
2261
2375
|
{
|
|
@@ -2299,6 +2413,11 @@ window.__ModuleLoader__.load({
|
|
|
2299
2413
|
task.title,
|
|
2300
2414
|
),
|
|
2301
2415
|
h('div', { className: 'tb-needs-card-q', title: task.question || '' }, task.question || ''),
|
|
2416
|
+
h(WorkspaceTag, {
|
|
2417
|
+
label: workspaceLabelOf ? workspaceLabelOf(task) : '',
|
|
2418
|
+
empty: !(typeof task.cwd === 'string' && task.cwd !== ''),
|
|
2419
|
+
path: typeof task.cwd === 'string' ? task.cwd : '',
|
|
2420
|
+
}),
|
|
2302
2421
|
h(
|
|
2303
2422
|
'div',
|
|
2304
2423
|
{ className: 'tb-card-actions' },
|
|
@@ -2321,6 +2440,9 @@ window.__ModuleLoader__.load({
|
|
|
2321
2440
|
const actions = bind.actions
|
|
2322
2441
|
const task = props.task
|
|
2323
2442
|
const status = task.status
|
|
2443
|
+
// 工作区标签(v0.2.4):只有平台看板的 Col 传值;右栏看板传空串 → 不渲染。
|
|
2444
|
+
const workspaceLabel = typeof props.workspaceLabel === 'string' ? props.workspaceLabel : ''
|
|
2445
|
+
const hasCwd = typeof task.cwd === 'string' && task.cwd !== ''
|
|
2324
2446
|
const isEditing = editing !== null && editing.id === task.id
|
|
2325
2447
|
const busyKey = 'update:' + task.id
|
|
2326
2448
|
// 行内二次确认:不用 window.confirm(浏览器可能已勾选「阻止此页面的其它对话框」,那样确认永远为 false,
|
|
@@ -2387,16 +2509,19 @@ window.__ModuleLoader__.load({
|
|
|
2387
2509
|
cardActions.push([confirmingDelete ? 'deleteConfirmShort' : 'delete', requestDelete, false])
|
|
2388
2510
|
}
|
|
2389
2511
|
|
|
2390
|
-
// 卡片只留标题 + 操作按钮:note / result / lastError / id /
|
|
2512
|
+
// 卡片只留标题 + 操作按钮:note / result / lastError / id / 时间 /
|
|
2391
2513
|
// 执行者 / 组长这些背景信息都在详情浮层里看(点标题或「详情」)。
|
|
2514
|
+
// 唯一例外是全局平台看板多一行工作区标签(WorkspaceTag,由 props.workspaceLabel 控制)。
|
|
2392
2515
|
// 少这一整段后卡片高度由内容决定(.tb-card-fixed 的标题固定 2 行高度 +
|
|
2393
2516
|
// 标题/按钮之间只留 gap,不再用整卡 min-height + 操作行 margin-top:auto 撑空行)。
|
|
2394
2517
|
|
|
2395
2518
|
cardActions.unshift(['detail', () => actions.openDetail(task), false])
|
|
2396
2519
|
// 卡片「对话」优先 worker 子会话(真正干活的对话),其次组长 / 发起对话;title 用实际目标 id 便于辨认。
|
|
2520
|
+
// 点击走 actions.openChat(task):worker 打不开时自动回退组长 / 发起会话,全部失败出顶部提示(不静默)。
|
|
2397
2521
|
const cardSessionId = sessionOf(task)
|
|
2398
2522
|
if (cardSessionId !== '') {
|
|
2399
|
-
|
|
2523
|
+
const openChatAction = () => (typeof actions.openChat === 'function' ? actions.openChat(task) : actions.openSession(cardSessionId))
|
|
2524
|
+
cardActions.push(['openChat', openChatAction, false, cardSessionId])
|
|
2400
2525
|
}
|
|
2401
2526
|
|
|
2402
2527
|
return h(
|
|
@@ -2420,6 +2545,9 @@ window.__ModuleLoader__.load({
|
|
|
2420
2545
|
},
|
|
2421
2546
|
task.title,
|
|
2422
2547
|
),
|
|
2548
|
+
// 工作区标签放在标题与操作行之间(副标题位):不挤标题的 2 行高度,
|
|
2549
|
+
// 单行省略;cwd 为空时显示「—」占位。
|
|
2550
|
+
h(WorkspaceTag, { label: workspaceLabel, empty: !hasCwd, path: hasCwd ? task.cwd : '' }),
|
|
2423
2551
|
h(
|
|
2424
2552
|
'div',
|
|
2425
2553
|
{ className: 'tb-card-actions' },
|
|
@@ -2537,6 +2665,11 @@ window.__ModuleLoader__.load({
|
|
|
2537
2665
|
'\u00d7',
|
|
2538
2666
|
),
|
|
2539
2667
|
),
|
|
2668
|
+
// t-71:浮层内会话按钮失败时,提示条渲染在浮层内部——`.tb-detail-mask` 是 z-index:9000
|
|
2669
|
+
// 的全屏遮罩,看板顶部的 notice 横幅会被它盖住,用户看起来仍是「点了没反应」。
|
|
2670
|
+
props.notice && props.notice.text
|
|
2671
|
+
? h('div', { className: 'tb-detail-banner' }, h(Banner, { item: props.notice, onClose: props.onDismissNotice }))
|
|
2672
|
+
: null,
|
|
2540
2673
|
h(
|
|
2541
2674
|
'div',
|
|
2542
2675
|
{ className: 'tb-detail-body' },
|
|
@@ -2866,7 +2999,7 @@ window.__ModuleLoader__.load({
|
|
|
2866
2999
|
return h('div', { className: 'tb-leads', role: 'group', 'aria-label': t('lead.barLabel') }, cells)
|
|
2867
3000
|
}
|
|
2868
3001
|
|
|
2869
|
-
return { Banner, Col, Detail, LeadBar, NeedsBanner, NeedsColumn }
|
|
3002
|
+
return { Banner, Col, Detail, LeadBar, NeedsBanner, NeedsColumn, sessionCandidatesOf }
|
|
2870
3003
|
}
|
|
2871
3004
|
|
|
2872
3005
|
/* ── 看板页 ─────────────────────────────────────────────── */
|
|
@@ -2897,6 +3030,8 @@ window.__ModuleLoader__.load({
|
|
|
2897
3030
|
const [busy, setBusy] = useState('')
|
|
2898
3031
|
const [confirmDeleteId, setConfirmDeleteId] = useState(null)
|
|
2899
3032
|
const [detailId, setDetailId] = useState(null)
|
|
3033
|
+
// t-71:详情浮层内的会话跳转失败提示(渲染在浮层内部;顶部横幅会被 .tb-detail-mask 遮住)。
|
|
3034
|
+
const [detailNotice, setDetailNotice] = useState(null)
|
|
2900
3035
|
// v0.2.2「待你处理」:回答草稿 / 行内错误(详情浮层只读,不持有 state)。
|
|
2901
3036
|
const [answerDraft, setAnswerDraft] = useState('')
|
|
2902
3037
|
const [answerError, setAnswerError] = useState('')
|
|
@@ -3180,6 +3315,43 @@ window.__ModuleLoader__.load({
|
|
|
3180
3315
|
setNote((prev) => removeAttachmentRef(prev, id))
|
|
3181
3316
|
}
|
|
3182
3317
|
|
|
3318
|
+
/* ── 跳到关联会话(v0.2.4):失败不再静默 ─────────── */
|
|
3319
|
+
/**
|
|
3320
|
+
* 统一反馈:能打开就跳转,打不开就出 warn 横幅(`setNotice`,§5.2)。
|
|
3321
|
+
* 返回底层结果,便于把纯逻辑与 UI 拆开测试。
|
|
3322
|
+
*
|
|
3323
|
+
* t-71:浮层开着时把提示交给浮层(`detailNotice`)渲染——`.tb-detail-mask` 是 z-index:9000
|
|
3324
|
+
* 的全屏遮罩,看板顶部横幅在它下面,用户看不见。成功跳转顺带清掉上一次的会话失败提示;
|
|
3325
|
+
* `kind:'session'` 标记保证只清自己设的提示,不误清「派发成功」「已归档」等其它通知。
|
|
3326
|
+
*/
|
|
3327
|
+
function reportSessionFailure(result, candidates) {
|
|
3328
|
+
if (result && result.ok) {
|
|
3329
|
+
setNotice((prev) => (prev && prev.kind === 'session' ? null : prev))
|
|
3330
|
+
setDetailNotice((prev) => (prev && prev.kind === 'session' ? null : prev))
|
|
3331
|
+
return result
|
|
3332
|
+
}
|
|
3333
|
+
const item = { tone: 'warn', text: sessionFailureText(t, result, candidates), kind: 'session' }
|
|
3334
|
+
if (detailId !== null) {
|
|
3335
|
+
setDetailNotice(item)
|
|
3336
|
+
setNotice((prev) => (prev && prev.kind === 'session' ? null : prev))
|
|
3337
|
+
} else {
|
|
3338
|
+
setNotice(item)
|
|
3339
|
+
}
|
|
3340
|
+
return result
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
/** 单个会话 id 的跳转(组长条 / 详情「关联对话」用)。 */
|
|
3344
|
+
function openSessionAction(sessionId) {
|
|
3345
|
+
return reportSessionFailure(openSessionById(sessionId), [sessionId])
|
|
3346
|
+
}
|
|
3347
|
+
|
|
3348
|
+
/** 任务卡片的「对话」:按候选链(worker → 组长 → 发起 → poll 兜底)试到第一个能打开的。 */
|
|
3349
|
+
function openChatAction(task) {
|
|
3350
|
+
const pieces = boardPiecesRef.current
|
|
3351
|
+
const candidates = pieces && typeof pieces.sessionCandidatesOf === 'function' ? pieces.sessionCandidatesOf(task) : []
|
|
3352
|
+
return reportSessionFailure(openFirstAvailable(candidates), candidates)
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3183
3355
|
/* ── 组长条动作(v0.2.0)────────────────────────────────── */
|
|
3184
3356
|
// 三个新 RPC:bind-main-session {sessionId} / clear-main-session {} / ensure-workspace-lead {cwd}。
|
|
3185
3357
|
// 失败走 run() 的顶部错误条(errorText),不乐观更新、不崩。
|
|
@@ -3193,7 +3365,7 @@ window.__ModuleLoader__.load({
|
|
|
3193
3365
|
if (typeof cwd !== 'string' || cwd === '') return
|
|
3194
3366
|
run('lead:ensure', () => callRpc('ensure-workspace-lead', { cwd }), t('lead.ensureOk'))
|
|
3195
3367
|
},
|
|
3196
|
-
openSession: (sessionIdToOpen) =>
|
|
3368
|
+
openSession: (sessionIdToOpen) => openSessionAction(sessionIdToOpen),
|
|
3197
3369
|
}
|
|
3198
3370
|
|
|
3199
3371
|
/* ── 子组件(与平台看板共用)──────────────────────────── */
|
|
@@ -3210,16 +3382,19 @@ window.__ModuleLoader__.load({
|
|
|
3210
3382
|
// v0.2.2:换一条任务就清掉上一条的回答草稿 / 错误,避免答案串台。
|
|
3211
3383
|
setAnswerDraft('')
|
|
3212
3384
|
setAnswerError('')
|
|
3385
|
+
// t-71:上一条任务的会话失败提示也不带到新浮层。
|
|
3386
|
+
setDetailNotice(null)
|
|
3213
3387
|
setDetailId(task.id)
|
|
3214
3388
|
},
|
|
3215
3389
|
// 「对话」按钮传目标会话 id;仍兼容传任务对象的旧调用(取 dispatched → creator)。
|
|
3390
|
+
// 失败(目标会话已关闭 / 服务缺失)出 warn 提示,不再只 console.warn(v0.2.4)。
|
|
3216
3391
|
openSession: (target) => {
|
|
3217
|
-
if (typeof target === 'string')
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
}
|
|
3221
|
-
openSessionById(target && (target.dispatchedSessionId || target.sessionId))
|
|
3392
|
+
if (typeof target === 'string') return openSessionAction(target)
|
|
3393
|
+
const candidates = target ? [target.dispatchedSessionId, target.sessionId] : []
|
|
3394
|
+
return reportSessionFailure(openFirstAvailable(candidates), candidates)
|
|
3222
3395
|
},
|
|
3396
|
+
// 卡片「对话」专用:worker 打不开时回退组长 / 发起会话(候选链见 sessionCandidatesOf)。
|
|
3397
|
+
openChat: (task) => openChatAction(task),
|
|
3223
3398
|
startEdit,
|
|
3224
3399
|
saveEdit,
|
|
3225
3400
|
setEditing,
|
|
@@ -3509,14 +3684,19 @@ window.__ModuleLoader__.load({
|
|
|
3509
3684
|
task: detailTask,
|
|
3510
3685
|
onClose: () => {
|
|
3511
3686
|
setDetailId(null)
|
|
3687
|
+
setDetailNotice(null)
|
|
3512
3688
|
setAnswerDraft('')
|
|
3513
3689
|
setAnswerError('')
|
|
3514
3690
|
},
|
|
3515
3691
|
onStatus: (status) => {
|
|
3516
3692
|
setDetailId(null)
|
|
3693
|
+
setDetailNotice(null)
|
|
3517
3694
|
updateTask(detailTask.id, { status })
|
|
3518
3695
|
},
|
|
3519
|
-
|
|
3696
|
+
// t-71:浮层内会话按钮失败时,提示条渲染在浮层内部(遮罩盖住顶部的 notice 横幅)。
|
|
3697
|
+
notice: detailNotice,
|
|
3698
|
+
onDismissNotice: () => setDetailNotice(null),
|
|
3699
|
+
openSession: (sessionId) => openSessionAction(sessionId),
|
|
3520
3700
|
})
|
|
3521
3701
|
: null,
|
|
3522
3702
|
)
|
|
@@ -3585,6 +3765,8 @@ window.__ModuleLoader__.load({
|
|
|
3585
3765
|
const [busy, setBusy] = useState('')
|
|
3586
3766
|
const [confirmDeleteId, setConfirmDeleteId] = useState(null)
|
|
3587
3767
|
const [detailId, setDetailId] = useState(null)
|
|
3768
|
+
// t-71:详情浮层内的会话跳转失败提示(渲染在浮层内部;顶部横幅会被 .tb-detail-mask 遮住)。
|
|
3769
|
+
const [detailNotice, setDetailNotice] = useState(null)
|
|
3588
3770
|
// v0.2.2「待你处理」:回答草稿 / 行内错误(详情浮层只读,不持有 state)。
|
|
3589
3771
|
const [answerDraft, setAnswerDraft] = useState('')
|
|
3590
3772
|
const [answerError, setAnswerError] = useState('')
|
|
@@ -3695,6 +3877,9 @@ window.__ModuleLoader__.load({
|
|
|
3695
3877
|
// v0.2.3:新建行的「任务所属工作区」同样按 snapshot.workspaces 校验——
|
|
3696
3878
|
// 选中的工作区在页面打开期间被删 / 改名 → 回退占位(提交重新禁用),不拿失效路径建任务。
|
|
3697
3879
|
const activeWorkspaceCwd = resolveWorkspaceSelection(workspaceCwd, workspaces) || ''
|
|
3880
|
+
// v0.2.4:平台看板卡片上的工作区标签——title 优先、目录名回退、无 cwd 用「—」。
|
|
3881
|
+
// 只传给平台看板的 Col / NeedsColumn;右栏看板本来就绑定单个工作区,不重复显示。
|
|
3882
|
+
const workspaceLabelOf = (task) => taskWorkspaceLabel(workspaces, task)
|
|
3698
3883
|
const visibleAll = tasksForFilter(allTasks, activeFilter)
|
|
3699
3884
|
// v0.2.2(§1.9):flagged 任务只进最左第五列,不重复出现在普通四列。
|
|
3700
3885
|
const needsUser = needsUserTasks(visibleAll)
|
|
@@ -3909,6 +4094,40 @@ window.__ModuleLoader__.load({
|
|
|
3909
4094
|
setNote((prev) => removeAttachmentRef(prev, id))
|
|
3910
4095
|
}
|
|
3911
4096
|
|
|
4097
|
+
/* ── 跳到关联会话(v0.2.4):失败不再静默 ─────────── */
|
|
4098
|
+
/**
|
|
4099
|
+
* 与右栏看板同一套反馈:能打开就跳转,打不开就出 warn 横幅。
|
|
4100
|
+
* t-71:浮层开着时提示渲染在浮层内部(`detailNotice`),否则看板顶部横幅会被遮罩盖住;
|
|
4101
|
+
* 成功跳转只清 `kind:'session'` 的旧提示(不误清派发 / 归档等其它通知)。
|
|
4102
|
+
*/
|
|
4103
|
+
function reportSessionFailure(result, candidates) {
|
|
4104
|
+
if (result && result.ok) {
|
|
4105
|
+
setNotice((prev) => (prev && prev.kind === 'session' ? null : prev))
|
|
4106
|
+
setDetailNotice((prev) => (prev && prev.kind === 'session' ? null : prev))
|
|
4107
|
+
return result
|
|
4108
|
+
}
|
|
4109
|
+
const item = { tone: 'warn', text: sessionFailureText(t, result, candidates), kind: 'session' }
|
|
4110
|
+
if (detailId !== null) {
|
|
4111
|
+
setDetailNotice(item)
|
|
4112
|
+
setNotice((prev) => (prev && prev.kind === 'session' ? null : prev))
|
|
4113
|
+
} else {
|
|
4114
|
+
setNotice(item)
|
|
4115
|
+
}
|
|
4116
|
+
return result
|
|
4117
|
+
}
|
|
4118
|
+
|
|
4119
|
+
/** 单个会话 id 的跳转(组长条 / 详情「关联对话」用)。 */
|
|
4120
|
+
function openSessionAction(sessionId) {
|
|
4121
|
+
return reportSessionFailure(openSessionById(sessionId), [sessionId])
|
|
4122
|
+
}
|
|
4123
|
+
|
|
4124
|
+
/** 任务卡片的「对话」:按候选链(worker → 组长 → 发起 → poll 兜底)试到第一个能打开的。 */
|
|
4125
|
+
function openChatAction(task) {
|
|
4126
|
+
const pieces = boardPiecesRef.current
|
|
4127
|
+
const candidates = pieces && typeof pieces.sessionCandidatesOf === 'function' ? pieces.sessionCandidatesOf(task) : []
|
|
4128
|
+
return reportSessionFailure(openFirstAvailable(candidates), candidates)
|
|
4129
|
+
}
|
|
4130
|
+
|
|
3912
4131
|
/* ── 组长条动作(v0.2.0,与右栏看板同一套 RPC)──────────── */
|
|
3913
4132
|
const leadActions = {
|
|
3914
4133
|
bindMain: () => {
|
|
@@ -3920,7 +4139,7 @@ window.__ModuleLoader__.load({
|
|
|
3920
4139
|
if (typeof cwd !== 'string' || cwd === '') return
|
|
3921
4140
|
run('lead:ensure', () => callRpc('ensure-workspace-lead', { cwd }), t('lead.ensureOk'))
|
|
3922
4141
|
},
|
|
3923
|
-
openSession: (sessionIdToOpen) =>
|
|
4142
|
+
openSession: (sessionIdToOpen) => openSessionAction(sessionIdToOpen),
|
|
3924
4143
|
}
|
|
3925
4144
|
|
|
3926
4145
|
// 组件身份保持稳定(同右栏看板):bind 存 ref、只改字段,pieces 只创建一次。
|
|
@@ -3935,16 +4154,19 @@ window.__ModuleLoader__.load({
|
|
|
3935
4154
|
// v0.2.2:换一条任务就清掉上一条的回答草稿 / 错误,避免答案串台。
|
|
3936
4155
|
setAnswerDraft('')
|
|
3937
4156
|
setAnswerError('')
|
|
4157
|
+
// t-71:上一条任务的会话失败提示也不带到新浮层。
|
|
4158
|
+
setDetailNotice(null)
|
|
3938
4159
|
setDetailId(task.id)
|
|
3939
4160
|
},
|
|
3940
4161
|
// 「对话」按钮传目标会话 id;仍兼容传任务对象的旧调用(取 dispatched → creator)。
|
|
4162
|
+
// 失败(目标会话已关闭 / 服务缺失)出 warn 提示,不再只 console.warn(v0.2.4)。
|
|
3941
4163
|
openSession: (target) => {
|
|
3942
|
-
if (typeof target === 'string')
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
}
|
|
3946
|
-
openSessionById(target && (target.dispatchedSessionId || target.sessionId))
|
|
4164
|
+
if (typeof target === 'string') return openSessionAction(target)
|
|
4165
|
+
const candidates = target ? [target.dispatchedSessionId, target.sessionId] : []
|
|
4166
|
+
return reportSessionFailure(openFirstAvailable(candidates), candidates)
|
|
3947
4167
|
},
|
|
4168
|
+
// 卡片「对话」专用:worker 打不开时回退组长 / 发起会话(候选链见 sessionCandidatesOf)。
|
|
4169
|
+
openChat: (task) => openChatAction(task),
|
|
3948
4170
|
startEdit,
|
|
3949
4171
|
saveEdit,
|
|
3950
4172
|
setEditing,
|
|
@@ -4220,8 +4442,12 @@ window.__ModuleLoader__.load({
|
|
|
4220
4442
|
'div',
|
|
4221
4443
|
{ className: 'tb-board', 'data-layout': 'wide', 'data-needs': needsUser.length > 0 ? 'true' : 'false' },
|
|
4222
4444
|
// 第五列「待你处理」放最左(在「待开始」之前),仅非空时渲染。
|
|
4223
|
-
needsUser.length > 0
|
|
4224
|
-
|
|
4445
|
+
needsUser.length > 0
|
|
4446
|
+
? h(NeedsColumn, { key: 'needsUser', tasks: needsUser, workspaceLabel: workspaceLabelOf })
|
|
4447
|
+
: null,
|
|
4448
|
+
STATUS_ORDER.map((status) =>
|
|
4449
|
+
h(Col, { key: status, status, tasks: groups[status], compact: false, workspaceLabel: workspaceLabelOf }),
|
|
4450
|
+
),
|
|
4225
4451
|
),
|
|
4226
4452
|
|
|
4227
4453
|
h(
|
|
@@ -4238,14 +4464,19 @@ window.__ModuleLoader__.load({
|
|
|
4238
4464
|
task: detailTask,
|
|
4239
4465
|
onClose: () => {
|
|
4240
4466
|
setDetailId(null)
|
|
4467
|
+
setDetailNotice(null)
|
|
4241
4468
|
setAnswerDraft('')
|
|
4242
4469
|
setAnswerError('')
|
|
4243
4470
|
},
|
|
4244
4471
|
onStatus: (status) => {
|
|
4245
4472
|
setDetailId(null)
|
|
4473
|
+
setDetailNotice(null)
|
|
4246
4474
|
updateTask(detailTask.id, { status })
|
|
4247
4475
|
},
|
|
4248
|
-
|
|
4476
|
+
// t-71:浮层内会话按钮失败时,提示条渲染在浮层内部(遮罩盖住顶部的 notice 横幅)。
|
|
4477
|
+
notice: detailNotice,
|
|
4478
|
+
onDismissNotice: () => setDetailNotice(null),
|
|
4479
|
+
openSession: (sessionId) => openSessionAction(sessionId),
|
|
4249
4480
|
})
|
|
4250
4481
|
: null,
|
|
4251
4482
|
)
|
|
@@ -4371,6 +4602,9 @@ window.__ModuleLoader__.load({
|
|
|
4371
4602
|
normalizePath,
|
|
4372
4603
|
samePath,
|
|
4373
4604
|
workspaceTitleOf,
|
|
4605
|
+
// v0.2.4:平台看板卡片的工作区标签(title 优先 / 目录名回退 / 空 cwd 占位)
|
|
4606
|
+
taskWorkspaceLabel,
|
|
4607
|
+
workspaceLabelNone: WORKSPACE_LABEL_NONE,
|
|
4374
4608
|
tasksForWorkspace,
|
|
4375
4609
|
tasksForFilter,
|
|
4376
4610
|
// v0.2.3:看板「工作区」过滤选择的恢复 / 脏值回退
|
package/lib/index.js
CHANGED
|
@@ -118,6 +118,17 @@ export const LEAD_AUTO_MARK = 'lead-dispatch'
|
|
|
118
118
|
* (worker 长跑 / 组长卡死)就不再挡住直聊派活——宁可多一条可见任务,也不让派活无声消失。
|
|
119
119
|
*/
|
|
120
120
|
export const LEAD_IN_FLIGHT_TTL_MS = 30 * 60 * 1000
|
|
121
|
+
/**
|
|
122
|
+
* §1.8(0.2.4):组长把「轮询投递来的任务」置 `doing` = 即将为它启动 worker 的**意图**。
|
|
123
|
+
* 派发闸门只认这条意图一次(认领后删除);超过这个窗口没派发就作废,避免陈旧意图把后续直聊派活
|
|
124
|
+
* 错误地并进旧任务(t-69 事故的根因就是「按组长名下 in-flight 任务盲目去重」)。
|
|
125
|
+
*/
|
|
126
|
+
export const LEAD_DISPATCH_INTENT_MS = 10 * 60 * 1000
|
|
127
|
+
/**
|
|
128
|
+
* §1.8(0.2.4):同一次派发被重复调用(模型重试 / PTC 子调用)时,认领「刚建好、还没挂 worker」
|
|
129
|
+
* 的预建卡片的时间窗;窗口内标题 + note 完全相同 → 复用,不再建第二张。
|
|
130
|
+
*/
|
|
131
|
+
export const LEAD_DISPATCH_DEDUPE_MS = 2 * 60 * 1000
|
|
121
132
|
|
|
122
133
|
/** 看板四列。顺序即 UI 列顺序。 */
|
|
123
134
|
export const STATUSES = ['todo', 'doing', 'done', 'archived']
|
|
@@ -2739,6 +2750,8 @@ export function createLeadAutoState(now = Date.now()) {
|
|
|
2739
2750
|
deduped: 0,
|
|
2740
2751
|
completed: 0,
|
|
2741
2752
|
skipped: 0,
|
|
2753
|
+
// §1.8(0.2.4):派发前强制建卡闸门的计数。
|
|
2754
|
+
aborted: 0,
|
|
2742
2755
|
lastError: '',
|
|
2743
2756
|
lastErrorAt: null,
|
|
2744
2757
|
lastTaskId: null,
|
|
@@ -2761,6 +2774,8 @@ export function normalizeLeadAuto(raw) {
|
|
|
2761
2774
|
deduped: counterOf(source.deduped),
|
|
2762
2775
|
completed: counterOf(source.completed),
|
|
2763
2776
|
skipped: counterOf(source.skipped),
|
|
2777
|
+
// §1.8(0.2.4):老 runtime 没有这个字段 → 0(Snapshot 始终给全)。
|
|
2778
|
+
aborted: counterOf(source.aborted),
|
|
2764
2779
|
lastError: trimmed(source.lastError, 500),
|
|
2765
2780
|
lastErrorAt: asString(source.lastErrorAt) || null,
|
|
2766
2781
|
lastTaskId: asString(source.lastTaskId) || null,
|
|
@@ -2889,10 +2904,452 @@ export function workspacePathForCwd(ctx, cwd) {
|
|
|
2889
2904
|
return raw
|
|
2890
2905
|
}
|
|
2891
2906
|
|
|
2907
|
+
/* ------------------------------------------------------------------ *
|
|
2908
|
+
* §1.8(0.2.4)派发前强制建卡闸门(tools/pre-execute)
|
|
2909
|
+
*
|
|
2910
|
+
* 背景(t-69 事故):旧实现只在 `tools/result`(worker 已经启动之后)观察派发,并且用
|
|
2911
|
+
* `findLeadInFlightTask` 把「组长名下任意一条未陈旧的轮询任务」当成这次 subagent 的归属——
|
|
2912
|
+
* 组长处理完轮询任务 t-68 后,用户在直聊里再让它派活,第二次 subagent 仍被误判成「t-68 的 worker」
|
|
2913
|
+
* 而跳过建卡:worker 跑了、看板没有任务(见 §1.8)。
|
|
2914
|
+
*
|
|
2915
|
+
* 0.2.4 起把建卡提前到派发**之前**:`tools/pre-execute` 拦 `subagent` 调用(只针对
|
|
2916
|
+
* taskboard-dispatch 组长),先认领已有卡片(显式 `任务 id` → 组长刚置 doing 的轮询任务意图 →
|
|
2917
|
+
* 刚建好还没挂 worker 的同参数卡片),认领不到就建一条 `doing` + `autoDispatch` 卡片;
|
|
2918
|
+
* 建卡 / 写盘失败 → `{kind:'deny'}`,worker **不会启动**。`tools/result` 只负责把 worker 会话 id
|
|
2919
|
+
* 挂到这张卡上(`handleSubagentDispatch` 的 prepared 分支),不再决定是否建卡。
|
|
2920
|
+
* ------------------------------------------------------------------ */
|
|
2921
|
+
|
|
2922
|
+
/** 按 id 找任务(找不到返回 null,不抛 not-found——闸门是副作用路径,不该把派发变成异常)。 */
|
|
2923
|
+
export function taskById(state, id) {
|
|
2924
|
+
const target = trimmed(id, 40)
|
|
2925
|
+
if (!state || !Array.isArray(state.tasks) || target === '') return null
|
|
2926
|
+
return state.tasks.find((task) => task && task.id === target) || null
|
|
2927
|
+
}
|
|
2928
|
+
|
|
2929
|
+
/**
|
|
2930
|
+
* 派发 prompt 的行归一化(§1.8,0.2.4 宽容解析):组长(模型)写 worker prompt 习惯给「任务 id」加粗 /
|
|
2931
|
+
* 套反引号 / 用半角冒号,逐行归一后再匹配,避免「同一句话的不同 markdown 写法」漏识别:
|
|
2932
|
+
* 1) 去掉 markdown 强调 / 反引号 `*` `_` `` ` `` `~`(`**任务 id:t-N**` → `任务 id:t-N`);
|
|
2933
|
+
* 2) 全角冒号 `:` → `:`,全角 / 不换行空格 → 普通空格,连续空白压成一个;
|
|
2934
|
+
* 3) 去掉行首缩进与列表 / 标题 / 引用符号(`- ` / `+ ` / `> ` / `1. ` / `## `,可叠加),再 trim。
|
|
2935
|
+
* 只归一「形态」、不放宽「语义」:归一化后仍要求标签在行首(`任务 id:`)或紧跟 `看板任务:`,
|
|
2936
|
+
* 正文段落里顺带提到的 t-N(「上次那个 t-3」「见 t-7」)依旧不认。
|
|
2937
|
+
*/
|
|
2938
|
+
function normalizeDispatchLines(text) {
|
|
2939
|
+
const source = typeof text === 'string' ? text : ''
|
|
2940
|
+
if (source === '') return []
|
|
2941
|
+
return source.split(/\r?\n/).map((raw) =>
|
|
2942
|
+
raw
|
|
2943
|
+
.replace(/[*_`~]/g, '')
|
|
2944
|
+
.replace(/[:﹕]/g, ':')
|
|
2945
|
+
.replace(/[\u00a0\u3000]/g, ' ')
|
|
2946
|
+
.replace(/\s+/g, ' ')
|
|
2947
|
+
.trim()
|
|
2948
|
+
.replace(/^(?:(?:[-+]|#{1,6}|>|\d+[.)]) +)+/, '')
|
|
2949
|
+
.trim(),
|
|
2950
|
+
)
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
/** 一行里出现的任务 id(先去掉括号 / 引号里的标题内容:`任务 id:t-81「…t-71…」` 里的 t-71 是标题)。 */
|
|
2954
|
+
function taskIdsInDispatchLine(text) {
|
|
2955
|
+
const bare = String(text)
|
|
2956
|
+
.replace(/([^)]*)/g, ' ')
|
|
2957
|
+
.replace(/\([^)]*\)/g, ' ')
|
|
2958
|
+
.replace(/「[^」]*」/g, ' ')
|
|
2959
|
+
.replace(/『[^』]*』/g, ' ')
|
|
2960
|
+
.replace(/“[^”]*”/g, ' ')
|
|
2961
|
+
.replace(/\[[^\]]*\]/g, ' ')
|
|
2962
|
+
return bare.match(/t-[0-9]{1,6}(?![0-9])/gi) || []
|
|
2963
|
+
}
|
|
2964
|
+
|
|
2965
|
+
/**
|
|
2966
|
+
* 派发 prompt 里显式声明的看板任务 id(§1.8):`任务 id:t-68` / `- 任务 id: \`t-68\`` → `t-68`。
|
|
2967
|
+
* 只认行首(允许列表符号 / 缩进 / markdown 强调)的「任务 id」标签,避免验证类 prompt 里顺带提到 t-xx
|
|
2968
|
+
* 被误认领。宽容化来自 t-78 事故:组长把 prompt 写成 `**任务 id:t-78**`,旧正则要求行首直接是
|
|
2969
|
+
* `任务`/`- 任务`,`*` 不在列表符号的「符号 + 空格」形态里 → 整行不匹配 → 没复用已有的 t-78,
|
|
2970
|
+
* 另建了重复卡 t-79(已归档)。
|
|
2971
|
+
*/
|
|
2972
|
+
export function dispatchTaskIdFromPrompt(text) {
|
|
2973
|
+
for (const line of normalizeDispatchLines(text)) {
|
|
2974
|
+
const match = /^任务 *id *: *(t-[0-9]{1,6})(?![0-9])/i.exec(line)
|
|
2975
|
+
if (!match) continue
|
|
2976
|
+
const id = match[1].toLowerCase()
|
|
2977
|
+
// 同一行还写了别的任务 id(`任务 id:t-3 或 t-4`)= 归属不明:宁可不认领,也不认错卡片。
|
|
2978
|
+
const rest = line.slice(match[0].length)
|
|
2979
|
+
if (taskIdsInDispatchLine(rest).some((other) => other.toLowerCase() !== id)) continue
|
|
2980
|
+
return id
|
|
2981
|
+
}
|
|
2982
|
+
return ''
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
/**
|
|
2986
|
+
* 派发 prompt 里以「看板任务:t-N」/「看板任务 `t-N`」/「看板任务:**任务 id:t-N**」形式提到的卡片 id
|
|
2987
|
+
* (§1.8,0.2.4)。组长给 worker 的 prompt 不一定写行首「任务 id:」(实测 t-70 写成
|
|
2988
|
+
* 「看板任务:**t-70…**」;t-78 写成「看板任务:**任务 id:t-78**,后面跟标题」——行首是正文,行首规则不认,
|
|
2989
|
+
* 旧「看板任务 + 紧邻 t-N」也不认中间夹着的「任务 id:」,于是另建了重复卡 t-79)。这种明确的任务引用
|
|
2990
|
+
* 也应认领原卡片;是否复用还要过 `canReuseMentionedTask`(待做 / 未挂 worker)。
|
|
2991
|
+
*/
|
|
2992
|
+
export function dispatchReferencedTaskId(text) {
|
|
2993
|
+
for (const line of normalizeDispatchLines(text)) {
|
|
2994
|
+
const match = /看板任务 *:? *(?:任务 *id *: *)?(t-[0-9]{1,6})(?![0-9])/i.exec(line)
|
|
2995
|
+
if (match) return match[1].toLowerCase()
|
|
2996
|
+
}
|
|
2997
|
+
return ''
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
/** assignee 看起来是不是一个真实 worker 会话 id(UUID / session-…);自由文本标签(如 taskboard-worker)不算。 */
|
|
3001
|
+
export function looksLikeSessionId(value) {
|
|
3002
|
+
const text = typeof value === 'string' ? value.trim() : ''
|
|
3003
|
+
if (text === '') return false
|
|
3004
|
+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(text)) return true
|
|
3005
|
+
return /^session-[0-9a-z-]{8,}$/i.test(text)
|
|
3006
|
+
}
|
|
3007
|
+
|
|
3008
|
+
/**
|
|
3009
|
+
* 「看板任务:t-N」提到的卡片能否被这次派发认领:
|
|
3010
|
+
* - 必须在待做 / 进行中(做完 / 归档的任务不抢);
|
|
3011
|
+
* - 还没挂真实 worker 会话 id(已挂 = 已有 worker 在干,这次多半是验证子 Agent / 另一个 worker,
|
|
3012
|
+
* 应该有自己的卡片;自由文本 assignee 如 `taskboard-worker` 不算)。
|
|
3013
|
+
*/
|
|
3014
|
+
export function canReuseMentionedTask(task) {
|
|
3015
|
+
if (!task) return false
|
|
3016
|
+
if (task.status !== 'todo' && task.status !== 'doing') return false
|
|
3017
|
+
return !looksLikeSessionId(task.assignee)
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
function preparedDispatchStore(rt) {
|
|
3021
|
+
if (!(rt.preparedDispatches instanceof WeakMap)) rt.preparedDispatches = new WeakMap()
|
|
3022
|
+
return rt.preparedDispatches
|
|
3023
|
+
}
|
|
3024
|
+
|
|
3025
|
+
/** 预建卡片的执行句柄(WeakMap 键 = tools 管线的 exec 对象,pre-execute 与 tools/result 是同一个对象)。 */
|
|
3026
|
+
export function takePreparedDispatch(rt, exec) {
|
|
3027
|
+
if (!exec || typeof exec !== 'object') return null
|
|
3028
|
+
const store = preparedDispatchStore(rt)
|
|
3029
|
+
const hit = store.get(exec) || null
|
|
3030
|
+
if (hit) store.delete(exec)
|
|
3031
|
+
return hit
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
/**
|
|
3035
|
+
* §1.8(0.2.4):组长把轮询投递任务置 doing → 记一条「即将为它派 worker」的意图(不落盘)。
|
|
3036
|
+
* 只在任务当前 `assignee === ''`(还没挂 worker)时记录:worker 已经挂上后再改 doing 不算新意图,
|
|
3037
|
+
* 避免把后续直聊派活错误并进旧任务。
|
|
3038
|
+
*/
|
|
3039
|
+
export function noteLeadDispatchIntent(rt, agent, taskId, now = Date.now()) {
|
|
3040
|
+
try {
|
|
3041
|
+
if (!agent) return false
|
|
3042
|
+
if (sessionPresetOfContext(rt.ctx, agent) !== DISPATCH_PRESET_ID) return false
|
|
3043
|
+
const leadId = agentSessionId(agent) || ''
|
|
3044
|
+
if (leadId === '') return false
|
|
3045
|
+
const task = taskById(rt.state, taskId)
|
|
3046
|
+
if (!task) return false
|
|
3047
|
+
if (task.status !== 'doing' || asString(task.notifiedAt) === '') return false
|
|
3048
|
+
if (task.dispatchedSessionId !== leadId) return false
|
|
3049
|
+
if (task.assignee !== '') return false
|
|
3050
|
+
if (!(rt.leadDispatchIntent instanceof Map)) rt.leadDispatchIntent = new Map()
|
|
3051
|
+
rt.leadDispatchIntent.set(leadId, { taskId: task.id, at: now })
|
|
3052
|
+
return true
|
|
3053
|
+
} catch {
|
|
3054
|
+
return false
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
/** 取走(一次性)该组长的派发意图;过期 / 任务状态不符 → 作废。 */
|
|
3059
|
+
function takeLeadDispatchIntent(rt, leadId, now) {
|
|
3060
|
+
if (!leadId || !(rt.leadDispatchIntent instanceof Map)) return null
|
|
3061
|
+
const entry = rt.leadDispatchIntent.get(leadId)
|
|
3062
|
+
if (!entry) return null
|
|
3063
|
+
rt.leadDispatchIntent.delete(leadId)
|
|
3064
|
+
if (!Number.isFinite(entry.at) || now - entry.at > LEAD_DISPATCH_INTENT_MS) return null
|
|
3065
|
+
const task = taskById(rt.state, entry.taskId)
|
|
3066
|
+
if (!task || task.status !== 'doing' || asString(task.notifiedAt) === '') return null
|
|
3067
|
+
return task
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
/**
|
|
3071
|
+
* 这次派发的 prompt 是否真的指向这条任务(任务 id 或标题出现在 prompt 里)。
|
|
3072
|
+
* 用来防止「组长刚给 t-68 记了派发意图」的**下一条无关直聊派发**把 t-68 认领走(t-69 事故的变体)。
|
|
3073
|
+
*/
|
|
3074
|
+
export function dispatchMentionsTask(args, task) {
|
|
3075
|
+
if (!task) return false
|
|
3076
|
+
const prompt = subagentPromptText(args)
|
|
3077
|
+
if (prompt === '') return false
|
|
3078
|
+
const id = asString(task.id)
|
|
3079
|
+
if (id !== '') {
|
|
3080
|
+
const escaped = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
3081
|
+
if (new RegExp('(^|[^A-Za-z0-9_-])' + escaped + '([^A-Za-z0-9_-]|$)').test(prompt)) return true
|
|
3082
|
+
}
|
|
3083
|
+
const title = asString(task.title).trim()
|
|
3084
|
+
return title.length >= 4 && prompt.includes(title)
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3087
|
+
/** 刚建好、还没挂 worker 的同参数卡片(同一组长 / 同 title+note / 时间窗内)→ 幂等复用。 */
|
|
3088
|
+
export function findPendingDispatchCard(state, leadId, title, note, now = Date.now()) {
|
|
3089
|
+
if (!state || !Array.isArray(state.tasks) || !leadId) return null
|
|
3090
|
+
for (let i = state.tasks.length - 1; i >= 0; i -= 1) {
|
|
3091
|
+
const task = state.tasks[i]
|
|
3092
|
+
if (!task || task.autoDispatch !== LEAD_AUTO_MARK) continue
|
|
3093
|
+
if (task.status !== 'doing' || task.assignee !== '') continue
|
|
3094
|
+
if (task.dispatchedSessionId !== leadId) continue
|
|
3095
|
+
if (task.title !== title || (task.note || '') !== (note || '')) continue
|
|
3096
|
+
const stamp = Date.parse(asString(task.createdAt))
|
|
3097
|
+
if (!Number.isFinite(stamp) || now - stamp > LEAD_DISPATCH_DEDUPE_MS) continue
|
|
3098
|
+
return task
|
|
3099
|
+
}
|
|
3100
|
+
return null
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
/** 派发卡片正文(0.2.4):pre-execute 时还没有 worker 会话 id,标题先取 description / prompt 首行。 */
|
|
3104
|
+
export function leadDispatchTitle(args) {
|
|
3105
|
+
return leadTaskTitle(args, '')
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
function leadDispatchNote(args) {
|
|
3109
|
+
return truncateNote(subagentPromptText(args), MAX_NOTE_CHARS)
|
|
3110
|
+
}
|
|
3111
|
+
|
|
3112
|
+
function leadDispatchCwd(rt, agent, args) {
|
|
3113
|
+
const sessionId = agentSessionId(agent) || ''
|
|
3114
|
+
const rawCwd = sessionCwd(agent) || resolveSessionCwd(rt.ctx, sessionId) || (isPlainObject(args) ? asString(args.cwd) : '')
|
|
3115
|
+
return workspacePathForCwd(rt.ctx, rawCwd)
|
|
3116
|
+
}
|
|
3117
|
+
|
|
3118
|
+
function removeTaskFromState(state, taskId) {
|
|
3119
|
+
if (!state || !Array.isArray(state.tasks)) return false
|
|
3120
|
+
const index = state.tasks.findIndex((task) => task && task.id === taskId)
|
|
3121
|
+
if (index < 0) return false
|
|
3122
|
+
state.tasks.splice(index, 1)
|
|
3123
|
+
return true
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
function dispatchDeniedMessage(reason, detail) {
|
|
3127
|
+
return (
|
|
3128
|
+
'派发已中止:没有看板卡片就不能启动 worker(§1.8)。' +
|
|
3129
|
+
reason +
|
|
3130
|
+
(detail ? ':' + detail : '') +
|
|
3131
|
+
'。请修复 $DSH_HOME/storages/dsh-taskboard/board.json 的写权限后重试,' +
|
|
3132
|
+
'或先用 taskboard_add 建卡、再把卡号写进 prompt(任务 id:t-N)重试。'
|
|
3133
|
+
)
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3136
|
+
function finishPreparedDispatch(rt, auto, store, exec, task, created, reused, now) {
|
|
3137
|
+
const outcome = { ok: true, taskId: task.id, created, reused }
|
|
3138
|
+
// created 只在闸门真正新建时 +1;handleSubagentDispatch 的 prepared 分支不再重复计数。
|
|
3139
|
+
if (created) auto.created += 1
|
|
3140
|
+
else auto.deduped += 1
|
|
3141
|
+
auto.lastTaskId = task.id
|
|
3142
|
+
auto.updatedAt = iso(now)
|
|
3143
|
+
if (exec && typeof exec === 'object') store.set(exec, outcome)
|
|
3144
|
+
return outcome
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
/**
|
|
3148
|
+
* §1.8(0.2.4):派发前准备看板卡片。
|
|
3149
|
+
* - 能认领已有卡片就复用(显式 `任务 id` / 组长置 doing 的轮询任务 / 同参数预建卡片),不重复建;
|
|
3150
|
+
* - 认领不到就新建 `doing` + `autoDispatch` 卡片并**同步写盘**;
|
|
3151
|
+
* - 建卡 / 写盘失败 → `{ok:false}`(调用方必须拒绝派发),并回滚内存里的半成品卡片。
|
|
3152
|
+
* @param {{agent:object, exec?:object, args?:object}} input
|
|
3153
|
+
* @returns {{ok:true, taskId:string, created:boolean, reused:string} | {ok:false, reason:string, message:string}}
|
|
3154
|
+
*/
|
|
3155
|
+
export function prepareLeadDispatch(rt, input, now = Date.now()) {
|
|
3156
|
+
const auto = ensureLeadAuto(rt)
|
|
3157
|
+
const agent = input && input.agent
|
|
3158
|
+
const exec = input && input.exec
|
|
3159
|
+
const store = preparedDispatchStore(rt)
|
|
3160
|
+
try {
|
|
3161
|
+
if (!agent) return { ok: true, taskId: '', created: false, reused: 'no-agent' }
|
|
3162
|
+
if (sessionPresetOfContext(rt.ctx, agent) !== DISPATCH_PRESET_ID) {
|
|
3163
|
+
return { ok: true, taskId: '', created: false, reused: 'not-lead' }
|
|
3164
|
+
}
|
|
3165
|
+
// 同一 exec 重复进闸门(PTC / 重试):直接返回第一次的结果,绝不再建卡。
|
|
3166
|
+
if (exec && typeof exec === 'object') {
|
|
3167
|
+
const prior = store.get(exec)
|
|
3168
|
+
if (prior) return { ...prior, reused: 'same-exec' }
|
|
3169
|
+
}
|
|
3170
|
+
const leadId = agentSessionId(agent) || ''
|
|
3171
|
+
reloadBoardIfStale(rt)
|
|
3172
|
+
const args = input && input.args
|
|
3173
|
+
const title = leadDispatchTitle(args)
|
|
3174
|
+
const note = leadDispatchNote(args)
|
|
3175
|
+
// 0) 一次性消费「组长刚置 doing」的意图:即使这次靠显式任务 id 认领,也要把它清掉,
|
|
3176
|
+
// 否则陈旧的 t-68 意图会在下一次无关的直聊派发里把旧任务认领走(t-69 事故的变体)。
|
|
3177
|
+
const intent = takeLeadDispatchIntent(rt, leadId, now)
|
|
3178
|
+
// 1) 显式任务 id(prompt 里的「任务 id:t-N」)优先:轮询任务的 worker / 返工都靠它认领。
|
|
3179
|
+
const explicitId = dispatchTaskIdFromPrompt(subagentPromptText(args))
|
|
3180
|
+
const explicit = explicitId === '' ? null : taskById(rt.state, explicitId)
|
|
3181
|
+
if (explicit && explicit.status !== 'archived') {
|
|
3182
|
+
return finishPreparedDispatch(rt, auto, store, exec, explicit, false, 'task-id', now)
|
|
3183
|
+
}
|
|
3184
|
+
// 1b) 「看板任务:t-N」式引用(0.2.4):组长直聊派活时手动建了卡、prompt 用这种写法也要认领,
|
|
3185
|
+
// 否则会为同一件事建两张卡。只认领待做 / 进行中且还没挂真实 worker 的卡片。
|
|
3186
|
+
const referencedId = dispatchReferencedTaskId(subagentPromptText(args))
|
|
3187
|
+
const referenced = referencedId === '' ? null : taskById(rt.state, referencedId)
|
|
3188
|
+
if (referenced && canReuseMentionedTask(referenced)) {
|
|
3189
|
+
return finishPreparedDispatch(rt, auto, store, exec, referenced, false, 'task-id-mention', now)
|
|
3190
|
+
}
|
|
3191
|
+
// 2) 组长刚把某条轮询任务置 doing → 这次派发就是它的 worker(要求 prompt 真的指向那条任务)。
|
|
3192
|
+
if (intent && dispatchMentionsTask(args, intent)) {
|
|
3193
|
+
return finishPreparedDispatch(rt, auto, store, exec, intent, false, 'lead-intent', now)
|
|
3194
|
+
}
|
|
3195
|
+
// 3) 同参数重复调用(模型重试 / PTC 嵌套)→ 复用刚建好还没挂 worker 的卡片。
|
|
3196
|
+
const pending = findPendingDispatchCard(rt.state, leadId, title, note, now)
|
|
3197
|
+
if (pending) return finishPreparedDispatch(rt, auto, store, exec, pending, false, 'pending-duplicate', now)
|
|
3198
|
+
// 4) 新派发:先建卡(doing + autoDispatch),写盘成功才允许启动 worker。
|
|
3199
|
+
const task = addTask(
|
|
3200
|
+
rt.state,
|
|
3201
|
+
{ title, note, source: 'agent', sessionId: leadId || null, cwd: leadDispatchCwd(rt, agent, args) },
|
|
3202
|
+
now,
|
|
3203
|
+
)
|
|
3204
|
+
applyTaskUpdate(rt.state, task.id, { status: 'doing' }, now)
|
|
3205
|
+
task.autoDispatch = LEAD_AUTO_MARK
|
|
3206
|
+
task.dispatchedSessionId = leadId || null
|
|
3207
|
+
task.dispatchedSessionTitle = sessionTitle(agent)
|
|
3208
|
+
task.lastError = ''
|
|
3209
|
+
task.updatedAt = iso(now)
|
|
3210
|
+
const saved = commitBoard(rt.state, rt.filePath)
|
|
3211
|
+
if (!saved || saved.saved === false) {
|
|
3212
|
+
// 卡没落盘 = 不能派发:回滚内存半成品,保持「板上有卡 ⇔ 真派了活」。
|
|
3213
|
+
removeTaskFromState(rt.state, task.id)
|
|
3214
|
+
auto.aborted += 1
|
|
3215
|
+
auto.updatedAt = iso(now)
|
|
3216
|
+
recordLeadAutoError(rt, '派发前建卡写盘失败,已中止派发:' + ((saved && saved.error) || '未知写盘错误'), now)
|
|
3217
|
+
return {
|
|
3218
|
+
ok: false,
|
|
3219
|
+
reason: 'write-failed',
|
|
3220
|
+
message: dispatchDeniedMessage('看板卡片写入失败', (saved && saved.error) || ''),
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
console.log('[taskboard] 派发前已建卡:' + task.id + ' ← 组长会话 ' + (leadId || '(unknown)'))
|
|
3224
|
+
return finishPreparedDispatch(rt, auto, store, exec, task, true, 'created', now)
|
|
3225
|
+
} catch (error) {
|
|
3226
|
+
auto.aborted += 1
|
|
3227
|
+
auto.updatedAt = iso(now)
|
|
3228
|
+
recordLeadAutoError(rt, '派发前建卡失败,已中止派发:' + describeError(error), now)
|
|
3229
|
+
return { ok: false, reason: 'error', message: dispatchDeniedMessage('看板卡片准备失败', describeError(error)) }
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
|
|
3233
|
+
/** tools/result 里的错误文本:优先 error.message,其次 content 的 text 块(post-execute block 只有 content)。 */
|
|
3234
|
+
function toolResultFailureText(result) {
|
|
3235
|
+
const error = result && result.error
|
|
3236
|
+
if (typeof error === 'string') return flattenResultLine(error, 200)
|
|
3237
|
+
if (isPlainObject(error)) {
|
|
3238
|
+
const message = asString(error.message)
|
|
3239
|
+
if (message !== '') return flattenResultLine(message, 200)
|
|
3240
|
+
const info = error.info
|
|
3241
|
+
if (isPlainObject(info)) {
|
|
3242
|
+
const name = asString(info.name).trim()
|
|
3243
|
+
const code = asString(info.code).trim()
|
|
3244
|
+
if (name !== '' || code !== '') return name + (code === '' ? '' : '(' + code + ')')
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
const content = result && result.content
|
|
3248
|
+
if (!Array.isArray(content)) return ''
|
|
3249
|
+
return flattenResultLine(
|
|
3250
|
+
content
|
|
3251
|
+
.map((block) => (block && block.type === 'text' && typeof block.text === 'string' ? block.text : ''))
|
|
3252
|
+
.filter((text) => text !== '')
|
|
3253
|
+
.join(' '),
|
|
3254
|
+
200,
|
|
3255
|
+
)
|
|
3256
|
+
}
|
|
3257
|
+
|
|
3258
|
+
/**
|
|
3259
|
+
* 非 activation 结果的原因摘要(写进卡片 `lastError='派发未启动:<摘要>'`)。
|
|
3260
|
+
* 覆盖 `isError`(被 pre-execute 拒绝 / post-execute block / 取消 / 启动失败)与返回形状未知两类。
|
|
3261
|
+
*/
|
|
3262
|
+
export function dispatchAbortSummary(result) {
|
|
3263
|
+
if (!isPlainObject(result)) return '没有收到工具执行结果'
|
|
3264
|
+
if (result.isError === true) {
|
|
3265
|
+
const detail = toolResultFailureText(result)
|
|
3266
|
+
return detail === '' ? '派发被拒绝或 worker 启动失败' : '工具调用失败:' + detail
|
|
3267
|
+
}
|
|
3268
|
+
const value = result.value
|
|
3269
|
+
if (!isPlainObject(value)) return '工具返回不是 activation(缺少 value)'
|
|
3270
|
+
if (value.kind !== 'activation') {
|
|
3271
|
+
const kind = asString(value.kind).trim()
|
|
3272
|
+
return '工具返回不是 activation' + (kind === '' ? '(缺少 kind)' : '(kind=' + kind + ')')
|
|
3273
|
+
}
|
|
3274
|
+
return 'activation 结果缺少 subagentId'
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3277
|
+
/**
|
|
3278
|
+
* §1.8(0.2.4,t-70 加固):派发没有真正启动 / **无法确认**已启动时,**绝不删除**闸门预建的卡片,
|
|
3279
|
+
* 只把它降级为可见的待开始记录:`status='todo'`、清掉派发字段、`lastError='派发未启动:<原因>'`,
|
|
3280
|
+
* 保留 title / note / cwd / sessionId。复用来的卡片(轮询任务 / 显式 taskId)绝不动。
|
|
3281
|
+
*
|
|
3282
|
+
* 为什么不删:`tools/result` 的非 activation 结果无法 100% 证明 worker 没启动——`tools/post-execute`
|
|
3283
|
+
* 的 `block` 发生在工具体执行之后、取消可能发生在启动之后、provider 返回形状也可能变化;删卡会抹掉
|
|
3284
|
+
* 一张 worker 可能正在使用的卡,重新制造「有活没卡」(与本任务初衷相反)。保守起见一律保留。
|
|
3285
|
+
*
|
|
3286
|
+
* 幂等:prepared 句柄是 WeakMap 一次性消费(同一 exec 第二次进入 = `no-prepared`);任务对象再加
|
|
3287
|
+
* WeakSet 防重复降级,`leadAuto.aborted` 只 +1 一次。
|
|
3288
|
+
* @param {string} [abortReason] 原因摘要(`dispatchAbortSummary(result)` 或调用方文案)
|
|
3289
|
+
* @returns {{released:boolean, taskId?:string, status?:string, reason?:string}}
|
|
3290
|
+
*/
|
|
3291
|
+
export function releasePreparedDispatch(rt, exec, abortReason = '', now = Date.now()) {
|
|
3292
|
+
const prepared = takePreparedDispatch(rt, exec)
|
|
3293
|
+
if (!prepared) return { released: false, reason: 'no-prepared' }
|
|
3294
|
+
if (prepared.created !== true) return { released: false, taskId: prepared.taskId, reason: 'reused' }
|
|
3295
|
+
try {
|
|
3296
|
+
reloadBoardIfStale(rt)
|
|
3297
|
+
const task = taskById(rt.state, prepared.taskId)
|
|
3298
|
+
if (!task) return { released: false, reason: 'missing' }
|
|
3299
|
+
if (!(rt.releasedDispatchTasks instanceof WeakSet)) rt.releasedDispatchTasks = new WeakSet()
|
|
3300
|
+
if (rt.releasedDispatchTasks.has(task)) return { released: false, taskId: task.id, reason: 'already-released' }
|
|
3301
|
+
const detail = trimmed(abortReason, 300) || '未知原因'
|
|
3302
|
+
const lastError = trimmed('派发未启动:' + detail, 500)
|
|
3303
|
+
if (task.status === 'doing') {
|
|
3304
|
+
try {
|
|
3305
|
+
// doing → todo:applyTaskUpdate 顺带清 assignee / autoDispatch / 通知记账,卡片回到普通待做队列。
|
|
3306
|
+
applyTaskUpdate(rt.state, task.id, { status: 'todo', assignee: '', lastError }, now)
|
|
3307
|
+
} catch (error) {
|
|
3308
|
+
// 归档等不可迁移状态:不猜、也不删卡,保留原状态只写 lastError。
|
|
3309
|
+
task.lastError = lastError
|
|
3310
|
+
task.updatedAt = iso(now)
|
|
3311
|
+
recordLeadAutoError(rt, '降级预建卡片失败(保留原状态):' + describeError(error), now)
|
|
3312
|
+
}
|
|
3313
|
+
} else {
|
|
3314
|
+
// 状态已被组长 / 用户改过(todo / done / archived):不改状态,只补可见原因。
|
|
3315
|
+
task.lastError = lastError
|
|
3316
|
+
task.updatedAt = iso(now)
|
|
3317
|
+
}
|
|
3318
|
+
// status→todo 已清 assignee / autoDispatch;这里再清掉「这次派发」的会话字段。
|
|
3319
|
+
// title / note / cwd / sessionId(创建者)保留:卡片仍是一条可读记录。
|
|
3320
|
+
task.dispatchedSessionId = null
|
|
3321
|
+
task.dispatchedSessionTitle = ''
|
|
3322
|
+
rt.releasedDispatchTasks.add(task)
|
|
3323
|
+
const auto = ensureLeadAuto(rt)
|
|
3324
|
+
auto.aborted += 1
|
|
3325
|
+
auto.lastTaskId = task.id
|
|
3326
|
+
auto.updatedAt = iso(now)
|
|
3327
|
+
const saved = commitBoard(rt.state, rt.filePath)
|
|
3328
|
+
if (saved && saved.saved === false) {
|
|
3329
|
+
recordLeadAutoError(rt, '降级派发预建卡片写盘失败:' + (saved.error || ''), now)
|
|
3330
|
+
}
|
|
3331
|
+
console.warn('[taskboard] 派发未启动,已把预建卡片降级为待开始:' + task.id + '(' + detail + ')')
|
|
3332
|
+
return { released: true, taskId: task.id, status: task.status }
|
|
3333
|
+
} catch (error) {
|
|
3334
|
+
recordLeadAutoError(rt, '降级派发预建卡片失败:' + describeError(error), now)
|
|
3335
|
+
return { released: false, reason: 'error' }
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
|
|
3339
|
+
/**
|
|
3340
|
+
* @deprecated 0.2.4 起不再删除预建卡片(见 `releasePreparedDispatch`);保留旧导出名兼容,
|
|
3341
|
+
* 行为等价于「降级为待开始」而不是删除。
|
|
3342
|
+
*/
|
|
3343
|
+
export const discardPreparedDispatch = releasePreparedDispatch
|
|
3344
|
+
|
|
2892
3345
|
/**
|
|
2893
|
-
* tools/result 命中「工作区组长成功派出 worker
|
|
3346
|
+
* tools/result 命中「工作区组长成功派出 worker」时把 worker 会话 id 挂到卡片上(§1.8)。
|
|
3347
|
+
*
|
|
3348
|
+
* 0.2.4 起卡片由 `tools/pre-execute` 的派发闸门(`prepareLeadDispatch`)在 worker 启动**之前**
|
|
3349
|
+
* 建好 / 认领好;这里优先消费闸门留下的 `exec → 卡片` 句柄(`prepared` 分支),只补 worker 字段。
|
|
3350
|
+
* 闸门没留下句柄(老宿主 / 单测直接调用)时退回旧的「观察后补建」路径,保证兜底也有记录。
|
|
2894
3351
|
* 只做副作用:永不抛出(失败只记 leadAuto.lastError),不阻断派发。
|
|
2895
|
-
* @param {{agent:object, childId:string, args?:object}} input
|
|
3352
|
+
* @param {{agent:object, childId:string, args?:object, exec?:object}} input
|
|
2896
3353
|
* @returns {{created:boolean, reason?:string, taskId?:string, task?:object}}
|
|
2897
3354
|
*/
|
|
2898
3355
|
export function handleSubagentDispatch(rt, input, now = Date.now()) {
|
|
@@ -2912,6 +3369,37 @@ export function handleSubagentDispatch(rt, input, now = Date.now()) {
|
|
|
2912
3369
|
return { created: false, reason: 'not-lead' }
|
|
2913
3370
|
}
|
|
2914
3371
|
reloadBoardIfStale(rt)
|
|
3372
|
+
// 0.2.4:闸门已经在 worker 启动前建好 / 认领好卡片 → 只补 worker 会话字段,绝不重复建卡。
|
|
3373
|
+
const prepared = takePreparedDispatch(rt, input && input.exec)
|
|
3374
|
+
if (prepared) {
|
|
3375
|
+
const task = taskById(rt.state, prepared.taskId)
|
|
3376
|
+
if (task) {
|
|
3377
|
+
const sessionId = agentSessionId(agent) || ''
|
|
3378
|
+
if (task.status !== 'doing') {
|
|
3379
|
+
try {
|
|
3380
|
+
applyTaskUpdate(rt.state, task.id, { status: 'doing' }, now)
|
|
3381
|
+
} catch {
|
|
3382
|
+
/* 归档等不可迁移状态:保留原状态,只补 worker 字段(不阻断派发) */
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
// 自动建的卡片归当前 worker;轮询任务只在还没挂 worker 时补——组长审核的对象不被覆盖。
|
|
3386
|
+
if (task.autoDispatch === LEAD_AUTO_MARK || task.assignee === '') task.assignee = childId
|
|
3387
|
+
if (sessionId !== '' && asString(task.dispatchedSessionId) === '') task.dispatchedSessionId = sessionId
|
|
3388
|
+
if (asString(task.dispatchedSessionTitle) === '') task.dispatchedSessionTitle = sessionTitle(agent)
|
|
3389
|
+
task.lastError = ''
|
|
3390
|
+
task.updatedAt = iso(now)
|
|
3391
|
+
const saved = commitBoard(rt.state, rt.filePath)
|
|
3392
|
+
auto.lastTaskId = task.id
|
|
3393
|
+
auto.lastWorkerSessionId = childId
|
|
3394
|
+
auto.updatedAt = iso(now)
|
|
3395
|
+
if (saved && saved.saved === false) {
|
|
3396
|
+
// worker 已经跑起来了(无法回退),但卡片在启动前已落盘:只记错误,让排障知道 worker 会话 id 没落盘。
|
|
3397
|
+
recordLeadAutoError(rt, 'worker 已启动,但卡片 worker 字段写盘失败:' + (saved.error || ''), now)
|
|
3398
|
+
}
|
|
3399
|
+
return { created: false, reason: 'prepared', taskId: task.id, task: { ...task } }
|
|
3400
|
+
}
|
|
3401
|
+
// 卡片在闸门之后被删掉了:继续走下面的兜底建卡,绝不出现「worker 在跑、看板没记录」。
|
|
3402
|
+
}
|
|
2915
3403
|
const existing = findTaskByWorker(rt.state, childId)
|
|
2916
3404
|
if (existing) {
|
|
2917
3405
|
auto.deduped += 1
|
|
@@ -2921,7 +3409,8 @@ export function handleSubagentDispatch(rt, input, now = Date.now()) {
|
|
|
2921
3409
|
const sessionId = agentSessionId(agent) || ''
|
|
2922
3410
|
const inFlight = findLeadInFlightTask(rt.state, sessionId, now)
|
|
2923
3411
|
if (inFlight) {
|
|
2924
|
-
//
|
|
3412
|
+
// 兜底路径(闸门未注册 / 卡片被删):组长正在处理轮询投递来的看板任务,这次 subagent 就当它是那条
|
|
3413
|
+
// 任务的 worker,别再建一条。注意:0.2.4 起直聊派发不再依赖这条判断——闸门会先建卡并留下 prepared 句柄。
|
|
2925
3414
|
auto.deduped += 1
|
|
2926
3415
|
auto.updatedAt = iso(now)
|
|
2927
3416
|
return { created: false, reason: 'lead-task-in-flight', taskId: inFlight.id }
|
|
@@ -3068,17 +3557,23 @@ export function registerLeadAutoHooks(ctx, rt) {
|
|
|
3068
3557
|
'tools/result',
|
|
3069
3558
|
(exec, result) => {
|
|
3070
3559
|
try {
|
|
3560
|
+
if (!exec || exec.name !== 'subagent') return
|
|
3071
3561
|
// §1.8 命中条件(三个条件缺一不可,避免别的工具输出里恰好带 subagentId 就误建任务):
|
|
3072
3562
|
// exec.name === 'subagent' + 非错误结果 + value 是 {kind:'activation', subagentId}。
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
const
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3563
|
+
const failed = !result || result.isError === true
|
|
3564
|
+
const value = result && result.value
|
|
3565
|
+
const activation = !failed && isPlainObject(value) && value.kind === 'activation'
|
|
3566
|
+
const childId = activation && typeof value.subagentId === 'string' ? value.subagentId.trim() : ''
|
|
3567
|
+
if (!activation || childId === '') {
|
|
3568
|
+
// §1.8(0.2.4,t-70 加固):无法确认 worker 已启动(被其它策略拒绝 / post-execute block /
|
|
3569
|
+
// 启动失败 / 取消 / 返回形状变化)→ **绝不删卡**,只把闸门预建的卡片降级为可见的待开始
|
|
3570
|
+
// 记录(status=todo + lastError)。删掉一张 worker 可能正在使用的卡 = 重新制造「有活没卡」。
|
|
3571
|
+
releasePreparedDispatch(rt, exec, dispatchAbortSummary(result))
|
|
3572
|
+
return
|
|
3573
|
+
}
|
|
3079
3574
|
const agent = exec.agent
|
|
3080
3575
|
if (!agent) return
|
|
3081
|
-
handleSubagentDispatch(rt, { agent, childId, args: exec.arguments })
|
|
3576
|
+
handleSubagentDispatch(rt, { agent, childId, args: exec.arguments, exec })
|
|
3082
3577
|
} catch (error) {
|
|
3083
3578
|
recordLeadAutoError(rt, '组长直聊派活挂钩失败:' + describeError(error))
|
|
3084
3579
|
}
|
|
@@ -3100,6 +3595,53 @@ export function registerLeadAutoHooks(ctx, rt) {
|
|
|
3100
3595
|
return true
|
|
3101
3596
|
}
|
|
3102
3597
|
|
|
3598
|
+
/**
|
|
3599
|
+
* 注册 §1.8(0.2.4)的**派发前强制建卡闸门**(`tools/pre-execute`)。
|
|
3600
|
+
*
|
|
3601
|
+
* 这是「没有卡片就不能派发」的硬约束:`tools/pre-execute` 是 tools 管线在**启动工具体之前**的
|
|
3602
|
+
* allow/deny 策略瀑布;这里只拦 `exec.name === 'subagent'` 且调用方预设有 `taskboard-dispatch`
|
|
3603
|
+
* 的派发(worker 自己的 subagent 调用 / 普通会话派子 Agent 一律 `next()` 放行)。
|
|
3604
|
+
* 返回 `{kind:'deny'}` 时工具体不会执行 → worker 不会启动,模型看到可操作错误。
|
|
3605
|
+
*
|
|
3606
|
+
* 注意:非本闸门的调用必须 `return next()`(waterfall 里不调用 next 会截断后面所有策略)。
|
|
3607
|
+
* @returns {boolean} 是否注册成功
|
|
3608
|
+
*/
|
|
3609
|
+
export function registerLeadDispatchGate(ctx, rt) {
|
|
3610
|
+
if (!ctx || typeof ctx.on !== 'function') {
|
|
3611
|
+
console.warn('[taskboard] ctx.on 不可用,跳过派发强制建卡闸门')
|
|
3612
|
+
return false
|
|
3613
|
+
}
|
|
3614
|
+
ctx.on(
|
|
3615
|
+
'tools/pre-execute',
|
|
3616
|
+
(exec, next) => {
|
|
3617
|
+
if (typeof next !== 'function') return { kind: 'allow' }
|
|
3618
|
+
if (!exec || exec.name !== 'subagent') return next()
|
|
3619
|
+
try {
|
|
3620
|
+
const agent = exec.agent
|
|
3621
|
+
if (!agent) return next()
|
|
3622
|
+
// 只拦工作区组长(taskboard-dispatch)的派发;worker / 普通会话的子 Agent 调用不受影响。
|
|
3623
|
+
if (sessionPresetOfContext(rt.ctx, agent) !== DISPATCH_PRESET_ID) return next()
|
|
3624
|
+
const outcome = prepareLeadDispatch(rt, { agent, exec, args: exec.arguments })
|
|
3625
|
+
if (!outcome.ok) {
|
|
3626
|
+
return {
|
|
3627
|
+
kind: 'deny',
|
|
3628
|
+
reason: outcome.message,
|
|
3629
|
+
info: { name: 'TaskboardDispatchError', code: outcome.reason === 'write-failed' ? 'internal' : 'bad-request' },
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3632
|
+
return next()
|
|
3633
|
+
} catch (error) {
|
|
3634
|
+
const message =
|
|
3635
|
+
'派发已中止:看板卡片准备失败(' + describeError(error) + ')。没有卡片不会启动 worker;请修复看板后重试。'
|
|
3636
|
+
recordLeadAutoError(rt, message)
|
|
3637
|
+
return { kind: 'deny', reason: message, info: { name: 'TaskboardDispatchError', code: 'internal' } }
|
|
3638
|
+
}
|
|
3639
|
+
},
|
|
3640
|
+
{ global: true },
|
|
3641
|
+
)
|
|
3642
|
+
return true
|
|
3643
|
+
}
|
|
3644
|
+
|
|
3103
3645
|
/** 冷会话唤醒失败的负缓存时长(5 分钟)。 */
|
|
3104
3646
|
const REVIVE_RETRY_MS = 5 * 60 * 1000
|
|
3105
3647
|
|
|
@@ -3435,6 +3977,16 @@ export function registerTools(toolCtx, rt) {
|
|
|
3435
3977
|
}
|
|
3436
3978
|
}
|
|
3437
3979
|
if (typeof patch.note === 'string') assertNoteAttachments(patch.note)
|
|
3980
|
+
// §1.8(0.2.4):组长把轮询投递任务置 doing = 即将为它启动 worker 的意图。必须在
|
|
3981
|
+
// applyTaskUpdate **之前**记(用任务更新前的字段判断「还没挂 worker」),供派发闸门一次性认领。
|
|
3982
|
+
if (patch.status === 'doing') {
|
|
3983
|
+
try {
|
|
3984
|
+
const agent = exec && exec.agent
|
|
3985
|
+
if (agent) noteLeadDispatchIntent(rt, agent, args.id)
|
|
3986
|
+
} catch {
|
|
3987
|
+
/* 意图只是加速认领;记录失败不影响更新本身 */
|
|
3988
|
+
}
|
|
3989
|
+
}
|
|
3438
3990
|
const task = applyTaskUpdate(rt.state, args.id, patch)
|
|
3439
3991
|
commitBoard(rt.state, rt.filePath)
|
|
3440
3992
|
// 任务刚变成 done(或从 done 重开):顺手尝试 flush 完成回执(§1.6 flush 时机)。
|
|
@@ -3473,6 +4025,12 @@ export function apply(ctx) {
|
|
|
3473
4025
|
},
|
|
3474
4026
|
// 组长直聊派活自动建任务(§1.8)的运行时计数 / 最近错误。
|
|
3475
4027
|
leadAuto: createLeadAutoState(),
|
|
4028
|
+
// §1.8(0.2.4):派发闸门的 exec → 预建卡片句柄(WeakMap,不落盘 / 不阻止 GC),
|
|
4029
|
+
// 以及组长「置 doing → 即将派 worker」的一次性意图(Map<组长会话 id, {taskId, at}>)。
|
|
4030
|
+
preparedDispatches: new WeakMap(),
|
|
4031
|
+
// t-70 加固:已降级为 todo 的预建卡片(WeakSet,防同一任务被重复降级 / 重复计数)。
|
|
4032
|
+
releasedDispatchTasks: new WeakSet(),
|
|
4033
|
+
leadDispatchIntent: new Map(),
|
|
3476
4034
|
}
|
|
3477
4035
|
|
|
3478
4036
|
try {
|
|
@@ -3580,4 +4138,13 @@ export function apply(ctx) {
|
|
|
3580
4138
|
} catch (error) {
|
|
3581
4139
|
console.warn('[taskboard] 组长直聊派活挂钩注册失败:' + describeError(error))
|
|
3582
4140
|
}
|
|
3583
|
-
|
|
4141
|
+
|
|
4142
|
+
// §1.8(0.2.4):派发前强制建卡闸门——没有卡片就不能启动 subagent worker。
|
|
4143
|
+
try {
|
|
4144
|
+
if (registerLeadDispatchGate(ctx, runtime)) {
|
|
4145
|
+
console.log('[taskboard] 派发强制建卡闸门已注册:tools/pre-execute(subagent)')
|
|
4146
|
+
}
|
|
4147
|
+
} catch (error) {
|
|
4148
|
+
console.warn('[taskboard] 派发强制建卡闸门注册失败:' + describeError(error))
|
|
4149
|
+
}
|
|
4150
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dispatch-board",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "DeepSeek Harness 插件:派单看板 + 派单模式。主 Agent 只拆解/派发/审核/汇报,子 Agent 干活;看板四列(待开始/进行中/已完成/已归档)由轮询自动派发,结论按 Markdown 展示。Dispatcher mode plus a dispatch board for DeepSeek Harness.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
消息以「【任务看板 · 待开始】」开头。收到后的固定动作:
|
|
33
33
|
1) 先 taskboard_update 把该任务置为 doing(硬要求,不要漏);
|
|
34
34
|
2) 用 subagent 派发一个 worker(agentPreset 已固定为 taskboard-worker,后台执行,不等待)。
|
|
35
|
-
prompt 必须自包含:任务 id
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
prompt 必须自包含:任务 id 与标题(宿主据此复用原卡片,**不要省略**)、任务的工作目录、
|
|
36
|
+
验收标准(任务备注)、以及回报模板(改了哪些文件 / 跑了什么命令 / 证据 / 验收结论 /
|
|
37
|
+
未完成的部分,用 Markdown 分条写)。子 Agent 看不到这段对话,别写「如上」「刚才那个」;
|
|
38
38
|
3) 一句话说明派了什么,然后结束本轮。不要在轮内等待、不要轮询、不要叙述你在等——
|
|
39
39
|
下一次行动的输入是子 Agent 的完成通知,它会为你开新一轮。
|
|
40
40
|
|
|
@@ -53,10 +53,14 @@
|
|
|
53
53
|
与已尝试的动作,必要时把任务回退 todo,交给人处理。
|
|
54
54
|
|
|
55
55
|
直聊派活(v0.2.0 补充):用户也可以直接在这个会话里要求你派活。照常先 subagent 派 worker
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
taskboard_add。
|
|
56
|
+
即可——宿主会在 **worker 启动前**强制建一条看板 doing 任务(带 autoDispatch 标记),worker
|
|
57
|
+
结束时自动写回 done + result(完成回执也由宿主汇总给主会话,你不用去找用户汇报)。这种场景
|
|
58
|
+
不要为了记录再手动 taskboard_add 一条(会重复);只有真正要另立任务(后续安排、跨工作区拆分
|
|
59
|
+
记账)才用 taskboard_add。
|
|
60
|
+
无卡不得派发(v0.2.4 硬规则):建卡写盘失败时宿主会**拒绝派发**(worker 不会启动),返回
|
|
61
|
+
「派发已中止:没有看板卡片就不能启动 worker」。按错误提示修复
|
|
62
|
+
$DSH_HOME/storages/dsh-taskboard/board.json 的写权限后重试,或先用 taskboard_add 建卡、
|
|
63
|
+
把卡号按「任务 id:t-N」写进 worker prompt 再重试;**不要绕过闸门**(例如改名/直接调其它工具)。
|
|
60
64
|
注意:自动收尾只对宿主自动建的任务生效。轮询投递来的任务(看板原本就有、消息以
|
|
61
65
|
「【任务看板 · 待开始】」开头)始终由你审核后 taskboard_update 写回 done 或打回 doing,
|
|
62
66
|
宿主不会替你置 done。
|