dsh-todo-board 0.4.1 → 0.5.0

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
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ - **面板可以折叠**,不用的时候只占一行:
6
+ - 标题栏的 `–` 把整板收成**一行**(不再是浮动胶囊):`TODO · 未完成数 · 下一条待办` + 待验收计数;点这一行任意位置展开,键盘 `Enter` / 空格也行。这一行按内容收窄,不撑满面板宽度。
7
+ - 面板内部三个区块各自可折叠:**新增待办**(输入框 / 图片 / 模式 / 定时 / 目录)、**待办列表**(标题带条数)、**面板**(页脚计数器 / 清理已验收 / Cordis 入口)。区块标题本身就是开关,箭头 `▾ / ▸` 表示状态。
8
+ - 折叠状态存进 `localStorage`(`dsh.todoBoard.sections.v1`),刷新后保持。
9
+ - 修复:标题栏里的按钮点不动。拖动用的 `setPointerCapture` 会把随后的 click 重定向到指针捕获元素,按钮永远收不到点击;现在标题栏上的 `pointerdown` 落在按钮上时不启动拖动。(收成一行后如果没有这个修复,会卡在收不起也展不开的状态。)
10
+ - `tools/client-smoke.mjs`:浏览器半边的自检(自带极简 React hook 运行时 + DOM stub,无需浏览器),覆盖区块折叠、一行视图的内容、以及标题栏按钮不被拖动吞掉。`npm test` 现在跑 host + client 两个 smoke。
11
+
3
12
  ## 0.4.1
4
13
 
5
14
  - 市场素材:`assets/screenshot-1.png`(整体界面)与 `assets/screenshot-2.png`(面板特写)由 `tools/capture-screenshots.mjs` 从真实运行中的 UI 渲染生成,配 `screenshots.json` 声明;README 顶部展示面板截图。
package/README.md CHANGED
@@ -112,12 +112,17 @@ Only the right-hand box closes a task. The prompt section explicitly forbids the
112
112
 
113
113
  ## 面板操作 / Panel
114
114
 
115
+ - **折叠为一行**:标题栏右侧的 `–` 把整板收成一行 —— `TODO · 未完成数 · 下一条待办 · 待验 N`,点这一行任意位置展开。平时挂着不占地方,扫一眼就知道还剩什么。
116
+ - **区块折叠**:面板内部三个区块(新增待办 / 待办列表 / 面板)各自可折叠,点区块标题切换,`▾` 展开、`▸` 已折叠。只留列表时最省空间;折叠状态记在 `localStorage`,刷新后保持。
115
117
  - **拖动 / 缩放**:拖标题栏移动,右下角 `◢` 缩放;位置与尺寸存进 `localStorage`,刷新保留;双击标题栏或拖柄还原。
116
118
  - **筛选**:当前目录 / 当前会话 / 全部,每段带未完成计数。
117
119
  - **行内编辑**:双击标题改名;点模式标签在 提醒 → 续跑 → 新会话 之间循环切换。
118
120
  - **多行输入**:新增框自动增高(3 行起步,最高 180px),`Enter` 添加、`Shift+Enter` 换行。
119
121
  - **Cordis 入口**:侧边栏底部的 `Cordis Plugin` 按钮折起,入口移到本面板底部;点它打开原面板,面板出现在**本面板正下方**(右对齐、互不覆盖),拖动或缩放本面板时它会跟着走。找不到入口时按钮会变灰并给出提示。
120
122
 
123
+ - **Park as one line**: the `–` in the title bar collapses the whole board to a single line — `TODO · open count · next task · 待验 N`. Click anywhere on that line (or press `Enter`/`Space`) to unfold; the line hugs its content instead of spanning the panel. It stays out of the way until you need it.
124
+ - **Section folding**: the composer, the list, and the footer each fold away from their own header (`▾` open, `▸` folded); with only the list left the panel is at its smallest. The folded set is kept in `localStorage` across reloads.
125
+
121
126
  ## 模型工具 / The `todo_board` tool
122
127
 
123
128
  | action | 作用 |
@@ -151,6 +156,7 @@ cordis.patch.yml 向 profile 树 insert 一行 todo-board
151
156
  lib/index.js Host:板文件、todo_board 工具、回合结束钩子、提示词段落、/dsh-todo-board/api
152
157
  client/client.js Browser:shell.overlay 浮窗,走 fetch 访问上面的路由
153
158
  tools/smoke.mjs Host 半边自检(stub ctx + 临时 DSH_HOME)
159
+ tools/client-smoke.mjs Browser 半边自检(极简 React hook 运行时 + DOM stub,折叠行为)
154
160
  ```
155
161
 
156
162
  Host 半刻意不 import 任何 `@deepseek-ai/*`:profile 安装的插件从自身目录解析模块,harness 包在那里不可达,一切通过 `ctx`。
@@ -159,7 +165,7 @@ Host 半刻意不 import 任何 `@deepseek-ai/*`:profile 安装的插件从自
159
165
 
160
166
  ```sh
161
167
  npm run check # node --check 两个入口
162
- npm test # host 半边 smoke 自检
168
+ npm test # host + client 两半 smoke 自检
163
169
  ```
164
170
 
165
171
  改完客户端只需刷新页面;改 Host 半边需要重启 Profile。
package/client/client.js CHANGED
@@ -38,7 +38,7 @@ const MODE_HINT = {
38
38
  }
39
39
  const MONO = 'ui-monospace,"Cascadia Mono","SF Mono",Menlo,Consolas,monospace'
40
40
  /** Bumped whenever the browser half changes, so the footer proves which build is live. */
41
- const BUILD = '0.4.0'
41
+ const BUILD = '0.5.0'
42
42
 
43
43
  const CSS = `
44
44
  .dshtb-root{position:fixed;top:56px;right:16px;z-index:2147482000;pointer-events:auto;
@@ -69,9 +69,19 @@ const CSS = `
69
69
  .dshtb-stats i{font-style:normal;display:inline-flex;align-items:center;gap:4px}
