dsh-progress-union 0.5.1 → 0.5.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,53 @@
2
2
 
3
3
  本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
4
4
 
5
+ ## 0.5.4 (2026-11-29)
6
+
7
+ **feat(浮窗暂停/继续):迷你条加目标控制按钮,暂停真停、继续真跑。**
8
+
9
+ 起因:用户要「浮窗应该有一个暂停/继续按钮,接线 pause/resume,重新 resume 会话应该主动继续」。
10
+
11
+ - **feat(HTTP 控制面)**:新增 `POST /progress-union/goal` `{sessionId, action:'pause'|'resume'|'status'}` → `{ok, goal}`;非法 action 或缺 sessionId 一律 400。`/progress-board` 旧前缀同样可用。
12
+ - **feat(pause 真停)**:`pauseGoal` 落 `paused/disarmed` 后**撤回已排队的下一轮**(`inbox.remove`),并清掉内存 attempt —— 否则暂停后那一轮还会照跑、或恢复后被栅栏判 stale 平白丢一轮。回合正在跑时 `controlGoal` 会中断它(`agent.cancel({kind:'user'}, {keepInbox:true})`,用户排队输入不丢)。
13
+ - **feat(resume 真跑)**:`resumeGoal` 重新武装后**等点火落地才返回**(`kickGoalDrive` 现在返回 run promise,`create/edit/resume` 全部 await)。所以浮窗点「继续」→ 下一轮立刻进 inbox,不是只改了个 phase 等人来推。
14
+ - **feat(迷你条按钮)**:`ProgressDock` 动作区按 phase 门控——`active` 显示「暂停」(品牌色描边),`paused`/`blocked` 显示「继续」(品牌色实心,全条唯一强调色);请求在飞时禁用防连点。副标题插入「目标已暂停 / 目标已受阻」。zh/en 双语文案。
15
+ - **fix(liveAgentOf)**:`agentOfSession` 只在 hook 时记录一次,插件热装/重启后可能缺项;新增兜底扫 `agents.list()`,控制面不再因为查不到 agent 而静默不中断。
16
+ - **test**:新增 `test/goal-control.test.mjs`(6 例:pause 撤队列 / resume 立刻派发 / resume 后循环继续 / status 只读 / 400 分支 / 运行中中断且 keepInbox)+ `client.test.mjs` 增加按钮接线守卫(渲染+请求+phase 门控+样式)。
17
+ - 全量 `npm test` **100/100** 绿。
18
+ ## 0.5.3 (2026-11-29)
19
+
20
+ **fix(/progress-goal 出不来重启死循环):异常退出后没有任何回到目标循环的路径。**
21
+
22
+ 起因:用户贴出 `/progress-goal` 的回执「目标当前为 active;先用 clear 清除,或 edit 改目标」,问「目前的情况无法从异常退出回到 goal 循环中吧」。核对代码后确认:**确实没有自愈路径**,而且是三重锁。
23
+
24
+ 1. **没有点火源**:续轮驱动器只挂在 `agent/status` 的 `running→idle` 边沿上。宿主重启后 agent 由构造器以 `idle` 起家(`setPhase` 只在状态**变化**时 emit),这个边沿永远不会发生 → 目标保持 `active/armed` 但一轮都不派发。同时建目标本身也不点火,`/progress-goal X` 之后如果没有下一条用户消息,同样空转。
25
+ 2. **命令面把门焊死**:`createGoal` 对 `active/paused/blocked` 一律抛错(就是截图那句),`resumeGoal` 只认 `paused/blocked` → 用户唯一能试的两条路都被拒;`clear` + 重建虽然能绕,但既不清预算也不点火。
26
+ 3. **排队中的一轮会被静默吞掉**:inbox 是持久化 projection,崩溃前 `followup` 的那一轮重启后还在 `next-turn` 里;但内存 `attempt` 没了,pre-step 身份栅栏判 `attempt && ...` 为假 → `{kind:'reject'}` 丢掉整步,而 `roundsStarted` 在排队时就已 +1 → 白烧一轮预算。更糟的是宿主 resume 时**不会**唤醒 durable inbox,这一轮既不会被执行、又挡住新轮。
27
+
28
+ - **fix(建目标即点火)**:`createGoal` / `editGoal` / `resumeGoal` 落盘后立刻 `kickGoalDrive()` 派发,不再等回合边沿。
29
+ - **fix(重启自愈)**:新增 `kickGoalDrive()` 点火器。会话重新挂载(`installAgentHook`,覆盖 `agent/created` 与存量 agent)时,对 `active+armed` 目标延迟 2.5s 补点火;多会话同时挂载按 400ms 错开,避免启动瞬间齐开回合。存活校验对齐官方 driver(`ctx.agents.get(id) !== agent` 即放弃)。设置项 `goalResumeOnLoad`(`Config` 新叶子,默认 `true`)可关。
30
+ - **fix(resume 接受 active)**:`/progress-goal resume` 现在接受 `active`(重新武装 + 点火);同目标再敲一次 `/progress-goal <同一 objective>` 也按 resume 处理,只有换目标才要求 `edit`。
31
+ - **fix(孤儿轮次)**:`driveGoal` 遇到 inbox 里的遗留轮次——本进程排的就等它跑;上一次进程留下的若 `inbox.remove` 可用就撤掉并按当前进度重排(`roundsStarted` 顺势 +1,不重复执行旧轮)。
32
+ - **fix(pre-step 栅栏双修)**:① 重启后 `attempt` 为空但来源绑定本目标且轮次对齐 → **收养**该轮(重建 attempt)而不是 reject;② 真孤儿只摘掉这一条消息,同一步里的用户消息不再被连坐 `reject`。
33
+ - **test**:`test/goal-drive.test.mjs` 扩到 11 例,新增「建目标即点火」「同轮未消费不得连排两轮」「孤儿轮次只丢自己」「重启收养排队轮」「重启清掉遗留轮并重排」「resume 接受 active」等;harness 补齐宿主 `inbox`(含 `remove`)。旧码在「建目标即点火」「重启自愈」等例上全红。
34
+ - 全量 `npm test` **93/93** 绿。
35
+
36
+ ## 0.5.2 (2026-11-29)
37
+
38
+ **fix(/progress-goal 自动续轮彻底不工作):`driveGoal` 拿不到 agent,每轮派发都抛 TypeError 被静默吞掉。**
39
+
40
+ 起因:用户报「已经用 /progress-goal 设了规则,还是没检查完成就中途停止」。回查 session-`3353b1ac`:`/progress-goal` 建目标成功(`Status: active` / `Activation: armed` / `Rounds: 0/256`),但此后**没有任何一轮被派发** —— 会话日志里没有一条 `<progress_goal_round>`,持久化状态里 `roundsStarted` 恒为 `0`,轮次预算却一直显示满额。
41
+
42
+ - **根因**:`driveGoal(state)` 第一行 `const { agent } = state` 期望拿到官方 driver 的 `DriverState`(其带 `agent` 字段),而本插件实际传入的是 `driveStateFor()` 的 live state —— `{ attempt, requested, run, stopping }`,**没有 `agent`**。于是 `String(agent.session?.id ?? agent.id)` 必然抛 `TypeError: Cannot read properties of undefined (reading 'session')`,而 `requestGoalDrive` 的 `catch` 原本是静默的 → 续轮驱动器从落地起就 100% 空转,表面一切正常(目标 active/armed),实际永不续轮。
43
+ - **fix**:`driveStateFor()` 在 live state 上带 `agent`(对齐官方 `DriverState` 形状),`driveGoal` 解构即得。
44
+ - **fix(可观测)**:`requestGoalDrive` 的单轮失败不再静默,改走 `ctx.logger.warn`(带 stack)——这正是本次事故「无日志、无报错、状态还像对的」的成因。
45
+ - **test(回归)**:新增 `test/goal-drive.test.mjs`(5 例)——idle 边沿必须派发一轮带 `plugin:progress-goal-goal` source 的续轮消息并落盘 `roundsStarted=1`、无目标时不派发、pre-step 身份栅栏放行自己/reject 伪造轮次、预算到顶转 blocked、官方目标 active 时让路。旧代码在本测试第一例即失败。
46
+ - **fix(侧栏排版)**:进度板侧栏头部里,副标题原本和标题同属左侧块、与右侧三个按钮同行;
47
+ 按钮 `flex: none` 把文字列压到约 8em,中文说明被折成每列 2~3 字(335px 侧栏实测截图)。
48
+ 改为 `.pb-side-sub` 脱离 `pb-side-head`、作为其兄弟节点独占整行(`max-width: none` + 自带 14px 下边距,
49
+ 接替旧 head 的 `margin-bottom`),可用宽度回到整个面板内容宽。新增 `test/layout-squeeze.test.mjs`(3 例)钉住契约。
50
+ - 全量 `npm test` **87/87** 绿。
51
+
5
52
  ## 0.5.1 (2026-11-26)
6
53
 
7
54
  **fix(头部图标反色):板样式改为 apply 阶段注入 document.head + 按钮内联兜底。**
