@v587d/capital-generation 2.21.3 → 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,16 @@
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
+
10
20
  ## [2.21.3] - 2026-11-13
11
21
 
12
22
  已触发 TODO 隔天收入历史;右侧面板的折叠箭头恢复方向变化。
package/README.md CHANGED
@@ -3,7 +3,7 @@
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.3-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
 
@@ -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.3` 或 `@2.21.3`。
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 提取失败时可尝试本机直连。关闭后,本机直连的具名来源查询也不可用;请检查该开关和网络连接。
@@ -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)
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Shared extraction for model-authored JSON. Briefs and TODO verdicts both arrive as an
3
+ * object wrapped in prose or a code fence, and models occasionally leave a trailing comma
4
+ * before `]`/`}`; one implementation keeps both readers on the same rules.
5
+ */
6
+
7
+ function parseValue(text) {
8
+ try {
9
+ return JSON.parse(text)
10
+ } catch {
11
+ return undefined
12
+ }
13
+ }
14
+
15
+ export function stripTrailingCommas(text) {
16
+ let output = ''
17
+ let inString = false
18
+ let escaped = false
19
+ for (let index = 0; index < text.length; index += 1) {
20
+ const char = text[index]
21
+ if (inString) {
22
+ output += char
23
+ if (escaped) escaped = false
24
+ else if (char === '\\') escaped = true
25
+ else if (char === '"') inString = false
26
+ continue
27
+ }
28
+ if (char === '"') {
29
+ inString = true
30
+ output += char
31
+ continue
32
+ }
33
+ if (char === ',') {
34
+ let next = index + 1
35
+ while (next < text.length && /\s/.test(text[next])) next += 1
36
+ if (text[next] === ']' || text[next] === '}') continue
37
+ }
38
+ output += char
39
+ }
40
+ return output
41
+ }
42
+
43
+ /** Parse any JSON value, retrying once with string-aware trailing-comma removal. */
44
+ export function parseJsonValue(text) {
45
+ const direct = parseValue(text)
46
+ if (direct !== undefined) return direct
47
+ return parseValue(stripTrailingCommas(text))
48
+ }
49
+
50
+ /**
51
+ * Narrow a model reply to the JSON text it carries: the last code fence when one exists,
52
+ * otherwise the outermost `{...}` after a prose preamble. Truncated text is returned as-is so
53
+ * the caller can report a parse failure instead of silently accepting half an object.
54
+ */
55
+ export function extractJsonText(raw) {
56
+ const text = String(raw ?? '').replace(/^\uFEFF/, '').trim()
57
+ const fences = [...text.matchAll(/```(?:json)?\s*([\s\S]*?)\s*```/gi)]
58
+ if (fences.length > 0) return fences.at(-1)[1].trim()
59
+ const start = text.indexOf('{')
60
+ if (start < 0) return text
61
+ const end = text.lastIndexOf('}')
62
+ return end > start ? text.slice(start, end + 1) : text.slice(start)
63
+ }
64
+
65
+ /** The extracted reply when it is a JSON object, otherwise undefined. */
66
+ export function extractJsonObject(raw) {
67
+ const value = parseJsonValue(extractJsonText(raw))
68
+ return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined
69
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-automation",
3
- "version": "2.21.3",
3
+ "version": "2.21.4",
4
4
  "description": "CapGen 投研自动化:独立 host bundle(固定 capital_automation 域、单 scheduler owner、/capital-automation 路由与浏览器页面)。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -7,6 +7,7 @@ import { createHash } from 'node:crypto'
7
7
  import { isDeepStrictEqual } from 'node:util'
8
8
 
9
9
  import { includesQuote, sourceBlocksOf } from './brief.js'
10
+ import { extractJsonObject } from './json-text.js'
10
11
  import { sanitizeMessage } from './redact.js'
11
12
  import { localPartsAt } from './time.js'
12
13
 
@@ -91,65 +92,6 @@ function decisionCovers(decision, lastSeenAt) {
91
92
  return seenAt <= decidedAt
92
93
  }
93
94
 
94
- function parseObject(text) {
95
- try {
96
- const value = JSON.parse(text)
97
- return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined
98
- } catch {
99
- return undefined
100
- }
101
- }
102
-
103
- /**
104
- * Models occasionally leave a trailing comma before `]`/`}`; JSON.parse then drops the whole
105
- * verdict block and every candidate silently falls back to insufficient.
106
- */
107
- function stripTrailingCommas(text) {
108
- let output = ''
109
- let inString = false
110
- let escaped = false
111
- for (let index = 0; index < text.length; index += 1) {
112
- const char = text[index]
113
- if (inString) {
114
- output += char
115
- if (escaped) escaped = false
116
- else if (char === '\\') escaped = true
117
- else if (char === '"') inString = false
118
- continue
119
- }
120
- if (char === '"') {
121
- inString = true
122
- output += char
123
- continue
124
- }
125
- if (char === ',') {
126
- let next = index + 1
127
- while (next < text.length && /\s/.test(text[next])) next += 1
128
- if (text[next] === ']' || text[next] === '}') continue
129
- }
130
- output += char
131
- }
132
- return output
133
- }
134
-
135
- /**
136
- * Validate the verifier's result block against the evidence text it claims to quote. A quote
137
- * that exists in neither the tool output nor the final answer is a fabrication and is dropped.
138
- */
139
- function extractJsonObject(raw) {
140
- let text = String(raw ?? '').trim()
141
- const fences = [...text.matchAll(/```(?:json)?\s*([\s\S]*?)\s*```/gi)]
142
- if (fences.length > 0) {
143
- text = fences.at(-1)[1].trim()
144
- } else {
145
- // A verifier may wrap the JSON in a short prose preamble; keep the outermost object.
146
- const start = text.indexOf('{')
147
- const end = text.lastIndexOf('}')
148
- if (start >= 0 && end > start) text = text.slice(start, end + 1)
149
- }
150
- return parseObject(text) ?? parseObject(stripTrailingCommas(text))
151
- }
152
-
153
95
  /**
154
96
  * The verifier authors the board card in the same final answer as its verdicts, so the brief
155
97
  * costs no extra model call. Validation and fallback live in `verifierBriefContent`.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-charts",
3
- "version": "2.21.3",
3
+ "version": "2.21.4",
4
4
  "description": "自动模式的图表前端组件(浏览器半边 + 序列旁路路由):由 @v587d/capital-generation 随包携带并作为 host 平面行挂载。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/config",
3
- "version": "2.21.3",
3
+ "version": "2.21.4",
4
4
  "description": "自动模式的取数凭据与偏好配置行:卡片坐在 @v587d/capital-generation 插件主页的「配置」段,点这一行本身没有表单。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -3,7 +3,7 @@
3
3
  * Known limit: DNS resolves per request but the IP is not pinned to the connection,
4
4
  * so a rebinding window remains (same trade-off as dsh-search-first).
5
5
  */
6
- export declare const LOCAL_FETCH_CLIENT_VERSION = "2.21.3";
6
+ export declare const LOCAL_FETCH_CLIENT_VERSION = "2.21.4";
7
7
  export declare const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
8
8
  export type LocalFetchErrorCode = 'ABORTED' | 'TIMEOUT' | 'INVALID_URL' | 'BLOCKED_URL' | 'DNS' | 'REDIRECT' | 'HTTP' | 'TOO_LARGE' | 'UNSUPPORTED_CONTENT_TYPE';
9
9
  export declare class LocalFetchError extends Error {
@@ -4,7 +4,7 @@
4
4
  * so a rebinding window remains (same trade-off as dsh-search-first).
5
5
  */
6
6
  import { htmlToMarkdown, stripInvisibleText } from './html-markdown.js';
7
- export const LOCAL_FETCH_CLIENT_VERSION = '2.21.3';
7
+ export const LOCAL_FETCH_CLIENT_VERSION = '2.21.4';
8
8
  export const LOCAL_FETCH_MAX_URL_LENGTH = 2048;
9
9
  export class LocalFetchError extends Error {
10
10
  code;
@@ -35,7 +35,7 @@ export interface WindCallResult {
35
35
  code?: WindErrorCode;
36
36
  }
37
37
  /** Must match `package.json` version; a test pins the two together. */
38
- export declare const WIND_CLIENT_VERSION = "2.21.3";
38
+ export declare const WIND_CLIENT_VERSION = "2.21.4";
39
39
  export interface WindClient {
40
40
  callTool(toolName: string, args: Record<string, unknown>, signal?: AbortSignal): Promise<WindCallResult>;
41
41
  }
@@ -19,7 +19,7 @@ export const WIND_SERVER_ENDPOINTS = {
19
19
  analytics_data: 'https://mcp.wind.com.cn/vserver_analytics_data/mcp/',
20
20
  };
21
21
  /** Must match `package.json` version; a test pins the two together. */
22
- export const WIND_CLIENT_VERSION = '2.21.3';
22
+ export const WIND_CLIENT_VERSION = '2.21.4';
23
23
  function errorText(error) {
24
24
  return error instanceof Error ? error.message : String(error);
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-generation",
3
- "version": "2.21.3",
3
+ "version": "2.21.4",
4
4
  "description": "Capital Generation:面向中国散户的 AI 投资助手插件(自动模式 Agent Preset)",
5
5
  "icon": "assets/cg-icon.png",
6
6
  "author": "v587d",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/watchlist",
3
- "version": "2.21.3",
3
+ "version": "2.21.4",
4
4
  "description": "自动模式的用户自选股(宿主级清单 + Fuyao 报价快照 + /capital-watchlist 路由 + 输入框菜单弹窗):由 @v587d/capital-generation 随包携带并作为 host 平面行挂载。",
5
5
  "license": "MIT",
6
6
  "type": "module",