70
70
  .dshtb-stats i::before{content:'';width:5px;height:5px;border-radius:50%;background:currentColor;opacity:.75}
71
71
  .dshtb-sp{flex:1}
72
- .dshtb-fold{width:20px;height:20px;border:0;border-radius:6px;background:transparent;color:var(--tb-dim);
73
- cursor:pointer;font:600 13px/1 ${MONO};padding:0;transition:background .12s,color .12s}
74
- .dshtb-fold:hover{background:var(--dsw-alias-bg-layer-1);color:var(--tb-ink)}
72
+ .dshtb-fold{width:26px;height:26px;border:1px solid transparent;border-radius:7px;background:transparent;
73
+ color:var(--tb-dim);cursor:pointer;font:600 14px/1 ${MONO};padding:0;display:grid;place-items:center;
74
+ transition:background .12s,color .12s,border-color .12s}
75
+ .dshtb-fold:hover{background:var(--dsw-alias-bg-layer-1);color:var(--tb-ink);border-color:var(--tb-line2)}
76
+ .dshtb-fold:focus-visible{outline:2px solid var(--tb-accent);outline-offset:1px}
77
+ /* Section label doubling as the fold/unfold control for what follows it. */
78
+ .dshtb-sect{display:flex;align-items:center;gap:6px;width:100%;padding:9px 12px 5px;
79
+ border:0;background:transparent;cursor:pointer;user-select:none;text-align:left;
80
+ font:600 10.5px/1 ${MONO};letter-spacing:.09em;text-transform:uppercase;color:var(--tb-dim);
81
+ transition:color .12s}
82
+ .dshtb-sect:hover{color:var(--tb-ink)}
83
+ .dshtb-sect::after{content:'';flex:1;height:1px;background:var(--tb-line)}
84
+ .dshtb-sect .car{font:700 11px/1 ${MONO};color:var(--tb-accent)}
75
85
  .dshtb-seg{display:flex;gap:2px;margin:9px 12px 0;padding:2px;border-radius:10px;
76
86
  background:var(--dsw-alias-bg-layer-1);border:1px solid var(--tb-line)}
77
87
  .dshtb-seg button{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:5px 6px;
@@ -207,11 +217,17 @@ button.dshtb-chip:hover{border-color:var(--tb-line2);color:var(--tb-ink)}
207
217
  max-height:var(--dsh-todo-cordis-maxh,60vh) !important}
208
218
  .dshtb-err{padding:6px 12px;color:var(--dsw-alias-state-error-primary);font:400 10.5px/1.4 ${MONO};
209
219
  word-break:break-all;border-top:1px solid var(--tb-line)}
210
- .dshtb-pill{display:inline-flex;align-items:center;gap:7px;padding:7px 12px 7px 10px;border-radius:999px;
220
+ /* Parked as one line: label + counts + the next task, expandable by a click.
221
+ align-self keeps it hugging its content instead of stretching to the card width. */
222
+ .dshtb-pill{align-self:flex-start;display:flex;align-items:center;gap:8px;min-width:0;
223
+ max-width:calc(100vw - 32px);padding:6px 10px;border-radius:10px;
211
224
  background:var(--tb-bg);border:1px solid var(--tb-line);cursor:pointer;user-select:none;
212
- box-shadow:0 8px 26px -10px rgba(0,0,0,.5);transition:transform .14s,border-color .14s}
213
- .dshtb-pill:hover{transform:translateY(-1px);border-color:var(--tb-line2)}
214
- .dshtb-pill .lbl{font:600 10px/1 ${MONO};letter-spacing:.12em;text-transform:uppercase}
225
+ box-shadow:0 10px 30px -12px rgba(0,0,0,.5);transition:border-color .14s}
226
+ .dshtb-pill:hover{border-color:var(--tb-line2)}
227
+ .dshtb-pill .lbl{font:600 10px/1 ${MONO};letter-spacing:.12em;text-transform:uppercase;color:var(--tb-ink)}
228
+ .dshtb-pill .next{flex:1;min-width:0;max-width:220px;overflow:hidden;text-overflow:ellipsis;
229
+ white-space:nowrap;font-size:12px;color:var(--tb-dim)}
230
+ .dshtb-pill .next.q{font-style:italic;opacity:.7}
215
231
  .dshtb-badge{min-width:18px;height:18px;padding:0 5px;border-radius:9px;background:var(--tb-accent);
216
232
  color:#fff;font:700 10px/1 ${MONO};font-variant-numeric:tabular-nums;display:inline-grid;place-items:center}
217
233
  .dshtb-badge.warn{background:var(--tb-warn)}
@@ -408,6 +424,35 @@ function saveLayout(layout) {
408
424
  }
409
425
  }
410
426
 
