@v587d/capital-generation 2.21.0 → 2.21.1

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,10 @@ 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"}]}',
480
+ '{"brief":{"headline":"≤24 字","plain":"40–200 字:先写触发了什么,再写核实线索(数据/公告、关键数值、as-of)"},"results":[{"id":"候选 id","verdict":"triggered|not_triggered|insufficient","confidence":"high|medium|low","evidence":"工具结果中的原文片段","source":"来源 + as-of"}]}',
431
481
  'triggered / not_triggered 必须有可核验的工具原文;缺数据、只见到媒体转述、口径不一致或条件有歧义一律 insufficient。',
482
+ 'JSON 必须严格合法:不要尾逗号、注释或省略引号;每条候选都要用候选 id 返回一次。',
483
+ 'brief 只写已触发的条目与线索,没有触发就直说;不要写 Markdown、链接或表情,也不要给买卖建议。',
432
484
  ].join('\n'),
433
485
  candidates: candidates.map(candidatePayload),
434
486
  empty: false,
@@ -439,6 +491,7 @@ export function createTodoWatchService(options) {
439
491
  if (!owner()) return
440
492
  const { run, task, text, toolText } = payload
441
493
  if (typeof text !== 'string' || text.trim().length === 0) return
494
+ const authoredBrief = parseVerifierBrief(text)
442
495
  await syncInternal()
443
496
  const all = await store.listTodoWatches()
444
497
  const acks = await store.listTodoAcks()
@@ -452,7 +505,7 @@ export function createTodoWatchService(options) {
452
505
  .sort((left, right) => String(left.todoId).localeCompare(String(right.todoId)))
453
506
  if (candidates.length === 0) {
454
507
  await notifyPendingInternal()
455
- return
508
+ return { checked: 0, triggered: [], notTriggered: 0, needsHuman: 0, expired: 0, ...(authoredBrief === undefined ? {} : { brief: authoredBrief }) }
456
509
  }
457
510
  // Subagents keep their raw tool output in child sessions; the main answer is the compiled
458
511
  // evidence record. Accept either source rather than rejecting every delegated lookup.
@@ -462,11 +515,15 @@ export function createTodoWatchService(options) {
462
515
  const blocks = sourceBlocksOf(evidenceText, Number.POSITIVE_INFINITY)
463
516
  const todos = candidates.map(candidatePayload)
464
517
  const results = parseWatchOutput(text, { todos, blocks, sourceText: evidenceText })
518
+ if (results.length === 0 && /"results"\s*:/.test(text)) {
519
+ logger?.warn?.('capital-automation: 核验结果解析为空,候选按数据不足处理')
520
+ }
465
521
  const resultById = new Map(results.map((result) => [result.id, result]))
466
522
  const today = localPartsAt(now(), timeZone).date
467
523
  const currentById = new Map((await store.listTodoWatches()).map((watch) => [watch.todoId, watch]))
468
524
  const decisionByIdAtApply = new Map((await store.listTodoAcks()).map((ack) => [ack.todoId, ack]))
469
525
  const at = iso(now())
526
+ const summary = { checked: 0, triggered: [], notTriggered: 0, needsHuman: 0, expired: 0 }
470
527
  for (const candidate of candidates) {
471
528
  const current = currentById.get(candidate.todoId)
472
529
  if (current === undefined) continue
@@ -526,8 +583,23 @@ export function createTodoWatchService(options) {
526
583
  else next.source = result.source
527
584
  if (handoffReason === undefined) delete next.handoffReason
528
585
  await store.putTodoWatch(next)
586
+ summary.checked += 1
587
+ if (status === 'triggered') {
588
+ summary.triggered.push({
589
+ title: current.title,
590
+ ...(current.symbol === undefined ? {} : { symbol: current.symbol }),
591
+ ...(result?.evidence === undefined ? {} : { evidence: result.evidence }),
592
+ })
593
+ } else if (status === 'watching') {
594
+ summary.notTriggered += 1
595
+ } else if (status === 'needs_human') {
596
+ summary.needsHuman += 1
597
+ } else if (status === 'expired') {
598
+ summary.expired += 1
599
+ }
529
600
  }
530
601
  await notifyPendingInternal()
602
+ return { ...summary, ...(authoredBrief === undefined ? {} : { brief: authoredBrief }) }
531
603
  }
532
604
 
533
605
  async function onFinalAnswer(payload) {
@@ -543,7 +615,7 @@ export function createTodoWatchService(options) {
543
615
  if (typeof readAnswer !== 'function' || typeof payload.run.sessionId !== 'string') return
544
616
  try {
545
617
  const answer = await readAnswer(payload.run.sessionId)
546
- await onFinalAnswer({ ...payload, text: answer.text, toolText: answer.toolText })
618
+ return onFinalAnswer({ ...payload, text: answer.text, toolText: answer.toolText })
547
619
  } catch (error) {
548
620
  logger?.warn?.(`capital-automation: TODO 核验读取 session 失败:${errorText(error)}`)
549
621
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v587d/capital-charts",
3
- "version": "2.21.0",
3
+ "version": "2.21.1",
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.1",
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.1";
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.1';
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.1";
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.1';
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.1",
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.1",
4
4
  "description": "自动模式的用户自选股(宿主级清单 + Fuyao 报价快照 + /capital-watchlist 路由 + 输入框菜单弹窗):由 @v587d/capital-generation 随包携带并作为 host 平面行挂载。",
5
5
  "license": "MIT",
6
6
  "type": "module",