dsh-project-flow 0.8.3 → 0.9.1

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 (75) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/README.md +166 -358
  3. package/bench/corpus/qa-fail-3-issues.md +33 -0
  4. package/bench/corpus/qa-fail-assertion.md +20 -0
  5. package/bench/corpus/qa-fail-missing-detect.md +21 -0
  6. package/bench/corpus/qa-pass.md +9 -0
  7. package/bench/corpus/qa-reverify-partial.md +30 -0
  8. package/bench/corpus/qa-unverified-only.md +15 -0
  9. package/bench/corpus/requirement-no-check.md +8 -0
  10. package/bench/corpus/requirement-with-check.md +16 -0
  11. package/bench/corpus/reverify-table-not-defects.md +18 -0
  12. package/bench/run.mjs +142 -0
  13. package/client.js +195 -9
  14. package/cordis.patch.yml +29 -9
  15. package/docs/CHECKS.md +100 -0
  16. package/docs/DETAIL.md +6 -6
  17. package/docs/FEATURES.md +12 -5
  18. package/docs/ISSUES.md +75 -0
  19. package/docs/LAUNCH.md +3 -3
  20. package/docs/LEDGER.md +46 -0
  21. package/docs/MOMENTS.md +4 -4
  22. package/docs/USAGE.md +2 -2
  23. package/docs/adr/0001-four-stage-isolation.md +25 -0
  24. package/docs/adr/0002-file-handoff-not-context.md +27 -0
  25. package/docs/adr/0003-diff-over-self-report.md +27 -0
  26. package/docs/adr/0004-issue-level-rework.md +30 -0
  27. package/docs/adr/0005-assertion-over-prose.md +30 -0
  28. package/docs/anchors/assertion-exec.md +39 -0
  29. package/docs/anchors/cost-accounting.md +44 -0
  30. package/docs/anchors/diff-reconciliation.md +35 -0
  31. package/docs/anchors/file-whitelist.md +29 -0
  32. package/docs/anchors/intent-gate.md +41 -0
  33. package/docs/anchors/issue-loop.md +40 -0
  34. package/docs/anchors/patch-ledger.md +38 -0
  35. package/docs/anchors/watchdog.md +30 -0
  36. package/domains.mjs +1 -1
  37. package/evidence.mjs +19 -3
  38. package/flow.schema.mjs +600 -0
  39. package/gate.mjs +49 -23
  40. package/index.js +2800 -134
  41. package/locale/en.json +15 -4
  42. package/locale/zh.json +17 -6
  43. package/package.json +11 -2
  44. package/tests/_heartbeat-regression.test.mjs +124 -0
  45. package/tests/_wd_sandbox/.project-flow/demo/run.log +1 -0
  46. package/tests/_wd_sandbox/a.txt +1 -0
  47. package/tests/aesthetic.test.mjs +534 -0
  48. package/tests/assertions-e2e.mjs +234 -0
  49. package/tests/bench-check.mjs +32 -0
  50. package/tests/client-bundle.test.mjs +707 -0
  51. package/tests/contract.test.mjs +137 -0
  52. package/tests/desktop.test.mjs +130 -0
  53. package/tests/domains.test.mjs +220 -0
  54. package/tests/e2e.mjs +300 -0
  55. package/tests/evidence.test.mjs +408 -0
  56. package/tests/extra-phase.test.mjs +133 -0
  57. package/tests/feedback.test.mjs +187 -0
  58. package/tests/flow-create.test.mjs +168 -0
  59. package/tests/flow-gate.test.mjs +232 -0
  60. package/tests/flow-schema.test.mjs +213 -0
  61. package/tests/gate.test.mjs +246 -0
  62. package/tests/issue-loop.test.mjs +254 -0
  63. package/tests/issues-e2e.mjs +246 -0
  64. package/tests/panel-independence.test.mjs +78 -0
  65. package/tests/panel-report.test.mjs +129 -0
  66. package/tests/patch-ledger.test.mjs +280 -0
  67. package/tests/paths.mjs +94 -0
  68. package/tests/preview-path.test.mjs +69 -0
  69. package/tests/qa-assertions.test.mjs +352 -0
  70. package/tests/run-all.mjs +90 -0
  71. package/tests/stage-model.test.mjs +120 -0
  72. package/tests/stop-resume.test.mjs +260 -0
  73. package/tests/watch-root.test.mjs +167 -0
  74. package/tests/watchdog-tokens.test.mjs +49 -0
  75. package/tests/watchdog.test.mjs +301 -0
