@v587d/capital-generation 2.19.3 → 2.20.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 +35 -0
- package/README.md +3 -3
- package/automation/ask.js +8 -1
- package/automation/board.js +189 -30
- package/automation/brief.js +32 -31
- package/automation/client.js +52 -24
- package/automation/client.src.cjs +594 -128
- package/automation/defaults.js +1 -0
- package/automation/index.js +18 -5
- package/automation/package.json +2 -1
- package/automation/route.js +5 -0
- package/automation/schema.js +46 -1
- package/automation/service.js +12 -0
- package/automation/store.js +49 -0
- package/automation/watch.js +483 -0
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- 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
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,41 @@
|
|
|
7
7
|
- **第三位(patch)**:不破坏既有工具 / 配置 / 会话的新增与修复(如 2.1.1、2.1.2)。
|
|
8
8
|
- **第二位(minor)**:有需要用户知晓的行为变更,且段内附迁移说明(如 2.1.0 的图表呈现通道重做、2.2.0 的数据源与检索来源扩容、2.4.0 的**必须换宿主版本**、2.9.0 的选择器收敛与质检前置——本插件自己的工具与数据契约没变,所以只抬第二位)。
|
|
9
9
|
|
|
10
|
+
## [2.20.0] - 2026-11-10
|
|
11
|
+
|
|
12
|
+
投研自动化的 TODO 支持自动核验与人工交接;看板对话弹窗保留该次运行的全部追问。
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **TODO 自动跟踪**:`confirm` 与 `verify` 进入 `todo_watches`;`track` 保持只展示。最近 3 天仍被运行提到的条目才进入跟踪,避免把历史待办一次性变成提醒。
|
|
17
|
+
- **无工具核验**:只在内置「午间快照」与「每日复盘」成功运行后,用同一模型对全部 `watching` / `needs_human` 的 `verify` 条目做一次三值判断(触发 / 未触发 / 数据不足),不再限制 16 条;判卷稿用终稿全文。只认同一标的、同一口径、同一时点,`evidence` 必须能在终稿原文中找到,否则按数据不足处理。
|
|
18
|
+
- **简报与核验都读全文**:任务简报不再把终稿截成头 6000 + 尾 6000;`sourceBlocks` 也不再按行截 600 字。正文清洗后直接进入简报与 TODO 判卷,避免关键证据落在中间被省略。
|
|
19
|
+
- **人工交接**:`confirm` 直接标记「待人工确认」;`verify` 在终稿提到但缺少核验数据时也转「待人工确认」。看板 TODO 行显示核验状态、核验时间与原文依据。
|
|
20
|
+
- **任务通知**:新增 `todo_triggered` / `todo_needs_human`;同一状态只通知一次,通知带 `todoId`,点击直接回到看板 TODO。
|
|
21
|
+
- **用户确认收口**:确认仍写入 `todo_acks`,对应跟踪记录转为 `resolved`;该版本在列表里保留为「已确认」,不计入今日 TODO 与个股跟进数,后续运行再次提到时重新出现。连续 3 天没有新运行提到则移出跟踪,`dueAt` 已过且有过核验记录转 `expired`;到期仍没拿到可复核数据则转「待人工确认」并通知,不静默过期。
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- 看板 TODO 排序在同类型内优先显示「已触发 / 待人工确认」,再按日期与最近出现时间排列;确认后条目留在原位显示「已确认」。
|
|
26
|
+
- 看板 TODO 只保留一个状态标签,`待验证` / `待确认` / `待你核对` 不再并列显示;待人工确认的「确认」按钮换成勾选框,勾选后显示「已确认 ✓」。
|
|
27
|
+
- **看板个股动态**:模块名从「标的」改为「个股动态」,统计卡改为「个股」。同一代码带 / 不带交易所后缀的写法合并(如 `300803` 与 `300803.SZ`),持仓 / 风险 / 事件 / 关注标签合并去重;标签 hover 显示释义。
|
|
28
|
+
- **个股筛选与展开**:右上角改为标签筛选(全部 / 持仓 / 风险 / 事件 / 关注),默认首屏展示 12 只,其余通过「展开全部 N 只」完整加载。
|
|
29
|
+
- **跟进数一致**:「N 项待办」改为「N 条待跟进」,并与展开条目共用服务端随个股返回的同一份列表;即使页面 TODO 被截到 50 条,个股计数仍等于实际能展开的条目数,不再出现「写着 13 条却只展开 8 条」或有点击无内容。
|
|
30
|
+
- **可点击反馈**:个股行与跟进条目 hover / 聚焦时变为品牌蓝色,明确提示可点击。
|
|
31
|
+
- **个股跟进直达来源**:展开后的条目整行可点,直接打开来源 session,移除逐条「打开 session」按钮。
|
|
32
|
+
- 移除 TODO 标题行的「N 条待你处理」计数和待人工确认的通用交接说明,减少重复信息。
|
|
33
|
+
- **数据体检更轻**:移除每条缺口前的「能力缺口 / 本次未取到 / 口径冲突 / 数据质量」标签;展开后的「打开 session」收成 30px 外链箭头,与 TODO 依据行一致。
|
|
34
|
+
- **运行健康更轻**:异常行右侧的「打开 session」也收成 30px 外链箭头(`title` / `aria-label` 仍为「打开 session」)。
|
|
35
|
+
- **对话弹窗保留全部追问**:打开弹窗时按创建时间正序展示该 run 的全部问答;卡片仍只显示最新一轮。新增 `GET /board/briefs/:runId/asks`。
|
|
36
|
+
- `capital_automation` 域新增 `todo_watches` 表;`notifications` 增加可选 `todoId`,未知字段仍严格拒绝。
|
|
37
|
+
|
|
38
|
+
### Migration
|
|
39
|
+
|
|
40
|
+
- 升级后 `capital_automation` 域自动新增 `todo_watches` 表;任务、运行、简报与既有 TODO 确认记录不变。
|
|
41
|
+
- 首次启动只跟踪最近 3 天出现且未到期的 `confirm` / `verify`;历史条目不会批量补发通知。
|
|
42
|
+
- 需要重启 dsh 进程并刷新页面后生效。
|
|
43
|
+
- 回滚到 2.19.x 前先清空 `todo_triggered` / `todo_needs_human` 通知:旧版不认识这两个 kind,批量已读会拒绝这些记录;`todo_watches` 是派生数据,回滚后丢失可接受。
|
|
44
|
+
|
|
10
45
|
## [2.19.3] - 2026-11-09
|
|
11
46
|
|
|
12
47
|
插件页改为面向已安装用户的索引页;README 补清版本检查与回滚路径。
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<p align="center">
|
|
15
15
|
<a href="https://awesome-dsh-plugin.com"><img src="https://awesome-dsh-plugin.com/badge.svg" alt="awesome · DSH plugin"></a>
|
|
16
16
|
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-green" alt="License"></a>
|
|
17
|
-
<a href="https://github.com/v587d/capital-generation/releases"><img src="https://img.shields.io/badge/version-2.
|
|
17
|
+
<a href="https://github.com/v587d/capital-generation/releases"><img src="https://img.shields.io/badge/version-2.20.0-9cf" alt="Version"></a>
|
|
18
18
|
<a href="https://www.npmjs.com/package/@v587d/capital-generation"><img src="https://img.shields.io/npm/v/%40v587d%2Fcapital-generation" alt="npm version"></a>
|
|
19
19
|
<a href="https://github.com/deepseek-ai/deepseek-harness"><img src="https://img.shields.io/badge/powered_by-dsh-4D6BFE?style=flat-square&logo=deepseek&logoColor=white" alt="powered-by-dsh"></a>
|
|
20
20
|
</p>
|
|
@@ -179,7 +179,7 @@ Capital Generation 是运行在 [DeepSeek Harness(DSH)](https://github.com/d
|
|
|
179
179
|
| [Quant Agent Skills](https://github.com/Howard-Jerry/quant-agent-skills) | 1 个跨市场选线 Skill:同一家公司在 A 股与港股、或美股 ADR 与港股各有一条线时该走哪一条——价差、币种与股息税、流动性与通道、披露文件路径各不相同。公司本身只研究一次,便宜的那条线不构成"这家公司更值得买";A/H 溢价与 ADR 平价没有现成条目,须按两条线同一天的收盘价与当日汇率现算,缺任一项就只报缺的那一项 |
|
|
180
180
|
|
|
181
181
|
<a id="capgen-automation" name="capgen-automation"></a>
|
|
182
|
-
- **CapGen 投研自动化:** 内置 16 个模板(默认未添加,按需添加),覆盖资讯、行情、复盘、研究、组合与监控:交易日有盘前公告(08:00)、早间资讯(08:30)、午间快照(11:35)、当日公告(16:00)、港股收盘(16:30)与每日复盘(20:00),另有美股收盘(周二至周六 07:00)、美股盘前(周一至周五 20:30)、组合周报、自选股周检、行业周报、研究选题、财报跟踪、下周事件日历、市场周报与组合风险月报;也可新建自己的任务,并从 30 个图标里挑一个;内置模板也有各自的固定图标,看板卡片沿用同一枚。到点自动新建 session 执行,也能手动运行。任务、看板、12
|
|
182
|
+
- **CapGen 投研自动化:** 内置 16 个模板(默认未添加,按需添加),覆盖资讯、行情、复盘、研究、组合与监控:交易日有盘前公告(08:00)、早间资讯(08:30)、午间快照(11:35)、当日公告(16:00)、港股收盘(16:30)与每日复盘(20:00),另有美股收盘(周二至周六 07:00)、美股盘前(周一至周五 20:30)、组合周报、自选股周检、行业周报、研究选题、财报跟踪、下周事件日历、市场周报与组合风险月报;也可新建自己的任务,并从 30 个图标里挑一个;内置模板也有各自的固定图标,看板卡片沿用同一枚。到点自动新建 session 执行,也能手动运行。任务、看板、12 个月运行热力图与任务通知在同一页,可在设置卡把任一已注册工作区设为任务统一使用的默认工作区,支持运行预算、通知和仅交易日触发;看板简报卡右上角的对话入口可直接追问,回答完成后卡片显示最新一轮摘要并可在卡内展开全文,弹窗按时间列出这次运行的全部追问,右上角可打开完整 session。看板 TODO 会随内置「午间快照」与「每日复盘」自动核验待验证条件,待确认或数据不足的条目交给你核对;触发或需要你处理时写入任务通知。
|
|
183
183
|
|
|
184
184
|
<p align="center">
|
|
185
185
|
<a href="assets/capgen-automation-kanban.png">
|
|
@@ -198,7 +198,7 @@ Capital Generation 是运行在 [DeepSeek Harness(DSH)](https://github.com/d
|
|
|
198
198
|
- **安装后找不到模式?** 确认插件出现在「插件」→ 已安装列表;Web / CLI profile 安装后要重启该 profile,并在新会话选择模式。选择器里应看到自动模式、行情专家、资讯专员;分析师和绘图专员是自动模式的内部角色,不会出现在这里。
|
|
199
199
|
- **配置在哪?** 打开「插件」→ 已安装的 **Capital Generation**,插件介绍下方就是「数据源 / 投研自动化 / 精选 Skills / 包含的组件」四格,五把密钥都在第一格;第二格可指定任务统一使用的默认工作区,也能改自动检查间隔与最长运行时间等上限;不在 DSH 的普通「设置」页面,也不用点进任何一行组件。保存密钥后新建会话再试。
|
|
200
200
|
- **升级到 2.9.0 后,分析师和绘图专员去哪了?** 这一版把它们收进自动模式内部,不再出现在选择器与预设管理里,避免误开一个没有取数入口的空会话。旧会话仍能按原身份恢复;新任务直接用自动模式提出即可。
|
|
201
|
-
- **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.
|
|
201
|
+
- **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.20.0` 或 `@2.20.0`。
|
|
202
202
|
- **刚发布的新版本装不到?** 桌面端取包时会跳过**刚发布不久**的版本(宿主侧包管理器的发布冷却策略,实测会静默装成上一个版本),国内镜像的同步也可能滞后一段时间。急着用最新代码,改用仓库地址安装最直接;但仓库地址安装的是 git 依赖,插件页不显示「版本」检查。
|
|
203
203
|
- **插件页的「版本」段怎么用?** 只有用包名从 npm 安装的版本才有;它只列比当前新的版本。回旧版要先卸载,再安装 `@v587d/capital-generation@版本号`(桌面端地址末尾加 `#v版本号`);旧版必须匹配当前 DSH 基线,对应关系见 [CHANGELOG 的 Migration](CHANGELOG.md)。
|
|
204
204
|
- **网页抓取失败?** 配置卡片中的「允许启动本地提取网页内容」默认开启:AnySearch 提取失败时可尝试本机直连。关闭后,本机直连的具名来源查询也不可用;请检查该开关和网络连接。
|
package/automation/ask.js
CHANGED
|
@@ -327,6 +327,13 @@ export function createAskService(options) {
|
|
|
327
327
|
return result
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
+
async function history(runId) {
|
|
331
|
+
const run = await store.getRun(runId)
|
|
332
|
+
if (run === undefined) throw new AskError('run_not_found', '运行不存在。', 404)
|
|
333
|
+
const records = await store.listAsksForRun(runId)
|
|
334
|
+
return records.map(publicOf)
|
|
335
|
+
}
|
|
336
|
+
|
|
330
337
|
async function answer(askId) {
|
|
331
338
|
const record = await store.getAsk(askId)
|
|
332
339
|
if (record === undefined) throw new AskError('ask_not_found', '这条追问不存在。', 404)
|
|
@@ -353,5 +360,5 @@ export function createAskService(options) {
|
|
|
353
360
|
}
|
|
354
361
|
}
|
|
355
362
|
|
|
356
|
-
return { ask, status, latestForRuns, answer }
|
|
363
|
+
return { ask, status, latestForRuns, history, answer }
|
|
357
364
|
}
|
package/automation/board.js
CHANGED
|
@@ -11,15 +11,65 @@ const DEFAULT_DAYS = '14'
|
|
|
11
11
|
const DEFAULT_LIMIT = 30
|
|
12
12
|
const MAX_LIMIT = 50
|
|
13
13
|
const MAX_TODOS = 50
|
|
14
|
-
|
|
14
|
+
// The client paints 12 rows first and reveals the rest on demand. 200 leaves room for that
|
|
15
|
+
// interaction across a large run window without letting symbol churn inflate one response.
|
|
16
|
+
const MAX_STOCKS = 200
|
|
17
|
+
// Stock rows carry their own follow-up summaries so the count always equals what expands,
|
|
18
|
+
// even when the page-wide TODO slice is capped. 100 leaves ample room per instrument without
|
|
19
|
+
// duplicating every historical item into the board response.
|
|
20
|
+
const MAX_STOCK_ITEMS = 100
|
|
15
21
|
const MAX_GAPS = 20
|
|
16
22
|
const HEALTH_DAYS = 7
|
|
17
23
|
const RUN_ID_PATTERN = /^[A-Za-z0-9_-]{1,120}$/
|
|
18
24
|
const CATEGORY_VALUES = new Set(TaskCategorySchema.options)
|
|
19
25
|
const FAILURE_STATUSES = new Set(['failed', 'timed_out', 'blocked_requires_user', 'unknown_after_restart', 'missed'])
|
|
20
26
|
const KIND_RANK = { confirm: 0, verify: 1, track: 2 }
|
|
27
|
+
const WATCH_RANK = { triggered: 0, needs_human: 1, watching: 2, expired: 3, resolved: 4 }
|
|
21
28
|
const GAP_RANK = { capability: 0, conflict: 1, quality: 2, transient: 3 }
|
|
22
29
|
const ROLE_RANK = { holding: 0, risk: 1, event: 2, watch: 3 }
|
|
30
|
+
const A_SHARE_MARKETS = new Set(['SH', 'SZ', 'BJ'])
|
|
31
|
+
const US_MARKETS = new Set(['OQ', 'N', 'US', 'NYSE', 'NASDAQ'])
|
|
32
|
+
|
|
33
|
+
function inferredMarket(code) {
|
|
34
|
+
if (/^\d{6}$/.test(code)) {
|
|
35
|
+
if (code.startsWith('6')) return 'SH'
|
|
36
|
+
if (code.startsWith('4') || code.startsWith('8')) return 'BJ'
|
|
37
|
+
return 'SZ'
|
|
38
|
+
}
|
|
39
|
+
if (/^\d{5}$/.test(code)) return 'HK'
|
|
40
|
+
return undefined
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Merge the same instrument written with and without an exchange suffix. A bare six-digit A-share
|
|
45
|
+
* code can infer its market from the code pattern; explicit suffixes still win, so an index such as
|
|
46
|
+
* `000001.SS` does not collapse into Shenzhen's `000001`.
|
|
47
|
+
*/
|
|
48
|
+
export function stockSymbolKey(value) {
|
|
49
|
+
const raw = String(value ?? '').trim().toUpperCase()
|
|
50
|
+
if (raw.length === 0) return raw
|
|
51
|
+
const match = /^([A-Z0-9]+)\.([A-Z]+)$/.exec(raw)
|
|
52
|
+
if (match === null) {
|
|
53
|
+
const market = inferredMarket(raw)
|
|
54
|
+
return market === undefined ? raw : `${raw}.${market}`
|
|
55
|
+
}
|
|
56
|
+
const [, base, suffix] = match
|
|
57
|
+
if (/^\d{6}$/.test(base) && (suffix === 'SS' || A_SHARE_MARKETS.has(suffix))) {
|
|
58
|
+
return `${base}.${suffix === 'SS' ? 'SH' : suffix}`
|
|
59
|
+
}
|
|
60
|
+
if (/^\d{5}$/.test(base) && suffix === 'HK') return `${base}.HK`
|
|
61
|
+
if (US_MARKETS.has(suffix)) return base
|
|
62
|
+
return `${base}.${suffix}`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function symbolDisplayScore(symbol) {
|
|
66
|
+
const raw = String(symbol ?? '')
|
|
67
|
+
return (raw === raw.toUpperCase() ? 1 : 0) + (raw.includes('.') ? 2 : 0)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function preferredSymbol(current, incoming) {
|
|
71
|
+
return symbolDisplayScore(incoming) > symbolDisplayScore(current) ? incoming : current
|
|
72
|
+
}
|
|
23
73
|
|
|
24
74
|
export class BoardError extends Error {
|
|
25
75
|
constructor(code, message, status = 400) {
|
|
@@ -114,13 +164,17 @@ function normalize(value) {
|
|
|
114
164
|
return String(value ?? '').trim().toLowerCase().replace(/[\s|,,。;;::()[\]{}'"“”‘’\-_/]+/g, '')
|
|
115
165
|
}
|
|
116
166
|
|
|
167
|
+
function gapKey(gap) {
|
|
168
|
+
return `${gap.kind}|${normalize(gap.topic)}`
|
|
169
|
+
}
|
|
170
|
+
|
|
117
171
|
function todoKey(item) {
|
|
118
172
|
if (item.kind === 'confirm') return `confirm|${item.symbol ?? normalize(item.title)}`
|
|
119
173
|
if (item.kind === 'verify') return `verify|${item.symbol ?? ''}|${normalize(item.trigger ?? item.detail ?? item.title)}`
|
|
120
174
|
return `track|${item.symbol ?? ''}|${item.dueAt ?? normalize(item.title)}`
|
|
121
175
|
}
|
|
122
176
|
|
|
123
|
-
/** An ack
|
|
177
|
+
/** An ack covers only the version the user saw; a later run makes the item open again. */
|
|
124
178
|
function todoAckCovers(ack, item) {
|
|
125
179
|
if (ack === undefined) return false
|
|
126
180
|
const confirmedAt = Date.parse(ack.confirmedAt)
|
|
@@ -139,6 +193,24 @@ function sourceOf(run, item) {
|
|
|
139
193
|
}
|
|
140
194
|
}
|
|
141
195
|
|
|
196
|
+
/** Only the tracking facts belong on the wire; profileKey and storage ids stay server-side. */
|
|
197
|
+
function watchSummary(watch) {
|
|
198
|
+
if (watch === undefined) return null
|
|
199
|
+
return {
|
|
200
|
+
status: watch.status,
|
|
201
|
+
resolvedFrom: watch.resolvedFrom ?? null,
|
|
202
|
+
checkedAt: watch.checkedAt ?? null,
|
|
203
|
+
evidence: watch.evidence ?? null,
|
|
204
|
+
handoffReason: watch.handoffReason ?? null,
|
|
205
|
+
dueAt: watch.dueAt ?? null,
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function watchRank(item) {
|
|
210
|
+
if (item.watch === null || item.watch === undefined) return 9
|
|
211
|
+
return WATCH_RANK[item.watch.resolvedFrom ?? item.watch.status] ?? 9
|
|
212
|
+
}
|
|
213
|
+
|
|
142
214
|
function aggregateTodos(entries) {
|
|
143
215
|
const byKey = new Map()
|
|
144
216
|
for (const { run, brief } of entries) {
|
|
@@ -199,25 +271,30 @@ function aggregateTodos(entries) {
|
|
|
199
271
|
return result
|
|
200
272
|
}
|
|
201
273
|
|
|
202
|
-
function aggregateStocks(entries, todos) {
|
|
274
|
+
function aggregateStocks(entries, todos, firstSeenByKey = new Map()) {
|
|
203
275
|
const bySymbol = new Map()
|
|
204
276
|
for (const { run, brief } of entries) {
|
|
205
277
|
if (brief.status !== 'ready') continue
|
|
206
278
|
for (const stock of brief.stocks) {
|
|
207
279
|
const at = run.finishedAt ?? run.queuedAt
|
|
208
|
-
const
|
|
280
|
+
const symbolKey = stockSymbolKey(stock.symbol)
|
|
281
|
+
const current = bySymbol.get(symbolKey)
|
|
209
282
|
if (current === undefined) {
|
|
210
|
-
bySymbol.set(
|
|
283
|
+
bySymbol.set(symbolKey, {
|
|
284
|
+
symbolKey,
|
|
211
285
|
symbol: stock.symbol,
|
|
212
286
|
name: stock.name,
|
|
213
287
|
roles: new Set(stock.roles),
|
|
214
288
|
note: stock.note,
|
|
215
289
|
nextAt: stock.nextAt,
|
|
290
|
+
firstSeenAt: firstSeenByKey.get(symbolKey) ?? at,
|
|
216
291
|
lastSeenAt: at,
|
|
217
292
|
})
|
|
218
293
|
continue
|
|
219
294
|
}
|
|
220
295
|
for (const role of stock.roles) current.roles.add(role)
|
|
296
|
+
current.symbol = preferredSymbol(current.symbol, stock.symbol)
|
|
297
|
+
if (at < current.firstSeenAt) current.firstSeenAt = at
|
|
221
298
|
if (at >= current.lastSeenAt) {
|
|
222
299
|
current.name = stock.name
|
|
223
300
|
current.note = stock.note
|
|
@@ -226,17 +303,30 @@ function aggregateStocks(entries, todos) {
|
|
|
226
303
|
if (stock.nextAt !== undefined && (current.nextAt === undefined || stock.nextAt < current.nextAt)) current.nextAt = stock.nextAt
|
|
227
304
|
}
|
|
228
305
|
}
|
|
229
|
-
const
|
|
230
|
-
for (const item of todos)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
306
|
+
const stockItems = new Map()
|
|
307
|
+
for (const item of todos) {
|
|
308
|
+
if (item.symbol === undefined) continue
|
|
309
|
+
const key = stockSymbolKey(item.symbol)
|
|
310
|
+
const items = stockItems.get(key) ?? []
|
|
311
|
+
if (items.length >= MAX_STOCK_ITEMS) continue
|
|
312
|
+
items.push({ id: item.id, title: item.title, sessionId: item.sessionId ?? null })
|
|
313
|
+
stockItems.set(key, items)
|
|
314
|
+
}
|
|
315
|
+
const result = [...bySymbol.values()].map((stock) => {
|
|
316
|
+
const items = stockItems.get(stock.symbolKey) ?? []
|
|
317
|
+
return {
|
|
318
|
+
symbol: stock.symbol,
|
|
319
|
+
symbolKey: stock.symbolKey,
|
|
320
|
+
name: stock.name,
|
|
321
|
+
roles: [...stock.roles].sort((left, right) => (ROLE_RANK[left] ?? 9) - (ROLE_RANK[right] ?? 9)),
|
|
322
|
+
...(stock.note === undefined ? {} : { note: stock.note }),
|
|
323
|
+
...(stock.nextAt === undefined ? {} : { nextAt: stock.nextAt }),
|
|
324
|
+
todoCount: items.length,
|
|
325
|
+
items,
|
|
326
|
+
firstSeenAt: stock.firstSeenAt,
|
|
327
|
+
lastSeenAt: stock.lastSeenAt,
|
|
328
|
+
}
|
|
329
|
+
})
|
|
240
330
|
result.sort((left, right) => {
|
|
241
331
|
const role = (ROLE_RANK[left.roles[0]] ?? 9) - (ROLE_RANK[right.roles[0]] ?? 9)
|
|
242
332
|
if (role !== 0) return role
|
|
@@ -245,12 +335,12 @@ function aggregateStocks(entries, todos) {
|
|
|
245
335
|
return result
|
|
246
336
|
}
|
|
247
337
|
|
|
248
|
-
function aggregateGaps(entries) {
|
|
338
|
+
function aggregateGaps(entries, firstSeenByKey = new Map()) {
|
|
249
339
|
const byKey = new Map()
|
|
250
340
|
for (const { run, brief } of entries) {
|
|
251
341
|
if (brief.status !== 'ready') continue
|
|
252
342
|
for (const gap of brief.gaps) {
|
|
253
|
-
const key =
|
|
343
|
+
const key = gapKey(gap)
|
|
254
344
|
const at = run.finishedAt ?? run.queuedAt
|
|
255
345
|
const source = {
|
|
256
346
|
runId: run.id,
|
|
@@ -265,7 +355,7 @@ function aggregateGaps(entries) {
|
|
|
265
355
|
id: key,
|
|
266
356
|
...gap,
|
|
267
357
|
seenCount: 1,
|
|
268
|
-
firstSeenAt: at,
|
|
358
|
+
firstSeenAt: firstSeenByKey.get(key) ?? at,
|
|
269
359
|
lastSeenAt: at,
|
|
270
360
|
sources: [source],
|
|
271
361
|
runIds: new Set([run.id]),
|
|
@@ -296,6 +386,25 @@ function aggregateGaps(entries) {
|
|
|
296
386
|
return result
|
|
297
387
|
}
|
|
298
388
|
|
|
389
|
+
/** First mention across the whole retained run window, not just the selected date range. */
|
|
390
|
+
function firstSeenMaps(entries) {
|
|
391
|
+
const stocks = new Map()
|
|
392
|
+
const gaps = new Map()
|
|
393
|
+
for (const { run, brief } of entries) {
|
|
394
|
+
if (brief.status !== 'ready') continue
|
|
395
|
+
const at = run.finishedAt ?? run.queuedAt
|
|
396
|
+
for (const stock of brief.stocks) {
|
|
397
|
+
const key = stockSymbolKey(stock.symbol)
|
|
398
|
+
if (!stocks.has(key) || at < stocks.get(key)) stocks.set(key, at)
|
|
399
|
+
}
|
|
400
|
+
for (const gap of brief.gaps) {
|
|
401
|
+
const key = gapKey(gap)
|
|
402
|
+
if (!gaps.has(key) || at < gaps.get(key)) gaps.set(key, at)
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return { stocks, gaps }
|
|
406
|
+
}
|
|
407
|
+
|
|
299
408
|
function statusCounts(runs) {
|
|
300
409
|
const counts = {
|
|
301
410
|
total: runs.length,
|
|
@@ -376,6 +485,8 @@ function healthOf({ runs, briefs, timeZone, now, scheduler, tasks }) {
|
|
|
376
485
|
calendar: schedulerStatus.calendar ?? { available: false, source: 'none' },
|
|
377
486
|
recentIssues,
|
|
378
487
|
issueCount: ordered.filter((run) => FAILURE_STATUSES.has(run.status)).length,
|
|
488
|
+
todayIssueCount: runs.filter((run) => FAILURE_STATUSES.has(run.status)
|
|
489
|
+
&& dateOf(run.finishedAt ?? run.queuedAt, timeZone) === today).length,
|
|
379
490
|
nextRuns,
|
|
380
491
|
}
|
|
381
492
|
}
|
|
@@ -413,26 +524,62 @@ function cardOf(run, brief, task, ask) {
|
|
|
413
524
|
export function createBoardService(options) {
|
|
414
525
|
const { store, scheduler, asks, now = () => Date.now() } = options
|
|
415
526
|
|
|
416
|
-
|
|
417
|
-
|
|
527
|
+
/** Same entries back the page projection and the unbounded watcher projection. */
|
|
528
|
+
async function entriesFor(parsed) {
|
|
418
529
|
const page = await store.listRunsPage({ limit: 2_000 })
|
|
419
530
|
const tasks = await store.listTasks()
|
|
420
531
|
const taskById = new Map(tasks.map((task) => [task.id, task]))
|
|
421
532
|
const briefs = await store.listBriefsForRuns(page.runs.map((run) => run.id))
|
|
422
|
-
const todoAcks = await store.listTodoAcks()
|
|
423
|
-
const lifetime = await store.countBriefs()
|
|
424
533
|
const entries = []
|
|
534
|
+
const historyEntries = []
|
|
425
535
|
for (const run of page.runs) {
|
|
426
536
|
const brief = briefs.get(run.id)
|
|
427
537
|
if (run.status !== 'succeeded' || brief === undefined) continue
|
|
428
538
|
const task = taskById.get(run.taskId)
|
|
429
539
|
if (parsed.category !== undefined && task?.category !== parsed.category) continue
|
|
540
|
+
const entry = { run, task, brief }
|
|
541
|
+
historyEntries.push(entry)
|
|
430
542
|
if (!inRange(run.finishedAt ?? run.queuedAt, parsed.from, parsed.to, parsed.timeZone)) continue
|
|
431
|
-
entries.push(
|
|
543
|
+
entries.push(entry)
|
|
432
544
|
}
|
|
433
545
|
entries.sort((left, right) =>
|
|
434
546
|
String(right.run.finishedAt ?? right.run.queuedAt).localeCompare(String(left.run.finishedAt ?? left.run.queuedAt))
|
|
435
547
|
|| String(right.run.id).localeCompare(String(left.run.id)))
|
|
548
|
+
return { page, tasks, briefs, entries, historyEntries }
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
async function todosFor(parsed, sourceEntries, options = {}) {
|
|
552
|
+
const entries = sourceEntries ?? (await entriesFor(parsed)).entries
|
|
553
|
+
const [acks, watches] = await Promise.all([store.listTodoAcks(), store.listTodoWatches()])
|
|
554
|
+
const ackById = new Map(acks.map((ack) => [ack.todoId, ack]))
|
|
555
|
+
const watchById = new Map(watches.map((watch) => [watch.todoId, watch]))
|
|
556
|
+
const todos = aggregateTodos(entries).map((item) => {
|
|
557
|
+
const ack = ackById.get(item.id)
|
|
558
|
+
const ackedAt = todoAckCovers(ack, item) ? ack.confirmedAt : undefined
|
|
559
|
+
return {
|
|
560
|
+
...item,
|
|
561
|
+
watch: watchSummary(watchById.get(item.id)),
|
|
562
|
+
...(item.symbol === undefined ? {} : { symbolKey: stockSymbolKey(item.symbol) }),
|
|
563
|
+
...(ackedAt === undefined ? {} : { ackedAt }),
|
|
564
|
+
}
|
|
565
|
+
})
|
|
566
|
+
const visible = options.includeAcked === true ? todos : todos.filter((item) => item.ackedAt === undefined)
|
|
567
|
+
visible.sort((left, right) => {
|
|
568
|
+
const kind = (KIND_RANK[left.kind] ?? 9) - (KIND_RANK[right.kind] ?? 9)
|
|
569
|
+
if (kind !== 0) return kind
|
|
570
|
+
const watch = watchRank(left) - watchRank(right)
|
|
571
|
+
if (watch !== 0) return watch
|
|
572
|
+
return String(left.dueAt ?? '9999-12-31').localeCompare(String(right.dueAt ?? '9999-12-31'))
|
|
573
|
+
|| String(right.lastSeenAt).localeCompare(String(left.lastSeenAt))
|
|
574
|
+
|| String(left.id).localeCompare(String(right.id))
|
|
575
|
+
})
|
|
576
|
+
return visible
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
async function board(query = {}) {
|
|
580
|
+
const parsed = parseBoardQuery(query, now)
|
|
581
|
+
const { page, tasks, briefs, entries, historyEntries } = await entriesFor(parsed)
|
|
582
|
+
const lifetime = await store.countBriefs()
|
|
436
583
|
let start = 0
|
|
437
584
|
if (parsed.before !== undefined) {
|
|
438
585
|
const index = entries.findIndex((entry) => entry.run.id === parsed.before)
|
|
@@ -445,10 +592,11 @@ export function createBoardService(options) {
|
|
|
445
592
|
const askByRun = typeof asks?.latestForRuns === 'function'
|
|
446
593
|
? await asks.latestForRuns(pageRunIds)
|
|
447
594
|
: new Map()
|
|
448
|
-
const
|
|
449
|
-
const
|
|
450
|
-
const
|
|
451
|
-
const
|
|
595
|
+
const todos = await todosFor(parsed, entries, { includeAcked: true })
|
|
596
|
+
const openTodos = todos.filter((item) => item.ackedAt === undefined)
|
|
597
|
+
const firstSeen = firstSeenMaps(historyEntries)
|
|
598
|
+
const stocks = aggregateStocks(entries, openTodos, firstSeen.stocks)
|
|
599
|
+
const gaps = aggregateGaps(entries, firstSeen.gaps)
|
|
452
600
|
const health = healthOf({
|
|
453
601
|
runs: page.runs,
|
|
454
602
|
briefs,
|
|
@@ -457,6 +605,8 @@ export function createBoardService(options) {
|
|
|
457
605
|
scheduler,
|
|
458
606
|
tasks,
|
|
459
607
|
})
|
|
608
|
+
const today = parsed.to
|
|
609
|
+
const isToday = (value) => dateOf(value, parsed.timeZone) === today
|
|
460
610
|
return {
|
|
461
611
|
ok: true,
|
|
462
612
|
generatedAt: iso(now()),
|
|
@@ -464,10 +614,14 @@ export function createBoardService(options) {
|
|
|
464
614
|
range: { days: parsed.days === 'all' ? 'all' : Number(parsed.days), from: parsed.from ?? null, to: parsed.to },
|
|
465
615
|
stats: {
|
|
466
616
|
briefs: entries.length,
|
|
467
|
-
|
|
617
|
+
briefsToday: entries.filter((entry) => isToday(entry.run.finishedAt ?? entry.run.queuedAt)).length,
|
|
618
|
+
todos: openTodos.length,
|
|
468
619
|
stocks: stocks.length,
|
|
620
|
+
stocksNewToday: stocks.filter((stock) => isToday(stock.firstSeenAt)).length,
|
|
469
621
|
gaps: gaps.length,
|
|
622
|
+
gapsNewToday: gaps.filter((gap) => isToday(gap.firstSeenAt)).length,
|
|
470
623
|
issues7d: health.issueCount,
|
|
624
|
+
issuesToday: health.todayIssueCount,
|
|
471
625
|
},
|
|
472
626
|
cards: pageEntries.map((entry) => cardOf(entry.run, entry.brief, entry.task, askByRun.get(entry.run.id))),
|
|
473
627
|
todos: todos.slice(0, MAX_TODOS),
|
|
@@ -478,10 +632,15 @@ export function createBoardService(options) {
|
|
|
478
632
|
}
|
|
479
633
|
}
|
|
480
634
|
|
|
635
|
+
/** Unbounded TODO projection for the watcher; the page still gets MAX_TODOS. */
|
|
636
|
+
async function openTodos(query = {}) {
|
|
637
|
+
return todosFor(parseBoardQuery(query, now))
|
|
638
|
+
}
|
|
639
|
+
|
|
481
640
|
async function confirmTodo(todoId) {
|
|
482
641
|
const record = await store.confirmTodo(todoId)
|
|
483
642
|
return { id: record.todoId, confirmedAt: record.confirmedAt }
|
|
484
643
|
}
|
|
485
644
|
|
|
486
|
-
return { board, confirmTodo }
|
|
645
|
+
return { board, openTodos, confirmTodo }
|
|
487
646
|
}
|
package/automation/brief.js
CHANGED
|
@@ -14,12 +14,9 @@ import {
|
|
|
14
14
|
} from './schema.js'
|
|
15
15
|
import { sanitizeMessage } from './redact.js'
|
|
16
16
|
|
|
17
|
-
export const BRIEF_PROMPT_VERSION =
|
|
17
|
+
export const BRIEF_PROMPT_VERSION = 7
|
|
18
18
|
export const BRIEF_PENDING_STALE_MS = 10 * 60_000
|
|
19
19
|
export const BRIEF_MAX_ATTEMPTS = 5
|
|
20
|
-
export const BRIEF_MAX_ANSWER_CHARS = 12_000
|
|
21
|
-
export const BRIEF_HEAD_CHARS = 6_000
|
|
22
|
-
export const BRIEF_TAIL_CHARS = 6_000
|
|
23
20
|
export const BRIEF_TIMEOUT_MS = 90_000
|
|
24
21
|
// Reasoning models spend 1.5–2.5k thinking tokens before the JSON; 2.4k finishes at `length`.
|
|
25
22
|
const BRIEF_MAX_TOKENS = 8_000
|
|
@@ -154,14 +151,17 @@ export function extractSessionAnswer(snapshot) {
|
|
|
154
151
|
}
|
|
155
152
|
|
|
156
153
|
/** Build the one input object the model sees. sessionId is traceability, not extra knowledge. */
|
|
157
|
-
export function sourceBlocksOf(text) {
|
|
154
|
+
export function sourceBlocksOf(text, maxLineChars = Number.POSITIVE_INFINITY) {
|
|
158
155
|
const lines = String(text ?? '')
|
|
159
156
|
.split('\n')
|
|
160
157
|
.map((line) => line.trim())
|
|
161
158
|
.filter((line) => line.length > 0)
|
|
162
159
|
.filter((line) => !line.includes('……(中间省略)……'))
|
|
163
160
|
.filter((line) => !/^\|?[\s:|-]+\|?$/.test(line))
|
|
164
|
-
return lines.map((line, index) => ({
|
|
161
|
+
return lines.map((line, index) => ({
|
|
162
|
+
id: index + 1,
|
|
163
|
+
text: Number.isFinite(maxLineChars) ? line.slice(0, maxLineChars) : line,
|
|
164
|
+
}))
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
export function buildBriefPayload({ sessionId, task, run, answer, coverage }) {
|
|
@@ -176,23 +176,15 @@ export function buildBriefPayload({ sessionId, task, run, answer, coverage }) {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
export function
|
|
180
|
-
|
|
181
|
-
const chars = Array.from(source)
|
|
182
|
-
if (chars.length <= BRIEF_MAX_ANSWER_CHARS) return { text: source, coverage: 'full' }
|
|
183
|
-
const head = chars.slice(0, BRIEF_HEAD_CHARS).join('')
|
|
184
|
-
const tail = chars.slice(-BRIEF_TAIL_CHARS).join('')
|
|
185
|
-
return {
|
|
186
|
-
text: `${head}\n\n……(中间省略)……\n\n${tail}`,
|
|
187
|
-
coverage: 'partial',
|
|
188
|
-
}
|
|
179
|
+
export function normalizeFinalAnswer(text) {
|
|
180
|
+
return { text: String(text ?? '').replace(/\u0000/g, '').trim(), coverage: 'full' }
|
|
189
181
|
}
|
|
190
182
|
|
|
191
183
|
export function sourceHashOf(text) {
|
|
192
184
|
return createHash('sha256').update(String(text ?? '')).digest('hex').slice(0, 16)
|
|
193
185
|
}
|
|
194
186
|
|
|
195
|
-
function normalizeQuote(text) {
|
|
187
|
+
export function normalizeQuote(text) {
|
|
196
188
|
// Compare content only: NFKC folds full-width forms, then drop all whitespace,
|
|
197
189
|
// punctuation and symbols. Models often add periods/quotes/ellipses or rewrite
|
|
198
190
|
// table pipes when quoting; those must not read as a fabricated citation.
|
|
@@ -216,7 +208,7 @@ function optionalDate(value) {
|
|
|
216
208
|
return value
|
|
217
209
|
}
|
|
218
210
|
|
|
219
|
-
function includesQuote(source, quote) {
|
|
211
|
+
export function includesQuote(source, quote) {
|
|
220
212
|
const normalized = normalizeQuote(source)
|
|
221
213
|
const wanted = normalizeQuote(quote)
|
|
222
214
|
return wanted.length > 0 && normalized.includes(wanted)
|
|
@@ -418,7 +410,7 @@ async function readSessionAnswer(sessionQuery, sessionId) {
|
|
|
418
410
|
throw new BriefValidationError('session_unavailable', `读取 session 失败:${String(lastError?.message ?? lastError)}`)
|
|
419
411
|
}
|
|
420
412
|
|
|
421
|
-
async function streamText(llm, options) {
|
|
413
|
+
export async function streamText(llm, options) {
|
|
422
414
|
const stream = llm.stream(options)
|
|
423
415
|
let text = ''
|
|
424
416
|
for await (const chunk of stream) {
|
|
@@ -465,6 +457,7 @@ export function createBriefService(options) {
|
|
|
465
457
|
scheduler,
|
|
466
458
|
now = () => Date.now(),
|
|
467
459
|
logger,
|
|
460
|
+
onBriefReady,
|
|
468
461
|
promptVersion = BRIEF_PROMPT_VERSION,
|
|
469
462
|
maxActive = BRIEF_MAX_ACTIVE_PER_PROFILE,
|
|
470
463
|
recoveryIntervalMs = BRIEF_RECOVERY_INTERVAL_MS,
|
|
@@ -551,23 +544,31 @@ export function createBriefService(options) {
|
|
|
551
544
|
}
|
|
552
545
|
if (!owner()) return
|
|
553
546
|
|
|
554
|
-
const
|
|
555
|
-
const sourceHash = sourceHashOf(
|
|
547
|
+
const normalized = normalizeFinalAnswer(extracted.text)
|
|
548
|
+
const sourceHash = sourceHashOf(normalized.text)
|
|
556
549
|
const task = await store.getTask(run.taskId).catch(() => undefined)
|
|
557
550
|
const payload = buildBriefPayload({
|
|
558
551
|
sessionId: run.sessionId,
|
|
559
552
|
task,
|
|
560
553
|
run,
|
|
561
|
-
answer:
|
|
562
|
-
coverage:
|
|
554
|
+
answer: normalized.text,
|
|
555
|
+
coverage: normalized.coverage,
|
|
563
556
|
})
|
|
564
557
|
const route = extracted.provider !== undefined && extracted.model !== undefined
|
|
565
558
|
? { provider: extracted.provider, model: extracted.model }
|
|
566
559
|
: fallbackModelRoute(ctx)
|
|
567
560
|
if (route === undefined) {
|
|
568
|
-
await markFailed(runId, new Error('没有可用的模型路由'), { sourceHash, coverage:
|
|
561
|
+
await markFailed(runId, new Error('没有可用的模型路由'), { sourceHash, coverage: normalized.coverage, promptVersion })
|
|
569
562
|
return
|
|
570
563
|
}
|
|
564
|
+
// Evaluate TODO conditions from the same answer even when brief generation later fails or skips.
|
|
565
|
+
if (typeof onBriefReady === 'function') {
|
|
566
|
+
try {
|
|
567
|
+
await onBriefReady({ run, task, text: normalized.text, route })
|
|
568
|
+
} catch (error) {
|
|
569
|
+
logger?.warn?.(`capital-automation: TODO 核验入队失败:${String(error)}`)
|
|
570
|
+
}
|
|
571
|
+
}
|
|
571
572
|
|
|
572
573
|
let attempts = brief.attempts
|
|
573
574
|
let raw
|
|
@@ -586,17 +587,17 @@ export function createBriefService(options) {
|
|
|
586
587
|
}
|
|
587
588
|
}
|
|
588
589
|
if (raw === undefined) {
|
|
589
|
-
await markFailed(runId, callError ?? new Error('模型调用失败'), { attempts, model: routeLabel(route), sourceHash, coverage:
|
|
590
|
+
await markFailed(runId, callError ?? new Error('模型调用失败'), { attempts, model: routeLabel(route), sourceHash, coverage: normalized.coverage, promptVersion })
|
|
590
591
|
return
|
|
591
592
|
}
|
|
592
593
|
if (!owner()) return
|
|
593
594
|
|
|
594
595
|
let parsed
|
|
595
596
|
try {
|
|
596
|
-
parsed = parseBriefOutput(raw,
|
|
597
|
+
parsed = parseBriefOutput(raw, normalized.text, payload.sourceBlocks)
|
|
597
598
|
} catch (firstError) {
|
|
598
599
|
if (attempts >= BRIEF_MAX_ATTEMPTS) {
|
|
599
|
-
await markFailed(runId, firstError, { attempts, model: routeLabel(route), sourceHash, coverage:
|
|
600
|
+
await markFailed(runId, firstError, { attempts, model: routeLabel(route), sourceHash, coverage: normalized.coverage, promptVersion })
|
|
600
601
|
return
|
|
601
602
|
}
|
|
602
603
|
try {
|
|
@@ -616,9 +617,9 @@ export function createBriefService(options) {
|
|
|
616
617
|
},
|
|
617
618
|
},
|
|
618
619
|
})
|
|
619
|
-
parsed = parseBriefOutput(repair,
|
|
620
|
+
parsed = parseBriefOutput(repair, normalized.text, payload.sourceBlocks)
|
|
620
621
|
} catch (secondError) {
|
|
621
|
-
await markFailed(runId, secondError, { attempts, model: routeLabel(route), sourceHash, coverage:
|
|
622
|
+
await markFailed(runId, secondError, { attempts, model: routeLabel(route), sourceHash, coverage: normalized.coverage, promptVersion })
|
|
622
623
|
return
|
|
623
624
|
}
|
|
624
625
|
}
|
|
@@ -631,7 +632,7 @@ export function createBriefService(options) {
|
|
|
631
632
|
model: routeLabel(route),
|
|
632
633
|
promptVersion,
|
|
633
634
|
sourceHash,
|
|
634
|
-
coverage:
|
|
635
|
+
coverage: normalized.coverage,
|
|
635
636
|
generatedAt: iso(now()),
|
|
636
637
|
})
|
|
637
638
|
return
|
|
@@ -647,7 +648,7 @@ export function createBriefService(options) {
|
|
|
647
648
|
model: routeLabel(route),
|
|
648
649
|
promptVersion,
|
|
649
650
|
sourceHash,
|
|
650
|
-
coverage:
|
|
651
|
+
coverage: normalized.coverage,
|
|
651
652
|
generatedAt: iso(now()),
|
|
652
653
|
})
|
|
653
654
|
}
|