@v587d/capital-generation 2.21.0 → 2.21.2

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.
@@ -91,11 +91,52 @@ function decisionCovers(decision, lastSeenAt) {
91
91
  return seenAt <= decidedAt
92
92
  }
93
93
 
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
+
94
135
  /**
95
136
  * Validate the verifier's result block against the evidence text it claims to quote. A quote
96
137
  * that exists in neither the tool output nor the final answer is a fabrication and is dropped.
97
138
  */
98
- export function parseWatchOutput(raw, { todos, blocks, sourceText }) {
139
+ function extractJsonObject(raw) {
99
140
  let text = String(raw ?? '').trim()
100
141
  const fences = [...text.matchAll(/```(?:json)?\s*([\s\S]*?)\s*```/gi)]
101
142
  if (fences.length > 0) {
@@ -106,13 +147,22 @@ export function parseWatchOutput(raw, { todos, blocks, sourceText }) {
106
147
  const end = text.lastIndexOf('}')
107
148
  if (start >= 0 && end > start) text = text.slice(start, end + 1)
108
149
  }
109
- let value
110
- try {
111
- value = JSON.parse(text)
112
- } catch {
113
- return []
114
- }
115
- if (value === null || typeof value !== 'object' || Array.isArray(value)) return []
150
+ return parseObject(text) ?? parseObject(stripTrailingCommas(text))
151
+ }
152
+
153
+ /**
154
+ * The verifier authors the board card in the same final answer as its verdicts, so the brief
155
+ * costs no extra model call. Validation and fallback live in `verifierBriefContent`.
156
+ */
157
+ export function parseVerifierBrief(raw) {
158
+ const brief = extractJsonObject(raw)?.brief
159
+ if (brief === null || typeof brief !== 'object' || Array.isArray(brief)) return undefined
160
+ return { headline: brief.headline, plain: brief.plain }
161
+ }
162
+
163
+ export function parseWatchOutput(raw, { todos, blocks, sourceText }) {
164
+ const value = extractJsonObject(raw)
165
+ if (value === undefined) return []
116
166
  const byId = new Map((Array.isArray(todos) ? todos : []).map((todo) => [todo.id, todo]))
117
167
  const blockList = Array.isArray(blocks) ? blocks : []
118
168
  const results = []
@@ -416,7 +466,7 @@ export function createTodoWatchService(options) {
416
466
  ]
417
467
  if (candidates.length === 0) {
418
468
  return {
419
- text: `${header.join('\n')}\n\n本次没有待核验的 TODO。直接返回 {"results":[]},不要调用工具。`,
469
+ text: `${header.join('\n')}\n\n本次没有待核验的 TODO。直接返回 {"brief":{"headline":"核验完成:本次无候选","plain":"本次没有待核验的 TODO,核验任务按计划结束。"},"results":[]},不要调用工具。`,
420
470
  candidates: [],
421
471
  empty: true,
422
472
  }
@@ -427,8 +477,11 @@ export function createTodoWatchService(options) {
427
477
  `候选 TODO(共 ${candidates.length} 条,必须逐条返回):`,
428
478
  JSON.stringify(candidates.map(candidatePayload), null, 2),
429
479
  '输出要求:先写一句本次核验摘要,再输出一个 ```json 代码块:',
430
- '{"results":[{"id":"候选 id","verdict":"triggered|not_triggered|insufficient","confidence":"high|medium|low","evidence":"工具结果中的原文片段","source":"来源 + as-of"}]}',
431
- 'triggered / not_triggered 必须有可核验的工具原文;缺数据、只见到媒体转述、口径不一致或条件有歧义一律 insufficient。',
480
+ '{"brief":{"headline":"≤24 字","plain":"40–200 字:先写触发了什么,再写核实线索(数据/公告、关键数值、截至时间)"},"results":[{"id":"候选 id","verdict":"triggered|not_triggered|insufficient","confidence":"high|medium|low","evidence":"给用户看的核验依据:结论 + 关键数字,≤120 字","source":"人类可读的来源与口径,如「Wind 日线,截至 11-12 收盘」,≤60 字"}]}',
481
+ 'triggered / not_triggered 必须能在工具结果中找到依据;缺数据、只见到媒体转述、口径不一致或条件有歧义一律 insufficient。',
482
+ 'evidence 与 source 会原样展示在 TODO 卡片:不要出现内部 ID(data_ds_…、ds_…、art_code)、工具或能力名(wind_stock_kline、fuyao_history、index_quote 等)、采集字段(captured_at、quote_time、as-of、sourceId)、Markdown 或反引号;不要贴工具原文或「来源:」引用块。数据口径用中文写,如「截至 11-12 收盘」;source 没有可读来源就留空。',
483
+ 'JSON 必须严格合法:不要尾逗号、注释或省略引号;每条候选都要用候选 id 返回一次。',
484
+ 'brief 只写已触发的条目与线索,没有触发就直说;不要写 Markdown、链接或表情,也不要给买卖建议;同样不要写工具名、ID 或 as-of。',
432
485
  ].join('\n'),
433
486
  candidates: candidates.map(candidatePayload),
434
487
  empty: false,
@@ -439,6 +492,7 @@ export function createTodoWatchService(options) {
439
492
  if (!owner()) return
440
493
  const { run, task, text, toolText } = payload
441
494
  if (typeof text !== 'string' || text.trim().length === 0) return
495
+ const authoredBrief = parseVerifierBrief(text)
442
496
  await syncInternal()
443
497
  const all = await store.listTodoWatches()
444
498
  const acks = await store.listTodoAcks()
@@ -452,7 +506,7 @@ export function createTodoWatchService(options) {
452
506
  .sort((left, right) => String(left.todoId).localeCompare(String(right.todoId)))
453
507
  if (candidates.length === 0) {
454
508
  await notifyPendingInternal()
455
- return
509
+ return { checked: 0, triggered: [], notTriggered: 0, needsHuman: 0, expired: 0, ...(authoredBrief === undefined ? {} : { brief: authoredBrief }) }
456
510
  }
457
511
  // Subagents keep their raw tool output in child sessions; the main answer is the compiled
458
512
  // evidence record. Accept either source rather than rejecting every delegated lookup.
@@ -462,11 +516,15 @@ export function createTodoWatchService(options) {
462
516
  const blocks = sourceBlocksOf(evidenceText, Number.POSITIVE_INFINITY)
463
517
  const todos = candidates.map(candidatePayload)
464
518
  const results = parseWatchOutput(text, { todos, blocks, sourceText: evidenceText })
519
+ if (results.length === 0 && /"results"\s*:/.test(text)) {
520
+ logger?.warn?.('capital-automation: 核验结果解析为空,候选按数据不足处理')
521
+ }
465
522
  const resultById = new Map(results.map((result) => [result.id, result]))
466
523
  const today = localPartsAt(now(), timeZone).date
467
524
  const currentById = new Map((await store.listTodoWatches()).map((watch) => [watch.todoId, watch]))
468
525
  const decisionByIdAtApply = new Map((await store.listTodoAcks()).map((ack) => [ack.todoId, ack]))
469
526
  const at = iso(now())
527
+ const summary = { checked: 0, triggered: [], notTriggered: 0, needsHuman: 0, expired: 0 }
470
528
  for (const candidate of candidates) {
471
529
  const current = currentById.get(candidate.todoId)
472
530
  if (current === undefined) continue
@@ -526,8 +584,23 @@ export function createTodoWatchService(options) {
526
584
  else next.source = result.source
527
585
  if (handoffReason === undefined) delete next.handoffReason
528
586
  await store.putTodoWatch(next)
587
+ summary.checked += 1
588
+ if (status === 'triggered') {
589
+ summary.triggered.push({
590
+ title: current.title,
591
+ ...(current.symbol === undefined ? {} : { symbol: current.symbol }),
592
+ ...(result?.evidence === undefined ? {} : { evidence: result.evidence }),
593
+ })
594
+ } else if (status === 'watching') {
595
+ summary.notTriggered += 1
596
+ } else if (status === 'needs_human') {
597
+ summary.needsHuman += 1
598
+ } else if (status === 'expired') {
599
+ summary.expired += 1
600
+ }
529
601
  }
530
602
  await notifyPendingInternal()
603
+ return { ...summary, ...(authoredBrief === undefined ? {} : { brief: authoredBrief }) }
531
604
  }
532
605
 
533
606
  async function onFinalAnswer(payload) {
@@ -543,7 +616,7 @@ export function createTodoWatchService(options) {
543
616
  if (typeof readAnswer !== 'function' || typeof payload.run.sessionId !== 'string') return
544
617
  try {
545
618
  const answer = await readAnswer(payload.run.sessionId)
546
- await onFinalAnswer({ ...payload, text: answer.text, toolText: answer.toolText })
619
+ return onFinalAnswer({ ...payload, text: answer.text, toolText: answer.toolText })
547
620
  } catch (error) {
548
621
  logger?.warn?.(`capital-automation: TODO 核验读取 session 失败:${errorText(error)}`)
549
622
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-charts",
3
- "version": "2.21.0",
3
+ "version": "2.21.2",
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.0",
3
+ "version": "2.21.2",
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.0";
6
+ export declare const LOCAL_FETCH_CLIENT_VERSION = "2.21.2";
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.0';
7
+ export const LOCAL_FETCH_CLIENT_VERSION = '2.21.2';
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.0";
38
+ export declare const WIND_CLIENT_VERSION = "2.21.2";
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.0';
22
+ export const WIND_CLIENT_VERSION = '2.21.2';
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.0",
3
+ "version": "2.21.2",
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.0",
3
+ "version": "2.21.2",
4
4
  "description": "自动模式的用户自选股(宿主级清单 + Fuyao 报价快照 + /capital-watchlist 路由 + 输入框菜单弹窗):由 @v587d/capital-generation 随包携带并作为 host 平面行挂载。",
5
5
  "license": "MIT",
6
6
  "type": "module",