dsh-progress-union 0.1.1 → 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 +411 -12
- 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
|
@@ -58,6 +58,13 @@ const STALE_MS = 10 * 60 * 1000
|
|
|
58
58
|
const KICKOFF_COOLDOWN_MS = 60 * 1000
|
|
59
59
|
const STATUSES = new Set(['todo', 'doing', 'done', 'blocked'])
|
|
60
60
|
|
|
61
|
+
// —— /progress-goal 迷你目标域常量(自建,不复用官方 goals 域)——
|
|
62
|
+
const GOAL_PHASES = new Set(['idle', 'active', 'paused', 'blocked', 'complete'])
|
|
63
|
+
const GOAL_SOURCE_KIND = 'plugin:progress-goal-goal' // producer-owned source kind(身份栅栏用)
|
|
64
|
+
const GOAL_DEFAULT_MAX_ROUNDS = 256
|
|
65
|
+
const GOAL_BLOCK_STREAK = 3 // blocked 连续 N 轮同一条件才落 phase(对齐 tool-goal 默认)
|
|
66
|
+
const GOAL_TAG = '<progress_goal_round>'
|
|
67
|
+
|
|
61
68
|
// —— widget 侧时间与统计(DSH_HOME 与鲸程共文件,样本不迁移)——
|
|
62
69
|
const DSH_HOME = process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
|
|
63
70
|
const PROGRESS_FILE = path.join(DSH_HOME, 'dsh-progress.json')
|
|
@@ -132,6 +139,25 @@ function emptyState(sessionId) {
|
|
|
132
139
|
updatedAt: now,
|
|
133
140
|
items: [],
|
|
134
141
|
userChanges: [],
|
|
142
|
+
goal: emptyGoal(),
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function newGoalId() {
|
|
147
|
+
return `goal_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function emptyGoal() {
|
|
151
|
+
return {
|
|
152
|
+
id: newGoalId(),
|
|
153
|
+
objective: '',
|
|
154
|
+
phase: 'idle',
|
|
155
|
+
maxRounds: GOAL_DEFAULT_MAX_ROUNDS,
|
|
156
|
+
roundsStarted: 0,
|
|
157
|
+
blockedStreak: 0,
|
|
158
|
+
blockedReason: null,
|
|
159
|
+
activation: 'disarmed',
|
|
160
|
+
currentRound: 0, // 正在派发的轮次(attempt),0 表示无
|
|
135
161
|
}
|
|
136
162
|
}
|
|
137
163
|
|
|
@@ -605,6 +631,18 @@ export async function apply(ctx, config) {
|
|
|
605
631
|
if (typeof item.approach !== 'string') item.approach = ''
|
|
606
632
|
}
|
|
607
633
|
if (typeof state.enabled !== 'boolean') state.enabled = false
|
|
634
|
+
if (!isObject(state.goal)) state.goal = emptyGoal()
|
|
635
|
+
else {
|
|
636
|
+
const g = state.goal
|
|
637
|
+
if (!GOAL_PHASES.has(g.phase)) g.phase = 'idle'
|
|
638
|
+
if (!Number.isSafeInteger(g.maxRounds) || g.maxRounds < 1) g.maxRounds = GOAL_DEFAULT_MAX_ROUNDS
|
|
639
|
+
if (!Number.isSafeInteger(g.roundsStarted) || g.roundsStarted < 0) g.roundsStarted = 0
|
|
640
|
+
if (!Number.isSafeInteger(g.blockedStreak) || g.blockedStreak < 0) g.blockedStreak = 0
|
|
641
|
+
if (g.activation !== 'armed' && g.activation !== 'disarmed') g.activation = 'disarmed'
|
|
642
|
+
if (!Number.isSafeInteger(g.currentRound) || g.currentRound < 0) g.currentRound = 0
|
|
643
|
+
if (typeof g.objective !== 'string') g.objective = ''
|
|
644
|
+
if (typeof g.id !== 'string' || !g.id) g.id = newGoalId()
|
|
645
|
+
}
|
|
608
646
|
return state
|
|
609
647
|
}
|
|
610
648
|
|
|
@@ -637,16 +675,8 @@ export async function apply(ctx, config) {
|
|
|
637
675
|
storageError: storageError || null,
|
|
638
676
|
items,
|
|
639
677
|
summary: summarize(items),
|
|
640
|
-
//
|
|
641
|
-
|
|
642
|
-
enabled: assistantReady(),
|
|
643
|
-
mode: cfg.assistant.mode || '',
|
|
644
|
-
baseUrl: String(cfg.assistant.baseUrl || ''),
|
|
645
|
-
model: String(cfg.assistant.model || ''),
|
|
646
|
-
hasApiKey: String(cfg.assistant.apiKey || '') !== '',
|
|
647
|
-
minIntervalMs: Number(cfg.assistant.minIntervalMs) || 0,
|
|
648
|
-
autoApply: cfg.assistant.autoApply !== false,
|
|
649
|
-
},
|
|
678
|
+
// /progress-goal 迷你目标域回声
|
|
679
|
+
goal: state.goal ? goalView(state.sessionId) : null,
|
|
650
680
|
// 辅助 LLM 的配置回声:只回非机密字段,apiKey 只回布尔
|
|
651
681
|
assistant: (() => {
|
|
652
682
|
const a = liveAssistant()
|
|
@@ -871,6 +901,304 @@ export async function apply(ctx, config) {
|
|
|
871
901
|
return { snapshot: publicSnapshot(working), changed: changed.filter(Boolean) }
|
|
872
902
|
}
|
|
873
903
|
|
|
904
|
+
// ==========================================================================
|
|
905
|
+
// A2. /progress-goal 迷你目标域(预算 / 检查 / 重试 三件套)
|
|
906
|
+
// 自建、不走官方 goals 域:避免 /goal 的 pre-step 身份校验被本插件注入污染。
|
|
907
|
+
// ==========================================================================
|
|
908
|
+
|
|
909
|
+
function goalView(sessionId) {
|
|
910
|
+
const state = ensureState(sessionId)
|
|
911
|
+
const g = state.goal
|
|
912
|
+
const summary = summarize(state.items.slice().sort((a, b) => a.order - b.order).map(itemView))
|
|
913
|
+
return {
|
|
914
|
+
objective: g.objective,
|
|
915
|
+
phase: g.phase,
|
|
916
|
+
maxRounds: g.maxRounds,
|
|
917
|
+
roundsStarted: g.roundsStarted,
|
|
918
|
+
blockedStreak: g.blockedStreak,
|
|
919
|
+
blockedReason: g.blockedReason,
|
|
920
|
+
activation: g.activation,
|
|
921
|
+
currentRound: g.currentRound,
|
|
922
|
+
board: summary,
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
function goalPhaseLabel(phase) {
|
|
927
|
+
return GOAL_PHASES.has(phase) ? phase : 'idle'
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// 板是否全部完成(>0 项且全 done)——"检查"的真相源,避免猜消息身份。
|
|
931
|
+
function goalBoardComplete(state) {
|
|
932
|
+
return state.items.length > 0 && state.items.every((item) => item.status === 'done')
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
async function saveGoal(sessionId) {
|
|
936
|
+
const state = ensureState(sessionId)
|
|
937
|
+
state.updatedAt = now()
|
|
938
|
+
await persist(sessionId)
|
|
939
|
+
return state.goal
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
async function createGoal(sessionId, objective) {
|
|
943
|
+
const state = ensureState(sessionId)
|
|
944
|
+
if (state.goal.phase === 'active' || state.goal.phase === 'paused' || state.goal.phase === 'blocked') {
|
|
945
|
+
throw new Error(`目标当前为 ${goalPhaseLabel(state.goal.phase)};先用 /progress-goal clear 清除,或 edit 改目标。`)
|
|
946
|
+
}
|
|
947
|
+
const clean = text(objective, 600)
|
|
948
|
+
if (!clean) throw new Error('目标内容不能为空')
|
|
949
|
+
state.goal = {
|
|
950
|
+
...emptyGoal(),
|
|
951
|
+
objective: clean,
|
|
952
|
+
phase: 'active',
|
|
953
|
+
activation: 'armed',
|
|
954
|
+
}
|
|
955
|
+
await saveGoal(sessionId)
|
|
956
|
+
return goalView(sessionId)
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
async function editGoal(sessionId, objective) {
|
|
960
|
+
const state = ensureState(sessionId)
|
|
961
|
+
if (state.goal.phase === 'idle') throw new Error('没有可编辑的目标')
|
|
962
|
+
const clean = text(objective, 600)
|
|
963
|
+
if (!clean) throw new Error('目标内容不能为空')
|
|
964
|
+
state.goal.objective = clean
|
|
965
|
+
if (state.goal.phase === 'complete') {
|
|
966
|
+
state.goal.phase = 'active'
|
|
967
|
+
state.goal.activation = 'armed'
|
|
968
|
+
state.goal.roundsStarted = 0
|
|
969
|
+
state.goal.blockedStreak = 0
|
|
970
|
+
state.goal.blockedReason = null
|
|
971
|
+
}
|
|
972
|
+
await saveGoal(sessionId)
|
|
973
|
+
return goalView(sessionId)
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
async function setGoalBudget(sessionId, value) {
|
|
977
|
+
const state = ensureState(sessionId)
|
|
978
|
+
if (state.goal.phase === 'idle') throw new Error('没有目标可设置预算')
|
|
979
|
+
const n = finiteNumber(value)
|
|
980
|
+
if (n === undefined || !Number.isSafeInteger(n) || n < 1) throw new Error('预算必须是 ≥1 的整数')
|
|
981
|
+
state.goal.maxRounds = Math.min(n, 100000)
|
|
982
|
+
await saveGoal(sessionId)
|
|
983
|
+
return goalView(sessionId)
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
async function pauseGoal(sessionId) {
|
|
987
|
+
const state = ensureState(sessionId)
|
|
988
|
+
if (state.goal.phase === 'idle') throw new Error('没有可暂停的目标')
|
|
989
|
+
if (state.goal.phase !== 'active') throw new Error(`只有 active 目标可暂停(当前 ${goalPhaseLabel(state.goal.phase)})`)
|
|
990
|
+
state.goal.phase = 'paused'
|
|
991
|
+
state.goal.activation = 'disarmed'
|
|
992
|
+
state.goal.currentRound = 0
|
|
993
|
+
await saveGoal(sessionId)
|
|
994
|
+
return goalView(sessionId)
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
async function resumeGoal(sessionId) {
|
|
998
|
+
const state = ensureState(sessionId)
|
|
999
|
+
if (state.goal.phase !== 'paused' && state.goal.phase !== 'blocked') {
|
|
1000
|
+
throw new Error(`只有 paused/blocked 目标可恢复(当前 ${goalPhaseLabel(state.goal.phase)})`)
|
|
1001
|
+
}
|
|
1002
|
+
if (state.goal.roundsStarted >= state.goal.maxRounds) {
|
|
1003
|
+
state.goal.roundsStarted = 0 // 预算已耗尽时恢复 = 新的一轮预算
|
|
1004
|
+
}
|
|
1005
|
+
state.goal.phase = 'active'
|
|
1006
|
+
state.goal.activation = 'armed'
|
|
1007
|
+
state.goal.blockedStreak = 0
|
|
1008
|
+
state.goal.blockedReason = null
|
|
1009
|
+
await saveGoal(sessionId)
|
|
1010
|
+
return goalView(sessionId)
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
async function clearGoal(sessionId) {
|
|
1014
|
+
const state = ensureState(sessionId)
|
|
1015
|
+
state.goal = emptyGoal()
|
|
1016
|
+
await saveGoal(sessionId)
|
|
1017
|
+
return goalView(sessionId)
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// 模型每轮末调用 progress_goal_report 报状态;助手草案只作建议、不自动调这里。
|
|
1021
|
+
async function applyGoalReport(sessionId, report) {
|
|
1022
|
+
const state = ensureState(sessionId)
|
|
1023
|
+
const g = state.goal
|
|
1024
|
+
if (g.phase !== 'active') throw new Error(`目标当前为 ${goalPhaseLabel(g.phase)},只有 active 目标可上报`)
|
|
1025
|
+
if (!isObject(report)) throw new Error('上报必须是对象')
|
|
1026
|
+
const status = String(report.status || '')
|
|
1027
|
+
if (!['continue', 'complete', 'blocked'].includes(status)) throw new Error('status 必须是 continue/complete/blocked')
|
|
1028
|
+
|
|
1029
|
+
if (status === 'complete') {
|
|
1030
|
+
const evidence = Array.isArray(report.evidence) ? report.evidence.filter((e) => typeof e === 'string' && e.trim()) : []
|
|
1031
|
+
if (evidence.length === 0) throw new Error('complete 必须提供至少一条证据 evidence')
|
|
1032
|
+
if (!goalBoardComplete(state)) throw new Error('complete 被拒:进度板尚未全部完成(先更新板再报完成)')
|
|
1033
|
+
g.phase = 'complete'
|
|
1034
|
+
g.activation = 'disarmed'
|
|
1035
|
+
g.currentRound = 0
|
|
1036
|
+
g.blockedStreak = 0
|
|
1037
|
+
g.blockedReason = null
|
|
1038
|
+
await saveGoal(sessionId)
|
|
1039
|
+
return goalView(sessionId)
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
if (status === 'blocked') {
|
|
1043
|
+
const reason = text(report.blocker, 400) || '未提供阻塞原因'
|
|
1044
|
+
if (g.blockedReason === reason) g.blockedStreak += 1
|
|
1045
|
+
else { g.blockedReason = reason; g.blockedStreak = 1 }
|
|
1046
|
+
if (g.blockedStreak >= GOAL_BLOCK_STREAK) {
|
|
1047
|
+
g.phase = 'blocked'
|
|
1048
|
+
g.activation = 'disarmed'
|
|
1049
|
+
g.currentRound = 0
|
|
1050
|
+
}
|
|
1051
|
+
await saveGoal(sessionId)
|
|
1052
|
+
return goalView(sessionId)
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// continue:确认有实质进展,清 blocked 累积,轮次计数不在这里(由驱动器派发时计)
|
|
1056
|
+
g.blockedStreak = 0
|
|
1057
|
+
g.blockedReason = null
|
|
1058
|
+
await saveGoal(sessionId)
|
|
1059
|
+
return goalView(sessionId)
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function renderGoalViewText(view) {
|
|
1063
|
+
const parts = [
|
|
1064
|
+
`Objective: ${JSON.stringify(view.objective)}`,
|
|
1065
|
+
`Status: ${goalPhaseLabel(view.phase)}`,
|
|
1066
|
+
`Rounds: ${view.roundsStarted}/${view.maxRounds}`,
|
|
1067
|
+
`Activation: ${view.activation}`,
|
|
1068
|
+
`Board: ${view.board.done}/${view.board.total} done · ${view.board.percent}%`,
|
|
1069
|
+
]
|
|
1070
|
+
if (view.blockedReason) parts.push(`Blocker: ${view.blockedReason} (streak ${view.blockedStreak}/${GOAL_BLOCK_STREAK})`)
|
|
1071
|
+
return parts.join('\n')
|
|
1072
|
+
}
|
|
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
|
+
|
|
874
1202
|
// ==========================================================================
|
|
875
1203
|
// B. 注入面(board 三块照板 + 鲸程文件上报协议收敛)
|
|
876
1204
|
// ==========================================================================
|
|
@@ -1200,14 +1528,38 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
1200
1528
|
hookedAgents.add(agent)
|
|
1201
1529
|
try {
|
|
1202
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
|
+
|
|
1203
1554
|
const decision = await next()
|
|
1204
1555
|
try {
|
|
1205
1556
|
if (!cfg.protocolHint) return decision
|
|
1557
|
+
// /progress-goal 续轮消息绝不注入协议消息:避免重蹈 /goal 身份污染覆辙。
|
|
1558
|
+
if (stepMessages.some((m) => isGoalRoundMessage(m))) return decision
|
|
1206
1559
|
// 单协议收敛:本会话板已启用 → 不再注入文件上报协议。
|
|
1207
|
-
const sid = String(agent.session?.id ?? agent.id)
|
|
1208
1560
|
if (isEnabled(sid)) return decision
|
|
1209
1561
|
if (!decision || decision.kind !== 'enter' || !Array.isArray(decision.messages)) return decision
|
|
1210
|
-
const freshUser =
|
|
1562
|
+
const freshUser = stepMessages.find((m) => m && m.source && m.source.kind === 'user')
|
|
1211
1563
|
if (!freshUser) return decision
|
|
1212
1564
|
decision.messages.push({
|
|
1213
1565
|
id: 'dpg-' + now().toString(36) + '-' + Math.random().toString(36).slice(2, 8),
|
|
@@ -1524,6 +1876,49 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
1524
1876
|
} catch (_err) {}
|
|
1525
1877
|
for (const agent of agents?.list?.() ?? []) installAgentHook(agent)
|
|
1526
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
|
+
|
|
1527
1922
|
disposers.push(ctx.on('session/event', (session, event) => {
|
|
1528
1923
|
try {
|
|
1529
1924
|
if (!event) return
|
|
@@ -1673,6 +2068,10 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
|
|
|
1673
2068
|
const task = taskMap.get(String(agent.id))
|
|
1674
2069
|
if (task && task.active) task.lastActivityAt = now()
|
|
1675
2070
|
}
|
|
2071
|
+
// /progress-goal 续轮:agent 空载时自动派发下一轮(用户主动消息会抢占 attempt 而停)。
|
|
2072
|
+
if (agent && st === 'idle') {
|
|
2073
|
+
requestGoalDrive(agent)
|
|
2074
|
+
}
|
|
1676
2075
|
// idle 不直接结束任务:maintenance 阶段也报 idle,会误杀进行中任务;结束统一走 sweep。
|
|
1677
2076
|
}))
|
|
1678
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",
|