package/README.md CHANGED
@@ -80,6 +80,25 @@ import { ANCHOR_VERSION, ANCHOR_ROUTES, isAnchor, anchorLine } from 'dsh-progres
80
80
  - 单协议收敛:板启用的会话不再注入鲸程的文件上报协议(`progress_update` 是唯一写通道);板关闭时文件上报层、`$DSH_HOME/dsh-progress/` 读取与 `/dsh-progress/status` 全部按鲸程原行为保留。
81
81
  - ETA 学习样本沿用鲸程的 `$DSH_HOME/dsh-progress-stats.json`(≥20 条/桶即用本机分位),不迁移不损坏。
82
82
 
83
+ ### `/progress-goal`(长程目标自动续轮)
84
+
85
+ - `/progress-goal <objective>` 建目标即点火:立刻派发第 1 轮,不用再发一条消息催它。
86
+ - 每轮走同一会话:回合收尾(`agent/status → idle`)派发下一轮;模型用 `progress_goal_report` 报
87
+ `continue` / `complete`(须全板 done + evidence)/ `blocked`(同因连续 3 轮落 `blocked`)。
88
+ - 预算用尽自动落 `blocked`;`/progress-goal budget <n>` 改上限,`/progress-goal resume` 重新武装并点火
89
+ (**active 也能 resume**:重启/崩溃后目标还活着但驱动器没跑时,这是回到循环的那条路)。
90
+ - **重启自愈**:宿主重启或崩溃后,armed 目标在会话重新挂载时会自动补一次点火(延迟约 2.5s,多会话
91
+ 错开排队)。上一次进程遗留的排队轮次会被撤掉重排,不会「既不执行又挡住新轮」;重启前已在 inbox
92
+ 里的轮次也会被 pre-step 栅栏收养而不是静默拒绝。设置项 `goalResumeOnLoad`(默认开)可关掉自动点火。
93
+
94
+ - **浮窗暂停 / 继续**:composer 上方的迷你条右侧按钮直连目标控制面。
95
+ - 目标 `active` → 显示「暂停」:落 `paused`,**撤回已排队的下一轮**,回合正在跑就中断它
96
+ (`keepInbox: true`,不会把你排队中的输入一起丢)。暂停后不会再偷偷跑一轮。
97
+ - 目标 `paused` / `blocked` → 显示「继续」:重新武装 **并立刻派发下一轮**(不等你再发消息),
98
+ 所以点完就真继续跑,恢复的是循环而不是一次性。
99
+ - 副标题会带「目标已暂停 / 目标已受阻」;HTTP 面 `POST /progress-union/goal`
100
+ `{sessionId, action:'pause'|'resume'|'status'}` → `{ok, goal}`(其它 action 400)。
101
+
83
102
  ## 观察者(辅助主工作模型)
84
103
 
85
104
  板上还有活干(enabled 且存在未完成项)时,每请求注入一个重建式观察块 `<progress-observer>`(不进历史累积):