@@ -0,0 +1,33 @@
1
+ ---
2
+ verdict: "FAIL"
3
+ round: 1
4
+ issues:
5
+ - id: Q-001
6
+ severity: P0
7
+ location: src/foo.ts:88
8
+ claim: 任务书要求支持引号内的逗号,实际直接按逗号切了
9
+ evidence: 见 diff 第 88 行
10
+ detect: node --test test/csv.test.js
11
+ pass: 引号内逗号不被切开
12
+ status: open
13
+ - id: Q-002
14
+ severity: P1
15
+ location: 缺失:README.md 的用法一节
16
+ claim: 任务书要求写用法,实际没写
17
+ evidence: README 只有一句标题
18
+ detect: node -e "process.exit(require('fs').readFileSync('README.md','utf8').includes('用法')?0:1)"
19
+ pass: README 里能找到「用法」
20
+ status: open
21
+ - id: Q-003
22
+ severity: P2
23
+ location: src/foo.ts:12
24
+ claim: 函数名和任务书里写的不一致,调用方会找不到
25
+ evidence: 任务书写 toMarkdown,实现是 convert
26
+ detect: npm run lint
27
+ pass: 没有命名相关的报错
28
+ status: open
29
+ ---
30
+
31
+ # 质检结论:FAIL
32
+
33
+ 三条,都不影响构建,但都不是任务书要的样子。
@@ -0,0 +1,20 @@
1
+ ---
2
+ verdict: "FAIL(断言未过 1 条)"
3
+ round: 1
4
+ assertions:
5
+ - req: 1
6
+ cmd: "node --test test/csv.test.js"
7
+ exit: 1
8
+ durationMs: 63
9
+ status: fail
10
+ - req: 2
11
+ cmd: "npm run lint"
12
+ exit: 0
13
+ durationMs: 1200
14
+ status: pass
15
+ issues: []
16
+ ---
17
+
18
+ # 质检结论:FAIL(断言未过 1 条)
19
+
20
+ 第 1 条要求的测试没通过。模型说什么都不算。
@@ -0,0 +1,21 @@
1
+ ---
2
+ verdict: "FAIL"
3
+ round: 1
4
+ issues:
5
+ - id: Q-001
6
+ severity: P0
7
+ location: src/foo.ts:88
8
+ claim: 有检测命令的一条
9
+ detect: node --test test/csv.test.js
10
+ pass: 全部通过
11
+ status: open
12
+ - id: Q-002
13
+ severity: P1
14
+ location: src/bar.ts:10
15
+ claim: 这条没有检测命令——等于没定义,数得出来
16
+ status: open
17
+ ---
18
+
19
+ # 质检结论:FAIL
20
+
21
+ Q-002 缺 detect,这一轮该报「问题缺少可执行定义」。
@@ -0,0 +1,9 @@
1
+ ---
2
+ verdict: "PASS"
3
+ round: 1
4
+ issues: []
5
+ ---
6
+
7
+ # 质检结论:PASS
8
+
9
+ 三条要求逐条核过,实现和任务书对得上。没有未闭环的问题。
@@ -0,0 +1,30 @@
1
+ ---
2
+ verdict: "FAIL"
3
+ round: 2
4
+ issues:
5
+ - id: Q-001
6
+ severity: P0
7
+ location: src/foo.ts:88
8
+ claim: 任务书要求支持引号内的逗号,实际直接按逗号切了
9
+ detect: node --test test/csv.test.js
10
+ pass: 引号内逗号不被切开
11
+ status: open
12
+ - id: Q-002
13
+ severity: P1
14
+ location: README.md
15
+ claim: 任务书要求写用法,实际没写
16
+ detect: npm run lint
17
+ pass: README 里能找到「用法」
18
+ status: closed
19
+ - id: Q-003
20
+ severity: P2
21
+ location: src/foo.ts:12
22
+ claim: 函数名和任务书里写的不一致
23
+ detect: npm run lint
24
+ pass: 没有命名相关的报错
25
+ status: open
26
+ ---
27
+
28
+ # 质检结论:FAIL(第 2 轮)
29
+
30
+ Q-002 关了。Q-001 还在,Q-003 还在。
@@ -0,0 +1,15 @@
1
+ ---
2
+ verdict: "UNVERIFIED"
3
+ round: 1
4
+ assertions:
5
+ - req: 1
6
+ cmd: ""
7
+ exit: null
8
+ durationMs: 0
9
+ status: unverified
10
+ issues: []
11
+ ---
12
+
13
+ # 质检结论
14
+
15
+ 这条要求没有判据,判不了。判不了不等于判过了。
@@ -0,0 +1,8 @@
1
+ # 需求
2
+
3
+ ## 用户要求
4
+
5
+ 1. 把首页的标题改短
6
+ 2. 颜色换成深一点的蓝
7
+
8
+ 这两条都没法写成命令,所以没有判据。判据没启用,走老路。
@@ -0,0 +1,16 @@
1
+ ---
2
+ checks:
3
+ - req: 1
4
+ cmd: "node --test test/csv.test.js"
5
+ exit: 0
6
+ - req: 2
7
+ cmd: "npm run lint"
8
+ exit: 0
9
+ ---
10
+
11
+ # 需求
12
+
13
+ ## 用户要求
14
+
15
+ 1. CSV 转 Markdown 表格,引号内的逗号不算分隔
16
+ 2. 代码要过 lint
@@ -0,0 +1,18 @@
1
+ ---
2
+ verdict: "FAIL"
3
+ round: 3
4
+ issues: []
5
+ ---
6
+
7
+ # 质检结论:FAIL
8
+
9
+ 下面是复验对照表,不是缺陷清单。逐条对上轮的问题复核了一遍:
10
+
11
+ | 编号 | 上轮问题 | 本轮结果 |
12
+ | --- | --- | --- |
13
+ | Q-001 | 引号内逗号 | 已修,测试通过 |
14
+ | Q-002 | 缺用法 | 已修 |
15
+ | Q-003 | 函数名 | 已修 |
16
+
17
+ 三条都闭环了。这一轮 FAIL 的原因是另一件事:导出格式和任务书要求的文件名对不上,
18
+ 那件事在正文里写着,不在问题清单里。
package/bench/run.mjs ADDED
@@ -0,0 +1,142 @@
1
+ /**
2
+ * 回归语料跑一遍。
3
+ *
4
+ * 目的只有一个:改四阶逻辑之后,知道哪些判定变了。以前靠手动造场景,
5
+ * 改一处不知道碰坏别处——现在一条命令给结论。
6
+ *
7
+ * 用法:
8
+ * node bench/run.mjs 跑全部
9
+ * node bench/run.mjs qa- 只跑文件名含 qa- 的
10
+ *
11
+ * 任何一条不过就非零退出。输出是 {case, expected, actual, pass} 一行一条。
12
+ */
13
+ import { readFile, readdir } from 'node:fs/promises'
14
+ import { join, dirname } from 'node:path'
15
+ import { fileURLToPath, pathToFileURL } from 'node:url'
16
+
17
+ const HERE = dirname(fileURLToPath(import.meta.url))
18
+ const CORPUS = join(HERE, 'corpus')
19
+ const PLUGIN = process.env.PF_LIVE_DIR ?? join(HERE, '..')
20
+
21
+ const mod = await import(pathToFileURL(join(PLUGIN, 'index.js')).href + `?t=${Date.now()}`)
22
+ const { parseIssueBlock, parseRequirementChecks, parseAssertionBlock, gateAssertions } = mod
23
+
24
+ const openOf = issues => issues.filter(item => item.status === 'open' || item.status === 'reopened')
25
+ const closedOf = issues => issues.filter(item => item.status === 'closed')
26
+
27
+ /**
28
+ * 每个语料喂给哪个判定、期望什么。
29
+ *
30
+ * 名字就是断言——看文件名叫得出这条在防什么。加语料只要往这儿补一行,
31
+ * 不用改判定逻辑:判定逻辑改了,这一跑就告诉你哪条变了。
32
+ */
33
+ const CASES = [
34
+ // ── PASS/FAIL 判定 ──
35
+ {
36
+ file: 'qa-pass.md',
37
+ why: '一份干净的 PASS 报告,不该读出任何问题',
38
+ judge: text => ({ open: openOf(parseIssueBlock(text)).length }),
39
+ expect: { open: 0 },
40
+ },
41
+ {
42
+ file: 'qa-fail-3-issues.md',
43
+ why: '判 FAIL 且正好三条问题,编号要连号',
44
+ judge: text => {
45
+ const open = openOf(parseIssueBlock(text))
46
+ return { open: open.length, ids: open.map(item => item.id).join(',') }
47
+ },
48
+ expect: { open: 3, ids: 'Q-001,Q-002,Q-003' },
49
+ },
50
+ {
51
+ file: 'qa-reverify-partial.md',
52
+ why: '复验轮:一条关单两条还开着,编号不能重排',
53
+ judge: text => {
54
+ const all = parseIssueBlock(text)
55
+ return { open: openOf(all).length, closed: closedOf(all).length, ids: openOf(all).map(i => i.id).join(',') }
56
+ },
57
+ expect: { open: 2, closed: 1, ids: 'Q-001,Q-003' },
58
+ },
59
+
60
+ // ── 问题开关单 ──
61
+ {
62
+ file: 'qa-fail-missing-detect.md',
63
+ why: '有一条问题缺 detect,必须数出来——没有检测命令的缺陷等于没定义',
64
+ judge: text => {
65
+ const open = openOf(parseIssueBlock(text))
66
+ return { missingDetect: open.filter(item => typeof item.detect !== 'string' || item.detect.trim() === '').length }
67
+ },
68
+ expect: { missingDetect: 1 },
69
+ },
70
+ {
71
+ file: 'reverify-table-not-defects.md',
72
+ why: '复验对照表只是表格,不是缺陷清单——整表必须判成「没有问题」',
73
+ judge: text => ({ open: openOf(parseIssueBlock(text)).length }),
74
+ expect: { open: 0 },
75
+ },
76
+
77
+ // ── 断言执行 ──
78
+ {
79
+ file: 'requirement-with-check.md',
80
+ why: '两条要求各带一条判据,都要读出来',
81
+ judge: text => {
82
+ const checks = parseRequirementChecks(text)
83
+ return { count: checks.length, reqs: checks.map(item => item.req).join(',') }
84
+ },
85
+ expect: { count: 2, reqs: '1,2' },
86
+ },
87
+ {
88
+ file: 'requirement-no-check.md',
89
+ why: '一条判据都没有,判据没启用,走老路',
90
+ judge: text => ({ count: parseRequirementChecks(text).length }),
91
+ expect: { count: 0 },
92
+ },
93
+ {
94
+ file: 'qa-fail-assertion.md',
95
+ why: '断言挂了,结论必须是 FAIL 而不是 PASS',
96
+ judge: text => {
97
+ const assertions = parseAssertionBlock(text)
98
+ // gateAssertions 返回的是对象(还带 failed/unverified 明细),不是一句话。
99
+ return { verdict: gateAssertions(assertions, 2).verdict, fail: assertions.filter(item => item.status === 'fail').length }
100
+ },
101
+ expect: { verdict: 'FAIL', fail: 1 },
102
+ },
103
+ {
104
+ file: 'qa-unverified-only.md',
105
+ why: '判不了不等于判过了:全是 unverified 时不许给 PASS',
106
+ judge: text => {
107
+ const assertions = parseAssertionBlock(text)
108
+ return { verdict: gateAssertions(assertions, 1).verdict }
109
+ },
110
+ expect: { verdict: 'UNVERIFIED' },
111
+ },
112
+ ]
113
+
114
+ const filter = process.argv[2] ?? ''
115
+ const only = CASES.filter(item => filter === '' || item.file.includes(filter))
116
+
117
+ let failed = 0
118
+ for (const item of only) {
119
+ let text
120
+ try {
121
+ text = await readFile(join(CORPUS, item.file), 'utf8')
122
+ } catch {
123
+ console.log(`✖ ${item.file} 语料文件不存在`)
124
+ failed += 1
125
+ continue
126
+ }
127
+ let actual
128
+ try {
129
+ actual = item.judge(text)
130
+ } catch (error) {
131
+ actual = { error: error.message }
132
+ }
133
+ const ok = Object.entries(item.expect).every(([key, want]) => actual[key] === want)
134
+ if (!ok) failed += 1
135
+ console.log(`${ok ? '✔' : '✖'} ${item.file}`)
136
+ console.log(` 期望 ${JSON.stringify(item.expect)}`)
137
+ console.log(` 实得 ${JSON.stringify(actual)}`)
138
+ if (!ok) console.log(` 这条防的是:${item.why}`)
139
+ }
140
+
141
+ console.log(`\n${only.length - failed}/${only.length} 通过`)
142
+ process.exit(failed === 0 ? 0 : 1)
package/client.js CHANGED
@@ -42,6 +42,26 @@ window.__ModuleLoader__.load({
42
42
  /** 能改模型的只有 2/3/4 阶;第 1 阶跑在主对话,插件改不了。 */
43
43
  const SWITCHABLE = [2, 3, 4]
44
44
 
45
+ /**
46
+ * 每一阶的门禁是什么。
47
+ *
48
+ * 写死在这里是因为它和 STAGES 一样属于「内置四阶」的定义——真从 flow.yaml
49
+ * 读要再走一趟请求,而这一段只是给人看的摘要,不值当。用户自定义的阶段
50
+ * 现在也进不到这张表里(面板只画四阶),所以不存在「配了却不显示」的落差。
51
+ */
52
+ const GATE_TEXT = { 1: '意图 95 分', 2: '产物在', 3: '断言退出码', 4: '判词 + 问题' }
53
+
54
+ /** 把毫秒说成人话。算不出来就返回空串,调用方据此不显示。 */
55
+ function durationText(ms) {
56
+ if (!Number.isFinite(ms) || ms <= 0) return ''
57
+ const sec = Math.round(ms / 1000)
58
+ if (sec < 60) return `${sec} 秒`
59
+ const min = Math.floor(sec / 60)
60
+ const rest = sec % 60
61
+ if (min < 60) return rest === 0 ? `${min} 分` : `${min} 分 ${rest} 秒`
62
+ return `${Math.floor(min / 60)} 时 ${min % 60} 分`
63
+ }
64
+
45
65
  /** 内置名字只为下拉好点;不在表里的照样能用 /flow-set 换。 */
46
66
  /**
47
67
  * 本机可用模型,从宿主现读,不写死。
@@ -278,6 +298,9 @@ function beacon(stage) {
278
298
  status: typeof state.status === 'string' ? state.status : '',
279
299
  rework: typeof state.rework === 'number' ? state.rework : 0,
280
300
  maxRework: typeof state.maxRework === 'number' ? state.maxRework : 2,
301
+ // 未闭环问题数(P0+P1 的 open+reopened 数)。阶段灯旁边显示的就是它:
302
+ // 「返工 2/4」说的是花了几轮,「open: 3」说的是还剩几件事没干完。
303
+ open: typeof state.openCritical === 'number' ? state.openCritical : (typeof state.openIssues === 'number' ? state.openIssues : 0),
281
304
  routes: state.routes ?? undefined,
282
305
  updatedAt: typeof state.updatedAt === 'string' ? state.updatedAt : null,
283
306
  running: false,
@@ -339,6 +362,9 @@ function beacon(stage) {
339
362
  const [busy, setBusy] = useState(false)
340
363
  const [notice, setNotice] = useState('')
341
364
  const [catalog, setCatalog] = useState([])
365
+ // 抽屉:点开的是「本轮问题」还是「未过的命令」,null 表示都收着。
366
+ // 只允许同时开一个——两块内容加起来比浮层还长,全开着等于没做折叠。
367
+ const [drawer, setDrawer] = useState(null)
342
368
 
343
369
  const anchorRef = useRef(null)
344
370
  const popRef = useRef(null)
@@ -553,18 +579,35 @@ function beacon(stage) {
553
579
  }, [runCommand, refresh])
554
580
 
555
581
  const running = panel.projects.find(project => project.running === true)
556
- // 优先级:我这个会话开的那个 → 任意在跑的 → 当前目录对着的 → 最近更新的。
582
+ // 优先级:我这个对话开的那个 → 我碰过的里最近的 → 当前目录对着的。
557
583
  //
558
- // 第一档是修「两个项目同时跑,两条状态栏显示一样」:
559
- // 以前只认 running,两个都在跑时 find 永远返回排在前面的那个,
560
- // 于是两个会话看到的是同一个项目。mine 由宿主按「这一轮是哪个会话发起的」标记。
584
+ // 两个字段分工不同,缺一不可:
585
+ // mine 只在这一轮正在跑时为真,跑完就假了;
586
+ // owned 是这个会话碰过的全部项目,落盘的,跑完、重启都还在。
587
+ // 以前只有 mine,跑完就退回「全表第一个项目」——于是每个对话都显示
588
+ // 同一个项目,用户说的「所有对话共用一条状态栏」就是它。
561
589
  const mine = panel.projects.find(project => project.mine === true)
590
+ // owned 有三种值,缺一不可:
591
+ // true 归我
592
+ // false 不归我(有归属记录,但没有我这个会话)
593
+ // null 未知归属——升级前跑的老项目没有 ownerSessions
594
+ //
595
+ // 老项目不能judge成「不是我的」,否则升级当天所有历史项目一起从栏里消失。
596
+ // 但也不能拿「未知」当「我的」去顶掉别人的——所以它排在自己的项目后面。
597
+ const owned = panel.projects
598
+ .filter(project => project.owned === true)
599
+ .sort((left, right) => String(right.updatedAt ?? '').localeCompare(String(left.updatedAt ?? '')))
600
+ const legacy = panel.projects.filter(project => project.owned !== true && project.owned !== false)
562
601
  const focused = panel.focus === undefined
563
602
  ? undefined
564
603
  : panel.projects.find(project => project.project === panel.focus)
565
- const target = mine ?? running ?? focused ?? panel.projects[0]
566
- // 「停止」按钮该停谁:我自己开的优先,其次才是任意在跑的那个。
567
- const stoppable = mine ?? running
604
+ // 自己的项目优先;没有就退到「归属未知」的老项目;再没有就是空态。
605
+ // 明确不归我的(false)永远不顶上来——那正是「共用一条状态栏」的来源。
606
+ const target = mine ?? owned[0] ?? focused ?? legacy[0]
607
+ // 停止按钮:自己的优先,其次自己碰过且在跑的,最后才轮到归属未知的。
608
+ const stoppable = mine
609
+ ?? owned.find(project => project.running === true)
610
+ ?? legacy.find(project => project.running === true)
568
611
  const routes = panel.routes ?? target?.routes ?? undefined
569
612
  const stage = target === undefined ? 0 : target.stage
570
613
  const doneCount = target === undefined
@@ -627,8 +670,13 @@ function beacon(stage) {
627
670
  // 只报状态词:已通过 / 未通过 / 进行中。
628
671
  // 之前报「4/4」和「3 个项目」,既不像状态,也容易被读成
629
672
  // 「当前这个活干完了」——用户要的是判词,不是计数。
630
- const verdict = target === undefined ? verdictOf(panel.projects) : verdictOf([target])
673
+ const verdict = target === undefined ? '' : verdictOf([target])
631
674
  if (verdict === '') {
675
+ // 这个对话自己没有项目,但工作流里躺着别人的——明说,别拿别人的
676
+ // 结论充数,也别让人以为数据丢了。
677
+ if (target === undefined && panel.projects.length > 0) {
678
+ return `这个对话还没开工 · 另有 ${panel.projects.length} 个`
679
+ }
632
680
  return panel.inside !== true
633
681
  ? (typeof panel.willCreate === 'string' ? '工作模式 · 自动建目录' : '工作模式 · 未启用')
634
682
  : '工作模式 · 就绪'
@@ -672,6 +720,9 @@ function beacon(stage) {
672
720
  className: `pfchip-seg is-${segStateOf(entry, stage, target)}`,
673
721
  })),
674
722
  ),
723
+ target !== undefined && target.open > 0
724
+ ? h('span', { className: 'pfchip-open' }, `open:${target.open}`)
725
+ : null,
675
726
  h('span', { className: 'pfchip-text' }, chipLabel),
676
727
  )
677
728
 
@@ -682,10 +733,20 @@ function beacon(stage) {
682
733
 
683
734
  // ── 展开态:浮层 ──────────────────────────────────
684
735
  const rect = anchorRef.current?.getBoundingClientRect?.() ?? { left: 0, bottom: 0, right: 0 }
685
- const width = 320
736
+ // 四列比原来那三行挤得多,宽度从 320 提到 420。窄屏还得收着,
737
+ // 所以按 window.innerWidth 封顶,不允许溢出屏幕。
738
+ const width = Math.min(420, (typeof window !== 'undefined' ? window.innerWidth : 420) - 16)
686
739
  const left = Math.max(8, Math.min(rect.right - width, (typeof window !== 'undefined' ? window.innerWidth : width) - width - 8))
687
740
  const top = (rect.bottom ?? 0) + 6
688
741
 
742
+ // 面板要用的三样,先算出来,渲染时不再重复取值。
743
+ const report = target?.report ?? { issues: [], assertions: { total: 0, pass: 0, fail: 0, unverified: 0 }, failed: [] }
744
+ const startedMs = target?.startedAt ? Date.parse(target.startedAt) : Number.NaN
745
+ const updatedMs = target?.updatedAt ? Date.parse(target.updatedAt) : Number.NaN
746
+ const elapsed = Number.isFinite(startedMs) && Number.isFinite(updatedMs) ? updatedMs - startedMs : Number.NaN
747
+ const round = target === undefined ? 0 : (typeof target.rework === 'number' ? target.rework : 0) + 1
748
+ const spentCny = target?.cost?.cny
749
+
689
750
  const panelBody = h('div', {
690
751
  ref: popRef,
691
752
  className: 'pfpop',
@@ -743,6 +804,101 @@ function beacon(stage) {
743
804
  '重要、值得留档、要复盘的任务放进去做;不重要的直接做,不用走这套。'),
744
805
  )
745
806
  : h('div', { className: 'pfpop-body' },
807
+ // ── 顶部一条:版本 · 轮次 · 未闭环 · 耗时 · 花费 ──
808
+ //
809
+ // 一行把「这是哪个版本、跑到第几轮、还剩几件事、花了多久多少钱」
810
+ // 说完。这五个数原来要翻三个地方:/flow-cost、QA_Report.md、state.json。
811
+ h('div', { className: 'pfsum' },
812
+ typeof panel.version === 'string' && panel.version !== ''
813
+ ? h('span', { className: 'pfsum-v' }, `v${panel.version}`)
814
+ : null,
815
+ h('span', null, target === undefined ? '—' : `第 ${round} 轮`),
816
+ target !== undefined && target.open > 0
817
+ ? h('span', { className: 'pfpop-open' }, `open ${target.open}`)
818
+ : null,
819
+ durationText(elapsed) !== ''
820
+ ? h('span', { className: 'pfpop-dim' }, durationText(elapsed))
821
+ : null,
822
+ Number.isFinite(spentCny) && spentCny > 0
823
+ ? h('span', { className: 'pfpop-dim' }, `¥${Number(spentCny).toFixed(2)}`)
824
+ : null,
825
+ ),
826
+
827
+ // ── 四列:阶段 / 状态 / 门禁 / 问题 ──
828
+ //
829
+ // 任务书原本要「阶段/状态/耗时·token/门禁」四列。耗时和 token 没法
830
+ // 按阶拆——state 里只记了整轮的 startedAt/updatedAt 和总账,分阶的
831
+ // 那笔数在 watchdog 内存里,跑完就没了。硬摊到每一行是编数字,
832
+ // 所以把这两样挪到上面那条汇总里,这一列换成「这一阶卡了几条问题」。
833
+ h('div', { className: 'pfgrid' },
834
+ h('span', { className: 'pfgrid-h' }, '阶段'),
835
+ h('span', { className: 'pfgrid-h' }, '状态'),
836
+ h('span', { className: 'pfgrid-h' }, '门禁'),
837
+ h('span', { className: 'pfgrid-h pfright' }, '问题'),
838
+ ...STAGES.flatMap(entry => {
839
+ const segState = segStateOf(entry, stage, target)
840
+ const issuesHere = entry.no === 4 && report.issues.length > 0
841
+ ? String(report.issues.length)
842
+ : ''
843
+ return [
844
+ h('span', { key: `g-n-${entry.no}`, className: 'pfgrid-c' }, entry.label),
845
+ h('span', { key: `g-s-${entry.no}`, className: `pfgrid-c is-${segState}` }, SEG_LABEL[segState]),
846
+ h('span', { key: `g-t-${entry.no}`, className: 'pfgrid-c pfpop-dim' }, GATE_TEXT[entry.no] ?? ''),
847
+ h('span', { key: `g-i-${entry.no}`, className: 'pfgrid-c pfright' }, issuesHere),
848
+ ]
849
+ }),
850
+ ),
851
+
852
+ // ── 两个折叠块:问题清单、未过的命令 ──
853
+ //
854
+ // 只显示「还开着的」和「挂掉的」。过了的那些看完就忘,占地方。
855
+ // 同时只允许开一个:两块都展开会比浮层本身还长。
856
+ report.issues.length > 0
857
+ ? h('div', { className: 'pffold' },
858
+ h('button', {
859
+ type: 'button',
860
+ className: 'pffold-btn',
861
+ 'aria-expanded': drawer === 'issues',
862
+ onClick: () => setDrawer(drawer === 'issues' ? null : 'issues'),
863
+ }, `${drawer === 'issues' ? '▾' : '▸'} 本轮没闭环 ${report.issues.length} 条`),
864
+ drawer === 'issues'
865
+ ? h('div', { className: 'pfdrawer' },
866
+ ...report.issues.map((item, index) => h('div', { key: `is-${item.id || index}`, className: 'pfissue' },
867
+ h('span', { className: 'pfsev' }, item.severity || '—'),
868
+ h('span', { className: 'pfissue-id' }, item.id || ''),
869
+ h('span', { className: 'pfissue-claim', title: item.claim || '' }, item.claim || '(没有说明)'),
870
+ )),
871
+ ...report.issues
872
+ .filter(item => typeof item.detect === 'string' && item.detect !== '')
873
+ .map((item, index) => h('div', { key: `de-${item.id || index}`, className: 'pfdetect', title: item.detect },
874
+ h('span', { className: 'pfissue-id' }, item.id || ''),
875
+ h('span', null, item.detect),
876
+ )),
877
+ )
878
+ : null,
879
+ )
880
+ : null,
881
+
882
+ report.failed !== undefined && report.failed.length > 0
883
+ ? h('div', { className: 'pffold' },
884
+ h('button', {
885
+ type: 'button',
886
+ className: 'pffold-btn',
887
+ 'aria-expanded': drawer === 'failed',
888
+ onClick: () => setDrawer(drawer === 'failed' ? null : 'failed'),
889
+ }, `${drawer === 'failed' ? '▾' : '▸'} 没过的命令 ${report.failed.length} 条`),
890
+ drawer === 'failed'
891
+ ? h('div', { className: 'pfdrawer' },
892
+ ...report.failed.map((item, index) => h('div', { key: `f-${index}`, className: 'pfdetect' },
893
+ h('span', { className: 'pfexit' }, item.exit === null ? '—' : String(item.exit)),
894
+ h('span', { className: 'pfissue-id' }, `#${item.req}`),
895
+ h('span', { title: item.cmd }, item.cmd || '(空命令)'),
896
+ )),
897
+ )
898
+ : null,
899
+ )
900
+ : null,
901
+
746
902
  // 四段全貌
747
903
  h('div', { className: 'pftrack' },
748
904
  STAGES.map(entry => {
@@ -763,6 +919,9 @@ function beacon(stage) {
763
919
  target !== undefined && target.rework > 0
764
920
  ? h('span', { className: 'pfpop-dim' }, `返工 ${target.rework}/${target.maxRework}`)
765
921
  : null,
922
+ target !== undefined && target.open > 0
923
+ ? h('span', { className: 'pfpop-open' }, `open: ${target.open}`)
924
+ : null,
766
925
  h('span', { className: 'pfpop-grow' }),
767
926
  target !== undefined ? h('span', { className: 'pfpop-dim' }, `${doneCount}/4 阶`) : null,
768
927
  ),
@@ -893,6 +1052,7 @@ function beacon(stage) {
893
1052
  '.pfchip-seg.is-active{opacity:1}',
894
1053
  '.pfchip-seg.is-halted{opacity:.6}',
895
1054
  '.pfchip-text{overflow:hidden;text-overflow:ellipsis}',
1055
+ '.pfchip-open{font-variant-numeric:tabular-nums;letter-spacing:.01em;opacity:.9;flex:0 0 auto}',
896
1056
 
897
1057
  // 浮层
898
1058
  '.pfpop{z-index:9999;display:flex;flex-direction:column;gap:8px;padding:10px;font-size:12px;line-height:1.5;color:CanvasText;background:Canvas;border:1px solid rgba(128,128,128,.38);border-radius:10px;box-shadow:0 10px 30px rgba(0,0,0,.28)}',
@@ -903,6 +1063,8 @@ function beacon(stage) {
903
1063
  '.pfpop-body{display:flex;flex-direction:column;gap:8px}',
904
1064
  '.pfpop-p{margin:0}',
905
1065
  '.pfpop-dim{opacity:.6}',
1066
+ // 未闭环数是待办,不是装饰:给点重量,别和「返工 2/4」混成一片灰。
1067
+ '.pfpop-open{opacity:.95;font-variant-numeric:tabular-nums;letter-spacing:.01em}',
906
1068
  '.pfpop-line{display:flex;align-items:center;gap:8px}',
907
1069
  '.pfpop-grow{flex:1 1 auto}',
908
1070
 
@@ -935,6 +1097,30 @@ function beacon(stage) {
935
1097
  '.pfcmd:disabled{opacity:.35;cursor:default}',
936
1098
  // 命令结果可能是多行,给一个能滚的框,不再切成一行省略号
937
1099
  '.pfpop-notice{font-size:11px;opacity:.8;white-space:pre-wrap;max-height:110px;overflow:auto;word-break:break-word}',
1100
+
1101
+ // ── 四列面板 ────────────────────────────────────────────
1102
+ // 顶部汇总一条:版本 / 轮次 / 未闭环 / 耗时 / 花费
1103
+ '.pfsum{display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:11px;opacity:.9}',
1104
+ '.pfsum-v{font-weight:600}',
1105
+ // 阶段 / 状态 / 门禁 / 问题。第一列和最后一列定宽,中间一列吃掉余量。
1106
+ '.pfgrid{display:grid;grid-template-columns:46px minmax(0,1fr) minmax(0,1.1fr) 28px;gap:2px 6px;align-items:center;font-size:11px}',
1107
+ '.pfgrid-h{font-weight:600;opacity:.5;border-bottom:1px solid rgba(128,128,128,.25);padding-bottom:2px}',
1108
+ '.pfgrid-c{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding:1px 0}',
1109
+ '.pfright{text-align:right}',
1110
+ '.pfgrid-c.is-active{font-weight:600}',
1111
+ '.pfgrid-c.is-halted{font-weight:600}',
1112
+ // 折叠块
1113
+ '.pffold{display:flex;flex-direction:column;gap:3px}',
1114
+ '.pffold-btn{font:inherit;font-size:11px;text-align:left;color:inherit;background:transparent;border:0;padding:0;cursor:pointer;opacity:.75}',
1115
+ '.pffold-btn:hover{opacity:1}',
1116
+ '.pfdrawer{display:flex;flex-direction:column;gap:3px;padding:5px 6px;border-radius:6px;background:rgba(128,128,128,.1);font-size:11px;max-height:148px;overflow:auto}',
1117
+ '.pfissue{display:grid;grid-template-columns:24px 40px minmax(0,1fr);gap:5px;align-items:baseline}',
1118
+ '.pfsev{font-weight:600;opacity:.85}',
1119
+ '.pfissue-id{opacity:.55;font-variant-numeric:tabular-nums}',
1120
+ '.pfissue-claim{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
1121
+ // 检测命令可能很长,允许折行——这是要照着敲的东西,不能截断
1122
+ '.pfdetect{display:grid;grid-template-columns:34px 30px minmax(0,1fr);gap:5px;opacity:.8;word-break:break-all}',
1123
+ '.pfexit{font-variant-numeric:tabular-nums;opacity:.9}',
938
1124
  ].join('\n')
939
1125
 
940
1126
  return {