dsh-progress-union 0.1.0 → 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.
Files changed (3) hide show
  1. package/dsh.plugin.json +1 -1
  2. package/index.js +295 -19
  3. package/package.json +14 -2
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-progress-union",
3
- "version": "0.1.0",
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
@@ -19,6 +19,23 @@
19
19
  import fs from 'node:fs'
20
20
  import os from 'node:os'
21
21
  import path from 'node:path'
22
+ import z from '@deepseek-ai/schemastery'
23
+
24
+ // 设置页可见性:宿主 settings.describe() 只看插件导出的 Config(带 .volatile() 的字段
25
+ // 才会生成可编辑表单)。导出它,progress-union 才会出现在「设置 → 插件」里,客户端
26
+ // scopeOf('progress-union') 也才拿得到命名空间做运行时读写。
27
+ export const Config = z.object({
28
+ assistant: z.object({
29
+ mode: z.union(['', 'registered', 'direct']).default(''),
30
+ provider: z.string().default(''),
31
+ model: z.string().default(''),
32
+ baseUrl: z.string().default(''),
33
+ apiKey: z.string().role('secret').default(''),
34
+ authority: z.union(['slots', 'rounds', 'both']).default('both'),
35
+ minIntervalMs: z.number().step(1000).min(0).default(90000),
36
+ autoApply: z.boolean().default(true),
37
+ }).default({}).volatile(),
38
+ })
22
39
 
23
40
  // —— 路由与存储标识 ——
24
41
  const ROUTE_BASE = '/progress-union'
@@ -41,6 +58,13 @@ const STALE_MS = 10 * 60 * 1000
41
58
  const KICKOFF_COOLDOWN_MS = 60 * 1000
42
59
  const STATUSES = new Set(['todo', 'doing', 'done', 'blocked'])
43
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
+
44
68
  // —— widget 侧时间与统计(DSH_HOME 与鲸程共文件,样本不迁移)——
45
69
  const DSH_HOME = process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
46
70
  const PROGRESS_FILE = path.join(DSH_HOME, 'dsh-progress.json')
@@ -54,7 +78,7 @@ const SWEEP_MS = 4000
54
78
  const BAD_READ_GRACE_MS = 2000
55
79
 
56
80
  export const name = 'dsh-progress-union'
57
- export const inject = ['tools', 'systemPrompt', 'webServer', 'agents']
81
+ export const inject = ['tools', 'systemPrompt', 'webServer', 'agents', 'commands', 'llm', 'settings']
58
82
 
