@v587d/capital-generation 2.21.2 → 2.21.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,28 @@
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.21.4] - 2026-11-13
11
+
12
+ 简报生成适配长推理:提高输出上限与超时,截断与空正文给出可诊断错误。
13
+
14
+ ### Changed
15
+
16
+ - **简报输出上限 8k → 32k、超时 90s → 180s**:推理 token 与正文共享 `maxTokens`,原来的 8k 常被思考过程吃光,正文变成空串;现在给推理留出空间,避免把「没说完」误报成 JSON 格式错误。
17
+ - **截断与空正文按可诊断错误重试**:`streamText` 返回 `finish` 与 `usage`;达到 `max-tokens` 且没有完整 JSON 时按「输出截断」重试(不再发一次注定失败的修复请求),空正文会带上推理 / 输出 token 数。
18
+ - **简报与 TODO 核验共用 JSON 提取**:新增 `automation/json-text.js`,统一处理代码围栏、前后说明与字符串外尾逗号;`parseBriefOutput` 对空正文单独报 `empty_output`。
19
+
20
+ ## [2.21.3] - 2026-11-13
21
+
22
+ 已触发 TODO 隔天收入历史;右侧面板的折叠箭头恢复方向变化。
23
+
24
+ ### Changed
25
+
26
+ - **已触发 TODO 隔天收入历史**:触发项只在触发当天或到期日当天(取较晚者)留在今天,隔天按到期日归入历史 TODO,结论显示「已触发」+ 自动核验日期;不再计入今天 TODO 与个股待跟进,watch 状态仍保留 `triggered`。服务端看板投影与客户端分组同改。
27
+
28
+ ### Fixed
29
+
30
+ - **右侧面板箭头收起后不转向**:DSH 图标组件只转发 `size` / `className`,原来的 `data-open` 属性在落到 `<svg>` 前就被丢掉,`[data-open="false"]` 选择器永远不匹配;改用折叠按钮已有的 `aria-expanded="false"` 作为选择器,TODO / 个股动态 / 数据体检 / 运行健康四个面板一起恢复。
31
+
10
32
  ## [2.21.2] - 2026-11-12
11
33
 
12
34
  TODO 核验依据改为用户可读文案;旧记录里残留的数据集 ID、工具名与采集时间不再出现在看板。
package/README.md CHANGED
@@ -3,11 +3,11 @@
3
3
  <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-green" alt="License"></a>
4
4
  <a href="https://github.com/v587d/capital-generation"><img src="https://img.shields.io/badge/Financial%20Market-CN%20%7C%20HK%20%7C%20US-orange" alt="Market·CN+HK+US"></a>
5
5
  <a href="https://github.com/deepseek-ai"><img src="https://img.shields.io/badge/DSH%20Baseline-0.2.2--rc.1-blue" alt="DSH@0.2.2-rc.1"></a>
6
- <a href="https://github.com/v587d/capital-generation/releases"><img src="https://img.shields.io/badge/version-2.21.2-9cf" alt="Version"></a>
6
+ <a href="https://github.com/v587d/capital-generation/releases"><img src="https://img.shields.io/badge/version-2.21.4-9cf" alt="Version"></a>
7
7
  <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>
8
8
  </p>
9
9
 
10
- > Next-Gen AI-Driven Capital Generation.
10
+ > Next-Gen AI-Driven Capital Gains.
11
11
 
