dsh-dispatch-board 0.5.1 → 0.5.6
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 +281 -142
- package/lib/index.js +288 -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
|
|
|
@@ -3255,6 +3338,20 @@ function pruneArchivedBoard(rt, now = Date.now()) {
|
|
|
3255
3338
|
return outcome.removed
|
|
3256
3339
|
}
|
|
3257
3340
|
|
|
3341
|
+
/**
|
|
3342
|
+
* v0.5.2:卡住自动卡提醒的去重表(进程内 Set,不落盘)。键 = 任务 id + updatedAt——
|
|
3343
|
+
* 同一次「worker 已结束但卡片还停在 doing」只提醒一次;任务再有新的结束事件(updatedAt 变了)
|
|
3344
|
+
* 会重新提醒,不会因为历史去重而永久失声。
|
|
3345
|
+
*/
|
|
3346
|
+
function stuckAlertedSet(rt) {
|
|
3347
|
+
if (!(rt.stuckAlerted instanceof Set)) rt.stuckAlerted = new Set()
|
|
3348
|
+
return rt.stuckAlerted
|
|
3349
|
+
}
|
|
3350
|
+
|
|
3351
|
+
function stuckAlertKey(task) {
|
|
3352
|
+
return asString(task && task.id) + '@' + asString(task && task.updatedAt)
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3258
3355
|
/**
|
|
3259
3356
|
* v0.4.0:巡检并自愈失联的 `doing` 任务(进程重启掉线 / worker 异常退出未发 `subagent/end`)。
|
|
3260
3357
|
*
|
|
@@ -3263,9 +3360,13 @@ function pruneArchivedBoard(rt, now = Date.now()) {
|
|
|
3263
3360
|
* `lastError` 写明失联重排原因;
|
|
3264
3361
|
* - **内部切片子卡**(`autoDispatch === LEAD_AUTO_MARK` 且 `parentTaskId` 非空):保持 `doing`,标 `workerRunState = 'failed'`
|
|
3265
3362
|
* 并写 `lastError`;若所属组长会话在线且 `idle`,合并发送一条「异常恢复」提醒交组长续做或归档。
|
|
3363
|
+
* - **v0.5.2 卡住提醒**:`doing` + `autoDispatch === LEAD_AUTO_MARK` + `workerRunState` 已经是
|
|
3364
|
+
* `'ended'` / `'failed'`(worker 结束事件处理过、但卡片因非 completed / 合入冲突 / 认领失败停在 doing)
|
|
3365
|
+
* + 超过 `ORPHAN_GRACE_MS` 没再更新 → 组长 `idle` 时发一条**一次性**提醒(卡 id / 卡在哪一步 /
|
|
3366
|
+
* lastError 摘要 / 处理提示)。**绝不自动改状态**(收尾与合入必须由组长判断),用 rt 上的内存 Set 去重。
|
|
3266
3367
|
*/
|
|
3267
3368
|
export async function reconcileOrphanedDoingTasks(rt, options = {}) {
|
|
3268
|
-
const outcome = { requeued: 0, markedFailed: 0, ids: [] }
|
|
3369
|
+
const outcome = { requeued: 0, markedFailed: 0, reminded: 0, ids: [] }
|
|
3269
3370
|
if (!rt || !rt.state || !Array.isArray(rt.state.tasks)) return outcome
|
|
3270
3371
|
const startup = options.startup === true
|
|
3271
3372
|
const now = Number.isFinite(Number(options.now)) ? Number(options.now) : Date.now()
|
|
@@ -3291,6 +3392,8 @@ export async function reconcileOrphanedDoingTasks(rt, options = {}) {
|
|
|
3291
3392
|
|
|
3292
3393
|
const stamp = iso(now)
|
|
3293
3394
|
const leadAlerts = new Map()
|
|
3395
|
+
// v0.5.2:worker 已结束但卡片仍在 doing 的自动卡(只提醒,不改状态)。
|
|
3396
|
+
const stuckAlerts = new Map()
|
|
3294
3397
|
let changed = false
|
|
3295
3398
|
|
|
3296
3399
|
for (const task of rt.state.tasks) {
|
|
@@ -3338,7 +3441,21 @@ export async function reconcileOrphanedDoingTasks(rt, options = {}) {
|
|
|
3338
3441
|
orphaned = true
|
|
3339
3442
|
}
|
|
3340
3443
|
|
|
3341
|
-
if (!orphaned)
|
|
3444
|
+
if (!orphaned) {
|
|
3445
|
+
if (
|
|
3446
|
+
task.autoDispatch === LEAD_AUTO_MARK &&
|
|
3447
|
+
(task.workerRunState === 'ended' || task.workerRunState === 'failed') &&
|
|
3448
|
+
ageMs >= graceMs
|
|
3449
|
+
) {
|
|
3450
|
+
const leadId = asString(task.dispatchedSessionId || task.sessionId).trim()
|
|
3451
|
+
if (leadId !== '') {
|
|
3452
|
+
const list = stuckAlerts.get(leadId) || []
|
|
3453
|
+
list.push(task)
|
|
3454
|
+
stuckAlerts.set(leadId, list)
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
continue
|
|
3458
|
+
}
|
|
3342
3459
|
changed = true
|
|
3343
3460
|
outcome.ids.push(task.id)
|
|
3344
3461
|
|
|
@@ -3407,6 +3524,52 @@ export async function reconcileOrphanedDoingTasks(rt, options = {}) {
|
|
|
3407
3524
|
}
|
|
3408
3525
|
}
|
|
3409
3526
|
|
|
3527
|
+
// v0.5.2:worker 已经结束、卡片却还停在 doing(非 completed / 合入冲突 / 认领失败)时,
|
|
3528
|
+
// 组长 idle 就发一条一次性提醒——绝不自动改状态,只把「卡在哪一步 + 原因 + 怎么收尾」说清楚。
|
|
3529
|
+
if (!startup && stuckAlerts.size > 0 && agents) {
|
|
3530
|
+
const archived = archivedSessionIdSet(rt)
|
|
3531
|
+
const reminded = stuckAlertedSet(rt)
|
|
3532
|
+
for (const [leadId, stuckTasks] of stuckAlerts.entries()) {
|
|
3533
|
+
if (archived.has(leadId)) continue
|
|
3534
|
+
const leadAgent = liveAgentOf(agents, leadId)
|
|
3535
|
+
if (!leadAgent || leadAgent.status !== 'idle') continue
|
|
3536
|
+
const pending = stuckTasks.filter((task) => !reminded.has(stuckAlertKey(task)))
|
|
3537
|
+
if (pending.length === 0) continue
|
|
3538
|
+
const lines = [
|
|
3539
|
+
'【任务看板 · 卡住提醒】以下自动卡的任务已经结束,但看板还停在「进行中」(宿主不会自动改状态):',
|
|
3540
|
+
]
|
|
3541
|
+
for (const item of pending) {
|
|
3542
|
+
const step =
|
|
3543
|
+
(asString(item.parentTaskId) === '' ? '顶层任务' : '切片 · 父任务 ' + item.parentTaskId) +
|
|
3544
|
+
' · worker 已结束(' +
|
|
3545
|
+
asString(item.workerRunState) +
|
|
3546
|
+
')'
|
|
3547
|
+
const reason = trimmed(item.lastError, 200)
|
|
3548
|
+
lines.push('- ' + item.id + '(' + step + ')' + item.title + (reason === '' ? '' : ' · ' + reason))
|
|
3549
|
+
if (asString(item.worktreePath) !== '') {
|
|
3550
|
+
lines.push(' 隔离工作树还没合入:' + item.worktreePath + '(先 taskboard_merge_worktree 处理冲突 / 合入)')
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
lines.push(
|
|
3554
|
+
'请核对后收尾:直接 taskboard_update {id, status:"done", result:"…"};若挂有隔离工作树,先 taskboard_merge_worktree 合入(或传 discardOnly:true 回收)。宿主不会自动改状态。',
|
|
3555
|
+
)
|
|
3556
|
+
try {
|
|
3557
|
+
leadAgent.followup(createBoardUserMessage(lines.join('\n')))
|
|
3558
|
+
const sessions = serviceOf(rt.ctx, 'sessions')
|
|
3559
|
+
if (sessions && typeof sessions.flush === 'function') await sessions.flush(leadAgent.session)
|
|
3560
|
+
for (const item of pending) {
|
|
3561
|
+
reminded.add(stuckAlertKey(item))
|
|
3562
|
+
outcome.reminded += 1
|
|
3563
|
+
}
|
|
3564
|
+
console.warn(
|
|
3565
|
+
'[taskboard] 已提醒组长处理卡住的自动卡:' + pending.map((item) => item.id).join('、'),
|
|
3566
|
+
)
|
|
3567
|
+
} catch (error) {
|
|
3568
|
+
console.warn('[taskboard] 发送卡住自动卡提醒失败:' + describeError(error))
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3410
3573
|
return outcome
|
|
3411
3574
|
}
|
|
3412
3575
|
|
|
@@ -5019,18 +5182,27 @@ export async function handleSubagentEnd(rt, info, now = Date.now()) {
|
|
|
5019
5182
|
task = findTaskByWorker(rt.state, childId)
|
|
5020
5183
|
}
|
|
5021
5184
|
if (!task) {
|
|
5185
|
+
// v0.5.2:放宽兜底候选——workerSessionId 还没回填时,卡片可能已进入 ended / failed / null
|
|
5186
|
+
// (上一次 aborted 收尾、或宿主重启归一化),不能再要求 workerRunState === 'running',
|
|
5187
|
+
// 否则结束事件永远认领不到卡、卡片停在 doing 又没有任何外部提示。
|
|
5188
|
+
// 只按「该组长名下 + doing 自动卡 + workerSessionId 为空或正是本次 childId」筛,
|
|
5189
|
+
// 再用 info.name / assignee 精确匹配;多候选无法区分时不猜。
|
|
5022
5190
|
const candidates = rt.state.tasks.filter(
|
|
5023
5191
|
(candidate) =>
|
|
5024
5192
|
candidate &&
|
|
5025
5193
|
candidate.autoDispatch === LEAD_AUTO_MARK &&
|
|
5026
5194
|
candidate.status === 'doing' &&
|
|
5027
|
-
asString(candidate.workerRunState) === 'running' &&
|
|
5028
5195
|
asString(candidate.sessionId) === parentId &&
|
|
5029
|
-
asString(candidate.workerSessionId) === ''
|
|
5196
|
+
(asString(candidate.workerSessionId) === '' ||
|
|
5197
|
+
asString(candidate.workerSessionId) === childId),
|
|
5030
5198
|
)
|
|
5031
5199
|
if (workerName !== '') {
|
|
5032
5200
|
const byName = candidates.filter((candidate) => asString(candidate.assignee) === workerName)
|
|
5033
5201
|
if (byName.length === 1) task = byName[0]
|
|
5202
|
+
// 名字对不上、但只剩一条且 assignee 还没写(tools/result 没走到 / 回填失败):不算猜测。
|
|
5203
|
+
if (!task && byName.length === 0 && candidates.length === 1 && asString(candidates[0].assignee) === '') {
|
|
5204
|
+
task = candidates[0]
|
|
5205
|
+
}
|
|
5034
5206
|
}
|
|
5035
5207
|
if (!task && workerName === '' && candidates.length === 1) {
|
|
5036
5208
|
task = candidates[0]
|
|
@@ -5041,6 +5213,35 @@ export async function handleSubagentEnd(rt, info, now = Date.now()) {
|
|
|
5041
5213
|
const rawStopReason = asString(info && info.stopReason).trim()
|
|
5042
5214
|
const stopReason = rawStopReason === '' ? 'unknown' : rawStopReason
|
|
5043
5215
|
if (!task) {
|
|
5216
|
+
// v0.5.2:认领不到卡片时不再静默——该组长名下若确实还有 doing 的自动卡,说明收尾逻辑漏了,
|
|
5217
|
+
// 必须留下可查的告警(含 childId / name / parentId / stopReason),交给组长人工核对。
|
|
5218
|
+
if (parentId !== '') {
|
|
5219
|
+
const lingering = rt.state.tasks.filter(
|
|
5220
|
+
(candidate) =>
|
|
5221
|
+
candidate &&
|
|
5222
|
+
candidate.autoDispatch === LEAD_AUTO_MARK &&
|
|
5223
|
+
candidate.status === 'doing' &&
|
|
5224
|
+
(asString(candidate.sessionId) === parentId ||
|
|
5225
|
+
asString(candidate.dispatchedSessionId) === parentId),
|
|
5226
|
+
)
|
|
5227
|
+
if (lingering.length > 0) {
|
|
5228
|
+
recordLeadAutoError(
|
|
5229
|
+
rt,
|
|
5230
|
+
'worker 结束但没有匹配到看板自动卡:childId=' +
|
|
5231
|
+
childId +
|
|
5232
|
+
',name=' +
|
|
5233
|
+
(workerName === '' ? '(未知)' : workerName) +
|
|
5234
|
+
',parentId=' +
|
|
5235
|
+
parentId +
|
|
5236
|
+
',stopReason=' +
|
|
5237
|
+
stopReason +
|
|
5238
|
+
';该组长名下仍有 doing 的自动卡 ' +
|
|
5239
|
+
lingering.map((candidate) => candidate.id).join('、') +
|
|
5240
|
+
',需要人工核对',
|
|
5241
|
+
now,
|
|
5242
|
+
)
|
|
5243
|
+
}
|
|
5244
|
+
}
|
|
5044
5245
|
// 不是宿主建的自动任务(例如组长审核时派去跑命令的验证子 Agent,
|
|
5045
5246
|
// 或轮询投递任务的 worker——那条任务的 autoDispatch 为 null):仅收敛其 workerRunState。
|
|
5046
5247
|
settleNonAutoWorkerRunState(rt, childId, parentId, workerName, stopReason, now)
|
|
@@ -5220,10 +5421,34 @@ export function registerLeadAutoHooks(ctx, rt) {
|
|
|
5220
5421
|
return true
|
|
5221
5422
|
}
|
|
5222
5423
|
|
|
5424
|
+
/**
|
|
5425
|
+
* v0.5.2:`description` / `prompt` 里「用户明确要求留在主工作区」的措辞。
|
|
5426
|
+
*
|
|
5427
|
+
* 否定对象必须正好是「(建 / 用)隔离工作树」本身:像「不要删除隔离工作树里的文件」
|
|
5428
|
+
* 「不要在隔离工作树里装依赖」这类句子,否定的是「删除 / 装依赖」而不是「隔离」,
|
|
5429
|
+
* 绝不能命中——否则会把本该隔离执行的活错误地拉回主工作区并发踩踏。
|
|
5430
|
+
* (正则里 `不要` 与 `隔离` 之间只允许创建 / 使用一类的动词,其它动词会让整个分支失配。)
|
|
5431
|
+
*/
|
|
5432
|
+
const EXPLICIT_MAIN_WORKSPACE_RE = new RegExp(
|
|
5433
|
+
[
|
|
5434
|
+
// 不建隔离工作树 / 不要建 / 不要使用 / 无需隔离工作树 / 禁止创建 / 勿开
|
|
5435
|
+
'(?:不要|别|不|无需|禁止|勿)(?:要|用|需|必|许)?(?:创建|建立|建|启用|开启|使用|开)?\\s*隔离(?:的)?(?:git\\s*)?工作树',
|
|
5436
|
+
// 直接改主工作区 / 直接修改主仓库
|
|
5437
|
+
'直接\\s*(?:改|修改|操作|执行|跑|提交)\\s*(?:到|在)?\\s*(?:主工作区|主仓库|主仓)',
|
|
5438
|
+
// 在主工作区执行 / 在主工作区里改
|
|
5439
|
+
'在\\s*(?:主工作区|主仓库|主仓)\\s*(?:里|内|中)?\\s*(?:直接)?\\s*(?:执行|修改|操作|跑|改|提交|干活)',
|
|
5440
|
+
// 主工作区里直接改
|
|
5441
|
+
'(?:主工作区|主仓库|主仓)\\s*(?:里|内|中)\\s*直接\\s*(?:执行|修改|操作|跑|改|提交|干活)',
|
|
5442
|
+
].join('|'),
|
|
5443
|
+
'im',
|
|
5444
|
+
)
|
|
5445
|
+
|
|
5223
5446
|
/**
|
|
5224
5447
|
* v0.5.0:判断本次 `subagent` 派发是否必须留在主工作区执行(跳过 Git Worktree 隔离):
|
|
5225
5448
|
* - 任务自身或所属父任务处于 `assignee === 'merging'`(合并与全量验证阶段);
|
|
5226
|
-
* - `description` / `prompt` 明确声明为合并验证、解冲突、只读审查或以 `[主工作区]`
|
|
5449
|
+
* - `description` / `prompt` 明确声明为合并验证、解冲突、只读审查或以 `[主工作区]` 开头;
|
|
5450
|
+
* - v0.5.2:显式主工作区措辞(`不建隔离工作树` / `直接改主工作区` / `在主工作区执行` 等),
|
|
5451
|
+
* 见 `EXPLICIT_MAIN_WORKSPACE_RE`(尊重用户的显式指令,不再一律隔离)。
|
|
5227
5452
|
*/
|
|
5228
5453
|
export function shouldSkipWorktreeForDispatch(state, task, args) {
|
|
5229
5454
|
if (!task || task.status === 'archived') return true
|
|
@@ -5237,6 +5462,8 @@ export function shouldSkipWorktreeForDispatch(state, task, args) {
|
|
|
5237
5462
|
const prompt = subagentPromptText(args)
|
|
5238
5463
|
if (/合并与全量验证|合并验证|冲突合并|解冲突|全量验证|^\[主工作区\]/i.test(desc)) return true
|
|
5239
5464
|
if (/^\[主工作区\]|你是只读审查员/m.test(prompt)) return true
|
|
5465
|
+
// v0.5.2:显式要求主工作区(prompt / description 任一命中即可)。
|
|
5466
|
+
if (EXPLICIT_MAIN_WORKSPACE_RE.test(desc) || EXPLICIT_MAIN_WORKSPACE_RE.test(prompt)) return true
|
|
5240
5467
|
return false
|
|
5241
5468
|
}
|
|
5242
5469
|
|
|
@@ -5477,6 +5704,7 @@ export const TASK_LIST_OUTPUT_SCHEMA = {
|
|
|
5477
5704
|
questionOptions: { type: 'array', items: { type: 'string' } },
|
|
5478
5705
|
worktreePath: { type: 'string' },
|
|
5479
5706
|
worktreeBranch: { type: 'string' },
|
|
5707
|
+
lastError: { type: 'string' },
|
|
5480
5708
|
},
|
|
5481
5709
|
},
|
|
5482
5710
|
},
|
|
@@ -5511,6 +5739,9 @@ export function taskBrief(task) {
|
|
|
5511
5739
|
// v0.5.0:隔离工作树路径与分支,供组长判断是否需调 taskboard_merge_worktree 合入主工作区。
|
|
5512
5740
|
worktreePath: task.worktreePath || '',
|
|
5513
5741
|
worktreeBranch: task.worktreeBranch || '',
|
|
5742
|
+
// v0.5.2:故障原因必须对模型可见——中断(aborted)/ 合入冲突等只写 lastError、状态保持 doing 时,
|
|
5743
|
+
// 组长从 taskboard_list 就能看出「卡片为什么没动」,不再出现「活干完了、状态没变、也没提示」。
|
|
5744
|
+
lastError: task.lastError || '',
|
|
5514
5745
|
}
|
|
5515
5746
|
}
|
|
5516
5747
|
|
|
@@ -5529,6 +5760,8 @@ function renderTaskList(value) {
|
|
|
5529
5760
|
if (task.worktreePath) lines.push(' 隔离工作树:' + task.worktreePath + (task.worktreeBranch ? ' (' + task.worktreeBranch + ')' : ''))
|
|
5530
5761
|
if (task.note) lines.push(' 备注:' + task.note)
|
|
5531
5762
|
if (task.result) lines.push(' 结论:' + task.result)
|
|
5763
|
+
// v0.5.2:异常(aborted / 合入冲突等)必须出现在模型工具输出里,否则外部只看得到「卡在 doing」。
|
|
5764
|
+
if (task.lastError) lines.push(' 最近异常:' + task.lastError)
|
|
5532
5765
|
if (task.needsUser) lines.push(' 待用户回答:' + task.question)
|
|
5533
5766
|
}
|
|
5534
5767
|
return [{ type: 'text', text: lines.join('\n') }]
|
|
@@ -5549,6 +5782,7 @@ function renderTaskOne(prefix, task) {
|
|
|
5549
5782
|
if (task.worktreePath) lines.push('隔离工作树:' + task.worktreePath + (task.worktreeBranch ? ' (' + task.worktreeBranch + ')' : ''))
|
|
5550
5783
|
if (task.note) lines.push('备注:' + task.note)
|
|
5551
5784
|
if (task.result) lines.push('结论:' + task.result)
|
|
5785
|
+
if (task.lastError) lines.push('最近异常:' + task.lastError)
|
|
5552
5786
|
if (task.needsUser) lines.push('待用户回答:' + task.question)
|
|
5553
5787
|
const updatedMs = Date.parse(task.updatedAt)
|
|
5554
5788
|
lines.push(
|
|
@@ -5581,6 +5815,7 @@ export const TASK_ONE_OUTPUT_SCHEMA = {
|
|
|
5581
5815
|
questionOptions: { type: 'array', items: { type: 'string' } },
|
|
5582
5816
|
worktreePath: { type: 'string' },
|
|
5583
5817
|
worktreeBranch: { type: 'string' },
|
|
5818
|
+
lastError: { type: 'string' },
|
|
5584
5819
|
},
|
|
5585
5820
|
},
|
|
5586
5821
|
},
|
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.6",
|
|
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 并说明),结束本轮;任务需要跨工作区拆分时,
|