427
+ /**
428
+ * Folded sections and the parked panel survive a reload: folding away the
429
+ * composer is something you do once, not once per page load.
430
+ */
431
+ const SECTIONS_KEY = 'dsh.todoBoard.sections.v1'
432
+ const SECTION_IDS = ['compose', 'list', 'panel']
433
+
434
+ function loadSections() {
435
+ const state = { compose: true, list: true, panel: true }
436
+ try {
437
+ const raw = window.localStorage.getItem(SECTIONS_KEY)
438
+ if (raw === null) return state
439
+ const parsed = JSON.parse(raw)
440
+ if (parsed === null || typeof parsed !== 'object') return state
441
+ for (const id of SECTION_IDS) if (typeof parsed[id] === 'boolean') state[id] = parsed[id]
442
+ } catch (err) {
443
+ /* keep the defaults */
444
+ }
445
+ return state
446
+ }
447
+
448
+ function saveSections(state) {
449
+ try {
450
+ window.localStorage.setItem(SECTIONS_KEY, JSON.stringify(state))
451
+ } catch (err) {
452
+ /* storage unavailable */
453
+ }
454
+ }
455
+
411
456
  function clampLayout(layout) {
412
457
  const maxW = Math.max(MIN_W, window.innerWidth - 16)
413
458
  const maxH = Math.max(MIN_H, window.innerHeight - 16)
@@ -418,6 +463,37 @@ function clampLayout(layout) {
418
463
  return { x, y, w, h }
419
464
  }
420
465
 
466
+ /**
467
+ * A foldable section of the panel: its label doubles as the control that shows
468
+ * and hides the body, so a folded panel still says what it is hiding.
469
+ *
470
+ * @param options.id - stable key, also handed back to `onToggle`.
471
+ * @param options.name - section name, used in the tooltip.
472
+ * @param options.note - optional count rendered after the name.
473
+ * @param options.open - whether the body is currently visible.
474
+ * @param options.onToggle - called with `id` when the header is clicked.
475
+ * @param options.body - the single keyed element to hide when folded.
476
+ * @returns header and body as siblings, ready to spread into a children list.
477
+ */
478
+ function foldable(options) {
479
+ const { id, name, note, open, onToggle, body } = options
480
+ return [
481
+ h(
482
+ 'button',
483
+ {
484
+ key: id,
485
+ className: 'dshtb-sect',
486
+ 'aria-expanded': open ? 'true' : 'false',
487
+ title: (open ? '折叠' : '展开') + '「' + name + '」',
488
+ onClick: () => onToggle(id),
489
+ },
490
+ h('span', { className: 'car' }, open ? '\u25BE' : '\u25B8'),
491
+ note === undefined ? name : name + ' ' + note,
492
+ ),
493
+ open ? body : null,
494
+ ]
495
+ }
496
+
421
497
  // --------------------------------------------------------------- component
422
498
 
423
499
  function TodoBoard(props) {
@@ -449,6 +525,7 @@ function TodoBoard(props) {
449
525
  const [editText, setEditText] = React.useState('')
450
526
  const [layout, setLayout] = React.useState(loadLayout)
451
527
  const [cordisFound, setCordisFound] = React.useState(true)
528
+ const [sections, setSections] = React.useState(loadSections)
452
529
  const layoutRef = React.useRef(null)
453
530
  const dragRef = React.useRef(null)
454
531
  const inputRef = React.useRef(null)
@@ -478,6 +555,13 @@ function TodoBoard(props) {
478
555
  }
479
556
 
480
557
  function beginDrag(event) {
558
+ // A pointerdown on a control inside the title bar must not start a drag:
559
+ // setPointerCapture retargets the following click to the captured element,
560
+ // so the button underneath would never see it.
561
+ const target = event.target
562
+ if (target !== null && typeof target.closest === 'function' && target.closest('button') !== null) {
563
+ return
564
+ }
481
565
  seedFrom(event, 'move')
482
566
  }
483
567
 
@@ -510,6 +594,20 @@ function TodoBoard(props) {
510
594
  saveLayout(null)
511
595
  }
512
596
 
597
+ /** Fold one section of the panel away, or bring it back. */
598
+ function toggleSection(id) {
599
+ setSections((current) => {
600
+ const next = { ...current, [id]: !current[id] }
601
+ saveSections(next)
602
+ return next
603
+ })
604
+ }
605
+
606
+ /** Park the whole panel as a single line, or unfold it again. */
607
+ function togglePanel() {
608
+ setOpen((current) => !current)
609
+ }
610
+
513
611
  // Grow the composer with its content, up to the CSS max-height.
514
612
  React.useEffect(() => {
515
613
  const el = inputRef.current
@@ -941,6 +1039,7 @@ function TodoBoard(props) {
941
1039
  }
942
1040
 
943
1041
  if (!open) {
1042
+ const next = visible.filter((t) => !t.verified && !t.aiDone)[0]
944
1043
  return h(
945
1044
  'div',
946
1045
  {
@@ -962,10 +1061,19 @@ function TodoBoard(props) {
962
1061
  'div',
963
1062
  {
964
1063
  className: 'dshtb-pill',
1064
+ role: 'button',
1065
+ tabIndex: 0,
965
1066
  title:
966
1067
  'TODO 板 · 点击展开' +
1068
+ (next === undefined ? '(没有未完成待办)' : ':' + next.title) +
967
1069
  (data !== null && data !== undefined && data.storagePath ? '\n存储:' + data.storagePath : ''),
968
1070
  onClick: () => setOpen(true),
1071
+ onKeyDown: (e) => {
1072
+ if (e.key === 'Enter' || e.key === ' ') {
1073
+ e.preventDefault()
1074
+ setOpen(true)
1075
+ }
1076
+ },
969
1077
  },
970
1078
  h('span', { className: 'lbl' }, 'TODO'),
971
1079
  h(
@@ -973,6 +1081,10 @@ function TodoBoard(props) {
973
1081
  { className: 'dshtb-badge' + (awaitingVerify > 0 ? ' warn' : '') },
974
1082
  String(openCount),
975
1083
  ),
1084
+ next === undefined
1085
+ ? h('span', { className: 'next q' }, filter === 'dir' ? '当前目录已清空' : '没有未完成待办')
1086
+ : h('span', { className: 'next' }, '下一条 · ' + next.title),
1087
+ awaitingVerify > 0 ? h('span', { className: 'dshtb-badge warn' }, '待验 ' + awaitingVerify) : null,
976
1088
  ),
977
1089
  )
978
1090
  }
@@ -1054,158 +1166,187 @@ function TodoBoard(props) {
1054
1166
  h('i', { title: '未验收' }, String(openCount)),
1055
1167
  awaitingVerify > 0 ? h('i', { title: 'AI 已完成,等你验收' }, '待验 ' + awaitingVerify) : null,
1056
1168
  ),
1057
- h('button', { className: 'dshtb-fold', title: '收起', onClick: () => setOpen(false) }, '\u2013'),
1169
+ h(
1170
+ 'button',
1171
+ {
1172
+ className: 'dshtb-fold',
1173
+ title: '收起为一行(只留计数与下一条待办)',
1174
+ 'aria-label': '收起为一行',
1175
+ onClick: togglePanel,
1176
+ },
1177
+ '\u2013',
1178
+ ),
1058
1179
  ),
1059
1180
  h('div', { className: 'dshtb-seg' }, segments),
1060
- h(
1061
- 'div',
1062
- { className: 'dshtb-compose' },
1063
- h(
1181
+ ...foldable({
1182
+ id: 'compose',
1183
+ name: '新增待办',
1184
+ open: sections.compose,
1185
+ onToggle: toggleSection,
1186
+ body: h(
1064
1187
  'div',
1065
- { className: 'dshtb-add' },
1066
- h('textarea', {
1067
- ref: inputRef,
1068
- rows: 3,
1069
- placeholder: '新增待办…(Enter 添加,Shift+Enter 换行)',
1070
- value: draft,
1071
- onChange: (e) => setDraft(e.target.value),
1072
- onKeyDown: (e) => {
1073
- if (e.key === 'Enter' && !e.shiftKey) {
1074
- e.preventDefault()
1075
- add()
1076
- }
1077
- },
1078
- }),
1188
+ { className: 'dshtb-compose', key: 'compose-body' },
1079
1189
  h(
1080
- 'button',
1081
- { className: 'dshtb-ic', title: '添加', disabled: busy || draft.trim() === '', onClick: add },
1082
- '\uFF0B',
1083
- ),
1084
- ),
1085
- h(
1086
- 'div',
1087
- { className: 'dshtb-attach' },
1088
- h('label', { className: 'dshtb-link' + (pending.length >= MAX_IMAGES ? ' off' : ''), title: '给这条待办附图(最多 ' + MAX_IMAGES + ' 张,PNG/JPG/WebP/GIF)' },
1089
- '\uD83D\uDCCE 图片',
1090
- h('input', {
1091
- type: 'file',
1092
- accept: 'image/png,image/jpeg,image/webp,image/gif',
1093
- multiple: true,
1094
- disabled: pending.length >= MAX_IMAGES,
1095
- style: { display: 'none' },
1096
- onChange: pickImages,
1190
+ 'div',
1191
+ { className: 'dshtb-add' },
1192
+ h('textarea', {
1193
+ ref: inputRef,
1194
+ rows: 3,
1195
+ placeholder: '新增待办…(Enter 添加,Shift+Enter 换行)',
1196
+ value: draft,
1197
+ onChange: (e) => setDraft(e.target.value),
1198
+ onKeyDown: (e) => {
1199
+ if (e.key === 'Enter' && !e.shiftKey) {
1200
+ e.preventDefault()
1201
+ add()
1202
+ }
1203
+ },
1097
1204
  }),
1205
+ h(
1206
+ 'button',
1207
+ { className: 'dshtb-ic', title: '添加', disabled: busy || draft.trim() === '', onClick: add },
1208
+ '\uFF0B',
1209
+ ),
1098
1210
  ),
1099
- pending.length === 0
1100
- ? null
1101
- : h(
1102
- 'div',
1103
- { className: 'dshtb-thumbs' },
1104
- pending.map((image, at) =>
1105
- h(
1106
- 'button',
1107
- {
1108
- key: 'p' + at,
1109
- className: 'dshtb-thumb',
1110
- title: (image.name || '图片') + '(点击移除)',
1111
- onClick: () => setPending((current) => current.filter((_, i) => i !== at)),
1112
- },
1113
- h('img', { src: 'data:' + image.mediaType + ';base64,' + image.data, alt: image.name || '' }),
1114
- h('span', { className: 'x' }, '\u2715'),
1211
+ h(
1212
+ 'div',
1213
+ { className: 'dshtb-attach' },
1214
+ h('label', { className: 'dshtb-link' + (pending.length >= MAX_IMAGES ? ' off' : ''), title: '给这条待办附图(最多 ' + MAX_IMAGES + ' 张,PNG/JPG/WebP/GIF)' },
1215
+ '\uD83D\uDCCE 图片',
1216
+ h('input', {
1217
+ type: 'file',
1218
+ accept: 'image/png,image/jpeg,image/webp,image/gif',
1219
+ multiple: true,
1220
+ disabled: pending.length >= MAX_IMAGES,
1221
+ style: { display: 'none' },
1222
+ onChange: pickImages,
1223
+ }),
1224
+ ),
1225
+ pending.length === 0
1226
+ ? null
1227
+ : h(
1228
+ 'div',
1229
+ { className: 'dshtb-thumbs' },
1230
+ pending.map((image, at) =>
1231
+ h(
1232
+ 'button',
1233
+ {
1234
+ key: 'p' + at,
1235
+ className: 'dshtb-thumb',
1236
+ title: (image.name || '图片') + '(点击移除)',
1237
+ onClick: () => setPending((current) => current.filter((_, i) => i !== at)),
1238
+ },
1239
+ h('img', { src: 'data:' + image.mediaType + ';base64,' + image.data, alt: image.name || '' }),
1240
+ h('span', { className: 'x' }, '\u2715'),
1241
+ ),
1115
1242
  ),
1116
1243
  ),
1244
+ ),
1245
+ h(
1246
+ 'div',
1247
+ { className: 'dshtb-modes' },
1248
+ MODES.map((id) =>
1249
+ h(
1250
+ 'button',
1251
+ { key: id, className: mode === id ? 'on' : '', title: MODE_LABEL[id], onClick: () => setMode(id) },
1252
+ MODE_SHORT[id],
1117
1253
  ),
1118
- ),
1119
- h(
1120
- 'div',
1121
- { className: 'dshtb-modes' },
1122
- MODES.map((id) =>
1123
- h(
1124
- 'button',
1125
- { key: id, className: mode === id ? 'on' : '', title: MODE_LABEL[id], onClick: () => setMode(id) },
1126
- MODE_SHORT[id],
1127
1254
  ),
1128
1255
  ),
1256
+ h('div', { className: 'dshtb-hint' }, MODE_HINT[mode]),
1257
+ h(
1258
+ 'div',
1259
+ { className: 'dshtb-when' },
1260
+ h('span', { className: 'lbl' }, '定时'),
1261
+ h('input', {
1262
+ type: 'datetime-local',
1263
+ value: when,
1264
+ title: '到点后才执行(留空 = 立即可以执行)',
1265
+ onChange: (e) => setWhen(e.target.value),
1266
+ }),
1267
+ when !== ''
1268
+ ? h(
1269
+ 'button',
1270
+ {
1271
+ className: 'dshtb-ic',
1272
+ title: '取消定时',
1273
+ onClick: () => setWhen(''),
1274
+ },
1275
+ '\u2715',
1276
+ )
1277
+ : h('span', { className: 'dshtb-hint' }, '不填'),
1278
+ ),
1279
+ h(
1280
+ 'div',
1281
+ { className: 'dshtb-dir' },
1282
+ h('input', {
1283
+ placeholder: cwd === '' ? '目录(绝对路径)' : '目录:' + cwd,
1284
+ value: dirInput,
1285
+ onChange: (e) => setDirInput(e.target.value),
1286
+ }),
1287
+ ),
1129
1288
  ),
1130
- h('div', { className: 'dshtb-hint' }, MODE_HINT[mode]),
1131
- h(
1132
- 'div',
1133
- { className: 'dshtb-when' },
1134
- h('span', { className: 'lbl' }, '定时'),
1135
- h('input', {
1136
- type: 'datetime-local',
1137
- value: when,
1138
- title: '到点后才执行(留空 = 立即可以执行)',
1139
- onChange: (e) => setWhen(e.target.value),
1140
- }),
1141
- when !== ''
1289
+ }),
1290
+ ...foldable({
1291
+ id: 'list',
1292
+ name: '待办列表',
1293
+ note: visible.length,
1294
+ open: sections.list,
1295
+ onToggle: toggleSection,
1296
+ body:
1297
+ rows.length === 0
1142
1298
  ? h(
1143
- 'button',
1144
- {
1145
- className: 'dshtb-ic',
1146
- title: '取消定时',
1147
- onClick: () => setWhen(''),
1148
- },
1149
- '\u2715',
1299
+ 'div',
1300
+ { className: 'dshtb-empty', key: 'list-body' },
1301
+ h('b', null, '\u2610'),
1302
+ h(
1303
+ 'span',
1304
+ null,
1305
+ filter === 'dir' ? '当前目录还没有待办' : '这里还没有待办',
1306
+ ),
1150
1307
  )
1151
- : h('span', { className: 'dshtb-hint' }, '不填'),
1152
- ),
1153
- h(
1154
- 'div',
1155
- { className: 'dshtb-dir' },
1156
- h('input', {
1157
- placeholder: cwd === '' ? '目录(绝对路径)' : '目录:' + cwd,
1158
- value: dirInput,
1159
- onChange: (e) => setDirInput(e.target.value),
1160
- }),
1161
- ),
1162
- ),
1163
- rows.length === 0
1164
- ? h(
1165
- 'div',
1166
- { className: 'dshtb-empty' },
1167
- h('b', null, '\u2610'),
1168
- h(
1169
- 'span',
1170
- null,
1171
- filter === 'dir' ? '当前目录还没有待办' : '这里还没有待办',
1172
- ),
1173
- )
1174
- : h('div', { className: 'dshtb-list' }, rows),
1308
+ : h('div', { className: 'dshtb-list', key: 'list-body' }, rows),
1309
+ }),
1175
1310
  err !== '' ? h('div', { className: 'dshtb-err' }, err) : null,
1176
1311
  data !== null && data !== undefined && data.storageError
1177
1312
  ? h('div', { className: 'dshtb-err' }, data.storageError)
1178
1313
  : null,
1179
- h(
1180
- 'div',
1181
- { className: 'dshtb-foot' },
1182
- h('span', { title: '客户端构建标记,用来确认浏览器加载的是哪一版' }, 'v' + BUILD),
1183
- h('span', null, '未验收 ' + openCount),
1184
- awaitingVerify > 0 ? h('span', null, '· 待验 ' + awaitingVerify) : null,
1185
- h('span', { className: 'dshtb-sp' }),
1186
- verifiedCount > 0
1187
- ? h(
1188
- 'button',
1189
- {
1190
- className: 'dshtb-link',
1191
- title: '删除所有已验收的条目(共 ' + verifiedCount + ' 条)',
1192
- onClick: () => call('clearVerified'),
1193
- },
1194
- '清理已验收 ' + verifiedCount,
1195
- )
1196
- : null,
1197
- h(
1198
- 'button',
1199
- {
1200
- className: 'dshtb-link' + (cordisFound ? '' : ' off'),
1201
- title: cordisFound
1202
- ? '打开 Cordis 动态插件面板(显示在本面板正下方)'
1203
- : '找不到 Cordis 入口,暂时打不开',
1204
- onClick: openCordisPanel,
1205
- },
1206
- 'Cordis Plugin',
1207
- ),
1208
- ),
1314
+ ...foldable({
1315
+ id: 'panel',
1316
+ name: '面板',
1317
+ open: sections.panel,
1318
+ onToggle: toggleSection,
1319
+ body: h(
1320
+ 'div',
1321
+ { className: 'dshtb-foot', key: 'panel-body' },
1322
+ h('span', { title: '客户端构建标记,用来确认浏览器加载的是哪一版' }, 'v' + BUILD),
1323
+ h('span', null, '未验收 ' + openCount),
1324
+ awaitingVerify > 0 ? h('span', null, '· 待验 ' + awaitingVerify) : null,
1325
+ h('span', { className: 'dshtb-sp' }),
1326
+ verifiedCount > 0
1327
+ ? h(
1328
+ 'button',
1329
+ {
1330
+ className: 'dshtb-link',
1331
+ title: '删除所有已验收的条目(共 ' + verifiedCount + ' 条)',
1332
+ onClick: () => call('clearVerified'),
1333
+ },
1334
+ '清理已验收 ' + verifiedCount,
1335
+ )
1336
+ : null,
1337
+ h(
1338
+ 'button',
1339
+ {
1340
+ className: 'dshtb-link' + (cordisFound ? '' : ' off'),
1341
+ title: cordisFound
1342
+ ? '打开 Cordis 动态插件面板(显示在本面板正下方)'
1343
+ : '找不到 Cordis 入口,暂时打不开',
1344
+ onClick: openCordisPanel,
1345
+ },
1346
+ 'Cordis Plugin',
1347
+ ),
1348
+ ),
1349
+ }),
1209
1350
  h('div', {
1210
1351
  className: 'dshtb-resize',
1211
1352
  title: '拖动缩放 · 双击还原',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-todo-board",
3
- "version": "0.4.1",
4
- "description": "跨会话 TODO 板:右上角浮窗、按工作目录分组、可拖动排序;每条待办可选「提醒 / 自动续跑 / 自动新开会话」三档执行模式,可附图片(派发时作为真正的图片发给模型),可设定本地时间到点才执行,双勾选(AI 完成 / 用户验收)。AI 完成一项后自动查找同目录下一条未完成待办并继续执行。",
3
+ "version": "0.5.0",
4
+ "description": "跨会话 TODO 板:右上角浮窗、按工作目录分组、可拖动排序;每条待办可选「提醒 / 自动续跑 / 自动新开会话」三档执行模式,可附图片(派发时作为真正的图片发给模型),可设定本地时间到点才执行,双勾选(AI 完成 / 用户验收)。不占地方时可整体折叠为一行(显示计数与下一条待办),面板内各区块也能单独折叠。AI 完成一项后自动查找同目录下一条未完成待办并继续执行。",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -39,11 +39,12 @@
39
39
  "待办",
40
40
  "定时执行",
41
41
  "图片附件",
42
- "自动接续"
42
+ "自动接续",
43
+ "折叠"
43
44
  ],
44
45
  "scripts": {
45
46
  "check": "node --check lib/index.js && node --check client/client.js",
46
- "test": "node tools/smoke.mjs"
47
+ "test": "node tools/smoke.mjs && node tools/client-smoke.mjs"
47
48
  },
48
49
  "dsh": {
49
50
  "category": "extension",
@@ -0,0 +1,389 @@
1
+ /**
2
+ * Browser-half smoke test for dsh-todo-board.
3
+ *
4
+ * The client module only reaches for `require('react')` and a few globals, so it
5
+ * can be loaded in Node against a tiny hook runtime and a stub DOM. That is
6
+ * enough to pin down the panel's folding behaviour — which sections exist, what
7
+ * the parked one-line view shows, and that the title bar's drag handle does not
8
+ * swallow a click meant for a button.
9
+ *
10
+ * node tools/client-smoke.mjs
11
+ */
12
+
13
+ import assert from 'node:assert/strict'
14
+
15
+ // ------------------------------------------------------------- React shim
16
+
17
+ let hooks = []
18
+ let cursor = 0
19
+ let rendering = false
20
+ let scheduled = false
21
+ const pendingEffects = []
22
+
23
+ function scheduleRender() {
24
+ if (rendering) {
25
+ scheduled = true
26
+ return
27
+ }
28
+ let guard = 0
29
+ do {
30
+ scheduled = false
31
+ render()
32
+ guard += 1
33
+ } while (scheduled && guard < 50)
34
+ }
35
+
36
+ function flushEffects() {
37
+ if (pendingEffects.length === 0) return
38
+ const running = pendingEffects.splice(0, pendingEffects.length)
39
+ for (const effect of running) {
40
+ if (typeof effect.cleanup === 'function') effect.cleanup()
41
+ const cleanup = effect.run()
42
+ effect.cleanup = typeof cleanup === 'function' ? cleanup : undefined
43
+ effect.ran = true
44
+ }
45
+ }
46
+
47
+ function slot(at) {
48
+ if (hooks[at] === undefined) hooks[at] = {}
49
+ return hooks[at]
50
+ }
51
+
52
+ const React = {
53
+ createElement(type, props, ...children) {
54
+ const flat = []
55
+ const push = (value) => {
56
+ if (value === null || value === undefined || value === false || value === true) return
57
+ if (Array.isArray(value)) {
58
+ for (const item of value) push(item)
59
+ return
60
+ }
61
+ flat.push(value)
62
+ }
63
+ for (const child of children) push(child)
64
+ return { type, props: props === null || props === undefined ? {} : props, children: flat }
65
+ },
66
+ useState(initial) {
67
+ const at = cursor
68
+ cursor += 1
69
+ const store = slot(at)
70
+ if (!('value' in store)) store.value = typeof initial === 'function' ? initial() : initial
71
+ return [
72
+ store.value,
73
+ (next) => {
74
+ store.value = typeof next === 'function' ? next(store.value) : next
75
+ scheduleRender()
76
+ },
77
+ ]
78
+ },
79
+ useRef(initial) {
80
+ const at = cursor
81
+ cursor += 1
82
+ const store = slot(at)
83
+ if (store.ref === undefined) store.ref = { current: initial }
84
+ return store.ref
85
+ },
86
+ useEffect(run, deps) {
87
+ const at = cursor
88
+ cursor += 1
89
+ const store = slot(at)
90
+ const previous = store.deps
91
+ const changed =
92
+ previous === undefined ||
93
+ deps === undefined ||
94
+ deps.length !== previous.length ||
95
+ deps.some((value, i) => !Object.is(value, previous[i]))
96
+ if (!changed) return
97
+ store.deps = deps
98
+ // Cleanup belongs to the effect that installed it, not to the slot.
99
+ const effect = { run }
100
+ if (typeof store.cleanup === 'function') effect.cleanup = store.cleanup
101
+ store.cleanup = undefined
102
+ pendingEffects.push(effect)
103
+ store.effect = effect
104
+ },
105
+ }
106
+
107
+ // ------------------------------------------------------------- DOM stubs
108
+
109
+ const storage = new Map()
110
+ const listeners = []
111
+
112
+ // The interval the polling effect installs is never fired: this test drives
113
+ // renders through the controls, not through the clock.
114
+ globalThis.window = {
115
+ localStorage: {
116
+ getItem: (key) => (storage.has(key) ? storage.get(key) : null),
117
+ setItem: (key, value) => storage.set(key, String(value)),
118
+ removeItem: (key) => storage.delete(key),
119
+ },
120
+ setInterval: () => 1,
121
+ clearInterval: () => {},
122
+ addEventListener: (type, listener) => listeners.push({ type, listener }),
123
+ innerWidth: 1440,
124
+ innerHeight: 900,
125
+ }
126
+
127
+ globalThis.document = {
128
+ querySelector: () => null,
129
+ querySelectorAll: () => [],
130
+ createElement: () => ({ setAttribute() {}, remove() {}, style: {} }),
131
+ head: { appendChild() {} },
132
+ }
133
+
134
+ // ------------------------------------------------------------ board data
135
+
136
+ const CWD = 'D:\\DSH\\plugin'
137
+ const DIR_KEY = CWD.replace(/\//g, '\\').replace(/\\+$/, '').toLowerCase()
138
+
139
+ function todo(over) {
140
+ return {
141
+ id: 'x',
142
+ title: 'x',
143
+ dir: DIR_KEY,
144
+ dirPath: CWD,
145
+ dirLabel: 'plugin',
146
+ mode: 'resume',
147
+ aiDone: false,
148
+ verified: false,
149
+ note: '',
150
+ images: [],
151
+ schedule: '',
152
+ dueAt: 0,
153
+ remindedAt: 0,
154
+ order: 0,
155
+ sourceSessionId: 's1',
156
+ sourceSessionTitle: '会话',
157
+ dispatchedAt: 0,
158
+ runSessionId: '',
159
+ createdAt: 1,
160
+ updatedAt: 1,
161
+ ...over,
162
+ }
163
+ }
164
+
165
+ const snapshot = {
166
+ ok: true,
167
+ storagePath: 'D:\\DSH\\dsh-home\\todo-board\\board.json',
168
+ todos: [
169
+ todo({ id: 'a', title: '下一条要做的', order: 0 }),
170
+ todo({ id: 'b', title: 'AI 已做完的', order: 1, aiDone: true }),
171
+ todo({ id: 'c', title: '已验收的', order: 2, verified: true }),
172
+ ],
173
+ }
174
+
175
+ globalThis.fetch = async () => ({ ok: true, status: 200, json: async () => snapshot })
176
+
177
+ // ----------------------------------------------------- load the client half
178
+
179
+ let factory = null
180
+ globalThis.window.__ModuleLoader__ = {
181
+ load(entry) {
182
+ factory = entry.factory
183
+ },
184
+ }
185
+
186
+ const clientUrl = new URL('../client/client.js', import.meta.url)
187
+ await import(clientUrl.href)
188
+ assert.ok(factory !== null, 'client.js registered itself with the module loader')
189
+
190
+ const exports_ = factory((name) => {
191
+ if (name === 'react') return React
192
+ throw new Error('unexpected require: ' + name)
193
+ })
194
+ assert.equal(exports_.name, 'dsh-todo-board')
195
+
196
+ // ------------------------------------------------------------ render tree
197
+
198
+ const TodoBoard = (() => {
199
+ // The component is not exported; it is the slot target `apply()` registers.
200
+ let captured = null
201
+ exports_.apply({
202
+ effect: (callback) => {
203
+ callback()
204
+ return () => {}
205
+ },
206
+ slots: {
207
+ inject: (_name, register) => register(),
208
+ register: (_options, component) => {
209
+ captured = component
210
+ },
211
+ },
212
+ })
213
+ assert.ok(captured !== null, 'apply() registered the overlay component')
214
+ return captured
215
+ })()
216
+
217
+ function findByClass(node, className) {
218
+ const out = []
219
+ const walk = (current) => {
220
+ if (current === null || current === undefined || typeof current !== 'object') return
221
+ const cls = current.props?.className
222
+ if (typeof cls === 'string' && cls.split(/\s+/).includes(className)) out.push(current)
223
+ if (Array.isArray(current.children)) for (const child of current.children) walk(child)
224
+ }
225
+ walk(node)
226
+ return out
227
+ }
228
+
229
+ function textOf(node) {
230
+ if (typeof node === 'string' || typeof node === 'number') return String(node)
231
+ if (node === null || node === undefined || typeof node !== 'object') return ''
232
+ return node.children.map(textOf).join('')
233
+ }
234
+
235
+ function findByText(node, needle) {
236
+ const out = []
237
+ const walk = (current) => {
238
+ if (current === null || current === undefined || typeof current !== 'object') return
239
+ if (textOf(current).includes(needle)) out.push(current)
240
+ if (Array.isArray(current.children)) for (const child of current.children) walk(child)
241
+ }
242
+ walk(node)
243
+ return out
244
+ }
245
+
246
+ function render() {
247
+ cursor = 0
248
+ rendering = true
249
+ let tree
250
+ try {
251
+ tree = TodoBoard({
252
+ useSessions: (select) => select({ current: 's1', byId: { s1: { cwd: CWD, title: '会话' } } }),
253
+ })
254
+ } finally {
255
+ rendering = false
256
+ }
257
+ flushEffects()
258
+ return tree
259
+ }
260
+
261
+ function click(node) {
262
+ assert.equal(typeof node.props.onClick, 'function', 'the node is clickable')
263
+ node.props.onClick({ preventDefault() {}, stopPropagation() {} })
264
+ return render()
265
+ }
266
+
267
+ function sectionButton(tree, label) {
268
+ const found = findByClass(tree, 'dshtb-sect').filter((node) => textOf(node).includes(label))
269
+ assert.equal(found.length, 1, 'exactly one section header reads ' + label)
270
+ return found[0]
271
+ }
272
+
273
+ // ------------------------------------------------------------- assertions
274
+
275
+ let tree = render()
276
+ // Let the polling effect's fetch settle and re-render with real data.
277
+ await new Promise((resolve) => setTimeout(resolve, 0))
278
+ tree = render()
279
+
280
+ assert.equal(findByClass(tree, 'dshtb-card').length, 1, 'the expanded panel renders')
281
+ assert.equal(
282
+ findByClass(tree, 'dshtb-add').length,
283
+ 1,
284
+ 'the composer is visible by default',
285
+ )
286
+ assert.deepEqual(
287
+ findByClass(tree, 'dshtb-sect').map((node) => textOf(node).replace(/[▾▸]/g, '')),
288
+ ['新增待办', '待办列表 3', '面板'],
289
+ 'the three sections are labelled with their own state',
290
+ )
291
+ console.log('render OK')
292
+
293
+ // -- folding a section away keeps its header as the way back ---------------
294
+
295
+ tree = click(sectionButton(tree, '新增待办'))
296
+ assert.equal(findByClass(tree, 'dshtb-add').length, 0, 'the folded composer is gone')
297
+ assert.equal(
298
+ sectionButton(tree, '新增待办').props['aria-expanded'],
299
+ 'false',
300
+ 'the section header reports the folded state',
301
+ )
302
+ assert.ok(
303
+ JSON.parse(storage.get('dsh.todoBoard.sections.v1')).compose === false,
304
+ 'the folded section is persisted',
305
+ )
306
+
307
+ // The list folds the same way, and its header carries the row count.
308
+ tree = click(sectionButton(tree, '待办列表'))
309
+ assert.equal(findByClass(tree, 'dshtb-list').length, 0, 'the folded list is gone')
310
+ assert.ok(
311
+ textOf(sectionButton(tree, '待办列表')).includes('待办列表 3'),
312
+ 'the folded list header keeps its count',
313
+ )
314
+
315
+ // Unfolding restores it.
316
+ tree = click(sectionButton(tree, '待办列表'))
317
+ assert.equal(findByClass(tree, 'dshtb-list').length, 1, 'unfolding brings the list back')
318
+ console.log('sections OK')
319
+
320
+ // -- the title-bar button is not eaten by the drag handle -----------------
321
+
322
+ const head = findByClass(tree, 'dshtb-head')[0]
323
+ let captures = 0
324
+ head.props.onPointerDown({
325
+ button: 0,
326
+ pointerId: 1,
327
+ clientX: 0,
328
+ clientY: 0,
329
+ target: { closest: () => ({}) },
330
+ currentTarget: {
331
+ closest: () => ({ getBoundingClientRect: () => ({ left: 0, top: 0, width: 380, height: 500 }) }),
332
+ setPointerCapture: () => {
333
+ captures += 1
334
+ },
335
+ },
336
+ preventDefault() {},
337
+ })
338
+ assert.equal(captures, 0, 'pressing a button in the title bar never starts a drag')
339
+
340
+ head.props.onPointerDown({
341
+ button: 0,
342
+ pointerId: 1,
343
+ clientX: 0,
344
+ clientY: 0,
345
+ target: { closest: () => null },
346
+ currentTarget: {
347
+ closest: () => ({ getBoundingClientRect: () => ({ left: 0, top: 0, width: 380, height: 500 }) }),
348
+ setPointerCapture: () => {
349
+ captures += 1
350
+ },
351
+ },
352
+ preventDefault() {},
353
+ })
354
+ assert.equal(captures, 1, 'pressing the bar itself still starts a drag')
355
+ console.log('drag OK')
356
+
357
+ // -- parking the panel as one line ----------------------------------------
358
+
359
+ const fold = findByClass(tree, 'dshtb-fold')[0]
360
+ assert.equal(textOf(fold), '\u2013', 'the header carries a fold control')
361
+ tree = click(fold)
362
+ assert.equal(findByClass(tree, 'dshtb-card').length, 0, 'the parked panel drops the card')
363
+
364
+ const pill = findByClass(tree, 'dshtb-pill')[0]
365
+ assert.ok(pill !== undefined, 'the parked panel is one line')
366
+ const pillText = textOf(pill)
367
+ assert.ok(pillText.includes('TODO'), 'the line names the board')
368
+ assert.ok(pillText.includes('2'), 'the line counts the 2 unfinished todos')
369
+ assert.ok(pillText.includes('待验 1'), 'the line counts the 1 todo awaiting verification')
370
+ assert.ok(pillText.includes('下一条 · 下一条要做的'), 'the line shows the next todo, not a finished one')
371
+
372
+ // The line itself is the way back.
373
+ tree = click(pill)
374
+ assert.equal(findByClass(tree, 'dshtb-card').length, 1, 'clicking the line unfolds the panel')
375
+ console.log('park OK')
376
+
377
+ // -- an empty board still parks as one line -------------------------------
378
+
379
+ snapshot.todos = [todo({ id: 'c', title: '已验收的', verified: true })]
380
+ await new Promise((resolve) => setTimeout(resolve, 0))
381
+ tree = render()
382
+ tree = click(findByClass(tree, 'dshtb-fold')[0])
383
+ assert.ok(
384
+ textOf(findByClass(tree, 'dshtb-pill')[0]).includes('当前目录已清空'),
385
+ 'an empty board says so instead of naming a task',
386
+ )
387
+ console.log('empty OK')
388
+
389
+ console.log('\nall browser-half smoke checks passed')