@v587d/capital-generation 2.20.0 → 2.21.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 +34 -0
- package/README.md +7 -21
- package/automation/board.js +121 -9
- package/automation/brief.js +71 -15
- package/automation/builtins.js +17 -0
- package/automation/client.js +21 -12
- package/automation/client.src.cjs +462 -154
- package/automation/index.js +19 -5
- package/automation/package.json +1 -1
- package/automation/route.js +3 -0
- package/automation/runner.js +48 -4
- package/automation/scheduler.js +12 -0
- package/automation/schema.js +20 -2
- package/automation/service.js +15 -0
- package/automation/store.js +16 -3
- package/automation/task-icons.js +1 -0
- package/automation/watch.js +261 -159
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/chart/delivery.js +8 -6
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +1 -1
- package/plugin-page/README.en.md +1 -1
- package/plugin-page/README.zh.md +1 -1
- package/watchlist/package.json +1 -1
|
@@ -118,7 +118,7 @@ const zh = {
|
|
|
118
118
|
statsIssuesToday: '今天运行异常',
|
|
119
119
|
statsBriefsTodayHint: '点击高亮今天的简报卡片',
|
|
120
120
|
statsTodoHint: '点击查看今天的 TODO',
|
|
121
|
-
statsTodoManualHint: '
|
|
121
|
+
statsTodoManualHint: '需要你处理或跟踪的 TODO',
|
|
122
122
|
statsTodoAutoHint: '自动核验中的 TODO',
|
|
123
123
|
statsStockHint: '点击查看个股动态',
|
|
124
124
|
statsGapHint: '点击查看数据能力缺口',
|
|
@@ -160,18 +160,26 @@ const zh = {
|
|
|
160
160
|
stockShowAll: '展开全部 {n} 只',
|
|
161
161
|
stockShowLess: '收起',
|
|
162
162
|
gapsCount: '{n} 个缺口',
|
|
163
|
-
todoAckTitle: '标记为已确认',
|
|
164
163
|
todoAcked: '已确认',
|
|
164
|
+
todoMoreTitle: '更多操作',
|
|
165
|
+
todoActionConfirm: '已确认',
|
|
166
|
+
todoActionAuto: '转入自动校验',
|
|
167
|
+
todoActionDefer: '忽略',
|
|
168
|
+
todoAutoQueued: '已转入自动校验,下一次收盘核验',
|
|
169
|
+
todoDeferred: '已忽略当前版本',
|
|
165
170
|
watchWatching: '自动核验中',
|
|
166
171
|
watchTriggered: '已触发',
|
|
167
|
-
watchNeedsHuman: '
|
|
172
|
+
watchNeedsHuman: '待人工处理',
|
|
168
173
|
watchResolved: '已确认',
|
|
169
|
-
|
|
174
|
+
watchDeferred: '忽略',
|
|
175
|
+
watchExpired: '已过期',
|
|
170
176
|
watchTracking: '跟踪',
|
|
171
177
|
watchEvidence: '核验依据',
|
|
178
|
+
watchSource: '来源',
|
|
179
|
+
watchDeferredHint: '已忽略当前版本;后续新版本会重新出现',
|
|
172
180
|
watchChecked: '核验于 {time}',
|
|
173
181
|
notificationFallbackTodoTriggered: '条件已触发,查看 TODO 详情。',
|
|
174
|
-
notificationFallbackTodoNeedsHuman: '
|
|
182
|
+
notificationFallbackTodoNeedsHuman: '自动核验无法完成,需要你处理。',
|
|
175
183
|
todoEmptyToday: '今天暂无待办',
|
|
176
184
|
todoEmptyGroup: '暂无「{label}」待办',
|
|
177
185
|
todoFilterLabel: '按日期筛选',
|
|
@@ -1075,11 +1083,21 @@ function installStyles() {
|
|
|
1075
1083
|
.capital-automation-boardemptyhint { color: var(--ca-caption); font-size: 11.5px !important; line-height: 18px !important; }
|
|
1076
1084
|
.capital-automation-boardemptyactions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin-top: 6px; }
|
|
1077
1085
|
.capital-automation-todolist, .capital-automation-stocktodos, .capital-automation-gaplist, .capital-automation-gaprow { list-style: none; margin: 0; padding: 0; }
|
|
1078
|
-
.capital-automation-todoitem { padding: 8px 0; border-top: .5px solid var(--ca-line); }
|
|
1086
|
+
.capital-automation-todoitem { padding: 8px 0; border-top: .5px solid var(--ca-line); transition: opacity .16s ease, padding .18s ease; }
|
|
1079
1087
|
.capital-automation-todoitem:first-child { border-top: 0; }
|
|
1088
|
+
.capital-automation-todoitem[data-decided="true"], .capital-automation-todoitem[data-archived="true"] { padding: 7px 0; opacity: .72; border-top: 0; }
|
|
1089
|
+
.capital-automation-todoitem:not([data-decided="true"]) + .capital-automation-todoitem[data-decided="true"] { border-top: .5px solid var(--ca-line); }
|
|
1090
|
+
.capital-automation-todoitem[data-decided="true"]:hover, .capital-automation-todoitem[data-archived="true"]:hover { opacity: 1; }
|
|
1091
|
+
.capital-automation-todoitem[data-decided="true"] .capital-automation-todoline, .capital-automation-todoitem[data-archived="true"] .capital-automation-todoline { gap: 0; }
|
|
1092
|
+
.capital-automation-todoitem[data-decided="true"] .capital-automation-todotop, .capital-automation-todoitem[data-archived="true"] .capital-automation-todotop { justify-content: flex-start; gap: 10px; }
|
|
1093
|
+
.capital-automation-todoitem[data-decided="true"] .capital-automation-todotitle, .capital-automation-todoitem[data-archived="true"] .capital-automation-todotitle { flex: 1 1 auto; width: auto; min-width: 0; color: var(--ca-muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
1094
|
+
.capital-automation-todoitem[data-decided="true"] .capital-automation-todotitle { cursor: default; }
|
|
1095
|
+
.capital-automation-todoitem[data-archived="true"] .capital-automation-todotitle { cursor: pointer; }
|
|
1096
|
+
.capital-automation-todoitem[data-decided="true"] .capital-automation-todotitle:hover { color: var(--ca-muted); }
|
|
1097
|
+
.capital-automation-todoitem[data-archived="true"] .capital-automation-todotitle:hover { color: var(--ca-business-text); }
|
|
1080
1098
|
.capital-automation-todoline { display: flex; flex-direction: column; align-items: stretch; gap: 5px; min-width: 0; }
|
|
1081
1099
|
.capital-automation-todotop { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
|
|
1082
|
-
.capital-automation-todotags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 5px; min-width: 0; }
|
|
1100
|
+
.capital-automation-todotags { display: flex; flex: none; flex-wrap: wrap; align-items: center; gap: 4px 5px; min-width: 0; }
|
|
1083
1101
|
.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; }
|
|
1084
1102
|
.capital-automation-todotitle:hover, .capital-automation-gaptitle:hover { color: var(--ca-business-text); }
|
|
1085
1103
|
.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; }
|
|
@@ -1087,20 +1105,19 @@ function installStyles() {
|
|
|
1087
1105
|
.capital-automation-todotitle[aria-expanded="true"] .capital-automation-basiscaret, .capital-automation-gaptitle[aria-expanded="true"] .capital-automation-basiscaret { transform: rotate(0deg); }
|
|
1088
1106
|
.capital-automation-tododesc { margin: 3px 0 0; color: var(--ca-muted); font-size: 12px; line-height: 20px; overflow-wrap: anywhere; }
|
|
1089
1107
|
.capital-automation-todometa { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 3px; color: var(--ca-caption); font-size: 11px; line-height: 17px; }
|
|
1108
|
+
.capital-automation-todooutcome { color: var(--ca-muted); font-weight: 500; }
|
|
1090
1109
|
.capital-automation-todowatch { display: inline-flex; flex: none; align-items: center; min-height: 20px; padding: 0 6px; border-radius: 999px; background: var(--dsw-alias-bg-module-platform); color: var(--ca-muted); font-size: 10px; line-height: 20px; white-space: nowrap; }
|
|
1091
1110
|
.capital-automation-todowatch[data-status="triggered"] { background: color-mix(in srgb, var(--ca-error) 12%, var(--ca-card)); color: var(--ca-error-text); }
|
|
1092
1111
|
.capital-automation-todowatch[data-status="needs_human"] { background: color-mix(in srgb, var(--ca-warn) 14%, var(--ca-card)); color: var(--ca-warn-text); }
|
|
1093
1112
|
.capital-automation-todowatch[data-status="watching"] { color: var(--ca-business-text); }
|
|
1094
1113
|
.capital-automation-todowatch[data-status="resolved"] { background: color-mix(in srgb, var(--ca-success) 14%, var(--ca-card)); color: var(--ca-success-text); }
|
|
1114
|
+
.capital-automation-todowatch[data-status="deferred"] { background: color-mix(in srgb, var(--ca-muted) 12%, var(--ca-card)); color: var(--ca-muted); }
|
|
1095
1115
|
.capital-automation-todowatch[data-status="tracking"] { color: var(--ca-muted); }
|
|
1096
1116
|
.capital-automation-todowatch[data-status="expired"] { color: var(--ca-caption); }
|
|
1097
|
-
.capital-automation-
|
|
1098
|
-
.capital-automation-
|
|
1099
|
-
.capital-automation-
|
|
1100
|
-
.capital-automation-
|
|
1101
|
-
.capital-automation-todocheck[disabled] { opacity: .55; cursor: default; }
|
|
1102
|
-
.capital-automation-todocheckspin { width: 10px; height: 10px; border: 2px solid var(--ca-line); border-top-color: var(--ca-business); border-radius: 50%; animation: capital-automation-todospin .7s linear infinite; }
|
|
1103
|
-
@keyframes capital-automation-todospin { to { transform: rotate(360deg); } }
|
|
1117
|
+
.capital-automation-todomenu { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--ca-muted); cursor: pointer; transition: background .15s ease, color .15s ease; }
|
|
1118
|
+
.capital-automation-todomenu:hover:not(:disabled) { background: var(--ca-hover); color: var(--dsw-alias-label-primary); }
|
|
1119
|
+
.capital-automation-todomenu:focus-visible { outline: 2px solid var(--dsw-focus-ring-color, var(--ca-business)); outline-offset: 2px; }
|
|
1120
|
+
.capital-automation-todomenu:disabled { opacity: .4; cursor: default; }
|
|
1104
1121
|
.capital-automation-todowatchmsg { margin: 1px 0 0; padding: 6px 9px; border-left: 2px solid var(--ca-line); border-radius: 0 7px 7px 0; background: var(--ca-field); color: var(--ca-muted); font-size: 11.5px; line-height: 18px; overflow-wrap: anywhere; }
|
|
1105
1122
|
.capital-automation-todowatchmsg[data-status="triggered"] { border-left-color: var(--ca-error); color: var(--ca-error-text); }
|
|
1106
1123
|
.capital-automation-tododetail { margin: 6px 0 0; padding: 7px 9px; border-left: 2px solid var(--ca-line); background: var(--ca-field); border-radius: 0 7px 7px 0; }
|
|
@@ -1265,6 +1282,7 @@ function createApi() {
|
|
|
1265
1282
|
},
|
|
1266
1283
|
warm,
|
|
1267
1284
|
confirmTodo: (id) => request('/board/todos/confirm', { method: 'POST', body: { id } }),
|
|
1285
|
+
decideTodo: (id, action) => request('/board/todos/decision', { method: 'POST', body: { id, action } }),
|
|
1268
1286
|
retryBrief: (runId) => request(`/board/briefs/${encodeURIComponent(runId)}/retry`, { method: 'POST' }),
|
|
1269
1287
|
askBrief: (runId, question, timeZone) => request(`/board/briefs/${encodeURIComponent(runId)}/ask`, {
|
|
1270
1288
|
method: 'POST',
|
|
@@ -4035,11 +4053,15 @@ function boardCardIsToday(card, today = localDateKey(new Date())) {
|
|
|
4035
4053
|
|
|
4036
4054
|
function boardTodoPeriod(item, now = new Date()) {
|
|
4037
4055
|
const today = localDateKey(now)
|
|
4038
|
-
// Triggered or handed-off items stay in today's action list even when dueAt has passed; a
|
|
4039
|
-
// confirmed one only stays there through the day it was acknowledged.
|
|
4040
4056
|
const watchedStatus = item.watch?.resolvedFrom ?? item.watch?.status
|
|
4041
|
-
const
|
|
4042
|
-
|
|
4057
|
+
const decidedAt = typeof item.ackedAt === 'string' ? item.ackedAt : item.deferredAt
|
|
4058
|
+
const decidedToday = typeof decidedAt === 'string' && localDateKey(new Date(decidedAt)) === today
|
|
4059
|
+
// A decision is feedback for the rest of today, then it belongs to the archive.
|
|
4060
|
+
if (decidedAt !== undefined) return decidedToday ? 'today' : 'expired'
|
|
4061
|
+
// A triggered condition is a fact: keep it actionable until the user decides.
|
|
4062
|
+
if (watchedStatus === 'triggered') return 'today'
|
|
4063
|
+
// A stopped watch has reached its lifecycle end, including date-less "尽快" items.
|
|
4064
|
+
if (item.watch?.status === 'expired') return 'expired'
|
|
4043
4065
|
if (typeof item.dueAt === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(item.dueAt)) {
|
|
4044
4066
|
if (item.dueAt < today) return 'expired'
|
|
4045
4067
|
if (item.dueAt === today) return 'today'
|
|
@@ -4049,7 +4071,11 @@ function boardTodoPeriod(item, now = new Date()) {
|
|
|
4049
4071
|
const label = typeof item.dueLabel === 'string' ? item.dueLabel.trim() : ''
|
|
4050
4072
|
const seen = typeof item.finishedAt === 'string' ? new Date(item.finishedAt) : null
|
|
4051
4073
|
const seenToday = seen !== null && !Number.isNaN(seen.getTime()) && localDateKey(seen) === today
|
|
4052
|
-
if (['尽快', '马上', '现在'].includes(label))
|
|
4074
|
+
if (['尽快', '马上', '现在'].includes(label)) {
|
|
4075
|
+
// A tracked "尽快" item stays actionable through its 72-hour watch window.
|
|
4076
|
+
if (item.watch !== null && item.watch !== undefined) return 'today'
|
|
4077
|
+
return seenToday ? 'today' : 'future'
|
|
4078
|
+
}
|
|
4053
4079
|
if (['今天', '今日'].includes(label)) return seenToday ? 'today' : 'expired'
|
|
4054
4080
|
return 'future'
|
|
4055
4081
|
}
|
|
@@ -4062,7 +4088,7 @@ function boardTodoTodaySplit(todos, now = new Date()) {
|
|
|
4062
4088
|
const split = { total: 0, manual: 0, auto: 0 }
|
|
4063
4089
|
for (const item of todos) {
|
|
4064
4090
|
const status = boardTodoStatus(item)
|
|
4065
|
-
if (status === 'resolved' || boardTodoPeriod(item, now) !== 'today') continue
|
|
4091
|
+
if (status === 'resolved' || status === 'deferred' || boardTodoPeriod(item, now) !== 'today') continue
|
|
4066
4092
|
split.total += 1
|
|
4067
4093
|
if (status === 'watching') split.auto += 1
|
|
4068
4094
|
else split.manual += 1
|
|
@@ -4076,6 +4102,162 @@ function boardTodoGroupLabel(period) {
|
|
|
4076
4102
|
return zh.board.dueFuture
|
|
4077
4103
|
}
|
|
4078
4104
|
|
|
4105
|
+
/**
|
|
4106
|
+
* Today's pending rows stay on top; acknowledged rows collapse to a single line at the bottom so
|
|
4107
|
+
* the next item visibly moves up. The newest confirmation is the last row of the day.
|
|
4108
|
+
*/
|
|
4109
|
+
function boardTodoEntries(todos, now = new Date()) {
|
|
4110
|
+
const entries = todos.map((item) => {
|
|
4111
|
+
const decidedAt = typeof item.ackedAt === 'string' ? item.ackedAt : item.deferredAt
|
|
4112
|
+
return {
|
|
4113
|
+
item,
|
|
4114
|
+
period: boardTodoPeriod(item, now),
|
|
4115
|
+
decided: typeof decidedAt === 'string' && decidedAt.length > 0,
|
|
4116
|
+
decidedAt,
|
|
4117
|
+
}
|
|
4118
|
+
})
|
|
4119
|
+
entries.sort((left, right) => {
|
|
4120
|
+
const period = BOARD_TODO_PERIODS.indexOf(left.period) - BOARD_TODO_PERIODS.indexOf(right.period)
|
|
4121
|
+
if (period !== 0) return period
|
|
4122
|
+
if (left.period === 'expired') {
|
|
4123
|
+
// Archive order is newest expiry first; undated rows fall to the end.
|
|
4124
|
+
return String(right.item.dueAt ?? '').localeCompare(String(left.item.dueAt ?? ''))
|
|
4125
|
+
|| String(right.item.lastSeenAt ?? '').localeCompare(String(left.item.lastSeenAt ?? ''))
|
|
4126
|
+
|| String(left.item.id).localeCompare(String(right.item.id))
|
|
4127
|
+
}
|
|
4128
|
+
if (left.period !== 'today') return 0
|
|
4129
|
+
if (left.decided !== right.decided) return left.decided ? 1 : -1
|
|
4130
|
+
if (left.decided && right.decided) return String(left.decidedAt).localeCompare(String(right.decidedAt))
|
|
4131
|
+
return 0
|
|
4132
|
+
})
|
|
4133
|
+
return entries
|
|
4134
|
+
}
|
|
4135
|
+
|
|
4136
|
+
function boardTodoIsOpen(item) {
|
|
4137
|
+
return typeof item.ackedAt !== 'string' && typeof item.deferredAt !== 'string'
|
|
4138
|
+
}
|
|
4139
|
+
|
|
4140
|
+
function closeBoardWatch(watch) {
|
|
4141
|
+
if (watch === null || watch === undefined) return watch
|
|
4142
|
+
return {
|
|
4143
|
+
...watch,
|
|
4144
|
+
status: 'resolved',
|
|
4145
|
+
resolvedFrom: watch.resolvedFrom ?? (watch.status === 'resolved' ? null : watch.status),
|
|
4146
|
+
autoRequestedAt: null,
|
|
4147
|
+
handoffReason: null,
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
|
|
4151
|
+
function reopenBoardWatch(watch, at) {
|
|
4152
|
+
if (watch === null || watch === undefined) return watch
|
|
4153
|
+
return {
|
|
4154
|
+
...watch,
|
|
4155
|
+
status: 'watching',
|
|
4156
|
+
resolvedFrom: null,
|
|
4157
|
+
autoRequestedAt: at,
|
|
4158
|
+
handoffReason: null,
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
|
|
4162
|
+
/** Applied before the server remembers the decision, and to every board refresh in flight. */
|
|
4163
|
+
function applyTodoDecision(current, todoId, action, at) {
|
|
4164
|
+
if (current === null) return current
|
|
4165
|
+
const target = (current.todos ?? []).find((entry) => entry.id === todoId)
|
|
4166
|
+
if (target === undefined) return current
|
|
4167
|
+
const wasOpen = boardTodoIsOpen(target)
|
|
4168
|
+
let next
|
|
4169
|
+
if (action === 'auto') {
|
|
4170
|
+
if (target.watch === null || target.watch === undefined) return current
|
|
4171
|
+
next = {
|
|
4172
|
+
...target,
|
|
4173
|
+
ackedAt: undefined,
|
|
4174
|
+
deferredAt: undefined,
|
|
4175
|
+
decision: undefined,
|
|
4176
|
+
watch: reopenBoardWatch(target.watch, at),
|
|
4177
|
+
}
|
|
4178
|
+
} else {
|
|
4179
|
+
const decision = action === 'defer' ? 'deferred' : 'confirmed'
|
|
4180
|
+
if (target.decision === decision) return current
|
|
4181
|
+
next = {
|
|
4182
|
+
...target,
|
|
4183
|
+
ackedAt: decision === 'confirmed' ? at : undefined,
|
|
4184
|
+
deferredAt: decision === 'deferred' ? at : undefined,
|
|
4185
|
+
decision,
|
|
4186
|
+
watch: closeBoardWatch(target.watch),
|
|
4187
|
+
}
|
|
4188
|
+
}
|
|
4189
|
+
const isOpen = boardTodoIsOpen(next)
|
|
4190
|
+
const todos = current.todos.map((entry) => entry.id === todoId ? next : entry)
|
|
4191
|
+
const targetKey = target.symbol === undefined ? undefined : boardEntrySymbolKey(target)
|
|
4192
|
+
let stockDelta = 0
|
|
4193
|
+
if (wasOpen && !isOpen) stockDelta = -1
|
|
4194
|
+
if (!wasOpen && isOpen) stockDelta = 1
|
|
4195
|
+
const stocks = stockDelta === 0
|
|
4196
|
+
? current.stocks
|
|
4197
|
+
: (current.stocks ?? []).map((stock) => {
|
|
4198
|
+
if (targetKey === undefined || boardEntrySymbolKey(stock) !== targetKey) return stock
|
|
4199
|
+
if (!Array.isArray(stock.items)) {
|
|
4200
|
+
return { ...stock, todoCount: Math.max(0, (stock.todoCount ?? 0) + stockDelta) }
|
|
4201
|
+
}
|
|
4202
|
+
if (stockDelta < 0) {
|
|
4203
|
+
const items = stock.items.filter((entry) => entry.id !== target.id)
|
|
4204
|
+
return { ...stock, items, todoCount: items.length }
|
|
4205
|
+
}
|
|
4206
|
+
if (stock.items.some((entry) => entry.id === todoId)) return stock
|
|
4207
|
+
const items = [...stock.items, { id: target.id, title: target.title, sessionId: target.sessionId ?? null }]
|
|
4208
|
+
return { ...stock, items, todoCount: items.length }
|
|
4209
|
+
})
|
|
4210
|
+
return {
|
|
4211
|
+
...current,
|
|
4212
|
+
todos,
|
|
4213
|
+
stocks,
|
|
4214
|
+
stats: current.stats === undefined || stockDelta === 0
|
|
4215
|
+
? current.stats
|
|
4216
|
+
: { ...current.stats, todos: Math.max(0, (current.stats.todos ?? 0) + stockDelta) },
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
|
|
4220
|
+
function restoreBoardTodoState(current, todoId, previous) {
|
|
4221
|
+
if (current === null) return current
|
|
4222
|
+
const target = (current.todos ?? []).find((entry) => entry.id === todoId)
|
|
4223
|
+
if (target === undefined) return current
|
|
4224
|
+
const next = {
|
|
4225
|
+
...target,
|
|
4226
|
+
ackedAt: previous.ackedAt,
|
|
4227
|
+
deferredAt: previous.deferredAt,
|
|
4228
|
+
decision: previous.decision,
|
|
4229
|
+
watch: previous.watch ?? null,
|
|
4230
|
+
}
|
|
4231
|
+
const wasOpen = boardTodoIsOpen(target)
|
|
4232
|
+
const isOpen = boardTodoIsOpen(next)
|
|
4233
|
+
const stockDelta = wasOpen === isOpen ? 0 : isOpen ? 1 : -1
|
|
4234
|
+
const todos = current.todos.map((entry) => entry.id === todoId ? next : entry)
|
|
4235
|
+
const targetKey = target.symbol === undefined ? undefined : boardEntrySymbolKey(target)
|
|
4236
|
+
const stocks = stockDelta === 0
|
|
4237
|
+
? current.stocks
|
|
4238
|
+
: (current.stocks ?? []).map((stock) => {
|
|
4239
|
+
if (targetKey === undefined || boardEntrySymbolKey(stock) !== targetKey) return stock
|
|
4240
|
+
if (!Array.isArray(stock.items)) {
|
|
4241
|
+
return { ...stock, todoCount: Math.max(0, (stock.todoCount ?? 0) + stockDelta) }
|
|
4242
|
+
}
|
|
4243
|
+
if (stockDelta < 0) {
|
|
4244
|
+
const items = stock.items.filter((entry) => entry.id !== todoId)
|
|
4245
|
+
return { ...stock, items, todoCount: items.length }
|
|
4246
|
+
}
|
|
4247
|
+
if (stock.items.some((entry) => entry.id === todoId)) return stock
|
|
4248
|
+
const items = [...stock.items, { id: target.id, title: target.title, sessionId: target.sessionId ?? null }]
|
|
4249
|
+
return { ...stock, items, todoCount: items.length }
|
|
4250
|
+
})
|
|
4251
|
+
return {
|
|
4252
|
+
...current,
|
|
4253
|
+
todos,
|
|
4254
|
+
stocks,
|
|
4255
|
+
stats: current.stats === undefined || stockDelta === 0
|
|
4256
|
+
? current.stats
|
|
4257
|
+
: { ...current.stats, todos: Math.max(0, (current.stats.todos ?? 0) + stockDelta) },
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4260
|
+
|
|
4079
4261
|
function boardTodoFilterOptions() {
|
|
4080
4262
|
return BOARD_TODO_PERIODS.map((period) => ({ value: period, label: boardTodoGroupLabel(period) }))
|
|
4081
4263
|
}
|
|
@@ -4090,9 +4272,36 @@ function boardTodoDueLabel(item, period) {
|
|
|
4090
4272
|
return date || zh.board.dueNoDate
|
|
4091
4273
|
}
|
|
4092
4274
|
|
|
4093
|
-
const
|
|
4275
|
+
const TODO_VERIFIER_IDS = new Set(['todo-verifier-close'])
|
|
4276
|
+
|
|
4277
|
+
function boardTodoDecision(item) {
|
|
4278
|
+
if (item.decision === 'confirmed' || item.decision === 'deferred') return item.decision
|
|
4279
|
+
if (typeof item.ackedAt === 'string' && item.ackedAt.length > 0) return 'confirmed'
|
|
4280
|
+
if (typeof item.deferredAt === 'string' && item.deferredAt.length > 0) return 'deferred'
|
|
4281
|
+
return undefined
|
|
4282
|
+
}
|
|
4283
|
+
|
|
4284
|
+
/** Archived outcome shown after the primary "已过期" label. */
|
|
4285
|
+
function boardTodoOutcome(item) {
|
|
4286
|
+
const decision = boardTodoDecision(item)
|
|
4287
|
+
if (decision === 'confirmed') return '已确认'
|
|
4288
|
+
if (decision === 'deferred') return '忽略'
|
|
4289
|
+
const reason = item.watch?.expiredReason
|
|
4290
|
+
if (reason === 'not_triggered') return '到期未触发'
|
|
4291
|
+
if (reason === 'no_data') return '数据不足'
|
|
4292
|
+
if (reason === 'not_verified') return '未完成核验'
|
|
4293
|
+
if (reason === 'not_confirmed') return '未确认'
|
|
4294
|
+
if (reason === 'stale') return '已停止跟踪'
|
|
4295
|
+
if (item.watch?.status === 'needs_human') return '数据不足'
|
|
4296
|
+
if (item.watch?.status === 'watching') return '未完成核验'
|
|
4297
|
+
if (item.kind === 'confirm') return '未确认'
|
|
4298
|
+
if (item.kind === 'verify') return '未完成核验'
|
|
4299
|
+
if (item.kind === 'track') return '跟踪结束'
|
|
4300
|
+
return ''
|
|
4301
|
+
}
|
|
4094
4302
|
|
|
4095
4303
|
function boardTodoStatus(item) {
|
|
4304
|
+
if (typeof item.deferredAt === 'string' && item.deferredAt.length > 0) return 'deferred'
|
|
4096
4305
|
if (typeof item.ackedAt === 'string' && item.ackedAt.length > 0) return 'resolved'
|
|
4097
4306
|
if (item.watch !== null && item.watch !== undefined && typeof item.watch.status === 'string') return item.watch.status
|
|
4098
4307
|
// Track items are passive; everything else without a watch is waiting for the user.
|
|
@@ -4103,6 +4312,7 @@ function boardTodoWatchLabel(status) {
|
|
|
4103
4312
|
if (status === 'triggered') return zh.board.watchTriggered
|
|
4104
4313
|
if (status === 'needs_human') return zh.board.watchNeedsHuman
|
|
4105
4314
|
if (status === 'resolved') return zh.board.watchResolved
|
|
4315
|
+
if (status === 'deferred') return zh.board.watchDeferred
|
|
4106
4316
|
if (status === 'expired') return zh.board.watchExpired
|
|
4107
4317
|
if (status === 'tracking') return zh.board.watchTracking
|
|
4108
4318
|
if (status === 'watching') return zh.board.watchWatching
|
|
@@ -4112,26 +4322,45 @@ function boardTodoWatchLabel(status) {
|
|
|
4112
4322
|
function boardTodoWatchHint(status, checkpointHint) {
|
|
4113
4323
|
if (status === 'watching') return checkpointHint
|
|
4114
4324
|
if (status === 'triggered') return '自动核验已确认条件成立'
|
|
4115
|
-
if (status === 'needs_human') return '
|
|
4325
|
+
if (status === 'needs_human') return '需要你处理'
|
|
4116
4326
|
if (status === 'resolved') return '已确认'
|
|
4327
|
+
if (status === 'deferred') return zh.board.watchDeferredHint
|
|
4117
4328
|
if (status === 'tracking') return '仅展示,不自动核验'
|
|
4118
|
-
if (status === 'expired') return '
|
|
4329
|
+
if (status === 'expired') return '已过期;不再核验、提醒或计入待办'
|
|
4119
4330
|
return ''
|
|
4120
4331
|
}
|
|
4121
4332
|
|
|
4122
|
-
function
|
|
4333
|
+
function boardTodoVerifierHint(tasks) {
|
|
4123
4334
|
const names = []
|
|
4124
4335
|
for (const task of Array.isArray(tasks) ? tasks : []) {
|
|
4125
|
-
if (task?.origin !== 'builtin' || task.state !== 'active' || !
|
|
4336
|
+
if (task?.origin !== 'builtin' || task.state !== 'active' || !TODO_VERIFIER_IDS.has(task.sourceBuiltinId)) continue
|
|
4126
4337
|
if (typeof task.title === 'string' && task.title.length > 0 && !names.includes(task.title)) names.push(task.title)
|
|
4127
4338
|
}
|
|
4128
|
-
if (names.length > 0) return
|
|
4129
|
-
if (!Array.isArray(tasks) || tasks.length === 0) return '
|
|
4130
|
-
return '
|
|
4339
|
+
if (names.length > 0) return `自动核验由「${names.join('、')}」执行(A/H 收盘)`
|
|
4340
|
+
if (!Array.isArray(tasks) || tasks.length === 0) return '自动核验由「TODO 核验」执行(A/H 收盘)'
|
|
4341
|
+
return 'TODO 核验任务未启用'
|
|
4131
4342
|
}
|
|
4132
4343
|
|
|
4133
4344
|
function boardTodoCheckable(status) {
|
|
4134
4345
|
return status === 'needs_human' || status === 'triggered' || status === 'tracking'
|
|
4346
|
+
|| status === 'watching' || status === 'resolved' || status === 'deferred'
|
|
4347
|
+
}
|
|
4348
|
+
|
|
4349
|
+
function boardTodoAutoAvailable(item, status) {
|
|
4350
|
+
if (item.kind !== 'confirm' && item.kind !== 'verify') return false
|
|
4351
|
+
if (item.watch === null || item.watch === undefined) return false
|
|
4352
|
+
if (item.watch.autoEligible !== true) return false
|
|
4353
|
+
return status === 'needs_human' || status === 'resolved' || status === 'deferred'
|
|
4354
|
+
}
|
|
4355
|
+
|
|
4356
|
+
function boardTodoAutoReason(item, status) {
|
|
4357
|
+
if (item.kind === 'track') return ''
|
|
4358
|
+
if (item.watch === null || item.watch === undefined) return ''
|
|
4359
|
+
if (item.watch.autoEligible === true) return ''
|
|
4360
|
+
if (item.watch.autoIneligibleReason === 'triggered' || status === 'triggered') return '条件已触发'
|
|
4361
|
+
if (item.watch.autoIneligibleReason === 'expired') return '已过期'
|
|
4362
|
+
if (item.watch.autoIneligibleReason === 'us_symbol') return '美股暂不支持'
|
|
4363
|
+
return '暂不支持'
|
|
4135
4364
|
}
|
|
4136
4365
|
|
|
4137
4366
|
function boardCategoryOptions() {
|
|
@@ -4744,9 +4973,6 @@ function BriefCard(props) {
|
|
|
4744
4973
|
onClick: () => setAskOpen(true),
|
|
4745
4974
|
}, h(IconNewChatOutlineRegular, { size: 14 }))
|
|
4746
4975
|
: null
|
|
4747
|
-
const openLink = openSession
|
|
4748
|
-
? h('button', { type: 'button', className: 'capital-automation-btn', 'data-size': 'sm', onClick: openSession }, zh.openSession)
|
|
4749
|
-
: null
|
|
4750
4976
|
const trigger = card.trigger === 'manual' ? zh.triggerManual : zh.triggerScheduled
|
|
4751
4977
|
const relativeTime = boardRelativeTime(card.finishedAt)
|
|
4752
4978
|
const exactTime = formatTime(card.finishedAt)
|
|
@@ -4766,12 +4992,10 @@ function BriefCard(props) {
|
|
|
4766
4992
|
'data-size': 'sm',
|
|
4767
4993
|
disabled: retrying === true,
|
|
4768
4994
|
onClick: () => onRetry(card.runId),
|
|
4769
|
-
}, retrying === true ? zh.processing : zh.board.retry)
|
|
4770
|
-
openLink))
|
|
4995
|
+
}, retrying === true ? zh.processing : zh.board.retry)))
|
|
4771
4996
|
} else if (status === 'skipped') {
|
|
4772
4997
|
body = h('div', { className: 'capital-automation-briefstate' },
|
|
4773
|
-
h('p', null, zh.board.briefSkipped)
|
|
4774
|
-
h('div', { className: 'capital-automation-briefactions' }, openLink))
|
|
4998
|
+
h('p', null, zh.board.briefSkipped))
|
|
4775
4999
|
} else {
|
|
4776
5000
|
body = h('div', { className: 'capital-automation-briefstate' },
|
|
4777
5001
|
h(SkeletonBlock, { width: '72%', height: 14 }),
|
|
@@ -4877,8 +5101,9 @@ function BriefFeed(props) {
|
|
|
4877
5101
|
}
|
|
4878
5102
|
|
|
4879
5103
|
function TodoRow(props) {
|
|
4880
|
-
const { item, period, showDue = true, onOpenSession,
|
|
5104
|
+
const { item, period, showDue = true, onOpenSession, onDecide, checkpointHint = '', pending = false } = props
|
|
4881
5105
|
const [open, setOpen] = useState(false)
|
|
5106
|
+
const [menuOpen, setMenuOpen] = useState(false)
|
|
4882
5107
|
const quote = item.sourceQuote ?? item.sources?.[0]?.sourceQuote
|
|
4883
5108
|
const due = showDue === true ? boardTodoDueLabel(item, period) : ''
|
|
4884
5109
|
const source = {
|
|
@@ -4887,46 +5112,118 @@ function TodoRow(props) {
|
|
|
4887
5112
|
sessionId: item.sessionId ?? item.sources?.[0]?.sessionId,
|
|
4888
5113
|
}
|
|
4889
5114
|
const meta = []
|
|
4890
|
-
if (due) meta.push(h('span', { key: 'due' }, due))
|
|
4891
|
-
if (item.seenCount > 1) meta.push(h('span', { key: 'seen' }, zh.board.seenCount.replace('{n}', String(item.seenCount))))
|
|
4892
5115
|
const watch = item.watch && typeof item.watch === 'object' ? item.watch : null
|
|
4893
|
-
const
|
|
5116
|
+
const archived = period === 'expired'
|
|
5117
|
+
const status = archived ? 'expired' : boardTodoStatus(item)
|
|
5118
|
+
const decision = boardTodoDecision(item)
|
|
5119
|
+
const decided = decision !== undefined
|
|
5120
|
+
const compact = decided || archived
|
|
4894
5121
|
const watchLabel = boardTodoWatchLabel(status)
|
|
4895
|
-
if (
|
|
5122
|
+
if (due) meta.push(h('span', { key: 'due' }, due))
|
|
5123
|
+
if (archived) {
|
|
5124
|
+
const outcome = boardTodoOutcome(item)
|
|
5125
|
+
if (outcome.length > 0) meta.push(h('span', { key: 'outcome', className: 'capital-automation-todooutcome' }, outcome))
|
|
5126
|
+
}
|
|
5127
|
+
if (item.seenCount > 1) meta.push(h('span', { key: 'seen' }, zh.board.seenCount.replace('{n}', String(item.seenCount))))
|
|
5128
|
+
if (watch?.checkedAt && status !== 'resolved' && status !== 'deferred' && status !== 'tracking') {
|
|
4896
5129
|
meta.push(h('span', { key: 'checked' }, zh.board.watchChecked.replace('{time}', formatShortTime(watch.checkedAt))))
|
|
4897
5130
|
}
|
|
4898
5131
|
const watchMessage = status === 'triggered'
|
|
4899
|
-
? `${zh.board.watchEvidence}:${watch?.evidence ?? ''}`
|
|
5132
|
+
? `${zh.board.watchEvidence}:${watch?.evidence ?? ''}${watch?.source ? ` · ${zh.board.watchSource}:${watch.source}` : ''}`
|
|
4900
5133
|
: ''
|
|
4901
|
-
const
|
|
5134
|
+
const actionable = !archived && boardTodoCheckable(status)
|
|
5135
|
+
const pastDue = typeof item.dueAt === 'string' && item.dueAt < localDateKey(new Date())
|
|
5136
|
+
const autoAvailable = !archived && !pastDue && boardTodoAutoAvailable(item, status)
|
|
4902
5137
|
const basisAction = open ? zh.board.hideBasis : zh.board.showBasis
|
|
4903
5138
|
const basisCaret = h('span', { className: 'capital-automation-basiscaret', 'aria-hidden': 'true' }, h(IconChevronDownOutlineRegular, { size: 12 }))
|
|
4904
|
-
|
|
4905
|
-
h('div', { className: 'capital-automation-
|
|
5139
|
+
const tags = watchLabel.length > 0
|
|
5140
|
+
? h('div', { className: 'capital-automation-todotags' },
|
|
5141
|
+
h('span', {
|
|
5142
|
+
className: 'capital-automation-todowatch',
|
|
5143
|
+
'data-status': status,
|
|
5144
|
+
title: boardTodoWatchHint(status, checkpointHint),
|
|
5145
|
+
},
|
|
5146
|
+
watchLabel))
|
|
5147
|
+
: null
|
|
5148
|
+
const menuItems = []
|
|
5149
|
+
if (actionable) {
|
|
5150
|
+
menuItems.push({
|
|
5151
|
+
id: 'confirm',
|
|
5152
|
+
label: decision === 'confirmed' ? `${zh.board.todoActionConfirm}(当前)` : zh.board.todoActionConfirm,
|
|
5153
|
+
icon: h(IconChecklistOutlineRegular, { size: 14 }),
|
|
5154
|
+
disabled: pending || decision === 'confirmed',
|
|
5155
|
+
})
|
|
5156
|
+
if (autoAvailable) {
|
|
5157
|
+
menuItems.push({
|
|
5158
|
+
id: 'auto',
|
|
5159
|
+
label: zh.board.todoActionAuto,
|
|
5160
|
+
icon: h(IconSparkleRegular, { size: 14 }),
|
|
5161
|
+
disabled: pending,
|
|
5162
|
+
})
|
|
5163
|
+
} else if (actionable && status !== 'watching') {
|
|
5164
|
+
const autoReason = pastDue && status !== 'triggered' && item.kind !== 'track' ? '已过期' : boardTodoAutoReason(item, status)
|
|
5165
|
+
if (autoReason.length > 0) {
|
|
5166
|
+
menuItems.push({
|
|
5167
|
+
id: 'auto-unavailable',
|
|
5168
|
+
label: `${zh.board.todoActionAuto}(${autoReason})`,
|
|
5169
|
+
icon: h(IconSparkleRegular, { size: 14 }),
|
|
5170
|
+
disabled: true,
|
|
5171
|
+
})
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
menuItems.push({
|
|
5175
|
+
id: 'defer',
|
|
5176
|
+
label: decision === 'deferred' ? `${zh.board.todoActionDefer}(当前)` : zh.board.todoActionDefer,
|
|
5177
|
+
icon: h(IconClockOutlineRegular, { size: 14 }),
|
|
5178
|
+
disabled: pending || decision === 'deferred',
|
|
5179
|
+
})
|
|
5180
|
+
}
|
|
5181
|
+
const menu = actionable
|
|
5182
|
+
? h(Menu, {
|
|
5183
|
+
open: menuOpen,
|
|
5184
|
+
anchor: h('button', {
|
|
5185
|
+
type: 'button',
|
|
5186
|
+
className: 'capital-automation-todomenu',
|
|
5187
|
+
title: zh.board.todoMoreTitle,
|
|
5188
|
+
'aria-label': `${zh.board.todoMoreTitle}:${item.title}`,
|
|
5189
|
+
'aria-haspopup': 'menu',
|
|
5190
|
+
'aria-expanded': menuOpen ? 'true' : 'false',
|
|
5191
|
+
disabled: pending === true,
|
|
5192
|
+
onClick: () => setMenuOpen((value) => !value),
|
|
5193
|
+
}, h(IconEllipsisOutlineRegular, { size: 16 })),
|
|
5194
|
+
items: menuItems,
|
|
5195
|
+
onSelect: (id) => {
|
|
5196
|
+
setMenuOpen(false)
|
|
5197
|
+
if (id === 'confirm' || id === 'auto' || id === 'defer') onDecide(item, id)
|
|
5198
|
+
},
|
|
5199
|
+
onClose: () => setMenuOpen(false),
|
|
5200
|
+
align: 'end',
|
|
5201
|
+
portal: true,
|
|
5202
|
+
})
|
|
5203
|
+
: null
|
|
5204
|
+
return h('li', {
|
|
5205
|
+
className: 'capital-automation-todoitem',
|
|
5206
|
+
'data-decided': decided ? 'true' : undefined,
|
|
5207
|
+
'data-archived': archived ? 'true' : undefined,
|
|
5208
|
+
'data-decision': decision,
|
|
5209
|
+
},
|
|
5210
|
+
compact
|
|
5211
|
+
? h('div', { className: 'capital-automation-todoline' },
|
|
4906
5212
|
h('div', { className: 'capital-automation-todotop' },
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
? h('span', {
|
|
4910
|
-
className: 'capital-automation-todowatch',
|
|
4911
|
-
'data-status': status,
|
|
4912
|
-
title: boardTodoWatchHint(status, checkpointHint),
|
|
4913
|
-
},
|
|
4914
|
-
watchLabel,
|
|
4915
|
-
status === 'resolved' ? h('span', { className: 'capital-automation-todowatchcheck', 'aria-hidden': 'true' }, '✓') : null)
|
|
4916
|
-
: null),
|
|
4917
|
-
checkable
|
|
5213
|
+
tags,
|
|
5214
|
+
archived
|
|
4918
5215
|
? h('button', {
|
|
4919
5216
|
type: 'button',
|
|
4920
|
-
className: 'capital-automation-
|
|
4921
|
-
|
|
4922
|
-
'aria-
|
|
4923
|
-
title:
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
5217
|
+
className: 'capital-automation-todotitle',
|
|
5218
|
+
'aria-expanded': open ? 'true' : 'false',
|
|
5219
|
+
'aria-label': `${item.title},${basisAction}`,
|
|
5220
|
+
title: basisAction,
|
|
5221
|
+
onClick: () => setOpen((value) => !value),
|
|
5222
|
+
}, item.title, basisCaret)
|
|
5223
|
+
: h('span', { className: 'capital-automation-todotitle', title: item.title }, item.title),
|
|
5224
|
+
menu))
|
|
5225
|
+
: h('div', { className: 'capital-automation-todoline' },
|
|
5226
|
+
h('div', { className: 'capital-automation-todotop' }, tags, menu),
|
|
4930
5227
|
h('button', {
|
|
4931
5228
|
type: 'button',
|
|
4932
5229
|
className: 'capital-automation-todotitle',
|
|
@@ -4935,29 +5232,34 @@ function TodoRow(props) {
|
|
|
4935
5232
|
title: basisAction,
|
|
4936
5233
|
onClick: () => setOpen((value) => !value),
|
|
4937
5234
|
}, item.title, basisCaret)),
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
:
|
|
4959
|
-
|
|
4960
|
-
|
|
5235
|
+
!compact && item.detail ? h('p', { className: 'capital-automation-tododesc' }, item.detail) : null,
|
|
5236
|
+
!compact && watchMessage.length > 0
|
|
5237
|
+
? h('p', { className: 'capital-automation-todowatchmsg', 'data-status': status }, watchMessage)
|
|
5238
|
+
: null,
|
|
5239
|
+
(archived || !decided) && meta.length > 0 ? h('div', { className: 'capital-automation-todometa' }, meta) : null,
|
|
5240
|
+
(archived || !decided) && open
|
|
5241
|
+
? h('div', { className: 'capital-automation-tododetail' },
|
|
5242
|
+
archived && item.detail ? h('p', { className: 'capital-automation-tododesc' }, item.detail) : null,
|
|
5243
|
+
archived && watch?.evidence
|
|
5244
|
+
? h('p', { className: 'capital-automation-todowatchmsg', 'data-status': status },
|
|
5245
|
+
`${zh.board.watchEvidence}:${watch.evidence}${watch.source ? ` · ${zh.board.watchSource}:${watch.source}` : ''}`)
|
|
5246
|
+
: null,
|
|
5247
|
+
h('blockquote', null, quote),
|
|
5248
|
+
source
|
|
5249
|
+
? h('div', { className: 'capital-automation-todosource' },
|
|
5250
|
+
h('span', null, `${zh.board.sourceRun}:${source.taskTitle} · ${formatShortTime(source.finishedAt)}`),
|
|
5251
|
+
source.sessionId
|
|
5252
|
+
? h('button', {
|
|
5253
|
+
type: 'button',
|
|
5254
|
+
className: 'capital-automation-btn',
|
|
5255
|
+
'data-size': 'icon',
|
|
5256
|
+
title: zh.openSession,
|
|
5257
|
+
'aria-label': zh.openSession,
|
|
5258
|
+
onClick: () => onOpenSession(source.sessionId),
|
|
5259
|
+
}, h(IconRightUpOutlineRegular, { size: 14 }))
|
|
5260
|
+
: null)
|
|
5261
|
+
: null)
|
|
5262
|
+
: null)
|
|
4961
5263
|
}
|
|
4962
5264
|
|
|
4963
5265
|
function BoardPanelHead(props) {
|
|
@@ -4999,13 +5301,11 @@ function BoardPanel(props) {
|
|
|
4999
5301
|
}
|
|
5000
5302
|
|
|
5001
5303
|
function TodoPanel(props) {
|
|
5002
|
-
const { todos, tasks, onOpenSession,
|
|
5304
|
+
const { todos, tasks, onOpenSession, onDecideTodo, pendingTodoIds = new Set(), open, onToggle } = props
|
|
5003
5305
|
const [filter, setFilter] = useState('today')
|
|
5004
|
-
const
|
|
5005
|
-
const entries = todos.map((item) => ({ item, period: boardTodoPeriod(item, now) }))
|
|
5006
|
-
entries.sort((left, right) => BOARD_TODO_PERIODS.indexOf(left.period) - BOARD_TODO_PERIODS.indexOf(right.period))
|
|
5306
|
+
const entries = boardTodoEntries(todos, new Date())
|
|
5007
5307
|
const visible = entries.filter((entry) => entry.period === filter)
|
|
5008
|
-
const checkpointHint =
|
|
5308
|
+
const checkpointHint = boardTodoVerifierHint(tasks)
|
|
5009
5309
|
const emptyText = filter === 'today'
|
|
5010
5310
|
? zh.board.todoEmptyToday
|
|
5011
5311
|
: zh.board.todoEmptyGroup.replace('{label}', boardTodoGroupLabel(filter))
|
|
@@ -5031,10 +5331,9 @@ function TodoPanel(props) {
|
|
|
5031
5331
|
period: entry.period,
|
|
5032
5332
|
showDue: true,
|
|
5033
5333
|
onOpenSession,
|
|
5034
|
-
|
|
5035
|
-
acking: ackingTodoId === entry.item.id,
|
|
5036
|
-
ackDisabled: ackingTodoId !== null && ackingTodoId !== undefined,
|
|
5334
|
+
onDecide: onDecideTodo,
|
|
5037
5335
|
checkpointHint,
|
|
5336
|
+
pending: pendingTodoIds.has(entry.item.id),
|
|
5038
5337
|
}))))
|
|
5039
5338
|
}
|
|
5040
5339
|
|
|
@@ -5072,7 +5371,9 @@ function StockRow(props) {
|
|
|
5072
5371
|
const stockKey = boardEntrySymbolKey(stock)
|
|
5073
5372
|
const related = Array.isArray(stock.items)
|
|
5074
5373
|
? stock.items
|
|
5075
|
-
: todos.filter((item) => item.ackedAt === undefined &&
|
|
5374
|
+
: todos.filter((item) => item.ackedAt === undefined && item.deferredAt === undefined
|
|
5375
|
+
&& boardTodoPeriod(item) !== 'expired'
|
|
5376
|
+
&& boardEntrySymbolKey(item) === stockKey)
|
|
5076
5377
|
const followUpCount = Array.isArray(stock.items) ? stock.items.length : (stock.todoCount ?? 0)
|
|
5077
5378
|
const roleSummary = stock.roles.map((role) => boardRoleTitle(role)).join(';')
|
|
5078
5379
|
return h('div', { className: 'capital-automation-stockrow' },
|
|
@@ -5305,7 +5606,7 @@ function BoardPage(props) {
|
|
|
5305
5606
|
const {
|
|
5306
5607
|
board, tasks, api, loading, error, range, category, onRange, onCategory, onRefresh,
|
|
5307
5608
|
onOpenSession, onRetryBrief, retryingRunId, onLoadMore, loadingMore, onGoTasks, onNewTask, onGoRuns,
|
|
5308
|
-
|
|
5609
|
+
onDecideTodo, pendingTodoIds, hasActiveTasks, storageReady,
|
|
5309
5610
|
} = props
|
|
5310
5611
|
const [railOpen, setRailOpen] = useState(() => readBoardUi().rail !== false)
|
|
5311
5612
|
const [openPanels, setOpenPanels] = useState(() => boardPanelFlags(readBoardUi().panels))
|
|
@@ -5424,8 +5725,8 @@ function BoardPage(props) {
|
|
|
5424
5725
|
todos: board?.todos ?? [],
|
|
5425
5726
|
tasks,
|
|
5426
5727
|
onOpenSession,
|
|
5427
|
-
|
|
5428
|
-
|
|
5728
|
+
onDecideTodo,
|
|
5729
|
+
pendingTodoIds,
|
|
5429
5730
|
open: openPanels.todo,
|
|
5430
5731
|
onToggle: () => togglePanel('todo'),
|
|
5431
5732
|
}),
|
|
@@ -5466,7 +5767,6 @@ function AutomationPage(props) {
|
|
|
5466
5767
|
const [boardRange, setBoardRange] = useState('14')
|
|
5467
5768
|
const [boardCategory, setBoardCategory] = useState('all')
|
|
5468
5769
|
const [retryingBriefId, setRetryingBriefId] = useState(null)
|
|
5469
|
-
const [ackingTodoId, setAckingTodoId] = useState(null)
|
|
5470
5770
|
const [boardLoadingMore, setBoardLoadingMore] = useState(false)
|
|
5471
5771
|
const [unread, setUnread] = useState(0)
|
|
5472
5772
|
const [tasksReady, setTasksReady] = useState(false)
|
|
@@ -5483,6 +5783,7 @@ function AutomationPage(props) {
|
|
|
5483
5783
|
const [busyTaskId, setBusyTaskId] = useState(null)
|
|
5484
5784
|
const [inboxBusy, setInboxBusy] = useState(false)
|
|
5485
5785
|
const [notice, setNotice] = useState('')
|
|
5786
|
+
const [pendingTodoIds, setPendingTodoIds] = useState(() => new Set())
|
|
5486
5787
|
const [loadError, setLoadError] = useState('')
|
|
5487
5788
|
const mountedRef = useRef(false)
|
|
5488
5789
|
const tasksRef = useRef([])
|
|
@@ -5497,6 +5798,7 @@ function AutomationPage(props) {
|
|
|
5497
5798
|
const refreshSequenceRef = useRef(0)
|
|
5498
5799
|
const detailSequenceRef = useRef(0)
|
|
5499
5800
|
const boardSequenceRef = useRef(0)
|
|
5801
|
+
const optimisticDecisionRef = useRef(new Map())
|
|
5500
5802
|
const scrollRef = useRef(null)
|
|
5501
5803
|
const mountedAtRef = useRef(typeof performance === 'undefined' ? 0 : performance.now())
|
|
5502
5804
|
const timingRecordedRef = useRef(false)
|
|
@@ -5638,6 +5940,16 @@ function AutomationPage(props) {
|
|
|
5638
5940
|
}
|
|
5639
5941
|
}
|
|
5640
5942
|
|
|
5943
|
+
// A decision request and a board poll can cross: keep the optimistic state on every response
|
|
5944
|
+
// until the request settles, then let the next poll read the server truth.
|
|
5945
|
+
function applyOptimisticDecisions(value) {
|
|
5946
|
+
let next = value
|
|
5947
|
+
for (const [id, entry] of optimisticDecisionRef.current) {
|
|
5948
|
+
next = applyTodoDecision(next, id, entry.action, entry.at)
|
|
5949
|
+
}
|
|
5950
|
+
return next
|
|
5951
|
+
}
|
|
5952
|
+
|
|
5641
5953
|
async function loadBoard(nextRange = boardRange, nextCategory = boardCategory, before = null) {
|
|
5642
5954
|
const query = boardQueryOf(nextRange, nextCategory, before)
|
|
5643
5955
|
const snapshot = before === null ? readBoardSnapshot(query) : null
|
|
@@ -5647,7 +5959,7 @@ function AutomationPage(props) {
|
|
|
5647
5959
|
// A cached board paints immediately; the request below still revalidates it.
|
|
5648
5960
|
if (snapshot === null) setBoardLoading(true)
|
|
5649
5961
|
else {
|
|
5650
|
-
setBoard(snapshot)
|
|
5962
|
+
setBoard(applyOptimisticDecisions(snapshot))
|
|
5651
5963
|
setBoardLoading(false)
|
|
5652
5964
|
}
|
|
5653
5965
|
}
|
|
@@ -5655,11 +5967,11 @@ function AutomationPage(props) {
|
|
|
5655
5967
|
const value = await api.board(query)
|
|
5656
5968
|
if (!mountedRef.current || requestSequence !== boardSequenceRef.current) return
|
|
5657
5969
|
if (before === null) {
|
|
5658
|
-
setBoard(value)
|
|
5970
|
+
setBoard(applyOptimisticDecisions(value))
|
|
5659
5971
|
writeBoardSnapshot(query, value)
|
|
5660
|
-
} else setBoard((current) => current === null
|
|
5972
|
+
} else setBoard((current) => applyOptimisticDecisions(current === null
|
|
5661
5973
|
? value
|
|
5662
|
-
: { ...value, cards: [...current.cards, ...value.cards] })
|
|
5974
|
+
: { ...value, cards: [...current.cards, ...value.cards] }))
|
|
5663
5975
|
setBoardError('')
|
|
5664
5976
|
} catch (error) {
|
|
5665
5977
|
if (mountedRef.current && requestSequence === boardSequenceRef.current) {
|
|
@@ -5695,55 +6007,51 @@ function AutomationPage(props) {
|
|
|
5695
6007
|
}
|
|
5696
6008
|
}
|
|
5697
6009
|
|
|
5698
|
-
|
|
5699
|
-
if (
|
|
5700
|
-
|
|
6010
|
+
function decideTodo(item, action) {
|
|
6011
|
+
if (typeof item?.id !== 'string') return
|
|
6012
|
+
if (action !== 'confirm' && action !== 'auto' && action !== 'defer') return
|
|
6013
|
+
if (pendingTodoIds.has(item.id) || optimisticDecisionRef.current.has(item.id)) return
|
|
6014
|
+
// Paint the decision first; the write travels in the background and a crossing board poll is
|
|
6015
|
+
// overlaid with the same state.
|
|
6016
|
+
const at = new Date().toISOString()
|
|
6017
|
+
const previous = {
|
|
6018
|
+
ackedAt: item.ackedAt,
|
|
6019
|
+
deferredAt: item.deferredAt,
|
|
6020
|
+
decision: item.decision,
|
|
6021
|
+
watch: item.watch,
|
|
6022
|
+
}
|
|
6023
|
+
optimisticDecisionRef.current.set(item.id, { action, at })
|
|
6024
|
+
setPendingTodoIds((current) => {
|
|
6025
|
+
const next = new Set(current)
|
|
6026
|
+
next.add(item.id)
|
|
6027
|
+
return next
|
|
6028
|
+
})
|
|
6029
|
+
setBoard((current) => applyTodoDecision(current, item.id, action, at))
|
|
6030
|
+
setNotice(action === 'confirm'
|
|
6031
|
+
? zh.board.todoAcked
|
|
6032
|
+
: action === 'defer' ? zh.board.todoDeferred : zh.board.todoAutoQueued)
|
|
5701
6033
|
setBoardError('')
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
}),
|
|
5722
|
-
}
|
|
5723
|
-
: entry)
|
|
5724
|
-
const targetKey = target.symbol === undefined ? undefined : boardEntrySymbolKey(target)
|
|
5725
|
-
const stocks = (current.stocks ?? []).map((stock) => {
|
|
5726
|
-
if (targetKey === undefined || boardEntrySymbolKey(stock) !== targetKey) return stock
|
|
5727
|
-
if (!Array.isArray(stock.items)) return { ...stock, todoCount: Math.max(0, (stock.todoCount ?? 0) - 1) }
|
|
5728
|
-
const items = stock.items.filter((entry) => entry.id !== target.id)
|
|
5729
|
-
return { ...stock, items, todoCount: items.length }
|
|
5730
|
-
})
|
|
5731
|
-
return {
|
|
5732
|
-
...current,
|
|
5733
|
-
todos,
|
|
5734
|
-
stocks,
|
|
5735
|
-
stats: current.stats === undefined
|
|
5736
|
-
? current.stats
|
|
5737
|
-
: { ...current.stats, todos: Math.max(0, (current.stats.todos ?? 0) - 1) },
|
|
5738
|
-
}
|
|
6034
|
+
void api.decideTodo(item.id, action).then(() => {
|
|
6035
|
+
optimisticDecisionRef.current.delete(item.id)
|
|
6036
|
+
// Ignore a poll that started before the server write; the next poll reads the truth.
|
|
6037
|
+
boardSequenceRef.current += 1
|
|
6038
|
+
if (mountedRef.current) setBoardLoading(false)
|
|
6039
|
+
}).catch((error) => {
|
|
6040
|
+
optimisticDecisionRef.current.delete(item.id)
|
|
6041
|
+
boardSequenceRef.current += 1
|
|
6042
|
+
if (!mountedRef.current) return
|
|
6043
|
+
setBoardLoading(false)
|
|
6044
|
+
setBoard((current) => restoreBoardTodoState(current, item.id, previous))
|
|
6045
|
+
setNotice('')
|
|
6046
|
+
setBoardError(error?.message ?? zh.errorGeneric)
|
|
6047
|
+
}).finally(() => {
|
|
6048
|
+
if (!mountedRef.current) return
|
|
6049
|
+
setPendingTodoIds((current) => {
|
|
6050
|
+
const next = new Set(current)
|
|
6051
|
+
next.delete(item.id)
|
|
6052
|
+
return next
|
|
5739
6053
|
})
|
|
5740
|
-
|
|
5741
|
-
void loadBoard(boardRange, boardCategory)
|
|
5742
|
-
} catch (error) {
|
|
5743
|
-
setBoardError(error.message ?? zh.errorGeneric)
|
|
5744
|
-
} finally {
|
|
5745
|
-
setAckingTodoId(null)
|
|
5746
|
-
}
|
|
6054
|
+
})
|
|
5747
6055
|
}
|
|
5748
6056
|
|
|
5749
6057
|
async function loadDetail(id) {
|
|
@@ -6038,8 +6346,8 @@ function AutomationPage(props) {
|
|
|
6038
6346
|
onOpenSession: openSession,
|
|
6039
6347
|
onRetryBrief: (runId) => { void retryBrief(runId) },
|
|
6040
6348
|
retryingRunId: retryingBriefId,
|
|
6041
|
-
|
|
6042
|
-
|
|
6349
|
+
onDecideTodo: (item, action) => { decideTodo(item, action) },
|
|
6350
|
+
pendingTodoIds,
|
|
6043
6351
|
onLoadMore: () => { void loadMoreBoard() },
|
|
6044
6352
|
loadingMore: boardLoadingMore,
|
|
6045
6353
|
onGoTasks: () => switchTab('tasks'),
|