package/client.js CHANGED
@@ -209,6 +209,13 @@ window.__ModuleLoader__.load({
209
209
  dockEdit: '编辑',
210
210
  dockOpenFull: '打开完整进度板',
211
211
  dockAllDone: '全部完成',
212
+ dockPause: '暂停',
213
+ dockResume: '继续',
214
+ dockPauseHint: '暂停这个长程目标:立即停止当前回合,之后不再自动续轮',
215
+ dockResumeHint: '继续这个长程目标:重新武装并立刻派发下一轮',
216
+ goalPaused: '目标已暂停',
217
+ goalBlocked: '目标已受阻',
218
+ goalRunning: '目标推进中',
212
219
  llmTitle: '进度辅助 LLM(审查/槽位/轮次)',
213
220
  llmOn: '已启用',
214
221
  llmOff: '未启用:观察者为规则版(零 LLM 费用)。启用后由辅助模型管理任务槽位、产出续轮建议。',
@@ -376,6 +383,13 @@ window.__ModuleLoader__.load({
376
383
  dockEdit: 'Edit',
377
384
  dockOpenFull: 'Open full board',
378
385
  dockAllDone: 'All done',
386
+ dockPause: 'Pause',
387
+ dockResume: 'Resume',
388
+ dockPauseHint: 'Pause this long goal: stop the live turn now and stop auto-continuing',
389
+ dockResumeHint: 'Resume this long goal: re-arm and dispatch the next round immediately',
390
+ goalPaused: 'Goal paused',
391
+ goalBlocked: 'Goal blocked',
392
+ goalRunning: 'Goal running',
379
393
  llmTitle: 'Progress assistant LLM (audit/slots/rounds)',
380
394
  llmOn: 'Enabled',
381
395
  llmOff: 'Disabled: the observer is rule-based (zero LLM cost). When enabled, the assistant manages task slots and produces round suggestions.',
@@ -676,6 +690,12 @@ window.__ModuleLoader__.load({
676
690
  padding: 2px 7px; font: inherit; font-size: 11px; line-height: 1.4; cursor: pointer;
677
691
  }
678
692
  .pb-dock-btn:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
693
+ .pb-dock-btn:disabled { opacity: .45; cursor: not-allowed; }
694
+ /* 目标暂停/继续:唯一强调色落在这里,其余动作保持中性灰。 */
695
+ .pb-dock-goal { font-weight: 600; }
696
+ .pb-dock-goal-pause { border-color: var(--dsw-alias-brand-primary); color: var(--dsw-alias-brand-primary); }
697
+ .pb-dock-goal-resume { border-color: var(--dsw-alias-brand-primary); background: var(--dsw-alias-brand-primary); color: var(--dsw-alias-bg-base); }
698
+ .pb-dock-goal-resume:hover { color: var(--dsw-alias-bg-base); filter: brightness(1.06); }
679
699
  .pb-dock-expanded {
680
700
  display: flex; flex-direction: column; gap: 3px; margin-top: 7px; padding-top: 7px;
681
701
  border-top: 1px solid var(--dsw-alias-border-l1); max-height: 180px; overflow: auto;
@@ -693,10 +713,11 @@ window.__ModuleLoader__.load({
693
713
  color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-base);
694
714
  font-family: inherit; font-size: 13px; line-height: 1.45;
695
715
  }
696
- .pb-side-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
716
+ .pb-side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
697
717
  .pb-side-head-actions { display: flex; align-items: center; gap: 4px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
698
718
  .pb-side-title { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
699
- .pb-side-sub { margin: 3px 0 0; color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 1.4; }
719
+ /* 副标题单独占满整行:窄栏里不再被右侧按钮挤成竖排,而是用到按钮下方的空白铺开 */
720
+ .pb-side-sub { margin: 5px 0 14px; color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 1.4; max-width: none; }
700
721
  .pb-side-section { margin-top: 15px; }
701
722
  .pb-side-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; color: var(--dsw-alias-label-secondary); font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }
702
723
  .pb-side-card { border: 1px solid var(--dsw-alias-border-l1); border-radius: 9px; background: var(--dsw-alias-bg-layer-1); padding: 9px 10px; }
@@ -808,6 +829,23 @@ window.__ModuleLoader__.load({
808
829
  return body && body.ok === true ? body : null
809
830
  }
810
831
 
832
+ /** 浮窗/面板的目标控制面:pause | resume | status(宿主 /progress-union/goal)。 */
833
+ async function controlGoal(sessionId, action) {
834
+ try {
835
+ const response = await fetch(`${API}/goal`, {
836
+ method: 'POST',
837
+ credentials: 'same-origin',
838
+ headers: { 'content-type': 'application/json' },
839
+ body: JSON.stringify({ sessionId, action }),
840
+ })
841
+ const body = await response.json().catch(() => null)
842
+ return body && body.ok === true ? body : null
843
+ } catch (_error) {
844
+ // The board still works; only the goal control is unavailable.
845
+ return null
846
+ }
847
+ }
848
+
811
849
  function ProgressNavIcon({ size = 20 }) {
812
850
  return h(
813
851
  'svg',
@@ -1342,6 +1380,8 @@ window.__ModuleLoader__.load({
1342
1380
  const timing = useUnionTiming(sessionId)
1343
1381
  const usageView = usageSummary(useSessionUsage(sessionId, props.usage))
1344
1382
  const [expanded, setExpanded] = useState(false)
1383
+ // 浮窗暂停/继续:请求在飞时禁用按钮,避免连点排两轮或反复切状态。
1384
+ const [goalBusy, setGoalBusy] = useState(false)
1345
1385
 
1346
1386
  useEffect(() => {
1347
1387
  setExpanded(false)
@@ -1367,6 +1407,11 @@ window.__ModuleLoader__.load({
1367
1407
  else if (timing && timing.etaMin > 0) sub.push(`${t('etaLeft')} ${timing.etaMin} min`)
1368
1408
  if (snapshot.pendingUserChanges) sub.push(`${snapshot.pendingUserChanges} ${t('dockPending')}`)
1369
1409
  if (snapshot.enabled === false) sub.push(t('autoOff'))
1410
+ const goalPhase = snapshot.goal && snapshot.goal.phase ? String(snapshot.goal.phase) : ''
1411
+ const goalActive = goalPhase === 'active'
1412
+ const goalStopped = goalPhase === 'paused' || goalPhase === 'blocked'
1413
+ if (goalPhase === 'paused') sub.splice(1, 0, t('goalPaused'))
1414
+ else if (goalPhase === 'blocked') sub.splice(1, 0, t('goalBlocked'))
1370
1415
  if (usageView) sub.splice(1, 0, usageLabel(usageView))
1371
1416
  if (readError) sub.push(t('syncFailed'))
1372
1417
  sub.push(t('dockHint'))
@@ -1376,6 +1421,18 @@ window.__ModuleLoader__.load({
1376
1421
  refresh()
1377
1422
  }
1378
1423
 
1424
+ const onGoalControl = async (action) => {
1425
+ if (goalBusy) return
1426
+ setGoalBusy(true)
1427
+ try {
1428
+ await controlGoal(sessionId, action)
1429
+ } finally {
1430
+ // 以宿主状态为准刷新,不靠本地猜停在哪个 phase。
1431
+ refresh()
1432
+ setGoalBusy(false)
1433
+ }
1434
+ }
1435
+
1379
1436
  const openPanel = () => {
1380
1437
  try {
1381
1438
  props.openPanel?.()
@@ -1456,6 +1513,34 @@ window.__ModuleLoader__.load({
1456
1513
  t('autoEnable'),
1457
1514
  )
1458
1515
  : null,
1516
+ goalActive
1517
+ ? h(
1518
+ 'button',
1519
+ {
1520
+ type: 'button',
1521
+ className: 'pb-dock-btn pb-dock-goal pb-dock-goal-pause',
1522
+ title: t('dockPauseHint'),
1523
+ 'aria-label': t('dockPause'),
1524
+ disabled: goalBusy,
1525
+ onClick: () => onGoalControl('pause'),
1526
+ },
1527
+ t('dockPause'),
1528
+ )
1529
+ : null,
1530
+ goalStopped
1531
+ ? h(
1532
+ 'button',
1533
+ {
1534
+ type: 'button',
1535
+ className: 'pb-dock-btn pb-dock-goal pb-dock-goal-resume',
1536
+ title: t('dockResumeHint'),
1537
+ 'aria-label': t('dockResume'),
1538
+ disabled: goalBusy,
1539
+ onClick: () => onGoalControl('resume'),
1540
+ },
1541
+ t('dockResume'),
1542
+ )
1543
+ : null,
1459
1544
  h(
1460
1545
  'button',
1461
1546
  {
@@ -2170,12 +2255,7 @@ window.__ModuleLoader__.load({
2170
2255
  h(
2171
2256
  'div',
2172
2257
  { className: 'pb-side-head' },
2173
- h(
2174
- 'div',
2175
- null,
2176
- h('h2', { className: 'pb-side-title' }, t('nav')),
2177
- h('p', { className: 'pb-side-sub' }, t('subtitle')),
2178
- ),
2258
+ h('h2', { className: 'pb-side-title' }, t('nav')),
2179
2259
  h(
2180
2260
  'div',
2181
2261
  { className: 'pb-side-head-actions' },
@@ -2200,6 +2280,7 @@ window.__ModuleLoader__.load({
2200
2280
  h('button', { type: 'button', className: 'pb-btn', onClick: collapse }, t('sideCollapse')),
2201
2281
  ),
2202
2282
  ),
2283
+ h('p', { className: 'pb-side-sub' }, t('subtitle')),
2203
2284
  readError ? h('div', { className: 'pb-side-error' }, `${t('readError')}${readError}`) : null,
2204
2285
  h(LlmAssistNotice, { assistant: snapshot?.assistant, t: props.t }),
2205
2286
  actionError ? h('div', { className: 'pb-side-error' }, `${t('saveError')}${actionError}`) : null,
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-progress-union",
3
- "version": "0.5.1",
3
+ "version": "0.5.4",
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
@@ -28,6 +28,9 @@ import { ANCHOR_VERSION, ANCHOR_ROUTES, BOARD_STATUSES } from './anchor.js'
28
28
  // 只会空空如也),所以必须每个叶子单独标——与 dsh-llm-openai-completions 同式。
29
29
  export const Config = z.object({
30
30
  protocolHint: z.boolean().default(true).volatile(),
31
+ // /progress-goal 重启自愈:宿主重启/崩溃后,armed 目标在会话重新挂载时补一次续轮点火。
32
+ // 设 false 则恢复成「必须有人发消息产生回合收尾边沿」才动(旧行为,目标会静默停摆)。
33
+ goalResumeOnLoad: z.boolean().default(true).volatile(),
31
34
  assistant: z.object({
32
35
  mode: z.union(['', 'registered', 'direct']).default('').volatile(),
33
36
  provider: z.string().default('').volatile(),
@@ -798,6 +801,7 @@ function flushStats() {
798
801
 
799
802
  const DEFAULT_CONFIG = {
800
803
  protocolHint: true, // 板关闭会话的文件上报协议注入开关
804
+ goalResumeOnLoad: true, // 重启/重新挂载会话时给 armed 目标补一次续轮点火
801
805
  pollMs: 1000,
802
806
  doneHoldMs: 30000,
803
807
  doneKeepMs: 120000,
@@ -886,6 +890,12 @@ export async function apply(ctx, config) {
886
890
  })
887
891
  // assistant 的每个字段都是 volatile:保留原始 ref(整对象或逐叶子皆可),
888
892
  // 每次读取时解包,设置页改完下一次审查即生效,无需重启。
893
+ const goalResumeRaw = config && typeof config === 'object' ? config.goalResumeOnLoad : undefined
894
+ Object.defineProperty(cfg, 'goalResumeOnLoad', {
895
+ get: () => readVolatile(goalResumeRaw, DEFAULT_CONFIG.goalResumeOnLoad),
896
+ configurable: true,
897
+ enumerable: true,
898
+ })
889
899
  const assistantRaw = config && typeof config === 'object' ? config.assistant : undefined
890
900
  function assistantNow() {
891
901
  const base = DEFAULT_CONFIG.assistant
@@ -1559,8 +1569,17 @@ export async function apply(ctx, config) {
1559
1569
 
1560
1570
  async function createGoal(sessionId, objective) {
1561
1571
  const state = ensureState(sessionId)
1562
- if (state.goal.phase === 'active' || state.goal.phase === 'paused' || state.goal.phase === 'blocked') {
1563
- throw new Error(`目标当前为 ${goalPhaseLabel(state.goal.phase)};先用 /progress-goal clear 清除,或 edit 改目标。`)
1572
+ const phase = state.goal.phase
1573
+ if (phase === 'active' || phase === 'paused' || phase === 'blocked') {
1574
+ // active 不是死路:重启/崩溃后目标还活着但驱动器没跑,正是最常见的「回不去」现场。
1575
+ // 同目标一律按「重新武装 + 点火」处理,而不是逼用户 clear 掉重来。
1576
+ const clean = text(objective, 600)
1577
+ if (clean && clean !== state.goal.objective) {
1578
+ const err = new Error(`目标当前为 ${goalPhaseLabel(phase)};要换目标用 /progress-goal edit <新目标>,要继续用 /progress-goal resume。`)
1579
+ err.reason = 'goal-exists'
1580
+ throw err
1581
+ }
1582
+ return resumeGoal(sessionId)
1564
1583
  }
1565
1584
  const clean = text(objective, 600)
1566
1585
  if (!clean) throw new Error('目标内容不能为空')
@@ -1571,6 +1590,7 @@ export async function apply(ctx, config) {
1571
1590
  activation: 'armed',
1572
1591
  }
1573
1592
  await saveGoal(sessionId)
1593
+ await kickGoalDrive(liveAgentOf(sessionId))
1574
1594
  return goalView(sessionId)
1575
1595
  }
1576
1596
 
@@ -1588,6 +1608,7 @@ export async function apply(ctx, config) {
1588
1608
  state.goal.blockedReason = null
1589
1609
  }
1590
1610
  await saveGoal(sessionId)
1611
+ await kickGoalDrive(liveAgentOf(sessionId))
1591
1612
  return goalView(sessionId)
1592
1613
  }
1593
1614
 
@@ -1609,13 +1630,24 @@ export async function apply(ctx, config) {
1609
1630
  state.goal.activation = 'disarmed'
1610
1631
  state.goal.currentRound = 0
1611
1632
  await saveGoal(sessionId)
1633
+ // 暂停时撤掉内存 attempt:否则恢复后同一轮会被栅栏判 stale 而平白丢一轮。
1634
+ try {
1635
+ const agent = liveAgentOf(sessionId)
1636
+ const ds = agent ? driveStateFor(agent) : undefined
1637
+ if (ds) {
1638
+ const attempt = ds.attempt
1639
+ ds.attempt = undefined
1640
+ if (attempt && agent.inbox && typeof agent.inbox.remove === 'function') agent.inbox.remove(attempt.messageId)
1641
+ }
1642
+ } catch (_err) {}
1612
1643
  return goalView(sessionId)
1613
1644
  }
1614
1645
 
1615
1646
  async function resumeGoal(sessionId) {
1616
1647
  const state = ensureState(sessionId)
1617
- if (state.goal.phase !== 'paused' && state.goal.phase !== 'blocked') {
1618
- throw new Error(`只有 paused/blocked 目标可恢复(当前 ${goalPhaseLabel(state.goal.phase)})`)
1648
+ const phase = state.goal.phase
1649
+ if (phase !== 'paused' && phase !== 'blocked' && phase !== 'active') {
1650
+ throw new Error(`只有 active/paused/blocked 目标可恢复(当前 ${goalPhaseLabel(phase)})`)
1619
1651
  }
1620
1652
  if (state.goal.roundsStarted >= state.goal.maxRounds) {
1621
1653
  state.goal.roundsStarted = 0 // 预算已耗尽时恢复 = 新的一轮预算
@@ -1625,6 +1657,9 @@ export async function apply(ctx, config) {
1625
1657
  state.goal.blockedStreak = 0
1626
1658
  state.goal.blockedReason = null
1627
1659
  await saveGoal(sessionId)
1660
+ // 恢复不只是改状态:顺手点火,否则「恢复成功」但没回合边沿仍然不动。
1661
+ // 等点火落地再返回 —— 浮窗点「继续」后刷新到的必须已经是「下一轮已排队」的状态。
1662
+ await kickGoalDrive(liveAgentOf(sessionId))
1628
1663
  return goalView(sessionId)
1629
1664
  }
1630
1665
 
@@ -1696,7 +1731,8 @@ export async function apply(ctx, config) {
1696
1731
  function driveStateFor(agent) {
1697
1732
  let s = goalDrives.get(agent)
1698
1733
  if (!s) {
1699
- s = { attempt: undefined, requested: false, run: undefined, stopping: false }
1734
+ // agent 必须存在 live state 上:driveGoal(state) 从这里取 agent(对齐官方 DriverState)。
1735
+ s = { agent, attempt: undefined, requested: false, run: undefined, stopping: false }
1700
1736
  goalDrives.set(agent, s)
1701
1737
  }
1702
1738
  return s
@@ -1762,6 +1798,25 @@ export async function apply(ctx, config) {
1762
1798
  await saveGoal(sessionId)
1763
1799
  return
1764
1800
  }
1801
+ // 已有一轮还在 inbox 里排队:要么是本进程刚排的(等它跑,别连排两轮),
1802
+ // 要么是上一次进程留下的孤儿(宿主 resume 时不会唤醒 durable inbox,
1803
+ // 它既不会被执行、又会挡住新轮 → 清掉它,按当前进度重排一轮)。
1804
+ try {
1805
+ const inbox = agent.inbox
1806
+ const lists = inbox ? [inbox.nextTurn, inbox.nextStep] : []
1807
+ const pending = []
1808
+ for (const list of lists) {
1809
+ if (!Array.isArray(list)) continue
1810
+ for (const m of list) if (isGoalRoundMessage(m)) pending.push(m)
1811
+ }
1812
+ if (pending.length > 0) {
1813
+ const ours = Boolean(state.attempt && pending.some((m) => m.id === state.attempt.messageId))
1814
+ if (ours || typeof inbox.remove !== 'function') return
1815
+ for (const m of pending) {
1816
+ if (!inbox.remove(m.id)) return
1817
+ }
1818
+ }
1819
+ } catch (_err) {}
1765
1820
  const round = g.roundsStarted + 1
1766
1821
  const revision = current.revision
1767
1822
  const content = renderGoalRoundContent(sessionId, round, goalView(sessionId))
@@ -1790,9 +1845,9 @@ export async function apply(ctx, config) {
1790
1845
 
1791
1846
  function requestGoalDrive(agent) {
1792
1847
  const state = driveStateFor(agent)
1793
- if (state.stopping) return
1848
+ if (state.stopping) return state.run
1794
1849
  state.requested = true
1795
- if (state.run !== undefined) return
1850
+ if (state.run !== undefined) return state.run
1796
1851
  let run
1797
1852
  try {
1798
1853
  run = (async () => {
@@ -1800,14 +1855,17 @@ export async function apply(ctx, config) {
1800
1855
  state.requested = false
1801
1856
  try {
1802
1857
  await driveGoal(state)
1803
- } catch (_err) {
1804
- // 单轮失败静默,不阻断后续
1858
+ } catch (err) {
1859
+ // 单轮失败不阻断后续,但必须留痕:静默吞掉会让「设了目标却不续轮」无从排查。
1860
+ try {
1861
+ ctx.logger?.warn?.(`progress-union: goal round drive failed: ${err instanceof Error ? err.stack || err.message : String(err)}`)
1862
+ } catch (_logErr) {}
1805
1863
  }
1806
1864
  }
1807
1865
  })()
1808
1866
  } catch (_err) {
1809
1867
  state.run = undefined
1810
- return
1868
+ return undefined
1811
1869
  }
1812
1870
  state.run = run
1813
1871
  const retire = () => {
@@ -1815,6 +1873,99 @@ export async function apply(ctx, config) {
1815
1873
  if (state.requested && !state.stopping) requestGoalDrive(agent)
1816
1874
  }
1817
1875
  run.then(retire, retire)
1876
+ return run
1877
+ }
1878
+
1879
+ // —— 点火(重启自愈):驱动器只挂在 running→idle 边沿上,而宿主重启后 agent
1880
+ // 由构造器以 idle 起家、不再产生该边沿;崩溃时已排队的一轮又只在内存 attempt
1881
+ // 里有效。于是「目标 active+armed」和「驱动器在跑」之间没有任何桥。
1882
+ // 这里给会话重新挂载/目标刚建好的场景补一次派发,桥接起来。
1883
+ const GOAL_KICK_DELAY_MS = 2500
1884
+ const goalKickTimers = new Map() // agent -> timer(同 agent 只留一个,避免连排两轮)
1885
+
1886
+ function goalDrivable(sessionId) {
1887
+ const goal = states.get(sessionId)?.goal
1888
+ return Boolean(goal && goal.phase === 'active' && goal.activation === 'armed')
1889
+ }
1890
+
1891
+ function kickGoalDrive(agent, delayMs = 0) {
1892
+ if (!agent || !agent.id) return undefined
1893
+ const pending = goalKickTimers.get(agent)
1894
+ if (pending) clearTimeout(pending)
1895
+ const fire = () => {
1896
+ goalKickTimers.delete(agent)
1897
+ try {
1898
+ if (!cfg.goalResumeOnLoad) return undefined
1899
+ const sid = String(agent.session?.id ?? agent.id)
1900
+ if (!goalDrivable(sid)) return undefined
1901
+ // 回合正在跑:交给它自己的 running→idle 边沿,别插队。
1902
+ if (agent.status && agent.status !== 'idle') return undefined
1903
+ const liveAgent = ctx.get('agents')?.get?.(agent.id)
1904
+ if (liveAgent && liveAgent !== agent) return undefined
1905
+ return requestGoalDrive(agent)
1906
+ } catch (_err) {
1907
+ return undefined
1908
+ }
1909
+ }
1910
+ if (delayMs > 0) {
1911
+ // 多个会话同时挂载时错开点火,别在启动瞬间同时开十几个回合。
1912
+ const queueDelay = delayMs + Math.min(goalKickTimers.size, 20) * 400
1913
+ const timer = setTimeout(fire, queueDelay)
1914
+ if (typeof timer?.unref === 'function') timer.unref()
1915
+ goalKickTimers.set(agent, timer)
1916
+ return undefined
1917
+ }
1918
+ return fire()
1919
+ }
1920
+
1921
+ // 会话 → 活着的 agent。agentOfSession 只在 hook 时装一次;插件热装/重启后可能缺项,
1922
+ // 所以兜底扫一遍 agents.list(),找不到就返回 undefined(不硬猜)。
1923
+ function liveAgentOf(sessionId) {
1924
+ if (!sessionId) return undefined
1925
+ try {
1926
+ const known = agentOfSession.get(sessionId)
1927
+ if (known && (!known.session || String(known.session.id ?? known.id) === sessionId)) {
1928
+ const live = agents?.list?.() ?? []
1929
+ if (live.length === 0 || live.includes(known)) return known
1930
+ }
1931
+ for (const agent of agents?.list?.() ?? []) {
1932
+ if (sessionOfAgent(agent) === sessionId) {
1933
+ agentOfSession.set(sessionId, agent)
1934
+ return agent
1935
+ }
1936
+ }
1937
+ } catch (_err) {}
1938
+ return undefined
1939
+ }
1940
+
1941
+ // —— 浮窗/面板的暂停·继续(HTTP 控制面)——
1942
+ // pause:落 paused 并撤回本轮(排队中的续轮一起撤掉,不让它暂停后偷偷再跑一轮);
1943
+ // 回合正在跑时中断它——「暂停」就该立刻停手,而不是等这一轮自己跑完。
1944
+ // resume:重新武装 + 立刻点火(不等用户再发一条消息来制造 idle 边沿)。
1945
+ async function controlGoal(sessionId, action) {
1946
+ if (action === 'status') return goalView(sessionId)
1947
+ if (action === 'pause') {
1948
+ const view = await pauseGoal(sessionId)
1949
+ const agent = liveAgentOf(sessionId)
1950
+ if (agent) {
1951
+ try {
1952
+ const ds = driveStateFor(agent)
1953
+ const attempt = ds.attempt
1954
+ ds.attempt = undefined
1955
+ if (attempt && agent.inbox && typeof agent.inbox.remove === 'function') {
1956
+ agent.inbox.remove(attempt.messageId)
1957
+ }
1958
+ } catch (_err) {}
1959
+ try {
1960
+ if (agent.status === 'running' && typeof agent.cancel === 'function') {
1961
+ agent.cancel({ kind: 'user' }, { keepInbox: true })
1962
+ }
1963
+ } catch (_err) {}
1964
+ }
1965
+ return view
1966
+ }
1967
+ if (action === 'resume') return resumeGoal(sessionId)
1968
+ throw new Error(`未知的目标控制动作:${action}`)
1818
1969
  }
1819
1970
 
1820
1971
  // ==========================================================================
@@ -2348,26 +2499,48 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
2348
2499
  const stepMessages = ((payload && payload.messages) || [])
2349
2500
 
2350
2501
  // /progress-goal 身份栅栏:目标续轮消息必须精确匹配 attempt,否则拒绝本步。
2502
+ // 但拒绝要精确到「这一条」:整步 reject 会把同一步里用户真正说的话一起丢掉。
2351
2503
  const goalRound = stepMessages.find((m) => isGoalRoundMessage(m))
2504
+ let orphanRound = false
2352
2505
  if (goalRound) {
2353
2506
  const ds = driveStateFor(agent)
2354
2507
  const attempt = ds.attempt
2355
2508
  const src = goalRound.source
2356
2509
  const current = states.get(sid)
2357
2510
  const g = current && current.goal
2358
- const valid = Boolean(
2359
- attempt && sameGoalSource(goalRound, attempt) && !attempt.stale &&
2511
+ // 与目标本体的一致性:同一目标 + 仍 active/armed + 轮次正好等于已派发计数。
2512
+ const goalCurrent = Boolean(
2360
2513
  g && g.id === src.goalId && g.phase === 'active' && g.activation === 'armed' &&
2361
- src.round === g.roundsStarted && src.round === attempt.round
2514
+ src.round === g.roundsStarted
2362
2515
  )
2363
- if (!valid) {
2516
+ const valid = Boolean(attempt && sameGoalSource(goalRound, attempt) && !attempt.stale && goalCurrent)
2517
+ if (valid) attempt.phase = 'claimed'
2518
+ else if (goalCurrent && !attempt) {
2519
+ // 重启自愈:宿主重启后内存 attempt 丢了,但这一轮在持久化 inbox 里还在,
2520
+ // 且来源绑定本目标、轮次对齐 → 收养它(重建 attempt),别把排队中的一轮静默吞掉。
2521
+ ds.attempt = {
2522
+ goalId: src.goalId,
2523
+ revision: src.revision,
2524
+ round: src.round,
2525
+ messageId: goalRound.id,
2526
+ phase: 'claimed',
2527
+ stale: false,
2528
+ }
2529
+ } else {
2530
+ // 孤儿轮次:目标已 clear/换目标/轮次已推进(或显式 stale)。
2364
2531
  if (attempt && attempt.goalId === src.goalId) { attempt.stale = true; ds.attempt = undefined }
2365
- return { kind: 'reject' }
2532
+ orphanRound = true
2366
2533
  }
2367
- attempt.phase = 'claimed'
2368
2534
  }
2369
2535
 
2370
2536
  const decision = await next()
2537
+
2538
+ if (orphanRound) {
2539
+ if (!decision || decision.kind !== 'enter' || !Array.isArray(decision.messages)) return decision
2540
+ const kept = decision.messages.filter((m) => !isGoalRoundMessage(m))
2541
+ if (kept.length === 0) return { kind: 'reject' }
2542
+ return { ...decision, messages: kept }
2543
+ }
2371
2544
  try {
2372
2545
  if (!cfg.protocolHint) return decision
2373
2546
  // /progress-goal 续轮消息绝不注入协议消息:避免重蹈 /goal 身份污染覆辙。
@@ -2390,6 +2563,8 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
2390
2563
  }
2391
2564
  })
2392
2565
  } catch (_err) {}
2566
+ // 重启/新开会话:会话一挂载就给 armed 目标补点火(延迟等宿主把这回合的基础设施铺好)。
2567
+ kickGoalDrive(agent, GOAL_KICK_DELAY_MS)
2393
2568
  }
2394
2569
 
2395
2570
  // ==========================================================================
@@ -3268,6 +3443,41 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
3268
3443
  },
3269
3444
  }),
3270
3445
  )
3446
+ // 目标控制面(浮窗暂停/继续按钮):{sessionId, action:'pause'|'resume'|'status'}
3447
+ routeDisposers.push(
3448
+ webServer.register({
3449
+ kind: 'exact',
3450
+ path: `${base}/goal`,
3451
+ handler: async (req, res) => {
3452
+ if (req.method !== 'POST') {
3453
+ res.writeHead(405, { allow: 'POST' })
3454
+ res.end()
3455
+ return
3456
+ }
3457
+ if (!String(req.headers['content-type'] || '').toLowerCase().startsWith('application/json')) {
3458
+ sendJson(res, 415, { ok: false, error: 'content-type 必须是 application/json' })
3459
+ return
3460
+ }
3461
+ try {
3462
+ const body = await readJson(req)
3463
+ const sessionId = body.sessionId
3464
+ if (typeof sessionId !== 'string' || !sessionId || sessionId.length > 240) {
3465
+ sendJson(res, 400, { ok: false, error: '缺少有效的 sessionId' })
3466
+ return
3467
+ }
3468
+ const action = String(body.action || '').toLowerCase()
3469
+ if (!['pause', 'resume', 'status'].includes(action)) {
3470
+ sendJson(res, 400, { ok: false, error: 'action 必须是 pause/resume/status' })
3471
+ return
3472
+ }
3473
+ const goal = await controlGoal(sessionId, action)
3474
+ sendJson(res, 200, { ok: true, goal })
3475
+ } catch (error) {
3476
+ sendJson(res, 400, { ok: false, error: error instanceof Error ? error.message : String(error) })
3477
+ }
3478
+ },
3479
+ }),
3480
+ )
3271
3481
  routeDisposers.push(
3272
3482
  webServer.register({
3273
3483
  kind: 'exact',
@@ -3607,6 +3817,8 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
3607
3817
 
3608
3818
  ctx.effect(() => () => {
3609
3819
  clearInterval(sweepTimer)
3820
+ for (const timer of goalKickTimers.values()) clearTimeout(timer)
3821
+ goalKickTimers.clear()
3610
3822
  for (const dispose of disposers.splice(0)) {
3611
3823
  try {
3612
3824
  dispose()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.5.1",
3
+ "version": "0.5.4",
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",
@@ -27,6 +27,22 @@ test('client.js 命名空间已切到 union,无 progress-board API 残留', ()
27
27
  assert.match(src, /useUnionTiming/, '迷你条时间面钩子必须在')
28
28
  })
29
29
 
30
+ test('迷你条暂停/继续按钮接线齐全(渲染 + 请求 + 状态门控)', () => {
31
+ const src = fs.readFileSync(clientFile, 'utf8')
32
+ // 渲染:两个按钮都在 dock actions 区
33
+ assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-pause'/, '暂停按钮必须在')
34
+ assert.match(src, /className: 'pb-dock-btn pb-dock-goal pb-dock-goal-resume'/, '继续按钮必须在')
35
+ // 请求面:走 /progress-union/goal 控制路由
36
+ assert.match(src, /fetch\(`\$\{API\}\/goal`/, '必须调用目标控制路由')
37
+ assert.match(src, /action: 'pause'|onGoalControl\('pause'\)/, '暂停必须接线')
38
+ assert.match(src, /onGoalControl\('resume'\)/, '继续必须接线')
39
+ // 门控:只有目标 active 才给暂停,只有 paused/blocked 才给继续
40
+ assert.match(src, /goalActive = goalPhase === 'active'/, '暂停按钮必须按 phase 门控')
41
+ assert.match(src, /goalStopped = goalPhase === 'paused' \|\| goalPhase === 'blocked'/, '继续按钮必须按 phase 门控')
42
+ // 按钮样式必须真的存在(否则是裸浏览器按钮)
43
+ assert.match(src, /\.pb-dock-goal-resume \{[^}]*background: var\(--dsw-alias-brand-primary\)/, '继续按钮需要有主色实心样式')
44
+ })
45
+
30
46
  test('宿主 snapshot/status 两路由的客户端消费形状', async () => {
31
47
  const harness = createHarness()
32
48
  await harness.run()
@@ -0,0 +1,147 @@
1
+ /**
2
+ * 浮窗暂停/继续(目标控制面)验收:
3
+ * - POST /progress-union/goal {action:'pause'} → 落 paused + 撤回排队中的续轮 + 中断运行中的回合;
4
+ * - {action:'resume'} → 重新武装 + 立刻点火,下一轮真的被派发(不是只改状态);
5
+ * - {action:'status'} → 只读回声;
6
+ * - 非法 action / 缺 sessionId → 400;
7
+ * - 暂停后不会偷偷再跑一轮(idle 边沿不会派发);继续后能接上前进。
8
+ */
9
+ import assert from 'node:assert/strict'
10
+ import fs from 'node:fs'
11
+ import os from 'node:os'
12
+ import path from 'node:path'
13
+ import test from 'node:test'
14
+
15
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-goal-control-'))
16
+ const { SESSION, createHarness, jsonReq, callRoute, flush } = await import('./harness.mjs')
17
+
18
+ async function booted() {
19
+ const harness = createHarness({})
20
+ await harness.run()
21
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
22
+ return harness
23
+ }
24
+
25
+ function cmd(harness, input) {
26
+ return harness.commandMap.get('progress-goal').handler({ agent: harness.agent, rawInput: input })
27
+ }
28
+
29
+ async function goalCmd(harness, input) {
30
+ const result = await cmd(harness, input)
31
+ await flush()
32
+ await flush()
33
+ return result
34
+ }
35
+
36
+ async function update(harness, changes) {
37
+ const r = await harness.toolMap.get('progress_update').definition.execute({ changes }, { agent: harness.agent })
38
+ return r
39
+ }
40
+
41
+ async function goalControl(harness, action, sessionId = SESSION) {
42
+ const res = await callRoute(harness, '/progress-union/goal', jsonReq('POST', '/progress-union/goal', { sessionId, action }))
43
+ return { status: res.status, body: res.json() }
44
+ }
45
+
46
+ async function idle(harness) {
47
+ for (const listener of harness.listeners.filter((l) => l.type === 'agent/status')) {
48
+ listener.handler({ agent: harness.agent, status: 'idle' })
49
+ }
50
+ await flush()
51
+ await new Promise((resolve) => setTimeout(resolve, 10))
52
+ }
53
+
54
+ test('/progress-union/goal pause:落 paused 并撤掉排队中的续轮', async () => {
55
+ const h = await booted()
56
+ await update(h, [{ title: 't1', status: 'doing' }])
57
+ await goalCmd(h, '目标P')
58
+ assert.equal(h.agent.followups.length, 1)
59
+ assert.equal(h.inbox.nextTurn.length, 1, '第 1 轮应先排进 inbox')
60
+
61
+ const { status, body } = await goalControl(h, 'pause')
62
+ assert.equal(status, 200)
63
+ assert.equal(body.ok, true)
64
+ assert.equal(body.goal.phase, 'paused')
65
+ assert.equal(body.goal.activation, 'disarmed')
66
+ assert.equal(h.inbox.nextTurn.length, 0, '暂停必须撤回已排队的续轮,不能暂停后偷偷再跑一轮')
67
+
68
+ await idle(h)
69
+ assert.equal(h.agent.followups.length, 1, '暂停后 idle 边沿不得再派发')
70
+ })
71
+
72
+ test('/progress-union/goal resume:重新武装并立刻派发下一轮(主动继续)', async () => {
73
+ const h = await booted()
74
+ await update(h, [{ title: 't1', status: 'doing' }])
75
+ await goalCmd(h, '目标Q')
76
+ h.claim(h.agent.followups[0]) // 第 1 轮跑掉
77
+ await goalControl(h, 'pause')
78
+
79
+ const before = h.agent.followups.length
80
+ const { status, body } = await goalControl(h, 'resume')
81
+ await flush()
82
+ await flush()
83
+ assert.equal(status, 200)
84
+ assert.equal(body.ok, true)
85
+ assert.equal(body.goal.phase, 'active')
86
+ assert.equal(body.goal.activation, 'armed')
87
+ assert.equal(h.agent.followups.length, before + 1, 'resume 必须立刻点火,而不是等用户再发一条消息')
88
+ const round = h.agent.followups[h.agent.followups.length - 1]
89
+ assert.equal(round.source.round, 2)
90
+ assert.equal(h.inbox.nextTurn.length, 1)
91
+ })
92
+
93
+ test('resume 后回合收尾能继续推进(恢复的是循环,不是一次性)', async () => {
94
+ const h = await booted()
95
+ await update(h, [{ title: 't1', status: 'doing' }])
96
+ await goalCmd(h, '目标R')
97
+ h.claim(h.agent.followups[0])
98
+ await goalControl(h, 'pause')
99
+ await goalControl(h, 'resume')
100
+ const queued = h.claim(h.inbox.nextTurn[0])
101
+ assert.ok(queued)
102
+
103
+ const hook = h.agentHooks.find((x) => x.type === 'agent/pre-step')
104
+ const decision = await hook.handler(
105
+ { turn: 1, step: 1, messages: [queued] },
106
+ async () => ({ kind: 'enter', messages: [queued] }),
107
+ )
108
+ assert.equal(decision.kind, 'enter', '恢复后的轮次必须被身份栅栏放行')
109
+ await idle(h)
110
+ assert.equal(h.agent.followups.length, 3, '回合收尾后应继续派发下一轮')
111
+ })
112
+
113
+ test('/progress-union/goal status:只读回声,不改状态', async () => {
114
+ const h = await booted()
115
+ await update(h, [{ title: 't1', status: 'doing' }])
116
+ await goalCmd(h, '目标S')
117
+ const { status, body } = await goalControl(h, 'status')
118
+ assert.equal(status, 200)
119
+ assert.equal(body.goal.phase, 'active')
120
+ assert.equal(body.goal.objective, '目标S')
121
+ assert.equal(h.inbox.nextTurn.length, 1, 'status 不得动 inbox')
122
+ })
123
+
124
+ test('非法 action / 缺 sessionId → 400', async () => {
125
+ const h = await booted()
126
+ await goalCmd(h, '目标T')
127
+ let r = await goalControl(h, 'explode')
128
+ assert.equal(r.status, 400)
129
+ assert.match(String(r.body.error), /pause\/resume\/status/)
130
+ r = await goalControl(h, 'pause', '')
131
+ assert.equal(r.status, 400)
132
+ assert.match(String(r.body.error), /sessionId/)
133
+ })
134
+
135
+ test('暂停时回合正在跑:中断该回合', async () => {
136
+ const h = await booted()
137
+ await update(h, [{ title: 't1', status: 'doing' }])
138
+ await goalCmd(h, '目标U')
139
+ h.agent.status = 'running'
140
+ let cancelled = null
141
+ h.agent.cancel = (cause, options) => { cancelled = { cause, options } }
142
+ const { body } = await goalControl(h, 'pause')
143
+ assert.equal(body.goal.phase, 'paused')
144
+ assert.ok(cancelled, '暂停必须中断运行中的回合')
145
+ assert.equal(cancelled.options.keepInbox, true, '中断保留用户排队消息,别把用户输入一起丢了')
146
+ h.agent.status = 'idle'
147
+ })
@@ -0,0 +1,232 @@
1
+ /**
2
+ * /progress-goal 自动续轮驱动器验收(回归 session-3353b1ac 的「设了目标却不续轮」):
3
+ * - 建目标即点火,经 agent.followup 派发一轮带自有 source 的续轮消息;
4
+ * - 回合收尾(agent/status idle)→ 派发下一轮;同轮未消费时不得连排两轮;
5
+ * - pre-step 身份栅栏:自己派发/重启遗留的轮次放行,伪造轮次丢弃;
6
+ * - 重启自愈:进程重启后内存 attempt 丢失,排队中的一轮仍能被收养(不静默丢);
7
+ * - 重启自愈:armed 目标在会话重新挂载时补点火,不依赖用户再发一条消息;
8
+ * - 预算到顶转 blocked;官方目标 active 时让路。
9
+ */
10
+ import assert from 'node:assert/strict'
11
+ import fs from 'node:fs'
12
+ import os from 'node:os'
13
+ import path from 'node:path'
14
+ import test from 'node:test'
15
+
16
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-goal-drive-'))
17
+ const { SESSION, createHarness, jsonReq, callRoute, flush } = await import('./harness.mjs')
18
+
19
+ const GOAL_SOURCE_KIND = 'plugin:progress-goal-goal'
20
+
21
+ async function booted(config = {}, options = {}) {
22
+ const harness = createHarness({ config, ...options })
23
+ await harness.run()
24
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
25
+ return harness
26
+ }
27
+
28
+ function cmd(harness, input) {
29
+ return harness.commandMap.get('progress-goal').handler({ agent: harness.agent, rawInput: input })
30
+ }
31
+
32
+ /** 命令里的点火是 fire-and-forget 的异步派发:等它落完再断言。 */
33
+ async function goalCmd(harness, input) {
34
+ const result = await cmd(harness, input)
35
+ await flush()
36
+ await flush()
37
+ return result
38
+ }
39
+
40
+ function update(harness, changes) {
41
+ return harness.toolMap.get('progress_update').definition.execute({ changes }, { agent: harness.agent })
42
+ }
43
+
44
+ /** 宿主在回合收尾时把 agent 状态翻到 idle;插件在该边沿派发下一轮。 */
45
+ async function idle(harness) {
46
+ for (const listener of harness.listeners.filter((l) => l.type === 'agent/status')) {
47
+ listener.handler({ agent: harness.agent, status: 'idle' })
48
+ }
49
+ await flush()
50
+ await new Promise((resolve) => setTimeout(resolve, 10))
51
+ }
52
+
53
+ async function snapshotOf(harness) {
54
+ const res = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })
55
+ return res.json()
56
+ }
57
+
58
+ async function preStep(harness, message) {
59
+ const hook = harness.agentHooks.find((h) => h.type === 'agent/pre-step')
60
+ assert.ok(hook, 'pre-step hook 必须已安装')
61
+ return hook.handler(
62
+ { turn: 1, step: 1, messages: [message] },
63
+ async () => ({ kind: 'enter', messages: [message] }),
64
+ )
65
+ }
66
+
67
+ /** 模拟一次完整回合:take 走排队消息 → pre-step 认领 → 回合收尾 → idle 边沿。 */
68
+ async function runTurn(harness) {
69
+ const message = harness.claim(harness.inbox.nextTurn[0])
70
+ assert.ok(message, '应当有一轮排队中的续轮消息')
71
+ const decision = await preStep(harness, message)
72
+ assert.equal(decision.kind, 'enter')
73
+ await idle(harness)
74
+ return message
75
+ }
76
+
77
+ test('建目标即点火:立刻派发第 1 轮并落盘 roundsStarted=1', async () => {
78
+ const h = await booted()
79
+ await update(h, [{ title: 't1', status: 'doing', percent: 40 }])
80
+ await goalCmd(h, '把活干完')
81
+
82
+ assert.equal(h.agent.followups.length, 1, '建目标必须立刻点火,不能等用户再发一条消息')
83
+ const message = h.agent.followups[0]
84
+ assert.equal(message.role, 'user')
85
+ assert.equal(message.source.kind, GOAL_SOURCE_KIND)
86
+ assert.equal(message.source.round, 1)
87
+ assert.equal(typeof message.source.goalId, 'string')
88
+ assert.match(message.content[0].text, /<progress_goal_round>/)
89
+ assert.match(message.content[0].text, /Objective: "把活干完"/)
90
+ assert.match(message.content[0].text, /Round: 1\/256/)
91
+ assert.match(message.content[0].text, /progress_goal_report/)
92
+
93
+ const snap = await snapshotOf(h)
94
+ assert.equal(snap.goal.roundsStarted, 1, '轮次计数必须落盘,避免重复派发')
95
+ assert.equal(snap.goal.phase, 'active')
96
+ })
97
+
98
+ test('回合收尾派发下一轮;同一轮未消费时不得连排两轮', async () => {
99
+ const h = await booted()
100
+ await update(h, [{ title: 't1', status: 'doing' }])
101
+ await goalCmd(h, '目标A')
102
+
103
+ // 第 1 轮还排在 inbox 里(没被取走)→ idle 边沿不得再排一轮
104
+ await idle(h)
105
+ assert.equal(h.agent.followups.length, 1, '同轮未消费时连排两轮会白烧预算')
106
+
107
+ await runTurn(h)
108
+ assert.equal(h.agent.followups.length, 2, '回合收尾后应派发第 2 轮')
109
+ assert.equal(h.agent.followups[1].source.round, 2)
110
+ const snap = await snapshotOf(h)
111
+ assert.equal(snap.goal.roundsStarted, 2)
112
+ })
113
+
114
+ test('没有目标时 idle 不派发、不抛错', async () => {
115
+ const h = await booted()
116
+ await idle(h)
117
+ assert.equal(h.agent.followups.length, 0)
118
+ })
119
+
120
+ test('pre-step 身份栅栏:自己的轮次放行,伪造轮次只丢这一条', async () => {
121
+ const h = await booted()
122
+ await update(h, [{ title: 't1', status: 'doing' }])
123
+ await goalCmd(h, '目标X')
124
+
125
+ const message = h.claim(h.agent.followups[0])
126
+ const decision = await preStep(h, message)
127
+ assert.equal(decision.kind, 'enter', '插件自己派发的轮次必须放行')
128
+
129
+ // 伪造:轮次号对不上当前 roundsStarted
130
+ const forged = { ...message, id: 'forged', source: { ...message.source, round: 99 } }
131
+ const rejected = await preStep(h, forged)
132
+ assert.equal(rejected.kind, 'reject')
133
+ })
134
+
135
+ test('孤儿轮次只丢自己:同一步里的用户消息不能被连坐 reject', async () => {
136
+ const h = await booted()
137
+ await update(h, [{ title: 't1', status: 'doing' }])
138
+ await goalCmd(h, '目标O')
139
+ const stale = h.claim(h.agent.followups[0])
140
+ const forged = { ...stale, id: 'stale-round', source: { ...stale.source, round: 42 } }
141
+ const user = { id: 'u-1', role: 'user', content: [{ type: 'text', text: '我自己的话' }], source: { kind: 'user' } }
142
+
143
+ const hook = h.agentHooks.find((x) => x.type === 'agent/pre-step')
144
+ const decision = await hook.handler(
145
+ { turn: 1, step: 1, messages: [user, forged] },
146
+ async () => ({ kind: 'enter', messages: [user, forged] }),
147
+ )
148
+ assert.equal(decision.kind, 'enter')
149
+ assert.deepEqual(decision.messages.map((m) => m.id), ['u-1'], '用户消息必须留下,孤儿轮次被摘掉')
150
+ })
151
+
152
+ test('重启自愈:内存 attempt 丢失后,排队中的一轮被收养而不是静默丢弃', async () => {
153
+ const h = await booted()
154
+ await update(h, [{ title: 't1', status: 'doing' }])
155
+ await goalCmd(h, '目标R')
156
+ const message = h.agent.followups[0]
157
+
158
+ // 用同一份持久化记录重开宿主 = 重启;内存 attempt 必然为空。
159
+ const restarted = await booted({}, { seed: h.records })
160
+ restarted.agent.inbox.nextTurn.push(message)
161
+ const decision = await preStep(restarted, message)
162
+ assert.equal(decision.kind, 'enter', '重启后排队中的一轮必须被收养,否则白烧一轮预算')
163
+ })
164
+
165
+ test('重启自愈:armed 目标在会话重新挂载时自动补点火(无需用户先发消息)', async () => {
166
+ const h = await booted()
167
+ await update(h, [{ title: 't1', status: 'doing' }])
168
+ await goalCmd(h, '目标K')
169
+ h.claim(h.agent.followups[0]) // 上一轮已被消费掉,inbox 空;模拟崩在回合收尾前
170
+
171
+ const restarted = await booted({}, { seed: h.records })
172
+ assert.equal(restarted.agent.followups.length, 0)
173
+ // 重挂载的点火有 2.5s 抖动窗口(等宿主把回合基础设施铺好)
174
+ await new Promise((resolve) => setTimeout(resolve, 2800))
175
+ assert.equal(restarted.agent.followups.length, 1, '重启后必须自己续上,不能等用户说话')
176
+ assert.equal(restarted.agent.followups[0].source.round, 2)
177
+ })
178
+
179
+ test('重启自愈:上一次进程遗留的排队轮次被清掉并重排(否则它既不跑又挡新轮)', async () => {
180
+ const h = await booted()
181
+ await update(h, [{ title: 't1', status: 'doing' }])
182
+ await goalCmd(h, '目标S')
183
+ const stranded = h.claim(h.agent.followups[0]) // 崩在「已排队、未执行」之间
184
+
185
+ // 用同一份持久化记录重开宿主:attempt 空,但 inbox 里还留着上一轮
186
+ const restarted = await booted({}, { seed: h.records })
187
+ restarted.agent.inbox.nextTurn.push(stranded)
188
+ await new Promise((resolve) => setTimeout(resolve, 2800))
189
+
190
+ assert.equal(restarted.agent.followups.length, 1, '重启后必须重排一轮')
191
+ assert.equal(restarted.agent.inbox.nextTurn.includes(stranded), false, '孤儿轮次必须被撤掉')
192
+ assert.equal(restarted.agent.inbox.nextTurn.length, 1)
193
+ assert.notEqual(restarted.agent.inbox.nextTurn[0].id, stranded.id)
194
+ })
195
+
196
+ test('resume 接受 active:重新武装 + 点火', async () => {
197
+ const h = await booted()
198
+ await update(h, [{ title: 't1', status: 'doing' }])
199
+ await goalCmd(h, '目标M')
200
+ h.claim(h.agent.followups[0])
201
+ await idle(h)
202
+
203
+ const before = h.agent.followups.length
204
+ const text = (await goalCmd(h, 'resume')).text
205
+ assert.match(text, /Status: active/)
206
+ assert.match(text, /Activation: armed/)
207
+ assert.ok(h.agent.followups.length >= before, 'resume 必须至少不倒退')
208
+ const snap = await snapshotOf(h)
209
+ assert.equal(snap.goal.activation, 'armed')
210
+ })
211
+
212
+ test('预算到顶转 blocked,不再派发', async () => {
213
+ const h = await booted()
214
+ await update(h, [{ title: 't1', status: 'doing' }])
215
+ await goalCmd(h, '目标Y')
216
+ await goalCmd(h, 'budget 1')
217
+
218
+ await runTurn(h) // round 1 用完,回合收尾 → 预算已到顶
219
+ assert.equal(h.agent.followups.length, 1, '预算用尽后不得再派发')
220
+ const snap = await snapshotOf(h)
221
+ assert.equal(snap.goal.phase, 'blocked')
222
+ assert.match(snap.goal.blockedReason, /预算上限 1 轮/)
223
+ })
224
+
225
+ test('官方目标 active 时让路:不排队', async () => {
226
+ const h = await booted()
227
+ await update(h, [{ title: 't1', status: 'doing' }])
228
+ const original = h.ctx.get.bind(h.ctx)
229
+ h.ctx.get = (name) => (name === 'goals' ? { get: () => ({ phase: 'active', activation: 'armed' }) } : original(name))
230
+ await goalCmd(h, '目标Z')
231
+ assert.equal(h.agent.followups.length, 0, '官方目标在跑时不得抢轮')
232
+ })
@@ -38,10 +38,11 @@ test('create/status/budget/pause/resume/clear 全命令链', async () => {
38
38
  let r = await cmd(h, '把插件改完并测试')
39
39
  assert.equal(r.kind, 'success')
40
40
  assert.match(r.text, /Status: active/)
41
- assert.match(r.text, /Rounds: 0\/256/)
41
+ // v0.5.3:建目标即点火派发第 1 轮,轮次计数立刻为 1(旧版要等下一次回合收尾才动)。
42
+ assert.match(r.text, /Rounds: 1\/256/)
42
43
 
43
44
  r = await cmd(h, 'budget 3')
44
- assert.match(r.text, /Rounds: 0\/3/)
45
+ assert.match(r.text, /Rounds: 1\/3/)
45
46
 
46
47
  r = await cmd(h, 'status')
47
48
  assert.match(r.text, /Objective: "把插件改完并测试"/)
package/test/harness.mjs CHANGED
@@ -61,8 +61,29 @@ export function createHarness({ seed = {}, config = {}, withProjection = true, w
61
61
  const systemPrompt = {}
62
62
 
63
63
  const appends = []
64
+ const followups = []
65
+ // 宿主 inbox 形状(durable projection):followup 排进 nextTurn,被取走才算消费。
66
+ // 驱动器靠它判断「已有一轮还没跑」,避免补点火与 idle 边沿撞车连排两轮。
67
+ const nextTurn = []
68
+ const nextStep = []
64
69
  const agent = {
65
70
  id: SESSION,
71
+ status: 'idle',
72
+ inbox: {
73
+ nextTurn,
74
+ nextStep,
75
+ // 宿主 Inbox 契约:撤回一条排队消息(驱动器用它在重启清理孤儿轮次)。
76
+ remove(id) {
77
+ for (const list of [nextTurn, nextStep]) {
78
+ const i = list.findIndex((m) => m && m.id === id)
79
+ if (i >= 0) { list.splice(i, 1); return true }
80
+ }
81
+ return false
82
+ },
83
+ },
84
+ // /progress-goal 续轮驱动器经 agent.followup 排队;这里记录被派发的轮次消息。
85
+ followups,
86
+ followup(message) { followups.push(message); nextTurn.push(message) },
66
87
  // v0.3.0:todo 镜像写通道。默认记录调用;测试可覆写 append 注入失败。
67
88
  // v0.5.0:cwd 放在 session **顶层**(实测 shape,不是 header.cwd)——plan 扫描靠它。
68
89
  session: {
@@ -140,6 +161,8 @@ export function createHarness({ seed = {}, config = {}, withProjection = true, w
140
161
  config,
141
162
  agent,
142
163
  appends,
164
+ followups,
165
+ inbox: agent.inbox,
143
166
  records,
144
167
  routes,
145
168
  toolMap,
@@ -151,6 +174,12 @@ export function createHarness({ seed = {}, config = {}, withProjection = true, w
151
174
  provided,
152
175
  projections,
153
176
  run: () => apply(ctx, config),
177
+ /** 模拟宿主 claim:把一条排队消息从 nextTurn 取走(consume=true 才算消费)。 */
178
+ claim(message) {
179
+ const i = nextTurn.indexOf(message)
180
+ if (i >= 0) nextTurn.splice(i, 1)
181
+ return message
182
+ },
154
183
  /** 按 (session, {type, data}) 派发一条 session/event */
155
184
  emit(type, data, session) {
156
185
  // 默认 session 带顶层 cwd(实测 shape):plan 扫描靠事件流里的 session。
@@ -0,0 +1,65 @@
1
+ /**
2
+ * 窄栏布局回归:进度板副标题在 335px 侧栏里不得被按钮挤成竖排。
3
+ * 起因:截图里 .pb-side-head 是 flex 行,左侧标题+副标题块与三个按钮同行,
4
+ * 按钮 flex:none 把文字列压到约 8em,中文说明被折成每列 2~3 字。
5
+ * 契约:副标题必须是按钮下方独占整行的块,可用宽度接近整个面板内容宽度。
6
+ */
7
+ import { test } from 'node:test'
8
+ import assert from 'node:assert/strict'
9
+ import { readFileSync } from 'node:fs'
10
+ import { fileURLToPath } from 'node:url'
11
+
12
+ const root = fileURLToPath(new URL('..', import.meta.url))
13
+ const client = readFileSync(root + 'client.js', 'utf8')
14
+
15
+ function rule(selector) {
16
+ const i = client.indexOf(selector + ' {')
17
+ assert.notEqual(i, -1, `样式里找不到规则:${selector}`)
18
+ return client.slice(i, client.indexOf('}', i))
19
+ }
20
+
21
+ test('副标题是 pb-side-head 的兄弟节点,不再嵌在左侧标题块里', () => {
22
+ // 重构后:head 内有 h2 + actions,随后紧跟独立的 <p class="pb-side-sub">
23
+ const headMarker = "{ className: 'pb-side-head' }"
24
+ const headPos = client.indexOf(headMarker)
25
+ assert.notEqual(headPos, -1, '找不到 pb-side-head 渲染块')
26
+ // pb-side-head 的收尾:actions 的 ) 之后是 head div 的 ), 再下一行是副标题 <p>
27
+ const subPos = client.indexOf("h('p', { className: 'pb-side-sub' }", headPos)
28
+ assert.notEqual(subPos, -1, '副标题应渲染在 pb-side-head 之后,作为独占一行的兄弟节点')
29
+ const headBlock = client.slice(headPos, subPos)
30
+ assert.equal(headBlock.includes("className: 'pb-side-sub'"), false,
31
+ 'pb-side-head 内部不得再包含副标题(否则仍与按钮同行被挤压)')
32
+ // 副标题紧邻 head 结束(中间只有 actions 的闭合括号),确认不是嵌在别的容器里
33
+ const gap = headBlock.slice(headBlock.lastIndexOf('),'))
34
+ assert.ok(gap.length < 40, `副标题应紧跟 head 容器收尾,实际间隔:${JSON.stringify(gap)}`)
35
+ })
36
+
37
+ test('pb-side-head 只是标题+按钮的一行,副标题样式整行可用', () => {
38
+ const head = rule('.pb-side-head')
39
+ assert.match(head, /display:\s*flex/, 'header 仍是 flex 行')
40
+ assert.equal(/pb-side-sub/.test(head), false)
41
+
42
+ const sub = rule('.pb-side-sub')
43
+ assert.match(sub, /max-width:\s*none/, '副标题不得有窄 max-width 限制')
44
+ assert.match(sub, /margin:\s*[^;]*14px/, '副标题自带下边距,取代旧 head 的 margin-bottom')
45
+ })
46
+
47
+ test('窄栏几何:335px 面板里副标题可用宽度 >= 元素宽度的 90%', () => {
48
+ // 复现截图 335px 面板(左右各 14px padding + 2px 边框),按钮组约 168px。
49
+ // 旧布局:副标题在左侧块内 => 可用宽 ≈ 305 - 168 - 8 ≈ 129px(≈ 竖排 2-3 字)。
50
+ // 新布局:副标题独占一行 => 可用宽 = 305px(按钮下方也能铺文字)。
51
+ const panel = 335
52
+ const padding = 14 * 2
53
+ const borders = 2
54
+ const inner = panel - padding - borders // 293
55
+ const buttons = 168 // Agent 更新:开 + 全面展开 + 收起,实测约 56+52+40 + gaps
56
+ const oldWidth = inner - buttons - 8
57
+ const newWidth = inner
58
+ assert.ok(oldWidth < inner * 0.5, `旧布局应明显受限,实测 ${oldWidth}px`)
59
+ assert.ok(newWidth >= inner * 0.9, `新副标题应占满整行,实测 ${newWidth}px`)
60
+ // 中文 11px 字约 11px 宽 => 293px 一行约可放 24+ 字;旧布局只能 10 字左右。
61
+ const charsPerLineNew = Math.floor(newWidth / 11)
62
+ const charsPerLineOld = Math.floor(oldWidth / 11)
63
+ assert.ok(charsPerLineNew >= charsPerLineOld * 2,
64
+ '副标题每行可容纳字数应至少翻倍,才不会被挤成竖排')
65
+ })