dsh-dispatch-board 0.5.1 → 0.5.9
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 +12 -4
- package/lib/client.js +344 -142
- package/lib/index.js +327 -53
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
- package/presets/taskboard.patch.yml +4 -0
package/lib/index.js
CHANGED
|
@@ -181,7 +181,7 @@ const GIT_INFO_CACHE_MS = 15 * 1000
|
|
|
181
181
|
const WORKTREE_DEP_DIRS = Object.freeze(['node_modules', '.venv', 'venv'])
|
|
182
182
|
const WORKTREE_SCAN_SKIP_DIRS = new Set(['.git', 'node_modules', '.venv', 'venv', 'dist', 'build', 'out', 'target'])
|
|
183
183
|
|
|
184
|
-
/**
|
|
184
|
+
/** 四个状态列(v0.5.4 起「已归档」列默认隐藏、可折叠)。顺序即 UI 列顺序。 */
|
|
185
185
|
export const STATUSES = ['todo', 'doing', 'done', 'archived']
|
|
186
186
|
|
|
187
187
|
/** 合法状态迁移(含原地更新)。轮询只扫 todo。 */
|
|
@@ -1401,14 +1401,60 @@ export function extractGitApplyConflictFiles(stderrText) {
|
|
|
1401
1401
|
return files
|
|
1402
1402
|
}
|
|
1403
1403
|
|
|
1404
|
+
/**
|
|
1405
|
+
* v0.5.2:把 `git diff` 输出按 `diff --git` 头切成**文件级**补丁(Buffer 粒度,binary / rename /
|
|
1406
|
+
* mode 段原样保留,不会切开单个文件的多个 hunk)。空 diff → `[]`;单文件 → 1 段;
|
|
1407
|
+
* `diff --git` 之前的杂项前导(当前 git 不会产生)直接丢弃。
|
|
1408
|
+
*/
|
|
1409
|
+
export function splitGitPatchByFile(diffBuf) {
|
|
1410
|
+
const buf = Buffer.isBuffer(diffBuf) ? diffBuf : Buffer.from(diffBuf == null ? '' : String(diffBuf), 'utf8')
|
|
1411
|
+
if (buf.length === 0) return []
|
|
1412
|
+
const headMarker = Buffer.from('diff --git ')
|
|
1413
|
+
const marker = Buffer.from('\ndiff --git ')
|
|
1414
|
+
let cursor = 0
|
|
1415
|
+
if (!buf.subarray(0, headMarker.length).equals(headMarker)) {
|
|
1416
|
+
const first = buf.indexOf(marker)
|
|
1417
|
+
if (first === -1) return []
|
|
1418
|
+
cursor = first + 1
|
|
1419
|
+
}
|
|
1420
|
+
const chunks = []
|
|
1421
|
+
while (cursor < buf.length) {
|
|
1422
|
+
const next = buf.indexOf(marker, cursor + 1)
|
|
1423
|
+
if (next === -1) {
|
|
1424
|
+
chunks.push(buf.subarray(cursor))
|
|
1425
|
+
break
|
|
1426
|
+
}
|
|
1427
|
+
chunks.push(buf.subarray(cursor, next + 1))
|
|
1428
|
+
cursor = next + 1
|
|
1429
|
+
}
|
|
1430
|
+
return chunks.filter((chunk) => chunk.length > 0)
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
/** 从单文件补丁的 `diff --git` 头取目标路径(b/ 侧),仅用于面向组长的摘要 / 冲突说明。 */
|
|
1434
|
+
function patchTargetPath(patchBuf) {
|
|
1435
|
+
const head = patchBuf.toString('utf8', 0, Math.min(patchBuf.length, 8192))
|
|
1436
|
+
const firstLine = head.split('\n', 1)[0] || ''
|
|
1437
|
+
const rest = firstLine.startsWith('diff --git ') ? firstLine.slice('diff --git '.length).trim() : firstLine.trim()
|
|
1438
|
+
const quoted = /^"a\/(.+)"\s+"b\/(.+)"$/.exec(rest)
|
|
1439
|
+
if (quoted) return quoted[2]
|
|
1440
|
+
const idx = rest.indexOf(' b/')
|
|
1441
|
+
if (idx !== -1) return rest.slice(idx + 3)
|
|
1442
|
+
return rest === '' ? '(未知文件)' : rest
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1404
1445
|
/**
|
|
1405
1446
|
* 将指定任务的隔离 Git Worktree 改动原子预检并合入主工作区,成功后自动回收 Worktree 与临时分支。
|
|
1406
1447
|
*
|
|
1407
1448
|
* - 先卸载所有依赖 Junction,再把 Worktree 内未提交文件快照提交至临时分支 `taskboard/<id>`;
|
|
1408
|
-
* - 用 `git diff --binary --full-index -U1 <base>..<wtHead>`
|
|
1409
|
-
* -
|
|
1410
|
-
* -
|
|
1411
|
-
*
|
|
1449
|
+
* - 用 `git diff --binary --full-index -U1 <base>..<wtHead>` 生成补丁,**按文件粒度**在主工作区预检
|
|
1450
|
+
* (v0.5.2,t-209:整份补丁一次性判定会把「前序切片已改过同一文件」误判成整卡冲突):
|
|
1451
|
+
* - 每个文件补丁先跑 `git apply --check --reverse`:通过 = 主工作区已存在该改动 → alreadyApplied,
|
|
1452
|
+
* 跳过、不重复应用;
|
|
1453
|
+
* - 其余文件拼成子集补丁,`git apply --check` 通过 → `git apply` 写入主工作区(兼容主工作区已有
|
|
1454
|
+
* 未提交 WIP 或前序切片改动,不污染主分支 commit 历史),成功后照旧回收 Worktree;
|
|
1455
|
+
* - 子集里仍有文件判定失败 → 真实冲突:主工作区保持 100% 未修改,恢复 Worktree 依赖软链并返回
|
|
1456
|
+
* `{merged:false, conflict:true, conflictFiles}`(摘要里标出哪些文件其实已在主工作区,方便组长核对);
|
|
1457
|
+
* - 全部文件 alreadyApplied → 视为幂等成功(`merged:true`),只回收 Worktree。
|
|
1412
1458
|
*/
|
|
1413
1459
|
export function mergeAndCleanupTaskWorktree(rt, taskId, options = {}) {
|
|
1414
1460
|
const task = findTask(rt.state, taskId)
|
|
@@ -1570,54 +1616,75 @@ export function mergeAndCleanupTaskWorktree(rt, taskId, options = {}) {
|
|
|
1570
1616
|
)
|
|
1571
1617
|
if (!diffBuf || diffBuf.length === 0) return finishNoChanges()
|
|
1572
1618
|
|
|
1573
|
-
// 4) 主工作区原子预检(不触碰 git index
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
windowsHide: true,
|
|
1581
|
-
timeout: 15000,
|
|
1582
|
-
})
|
|
1583
|
-
} catch (checkError) {
|
|
1619
|
+
// 4) 主工作区原子预检(不触碰 git index,失败绝不留半截改动或冲突标记)。
|
|
1620
|
+
// v0.5.2(t-209):按**文件**粒度判定——主工作区已经存在某个文件的改动时(前序切片 / 用户手动改过),
|
|
1621
|
+
// 只跳过该文件、继续补入其它文件;不再因为一个文件已合入就把整份补丁判成冲突。
|
|
1622
|
+
const filePatches = splitGitPatchByFile(diffBuf)
|
|
1623
|
+
if (filePatches.length === 0) return finishNoChanges()
|
|
1624
|
+
|
|
1625
|
+
const checkPatch = (patchBuf, extraFlags = []) => {
|
|
1584
1626
|
try {
|
|
1585
|
-
execFileSync(
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1627
|
+
execFileSync(
|
|
1628
|
+
'git',
|
|
1629
|
+
['-C', repoRoot, 'apply', '--check', ...extraFlags, '--whitespace=nowarn', '-'],
|
|
1630
|
+
{
|
|
1631
|
+
input: patchBuf,
|
|
1632
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
1633
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
1634
|
+
windowsHide: true,
|
|
1635
|
+
timeout: 15000,
|
|
1636
|
+
},
|
|
1637
|
+
)
|
|
1638
|
+
return { ok: true, stderr: '' }
|
|
1639
|
+
} catch (error) {
|
|
1640
|
+
return { ok: false, stderr: String((error && error.stderr) || describeError(error)) }
|
|
1595
1641
|
}
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
const alreadyAppliedPatches = []
|
|
1645
|
+
const pendingPatches = []
|
|
1646
|
+
for (const patch of filePatches) {
|
|
1647
|
+
// `--check --reverse` 通过 = 主工作区已存在该文件的这份改动(alreadyApplied),不再重复应用。
|
|
1648
|
+
if (checkPatch(patch, ['--reverse']).ok) alreadyAppliedPatches.push(patch)
|
|
1649
|
+
else pendingPatches.push(patch)
|
|
1650
|
+
}
|
|
1651
|
+
const alreadyAppliedFiles = alreadyAppliedPatches.map((patch) => patchTargetPath(patch))
|
|
1652
|
+
const existingNote =
|
|
1653
|
+
alreadyAppliedFiles.length > 0
|
|
1654
|
+
? alreadyAppliedFiles.length + ' 个文件已在主工作区存在:' + alreadyAppliedFiles.join(', ')
|
|
1655
|
+
: ''
|
|
1656
|
+
|
|
1657
|
+
const conflictReturn = (stderrText) => {
|
|
1658
|
+
task.worktreeLinks = linkWorktreeDependencies(repoRoot, wtPath)
|
|
1659
|
+
const conflictFiles = extractGitApplyConflictFiles(stderrText)
|
|
1660
|
+
task.updatedAt = iso(Date.now())
|
|
1661
|
+
if (shouldCommitBoard) commitBoard(rt.state, rt.filePath)
|
|
1662
|
+
const conflictDesc =
|
|
1663
|
+
conflictFiles.length > 0 ? conflictFiles.join(', ') : flattenResultLine(stderrText, 180)
|
|
1664
|
+
return {
|
|
1665
|
+
id: task.id,
|
|
1666
|
+
merged: false,
|
|
1667
|
+
noChanges: false,
|
|
1668
|
+
conflict: true,
|
|
1669
|
+
cleaned: false,
|
|
1670
|
+
branch,
|
|
1671
|
+
worktreePath: wtPath,
|
|
1672
|
+
conflictFiles,
|
|
1673
|
+
summary:
|
|
1674
|
+
'合入主工作区检测到冲突(主工作区未被修改):' + conflictDesc +
|
|
1675
|
+
(existingNote === '' ? '' : ';' + existingNote) +
|
|
1676
|
+
';隔离工作树保留在 ' + wtPath,
|
|
1615
1677
|
}
|
|
1616
1678
|
}
|
|
1617
1679
|
|
|
1618
|
-
if (
|
|
1680
|
+
if (pendingPatches.length > 0) {
|
|
1681
|
+
const pendingBuf = Buffer.concat(pendingPatches)
|
|
1682
|
+
const forward = checkPatch(pendingBuf)
|
|
1683
|
+
// 子集里仍有文件应用失败 → 维持原有冲突语义(主工作区不动、保留工作树),
|
|
1684
|
+
// 摘要里标出哪些文件其实已在主工作区,方便组长核对后手动处理。
|
|
1685
|
+
if (!forward.ok) return conflictReturn(forward.stderr)
|
|
1619
1686
|
execFileSync('git', ['-C', repoRoot, 'apply', '--whitespace=nowarn', '-'], {
|
|
1620
|
-
input:
|
|
1687
|
+
input: pendingBuf,
|
|
1621
1688
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
1622
1689
|
maxBuffer: 64 * 1024 * 1024,
|
|
1623
1690
|
windowsHide: true,
|
|
@@ -1634,6 +1701,22 @@ export function mergeAndCleanupTaskWorktree(rt, taskId, options = {}) {
|
|
|
1634
1701
|
}
|
|
1635
1702
|
task.updatedAt = iso(Date.now())
|
|
1636
1703
|
if (shouldCommitBoard) commitBoard(rt.state, rt.filePath)
|
|
1704
|
+
let summary
|
|
1705
|
+
if (alreadyAppliedPatches.length === 0) {
|
|
1706
|
+
summary = '已将隔离工作树改动合入主工作区' + (cleaned ? '并清理临时分支 ' + branch : '')
|
|
1707
|
+
} else if (pendingPatches.length === 0) {
|
|
1708
|
+
summary =
|
|
1709
|
+
'隔离工作树的 ' + alreadyAppliedPatches.length + ' 个文件已在主工作区存在(无需重复应用)' +
|
|
1710
|
+
(cleaned ? ',已回收临时工作树与分支 ' + branch : '')
|
|
1711
|
+
} else {
|
|
1712
|
+
summary =
|
|
1713
|
+
'已将隔离工作树改动合入主工作区(' +
|
|
1714
|
+
alreadyAppliedPatches.length +
|
|
1715
|
+
' 个文件已在主工作区存在,仅补入 ' +
|
|
1716
|
+
pendingPatches.length +
|
|
1717
|
+
' 个)' +
|
|
1718
|
+
(cleaned ? ',已清理临时分支 ' + branch : '')
|
|
1719
|
+
}
|
|
1637
1720
|
return {
|
|
1638
1721
|
id: task.id,
|
|
1639
1722
|
merged: true,
|
|
@@ -1643,7 +1726,7 @@ export function mergeAndCleanupTaskWorktree(rt, taskId, options = {}) {
|
|
|
1643
1726
|
branch,
|
|
1644
1727
|
worktreePath: task.worktreePath || '',
|
|
1645
1728
|
conflictFiles: [],
|
|
1646
|
-
summary
|
|
1729
|
+
summary,
|
|
1647
1730
|
}
|
|
1648
1731
|
}
|
|
1649
1732
|
|
|
@@ -2782,6 +2865,43 @@ function workspaceLabelFor(key, cwd, workspaces) {
|
|
|
2782
2865
|
return baseName(cwd)
|
|
2783
2866
|
}
|
|
2784
2867
|
|
|
2868
|
+
/**
|
|
2869
|
+
* v0.5.7:此刻**真正在跑**的会话 id 列表(snapshot.runningSessions,§3.2)。
|
|
2870
|
+
* 纯运行时视图,不落盘、不改任务模型:
|
|
2871
|
+
* 1. agents.roots() 里 status === 'running' 的根会话;
|
|
2872
|
+
* 2. 所有任务里 `workerSessionId` 非空、且 `agents.get(id)` 的 status === 'running' 的 worker 会话
|
|
2873
|
+
* (worker 是子 Agent,不在 agents.roots() 里,只能按 id 查)。
|
|
2874
|
+
* Client 用它给「进行中 + worker 在跑」的卡片标题前挂转圈动画。
|
|
2875
|
+
*/
|
|
2876
|
+
export function collectRunningSessions(agents, state) {
|
|
2877
|
+
const out = []
|
|
2878
|
+
const seen = new Set()
|
|
2879
|
+
const push = (sessionId) => {
|
|
2880
|
+
if (typeof sessionId !== 'string' || sessionId === '' || seen.has(sessionId)) return
|
|
2881
|
+
seen.add(sessionId)
|
|
2882
|
+
out.push(sessionId)
|
|
2883
|
+
}
|
|
2884
|
+
let roots = []
|
|
2885
|
+
try {
|
|
2886
|
+
roots = agents && typeof agents.roots === 'function' ? agents.roots() : []
|
|
2887
|
+
} catch {
|
|
2888
|
+
roots = []
|
|
2889
|
+
}
|
|
2890
|
+
for (const agent of Array.isArray(roots) ? roots : []) {
|
|
2891
|
+
if (!agent || agent.status !== 'running') continue
|
|
2892
|
+
push(agentSessionId(agent))
|
|
2893
|
+
}
|
|
2894
|
+
const tasks = state && Array.isArray(state.tasks) ? state.tasks : []
|
|
2895
|
+
for (const task of tasks) {
|
|
2896
|
+
if (!task) continue
|
|
2897
|
+
const workerId = asString(task.workerSessionId).trim()
|
|
2898
|
+
if (workerId === '') continue
|
|
2899
|
+
const live = liveAgentOf(agents, workerId)
|
|
2900
|
+
if (live && live.status === 'running') push(workerId)
|
|
2901
|
+
}
|
|
2902
|
+
return out
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2785
2905
|
/** 工作区组长运行时视图(snapshot.leads.workspaces,§3.2):按 config.workspaceLeads 的对象键顺序。 */
|
|
2786
2906
|
export function buildWorkspaceLeadRefs(config, agents, workspaces, archived = new Set()) {
|
|
2787
2907
|
const cfg = normalizeConfig(config)
|
|
@@ -2826,6 +2946,8 @@ export function buildSnapshot(rt, now = Date.now(), preset = rt.presetInfo || nu
|
|
|
2826
2946
|
lastSkipReason: rt.poll.lastSkipReason || null,
|
|
2827
2947
|
},
|
|
2828
2948
|
agents: listAgents(rt),
|
|
2949
|
+
// v0.5.7:此刻 running 的会话 id(根会话 + 任务 worker 会话),纯运行时视图(§3.2 / §5.2)。
|
|
2950
|
+
runningSessions: collectRunningSessions(agentsService, rt.state),
|
|
2829
2951
|
workspaces,
|
|
2830
2952
|
// v0.2.0:组长 / 主会话运行时视图(组长条用;revision 不变也会变)。
|
|
2831
2953
|
leads: {
|
|
@@ -3255,6 +3377,20 @@ function pruneArchivedBoard(rt, now = Date.now()) {
|
|
|
3255
3377
|
return outcome.removed
|
|
3256
3378
|
}
|
|
3257
3379
|
|
|
3380
|
+
/**
|
|
3381
|
+
* v0.5.2:卡住自动卡提醒的去重表(进程内 Set,不落盘)。键 = 任务 id + updatedAt——
|
|
3382
|
+
* 同一次「worker 已结束但卡片还停在 doing」只提醒一次;任务再有新的结束事件(updatedAt 变了)
|
|
3383
|
+
* 会重新提醒,不会因为历史去重而永久失声。
|
|
3384
|
+
*/
|
|
3385
|
+
function stuckAlertedSet(rt) {
|
|
3386
|
+
if (!(rt.stuckAlerted instanceof Set)) rt.stuckAlerted = new Set()
|
|
3387
|
+
return rt.stuckAlerted
|
|
3388
|
+
}
|
|
3389
|
+
|
|
3390
|
+
function stuckAlertKey(task) {
|
|
3391
|
+
return asString(task && task.id) + '@' + asString(task && task.updatedAt)
|
|
3392
|
+
}
|
|
3393
|
+
|
|
3258
3394
|
/**
|
|
3259
3395
|
* v0.4.0:巡检并自愈失联的 `doing` 任务(进程重启掉线 / worker 异常退出未发 `subagent/end`)。
|
|
3260
3396
|
*
|
|
@@ -3263,9 +3399,13 @@ function pruneArchivedBoard(rt, now = Date.now()) {
|
|
|
3263
3399
|
* `lastError` 写明失联重排原因;
|
|
3264
3400
|
* - **内部切片子卡**(`autoDispatch === LEAD_AUTO_MARK` 且 `parentTaskId` 非空):保持 `doing`,标 `workerRunState = 'failed'`
|
|
3265
3401
|
* 并写 `lastError`;若所属组长会话在线且 `idle`,合并发送一条「异常恢复」提醒交组长续做或归档。
|
|
3402
|
+
* - **v0.5.2 卡住提醒**:`doing` + `autoDispatch === LEAD_AUTO_MARK` + `workerRunState` 已经是
|
|
3403
|
+
* `'ended'` / `'failed'`(worker 结束事件处理过、但卡片因非 completed / 合入冲突 / 认领失败停在 doing)
|
|
3404
|
+
* + 超过 `ORPHAN_GRACE_MS` 没再更新 → 组长 `idle` 时发一条**一次性**提醒(卡 id / 卡在哪一步 /
|
|
3405
|
+
* lastError 摘要 / 处理提示)。**绝不自动改状态**(收尾与合入必须由组长判断),用 rt 上的内存 Set 去重。
|
|
3266
3406
|
*/
|
|
3267
3407
|
export async function reconcileOrphanedDoingTasks(rt, options = {}) {
|
|
3268
|
-
const outcome = { requeued: 0, markedFailed: 0, ids: [] }
|
|
3408
|
+
const outcome = { requeued: 0, markedFailed: 0, reminded: 0, ids: [] }
|
|
3269
3409
|
if (!rt || !rt.state || !Array.isArray(rt.state.tasks)) return outcome
|
|
3270
3410
|
const startup = options.startup === true
|
|
3271
3411
|
const now = Number.isFinite(Number(options.now)) ? Number(options.now) : Date.now()
|
|
@@ -3291,6 +3431,8 @@ export async function reconcileOrphanedDoingTasks(rt, options = {}) {
|
|
|
3291
3431
|
|
|
3292
3432
|
const stamp = iso(now)
|
|
3293
3433
|
const leadAlerts = new Map()
|
|
3434
|
+
// v0.5.2:worker 已结束但卡片仍在 doing 的自动卡(只提醒,不改状态)。
|
|
3435
|
+
const stuckAlerts = new Map()
|
|
3294
3436
|
let changed = false
|
|
3295
3437
|
|
|
3296
3438
|
for (const task of rt.state.tasks) {
|
|
@@ -3338,7 +3480,21 @@ export async function reconcileOrphanedDoingTasks(rt, options = {}) {
|
|
|
3338
3480
|
orphaned = true
|
|
3339
3481
|
}
|
|
3340
3482
|
|
|
3341
|
-
if (!orphaned)
|
|
3483
|
+
if (!orphaned) {
|
|
3484
|
+
if (
|
|
3485
|
+
task.autoDispatch === LEAD_AUTO_MARK &&
|
|
3486
|
+
(task.workerRunState === 'ended' || task.workerRunState === 'failed') &&
|
|
3487
|
+
ageMs >= graceMs
|
|
3488
|
+
) {
|
|
3489
|
+
const leadId = asString(task.dispatchedSessionId || task.sessionId).trim()
|
|
3490
|
+
if (leadId !== '') {
|
|
3491
|
+
const list = stuckAlerts.get(leadId) || []
|
|
3492
|
+
list.push(task)
|
|
3493
|
+
stuckAlerts.set(leadId, list)
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
continue
|
|
3497
|
+
}
|
|
3342
3498
|
changed = true
|
|
3343
3499
|
outcome.ids.push(task.id)
|
|
3344
3500
|
|
|
@@ -3407,6 +3563,52 @@ export async function reconcileOrphanedDoingTasks(rt, options = {}) {
|
|
|
3407
3563
|
}
|
|
3408
3564
|
}
|
|
3409
3565
|
|
|
3566
|
+
// v0.5.2:worker 已经结束、卡片却还停在 doing(非 completed / 合入冲突 / 认领失败)时,
|
|
3567
|
+
// 组长 idle 就发一条一次性提醒——绝不自动改状态,只把「卡在哪一步 + 原因 + 怎么收尾」说清楚。
|
|
3568
|
+
if (!startup && stuckAlerts.size > 0 && agents) {
|
|
3569
|
+
const archived = archivedSessionIdSet(rt)
|
|
3570
|
+
const reminded = stuckAlertedSet(rt)
|
|
3571
|
+
for (const [leadId, stuckTasks] of stuckAlerts.entries()) {
|
|
3572
|
+
if (archived.has(leadId)) continue
|
|
3573
|
+
const leadAgent = liveAgentOf(agents, leadId)
|
|
3574
|
+
if (!leadAgent || leadAgent.status !== 'idle') continue
|
|
3575
|
+
const pending = stuckTasks.filter((task) => !reminded.has(stuckAlertKey(task)))
|
|
3576
|
+
if (pending.length === 0) continue
|
|
3577
|
+
const lines = [
|
|
3578
|
+
'【任务看板 · 卡住提醒】以下自动卡的任务已经结束,但看板还停在「进行中」(宿主不会自动改状态):',
|
|
3579
|
+
]
|
|
3580
|
+
for (const item of pending) {
|
|
3581
|
+
const step =
|
|
3582
|
+
(asString(item.parentTaskId) === '' ? '顶层任务' : '切片 · 父任务 ' + item.parentTaskId) +
|
|
3583
|
+
' · worker 已结束(' +
|
|
3584
|
+
asString(item.workerRunState) +
|
|
3585
|
+
')'
|
|
3586
|
+
const reason = trimmed(item.lastError, 200)
|
|
3587
|
+
lines.push('- ' + item.id + '(' + step + ')' + item.title + (reason === '' ? '' : ' · ' + reason))
|
|
3588
|
+
if (asString(item.worktreePath) !== '') {
|
|
3589
|
+
lines.push(' 隔离工作树还没合入:' + item.worktreePath + '(先 taskboard_merge_worktree 处理冲突 / 合入)')
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
lines.push(
|
|
3593
|
+
'请核对后收尾:直接 taskboard_update {id, status:"done", result:"…"};若挂有隔离工作树,先 taskboard_merge_worktree 合入(或传 discardOnly:true 回收)。宿主不会自动改状态。',
|
|
3594
|
+
)
|
|
3595
|
+
try {
|
|
3596
|
+
leadAgent.followup(createBoardUserMessage(lines.join('\n')))
|
|
3597
|
+
const sessions = serviceOf(rt.ctx, 'sessions')
|
|
3598
|
+
if (sessions && typeof sessions.flush === 'function') await sessions.flush(leadAgent.session)
|
|
3599
|
+
for (const item of pending) {
|
|
3600
|
+
reminded.add(stuckAlertKey(item))
|
|
3601
|
+
outcome.reminded += 1
|
|
3602
|
+
}
|
|
3603
|
+
console.warn(
|
|
3604
|
+
'[taskboard] 已提醒组长处理卡住的自动卡:' + pending.map((item) => item.id).join('、'),
|
|
3605
|
+
)
|
|
3606
|
+
} catch (error) {
|
|
3607
|
+
console.warn('[taskboard] 发送卡住自动卡提醒失败:' + describeError(error))
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
|
|
3410
3612
|
return outcome
|
|
3411
3613
|
}
|
|
3412
3614
|
|
|
@@ -5019,18 +5221,27 @@ export async function handleSubagentEnd(rt, info, now = Date.now()) {
|
|
|
5019
5221
|
task = findTaskByWorker(rt.state, childId)
|
|
5020
5222
|
}
|
|
5021
5223
|
if (!task) {
|
|
5224
|
+
// v0.5.2:放宽兜底候选——workerSessionId 还没回填时,卡片可能已进入 ended / failed / null
|
|
5225
|
+
// (上一次 aborted 收尾、或宿主重启归一化),不能再要求 workerRunState === 'running',
|
|
5226
|
+
// 否则结束事件永远认领不到卡、卡片停在 doing 又没有任何外部提示。
|
|
5227
|
+
// 只按「该组长名下 + doing 自动卡 + workerSessionId 为空或正是本次 childId」筛,
|
|
5228
|
+
// 再用 info.name / assignee 精确匹配;多候选无法区分时不猜。
|
|
5022
5229
|
const candidates = rt.state.tasks.filter(
|
|
5023
5230
|
(candidate) =>
|
|
5024
5231
|
candidate &&
|
|
5025
5232
|
candidate.autoDispatch === LEAD_AUTO_MARK &&
|
|
5026
5233
|
candidate.status === 'doing' &&
|
|
5027
|
-
asString(candidate.workerRunState) === 'running' &&
|
|
5028
5234
|
asString(candidate.sessionId) === parentId &&
|
|
5029
|
-
asString(candidate.workerSessionId) === ''
|
|
5235
|
+
(asString(candidate.workerSessionId) === '' ||
|
|
5236
|
+
asString(candidate.workerSessionId) === childId),
|
|
5030
5237
|
)
|
|
5031
5238
|
if (workerName !== '') {
|
|
5032
5239
|
const byName = candidates.filter((candidate) => asString(candidate.assignee) === workerName)
|
|
5033
5240
|
if (byName.length === 1) task = byName[0]
|
|
5241
|
+
// 名字对不上、但只剩一条且 assignee 还没写(tools/result 没走到 / 回填失败):不算猜测。
|
|
5242
|
+
if (!task && byName.length === 0 && candidates.length === 1 && asString(candidates[0].assignee) === '') {
|
|
5243
|
+
task = candidates[0]
|
|
5244
|
+
}
|
|
5034
5245
|
}
|
|
5035
5246
|
if (!task && workerName === '' && candidates.length === 1) {
|
|
5036
5247
|
task = candidates[0]
|
|
@@ -5041,6 +5252,35 @@ export async function handleSubagentEnd(rt, info, now = Date.now()) {
|
|
|
5041
5252
|
const rawStopReason = asString(info && info.stopReason).trim()
|
|
5042
5253
|
const stopReason = rawStopReason === '' ? 'unknown' : rawStopReason
|
|
5043
5254
|
if (!task) {
|
|
5255
|
+
// v0.5.2:认领不到卡片时不再静默——该组长名下若确实还有 doing 的自动卡,说明收尾逻辑漏了,
|
|
5256
|
+
// 必须留下可查的告警(含 childId / name / parentId / stopReason),交给组长人工核对。
|
|
5257
|
+
if (parentId !== '') {
|
|
5258
|
+
const lingering = rt.state.tasks.filter(
|
|
5259
|
+
(candidate) =>
|
|
5260
|
+
candidate &&
|
|
5261
|
+
candidate.autoDispatch === LEAD_AUTO_MARK &&
|
|
5262
|
+
candidate.status === 'doing' &&
|
|
5263
|
+
(asString(candidate.sessionId) === parentId ||
|
|
5264
|
+
asString(candidate.dispatchedSessionId) === parentId),
|
|
5265
|
+
)
|
|
5266
|
+
if (lingering.length > 0) {
|
|
5267
|
+
recordLeadAutoError(
|
|
5268
|
+
rt,
|
|
5269
|
+
'worker 结束但没有匹配到看板自动卡:childId=' +
|
|
5270
|
+
childId +
|
|
5271
|
+
',name=' +
|
|
5272
|
+
(workerName === '' ? '(未知)' : workerName) +
|
|
5273
|
+
',parentId=' +
|
|
5274
|
+
parentId +
|
|
5275
|
+
',stopReason=' +
|
|
5276
|
+
stopReason +
|
|
5277
|
+
';该组长名下仍有 doing 的自动卡 ' +
|
|
5278
|
+
lingering.map((candidate) => candidate.id).join('、') +
|
|
5279
|
+
',需要人工核对',
|
|
5280
|
+
now,
|
|
5281
|
+
)
|
|
5282
|
+
}
|
|
5283
|
+
}
|
|
5044
5284
|
// 不是宿主建的自动任务(例如组长审核时派去跑命令的验证子 Agent,
|
|
5045
5285
|
// 或轮询投递任务的 worker——那条任务的 autoDispatch 为 null):仅收敛其 workerRunState。
|
|
5046
5286
|
settleNonAutoWorkerRunState(rt, childId, parentId, workerName, stopReason, now)
|
|
@@ -5220,10 +5460,34 @@ export function registerLeadAutoHooks(ctx, rt) {
|
|
|
5220
5460
|
return true
|
|
5221
5461
|
}
|
|
5222
5462
|
|
|
5463
|
+
/**
|
|
5464
|
+
* v0.5.2:`description` / `prompt` 里「用户明确要求留在主工作区」的措辞。
|
|
5465
|
+
*
|
|
5466
|
+
* 否定对象必须正好是「(建 / 用)隔离工作树」本身:像「不要删除隔离工作树里的文件」
|
|
5467
|
+
* 「不要在隔离工作树里装依赖」这类句子,否定的是「删除 / 装依赖」而不是「隔离」,
|
|
5468
|
+
* 绝不能命中——否则会把本该隔离执行的活错误地拉回主工作区并发踩踏。
|
|
5469
|
+
* (正则里 `不要` 与 `隔离` 之间只允许创建 / 使用一类的动词,其它动词会让整个分支失配。)
|
|
5470
|
+
*/
|
|
5471
|
+
const EXPLICIT_MAIN_WORKSPACE_RE = new RegExp(
|
|
5472
|
+
[
|
|
5473
|
+
// 不建隔离工作树 / 不要建 / 不要使用 / 无需隔离工作树 / 禁止创建 / 勿开
|
|
5474
|
+
'(?:不要|别|不|无需|禁止|勿)(?:要|用|需|必|许)?(?:创建|建立|建|启用|开启|使用|开)?\\s*隔离(?:的)?(?:git\\s*)?工作树',
|
|
5475
|
+
// 直接改主工作区 / 直接修改主仓库
|
|
5476
|
+
'直接\\s*(?:改|修改|操作|执行|跑|提交)\\s*(?:到|在)?\\s*(?:主工作区|主仓库|主仓)',
|
|
5477
|
+
// 在主工作区执行 / 在主工作区里改
|
|
5478
|
+
'在\\s*(?:主工作区|主仓库|主仓)\\s*(?:里|内|中)?\\s*(?:直接)?\\s*(?:执行|修改|操作|跑|改|提交|干活)',
|
|
5479
|
+
// 主工作区里直接改
|
|
5480
|
+
'(?:主工作区|主仓库|主仓)\\s*(?:里|内|中)\\s*直接\\s*(?:执行|修改|操作|跑|改|提交|干活)',
|
|
5481
|
+
].join('|'),
|
|
5482
|
+
'im',
|
|
5483
|
+
)
|
|
5484
|
+
|
|
5223
5485
|
/**
|
|
5224
5486
|
* v0.5.0:判断本次 `subagent` 派发是否必须留在主工作区执行(跳过 Git Worktree 隔离):
|
|
5225
5487
|
* - 任务自身或所属父任务处于 `assignee === 'merging'`(合并与全量验证阶段);
|
|
5226
|
-
* - `description` / `prompt` 明确声明为合并验证、解冲突、只读审查或以 `[主工作区]`
|
|
5488
|
+
* - `description` / `prompt` 明确声明为合并验证、解冲突、只读审查或以 `[主工作区]` 开头;
|
|
5489
|
+
* - v0.5.2:显式主工作区措辞(`不建隔离工作树` / `直接改主工作区` / `在主工作区执行` 等),
|
|
5490
|
+
* 见 `EXPLICIT_MAIN_WORKSPACE_RE`(尊重用户的显式指令,不再一律隔离)。
|
|
5227
5491
|
*/
|
|
5228
5492
|
export function shouldSkipWorktreeForDispatch(state, task, args) {
|
|
5229
5493
|
if (!task || task.status === 'archived') return true
|
|
@@ -5237,6 +5501,8 @@ export function shouldSkipWorktreeForDispatch(state, task, args) {
|
|
|
5237
5501
|
const prompt = subagentPromptText(args)
|
|
5238
5502
|
if (/合并与全量验证|合并验证|冲突合并|解冲突|全量验证|^\[主工作区\]/i.test(desc)) return true
|
|
5239
5503
|
if (/^\[主工作区\]|你是只读审查员/m.test(prompt)) return true
|
|
5504
|
+
// v0.5.2:显式要求主工作区(prompt / description 任一命中即可)。
|
|
5505
|
+
if (EXPLICIT_MAIN_WORKSPACE_RE.test(desc) || EXPLICIT_MAIN_WORKSPACE_RE.test(prompt)) return true
|
|
5240
5506
|
return false
|
|
5241
5507
|
}
|
|
5242
5508
|
|
|
@@ -5477,6 +5743,7 @@ export const TASK_LIST_OUTPUT_SCHEMA = {
|
|
|
5477
5743
|
questionOptions: { type: 'array', items: { type: 'string' } },
|
|
5478
5744
|
worktreePath: { type: 'string' },
|
|
5479
5745
|
worktreeBranch: { type: 'string' },
|
|
5746
|
+
lastError: { type: 'string' },
|
|
5480
5747
|
},
|
|
5481
5748
|
},
|
|
5482
5749
|
},
|
|
@@ -5511,6 +5778,9 @@ export function taskBrief(task) {
|
|
|
5511
5778
|
// v0.5.0:隔离工作树路径与分支,供组长判断是否需调 taskboard_merge_worktree 合入主工作区。
|
|
5512
5779
|
worktreePath: task.worktreePath || '',
|
|
5513
5780
|
worktreeBranch: task.worktreeBranch || '',
|
|
5781
|
+
// v0.5.2:故障原因必须对模型可见——中断(aborted)/ 合入冲突等只写 lastError、状态保持 doing 时,
|
|
5782
|
+
// 组长从 taskboard_list 就能看出「卡片为什么没动」,不再出现「活干完了、状态没变、也没提示」。
|
|
5783
|
+
lastError: task.lastError || '',
|
|
5514
5784
|
}
|
|
5515
5785
|
}
|
|
5516
5786
|
|
|
@@ -5529,6 +5799,8 @@ function renderTaskList(value) {
|
|
|
5529
5799
|
if (task.worktreePath) lines.push(' 隔离工作树:' + task.worktreePath + (task.worktreeBranch ? ' (' + task.worktreeBranch + ')' : ''))
|
|
5530
5800
|
if (task.note) lines.push(' 备注:' + task.note)
|
|
5531
5801
|
if (task.result) lines.push(' 结论:' + task.result)
|
|
5802
|
+
// v0.5.2:异常(aborted / 合入冲突等)必须出现在模型工具输出里,否则外部只看得到「卡在 doing」。
|
|
5803
|
+
if (task.lastError) lines.push(' 最近异常:' + task.lastError)
|
|
5532
5804
|
if (task.needsUser) lines.push(' 待用户回答:' + task.question)
|
|
5533
5805
|
}
|
|
5534
5806
|
return [{ type: 'text', text: lines.join('\n') }]
|
|
@@ -5549,6 +5821,7 @@ function renderTaskOne(prefix, task) {
|
|
|
5549
5821
|
if (task.worktreePath) lines.push('隔离工作树:' + task.worktreePath + (task.worktreeBranch ? ' (' + task.worktreeBranch + ')' : ''))
|
|
5550
5822
|
if (task.note) lines.push('备注:' + task.note)
|
|
5551
5823
|
if (task.result) lines.push('结论:' + task.result)
|
|
5824
|
+
if (task.lastError) lines.push('最近异常:' + task.lastError)
|
|
5552
5825
|
if (task.needsUser) lines.push('待用户回答:' + task.question)
|
|
5553
5826
|
const updatedMs = Date.parse(task.updatedAt)
|
|
5554
5827
|
lines.push(
|
|
@@ -5581,6 +5854,7 @@ export const TASK_ONE_OUTPUT_SCHEMA = {
|
|
|
5581
5854
|
questionOptions: { type: 'array', items: { type: 'string' } },
|
|
5582
5855
|
worktreePath: { type: 'string' },
|
|
5583
5856
|
worktreeBranch: { type: 'string' },
|
|
5857
|
+
lastError: { type: 'string' },
|
|
5584
5858
|
},
|
|
5585
5859
|
},
|
|
5586
5860
|
},
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Task board + dispatcher mode",
|
|
4
|
-
"description": "Task board + workspace-lead dispatch: talk to the main session; leads dispatch workers and the
|
|
4
|
+
"description": "Task board + workspace-lead dispatch: talk to the main session; leads dispatch workers and the status-column board tracks progress and results (the archived column collapses)."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dispatch-board",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "DeepSeek Harness 插件:派单看板 + 工作区组长模式。组长派 worker
|
|
3
|
+
"version": "0.5.9",
|
|
4
|
+
"description": "DeepSeek Harness 插件:派单看板 + 工作区组长模式。组长派 worker 执行,看板按状态列跟踪进度与结论(归档列可折叠)。A dispatch board and workspace-lead mode for DeepSeek Harness.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"icon": "icon.svg",
|
|
@@ -102,6 +102,10 @@
|
|
|
102
102
|
(改了什么、验证结果、注意事项;非必要不画表格、不贴黑话)。插件会自动把完成回执汇总给主会话;
|
|
103
103
|
- 不通过:send_message 把具体修改意见发回同一个 worker 重做,任务保持 doing,
|
|
104
104
|
并把简明打回原因写进 result;确实要换人重做时才把任务置回 todo。
|
|
105
|
+
token 经济(复用优先,v0.5.5 实测):同一张卡的返工、补充要求、同一批文件的后续小步,优先用 `send_message`
|
|
106
|
+
把新要求发回**原来那个 worker**(它已有文件与上下文,省一次重读;本仓库对照实验:同一段代码的追问,复用组
|
|
107
|
+
成本约为新开 worker 的 1/8,整条任务约省 40%);只有独立任务、并行切片、或原 worker 上下文已明显过载时
|
|
108
|
+
才新开 worker。复用时别把无关任务塞进同一个 worker——历史会一直挂在上下文里,越滚越贵。
|
|
105
109
|
|
|
106
110
|
异常处理(不要臆造、不要跨工作区):任务没有工作目录、或不属于本工作区时,不要执行,
|
|
107
111
|
把原因写进 lastError(或回退 todo 并说明),结束本轮;任务需要跨工作区拆分时,
|