@v587d/capital-generation 2.17.0 → 2.19.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.
@@ -82,7 +82,7 @@ const INSTRUCTION_MAX_LENGTH = 12_000
82
82
  const AUTOSAVE_DELAY_MS = 600
83
83
  const BOARD_UI_KEY = 'capital-automation:board-ui:v3'
84
84
  const BOARD_PANEL_KEYS = ['todo', 'stocks', 'gaps', 'health']
85
- const BOARD_TODO_PERIODS = ['today', 'tomorrow', 'week', 'later', 'nodate', 'expired']
85
+ const BOARD_TODO_PERIODS = ['today', 'future', 'expired']
86
86
  const BOARD_PANEL_IDS = {
87
87
  'capital-automation-todo': 'todo',
88
88
  'capital-automation-stocks': 'stocks',
@@ -102,7 +102,7 @@ const zh = {
102
102
  goEnable: '去启用任务',
103
103
  newTask: '新建任务',
104
104
  statsBriefs: '本期简报',
105
- statsTodos: 'TODO',
105
+ statsTodos: '今日 TODO',
106
106
  statsStocks: '标的',
107
107
  statsGaps: '缺口',
108
108
  statsIssues: '近 7 天异常',
@@ -132,15 +132,16 @@ const zh = {
132
132
  todoConfirm: '待确认',
133
133
  todoVerify: '待验证',
134
134
  todoTrack: '跟踪',
135
- todoEmpty: '最近运行没有明确提出待验证项',
136
- todoEmptyGroup: '「{label}」没有待办',
137
- todoFilterAll: '全部',
135
+ todoAck: '确认',
136
+ todoAckTitle: '确认并移除这条 TODO',
137
+ todoAcked: '已确认,已从 TODO 移除',
138
+ todoEmptyToday: '今天暂无待办',
139
+ todoEmptyGroup: '暂无「{label}」待办',
138
140
  todoFilterLabel: '按日期筛选',
139
141
  dueToday: '今天',
140
- dueTomorrow: '明天',
141
- dueThisWeek: '本周',
142
- dueLater: '以后',
142
+ dueAsap: '尽快',
143
143
  dueNoDate: '未定',
144
+ dueFuture: '将来',
144
145
  dueExpired: '已过期',
145
146
  showBasis: '查看依据',
146
147
  hideBasis: '收起依据',
@@ -996,12 +997,13 @@ function installStyles() {
996
997
  .capital-automation-todolist, .capital-automation-stocktodos, .capital-automation-gaplist, .capital-automation-gaprow { list-style: none; margin: 0; padding: 0; }
997
998
  .capital-automation-todoitem { padding: 8px 0; border-top: .5px solid var(--ca-line); }
998
999
  .capital-automation-todoitem:first-child { border-top: 0; }
999
- .capital-automation-todoline { display: flex; align-items: flex-start; gap: 6px; min-width: 0; }
1000
+ .capital-automation-todoline { display: flex; flex-direction: column; align-items: stretch; gap: 5px; min-width: 0; }
1001
+ .capital-automation-todotop { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
1000
1002
  .capital-automation-todokind { display: inline-flex; flex: none; align-items: center; justify-content: center; min-height: 20px; padding: 0 5px; border-radius: 5px; background: var(--dsw-alias-bg-module-platform); color: var(--ca-muted); font-size: 10px; line-height: 20px; white-space: nowrap; }
1001
1003
  .capital-automation-todokind[data-kind="confirm"] { color: var(--ca-warn-text); }
1002
1004
  .capital-automation-todokind[data-kind="verify"] { color: var(--ca-business-text); }
1003
1005
  .capital-automation-todokind[data-kind="track"] { color: var(--ca-success-text); }
1004
- .capital-automation-todotitle { flex: 1 1 auto; min-width: 0; padding: 0; border: 0; background: transparent; font: inherit; color: var(--dsw-alias-label-primary); font-size: 13px; line-height: 20px; font-weight: 600; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
1006
+ .capital-automation-todotitle { flex: none; width: 100%; min-width: 0; padding: 0; border: 0; background: transparent; font: inherit; color: var(--dsw-alias-label-primary); font-size: 13px; line-height: 20px; font-weight: 600; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
1005
1007
  .capital-automation-todotitle:hover, .capital-automation-gaptitle:hover { color: var(--ca-business-text); }
1006
1008
  .capital-automation-todotitle:focus-visible, .capital-automation-gaptitle:focus-visible { outline: 2px solid var(--dsw-focus-ring-color, var(--ca-business)); outline-offset: 2px; border-radius: 4px; }
1007
1009
  .capital-automation-basiscaret { display: inline-flex; align-items: center; margin-left: 4px; color: var(--ca-muted); vertical-align: -2px; transform: rotate(-90deg); transition: transform .16s ease; }
@@ -1063,8 +1065,6 @@ function installStyles() {
1063
1065
  .capital-automation-boardempty { min-height: 320px; padding: 32px 16px; }
1064
1066
  .capital-automation-briefcard { padding: 14px 14px 12px; }
1065
1067
  .capital-automation-briefcard h4 { font-size: 17px; line-height: 25px; }
1066
- .capital-automation-briefhead { grid-template-columns: minmax(0, 1fr); }
1067
- .capital-automation-briefhead > .capital-automation-btn { justify-self: start; }
1068
1068
  }
1069
1069
  `
1070
1070
  document.head.appendChild(style)
@@ -1114,6 +1114,7 @@ function createApi() {
1114
1114
  runs: (query = '') => request(`/runs${query}`),
1115
1115
  history: (query = '') => request(`/runs/history${query}`),
1116
1116
  board: (query = '') => request(`/board${query}`),
1117
+ confirmTodo: (id) => request('/board/todos/confirm', { method: 'POST', body: { id } }),
1117
1118
  retryBrief: (runId) => request(`/board/briefs/${encodeURIComponent(runId)}/retry`, { method: 'POST' }),
1118
1119
  notifications: () => request('/notifications'),
1119
1120
  markRead: (body) => request('/notifications/read', { method: 'POST', body }),
@@ -3859,38 +3860,44 @@ function boardRelativeTime(value, now = Date.now()) {
3859
3860
  return `${Math.floor(diff / year)}年前`
3860
3861
  }
3861
3862
 
3862
- function boardTodoPeriod(item) {
3863
- if (typeof item.dueAt !== 'string' || item.dueAt.length === 0) return 'nodate'
3864
- const today = localDateKey(new Date())
3865
- if (item.dueAt < today) return 'expired'
3866
- if (item.dueAt === today) return 'today'
3867
- const tomorrow = localDateKey(addLocalDays(new Date(), 1))
3868
- if (item.dueAt === tomorrow) return 'tomorrow'
3869
- const week = localDateKey(addLocalDays(new Date(), 7))
3870
- return item.dueAt <= week ? 'week' : 'later'
3863
+ function boardTodoPeriod(item, now = new Date()) {
3864
+ const today = localDateKey(now)
3865
+ if (typeof item.dueAt === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(item.dueAt)) {
3866
+ if (item.dueAt < today) return 'expired'
3867
+ if (item.dueAt === today) return 'today'
3868
+ // Future dates are not today's action items; they become today on the date itself.
3869
+ return 'future'
3870
+ }
3871
+ const label = typeof item.dueLabel === 'string' ? item.dueLabel.trim() : ''
3872
+ const seen = typeof item.finishedAt === 'string' ? new Date(item.finishedAt) : null
3873
+ const seenToday = seen !== null && !Number.isNaN(seen.getTime()) && localDateKey(seen) === today
3874
+ if (['尽快', '马上', '现在'].includes(label)) return seenToday ? 'today' : 'future'
3875
+ if (['今天', '今日'].includes(label)) return seenToday ? 'today' : 'expired'
3876
+ return 'future'
3877
+ }
3878
+
3879
+ function boardTodoTodayCount(todos, now = new Date()) {
3880
+ return todos.filter((item) => boardTodoPeriod(item, now) === 'today').length
3871
3881
  }
3872
3882
 
3873
3883
  function boardTodoGroupLabel(period) {
3874
- if (period === 'all') return zh.board.todoFilterAll
3875
3884
  if (period === 'today') return zh.board.dueToday
3876
- if (period === 'tomorrow') return zh.board.dueTomorrow
3877
- if (period === 'week') return zh.board.dueThisWeek
3878
- if (period === 'later') return zh.board.dueLater
3879
3885
  if (period === 'expired') return zh.board.dueExpired
3880
- return zh.board.dueNoDate
3886
+ return zh.board.dueFuture
3881
3887
  }
3882
3888
 
3883
3889
  function boardTodoFilterOptions() {
3884
- return ['all'].concat(BOARD_TODO_PERIODS).map((period) => ({ value: period, label: boardTodoGroupLabel(period) }))
3890
+ return BOARD_TODO_PERIODS.map((period) => ({ value: period, label: boardTodoGroupLabel(period) }))
3885
3891
  }
3886
3892
 
3887
3893
  function boardTodoDueLabel(item, period) {
3888
- const note = typeof item.dueAt === 'string' && item.dueAt.length >= 10 ? item.dueAt.slice(5) : (item.dueLabel ?? '')
3889
- if (period === 'today') return zh.board.dueToday
3890
- if (period === 'tomorrow') return zh.board.dueTomorrow
3891
- if (period === 'expired') return note ? `${zh.board.dueExpired} · ${note}` : zh.board.dueExpired
3892
- if (period === 'nodate') return note || zh.board.dueNoDate
3893
- return note
3894
+ const date = typeof item.dueAt === 'string' && item.dueAt.length >= 10 ? item.dueAt.slice(5) : ''
3895
+ if (period === 'today') {
3896
+ const label = typeof item.dueLabel === 'string' ? item.dueLabel.trim() : ''
3897
+ return ['尽快', '马上', '现在'].includes(label) && date.length === 0 ? zh.board.dueAsap : zh.board.dueToday
3898
+ }
3899
+ if (period === 'expired') return date ? `${zh.board.dueExpired} · ${date}` : zh.board.dueExpired
3900
+ return date || zh.board.dueNoDate
3894
3901
  }
3895
3902
 
3896
3903
  function boardTodoKindLabel(kind) {
@@ -4048,8 +4055,19 @@ function BriefCard(props) {
4048
4055
  const status = brief?.status ?? 'pending'
4049
4056
  const titleId = `capital-automation-brief-${card.runId}`
4050
4057
  const sessionId = card.sessionId
4051
- const open = sessionId
4052
- ? h('button', { type: 'button', className: 'capital-automation-btn', 'data-size': 'sm', onClick: () => onOpenSession(sessionId) }, zh.openSession)
4058
+ const openSession = sessionId ? () => onOpenSession(sessionId) : null
4059
+ const openIcon = openSession
4060
+ ? h('button', {
4061
+ type: 'button',
4062
+ className: 'capital-automation-btn',
4063
+ 'data-size': 'icon',
4064
+ title: zh.openSession,
4065
+ 'aria-label': zh.openSession,
4066
+ onClick: openSession,
4067
+ }, h(IconRightUpOutlineRegular, { size: 14 }))
4068
+ : null
4069
+ const openLink = openSession
4070
+ ? h('button', { type: 'button', className: 'capital-automation-btn', 'data-size': 'sm', onClick: openSession }, zh.openSession)
4053
4071
  : null
4054
4072
  const trigger = card.trigger === 'manual' ? zh.triggerManual : zh.triggerScheduled
4055
4073
  const relativeTime = boardRelativeTime(card.finishedAt)
@@ -4074,11 +4092,11 @@ function BriefCard(props) {
4074
4092
  disabled: retrying === true,
4075
4093
  onClick: () => onRetry(card.runId),
4076
4094
  }, retrying === true ? zh.processing : zh.board.retry),
4077
- open))
4095
+ openLink))
4078
4096
  } else if (status === 'skipped') {
4079
4097
  body = h('div', { className: 'capital-automation-briefstate' },
4080
4098
  h('p', null, zh.board.briefSkipped),
4081
- h('div', { className: 'capital-automation-briefactions' }, open))
4099
+ h('div', { className: 'capital-automation-briefactions' }, openLink))
4082
4100
  } else {
4083
4101
  body = h('div', { className: 'capital-automation-briefstate' },
4084
4102
  h(SkeletonBlock, { width: '72%', height: 14 }),
@@ -4097,7 +4115,7 @@ function BriefCard(props) {
4097
4115
  dateTime: card.finishedAt,
4098
4116
  title: exactTime,
4099
4117
  }, relativeTime)),
4100
- open),
4118
+ openIcon),
4101
4119
  body)
4102
4120
  }
4103
4121
 
@@ -4163,7 +4181,7 @@ function BriefFeed(props) {
4163
4181
  }
4164
4182
 
4165
4183
  function TodoRow(props) {
4166
- const { item, period, showDue = true, onOpenSession } = props
4184
+ const { item, period, showDue = true, onOpenSession, onAck, acking = false, ackDisabled = false } = props
4167
4185
  const [open, setOpen] = useState(false)
4168
4186
  const quote = item.sourceQuote ?? item.sources?.[0]?.sourceQuote
4169
4187
  const due = showDue === true ? boardTodoDueLabel(item, period) : ''
@@ -4179,7 +4197,17 @@ function TodoRow(props) {
4179
4197
  const basisCaret = h('span', { className: 'capital-automation-basiscaret', 'aria-hidden': 'true' }, h(IconChevronDownOutlineRegular, { size: 12 }))
4180
4198
  return h('li', { className: 'capital-automation-todoitem' },
4181
4199
  h('div', { className: 'capital-automation-todoline' },
4182
- h('span', { className: 'capital-automation-todokind', 'data-kind': item.kind }, boardTodoKindLabel(item.kind)),
4200
+ h('div', { className: 'capital-automation-todotop' },
4201
+ h('span', { className: 'capital-automation-todokind', 'data-kind': item.kind }, boardTodoKindLabel(item.kind)),
4202
+ h('button', {
4203
+ type: 'button',
4204
+ className: 'capital-automation-btn',
4205
+ 'data-size': 'sm',
4206
+ title: zh.board.todoAckTitle,
4207
+ 'aria-label': `${zh.board.todoAckTitle}:${item.title}`,
4208
+ disabled: ackDisabled === true,
4209
+ onClick: () => onAck(item),
4210
+ }, acking === true ? zh.processing : zh.board.todoAck)),
4183
4211
  h('button', {
4184
4212
  type: 'button',
4185
4213
  className: 'capital-automation-todotitle',
@@ -4240,13 +4268,14 @@ function BoardPanel(props) {
4240
4268
  }
4241
4269
 
4242
4270
  function TodoPanel(props) {
4243
- const { todos, onOpenSession, open, onToggle } = props
4244
- const [filter, setFilter] = useState('all')
4245
- const entries = todos.map((item) => ({ item, period: boardTodoPeriod(item) }))
4271
+ const { todos, onOpenSession, onAckTodo, ackingTodoId, open, onToggle } = props
4272
+ const [filter, setFilter] = useState('today')
4273
+ const now = new Date()
4274
+ const entries = todos.map((item) => ({ item, period: boardTodoPeriod(item, now) }))
4246
4275
  entries.sort((left, right) => BOARD_TODO_PERIODS.indexOf(left.period) - BOARD_TODO_PERIODS.indexOf(right.period))
4247
- const visible = filter === 'all' ? entries : entries.filter((entry) => entry.period === filter)
4248
- const emptyText = filter === 'all'
4249
- ? zh.board.todoEmpty
4276
+ const visible = entries.filter((entry) => entry.period === filter)
4277
+ const emptyText = filter === 'today'
4278
+ ? zh.board.todoEmptyToday
4250
4279
  : zh.board.todoEmptyGroup.replace('{label}', boardTodoGroupLabel(filter))
4251
4280
  return h(BoardPanel, {
4252
4281
  id: 'capital-automation-todo',
@@ -4268,8 +4297,11 @@ function TodoPanel(props) {
4268
4297
  key: entry.item.id,
4269
4298
  item: entry.item,
4270
4299
  period: entry.period,
4271
- showDue: filter === 'all',
4300
+ showDue: true,
4272
4301
  onOpenSession,
4302
+ onAck: onAckTodo,
4303
+ acking: ackingTodoId === entry.item.id,
4304
+ ackDisabled: ackingTodoId !== null && ackingTodoId !== undefined,
4273
4305
  }))))
4274
4306
  }
4275
4307
 
@@ -4439,7 +4471,7 @@ function BoardPage(props) {
4439
4471
  const {
4440
4472
  board, loading, error, range, category, onRange, onCategory, onRefresh,
4441
4473
  onOpenSession, onRetryBrief, retryingRunId, onLoadMore, loadingMore, onGoTasks, onNewTask, onGoRuns,
4442
- hasActiveTasks, storageReady,
4474
+ onAckTodo, ackingTodoId, hasActiveTasks, storageReady,
4443
4475
  } = props
4444
4476
  const [railOpen, setRailOpen] = useState(() => readBoardUi().rail !== false)
4445
4477
  const [openPanels, setOpenPanels] = useState(() => boardPanelFlags(readBoardUi().panels))
@@ -4500,6 +4532,9 @@ function BoardPage(props) {
4500
4532
  error.length > 0 ? h('div', { className: 'capital-automation-banner', 'data-tone': 'error', role: 'alert' }, error) : null,
4501
4533
  h(BoardEmpty, { hasActiveTasks, storageReady, onGoTasks, onNewTask }))
4502
4534
  }
4535
+ const boardStats = board?.stats === undefined
4536
+ ? undefined
4537
+ : { ...board.stats, todos: boardTodoTodayCount(board?.todos ?? []) }
4503
4538
  return h('div', { className: 'capital-automation-board' },
4504
4539
  h(BoardToolbar, {
4505
4540
  range,
@@ -4512,7 +4547,7 @@ function BoardPage(props) {
4512
4547
  onToggleRail: toggleRail,
4513
4548
  }),
4514
4549
  error.length > 0 ? h('div', { className: 'capital-automation-banner', 'data-tone': 'error', role: 'alert' }, error) : null,
4515
- h(BoardStats, { stats: board?.stats, onJump: jumpTo }),
4550
+ h(BoardStats, { stats: boardStats, onJump: jumpTo }),
4516
4551
  h('div', {
4517
4552
  className: 'capital-automation-boardgrid',
4518
4553
  'data-rail': railOpen === true ? 'open' : 'closed',
@@ -4536,7 +4571,14 @@ function BoardPage(props) {
4536
4571
  className: 'capital-automation-boardrail',
4537
4572
  hidden: railOpen !== true,
4538
4573
  },
4539
- h(TodoPanel, { todos: board?.todos ?? [], onOpenSession, open: openPanels.todo, onToggle: () => togglePanel('todo') }),
4574
+ h(TodoPanel, {
4575
+ todos: board?.todos ?? [],
4576
+ onOpenSession,
4577
+ onAckTodo,
4578
+ ackingTodoId,
4579
+ open: openPanels.todo,
4580
+ onToggle: () => togglePanel('todo'),
4581
+ }),
4540
4582
  h(StockRadar, {
4541
4583
  stocks: board?.stocks ?? [],
4542
4584
  todos: board?.todos ?? [],
@@ -4574,6 +4616,7 @@ function AutomationPage(props) {
4574
4616
  const [boardRange, setBoardRange] = useState('14')
4575
4617
  const [boardCategory, setBoardCategory] = useState('all')
4576
4618
  const [retryingBriefId, setRetryingBriefId] = useState(null)
4619
+ const [ackingTodoId, setAckingTodoId] = useState(null)
4577
4620
  const [boardLoadingMore, setBoardLoadingMore] = useState(false)
4578
4621
  const [unread, setUnread] = useState(0)
4579
4622
  const [selectedId, setSelectedId] = useState(null)
@@ -4696,6 +4739,39 @@ function AutomationPage(props) {
4696
4739
  }
4697
4740
  }
4698
4741
 
4742
+ async function ackTodo(item) {
4743
+ if (ackingTodoId !== null) return
4744
+ setAckingTodoId(item.id)
4745
+ setBoardError('')
4746
+ try {
4747
+ await api.confirmTodo(item.id)
4748
+ setBoard((current) => {
4749
+ if (current === null) return current
4750
+ const removed = (current.todos ?? []).find((entry) => entry.id === item.id)
4751
+ if (removed === undefined) return current
4752
+ const todos = current.todos.filter((entry) => entry.id !== item.id)
4753
+ const stocks = (current.stocks ?? []).map((stock) =>
4754
+ removed.symbol !== undefined && stock.symbol === removed.symbol
4755
+ ? { ...stock, todoCount: Math.max(0, (stock.todoCount ?? 0) - 1) }
4756
+ : stock)
4757
+ return {
4758
+ ...current,
4759
+ todos,
4760
+ stocks,
4761
+ stats: current.stats === undefined
4762
+ ? current.stats
4763
+ : { ...current.stats, todos: Math.max(0, (current.stats.todos ?? 0) - 1) },
4764
+ }
4765
+ })
4766
+ setNotice(zh.board.todoAcked)
4767
+ void loadBoard(boardRange, boardCategory)
4768
+ } catch (error) {
4769
+ setBoardError(error.message ?? zh.errorGeneric)
4770
+ } finally {
4771
+ setAckingTodoId(null)
4772
+ }
4773
+ }
4774
+
4699
4775
  async function loadDetail(id) {
4700
4776
  const requestSequence = detailSequenceRef.current + 1
4701
4777
  detailSequenceRef.current = requestSequence
@@ -4917,6 +4993,8 @@ function AutomationPage(props) {
4917
4993
  onOpenSession: openSession,
4918
4994
  onRetryBrief: (runId) => { void retryBrief(runId) },
4919
4995
  retryingRunId: retryingBriefId,
4996
+ onAckTodo: (item) => { void ackTodo(item) },
4997
+ ackingTodoId,
4920
4998
  onLoadMore: () => { void loadMoreBoard() },
4921
4999
  loadingMore: boardLoadingMore,
4922
5000
  onGoTasks: () => switchTab('tasks'),
@@ -35,6 +35,7 @@ export const QUIET_SETTLE_MS = 750
35
35
  export const MAX_RUNS_PER_TASK = 200
36
36
  export const MAX_RUNS_PER_PROFILE = 2_000
37
37
  export const MAX_NOTIFICATIONS_PER_PROFILE = 200
38
+ export const MAX_TODO_ACKS_PER_PROFILE = 500
38
39
  export const MAX_ERRORS_PER_RUN = 20
39
40
 
40
41
  export const MAX_TITLE_CHARS = 120
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-automation",
3
- "version": "2.17.0",
3
+ "version": "2.19.0",
4
4
  "description": "CapGen 投研自动化:独立 host bundle(固定 capital_automation 域、单 scheduler owner、/capital-automation 路由与浏览器页面)。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -233,6 +233,9 @@ async function dispatch({ req, method, suffix, url, service, requestId }) {
233
233
  if (suffix === '/board' && method === 'GET') {
234
234
  return { body: await service.board(queryOf(url, new Set(['days', 'tz', 'limit', 'before', 'category']), 5)) }
235
235
  }
236
+ if (suffix === '/board/todos/confirm' && method === 'POST') {
237
+ return { body: await service.confirmTodo(await readBody(req)) }
238
+ }
236
239
  const briefRetry = /^\/board\/briefs\/([^/]+)\/retry$/.exec(suffix)
237
240
  if (briefRetry !== null && method === 'POST') {
238
241
  return { body: await service.retryBrief(decodeId(briefRetry[1])), status: 202 }
@@ -440,7 +440,7 @@ export function createRunRunner(options) {
440
440
  armIdle(entry)
441
441
  return
442
442
  }
443
- await finalize(entry, outcomeOf(entry), outcomeError(entry))
443
+ await finalize(entry, outcomeOf(entry), { error: outcomeError(entry) })
444
444
  } finally {
445
445
  entry.completing = false
446
446
  }
@@ -680,7 +680,7 @@ export function createRunRunner(options) {
680
680
  if (settled !== undefined) {
681
681
  entry.abandoned = true
682
682
  entry.abandonPromise = (async () => {
683
- await finalize(entry, settled)
683
+ await finalize(entry, settled, { error: outcomeError(entry) })
684
684
  await stopEntryAgent(entry, controller)
685
685
  })()
686
686
  return entry.abandonPromise
@@ -338,6 +338,18 @@ export const TaskBriefSchema = z.strictObject({
338
338
  }
339
339
  })
340
340
 
341
+ /**
342
+ * User acknowledgement of an aggregated TODO. Briefs stay read-only; the ack only suppresses
343
+ * the version the user saw. A later run mentioning the same item produces a newer `lastSeenAt`
344
+ * and the item shows up again.
345
+ */
346
+ export const TodoAckSchema = z.strictObject({
347
+ schemaVersion: z.literal(1),
348
+ profileKey: z.string().min(1).max(80),
349
+ todoId: z.string().min(1).max(200),
350
+ confirmedAt: isoInstant,
351
+ })
352
+
341
353
  export const OwnerRecordSchema = z.strictObject({
342
354
  schemaVersion: z.literal(1),
343
355
  profileKey: z.string().min(1).max(80),
@@ -374,6 +386,10 @@ export const TaskPatchSchema = z.strictObject({
374
386
  notifications: NotificationsSchema.optional(),
375
387
  })
376
388
 
389
+ export const TodoConfirmSchema = z.strictObject({
390
+ id: z.string().min(1).max(200),
391
+ })
392
+
377
393
  export const NotificationsReadSchema = z.strictObject({
378
394
  ids: z.array(z.string().min(1).max(80)).max(200).optional(),
379
395
  all: z.boolean().optional(),
@@ -21,6 +21,7 @@ import {
21
21
  TaskCategorySchema,
22
22
  TaskCreateSchema,
23
23
  TaskPatchSchema,
24
+ TodoConfirmSchema,
24
25
  parseStrict,
25
26
  } from './schema.js'
26
27
  import { sanitizeMessage } from './redact.js'
@@ -384,6 +385,19 @@ export function createAutomationService(options) {
384
385
  }
385
386
  }
386
387
 
388
+ async function confirmTodo(input) {
389
+ if (boardService === undefined || typeof boardService.confirmTodo !== 'function') {
390
+ throw new AutomationError('board_unavailable', '看板服务暂时不可用。', 503)
391
+ }
392
+ const parsed = parseStrict(TodoConfirmSchema, input, 'board/todo-confirm')
393
+ try {
394
+ return await boardService.confirmTodo(parsed.id)
395
+ } catch (error) {
396
+ if (error?.boardError === true) throw new AutomationError(error.code, error.message, error.status ?? 400)
397
+ throw error
398
+ }
399
+ }
400
+
387
401
  async function retryBrief(runId) {
388
402
  if (briefs === undefined || typeof briefs.retry !== 'function') {
389
403
  throw new AutomationError('brief_not_found', '任务简报服务暂时不可用。', 503)
@@ -444,6 +458,7 @@ export function createAutomationService(options) {
444
458
  listRuns,
445
459
  runHistory,
446
460
  board,
461
+ confirmTodo,
447
462
  retryBrief,
448
463
  listNotifications,
449
464
  markNotificationsRead,
@@ -15,6 +15,7 @@ import {
15
15
  TaskBriefSchema,
16
16
  TaskOverridesSchema,
17
17
  TaskRecordSchema,
18
+ TodoAckSchema,
18
19
  isActiveRun,
19
20
  parseStrict,
20
21
  resolveTaskRecord,
@@ -27,6 +28,7 @@ import {
27
28
  MAX_NOTIFICATIONS_PER_PROFILE,
28
29
  MAX_RUNS_PER_PROFILE,
29
30
  MAX_RUNS_PER_TASK,
31
+ MAX_TODO_ACKS_PER_PROFILE,
30
32
  SETTLED_RUN_STATUSES,
31
33
  } from './defaults.js'
32
34
  import { canonicalTrigger, formatInZone, nextOccurrence } from './time.js'
@@ -48,6 +50,7 @@ export const domainSpec = {
48
50
  notifications: { valueSchema: NotificationSchema },
49
51
  meta: { valueSchema: OwnerRecordSchema },
50
52
  briefs: { valueSchema: TaskBriefSchema },
53
+ todo_acks: { valueSchema: TodoAckSchema },
51
54
  },
52
55
  }
53
56
 
@@ -60,6 +63,11 @@ function builtinRecordId(profileKey, builtinId) {
60
63
  return `bt_${createHash('sha256').update(`${profileKey}:${builtinId}`).digest('hex').slice(0, 24)}`
61
64
  }
62
65
 
66
+ /** Hash the long, user-visible TODO id so the storage key stays bounded and plain. */
67
+ function todoAckRecordId(profileKey, todoId) {
68
+ return `ta_${createHash('sha256').update(`${profileKey}\u0000${todoId}`).digest('hex').slice(0, 32)}`
69
+ }
70
+
63
71
  function iso(now) {
64
72
  return new Date(now).toISOString()
65
73
  }
@@ -184,6 +192,7 @@ export function createAutomationStore(options) {
184
192
  notifications: domain.table('notifications'),
185
193
  meta: domain.table('meta'),
186
194
  briefs: domain.table('briefs'),
195
+ todoAcks: domain.table('todo_acks'),
187
196
  }
188
197
  })()
189
198
  }
@@ -748,6 +757,40 @@ export function createAutomationStore(options) {
748
757
  return count
749
758
  }
750
759
 
760
+ async function listTodoAcks() {
761
+ const tables = await ensure()
762
+ const records = []
763
+ for (const [, record] of tables.todoAcks.entries()) {
764
+ if (record.profileKey === profileKey) records.push(record)
765
+ }
766
+ return records
767
+ }
768
+
769
+ async function retainTodoAcks(tables) {
770
+ const records = []
771
+ for (const [key, record] of tables.todoAcks.entries()) {
772
+ if (record.profileKey === profileKey) records.push({ key, record })
773
+ }
774
+ if (records.length <= MAX_TODO_ACKS_PER_PROFILE) return
775
+ records.sort((left, right) =>
776
+ right.record.confirmedAt.localeCompare(left.record.confirmedAt)
777
+ || right.key.localeCompare(left.key))
778
+ for (const entry of records.slice(MAX_TODO_ACKS_PER_PROFILE)) await tables.todoAcks.delete(entry.key)
779
+ }
780
+
781
+ async function confirmTodo(todoId) {
782
+ const tables = await ensure()
783
+ const record = parseStrict(TodoAckSchema, {
784
+ schemaVersion: 1,
785
+ profileKey,
786
+ todoId,
787
+ confirmedAt: iso(now()),
788
+ }, 'todo ack')
789
+ await tables.todoAcks.put(todoAckRecordId(profileKey, todoId), record)
790
+ await retainTodoAcks(tables)
791
+ return record
792
+ }
793
+
751
794
  async function updateBrief(runId, patch) {
752
795
  const tables = await ensure()
753
796
  const current = tables.briefs.get(runId)
@@ -949,6 +992,8 @@ export function createAutomationStore(options) {
949
992
  listBriefsForRuns,
950
993
  listBriefsForProfile,
951
994
  countBriefs,
995
+ listTodoAcks,
996
+ confirmTodo,
952
997
  updateBrief,
953
998
  deleteBrief,
954
999
  publicBrief,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-charts",
3
- "version": "2.17.0",
3
+ "version": "2.19.0",
4
4
  "description": "自动模式的图表前端组件(浏览器半边 + 序列旁路路由):由 @v587d/capital-generation 随包携带并作为 host 平面行挂载。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/config",
3
- "version": "2.17.0",
3
+ "version": "2.19.0",
4
4
  "description": "自动模式的取数凭据与偏好配置行:卡片坐在 @v587d/capital-generation 插件主页的「配置」段,点这一行本身没有表单。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -6,15 +6,16 @@
6
6
  import type { AgentLike, GuardedExecution, PolicyContext } from './root-tool-policy.js';
7
7
  import { type RolePresetId } from '../preset-ids.js';
8
8
  export { ROLE_PRESET_IDS, ROLE_PRESET_ID_LIST, type RolePresetId } from '../preset-ids.js';
9
- /** Welded to `send_message` by `tool-subagent-control`; no host switch, so leaf roles deny it by name. */
10
- export declare const SIBLING_DENIED_TOOLS: readonly ["interrupt_agent"];
9
+ /** Registered together with `send_message` by `tool-subagent-control`; no host switch, so leaf roles deny these by name.
10
+ * 0.2.2 moved `list_agents` into the same main entry, so the welded set grew from one to two names. */
11
+ export declare const SIBLING_DENIED_TOOLS: readonly ["interrupt_agent", "list_agents"];
11
12
  /** Residual surface; no allow list: family rows define the tool surface. */
12
13
  export interface RoleSurface {
13
14
  /** Sibling names welded into a needed row that this persona must not have. */
14
15
  readonly denySiblings?: readonly string[];
15
16
  }
16
- /** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent`; specialist
17
- * mounts no control row. Tolerant per-name deny records misses without failing open. */
17
+ /** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent` / `list_agents`;
18
+ * specialist mounts no control row. Tolerant per-name deny records misses without failing open. */
18
19
  export declare const ROLE_TOOL_SURFACES: Record<RolePresetId, RoleSurface>;
19
20
  /** Role preset id only, undefined for root and other presets; failure means "do not converge". */
20
21
  export declare function rolePresetIdOf(ctx: PolicyContext, agent: AgentLike | undefined): RolePresetId | undefined;
@@ -7,10 +7,11 @@ import { isRootAgent, recordGuardDecision } from './root-tool-policy.js';
7
7
  import { readPresetClaim } from '../preset-claim.js';
8
8
  import { ROLE_PRESET_ID_LIST, ROLE_PRESET_IDS } from '../preset-ids.js';
9
9
  export { ROLE_PRESET_IDS, ROLE_PRESET_ID_LIST } from '../preset-ids.js';
10
- /** Welded to `send_message` by `tool-subagent-control`; no host switch, so leaf roles deny it by name. */
11
- export const SIBLING_DENIED_TOOLS = ['interrupt_agent'];
12
- /** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent`; specialist
13
- * mounts no control row. Tolerant per-name deny records misses without failing open. */
10
+ /** Registered together with `send_message` by `tool-subagent-control`; no host switch, so leaf roles deny these by name.
11
+ * 0.2.2 moved `list_agents` into the same main entry, so the welded set grew from one to two names. */
12
+ export const SIBLING_DENIED_TOOLS = ['interrupt_agent', 'list_agents'];
13
+ /** Leaf roles need `send_message`, so they inherit the welded `interrupt_agent` / `list_agents`;
14
+ * specialist mounts no control row. Tolerant per-name deny records misses without failing open. */
14
15
  export const ROLE_TOOL_SURFACES = {
15
16
  [ROLE_PRESET_IDS.collector]: { denySiblings: SIBLING_DENIED_TOOLS },
16
17
  [ROLE_PRESET_IDS.junior]: { denySiblings: SIBLING_DENIED_TOOLS },
@@ -76,6 +77,10 @@ export function roleSiblingGuardReasonFor(ctx) {
76
77
  return undefined;
77
78
  if (!ROLE_PRESET_ID_LIST.includes(claim.claim))
78
79
  return undefined;
80
+ if (name === 'list_agents') {
81
+ return `${name} 不对人设 ${claim.claim} 开放:叶子角色只回传自己的结果,子 Agent 名单与调度归主 Agent。`
82
+ + '需要别的 Agent 配合,用 send_message 回告主 Agent;不要自己换工具硬做。';
83
+ }
79
84
  return `${name} 不对人设 ${claim.claim} 开放:叶子角色只回传自己的结果,打断别的会话归主 Agent 决定。`
80
85
  + '需要别的 Agent 停下来,用 send_message 回告主 Agent;不要自己换工具硬做。';
81
86
  };
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * Chart delivery at the closing answer.
3
3
  *
4
- * DSH's deliverable card only replays `deliverables/presented` events whose seq is before the
5
- * turn's closing assistant message, and a turn is final only after the fact. The one place that is
6
- * provably before the closing message is the assistant stream's terminal `finish` chunk: the loop
7
- * appends the message after the stream ends. So delivery is deferred to that chunk, gated on the
8
- * root session being idle (no actionable inbox input, no running direct children), which is exactly
9
- * the shape of a closing turn. Waiting/aborted/tool-call responses never flush.
4
+ * DSH's deliverable card replays `deliverables/presented` from the closing turn (0.2.2 dropped the
5
+ * `file.seq < owner.seq` filter, so late declarations are no longer lost). A turn is still final
6
+ * only after the fact, and the one place where that is knowable before the turn closes is the
7
+ * assistant stream's terminal `finish` chunk: the loop appends the message after the stream ends.
8
+ * So delivery is deferred to that chunk, gated on the root session being idle (no actionable inbox
9
+ * input, no running direct children), which is exactly the shape of a closing turn.
10
+ * Waiting/aborted/tool-call responses never flush.
10
11
  *
11
12
  * `subagent-settled` notices are not actionable input: they can arrive while the closing answer is
12
13
  * already streaming. Counting them as pending would strand a card that the model has just selected,
@@ -46,7 +47,7 @@ interface InboxStateLike {
46
47
  }
47
48
  export interface ChartDeliveryOptions {
48
49
  artifacts: ChartArtifactRegistry;
49
- /** Writes one first-party deliverables/presented batch; must be synchronous (pre-message seq). */
50
+ /** Writes one first-party deliverables/presented batch; must be synchronous (listener runs before the message commits). */
50
51
  publish: (sessionId: string, inputs: ChartTurnEventInput[]) => boolean;
51
52
  /** Durable pending input; synchronous projection read. Absent means "cannot tell" → proceed. */
52
53
  inboxOf?: (session: SessionLike) => InboxStateLike | undefined;