dsh-progress-union 0.1.1 → 0.1.2
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 +210 -10
- 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.2",
|
|
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,176 @@ 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
|
+
|
|
874
1074
|
// ==========================================================================
|
|
875
1075
|
// B. 注入面(board 三块照板 + 鲸程文件上报协议收敛)
|
|
876
1076
|
// ==========================================================================
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-progress-union",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|