dsh-dispatch-board 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -57,6 +57,8 @@ window.__ModuleLoader__.load({
57
57
  doing: '#f0a24a',
58
58
  done: '#22b573',
59
59
  archived: '#98a2b3',
60
+ // v0.2.2:「待你处理」不是 status,只作为第五列的强调色(红)。
61
+ needsUser: '#e5484d',
60
62
  }
61
63
 
62
64
  /* ══════════════════════════════════════════════════════════════
@@ -268,6 +270,38 @@ window.__ModuleLoader__.load({
268
270
  '.tb-page[data-narrow=true] .tb-lead-label{max-width:160px}',
269
271
 
270
272
 
273
+ // ── 待你处理(v0.2.2,§1.9)────────────────────────────────
274
+ // 右栏顶部条:只在有 flagged 任务时渲染;这些任务不重复出现在下面的 lane / 四列。
275
+ '.tb-needs{position:sticky;top:0;z-index:3;display:flex;flex-direction:column;gap:6px;padding:9px 10px;border:1px solid color-mix(in srgb,var(--dsw-alias-state-error-primary) 38%,transparent);border-radius:var(--dsw-radius-md);background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 7%,var(--dsw-alias-bg-base))}',
276
+ '.tb-needs-head{display:flex;align-items:center;gap:6px}',
277
+ '.tb-needs-dot{width:7px;height:7px;border-radius:50%;background:var(--dsw-alias-state-error-primary);flex:0 0 auto}',
278
+ '.tb-needs-name{font:var(--dsw-font-xxs-strong-12);font-weight:600}',
279
+ '.tb-needs-count{min-width:18px;height:18px;padding:0 5px;display:inline-flex;align-items:center;justify-content:center;border-radius:999px;background:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-label-primary-foreground);font:var(--dsw-font-xxxs-strong-11);font-variant-numeric:tabular-nums}',
280
+ '.tb-needs-list{display:flex;flex-direction:column;gap:4px}',
281
+ '.tb-needs-item{display:flex;flex-direction:column;gap:1px;width:100%;padding:5px 7px;text-align:left;border:0;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-primary);cursor:pointer;font:inherit}',
282
+ '.tb-needs-item:hover{background:var(--dsw-alias-interactive-bg-hover)}',
283
+ '.tb-needs-item:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
284
+ '.tb-needs-title{font:var(--dsw-font-xxs-strong-12);font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
285
+ '.tb-needs-q{font:var(--dsw-font-xxxs-11);color:var(--dsw-alias-label-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
286
+ // 平台看板第五列(放在「待开始」之前;没有 flagged 任务时整列不渲染,仍是四列)。
287
+ '.tb-board[data-needs=true]{grid-template-columns:repeat(5,minmax(0,1fr))}',
288
+ '.tb-col[data-status=needsUser]{border:1px solid color-mix(in srgb,var(--dsw-alias-state-error-primary) 30%,transparent);border-radius:var(--dsw-radius-md);padding:9px 9px 11px;background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 5%,var(--dsw-alias-bg-layer-1))}',
289
+ '.tb-needs-card-q{margin:4px 0 0;font:var(--dsw-font-xxxs-11);line-height:1.5;color:var(--dsw-alias-label-secondary);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;word-break:break-word}',
290
+ '.tb-needs-card .tb-card-actions{margin-top:6px}',
291
+ // 详情浮层的「需要你处理」区(问题 / 选项 / 自由输入 / 回复并继续 / 最近回答)。
292
+ '.tb-detail-needs{border:1px solid color-mix(in srgb,var(--dsw-alias-state-error-primary) 35%,transparent);border-radius:var(--dsw-radius-md);padding:9px 11px;background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 6%,transparent);gap:7px}',
293
+ '.tb-needs-question{margin:0;font:var(--dsw-font-xs-12);line-height:1.6;white-space:pre-wrap;word-break:break-word}',
294
+ '.tb-needs-options{display:flex;flex-wrap:wrap;gap:6px}',
295
+ '.tb-answer{min-height:60px;height:auto}',
296
+ '.tb-detail-needs-actions{display:flex;justify-content:flex-end;gap:8px}',
297
+ '.tb-needs-error{margin:0;font:var(--dsw-font-xxxs-11);color:var(--dsw-alias-state-error-primary)}',
298
+ '.tb-needs-hint{margin:0;font:var(--dsw-font-xxxs-11);color:var(--dsw-alias-label-tertiary)}',
299
+ '.tb-detail-lastanswer{margin:0;padding:6px 8px;border-radius:6px;background:var(--dsw-alias-bg-skeleton);font:var(--dsw-font-xxxs-11);color:var(--dsw-alias-label-secondary);white-space:pre-wrap;word-break:break-word}',
300
+ // 独立红色角标:与 todo 角标同一形状,放在按钮 / 图标的另一角,不抢 todo 数字。
301
+ '.tb-badge-needs{top:auto;bottom:-3px;right:-5px;background:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-label-primary-foreground)}',
302
+ '.tb-page[data-layout=narrow] .tb-needs{padding:7px 8px}',
303
+ '.tb-page[data-layout=narrow] .tb-needs-item{padding:4px 5px}',
304
+
271
305
  // ── Apple 风格皮肤(最后追加,覆盖上面的基础样式)──────────
272
306
  // 设计参照 macOS / iOS:灰色画布 + 白色卡片、发丝分隔线、胶囊按钮、系统字体、柔和阴影。
273
307
  // 颜色全部走宿主主题 token,深色模式自动跟随。
@@ -567,6 +601,21 @@ window.__ModuleLoader__.load({
567
601
  'lead.ensureOk': '已创建工作区组长',
568
602
  'detail.lead': '组长',
569
603
  'detail.noLead': '(还没有组长)',
604
+
605
+ // v0.2.2「待你处理」(§1.9):组长提问 → 看板提示 → 用户回答 → 任务继续
606
+ 'column.needsUser': '待你处理',
607
+ 'needsUser.title': '需要你处理',
608
+ 'needsUser.question': '需要你回答的问题',
609
+ 'needsUser.answerPlaceholder': '输入你的回答(≤{max} 字)…',
610
+ 'needsUser.submit': '回复并继续',
611
+ 'needsUser.badge': '{n} 条待你处理',
612
+ 'needsUser.open': '处理',
613
+ 'needsUser.lastAnswer': '最近回答',
614
+ 'needsUser.answerOk': '已回复,任务继续处理',
615
+ 'needsUser.answerFailed': '回复发送失败:{message}',
616
+ 'needsUser.answerEmpty': '先写回答再提交',
617
+ 'needsUser.answerTooLong': '回答不能超过 {max} 字',
618
+ 'needsUser.pickOption': '点上面的选项可以填入输入框,也可以自己写。',
570
619
  }
571
620
 
572
621
  const DICT_EN = {
@@ -735,6 +784,21 @@ window.__ModuleLoader__.load({
735
784
  'lead.ensureOk': 'Workspace lead created',
736
785
  'detail.lead': 'Lead',
737
786
  'detail.noLead': '(no lead yet)',
787
+
788
+ // v0.2.2 needs-user loop (§1.9)
789
+ 'column.needsUser': 'Needs you',
790
+ 'needsUser.title': 'Needs your answer',
791
+ 'needsUser.question': 'Question for you',
792
+ 'needsUser.answerPlaceholder': 'Type your answer (≤{max} chars)…',
793
+ 'needsUser.submit': 'Reply and continue',
794
+ 'needsUser.badge': '{n} waiting for you',
795
+ 'needsUser.open': 'Answer',
796
+ 'needsUser.lastAnswer': 'Last answer',
797
+ 'needsUser.answerOk': 'Answer sent; the task continues',
798
+ 'needsUser.answerFailed': 'Could not send the answer: {message}',
799
+ 'needsUser.answerEmpty': 'Write an answer first',
800
+ 'needsUser.answerTooLong': 'The answer must be at most {max} chars',
801
+ 'needsUser.pickOption': 'Click an option to fill the box, or write your own answer.',
738
802
  }
739
803
 
740
804
  function detectLang(locale) {
@@ -1534,6 +1598,36 @@ window.__ModuleLoader__.load({
1534
1598
  return groups
1535
1599
  }
1536
1600
 
1601
+ /**
1602
+ * v0.2.2(§1.9):派生「待你处理」任务列表——`needsUser === true`、排除已归档,
1603
+ * 按 `askedAt` 升序(等得最久的排最前;缺 / 坏 `askedAt` 的排最后,再按 id)。
1604
+ */
1605
+ function needsUserTasks(tasks) {
1606
+ return (Array.isArray(tasks) ? tasks : [])
1607
+ .filter((task) => task && task.needsUser === true && task.status !== 'archived')
1608
+ .slice()
1609
+ .sort((a, b) => {
1610
+ const at = Date.parse(typeof a.askedAt === 'string' ? a.askedAt : '')
1611
+ const bt = Date.parse(typeof b.askedAt === 'string' ? b.askedAt : '')
1612
+ const aOk = Number.isFinite(at)
1613
+ const bOk = Number.isFinite(bt)
1614
+ if (aOk && bOk && at !== bt) return at - bt
1615
+ if (aOk !== bOk) return aOk ? -1 : 1
1616
+ return String(a.id).localeCompare(String(b.id))
1617
+ })
1618
+ }
1619
+
1620
+ /**
1621
+ * v0.2.2:普通四列 / lane 用的任务——未归档的 flagged 任务只在「待你处理」区出现,不重复;
1622
+ * 已归档的 flagged 任务不在「待你处理」派生列表里(needsUserTasks 排除 archived),
1623
+ * 所以照常留在「已归档」列,避免任务凭空消失。
1624
+ */
1625
+ function withoutNeedsUser(tasks) {
1626
+ return (Array.isArray(tasks) ? tasks : []).filter(
1627
+ (task) => !task || task.needsUser !== true || task.status === 'archived',
1628
+ )
1629
+ }
1630
+
1537
1631
  function errorText(t, error) {
1538
1632
  if (!error || typeof error !== 'object') return t('error.internal')
1539
1633
  const code = error.code || 'internal'
@@ -1886,6 +1980,8 @@ window.__ModuleLoader__.load({
1886
1980
  // 顺手记下当前对话 id(幂等赋值):根作用域的平台看板靠它绑定主会话,拿不到就禁用按钮。
1887
1981
  if (sessionId !== '') lastConversationSessionId = sessionId
1888
1982
  const [pending, setPending] = useState(-1)
1983
+ // v0.2.2(§1.9):待你处理数量单独一个红色角标(与 todo 角标并存、互不干扰)。
1984
+ const [needsCount, setNeedsCount] = useState(-1)
1889
1985
  // 按钮打开的是「本工作区看板」,角标也按本工作区数;拿不到工作区(冷会话)时退回全平台数。
1890
1986
  const cwdRef = useRef('')
1891
1987
 
@@ -1910,14 +2006,24 @@ window.__ModuleLoader__.load({
1910
2006
  callRpc('snapshot', {}).then((res) => {
1911
2007
  if (!alive) return
1912
2008
  if (!res.ok || !res.value || !Array.isArray(res.value.tasks)) return
1913
- const workspace = cwdRef.current
2009
+ // 与右栏看板(banner / 四列)用同一个过滤:cwd 属于本工作区,或任务创建于本对话。
2010
+ // 只按 cwd 过滤会让「banner 有、header 角标为 0」——旧任务 / 工具建的任务可能没有 cwd。
2011
+ // sessionId 缺失(理论上宿主不会这样渲染)时退回全量,与旧行为一致。
2012
+ const visible =
2013
+ sessionId === '' ? res.value.tasks : tasksForWorkspace(res.value.tasks, cwdRef.current, sessionId)
1914
2014
  let count = 0
1915
- for (const task of res.value.tasks) {
2015
+ let needs = 0
2016
+ for (const task of visible) {
2017
+ // flagged 任务算「待你处理」,不算 todo 待办(两枚角标不重复计数)。
2018
+ if (task.needsUser === true && task.status !== 'archived') {
2019
+ needs += 1
2020
+ continue
2021
+ }
1916
2022
  if (task.status !== 'todo') continue
1917
- if (workspace !== '' && !samePath(task.cwd, workspace)) continue
1918
2023
  count += 1
1919
2024
  }
1920
2025
  setPending(count)
2026
+ setNeedsCount(needs)
1921
2027
  })
1922
2028
  }
1923
2029
  read()
@@ -1929,7 +2035,11 @@ window.__ModuleLoader__.load({
1929
2035
  }, [])
1930
2036
 
1931
2037
  const badge = pending > 0 ? (pending > 99 ? '99+' : String(pending)) : null
1932
- const tip = t('panel.label') + (pending > 0 ? ' · ' + t('badge.label', { n: pending }) : '')
2038
+ const needsBadge = needsCount > 0 ? (needsCount > 99 ? '99+' : String(needsCount)) : null
2039
+ const tip =
2040
+ t('panel.label') +
2041
+ (pending > 0 ? ' · ' + t('badge.label', { n: pending }) : '') +
2042
+ (needsCount > 0 ? ' · ' + t('needsUser.badge', { n: needsCount }) : '')
1933
2043
 
1934
2044
  return h(
1935
2045
  'button',
@@ -1944,6 +2054,9 @@ window.__ModuleLoader__.load({
1944
2054
  },
1945
2055
  h(BoardGlyph, { size: 16 }),
1946
2056
  badge === null ? null : h('span', { className: 'tb-badge', 'aria-hidden': 'true' }, badge),
2057
+ needsBadge === null
2058
+ ? null
2059
+ : h('span', { className: 'tb-badge tb-badge-needs', 'aria-hidden': 'true' }, needsBadge),
1947
2060
  )
1948
2061
  }
1949
2062
 
@@ -2073,6 +2186,113 @@ window.__ModuleLoader__.load({
2073
2186
  )
2074
2187
  }
2075
2188
 
2189
+ /**
2190
+ * 右栏看板顶部的「待你处理」条(v0.2.2,§1.9):只读 bind.needsUserTasks,
2191
+ * 空列表返回 null(整块不渲染,不是空态盒子)。点条目打开详情浮层的回答区。
2192
+ */
2193
+ function NeedsBanner() {
2194
+ const t = bind.t
2195
+ const list = Array.isArray(bind.needsUserTasks) ? bind.needsUserTasks : []
2196
+ if (list.length === 0) return null
2197
+ const actions = bind.actions
2198
+ return h(
2199
+ 'section',
2200
+ { className: 'tb-needs', role: 'region', 'aria-label': t('column.needsUser') },
2201
+ h(
2202
+ 'header',
2203
+ { className: 'tb-needs-head' },
2204
+ h('span', { className: 'tb-needs-dot', 'aria-hidden': 'true' }),
2205
+ h('span', { className: 'tb-needs-name' }, t('column.needsUser')),
2206
+ h('span', { className: 'tb-needs-count' }, String(list.length)),
2207
+ ),
2208
+ h(
2209
+ 'div',
2210
+ { className: 'tb-needs-list' },
2211
+ list.map((task) =>
2212
+ h(
2213
+ 'button',
2214
+ {
2215
+ key: task.id,
2216
+ type: 'button',
2217
+ className: 'tb-needs-item',
2218
+ title: (task.title || '') + '\n' + (task.question || ''),
2219
+ onClick: () => actions.openDetail(task),
2220
+ },
2221
+ h('span', { className: 'tb-needs-title' }, task.title || ''),
2222
+ h('span', { className: 'tb-needs-q' }, task.question || ''),
2223
+ ),
2224
+ ),
2225
+ ),
2226
+ )
2227
+ }
2228
+
2229
+ /**
2230
+ * 平台看板的第五列「待你处理」(v0.2.2,§1.9):放在「待开始」之前,仅非空时由调用方渲染。
2231
+ * 卡片显示标题 + 问题一行 + 「处理」按钮(需要用户阅读,是纯标题卡的例外);
2232
+ * 点标题 / 「处理」都打开详情浮层的回答区。
2233
+ */
2234
+ function NeedsColumn(props) {
2235
+ const t = bind.t
2236
+ const list = props && Array.isArray(props.tasks) ? props.tasks : []
2237
+ const actions = bind.actions
2238
+ return h(
2239
+ 'section',
2240
+ {
2241
+ className: 'tb-col tb-needs-col',
2242
+ 'data-status': 'needsUser',
2243
+ 'aria-label': t('column.needsUser'),
2244
+ },
2245
+ h(
2246
+ 'header',
2247
+ { className: 'tb-colhead', style: { '--tb-accent': STATUS_ACCENT.needsUser } },
2248
+ h('span', { className: 'tb-coldot', 'aria-hidden': 'true' }),
2249
+ h('span', { className: 'tb-colname' }, t('column.needsUser')),
2250
+ h('span', { className: 'tb-colcount' }, String(list.length)),
2251
+ ),
2252
+ h(
2253
+ 'div',
2254
+ { className: 'tb-cards' },
2255
+ list.map((task) =>
2256
+ h(
2257
+ 'article',
2258
+ {
2259
+ key: task.id,
2260
+ className: 'tb-card tb-card-fixed tb-needs-card',
2261
+ style: { '--tb-accent': STATUS_ACCENT.needsUser },
2262
+ },
2263
+ h(
2264
+ 'div',
2265
+ {
2266
+ className: 'tb-card-title tb-card-titlebtn',
2267
+ role: 'button',
2268
+ tabIndex: 0,
2269
+ title: task.title,
2270
+ onClick: () => actions.openDetail(task),
2271
+ onKeyDown: (event) => {
2272
+ if (event.key === 'Enter' || event.key === ' ') {
2273
+ event.preventDefault()
2274
+ actions.openDetail(task)
2275
+ }
2276
+ },
2277
+ },
2278
+ task.title,
2279
+ ),
2280
+ h('div', { className: 'tb-needs-card-q', title: task.question || '' }, task.question || ''),
2281
+ h(
2282
+ 'div',
2283
+ { className: 'tb-card-actions' },
2284
+ h(
2285
+ 'button',
2286
+ { type: 'button', className: 'tb-btn tb-btn-sm tb-btn-primary', onClick: () => actions.openDetail(task) },
2287
+ t('needsUser.open'),
2288
+ ),
2289
+ ),
2290
+ ),
2291
+ ),
2292
+ ),
2293
+ )
2294
+ }
2295
+
2076
2296
  function Card(props) {
2077
2297
  const t = bind.t
2078
2298
  const busy = bind.busy
@@ -2215,6 +2435,11 @@ window.__ModuleLoader__.load({
2215
2435
  attachmentLoadingText: t('detail.imageLoading'),
2216
2436
  attachmentFailedText: t('detail.imageFailed'),
2217
2437
  }
2438
+ // v0.2.2「待你处理」:回答区读看板组件的草稿 / 错误 / 忙态(浮层不持有 state)。
2439
+ const needsOptions = task.needsUser === true && Array.isArray(task.questionOptions) ? task.questionOptions : []
2440
+ const answerDraft = typeof bind.answerDraft === 'string' ? bind.answerDraft : ''
2441
+ const answerError = typeof bind.answerError === 'string' ? bind.answerError : ''
2442
+ const answerBusyKey = 'answer:' + task.id
2218
2443
  const metaRows = [
2219
2444
  [t('detail.workspace'), task.cwd || '—'],
2220
2445
  [t('detail.lead'), taskLeadLabel(task) || t('detail.noLead')],
@@ -2294,6 +2519,68 @@ window.__ModuleLoader__.load({
2294
2519
  h(
2295
2520
  'div',
2296
2521
  { className: 'tb-detail-body' },
2522
+ // v0.2.2「待你处理」:问题 / 选项 / 自由输入 / 回复并继续 / 最近回答(§1.9)。
2523
+ // 草稿与错误状态放在看板组件里(经 bind 传入),浮层本身不调 hooks。
2524
+ task.needsUser
2525
+ ? h(
2526
+ 'section',
2527
+ { className: 'tb-detail-section tb-detail-needs' },
2528
+ h('h3', { className: 'tb-detail-sub' }, t('needsUser.title')),
2529
+ h('p', { className: 'tb-needs-question', 'aria-label': t('needsUser.question') }, task.question || ''),
2530
+ needsOptions.length > 0
2531
+ ? h(
2532
+ 'div',
2533
+ { className: 'tb-needs-options' },
2534
+ needsOptions.map((option) =>
2535
+ h(
2536
+ 'button',
2537
+ {
2538
+ key: option,
2539
+ type: 'button',
2540
+ className: 'tb-btn tb-btn-sm',
2541
+ disabled: bind.busy === answerBusyKey,
2542
+ onClick: () => bind.actions.setAnswerDraft(option),
2543
+ },
2544
+ option,
2545
+ ),
2546
+ ),
2547
+ )
2548
+ : null,
2549
+ h('textarea', {
2550
+ className: 'tb-textarea tb-answer',
2551
+ placeholder: t('needsUser.answerPlaceholder', { max: 1000 }),
2552
+ 'aria-label': t('needsUser.answerPlaceholder', { max: 1000 }),
2553
+ value: answerDraft,
2554
+ onChange: (event) => bind.actions.setAnswerDraft(event.target.value),
2555
+ }),
2556
+ answerError ? h('p', { className: 'tb-needs-error', role: 'alert' }, answerError) : null,
2557
+ h('p', { className: 'tb-needs-hint' }, t('needsUser.pickOption')),
2558
+ h(
2559
+ 'div',
2560
+ { className: 'tb-detail-needs-actions' },
2561
+ h(
2562
+ 'button',
2563
+ {
2564
+ type: 'button',
2565
+ className: 'tb-btn tb-btn-sm tb-btn-primary',
2566
+ disabled: bind.busy === answerBusyKey || answerDraft.trim() === '',
2567
+ onClick: () => bind.actions.submitAnswer(task.id),
2568
+ },
2569
+ t('needsUser.submit'),
2570
+ ),
2571
+ ),
2572
+ )
2573
+ : null,
2574
+ // v0.2.2:回答留档不依赖当前是否 flagged——回答成功后 needsUser 已清,
2575
+ // 详情仍要能看到「最近回答」(组长 / 用户回看任务时的重要上下文)。
2576
+ task.lastAnswer
2577
+ ? h(
2578
+ 'section',
2579
+ { className: 'tb-detail-section tb-detail-answer' },
2580
+ h('h3', { className: 'tb-detail-sub' }, t('needsUser.lastAnswer')),
2581
+ h('p', { className: 'tb-detail-lastanswer' }, task.lastAnswer),
2582
+ )
2583
+ : null,
2297
2584
  h(
2298
2585
  'section',
2299
2586
  { className: 'tb-detail-section' },
@@ -2558,7 +2845,7 @@ window.__ModuleLoader__.load({
2558
2845
  return h('div', { className: 'tb-leads', role: 'group', 'aria-label': t('lead.barLabel') }, cells)
2559
2846
  }
2560
2847
 
2561
- return { Banner, Col, Detail, LeadBar }
2848
+ return { Banner, Col, Detail, LeadBar, NeedsBanner, NeedsColumn }
2562
2849
  }
2563
2850
 
2564
2851
  /* ── 看板页 ─────────────────────────────────────────────── */
@@ -2589,6 +2876,9 @@ window.__ModuleLoader__.load({
2589
2876
  const [busy, setBusy] = useState('')
2590
2877
  const [confirmDeleteId, setConfirmDeleteId] = useState(null)
2591
2878
  const [detailId, setDetailId] = useState(null)
2879
+ // v0.2.2「待你处理」:回答草稿 / 行内错误(详情浮层只读,不持有 state)。
2880
+ const [answerDraft, setAnswerDraft] = useState('')
2881
+ const [answerError, setAnswerError] = useState('')
2592
2882
  // createBoardPieces 的稳定 bind / 组件缓存(避免轮询刷新时组件重建导致浮层闪烁)
2593
2883
  const boardBindRef = useRef(null)
2594
2884
  const boardPiecesRef = useRef(null)
@@ -2691,13 +2981,18 @@ window.__ModuleLoader__.load({
2691
2981
  // 右栏 = 本工作区看板:只显示 cwd 与当前工作区相同(归一化比较)的任务;
2692
2982
  // 工作区未知(历史会话 / 缺 cwd)时给说明条并显示空看板。
2693
2983
  const workspaceTitle = cwdForHint ? workspaceTitleOf(workspaces, cwdForHint) : ''
2694
- const tasks = tasksForWorkspace(allTasks, cwdForHint, sessionId)
2984
+ // v0.2.2(§1.9):flagged 任务只在顶部「待你处理」条显示,不进普通四列 / lane。
2985
+ // 条与四列都用本工作区可见任务(与看板范围一致)。
2986
+ const workspaceTasks = tasksForWorkspace(allTasks, cwdForHint, sessionId)
2987
+ const needsUser = needsUserTasks(workspaceTasks)
2988
+ const tasks = withoutNeedsUser(workspaceTasks)
2989
+ const plainTasks = withoutNeedsUser(allTasks)
2695
2990
  // 有些旧任务/别的会话建的任务没有 cwd,本面板按设计不显示;给个去处,避免「任务凭空消失」。
2696
2991
  const detailTask = detailId ? allTasks.find((task) => task && task.id === detailId) || null : null
2697
- const doingAll = allTasks.filter((task) => task && task.status === 'doing')
2992
+ const doingAll = plainTasks.filter((task) => task && task.status === 'doing')
2698
2993
  const fallbackDispatchSessionId =
2699
2994
  poll && poll.lastDispatchSessionId && (poll.lastDispatchTaskId || doingAll.length === 1) ? poll.lastDispatchSessionId : ''
2700
- const unboundElsewhere = allTasks.filter(
2995
+ const unboundElsewhere = plainTasks.filter(
2701
2996
  (task) => task && !task.cwd && task.status !== 'archived' && task.sessionId !== sessionId,
2702
2997
  ).length
2703
2998
  const groups = groupTasks(tasks)
@@ -2784,6 +3079,37 @@ window.__ModuleLoader__.load({
2784
3079
  })
2785
3080
  }
2786
3081
 
3082
+ /**
3083
+ * v0.2.2(§1.9):提交回答。不用 run():错误要显示在详情浮层的回答区(而不是顶部条),
3084
+ * 失败时不关闭浮层、不丢输入;成功后关闭浮层、清草稿并刷新看板。
3085
+ */
3086
+ function submitAnswer(taskId) {
3087
+ const answer = String(answerDraft || '').trim()
3088
+ if (answer === '') {
3089
+ setAnswerError(t('needsUser.answerEmpty'))
3090
+ return
3091
+ }
3092
+ if (answer.length > 1000) {
3093
+ setAnswerError(t('needsUser.answerTooLong', { max: 1000 }))
3094
+ return
3095
+ }
3096
+ setAnswerError('')
3097
+ setBusy('answer:' + taskId)
3098
+ callRpc('answer-task', { id: taskId, answer }).then((res) => {
3099
+ if (!aliveRef.current) return
3100
+ setBusy('')
3101
+ if (!res.ok) {
3102
+ setAnswerError(t('needsUser.answerFailed', { message: errorText(t, res.error) }))
3103
+ return
3104
+ }
3105
+ setAnswerDraft('')
3106
+ setAnswerError('')
3107
+ setDetailId(null)
3108
+ setNotice({ tone: 'ok', text: t('needsUser.answerOk') })
3109
+ refresh()
3110
+ })
3111
+ }
3112
+
2787
3113
  function setConfig(patch) {
2788
3114
  run('config', () => callRpc('set-config', patch))
2789
3115
  }
@@ -2860,6 +3186,9 @@ window.__ModuleLoader__.load({
2860
3186
  isConfirmingDelete: (id) => confirmDeleteId === id,
2861
3187
  openDetail: (task) => {
2862
3188
  if (task) loadTaskAttachments(task, attachmentSourcesRef, setAttachmentSources)
3189
+ // v0.2.2:换一条任务就清掉上一条的回答草稿 / 错误,避免答案串台。
3190
+ setAnswerDraft('')
3191
+ setAnswerError('')
2863
3192
  setDetailId(task.id)
2864
3193
  },
2865
3194
  // 「对话」按钮传目标会话 id;仍兼容传任务对象的旧调用(取 dispatched → creator)。
@@ -2874,6 +3203,9 @@ window.__ModuleLoader__.load({
2874
3203
  saveEdit,
2875
3204
  setEditing,
2876
3205
  archiveDone,
3206
+ // v0.2.2「待你处理」:回答草稿由看板持有,浮层通过 bind.actions 读写。
3207
+ setAnswerDraft,
3208
+ submitAnswer,
2877
3209
  }
2878
3210
  if (boardBindRef.current === null) {
2879
3211
  boardBindRef.current = {
@@ -2901,11 +3233,17 @@ window.__ModuleLoader__.load({
2901
3233
  boardBindRef.current.leadRows = leadRows
2902
3234
  boardBindRef.current.currentSessionId = sessionId
2903
3235
  boardBindRef.current.leadActions = leadActions
3236
+ // v0.2.2「待你处理」:条 / 第五列的任务列表与回答草稿(每次渲染都刷新)。
3237
+ boardBindRef.current.needsUserTasks = needsUser
3238
+ boardBindRef.current.answerDraft = answerDraft
3239
+ boardBindRef.current.answerError = answerError
2904
3240
  if (boardPiecesRef.current === null) boardPiecesRef.current = createBoardPieces(boardBindRef.current)
2905
3241
  const Banner = boardPiecesRef.current.Banner
2906
3242
  const Col = boardPiecesRef.current.Col
2907
3243
  const Detail = boardPiecesRef.current.Detail
2908
3244
  const LeadBar = boardPiecesRef.current.LeadBar
3245
+ const NeedsBanner = boardPiecesRef.current.NeedsBanner
3246
+ const NeedsColumn = boardPiecesRef.current.NeedsColumn
2909
3247
 
2910
3248
  /* ── 顶部状态文案 ─────────────────────────────────────── */
2911
3249
 
@@ -3121,6 +3459,9 @@ window.__ModuleLoader__.load({
3121
3459
  ),
3122
3460
  ),
3123
3461
 
3462
+ // v0.2.2(§1.9):顶部「待你处理」条(仅非空时由组件自己返回 null)。
3463
+ h(NeedsBanner, { key: 'needs' }),
3464
+
3124
3465
  wide
3125
3466
  ? h(
3126
3467
  'div',
@@ -3145,7 +3486,11 @@ window.__ModuleLoader__.load({
3145
3486
  detailTask
3146
3487
  ? h(Detail, {
3147
3488
  task: detailTask,
3148
- onClose: () => setDetailId(null),
3489
+ onClose: () => {
3490
+ setDetailId(null)
3491
+ setAnswerDraft('')
3492
+ setAnswerError('')
3493
+ },
3149
3494
  onStatus: (status) => {
3150
3495
  setDetailId(null)
3151
3496
  updateTask(detailTask.id, { status })
@@ -3162,6 +3507,8 @@ window.__ModuleLoader__.load({
3162
3507
  function PlatformPanelIcon(props) {
3163
3508
  const size = props && typeof props.size === 'number' && props.size > 0 ? props.size : 18
3164
3509
  const [openCount, setOpenCount] = useState(-1)
3510
+ // v0.2.2(§1.9):待你处理数量单独一个红色角标。
3511
+ const [needsCount, setNeedsCount] = useState(-1)
3165
3512
 
3166
3513
  useEffect(() => {
3167
3514
  let alive = true
@@ -3171,10 +3518,17 @@ window.__ModuleLoader__.load({
3171
3518
  if (!alive) return
3172
3519
  if (!res.ok || !res.value || !Array.isArray(res.value.tasks)) return
3173
3520
  let count = 0
3521
+ let needs = 0
3174
3522
  for (const task of res.value.tasks) {
3523
+ // flagged 任务算「待你处理」,不算未完成待办(两枚角标不重复计数)。
3524
+ if (task.needsUser === true && task.status !== 'archived') {
3525
+ needs += 1
3526
+ continue
3527
+ }
3175
3528
  if (task.status === 'todo' || task.status === 'doing') count += 1
3176
3529
  }
3177
3530
  setOpenCount(count)
3531
+ setNeedsCount(needs)
3178
3532
  })
3179
3533
  }
3180
3534
  read()
@@ -3186,12 +3540,19 @@ window.__ModuleLoader__.load({
3186
3540
  }, [])
3187
3541
 
3188
3542
  const badge = openCount > 0 ? (openCount > 99 ? '99+' : String(openCount)) : null
3189
- const tip = t('platform.label') + (openCount > 0 ? ' · ' + t('badge.open', { n: openCount }) : '')
3543
+ const needsBadge = needsCount > 0 ? (needsCount > 99 ? '99+' : String(needsCount)) : null
3544
+ const tip =
3545
+ t('platform.label') +
3546
+ (openCount > 0 ? ' · ' + t('badge.open', { n: openCount }) : '') +
3547
+ (needsCount > 0 ? ' · ' + t('needsUser.badge', { n: needsCount }) : '')
3190
3548
  return h(
3191
3549
  'span',
3192
3550
  { className: 'tb-icon', title: tip },
3193
3551
  h(BoardGlyph, { size }),
3194
3552
  badge === null ? null : h('span', { className: 'tb-badge', 'aria-hidden': 'true' }, badge),
3553
+ needsBadge === null
3554
+ ? null
3555
+ : h('span', { className: 'tb-badge tb-badge-needs', 'aria-hidden': 'true' }, needsBadge),
3195
3556
  )
3196
3557
  }
3197
3558
 
@@ -3203,6 +3564,9 @@ window.__ModuleLoader__.load({
3203
3564
  const [busy, setBusy] = useState('')
3204
3565
  const [confirmDeleteId, setConfirmDeleteId] = useState(null)
3205
3566
  const [detailId, setDetailId] = useState(null)
3567
+ // v0.2.2「待你处理」:回答草稿 / 行内错误(详情浮层只读,不持有 state)。
3568
+ const [answerDraft, setAnswerDraft] = useState('')
3569
+ const [answerError, setAnswerError] = useState('')
3206
3570
  // createBoardPieces 的稳定 bind / 组件缓存(避免轮询刷新时组件重建导致浮层闪烁)
3207
3571
  const boardBindRef = useRef(null)
3208
3572
  const boardPiecesRef = useRef(null)
@@ -3277,9 +3641,12 @@ window.__ModuleLoader__.load({
3277
3641
  })
3278
3642
  }
3279
3643
 
3280
- const visibleTasks = tasksForFilter(allTasks, filterPath)
3644
+ const visibleAll = tasksForFilter(allTasks, filterPath)
3645
+ // v0.2.2(§1.9):flagged 任务只进最左第五列,不重复出现在普通四列。
3646
+ const needsUser = needsUserTasks(visibleAll)
3647
+ const visibleTasks = withoutNeedsUser(visibleAll)
3281
3648
  const groups = groupTasks(visibleTasks)
3282
- const doingAll = allTasks.filter((task) => task && task.status === 'doing')
3649
+ const doingAll = withoutNeedsUser(allTasks).filter((task) => task && task.status === 'doing')
3283
3650
  const fallbackDispatchSessionId =
3284
3651
  poll && poll.lastDispatchSessionId && (poll.lastDispatchTaskId || doingAll.length === 1) ? poll.lastDispatchSessionId : ''
3285
3652
  const detailTask = detailId ? allTasks.find((task) => task && task.id === detailId) || null : null
@@ -3370,6 +3737,37 @@ window.__ModuleLoader__.load({
3370
3737
  })
3371
3738
  }
3372
3739
 
3740
+ /**
3741
+ * v0.2.2(§1.9):提交回答。不用 run():错误要显示在详情浮层的回答区(而不是顶部条),
3742
+ * 失败时不关闭浮层、不丢输入;成功后关闭浮层、清草稿并刷新看板。
3743
+ */
3744
+ function submitAnswer(taskId) {
3745
+ const answer = String(answerDraft || '').trim()
3746
+ if (answer === '') {
3747
+ setAnswerError(t('needsUser.answerEmpty'))
3748
+ return
3749
+ }
3750
+ if (answer.length > 1000) {
3751
+ setAnswerError(t('needsUser.answerTooLong', { max: 1000 }))
3752
+ return
3753
+ }
3754
+ setAnswerError('')
3755
+ setBusy('answer:' + taskId)
3756
+ callRpc('answer-task', { id: taskId, answer }).then((res) => {
3757
+ if (!aliveRef.current) return
3758
+ setBusy('')
3759
+ if (!res.ok) {
3760
+ setAnswerError(t('needsUser.answerFailed', { message: errorText(t, res.error) }))
3761
+ return
3762
+ }
3763
+ setAnswerDraft('')
3764
+ setAnswerError('')
3765
+ setDetailId(null)
3766
+ setNotice({ tone: 'ok', text: t('needsUser.answerOk') })
3767
+ refresh()
3768
+ })
3769
+ }
3770
+
3373
3771
  function setConfig(patch) {
3374
3772
  run('config', () => callRpc('set-config', patch))
3375
3773
  }
@@ -3442,6 +3840,9 @@ window.__ModuleLoader__.load({
3442
3840
  isConfirmingDelete: (id) => confirmDeleteId === id,
3443
3841
  openDetail: (task) => {
3444
3842
  if (task) loadTaskAttachments(task, attachmentSourcesRef, setAttachmentSources)
3843
+ // v0.2.2:换一条任务就清掉上一条的回答草稿 / 错误,避免答案串台。
3844
+ setAnswerDraft('')
3845
+ setAnswerError('')
3445
3846
  setDetailId(task.id)
3446
3847
  },
3447
3848
  // 「对话」按钮传目标会话 id;仍兼容传任务对象的旧调用(取 dispatched → creator)。
@@ -3456,6 +3857,9 @@ window.__ModuleLoader__.load({
3456
3857
  saveEdit,
3457
3858
  setEditing,
3458
3859
  archiveDone,
3860
+ // v0.2.2「待你处理」:回答草稿由看板持有,浮层通过 bind.actions 读写。
3861
+ setAnswerDraft,
3862
+ submitAnswer,
3459
3863
  }
3460
3864
  if (boardBindRef.current === null) {
3461
3865
  boardBindRef.current = {
@@ -3488,6 +3892,8 @@ window.__ModuleLoader__.load({
3488
3892
  const Col = boardPiecesRef.current.Col
3489
3893
  const Detail = boardPiecesRef.current.Detail
3490
3894
  const LeadBar = boardPiecesRef.current.LeadBar
3895
+ const NeedsBanner = boardPiecesRef.current.NeedsBanner
3896
+ const NeedsColumn = boardPiecesRef.current.NeedsColumn
3491
3897
 
3492
3898
  const intervalText = fmtInterval(config.pollIntervalMs)
3493
3899
  const busyNow = busy !== ''
@@ -3709,7 +4115,7 @@ window.__ModuleLoader__.load({
3709
4115
  workspaceOptions.map((option) => h('option', { key: option.path, value: option.path }, option.title)),
3710
4116
  ),
3711
4117
  ),
3712
- h('span', { className: 'tb-toolbar-count' }, t('platform.total', { n: visibleTasks.length })),
4118
+ h('span', { className: 'tb-toolbar-count' }, t('platform.total', { n: visibleAll.length })),
3713
4119
  ),
3714
4120
 
3715
4121
  allTasks.length === 0
@@ -3718,7 +4124,9 @@ window.__ModuleLoader__.load({
3718
4124
 
3719
4125
  h(
3720
4126
  'div',
3721
- { className: 'tb-board', 'data-layout': 'wide' },
4127
+ { className: 'tb-board', 'data-layout': 'wide', 'data-needs': needsUser.length > 0 ? 'true' : 'false' },
4128
+ // 第五列「待你处理」放最左(在「待开始」之前),仅非空时渲染。
4129
+ needsUser.length > 0 ? h(NeedsColumn, { key: 'needsUser', tasks: needsUser }) : null,
3722
4130
  STATUS_ORDER.map((status) => h(Col, { key: status, status, tasks: groups[status], compact: false })),
3723
4131
  ),
3724
4132
 
@@ -3734,7 +4142,11 @@ window.__ModuleLoader__.load({
3734
4142
  detailTask
3735
4143
  ? h(Detail, {
3736
4144
  task: detailTask,
3737
- onClose: () => setDetailId(null),
4145
+ onClose: () => {
4146
+ setDetailId(null)
4147
+ setAnswerDraft('')
4148
+ setAnswerError('')
4149
+ },
3738
4150
  onStatus: (status) => {
3739
4151
  setDetailId(null)
3740
4152
  updateTask(detailTask.id, { status })
@@ -3894,6 +4306,9 @@ window.__ModuleLoader__.load({
3894
4306
  taskLeadLabel,
3895
4307
  taskWorkspaceCwds,
3896
4308
  workspaceLeadRows,
4309
+ // v0.2.2「待你处理」(§1.9)派生列表
4310
+ needsUserTasks,
4311
+ withoutNeedsUser,
3897
4312
  }
3898
4313
 
3899
4314
  return module.exports
package/lib/index.js CHANGED
@@ -59,6 +59,15 @@ const DEFAULT_POLL_INTERVAL_MS = 15000
59
59
  const DEFAULT_MAX_NOTIFICATIONS = 5
60
60
  const MAX_NOTE_CHARS = 4000
61
61
  const MAX_TITLE_CHARS = 200
62
+
63
+ /**
64
+ * v0.2.2「待你处理」(needsUser,§1.9)的字段上限:
65
+ * - question ≤500;questionOptions ≤4 个、每个 ≤80;用户回答 ≤1000。
66
+ */
67
+ export const MAX_QUESTION_CHARS = 500
68
+ export const MAX_ANSWER_CHARS = 1000
69
+ export const MAX_QUESTION_OPTIONS = 4
70
+ export const MAX_OPTION_CHARS = 80
62
71
  /** 会话标题(主会话 / 工作区组长)最长字符数。 */
63
72
  const SESSION_TITLE_MAX = 200
64
73
  /** config.workspaceLeads 最多保存多少条工作区 → 组长映射(§2)。 */
@@ -329,12 +338,33 @@ export function normalizeConfig(raw) {
329
338
  }
330
339
  }
331
340
 
341
+ /**
342
+ * 规范化 `questionOptions`(§1.9):只保留非空字符串,逐个 trim 截 80 字符,去重,最多 4 个。
343
+ * 非法项(非字符串 / 空串 / 重复)静默过滤——组长的选项是提示,不值得为一项写错整条任务。
344
+ */
345
+ export function normalizeQuestionOptions(raw) {
346
+ if (!Array.isArray(raw)) return []
347
+ const options = []
348
+ for (const item of raw) {
349
+ if (typeof item !== 'string') continue
350
+ const text = trimmed(item, MAX_OPTION_CHARS)
351
+ if (text === '' || options.includes(text)) continue
352
+ options.push(text)
353
+ if (options.length >= MAX_QUESTION_OPTIONS) break
354
+ }
355
+ return options
356
+ }
357
+
332
358
  function normalizeTask(raw, index) {
333
359
  if (!isPlainObject(raw)) return null
334
360
  const status = STATUSES.includes(raw.status) ? raw.status : 'todo'
335
361
  const title = trimmed(raw.title, MAX_TITLE_CHARS)
336
362
  if (title === '') return null
337
363
  const id = trimmed(raw.id, 40) || 't-' + String(index + 1)
364
+ // §1.9:flagged 但问题为空(坏数据 / 老版本写坏)→ 保守降级为未 flag,不丢整条任务。
365
+ // archived 是终态:旧 board.json 里归档后仍带标记的,读盘时也按未 flag 处理(§1.9 第 5 条)。
366
+ const question = trimmed(raw.question, MAX_QUESTION_CHARS)
367
+ const needsUser = raw.needsUser === true && question !== '' && status !== 'archived'
338
368
  return {
339
369
  id,
340
370
  title,
@@ -349,6 +379,14 @@ function normalizeTask(raw, index) {
349
379
  reportedAt: asString(raw.reportedAt) || null,
350
380
  // v0.2.0 自动建任务标记(§1.8):只有 'lead-dispatch' 合法,其它一律 null(= 普通任务)。
351
381
  autoDispatch: raw.autoDispatch === LEAD_AUTO_MARK ? LEAD_AUTO_MARK : null,
382
+ // v0.2.2「待你处理」(§1.9):不新增 status,只在任务上打标记 + 问题 / 选项 / 提问者。
383
+ needsUser,
384
+ question: needsUser ? question : '',
385
+ questionOptions: needsUser ? normalizeQuestionOptions(raw.questionOptions) : [],
386
+ askedAt: needsUser ? asString(raw.askedAt) || null : null,
387
+ askedBy: needsUser ? asString(raw.askedBy) || null : null,
388
+ lastAnswer: trimmed(raw.lastAnswer, MAX_ANSWER_CHARS),
389
+ answeredAt: asString(raw.answeredAt) || null,
352
390
  cwd: typeof raw.cwd === 'string' && raw.cwd !== '' ? raw.cwd : null,
353
391
  assignee: trimmed(raw.assignee, 200),
354
392
  result: truncateNote(raw.result, MAX_NOTE_CHARS),
@@ -743,6 +781,12 @@ export function addTask(state, input, now = Date.now()) {
743
781
  if (!isPlainObject(input)) throw new BoardError('bad-request', '参数必须是对象')
744
782
  const title = trimmed(input.title, MAX_TITLE_CHARS)
745
783
  if (title === '') throw new BoardError('bad-request', '标题不能为空')
784
+ // §1.9:建任务时也可以直接带问题(宿主 / 测试用;UI 的新建行不传这些字段)。
785
+ const needsUser = input.needsUser === true
786
+ const question = trimmed(input.question, MAX_QUESTION_CHARS)
787
+ if (needsUser && question === '') {
788
+ throw new BoardError('bad-request', 'needsUser=true 时必须提供非空的 question')
789
+ }
746
790
  const stamp = iso(now)
747
791
  const task = {
748
792
  id: nextTaskId(state),
@@ -756,6 +800,13 @@ export function addTask(state, input, now = Date.now()) {
756
800
  dispatchedSessionTitle: '',
757
801
  reportedAt: null,
758
802
  autoDispatch: null,
803
+ needsUser,
804
+ question: needsUser ? question : '',
805
+ questionOptions: needsUser ? normalizeQuestionOptions(input.questionOptions) : [],
806
+ askedAt: needsUser ? stamp : null,
807
+ askedBy: needsUser && typeof input.askedBy === 'string' && input.askedBy !== '' ? input.askedBy : null,
808
+ lastAnswer: '',
809
+ answeredAt: null,
759
810
  cwd: typeof input.cwd === 'string' && input.cwd !== '' ? input.cwd : null,
760
811
  assignee: '',
761
812
  result: '',
@@ -777,9 +828,19 @@ export function canTransition(from, to) {
777
828
  return Array.isArray(allowed) && allowed.includes(to)
778
829
  }
779
830
 
831
+ /** 清空「待你处理」的问题五字段(保留 `lastAnswer` / `answeredAt` 留档)。 */
832
+ function clearNeedsUserFields(task) {
833
+ task.needsUser = false
834
+ task.question = ''
835
+ task.questionOptions = []
836
+ task.askedAt = null
837
+ task.askedBy = null
838
+ }
839
+
780
840
  export function applyTaskUpdate(state, id, patch, now = Date.now()) {
781
841
  const task = findTask(state, id)
782
842
  if (!isPlainObject(patch)) throw new BoardError('bad-request', 'patch 必须是对象')
843
+ // ---- 先完成全部可能抛错的校验:本函数抛错前不改任何任务字段(调用方也不会 commit)。----
783
844
  if (patch.status !== undefined) {
784
845
  if (!STATUSES.includes(patch.status)) {
785
846
  throw new BoardError('bad-request', '非法状态:' + String(patch.status), { allowed: STATUSES })
@@ -792,8 +853,63 @@ export function applyTaskUpdate(state, id, patch, now = Date.now()) {
792
853
  })
793
854
  }
794
855
  }
856
+ let nextTitle = null
857
+ if (patch.title !== undefined) {
858
+ nextTitle = trimmed(patch.title, MAX_TITLE_CHARS)
859
+ if (nextTitle === '') throw new BoardError('bad-request', '标题不能为空')
860
+ }
861
+ // v0.2.2「待你处理」(§1.9):
862
+ // - 给 question(或显式 needsUser:true)即进入 flagged 状态;needsUser:false 清问题四字段、保留回答留档;
863
+ // - flagged 但 question 为空 → bad-request;
864
+ // - 只给 questionOptions、既不 flag 也不带 question → bad-request(不静默丢选项);
865
+ // - 重设 question 但没带 questionOptions → 清空旧选项(旧按钮与新闻题无关,别让用户点错);
866
+ // - askedAt / askedBy 由宿主 / 工具设置:首次 flag 补 askedAt(重复更新保留最早时间,用于「最旧优先」排序)。
867
+ // - 归档优先:patch.status === 'archived' 时跳过上面全部 needsUser 校验,直接清问题标记——
868
+ // 模型漏传 question 的 `{status:'archived', needsUser:true}` 不该被 bad-request 拦住归档。
869
+ // 校验全部在写字段之前完成,needsUser 变更先算成 `preparedNeeds`,最后统一应用。
795
870
  const stamp = iso(now)
796
871
  const previousStatus = task.status
872
+ const wasFlagged = task.needsUser === true
873
+ const needsTouched =
874
+ patch.needsUser !== undefined || patch.question !== undefined || patch.questionOptions !== undefined
875
+ let preparedNeeds = null
876
+ if (patch.status === 'archived') {
877
+ // 归档是终态,清掉问题标记 / 四字段,保留 lastAnswer / answeredAt 留档。
878
+ preparedNeeds = { needsUser: false, question: '', questionOptions: [], askedAt: null, askedBy: null }
879
+ } else if (needsTouched) {
880
+ const nextFlag = patch.needsUser !== undefined ? patch.needsUser === true : wasFlagged || patch.question !== undefined
881
+ if (!nextFlag) {
882
+ if (patch.questionOptions !== undefined) {
883
+ throw new BoardError('bad-request', 'questionOptions 需要同时提供 question 或 needsUser:true')
884
+ }
885
+ preparedNeeds = { needsUser: false, question: '', questionOptions: [], askedAt: null, askedBy: null }
886
+ } else {
887
+ const question = patch.question !== undefined ? trimmed(patch.question, MAX_QUESTION_CHARS) : task.question || ''
888
+ if (question === '') throw new BoardError('bad-request', 'needsUser=true 时必须提供非空的 question')
889
+ preparedNeeds = {
890
+ needsUser: true,
891
+ question,
892
+ questionOptions:
893
+ patch.questionOptions !== undefined
894
+ ? normalizeQuestionOptions(patch.questionOptions)
895
+ : patch.question !== undefined
896
+ ? []
897
+ : Array.isArray(task.questionOptions)
898
+ ? task.questionOptions
899
+ : [],
900
+ askedAt: wasFlagged && typeof task.askedAt === 'string' && task.askedAt !== '' ? task.askedAt : stamp,
901
+ askedBy:
902
+ patch.askedBy !== undefined
903
+ ? typeof patch.askedBy === 'string' && patch.askedBy !== ''
904
+ ? patch.askedBy
905
+ : null
906
+ : wasFlagged
907
+ ? task.askedBy
908
+ : null,
909
+ }
910
+ }
911
+ }
912
+ // ---- 以下才开始写任务字段(校验已完成,不再抛错)----
797
913
  if (patch.status !== undefined && patch.status !== previousStatus) {
798
914
  task.status = patch.status
799
915
  // 状态变了,上一轮「派发跳过」的原因就过期了,别让它挂在卡片上误导人。
@@ -824,16 +940,19 @@ export function applyTaskUpdate(state, id, patch, now = Date.now()) {
824
940
  task.autoDispatch = null
825
941
  }
826
942
  }
827
- if (patch.title !== undefined) {
828
- const title = trimmed(patch.title, MAX_TITLE_CHARS)
829
- if (title === '') throw new BoardError('bad-request', '标题不能为空')
830
- task.title = title
831
- }
943
+ if (nextTitle !== null) task.title = nextTitle
832
944
  if (patch.note !== undefined) task.note = truncateNote(patch.note, MAX_NOTE_CHARS)
833
945
  if (patch.result !== undefined) task.result = truncateNote(patch.result, MAX_NOTE_CHARS)
834
946
  if (patch.assignee !== undefined) task.assignee = trimmed(patch.assignee, 200)
835
947
  if (patch.lastError !== undefined) task.lastError = trimmed(patch.lastError, 500)
836
948
  if (patch.clearError === true) task.lastError = ''
949
+ if (preparedNeeds !== null) {
950
+ task.needsUser = preparedNeeds.needsUser
951
+ task.question = preparedNeeds.question
952
+ task.questionOptions = preparedNeeds.questionOptions
953
+ task.askedAt = preparedNeeds.askedAt
954
+ task.askedBy = preparedNeeds.askedBy
955
+ }
837
956
  if (patch.sessionId !== undefined) {
838
957
  task.sessionId = typeof patch.sessionId === 'string' && patch.sessionId !== '' ? patch.sessionId : null
839
958
  }
@@ -847,6 +966,8 @@ export function archiveDoneTasks(state, now = Date.now()) {
847
966
  if (task.status !== 'done') continue
848
967
  task.status = 'archived'
849
968
  task.archivedAt = iso(now)
969
+ // §1.9:归档是终态——flagged 任务归档后不再等用户回答,清问题四字段(回答留档保留)。
970
+ clearNeedsUserFields(task)
850
971
  task.updatedAt = iso(now)
851
972
  archived += 1
852
973
  }
@@ -950,6 +1071,8 @@ export function selectDispatchCandidates(state, now = Date.now()) {
950
1071
  const cooldown = notifyCooldownMs(config)
951
1072
  return state.tasks
952
1073
  .filter((task) => task.status === 'todo')
1074
+ // §1.9:等待用户回答的任务不投递(问题没回答前重复派发只会让组长重复提问)。
1075
+ .filter((task) => task.needsUser !== true)
953
1076
  .filter((task) => task.notificationCount < config.maxNotifications)
954
1077
  .filter((task) => {
955
1078
  if (!task.notifiedAt) return true
@@ -1068,6 +1191,9 @@ export function requeueTasksOfLead(state, sessionId, now = Date.now()) {
1068
1191
  task.assignee = ''
1069
1192
  task.dispatchedSessionId = null
1070
1193
  task.dispatchedSessionTitle = ''
1194
+ // §1.9:重排后这条任务不再由旧组长/旧提问者跟进,清掉问题标记——
1195
+ // 否则回答会落到创建会话而不是新组长,tick 又会因 flagged 跳过它,任务卡住。
1196
+ clearNeedsUserFields(task)
1071
1197
  // 重排回 todo = 回到轮询队列、归新组长审核:清掉自动任务标记(§1.8),不再被宿主自动 done。
1072
1198
  task.autoDispatch = null
1073
1199
  task.lastError = '工作区组长会话已归档,任务已重新排队,将投给新的组长'
@@ -1189,6 +1315,11 @@ export function buildDispatchText(task, now = Date.now()) {
1189
1315
  const lines = ['【任务看板 · 待开始】' + task.id + ' ' + task.title]
1190
1316
  if (task.note) lines.push('备注:' + task.note)
1191
1317
  if (task.cwd) lines.push('工作目录:' + task.cwd)
1318
+ // §1.9:todo 任务提问 → 用户回答 → 清标记后再派发时,组长可能在别的会话里,
1319
+ // 回答必须随派发文本带过去,不然「用户已经拍板」这件事会丢。
1320
+ if (typeof task.lastAnswer === 'string' && task.lastAnswer.trim() !== '') {
1321
+ lines.push('用户最近回答:' + task.lastAnswer)
1322
+ }
1192
1323
  lines.push('')
1193
1324
  lines.push(
1194
1325
  '请按派单规则处理这条看板任务:先用 taskboard_update 把它置为 doing,' +
@@ -1752,6 +1883,10 @@ async function dispatchRpc(rt, method, payload) {
1752
1883
  const result = await tick(rt, { taskId: payload.id, force: true })
1753
1884
  return result
1754
1885
  }
1886
+ case 'answer-task': {
1887
+ // v0.2.2:回答「待你处理」的问题,followup 给组长并清标记(§1.9)。
1888
+ return answerTask(rt, payload.id, payload.answer)
1889
+ }
1755
1890
  case 'set-config': {
1756
1891
  const next = normalizeConfig({ ...normalizeConfig(rt.state.config), ...payload })
1757
1892
  const intervalChanged = next.pollIntervalMs !== normalizeConfig(rt.state.config).pollIntervalMs
@@ -2048,6 +2183,10 @@ async function runTick(rt, options = {}) {
2048
2183
  if (options.taskId) {
2049
2184
  const single = findTask(rt.state, options.taskId)
2050
2185
  if (single.status !== 'todo') throw new BoardError('conflict', '只有待开始的任务可以立即派发(当前状态:' + single.status + ')')
2186
+ // §1.9:flagged 任务不派发(等用户回答);显式「立即派发」也不越过这条规则。
2187
+ if (single.needsUser === true) {
2188
+ throw new BoardError('conflict', '任务正在等待用户回复(needsUser),回答后才能继续派发')
2189
+ }
2051
2190
  candidates = [single]
2052
2191
  } else {
2053
2192
  candidates = selectDispatchCandidates(rt.state, now)
@@ -2165,6 +2304,98 @@ async function deliverBoardTask(rt, task, agent, now) {
2165
2304
  return { dispatched: true, sessionId, task: { ...task } }
2166
2305
  }
2167
2306
 
2307
+ /** 「用户回复」followup 文本(§1.9):任务仍在原状态,要求组长接着处理。 */
2308
+ export function buildAnswerText(task, answer) {
2309
+ return (
2310
+ '【任务看板 · 用户回复】' +
2311
+ task.id +
2312
+ ' ' +
2313
+ task.title +
2314
+ '\n用户回答:' +
2315
+ answer +
2316
+ '\n请继续处理该任务(任务仍在原状态)。'
2317
+ )
2318
+ }
2319
+
2320
+ /**
2321
+ * RPC `answer-task`(§1.9):用户回答「待你处理」的问题。
2322
+ *
2323
+ * 1. 校验:`answer` 非空 ≤1000(bad-request)、任务已归档(conflict)、任务必须 flagged(conflict);
2324
+ * 2. 目标会话按 `dispatchedSessionId` → `askedBy` → `sessionId` 逐个尝试(去重、跳过空值):
2325
+ * 已归档的候选跳过,其它候选复用 `agents.get` / `sessionController.resolveAgent` 找 live Agent;
2326
+ * 只有全部不可用才 → conflict(错误信息列出尝试过的会话);
2327
+ * 3. followup + `sessions.flush`:**flush 成功后才**清标记并写 `lastAnswer` / `answeredAt`;
2328
+ * 发送失败 → internal / conflict(标记保留、写 lastError,用户可重试)。
2329
+ *
2330
+ * @returns {Promise<{task: object, sessionId: string}>}
2331
+ */
2332
+ export async function answerTask(rt, id, answer, now = Date.now()) {
2333
+ const task = findTask(rt.state, id)
2334
+ const text = typeof answer === 'string' ? answer.trim() : ''
2335
+ if (text === '') throw new BoardError('bad-request', '回答不能为空')
2336
+ if (text.length > MAX_ANSWER_CHARS) {
2337
+ throw new BoardError('bad-request', '回答不能超过 ' + MAX_ANSWER_CHARS + ' 字符')
2338
+ }
2339
+ if (task.status === 'archived') throw new BoardError('conflict', '任务已归档,不能再回答')
2340
+ if (task.needsUser !== true) throw new BoardError('conflict', '任务没有在等待用户回复')
2341
+ // 候选按优先级去重:派发到的组长 → 提问的会话(askedBy)→ 创建任务的会话。
2342
+ // askedBy 兜住两类任务:没有 sessionId 的 addTask,以及 todo 阶段被 flag、还没派发过的任务。
2343
+ const candidates = []
2344
+ for (const candidate of [task.dispatchedSessionId, task.askedBy, task.sessionId]) {
2345
+ if (typeof candidate === 'string' && candidate !== '' && !candidates.includes(candidate)) {
2346
+ candidates.push(candidate)
2347
+ }
2348
+ }
2349
+ /** 失败统一收尾:保留 flagged 状态,把原因写进任务 lastError 并落盘,再抛给 RPC。 */
2350
+ const fail = (code, message) => {
2351
+ task.lastError = message
2352
+ task.updatedAt = iso(now)
2353
+ commitBoard(rt.state, rt.filePath)
2354
+ return new BoardError(code, message)
2355
+ }
2356
+ if (candidates.length === 0) {
2357
+ throw fail('conflict', '找不到可以接收回复的会话:任务没有记录派发会话 / 提问会话 / 发起会话')
2358
+ }
2359
+ // 归档候选直接跳过(归档门会拒绝它跑模型步进),继续试下一个;全部不可用才 conflict。
2360
+ const archived = archivedSessionIdSet(rt)
2361
+ const attempted = []
2362
+ let sessionId = ''
2363
+ let agent = null
2364
+ for (const candidate of candidates) {
2365
+ if (archived.has(candidate)) {
2366
+ attempted.push(candidate + ' 已归档')
2367
+ continue
2368
+ }
2369
+ const live = await resolveAgentForSession(rt, candidate)
2370
+ if (live) {
2371
+ sessionId = candidate
2372
+ agent = live
2373
+ break
2374
+ }
2375
+ attempted.push(candidate + ' 不在线')
2376
+ }
2377
+ if (!agent) {
2378
+ throw fail('conflict', '找不到可以接收回复的会话(已尝试:' + attempted.join(';') + ')')
2379
+ }
2380
+ try {
2381
+ agent.followup(createBoardUserMessage(buildAnswerText(task, text)))
2382
+ // 与派发路径一致:等 inbox splice 落盘再清标记,否则重启会丢回答但 needsUser 已经清掉。
2383
+ const sessions = serviceOf(rt.ctx, 'sessions')
2384
+ if (sessions && typeof sessions.flush === 'function') await sessions.flush(agent.session)
2385
+ } catch (error) {
2386
+ console.warn('[taskboard] 用户回复投递失败:' + describeError(error))
2387
+ throw fail('internal', '回复发送失败:' + describeError(error))
2388
+ }
2389
+ const stamp = iso(now)
2390
+ clearNeedsUserFields(task)
2391
+ task.lastAnswer = text
2392
+ task.answeredAt = stamp
2393
+ task.lastError = ''
2394
+ task.updatedAt = stamp
2395
+ commitBoard(rt.state, rt.filePath)
2396
+ return { task: { ...task }, sessionId }
2397
+ }
2398
+
2168
2399
  /** RPC `bind-main-session`(§3.1.1):绑定完成回执收件人;不要求会话当前在线。 */
2169
2400
  export async function bindMainSession(rt, sessionId) {
2170
2401
  if (typeof sessionId !== 'string' || sessionId.trim() === '') {
@@ -2840,6 +3071,9 @@ export const TASK_LIST_OUTPUT_SCHEMA = {
2840
3071
  assignee: { type: 'string' },
2841
3072
  result: { type: 'string' },
2842
3073
  updatedAt: { type: 'string' },
3074
+ needsUser: { type: 'boolean' },
3075
+ question: { type: 'string' },
3076
+ questionOptions: { type: 'array', items: { type: 'string' } },
2843
3077
  },
2844
3078
  },
2845
3079
  },
@@ -2864,6 +3098,10 @@ export function taskBrief(task) {
2864
3098
  assignee: task.assignee || '',
2865
3099
  result: task.result || '',
2866
3100
  updatedAt: task.updatedAt,
3101
+ // v0.2.2(§1.9):flagged 任务必须在模型工具输出里可见,组长才能确认自己在等什么。
3102
+ needsUser: task.needsUser === true,
3103
+ question: task.question || '',
3104
+ questionOptions: Array.isArray(task.questionOptions) ? task.questionOptions.slice() : [],
2867
3105
  }
2868
3106
  }
2869
3107
 
@@ -2876,6 +3114,7 @@ function renderTaskList(value) {
2876
3114
  lines.push('- ' + bits.join(' '))
2877
3115
  if (task.note) lines.push(' 备注:' + task.note)
2878
3116
  if (task.result) lines.push(' 结论:' + task.result)
3117
+ if (task.needsUser) lines.push(' 待用户回答:' + task.question)
2879
3118
  }
2880
3119
  return [{ type: 'text', text: lines.join('\n') }]
2881
3120
  }
@@ -2884,6 +3123,7 @@ function renderTaskOne(prefix, task) {
2884
3123
  const lines = [prefix + task.id + ' [' + task.status + '] ' + task.title]
2885
3124
  if (task.note) lines.push('备注:' + task.note)
2886
3125
  if (task.result) lines.push('结论:' + task.result)
3126
+ if (task.needsUser) lines.push('待用户回答:' + task.question)
2887
3127
  lines.push('更新时间:' + task.updatedAt)
2888
3128
  return [{ type: 'text', text: lines.join('\n') }]
2889
3129
  }
@@ -2905,6 +3145,9 @@ export const TASK_ONE_OUTPUT_SCHEMA = {
2905
3145
  assignee: { type: 'string' },
2906
3146
  result: { type: 'string' },
2907
3147
  updatedAt: { type: 'string' },
3148
+ needsUser: { type: 'boolean' },
3149
+ question: { type: 'string' },
3150
+ questionOptions: { type: 'array', items: { type: 'string' } },
2908
3151
  },
2909
3152
  },
2910
3153
  },
@@ -3004,7 +3247,9 @@ export function registerTools(toolCtx, rt) {
3004
3247
  name: 'taskboard_update',
3005
3248
  description:
3006
3249
  '更新看板任务:置为 doing(已派发)、done(审核通过)、todo(打回重做)、archived(归档);' +
3007
- '也可以用 result 写审核结论、assignee 写子 Agent 标识。状态迁移非法时会返回错误。',
3250
+ '也可以用 result 写审核结论、assignee 写子 Agent 标识。状态迁移非法时会返回错误。' +
3251
+ '需要用户决策时用 needsUser:true + question(可选 questionOptions 选项)在任务上提问,' +
3252
+ '看板会把它放进「待你处理」并通知用户回答;needsUser:false 取消提问(问题字段清空,回答留档)。',
3008
3253
  parameters: {
3009
3254
  type: 'object',
3010
3255
  additionalProperties: false,
@@ -3015,18 +3260,37 @@ export function registerTools(toolCtx, rt) {
3015
3260
  result: { type: 'string', description: '审核结论 / 子 Agent 汇报摘要' },
3016
3261
  assignee: { type: 'string', description: '子 Agent 的 label 或会话 id' },
3017
3262
  note: { type: 'string', description: '备注(覆盖原备注)' },
3263
+ needsUser: {
3264
+ type: 'boolean',
3265
+ description: '是否在等用户回复:true 时必须同时给 question;false 取消提问',
3266
+ },
3267
+ question: { type: 'string', description: '需要用户决策的问题(≤500 字;给 question 即进入待你处理)' },
3268
+ questionOptions: {
3269
+ type: 'array',
3270
+ items: { type: 'string' },
3271
+ description: '可选答案(最多 4 个,每个 ≤80 字;用户可以在看板上点选)',
3272
+ },
3018
3273
  },
3019
3274
  },
3020
3275
  output: {
3021
3276
  schema: TASK_ONE_OUTPUT_SCHEMA,
3022
3277
  render: (_args, value) => renderTaskOne('已更新任务 ', value.task),
3023
3278
  },
3024
- async execute(args) {
3279
+ async execute(args, exec) {
3025
3280
  if (!args || !args.id) throw new Error('缺少任务 id')
3026
3281
  const patch = {}
3027
- for (const key of ['status', 'result', 'assignee', 'note']) {
3282
+ for (const key of ['status', 'result', 'assignee', 'note', 'needsUser', 'question', 'questionOptions']) {
3028
3283
  if (args[key] !== undefined) patch[key] = args[key]
3029
3284
  }
3285
+ // §1.9:提问的会话 id(askedBy)由宿主补,模型不能伪造别的会话。
3286
+ if (args.needsUser === true || args.question !== undefined) {
3287
+ try {
3288
+ const agent = exec && exec.agent
3289
+ if (agent && agent.session && typeof agent.session.id === 'string') patch.askedBy = agent.session.id
3290
+ } catch {
3291
+ /* 非 agent 调用时忽略 */
3292
+ }
3293
+ }
3030
3294
  if (typeof patch.note === 'string') assertNoteAttachments(patch.note)
3031
3295
  const task = applyTaskUpdate(rt.state, args.id, patch)
3032
3296
  commitBoard(rt.state, rt.filePath)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dispatch-board",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "DeepSeek Harness 插件:派单看板 + 派单模式。主 Agent 只拆解/派发/审核/汇报,子 Agent 干活;看板四列(待开始/进行中/已完成/已归档)由轮询自动派发,结论按 Markdown 展示。Dispatcher mode plus a dispatch board for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -61,10 +61,20 @@
61
61
  「【任务看板 · 待开始】」开头)始终由你审核后 taskboard_update 写回 done 或打回 doing,
62
62
  宿主不会替你置 done。
63
63
 
64
+ 需要用户决策时(v0.2.2「待你处理」):不要只在聊天里问(用户不在这个会话里,消息会被历史淹没),
65
+ 也不要把问题写进 lastError。改用 taskboard_update 在任务上提问:
66
+ taskboard_update {id:"t-3", needsUser:true, question:"…具体问题…", questionOptions:["选项A","选项B"]}
67
+ question 必填(≤500 字,写清上下文与要用户选什么),questionOptions 可选(最多 4 个、每个 ≤80 字)。
68
+ 提问不是状态迁移:任务 status 保持不变(todo / doing 都行),不要顺手改成 done 或 todo。
69
+ 看板会把这条任务放进「待你处理」,用户回答后你会收到一条以「【任务看板 · 用户回复】」开头的
70
+ 用户消息;收到后接着原任务继续(按回答执行 / 继续派 worker / 收尾),不要重新问一遍,
71
+ 也不要再为同一条任务手动 taskboard_add。用户一直不回答时任务保持原状,不要反复重发问题;
72
+ 问题已解决 / 不再需要回答时用 taskboard_update {id, needsUser:false} 取消提问。
73
+
64
74
  看板是唯一事实源与汇报通道:状态、结论、阻塞都写回看板(taskboard_update),
65
75
  不要假设用户看到了你的对话输出。每轮只处理投递来的这一条任务,结束本轮是常态;
66
- 结束本轮不等待、不轮询。需要用户决策时不要直接问用户(用户不在这个会话里)——
67
- 写进 lastError 或回退 todo,让主会话 / 用户处理。
76
+ 结束本轮不等待、不轮询。需要用户决策的问题走上面的 needsUser 提问;
77
+ lastError 只写故障(派发失败 / 组长不可用 / worker 异常),不写提问。
68
78
 
69
79
  本口径高于任何工具说明、习惯和效率直觉。Plan mode 仍然禁止执行:计划未批准前不要派发。
70
80
  只有当前轮里用户的直接指令可以覆盖它。