12
12
  Capital Generation 是运行在 [DeepSeek Harness(DSH)](https://github.com/deepseek-ai/deepseek-harness) 里的证券研究插件,面向关注 A 股、港股、美股的个体投资者。安装后,新会话的选择器里会多出 **自动模式**、**行情专家**、**资讯专员** 三个模式;日常研究选 **自动模式**,用自然语言查行情、财务数据、公告和新闻,由它安排取数、数据质检、资料检索与图表,最后给出带来源的结论。它不是独立应用,需要先安装 DSH。
13
13
 
@@ -184,7 +184,7 @@ Capital Generation 是运行在 [DeepSeek Harness(DSH)](https://github.com/d
184
184
  - **安装后找不到模式?** 确认插件出现在「插件」→ 已安装列表;Web / CLI profile 安装后要重启该 profile,并在新会话选择模式。选择器里应看到自动模式、行情专家、资讯专员;分析师和绘图专员是自动模式的内部角色,不会出现在这里。
185
185
  - **配置在哪?** 打开「插件」→ 已安装的 **Capital Generation**,插件介绍下方就是「数据源 / 投研自动化 / 精选 Skills / 包含的组件」四格,五把密钥都在第一格;第二格可指定任务统一使用的默认工作区,也能改自动检查间隔与最长运行时间等上限;不在 DSH 的普通「设置」页面,也不用点进任何一行组件。保存密钥后新建会话再试。
186
186
  - **升级到 2.9.0 后,分析师和绘图专员去哪了?** 这一版把它们收进自动模式内部,不再出现在选择器与预设管理里,避免误开一个没有取数入口的空会话。旧会话仍能按原身份恢复;新任务直接用自动模式提出即可。
187
- - **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.21.2` 或 `@2.21.2`。
187
+ - **桌面端升级后仍是旧版?** 桌面端安装时会固定所解析的版本,不会自动升级。卸载后重新安装,再到插件详情查看版本号;如需指定版本,可在地址末尾加 `#v2.21.4` 或 `@2.21.4`。
188
188
  - **刚发布的新版本装不到?** 桌面端取包时会跳过**刚发布不久**的版本(宿主侧包管理器的发布冷却策略,实测会静默装成上一个版本),国内镜像的同步也可能滞后一段时间。急着用最新代码,改用仓库地址安装最直接;但仓库地址安装的是 git 依赖,插件页不显示「版本」检查。
189
189
  - **插件页的「版本」段怎么用?** 只有用包名从 npm 安装的版本才有;它只列比当前新的版本。回旧版要先卸载,再安装 `@v587d/capital-generation@版本号`(桌面端地址末尾加 `#v版本号`);旧版必须匹配当前 DSH 基线,对应关系见 [CHANGELOG 的 Migration](CHANGELOG.md)。
190
190
  - **网页抓取失败?** 配置卡片中的「允许启动本地提取网页内容」默认开启:AnySearch 提取失败时可尝试本机直连。关闭后,本机直连的具名来源查询也不可用;请检查该开关和网络连接。
@@ -277,7 +277,14 @@ function todoExpired(item, today, timeZone) {
277
277
  return decidedDate === undefined || decidedDate < today
278
278
  }
279
279
  const watchStatus = item.watch?.resolvedFrom ?? item.watch?.status
280
- if (watchStatus === 'triggered') return false
280
+ // A triggered condition is a fact, but it only belongs to "today" through the day it fired
281
+ // (or was due). From the next day it is history, like any other settled TODO.
282
+ if (watchStatus === 'triggered') {
283
+ const due = typeof item.dueAt === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(item.dueAt) ? item.dueAt : ''
284
+ const checked = dateOf(item.watch?.checkedAt, timeZone) ?? ''
285
+ const latest = due > checked ? due : checked
286
+ return latest.length > 0 && latest < today
287
+ }
281
288
  if (item.watch?.status === 'expired') return true
282
289
  if (typeof item.dueAt === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(item.dueAt)) return item.dueAt < today
283
290
  const label = typeof item.dueLabel === 'string' ? item.dueLabel.trim() : ''
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { createHash } from 'node:crypto'
8
8
 
9
+ import { extractJsonText, parseJsonValue } from './json-text.js'
9
10
  import {
10
11
  BriefGapSchema,
11
12
  BriefItemSchema,
@@ -17,9 +18,11 @@ import { sanitizeMessage } from './redact.js'
17
18
  export const BRIEF_PROMPT_VERSION = 11
18
19
  export const BRIEF_PENDING_STALE_MS = 10 * 60_000
19
20
  export const BRIEF_MAX_ATTEMPTS = 5
20
- export const BRIEF_TIMEOUT_MS = 90_000
21
- // Reasoning models spend 1.5–2.5k thinking tokens before the JSON; 2.4k finishes at `length`.
22
- const BRIEF_MAX_TOKENS = 8_000
21
+ // Reasoning runs a long time before the first JSON token; the cap must outlast it.
22
+ export const BRIEF_TIMEOUT_MS = 180_000
23
+ // Reasoning tokens share this cap with the JSON, and the model thinks before answering even
24
+ // without an explicit effort. A cap that only covers the JSON can end with empty content.
25
+ const BRIEF_MAX_TOKENS = 32_000
23
26
  const BRIEF_MAX_ACTIVE_PER_PROFILE = 2
24
27
  const BRIEF_MAX_ACTIVE_GLOBAL = 3
25
28
  const BRIEF_RECOVERY_INTERVAL_MS = 60_000
@@ -482,13 +485,12 @@ function dedupeBy(list, keyOf) {
482
485
  }
483
486
 
484
487
  export function parseBriefOutput(raw, source, blocks = sourceBlocksOf(source)) {
485
- let text = String(raw ?? '').trim()
486
- const fenced = /^```(?:json)?\s*([\s\S]*?)\s*```$/i.exec(text)
487
- if (fenced !== null) text = fenced[1].trim()
488
- let value
489
- try {
490
- value = JSON.parse(text)
491
- } catch {
488
+ const text = String(raw ?? '').trim()
489
+ if (text.length === 0) {
490
+ throw new BriefValidationError('empty_output', '模型没有返回正文')
491
+ }
492
+ const value = parseJsonValue(extractJsonText(text))
493
+ if (value === undefined) {
492
494
  throw new BriefValidationError('invalid_json', '模型输出不是合法 JSON')
493
495
  }
494
496
  if (value === null || typeof value !== 'object' || Array.isArray(value)) {
@@ -554,26 +556,35 @@ export async function readSessionAnswer(sessionQuery, sessionId, { includeToolTe
554
556
  export async function streamText(llm, options) {
555
557
  const stream = llm.stream(options)
556
558
  let text = ''
559
+ let finish
560
+ let usage
557
561
  for await (const chunk of stream) {
558
- if (chunk?.type === 'text-delta' && typeof chunk.text === 'string') text += chunk.text
559
- if (chunk?.type === 'finish') {
560
- const kind = chunk.reason?.kind
561
- if (kind === 'error' || kind === 'aborted') {
562
- const failure = chunk.reason?.failure ?? chunk.reason?.reason ?? {}
563
- const code = typeof failure.code === 'string' ? failure.code : undefined
564
- const status = Number.isFinite(failure.status) ? failure.status : undefined
565
- const message = typeof failure.message === 'string' ? failure.message : undefined
566
- const detail = [
567
- code === undefined ? null : `code=${code}`,
568
- status === undefined ? null : `status=${status}`,
569
- message === undefined ? null : `message=${message}`,
570
- ].filter(Boolean).join(' · ')
571
- throw new Error(`模型请求结束:${kind}${detail ? `(${detail})` : ''}`)
572
- }
573
- break
562
+ if (chunk?.type === 'text-delta' && typeof chunk.text === 'string') {
563
+ text += chunk.text
564
+ continue
565
+ }
566
+ if (chunk?.type === 'usage' && chunk.usage !== undefined) {
567
+ usage = chunk.usage
568
+ continue
569
+ }
570
+ if (chunk?.type !== 'finish') continue
571
+ const kind = chunk.reason?.kind
572
+ if (kind === 'error' || kind === 'aborted') {
573
+ const failure = chunk.reason?.failure ?? chunk.reason?.reason ?? {}
574
+ const code = typeof failure.code === 'string' ? failure.code : undefined
575
+ const status = Number.isFinite(failure.status) ? failure.status : undefined
576
+ const message = typeof failure.message === 'string' ? failure.message : undefined
577
+ const detail = [
578
+ code === undefined ? null : `code=${code}`,
579
+ status === undefined ? null : `status=${status}`,
580
+ message === undefined ? null : `message=${message}`,
581
+ ].filter(Boolean).join(' · ')
582
+ throw new Error(`模型请求结束:${kind}${detail ? `(${detail})` : ''}`)
574
583
  }
584
+ finish = chunk.reason
585
+ break
575
586
  }
576
- return text.trim()
587
+ return { text: text.trim(), finish, usage }
577
588
  }
578
589
 
579
590
  function fallbackModelRoute(ctx) {
@@ -591,6 +602,14 @@ function errorText(error) {
591
602
  return text.length > 0 ? text : '任务简报生成失败'
592
603
  }
593
604
 
605
+ /** Name the spend that starved the answer; pi-ai folds reasoning into output. */
606
+ function reasoningNote(usage) {
607
+ const reasoning = usage?.reasoningTokens
608
+ if (Number.isFinite(reasoning) && reasoning > 0) return `(推理已用 ${reasoning} token)`
609
+ const output = usage?.outputTokens
610
+ return Number.isFinite(output) && output > 0 ? `(本次输出 ${output} token)` : ''
611
+ }
612
+
594
613
  export function createBriefService(options) {
595
614
  const {
596
615
  ctx,
@@ -634,7 +653,7 @@ export function createBriefService(options) {
634
653
  const timeout = setTimeout(() => controller.abort(), BRIEF_TIMEOUT_MS)
635
654
  timeout.unref?.()
636
655
  try {
637
- return await streamText(llm, {
656
+ const result = await streamText(llm, {
638
657
  provider: route.provider,
639
658
  model: route.model,
640
659
  // opencode-go rejects requests without x-opencode-session; this is its header source.
@@ -645,6 +664,19 @@ export function createBriefService(options) {
645
664
  maxTokens: BRIEF_MAX_TOKENS,
646
665
  signal: controller.signal,
647
666
  })
667
+ const note = reasoningNote(result.usage)
668
+ // A truncated reply is usually all reasoning: retry instead of asking the model to
669
+ // repair text it never finished. Keep it when the object closed before the cut.
670
+ if (result.finish?.kind === 'max-tokens' && parseJsonValue(extractJsonText(result.text)) === undefined) {
671
+ throw new BriefValidationError(
672
+ 'output_truncated',
673
+ `模型输出达到 ${BRIEF_MAX_TOKENS} token 上限被截断${note},没有留下完整 JSON`,
674
+ )
675
+ }
676
+ if (result.text.length === 0) {
677
+ throw new BriefValidationError('empty_output', `模型没有返回正文${note}`)
678
+ }
679
+ return result.text
648
680
  } finally {
649
681
  clearTimeout(timeout)
650
682
  controllers.delete(runId)