59
83
  const PROGRESS_POLICY = `## 进度板
60
84
  progress_update 维护用户可见的实时进度板。每项含 title/status/percent/current/next/approach/note。
@@ -115,6 +139,25 @@ function emptyState(sessionId) {
115
139
  updatedAt: now,
116
140
  items: [],
117
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 表示无
118
161
  }
119
162
  }
120
163
 
@@ -446,25 +489,41 @@ const DEFAULT_CONFIG = {
446
489
  maxTools: 3,
447
490
  maxItems: 12,
448
491
  },
449
- // 辅助 LLM(审查/监视进度):直连 OpenAI 兼容端点,默认关。只允许改
450
- // current/next/percent(命题→校验→落地),不增删任务、不改 title/status。
451
- // 宿主通道暂无纯 chat 调用面,故只支持 direct;建议指向本地/局域网自建端点。
492
+ // 辅助 LLM(审查/监视 + 槽位管理 + 轮次草案):
493
+ // mode: 'registered' 走宿主 llm.stream(选已注册 llm-pi-ai provider/model);
494
+ // 'direct' 走自建 OpenAI 兼容端点(baseUrl/apiKey/model);'' 关。
495
+ // authority: 'slots' 可增删改槽位 | 'rounds' 产轮次草案 | 'both'(默认)。
452
496
  assistant: {
453
- mode: '', // '' 关 | 'direct'
454
- baseUrl: '',
455
- apiKey: '',
456
- model: '',
497
+ mode: '', // '' 关 | 'registered' | 'direct'
498
+ provider: '', // registered:llm-pi-ai 里的 provider 名
499
+ model: '', // registered/direct 共用的模型 id
500
+ baseUrl: '', // direct
501
+ apiKey: '', // direct
502
+ authority: 'both', // slots | rounds | both
457
503
  timeoutMs: 20_000,
458
504
  minIntervalMs: 90_000,
459
505
  maxCallsPerTurn: 1,
506
+ maxSlotChanges: 8, // 助手单次可改槽位数上限(护栏)
460
507
  autoApply: true,
461
508
  },
462
509
  }
463
510
 
511
+ // .volatile() 字段在 0.1.7+ 宿主以 live ref(带 .get())传入,旧宿主为普通值。
512
+ function readVolatile(value, fallback) {
513
+ if (value !== null && typeof value === 'object' && typeof value.get === 'function') {
514
+ const snap = value.get()
515
+ return snap === undefined ? fallback : snap
516
+ }
517
+ return value ?? fallback
518
+ }
519
+
464
520
  export async function apply(ctx, config) {
465
521
  const cfg = Object.assign({}, DEFAULT_CONFIG, config && typeof config === 'object' ? config : {})
466
522
  cfg.observer = Object.assign({}, DEFAULT_CONFIG.observer, cfg.observer && typeof cfg.observer === 'object' ? cfg.observer : {})
467
- cfg.assistant = Object.assign({}, DEFAULT_CONFIG.assistant, cfg.assistant && typeof cfg.assistant === 'object' ? cfg.assistant : {})
523
+ // assistant 是 volatile 字段:保留原始 ref,每次读取时解包(设置面板改了立即生效)。
524
+ const assistantRaw = config && typeof config === 'object' ? config.assistant : undefined
525
+ const unwrappedAssistant = readVolatile(assistantRaw, {})
526
+ cfg.assistant = Object.assign({}, DEFAULT_CONFIG.assistant, unwrappedAssistant && typeof unwrappedAssistant === 'object' ? unwrappedAssistant : {})
468
527
  const now = () => Date.now()
469
528
 
470
529
  // —— 状态容器 ——
@@ -484,8 +543,36 @@ export async function apply(ctx, config) {
484
543
  const tools = ctx.get('tools')
485
544
  const agents = ctx.get('agents')
486
545
  const commands = ctx.get('commands')
546
+ const llm = ctx.get('llm')
547
+ const settings = ctx.get('settings')
487
548
  if (!systemPrompt || !tools) throw new Error('dsh-progress-union 需要 systemPrompt 与 tools 服务')
488
549
 
550
+ // settings 命名空间(面板可编辑的辅助 LLM 配置),composition config 作默认值。
551
+ const ASSISTANT_NS = 'progress-union'
552
+ function readAssistantSection() {
553
+ if (!settings) return undefined
554
+ try {
555
+ let descriptor
556
+ if (typeof settings.describe === 'function') {
557
+ const raw = settings.describe()
558
+ const list = Array.isArray(raw) ? raw : (raw && Array.isArray(raw.namespaces) ? raw.namespaces : undefined)
559
+ descriptor = list && list.find((row) => row && row.ns === ASSISTANT_NS)
560
+ if (descriptor && descriptor.value !== undefined) return { value: descriptor.value, revision: descriptor.revision }
561
+ }
562
+ if (typeof settings.get === 'function') {
563
+ const value = settings.get(ASSISTANT_NS)
564
+ if (value !== undefined) return { value, revision: undefined }
565
+ }
566
+ } catch (_err) {}
567
+ return undefined
568
+ }
569
+ // 运行时配置:settings 里的 assistant 覆盖静态 cfg.assistant(面板改了立即生效)。
570
+ function liveAssistant() {
571
+ const section = readAssistantSection()
572
+ const fromSettings = section && isObject(section.value) && isObject(section.value.assistant) ? section.value.assistant : undefined
573
+ return fromSettings ? { ...cfg.assistant, ...fromSettings } : cfg.assistant
574
+ }
575
+
489
576
  // ==========================================================================
490
577
  // A. board 核心(fork 语义原样:revision / 409 / 全成全败 / ack / userChanges)
491
578
  // ==========================================================================
@@ -544,6 +631,18 @@ export async function apply(ctx, config) {
544
631
  if (typeof item.approach !== 'string') item.approach = ''
545
632
  }
546
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
+ }
547
646
  return state
548
647
  }
549
648
 
@@ -576,16 +675,23 @@ export async function apply(ctx, config) {
576
675
  storageError: storageError || null,
577
676
  items,
578
677
  summary: summarize(items),
579
- // 辅助 LLM(审查/监视)的配置回声:只回非机密字段,apiKey 只回布尔
580
- assistant: {
581
- enabled: assistantReady(),
582
- mode: cfg.assistant.mode || '',
583
- baseUrl: String(cfg.assistant.baseUrl || ''),
584
- model: String(cfg.assistant.model || ''),
585
- hasApiKey: String(cfg.assistant.apiKey || '') !== '',
586
- minIntervalMs: Number(cfg.assistant.minIntervalMs) || 0,
587
- autoApply: cfg.assistant.autoApply !== false,
588
- },
678
+ // /progress-goal 迷你目标域回声
679
+ goal: state.goal ? goalView(state.sessionId) : null,
680
+ // 辅助 LLM 的配置回声:只回非机密字段,apiKey 只回布尔
681
+ assistant: (() => {
682
+ const a = liveAssistant()
683
+ return {
684
+ enabled: assistantReady(),
685
+ mode: a.mode || '',
686
+ provider: String(a.provider || ''),
687
+ baseUrl: String(a.baseUrl || ''),
688
+ model: String(a.model || ''),
689
+ hasApiKey: String(a.apiKey || '') !== '',
690
+ authority: a.authority || 'both',
691
+ minIntervalMs: Number(a.minIntervalMs) || 0,
692
+ autoApply: a.autoApply !== false,
693
+ }
694
+ })(),
589
695
  serverTime: now(),
590
696
  }
591
697
  }
@@ -795,6 +901,176 @@ export async function apply(ctx, config) {
795
901
  return { snapshot: publicSnapshot(working), changed: changed.filter(Boolean) }
796
902
  }
797
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
+
798
1074
  // ==========================================================================
799
1075
  // B. 注入面(board 三块照板 + 鲸程文件上报协议收敛)
800
1076
  // ==========================================================================
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.1.0",
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",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org",
9
+ "access": "public",
10
+ "tag": "latest"
11
+ },
12
+ "dependencies": {
13
+ "@deepseek-ai/schemastery": "~3.18.4"
14
+ },
7
15
  "main": "./index.js",
8
16
  "exports": {
9
17
  ".": "./index.js",
@@ -53,6 +61,10 @@
53
61
  ],
54
62
  "repository": {
55
63
  "type": "git",
56
- "url": "file:mine-dsh-plugins/dsh-progress-union"
64
+ "url": "git+https://github.com/drscrewdriver/dsh-progress-union.git"
65
+ },
66
+ "homepage": "https://github.com/drscrewdriver/dsh-progress-union#readme",
67
+ "bugs": {
68
+ "url": "https://github.com/drscrewdriver/dsh-progress-union/issues"
57
69
  }
58
70
  }