dsh-progress-union 0.1.2 → 0.1.3
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/dsh.plugin.json +1 -1
- package/index.js +201 -2
- package/package.json +1 -1
package/dsh.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-external/dsh-progress-union",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"description": "进度结合原型:board 槽位真相源(用户可编辑、diff+ack 增量同步、staleness nudge)× 鲸程时间引擎(step 计数、ETA 三档 board>todo>local>prior、悬浮迷你条),并向压缩插件暴露只读三层进度锚点 progressAnchor(board 语义锚 + time 时间锚 + userEdits 未确认改动,service 与 HTTP 双平面)。",
|
|
6
6
|
"engines": {
|
package/index.js
CHANGED
|
@@ -1071,6 +1071,134 @@ export async function apply(ctx, config) {
|
|
|
1071
1071
|
return parts.join('\n')
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
1074
|
+
// —— 续轮驱动器(重试):idle → followup 带自有 source 的 <progress_goal_round> ——
|
|
1075
|
+
// 每 agent 一个 attempt 状态:queued/claimed/cancelled + 串行 FIFO;官方 driver 的轻量版。
|
|
1076
|
+
const goalDrives = new WeakMap() // agent -> {attempt, requested, run, stopping}
|
|
1077
|
+
|
|
1078
|
+
function driveStateFor(agent) {
|
|
1079
|
+
let s = goalDrives.get(agent)
|
|
1080
|
+
if (!s) {
|
|
1081
|
+
s = { attempt: undefined, requested: false, run: undefined, stopping: false }
|
|
1082
|
+
goalDrives.set(agent, s)
|
|
1083
|
+
}
|
|
1084
|
+
return s
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
function sameGoalSource(message, attempt) {
|
|
1088
|
+
if (!attempt || !message || !message.source) return false
|
|
1089
|
+
const src = message.source
|
|
1090
|
+
return src.kind === GOAL_SOURCE_KIND && src.goalId === attempt.goalId && src.revision === attempt.revision && src.round === attempt.round
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
function isGoalRoundMessage(message) {
|
|
1094
|
+
return Boolean(message && message.source && message.source.kind === GOAL_SOURCE_KIND && message.source.round > 0)
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// 构造 followup 消息的 content,把板清单与助手轮次草案(若有)拼进去。
|
|
1098
|
+
function renderGoalRoundContent(sessionId, round, view) {
|
|
1099
|
+
const state = states.get(sessionId)
|
|
1100
|
+
const checklist = state ? renderChecklist(state, cfg.observer.maxItems).join('\n') : '(空板)'
|
|
1101
|
+
const parts = [
|
|
1102
|
+
`${GOAL_TAG}`,
|
|
1103
|
+
`Objective: ${JSON.stringify(view.objective)}`,
|
|
1104
|
+
`Round: ${round}/${view.maxRounds}`,
|
|
1105
|
+
'',
|
|
1106
|
+
'<progress-board-snapshot>',
|
|
1107
|
+
checklist,
|
|
1108
|
+
'</progress-board-snapshot>',
|
|
1109
|
+
]
|
|
1110
|
+
if (oRoundDraftOf(sessionId)) parts.push('', `助手建议:${oRoundDraftOf(sessionId)}`)
|
|
1111
|
+
parts.push(
|
|
1112
|
+
'',
|
|
1113
|
+
'继续在**同一会话**朝目标推进:以当前工作区、工具结果与持久化状态为准,先核对进度板再行动;做出实质进展并验证。',
|
|
1114
|
+
'若要收尾,先确保进度板全部完成,再调用 progress_goal_report 报 status=complete 并给出 evidence。若受阻,报 status=blocked 并写清 blocker。否则报 status=continue,本目标会自动进入下一轮。',
|
|
1115
|
+
'每轮至少用 progress_update 同步一次进度板(无变化传 changes=[])。',
|
|
1116
|
+
`${GOAL_TAG}`,
|
|
1117
|
+
)
|
|
1118
|
+
return [{ type: 'text', text: parts.join('\n') }]
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// 助手轮次草案:存在 observers 上,由 Phase3 的辅助 LLM 写入;这里只读。
|
|
1122
|
+
function oRoundDraftOf(sid) {
|
|
1123
|
+
const o = observers.get(sid)
|
|
1124
|
+
return o && typeof o.roundDraft === 'string' && o.roundDraft ? o.roundDraft.slice(0, 400) : ''
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
async function driveGoal(state) {
|
|
1128
|
+
const { agent } = state
|
|
1129
|
+
const sessionId = String(agent.session?.id ?? agent.id)
|
|
1130
|
+
const current = ensureState(sessionId)
|
|
1131
|
+
const g = current.goal
|
|
1132
|
+
// 让路:官方目标 active 时不排队
|
|
1133
|
+
try {
|
|
1134
|
+
const official = ctx.get('goals')?.get?.(agent)
|
|
1135
|
+
if (official && official.phase === 'active' && official.activation === 'armed') return
|
|
1136
|
+
} catch (_err) {}
|
|
1137
|
+
if (g.phase !== 'active' || g.activation !== 'armed') return
|
|
1138
|
+
if (g.roundsStarted >= g.maxRounds) {
|
|
1139
|
+
g.phase = 'blocked'
|
|
1140
|
+
g.activation = 'disarmed'
|
|
1141
|
+
g.blockedReason = `达到预算上限 ${g.maxRounds} 轮`
|
|
1142
|
+
g.blockedStreak = 1
|
|
1143
|
+
g.currentRound = 0
|
|
1144
|
+
await saveGoal(sessionId)
|
|
1145
|
+
return
|
|
1146
|
+
}
|
|
1147
|
+
const round = g.roundsStarted + 1
|
|
1148
|
+
const revision = current.revision
|
|
1149
|
+
const content = renderGoalRoundContent(sessionId, round, goalView(sessionId))
|
|
1150
|
+
const message = {
|
|
1151
|
+
id: `pg-${now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
|
|
1152
|
+
role: 'user',
|
|
1153
|
+
content,
|
|
1154
|
+
source: { kind: GOAL_SOURCE_KIND, goalId: g.id, revision, round },
|
|
1155
|
+
}
|
|
1156
|
+
// 声称本轮:写 currentRound + roundsStarted,避免重复派发
|
|
1157
|
+
g.currentRound = round
|
|
1158
|
+
g.roundsStarted = round
|
|
1159
|
+
await saveGoal(sessionId)
|
|
1160
|
+
state.attempt = { goalId: g.id, revision, round, messageId: message.id, phase: 'queued', stale: false }
|
|
1161
|
+
try {
|
|
1162
|
+
if (typeof agent.followup !== 'function') throw new Error('agent.followup unavailable')
|
|
1163
|
+
agent.followup(message)
|
|
1164
|
+
} catch (err) {
|
|
1165
|
+
state.attempt = undefined
|
|
1166
|
+
g.phase = 'blocked'
|
|
1167
|
+
g.activation = 'disarmed'
|
|
1168
|
+
g.blockedReason = `续轮派发失败:${err instanceof Error ? err.message : String(err)}`
|
|
1169
|
+
await saveGoal(sessionId)
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
function requestGoalDrive(agent) {
|
|
1174
|
+
const state = driveStateFor(agent)
|
|
1175
|
+
if (state.stopping) return
|
|
1176
|
+
state.requested = true
|
|
1177
|
+
if (state.run !== undefined) return
|
|
1178
|
+
let run
|
|
1179
|
+
try {
|
|
1180
|
+
run = (async () => {
|
|
1181
|
+
while (state.requested && !state.stopping) {
|
|
1182
|
+
state.requested = false
|
|
1183
|
+
try {
|
|
1184
|
+
await driveGoal(state)
|
|
1185
|
+
} catch (_err) {
|
|
1186
|
+
// 单轮失败静默,不阻断后续
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
})()
|
|
1190
|
+
} catch (_err) {
|
|
1191
|
+
state.run = undefined
|
|
1192
|
+
return
|
|
1193
|
+
}
|
|
1194
|
+
state.run = run
|
|
1195
|
+
const retire = () => {
|
|
1196
|
+
state.run = undefined
|
|
1197
|
+
if (state.requested && !state.stopping) requestGoalDrive(agent)
|
|
1198
|
+
}
|
|
1199
|
+
run.then(retire, retire)
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1074
1202
|
// ==========================================================================
|
|
1075
1203
|
// B. 注入面(board 三块照板 + 鲸程文件上报协议收敛)
|
|
1076
1204
|
// ==========================================================================
|
|
@@ -1400,14 +1528,38 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
1400
1528
|
hookedAgents.add(agent)
|
|
1401
1529
|
try {
|
|
1402
1530
|
agent.ctx.on('agent/pre-step', async (payload, next) => {
|
|
1531
|
+
const sid = String(agent.session?.id ?? agent.id)
|
|
1532
|
+
const stepMessages = ((payload && payload.messages) || [])
|
|
1533
|
+
|
|
1534
|
+
// /progress-goal 身份栅栏:目标续轮消息必须精确匹配 attempt,否则拒绝本步。
|
|
1535
|
+
const goalRound = stepMessages.find((m) => isGoalRoundMessage(m))
|
|
1536
|
+
if (goalRound) {
|
|
1537
|
+
const ds = driveStateFor(agent)
|
|
1538
|
+
const attempt = ds.attempt
|
|
1539
|
+
const src = goalRound.source
|
|
1540
|
+
const current = states.get(sid)
|
|
1541
|
+
const g = current && current.goal
|
|
1542
|
+
const valid = Boolean(
|
|
1543
|
+
attempt && sameGoalSource(goalRound, attempt) && !attempt.stale &&
|
|
1544
|
+
g && g.id === src.goalId && g.phase === 'active' && g.activation === 'armed' &&
|
|
1545
|
+
src.round === g.roundsStarted && src.round === attempt.round
|
|
1546
|
+
)
|
|
1547
|
+
if (!valid) {
|
|
1548
|
+
if (attempt && attempt.goalId === src.goalId) { attempt.stale = true; ds.attempt = undefined }
|
|
1549
|
+
return { kind: 'reject' }
|
|
1550
|
+
}
|
|
1551
|
+
attempt.phase = 'claimed'
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1403
1554
|
const decision = await next()
|
|
1404
1555
|
try {
|
|
1405
1556
|
if (!cfg.protocolHint) return decision
|
|
1557
|
+
// /progress-goal 续轮消息绝不注入协议消息:避免重蹈 /goal 身份污染覆辙。
|
|
1558
|
+
if (stepMessages.some((m) => isGoalRoundMessage(m))) return decision
|
|
1406
1559
|
// 单协议收敛:本会话板已启用 → 不再注入文件上报协议。
|
|
1407
|
-
const sid = String(agent.session?.id ?? agent.id)
|
|
1408
1560
|
if (isEnabled(sid)) return decision
|
|
1409
1561
|
if (!decision || decision.kind !== 'enter' || !Array.isArray(decision.messages)) return decision
|
|
1410
|
-
const freshUser =
|
|
1562
|
+
const freshUser = stepMessages.find((m) => m && m.source && m.source.kind === 'user')
|
|
1411
1563
|
if (!freshUser) return decision
|
|
1412
1564
|
decision.messages.push({
|
|
1413
1565
|
id: 'dpg-' + now().toString(36) + '-' + Math.random().toString(36).slice(2, 8),
|
|
@@ -1724,6 +1876,49 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
1724
1876
|
} catch (_err) {}
|
|
1725
1877
|
for (const agent of agents?.list?.() ?? []) installAgentHook(agent)
|
|
1726
1878
|
|
|
1879
|
+
// /progress-goal:任何非本域的新消息进入 inbox 视为用户抢占 → 标记 attempt stale 并暂停目标。
|
|
1880
|
+
try {
|
|
1881
|
+
disposers.push(ctx.on('agent/inbox/inserted', ({ agent, message }) => {
|
|
1882
|
+
if (!agent) return
|
|
1883
|
+
const ds = driveStateFor(agent)
|
|
1884
|
+
const attempt = ds.attempt
|
|
1885
|
+
if (!attempt) return
|
|
1886
|
+
if (sameGoalSource(message, attempt)) return // 自己派发的轮次不算竞争
|
|
1887
|
+
const src = message && message.source
|
|
1888
|
+
if (src && src.kind === GOAL_SOURCE_KIND) return
|
|
1889
|
+
// 用户/他人的新消息 → 抢占:暂停目标,清 attempt(等用户下一次明确 resume 或继续)
|
|
1890
|
+
attempt.stale = true
|
|
1891
|
+
ds.attempt = undefined
|
|
1892
|
+
try {
|
|
1893
|
+
const sid = String(agent.session?.id ?? agent.id)
|
|
1894
|
+
const g = ensureState(sid).goal
|
|
1895
|
+
if (g.phase === 'active') {
|
|
1896
|
+
g.phase = 'paused'
|
|
1897
|
+
g.activation = 'disarmed'
|
|
1898
|
+
g.currentRound = 0
|
|
1899
|
+
void saveGoal(sid)
|
|
1900
|
+
}
|
|
1901
|
+
} catch (_err) {}
|
|
1902
|
+
}))
|
|
1903
|
+
disposers.push(ctx.on('agent/inbox/claimed', ({ agent, message }) => {
|
|
1904
|
+
if (!agent) return
|
|
1905
|
+
const attempt = driveStateFor(agent).attempt
|
|
1906
|
+
if (attempt && sameGoalSource(message, attempt)) attempt.phase = 'claimed'
|
|
1907
|
+
}))
|
|
1908
|
+
disposers.push(ctx.on('agent/inbox/discarded', ({ agent, message }) => {
|
|
1909
|
+
if (!agent) return
|
|
1910
|
+
const attempt = driveStateFor(agent).attempt
|
|
1911
|
+
if (attempt && sameGoalSource(message, attempt)) {
|
|
1912
|
+
attempt.stale = true
|
|
1913
|
+
driveStateFor(agent).attempt = undefined
|
|
1914
|
+
}
|
|
1915
|
+
}))
|
|
1916
|
+
disposers.push(ctx.on('agent/disposed', ({ agent }) => {
|
|
1917
|
+
const ds = goalDrives.get(agent)
|
|
1918
|
+
if (ds) ds.stopping = true
|
|
1919
|
+
}))
|
|
1920
|
+
} catch (_err) {}
|
|
1921
|
+
|
|
1727
1922
|
disposers.push(ctx.on('session/event', (session, event) => {
|
|
1728
1923
|
try {
|
|
1729
1924
|
if (!event) return
|
|
@@ -1873,6 +2068,10 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
1873
2068
|
const task = taskMap.get(String(agent.id))
|
|
1874
2069
|
if (task && task.active) task.lastActivityAt = now()
|
|
1875
2070
|
}
|
|
2071
|
+
// /progress-goal 续轮:agent 空载时自动派发下一轮(用户主动消息会抢占 attempt 而停)。
|
|
2072
|
+
if (agent && st === 'idle') {
|
|
2073
|
+
requestGoalDrive(agent)
|
|
2074
|
+
}
|
|
1876
2075
|
// idle 不直接结束任务:maintenance 阶段也报 idle,会误杀进行中任务;结束统一走 sweep。
|
|
1877
2076
|
}))
|
|
1878
2077
|
} catch (_err) {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-progress-union",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎,另向压缩插件暴露只读三层进度锚点(service + HTTP 双平面)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
|
|
6
6
|
"license": "MIT",
|