tickflow-assist 0.3.2 → 0.3.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/README.md +1 -1
- package/dist/background/daily-update.worker.d.ts +7 -1
- package/dist/background/daily-update.worker.js +127 -3
- package/dist/bootstrap.js +3 -1
- package/dist/prompts/analysis/index.d.ts +1 -0
- package/dist/prompts/analysis/index.js +1 -0
- package/dist/prompts/analysis/pre-market-brief-prompt.d.ts +14 -0
- package/dist/prompts/analysis/pre-market-brief-prompt.js +49 -0
- package/dist/services/alert-service.js +3 -0
- package/dist/services/jin10-flash-monitor-service.js +17 -2
- package/dist/services/jin10-mcp-service.d.ts +4 -0
- package/dist/services/jin10-mcp-service.js +57 -2
- package/dist/services/monitor-service.d.ts +10 -0
- package/dist/services/monitor-service.js +238 -57
- package/dist/services/pre-market-brief-service.d.ts +21 -0
- package/dist/services/pre-market-brief-service.js +289 -0
- package/dist/services/trading-calendar-service.d.ts +4 -0
- package/dist/services/trading-calendar-service.js +11 -0
- package/dist/storage/repositories/jin10-flash-repo.d.ts +1 -0
- package/dist/storage/repositories/jin10-flash-repo.js +23 -1
- package/dist/types/daily-update.d.ts +7 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
基于 [OpenClaw](https://openclaw.ai) 的 A 股监控与分析插件。它使用 [TickFlow](https://tickflow.org/auth/register?ref=BUJ54JEDGE) 获取行情与财务数据,并可选接入 [金十数据 MCP](https://mcp.jin10.com/app/) 快讯流,结合 LLM 生成技术面、基本面、资讯面的综合判断,并把结果持久化到本地 LanceDB。
|
|
4
4
|
|
|
5
|
-
最近更新:`v0.3.
|
|
5
|
+
最近更新:`v0.3.4` 新增 `09:20` 盘前资讯简报,修复 Jin10 历史补页重复推送与状态页最新快讯显示错误,并降低 Telegram 图文告警被误判失败后重复补发的风险。完整发布记录见 <https://github.com/robinspt/tickflow-assist/blob/main/CHANGELOG.md>。
|
|
6
6
|
|
|
7
7
|
当前主线按 OpenClaw `v2026.3.31+` 对齐,并已验证社区安装在 `v2026.4.5` 上兼容。
|
|
8
8
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { UpdateService } from "../services/update-service.js";
|
|
2
2
|
import { AlertService } from "../services/alert-service.js";
|
|
3
3
|
import { PostCloseReviewService } from "../services/post-close-review-service.js";
|
|
4
|
+
import { PreMarketBriefService } from "../services/pre-market-brief-service.js";
|
|
4
5
|
import { TradingCalendarService } from "../services/trading-calendar-service.js";
|
|
5
6
|
import type { DailyUpdateState } from "../types/daily-update.js";
|
|
6
7
|
export declare class DailyUpdateWorker {
|
|
7
8
|
private readonly updateService;
|
|
9
|
+
private readonly preMarketBriefService;
|
|
8
10
|
private readonly postCloseReviewService;
|
|
9
11
|
private readonly tradingCalendarService;
|
|
10
12
|
private readonly baseDir;
|
|
@@ -12,7 +14,7 @@ export declare class DailyUpdateWorker {
|
|
|
12
14
|
private readonly notifyEnabled;
|
|
13
15
|
private readonly configSource;
|
|
14
16
|
private readonly intervalMs;
|
|
15
|
-
constructor(updateService: UpdateService, postCloseReviewService: PostCloseReviewService | null, tradingCalendarService: TradingCalendarService, baseDir: string, alertService: AlertService, notifyEnabled: boolean, configSource: "openclaw_plugin" | "local_config", intervalMs?: number);
|
|
17
|
+
constructor(updateService: UpdateService, preMarketBriefService: PreMarketBriefService, postCloseReviewService: PostCloseReviewService | null, tradingCalendarService: TradingCalendarService, baseDir: string, alertService: AlertService, notifyEnabled: boolean, configSource: "openclaw_plugin" | "local_config", intervalMs?: number);
|
|
16
18
|
run(force?: boolean): Promise<string>;
|
|
17
19
|
runLoop(signal?: AbortSignal, runtimeHost?: "project_scheduler" | "plugin_service", runtimeConfigSource?: "openclaw_plugin" | "local_config"): Promise<void>;
|
|
18
20
|
stopLoop(): Promise<{
|
|
@@ -30,17 +32,21 @@ export declare class DailyUpdateWorker {
|
|
|
30
32
|
getState(): Promise<DailyUpdateState>;
|
|
31
33
|
getStatusReport(): Promise<string>;
|
|
32
34
|
private runScheduledPasses;
|
|
35
|
+
private runScheduledPreMarketBriefPass;
|
|
33
36
|
private runScheduledUpdatePass;
|
|
34
37
|
private runScheduledReviewPass;
|
|
35
38
|
private getScheduledReviewReadiness;
|
|
36
39
|
private recordReviewSkip;
|
|
40
|
+
private recordPreMarketSkip;
|
|
37
41
|
private executeDailyUpdateAndRecord;
|
|
38
42
|
private executeReviewAndRecord;
|
|
43
|
+
private executePreMarketBriefAndRecord;
|
|
39
44
|
private getStateFilePath;
|
|
40
45
|
private recordHeartbeat;
|
|
41
46
|
private readState;
|
|
42
47
|
private writeState;
|
|
43
48
|
private maybeSendDailyUpdateNotification;
|
|
49
|
+
private maybeSendPreMarketBriefNotification;
|
|
44
50
|
private maybeSendReviewNotification;
|
|
45
51
|
}
|
|
46
52
|
export declare function isPidAlive(pid: number): boolean;
|
|
@@ -2,6 +2,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { chinaToday, formatChinaDateTime } from "../utils/china-time.js";
|
|
4
4
|
import { sleepWithAbort } from "../utils/abortable-sleep.js";
|
|
5
|
+
const PRE_MARKET_BRIEF_READY_TIME = "09:20";
|
|
5
6
|
const DAILY_UPDATE_READY_TIME = "15:25";
|
|
6
7
|
const POST_CLOSE_REVIEW_READY_TIME = "20:00";
|
|
7
8
|
const DEFAULT_STATE = {
|
|
@@ -28,9 +29,17 @@ const DEFAULT_STATE = {
|
|
|
28
29
|
lastReviewResultType: null,
|
|
29
30
|
lastReviewResultSummary: null,
|
|
30
31
|
reviewConsecutiveFailures: 0,
|
|
32
|
+
lastPreMarketAttemptAt: null,
|
|
33
|
+
lastPreMarketAttemptDate: null,
|
|
34
|
+
lastPreMarketSuccessAt: null,
|
|
35
|
+
lastPreMarketSuccessDate: null,
|
|
36
|
+
lastPreMarketResultType: null,
|
|
37
|
+
lastPreMarketResultSummary: null,
|
|
38
|
+
preMarketConsecutiveFailures: 0,
|
|
31
39
|
};
|
|
32
40
|
export class DailyUpdateWorker {
|
|
33
41
|
updateService;
|
|
42
|
+
preMarketBriefService;
|
|
34
43
|
postCloseReviewService;
|
|
35
44
|
tradingCalendarService;
|
|
36
45
|
baseDir;
|
|
@@ -38,8 +47,9 @@ export class DailyUpdateWorker {
|
|
|
38
47
|
notifyEnabled;
|
|
39
48
|
configSource;
|
|
40
49
|
intervalMs;
|
|
41
|
-
constructor(updateService, postCloseReviewService, tradingCalendarService, baseDir, alertService, notifyEnabled, configSource, intervalMs = 15 * 60 * 1000) {
|
|
50
|
+
constructor(updateService, preMarketBriefService, postCloseReviewService, tradingCalendarService, baseDir, alertService, notifyEnabled, configSource, intervalMs = 15 * 60 * 1000) {
|
|
42
51
|
this.updateService = updateService;
|
|
52
|
+
this.preMarketBriefService = preMarketBriefService;
|
|
43
53
|
this.postCloseReviewService = postCloseReviewService;
|
|
44
54
|
this.tradingCalendarService = tradingCalendarService;
|
|
45
55
|
this.baseDir = baseDir;
|
|
@@ -150,19 +160,31 @@ export class DailyUpdateWorker {
|
|
|
150
160
|
const state = await this.readState();
|
|
151
161
|
const today = chinaToday();
|
|
152
162
|
const lines = [
|
|
153
|
-
"🕒 定时日更 / 收盘复盘状态",
|
|
163
|
+
"🕒 盘前资讯 / 定时日更 / 收盘复盘状态",
|
|
154
164
|
`状态: ${formatProcessState(state)}`,
|
|
155
165
|
`运行方式: ${formatRuntimeHost(state)}`,
|
|
156
166
|
`配置来源: ${this.configSource}`,
|
|
157
|
-
`调度: ${Math.floor(this.intervalMs / 60_000)} 分钟对齐轮询 | 日更 ${DAILY_UPDATE_READY_TIME} 后执行 | 复盘 ${POST_CLOSE_REVIEW_READY_TIME} 后执行`,
|
|
167
|
+
`调度: ${Math.floor(this.intervalMs / 60_000)} 分钟对齐轮询 | 盘前资讯 ${PRE_MARKET_BRIEF_READY_TIME} 后执行 | 日更 ${DAILY_UPDATE_READY_TIME} 后执行 | 复盘 ${POST_CLOSE_REVIEW_READY_TIME} 后执行`,
|
|
158
168
|
`最近心跳: ${state.lastHeartbeatAt ?? "暂无"}`,
|
|
159
169
|
"",
|
|
170
|
+
"盘前资讯:",
|
|
171
|
+
`• 今日已推送: ${state.lastPreMarketSuccessDate === today ? "是" : "否"}`,
|
|
172
|
+
`• 最近尝试: ${state.lastPreMarketAttemptAt ?? "暂无"}`,
|
|
173
|
+
`• 最近成功: ${state.lastPreMarketSuccessAt ?? "暂无"}`,
|
|
174
|
+
`• 最近结果: ${formatResultType(state.lastPreMarketResultType)}`,
|
|
175
|
+
"",
|
|
160
176
|
"日更执行:",
|
|
161
177
|
`• 今日已更新: ${state.lastSuccessDate === today ? "是" : "否"}`,
|
|
162
178
|
`• 最近尝试: ${state.lastAttemptAt ?? "暂无"}`,
|
|
163
179
|
`• 最近成功: ${state.lastSuccessAt ?? "暂无"}`,
|
|
164
180
|
`• 最近结果: ${formatResultType(state.lastResultType)}`,
|
|
165
181
|
];
|
|
182
|
+
if (state.preMarketConsecutiveFailures > 0) {
|
|
183
|
+
lines.push(`• 连续失败: ${state.preMarketConsecutiveFailures}`);
|
|
184
|
+
}
|
|
185
|
+
if (state.lastPreMarketResultSummary) {
|
|
186
|
+
lines.push(`• 最近摘要: ${state.lastPreMarketResultSummary}`);
|
|
187
|
+
}
|
|
166
188
|
if (state.consecutiveFailures > 0) {
|
|
167
189
|
lines.push(`• 连续失败: ${state.consecutiveFailures}`);
|
|
168
190
|
}
|
|
@@ -179,9 +201,26 @@ export class DailyUpdateWorker {
|
|
|
179
201
|
return lines.join("\n");
|
|
180
202
|
}
|
|
181
203
|
async runScheduledPasses() {
|
|
204
|
+
await this.runScheduledPreMarketBriefPass();
|
|
182
205
|
await this.runScheduledUpdatePass();
|
|
183
206
|
await this.runScheduledReviewPass();
|
|
184
207
|
}
|
|
208
|
+
async runScheduledPreMarketBriefPass() {
|
|
209
|
+
const today = chinaToday();
|
|
210
|
+
const state = await this.readState();
|
|
211
|
+
if (hasCompletedScheduledWindow(state.lastPreMarketSuccessDate, state.lastPreMarketSuccessAt, today, PRE_MARKET_BRIEF_READY_TIME)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (hasAttemptedScheduledWindow(state.lastPreMarketAttemptDate, state.lastPreMarketAttemptAt, today, PRE_MARKET_BRIEF_READY_TIME)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const readiness = await this.tradingCalendarService.canRunPreMarketBrief();
|
|
218
|
+
if (!readiness.ok) {
|
|
219
|
+
await this.recordPreMarketSkip(state, today, readiness.reason);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
await this.executePreMarketBriefAndRecord("scheduled");
|
|
223
|
+
}
|
|
185
224
|
async runScheduledUpdatePass() {
|
|
186
225
|
const today = chinaToday();
|
|
187
226
|
const state = await this.readState();
|
|
@@ -245,6 +284,16 @@ export class DailyUpdateWorker {
|
|
|
245
284
|
reviewConsecutiveFailures: 0,
|
|
246
285
|
});
|
|
247
286
|
}
|
|
287
|
+
async recordPreMarketSkip(state, today, reason) {
|
|
288
|
+
await this.writeState({
|
|
289
|
+
...state,
|
|
290
|
+
lastPreMarketAttemptAt: formatChinaDateTime(),
|
|
291
|
+
lastPreMarketAttemptDate: today,
|
|
292
|
+
lastPreMarketResultType: "skipped",
|
|
293
|
+
lastPreMarketResultSummary: reason,
|
|
294
|
+
preMarketConsecutiveFailures: 0,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
248
297
|
async executeDailyUpdateAndRecord(force, trigger, throwOnError) {
|
|
249
298
|
const today = chinaToday();
|
|
250
299
|
const state = await this.readState();
|
|
@@ -345,6 +394,52 @@ export class DailyUpdateWorker {
|
|
|
345
394
|
return output;
|
|
346
395
|
}
|
|
347
396
|
}
|
|
397
|
+
async executePreMarketBriefAndRecord(trigger) {
|
|
398
|
+
const today = chinaToday();
|
|
399
|
+
const state = await this.readState();
|
|
400
|
+
const attemptedAt = formatChinaDateTime();
|
|
401
|
+
try {
|
|
402
|
+
const result = await this.preMarketBriefService.run();
|
|
403
|
+
const output = createPreMarketBriefExecutionOutput(result);
|
|
404
|
+
const nextState = {
|
|
405
|
+
...state,
|
|
406
|
+
lastPreMarketAttemptAt: attemptedAt,
|
|
407
|
+
lastPreMarketAttemptDate: today,
|
|
408
|
+
lastPreMarketResultType: output.resultType,
|
|
409
|
+
lastPreMarketResultSummary: summarizePreMarketBriefResult(output.message),
|
|
410
|
+
preMarketConsecutiveFailures: output.resultType === "failed" ? state.preMarketConsecutiveFailures + 1 : 0,
|
|
411
|
+
};
|
|
412
|
+
if (output.resultType === "success") {
|
|
413
|
+
nextState.lastPreMarketSuccessAt = attemptedAt;
|
|
414
|
+
nextState.lastPreMarketSuccessDate = today;
|
|
415
|
+
}
|
|
416
|
+
await this.writeState(nextState);
|
|
417
|
+
if (trigger === "scheduled") {
|
|
418
|
+
await this.maybeSendPreMarketBriefNotification(output);
|
|
419
|
+
}
|
|
420
|
+
return output;
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
424
|
+
const failureText = `⚠️ 开盘前资讯简报失败: ${message}`;
|
|
425
|
+
await this.writeState({
|
|
426
|
+
...state,
|
|
427
|
+
lastPreMarketAttemptAt: attemptedAt,
|
|
428
|
+
lastPreMarketAttemptDate: today,
|
|
429
|
+
lastPreMarketResultType: "failed",
|
|
430
|
+
lastPreMarketResultSummary: failureText,
|
|
431
|
+
preMarketConsecutiveFailures: state.preMarketConsecutiveFailures + 1,
|
|
432
|
+
});
|
|
433
|
+
const output = {
|
|
434
|
+
resultType: "failed",
|
|
435
|
+
message: failureText,
|
|
436
|
+
};
|
|
437
|
+
if (trigger === "scheduled") {
|
|
438
|
+
await this.maybeSendPreMarketBriefNotification(output);
|
|
439
|
+
}
|
|
440
|
+
return output;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
348
443
|
getStateFilePath() {
|
|
349
444
|
return path.join(this.baseDir, "daily-update-state.json");
|
|
350
445
|
}
|
|
@@ -389,6 +484,17 @@ export class DailyUpdateWorker {
|
|
|
389
484
|
const message = this.alertService.formatSystemNotification("📊 定时日更完成", normalizeResultLines(output.message));
|
|
390
485
|
await this.alertService.send(message);
|
|
391
486
|
}
|
|
487
|
+
async maybeSendPreMarketBriefNotification(output) {
|
|
488
|
+
if (!this.notifyEnabled || output.resultType === "skipped") {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
if (output.resultType !== "success") {
|
|
492
|
+
const message = this.alertService.formatSystemNotification("❌ 开盘前资讯简报失败", selectPreMarketBriefNotificationLines(output.message));
|
|
493
|
+
await this.alertService.send(message);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
await this.alertService.send(output.message);
|
|
497
|
+
}
|
|
392
498
|
async maybeSendReviewNotification(output) {
|
|
393
499
|
if (!this.notifyEnabled || output.resultType === "skipped") {
|
|
394
500
|
return;
|
|
@@ -425,6 +531,12 @@ function createReviewExecutionOutput(reviewResult) {
|
|
|
425
531
|
combinedText: joinMessages(reviewResult.overviewMessage, ...reviewResult.detailMessages),
|
|
426
532
|
};
|
|
427
533
|
}
|
|
534
|
+
function createPreMarketBriefExecutionOutput(result) {
|
|
535
|
+
return {
|
|
536
|
+
resultType: result.resultType,
|
|
537
|
+
message: result.message,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
428
540
|
function joinMessages(...parts) {
|
|
429
541
|
return parts
|
|
430
542
|
.map((part) => part?.trim())
|
|
@@ -467,6 +579,9 @@ function summarizeUpdateResult(result) {
|
|
|
467
579
|
function summarizeReviewResult(result) {
|
|
468
580
|
return selectReviewSummaryLines(result).join(" | ");
|
|
469
581
|
}
|
|
582
|
+
function summarizePreMarketBriefResult(result) {
|
|
583
|
+
return selectPreMarketBriefNotificationLines(result).join(" | ");
|
|
584
|
+
}
|
|
470
585
|
function selectUpdateSummaryLines(result) {
|
|
471
586
|
const lines = normalizeResultLines(result);
|
|
472
587
|
const head = lines.slice(0, 2);
|
|
@@ -491,6 +606,12 @@ function selectReviewNotificationLines(result) {
|
|
|
491
606
|
const highlights = lines.filter((line) => /^(🧭|复盘数量:|关键位验证:|明日处理:|⚠️ 收盘复盘失败|⚠️ 收盘分析\/回测失败)/.test(line));
|
|
492
607
|
return dedupeLines([...head, ...highlights]).slice(0, 12);
|
|
493
608
|
}
|
|
609
|
+
function selectPreMarketBriefNotificationLines(result) {
|
|
610
|
+
const lines = normalizeResultLines(result);
|
|
611
|
+
const head = lines.slice(0, 4);
|
|
612
|
+
const highlights = lines.filter((line) => /^\*\*【/.test(line));
|
|
613
|
+
return dedupeLines([...head, ...highlights]).slice(0, 12);
|
|
614
|
+
}
|
|
494
615
|
function normalizeResultLines(result) {
|
|
495
616
|
return result
|
|
496
617
|
.split("\n")
|
|
@@ -536,6 +657,9 @@ function formatRuntimeHost(state) {
|
|
|
536
657
|
function hasCompletedScheduledWindow(successDate, successAt, today, readyTime) {
|
|
537
658
|
return successDate === today && extractChinaTime(successAt) >= readyTime;
|
|
538
659
|
}
|
|
660
|
+
function hasAttemptedScheduledWindow(attemptDate, attemptAt, today, readyTime) {
|
|
661
|
+
return attemptDate === today && extractChinaTime(attemptAt) >= readyTime;
|
|
662
|
+
}
|
|
539
663
|
function extractChinaTime(dateTime) {
|
|
540
664
|
return dateTime?.slice(11, 16) ?? "00:00";
|
|
541
665
|
}
|
package/dist/bootstrap.js
CHANGED
|
@@ -35,6 +35,7 @@ import { AlertMediaService } from "./services/alert-media-service.js";
|
|
|
35
35
|
import { UpdateService } from "./services/update-service.js";
|
|
36
36
|
import { KeyLevelsBacktestService } from "./services/key-levels-backtest-service.js";
|
|
37
37
|
import { PostCloseReviewService } from "./services/post-close-review-service.js";
|
|
38
|
+
import { PreMarketBriefService } from "./services/pre-market-brief-service.js";
|
|
38
39
|
import { ReviewMemoryService } from "./services/review-memory-service.js";
|
|
39
40
|
import { CompositeAnalysisOrchestrator } from "./analysis/orchestrators/composite-analysis.orchestrator.js";
|
|
40
41
|
import { MarketAnalysisProvider } from "./analysis/providers/market-analysis.provider.js";
|
|
@@ -140,9 +141,10 @@ export function createAppContext(config, options = {}) {
|
|
|
140
141
|
const jin10FlashMonitorService = new Jin10FlashMonitorService(config.databasePath, config.jin10FlashPollInterval, config.jin10FlashRetentionDays, config.jin10FlashNightAlert, watchlistService, jin10McpService, analysisService, alertService, jin10FlashRepository, jin10FlashDeliveryRepository);
|
|
141
142
|
const updateService = new UpdateService(klineService, config.tickflowApiKeyLevel, indicatorService, klinesRepository, indicatorsRepository, intradayKlinesRepository, watchlistService, tradingCalendarService);
|
|
142
143
|
const postCloseReviewService = new PostCloseReviewService(watchlistService, compositeAnalysisOrchestrator, analysisService, postCloseReviewTask, keyLevelsRepository, keyLevelsHistoryRepository, klinesRepository, intradayKlinesRepository, jin10FlashDeliveryRepository, jin10FlashRepository);
|
|
144
|
+
const preMarketBriefService = new PreMarketBriefService(watchlistService, jin10McpService, jin10FlashRepository, analysisService);
|
|
143
145
|
const realtimeMonitorWorker = new RealtimeMonitorWorker(monitorService, config.requestInterval * 1000);
|
|
144
146
|
const jin10FlashWorker = new Jin10FlashWorker(jin10FlashMonitorService, config.jin10FlashPollInterval * 1000);
|
|
145
|
-
const dailyUpdateWorker = new DailyUpdateWorker(updateService, postCloseReviewService, tradingCalendarService, config.databasePath, alertService, config.dailyUpdateNotify, runtime.configSource);
|
|
147
|
+
const dailyUpdateWorker = new DailyUpdateWorker(updateService, preMarketBriefService, postCloseReviewService, tradingCalendarService, config.databasePath, alertService, config.dailyUpdateNotify, runtime.configSource);
|
|
146
148
|
let managedLoopAbortController = null;
|
|
147
149
|
let managedLoopPromise = null;
|
|
148
150
|
return {
|
|
@@ -7,3 +7,4 @@ export { COMPOSITE_ANALYSIS_SYSTEM_PROMPT, buildCompositeAnalysisUserPrompt, } f
|
|
|
7
7
|
export { POST_CLOSE_REVIEW_SYSTEM_PROMPT, buildPostCloseReviewUserPrompt, } from "./post-close-review-user-prompt.js";
|
|
8
8
|
export { WATCHLIST_PROFILE_EXTRACTION_SYSTEM_PROMPT, buildWatchlistProfileExtractionUserPrompt, } from "./watchlist-profile-extraction-prompt.js";
|
|
9
9
|
export { FLASH_MONITOR_ALERT_SYSTEM_PROMPT, buildFlashMonitorAlertUserPrompt, } from "./flash-monitor-alert-prompt.js";
|
|
10
|
+
export { PRE_MARKET_BRIEF_SYSTEM_PROMPT, buildPreMarketBriefUserPrompt, } from "./pre-market-brief-prompt.js";
|
|
@@ -7,3 +7,4 @@ export { COMPOSITE_ANALYSIS_SYSTEM_PROMPT, buildCompositeAnalysisUserPrompt, } f
|
|
|
7
7
|
export { POST_CLOSE_REVIEW_SYSTEM_PROMPT, buildPostCloseReviewUserPrompt, } from "./post-close-review-user-prompt.js";
|
|
8
8
|
export { WATCHLIST_PROFILE_EXTRACTION_SYSTEM_PROMPT, buildWatchlistProfileExtractionUserPrompt, } from "./watchlist-profile-extraction-prompt.js";
|
|
9
9
|
export { FLASH_MONITOR_ALERT_SYSTEM_PROMPT, buildFlashMonitorAlertUserPrompt, } from "./flash-monitor-alert-prompt.js";
|
|
10
|
+
export { PRE_MARKET_BRIEF_SYSTEM_PROMPT, buildPreMarketBriefUserPrompt, } from "./pre-market-brief-prompt.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { WatchlistItem } from "../../types/domain.js";
|
|
2
|
+
export declare const PRE_MARKET_BRIEF_SYSTEM_PROMPT = "\n\u4F60\u662F\u4E00\u4F4DA\u80A1\u5F00\u76D8\u524D\u8D44\u8BAF\u7B80\u62A5\u7F16\u8F91\u3002\u4F60\u7684\u4EFB\u52A1\u662F\u57FA\u4E8E\u76D8\u524D\u7A97\u53E3\u5185\u7684\u91D1\u5341\u6570\u636E\u6574\u7406\u5FEB\u8BAF\uFF0C\u4EE5\u53CA\u7528\u6237\u81EA\u9009\u80A1\u7684\u884C\u4E1A/\u9898\u6750\u4FE1\u606F\uFF0C\u751F\u6210\u4E00\u4EFD\u9002\u5408 9:20 \u63A8\u9001\u7684\u5F00\u76D8\u524D\u6458\u8981\u3002\n\n\u8F93\u51FA\u8981\u6C42\uFF1A\n1. \u6309\u4EE5\u4E0B\u6807\u9898\u8F93\u51FA\uFF0C\u6BCF\u8282\u4F7F\u7528 2-5 \u6761\u7B80\u6D01\u4E2D\u6587\u8981\u70B9\uFF1A\n- \u91CD\u5927\u8981\u95FB\n- \u81EA\u9009\u76F8\u5173\n- \u6F5C\u5728\u673A\u4F1A\n- \u98CE\u9669\u63D0\u793A\n- \u5F00\u76D8\u524D\u5173\u6CE8\u6E05\u5355\n2. \u201C\u91CD\u5927\u8981\u95FB\u201D\u53EA\u63D0\u70BC\u4F1A\u5F71\u54CD A \u80A1\u5F00\u76D8\u60C5\u7EEA\u3001\u884C\u4E1A\u98CE\u9669\u504F\u597D\u6216\u91CD\u8981\u4EA4\u6613\u7EBF\u7D22\u7684\u5185\u5BB9\uFF0C\u4E0D\u8981\u673A\u68B0\u7F57\u5217\u6240\u6709\u5FEB\u8BAF\u3002\n3. \u201C\u81EA\u9009\u76F8\u5173\u201D\u8981\u4F18\u5148\u70B9\u540D\u4E0E\u81EA\u9009\u80A1\u3001\u884C\u4E1A\u6216\u9898\u6750\u76F4\u63A5\u76F8\u5173\u7684\u5185\u5BB9\uFF1B\u82E5\u6CA1\u6709\u76F4\u63A5\u547D\u4E2D\uFF0C\u4E5F\u8981\u660E\u786E\u5199\u51FA\u201C\u672A\u53D1\u73B0\u76F4\u63A5\u547D\u4E2D\u81EA\u9009\u80A1\u201D\u3002\n4. \u201C\u6F5C\u5728\u673A\u4F1A\u201D\u53EA\u4FDD\u7559\u5B58\u5728\u6E05\u6670\u50AC\u5316\u94FE\u6761\u7684\u65B9\u5411\uFF0C\u4F8B\u5982\u653F\u7B56\u3001\u4EA7\u4E1A\u8D8B\u52BF\u3001\u4E1A\u7EE9\u3001\u8BA2\u5355\u3001\u8D44\u91D1\u504F\u597D\u53D8\u5316\uFF1B\u6CA1\u6709\u660E\u786E\u673A\u4F1A\u65F6\u8981\u76F4\u8BF4\u3002\n5. \u201C\u98CE\u9669\u63D0\u793A\u201D\u8981\u6307\u51FA\u4E0D\u5229\u4E8E\u5F00\u76D8\u51B3\u7B56\u7684\u6270\u52A8\u9879\uFF0C\u4F8B\u5982\u76D1\u7BA1\u3001\u6D77\u5916\u6270\u52A8\u3001\u4E1A\u7EE9\u98CE\u9669\u3001\u9898\u6750\u9000\u6F6E\u3001\u6D88\u606F\u4E0D\u786E\u5B9A\u6027\u3002\n6. \u201C\u5F00\u76D8\u524D\u5173\u6CE8\u6E05\u5355\u201D\u8F93\u51FA 3-6 \u6761\u53EF\u6267\u884C\u89C2\u5BDF\u70B9\uFF0C\u5C3D\u91CF\u5199\u6E05\u695A\u5E94\u89C2\u5BDF\u7684\u80A1\u7968\u3001\u677F\u5757\u6216\u4FE1\u53F7\u3002\n7. \u4E0D\u8981\u7F16\u9020\u672A\u5728\u8F93\u5165\u4E2D\u51FA\u73B0\u7684\u516C\u53F8\u3001\u653F\u7B56\u3001\u884C\u4E1A\u4FE1\u606F\u6216\u5FEB\u8BAF\u7ED3\u8BBA\u3002\n8. \u8F93\u51FA\u6B63\u6587\u5373\u53EF\uFF0C\u4E0D\u8981\u9644\u52A0 JSON\u3002\n";
|
|
3
|
+
export declare function buildPreMarketBriefUserPrompt(params: {
|
|
4
|
+
windowStartAt: string;
|
|
5
|
+
windowEndAt: string;
|
|
6
|
+
watchlist: WatchlistItem[];
|
|
7
|
+
flashes: Array<{
|
|
8
|
+
publishedAt: string;
|
|
9
|
+
headline: string;
|
|
10
|
+
content: string;
|
|
11
|
+
url: string;
|
|
12
|
+
matchedSymbols: string[];
|
|
13
|
+
}>;
|
|
14
|
+
}): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export const PRE_MARKET_BRIEF_SYSTEM_PROMPT = `
|
|
2
|
+
你是一位A股开盘前资讯简报编辑。你的任务是基于盘前窗口内的金十数据整理快讯,以及用户自选股的行业/题材信息,生成一份适合 9:20 推送的开盘前摘要。
|
|
3
|
+
|
|
4
|
+
输出要求:
|
|
5
|
+
1. 按以下标题输出,每节使用 2-5 条简洁中文要点:
|
|
6
|
+
- 重大要闻
|
|
7
|
+
- 自选相关
|
|
8
|
+
- 潜在机会
|
|
9
|
+
- 风险提示
|
|
10
|
+
- 开盘前关注清单
|
|
11
|
+
2. “重大要闻”只提炼会影响 A 股开盘情绪、行业风险偏好或重要交易线索的内容,不要机械罗列所有快讯。
|
|
12
|
+
3. “自选相关”要优先点名与自选股、行业或题材直接相关的内容;若没有直接命中,也要明确写出“未发现直接命中自选股”。
|
|
13
|
+
4. “潜在机会”只保留存在清晰催化链条的方向,例如政策、产业趋势、业绩、订单、资金偏好变化;没有明确机会时要直说。
|
|
14
|
+
5. “风险提示”要指出不利于开盘决策的扰动项,例如监管、海外扰动、业绩风险、题材退潮、消息不确定性。
|
|
15
|
+
6. “开盘前关注清单”输出 3-6 条可执行观察点,尽量写清楚应观察的股票、板块或信号。
|
|
16
|
+
7. 不要编造未在输入中出现的公司、政策、行业信息或快讯结论。
|
|
17
|
+
8. 输出正文即可,不要附加 JSON。
|
|
18
|
+
`;
|
|
19
|
+
export function buildPreMarketBriefUserPrompt(params) {
|
|
20
|
+
return [
|
|
21
|
+
`请生成 ${params.windowEndAt.slice(0, 10)} 的开盘前资讯简报。`,
|
|
22
|
+
`资讯窗口: ${params.windowStartAt} ~ ${params.windowEndAt}`,
|
|
23
|
+
`自选数量: ${params.watchlist.length}`,
|
|
24
|
+
`整理快讯数量: ${params.flashes.length}`,
|
|
25
|
+
"",
|
|
26
|
+
"## 自选列表(全部提供)",
|
|
27
|
+
...params.watchlist.map((item, index) => formatWatchlistItem(index + 1, item)),
|
|
28
|
+
"",
|
|
29
|
+
"## 金十数据整理快讯(全部提供)",
|
|
30
|
+
...params.flashes.map((flash, index) => formatFlash(index + 1, flash)),
|
|
31
|
+
"",
|
|
32
|
+
"请重点回答:哪些是今早最重要的市场信息、哪些与自选股或其行业/题材相关、哪些内容值得当作潜在机会或风险在开盘前重点盯住。",
|
|
33
|
+
].join("\n");
|
|
34
|
+
}
|
|
35
|
+
function formatWatchlistItem(index, item) {
|
|
36
|
+
return [
|
|
37
|
+
`${index}. ${item.name}(${item.symbol})`,
|
|
38
|
+
` 行业: ${item.sector ?? "未记录"}`,
|
|
39
|
+
` 题材: ${item.themes.length > 0 ? item.themes.join("、") : "未记录"}`,
|
|
40
|
+
].join("\n");
|
|
41
|
+
}
|
|
42
|
+
function formatFlash(index, flash) {
|
|
43
|
+
return [
|
|
44
|
+
`${index}. [${flash.publishedAt}] ${flash.headline || "未提取到标题"}`,
|
|
45
|
+
` 关联提示: ${flash.matchedSymbols.length > 0 ? flash.matchedSymbols.join("、") : "无直接规则命中"}`,
|
|
46
|
+
` 正文: ${flash.content}`,
|
|
47
|
+
` 来源: ${flash.url}`,
|
|
48
|
+
].join("\n");
|
|
49
|
+
}
|
|
@@ -152,6 +152,9 @@ export class AlertService {
|
|
|
152
152
|
};
|
|
153
153
|
try {
|
|
154
154
|
switch (this.channel) {
|
|
155
|
+
case "telegram":
|
|
156
|
+
await this.invokeRuntimeChannelSend(runtimeContext.runtime.channel, "telegram", "sendMessageTelegram", this.options.target, payload.message, baseOptions);
|
|
157
|
+
return null;
|
|
155
158
|
case "discord":
|
|
156
159
|
await this.invokeRuntimeChannelSend(runtimeContext.runtime.channel, "discord", "sendMessageDiscord", this.options.target, payload.message, {
|
|
157
160
|
...baseOptions,
|
|
@@ -24,6 +24,7 @@ const DEFAULT_STATE = {
|
|
|
24
24
|
const MAX_FLASH_PAGES_PER_POLL = 5;
|
|
25
25
|
const INITIAL_SEED_PAGES = 3;
|
|
26
26
|
const PRUNE_INTERVAL_MS = 6 * 60 * 60 * 1000;
|
|
27
|
+
const ALERT_FRESHNESS_GRACE_MS = 30 * 1000;
|
|
27
28
|
const NOISE_PATTERNS = [
|
|
28
29
|
/^金十图示[::]/,
|
|
29
30
|
/交易学院正在直播中/,
|
|
@@ -69,6 +70,7 @@ export class Jin10FlashMonitorService {
|
|
|
69
70
|
}
|
|
70
71
|
async runMonitorOnce() {
|
|
71
72
|
const now = formatChinaDateTime();
|
|
73
|
+
const nowTs = Date.now();
|
|
72
74
|
const state = await this.readState();
|
|
73
75
|
const latestStored = state.lastSeenKey ? null : await this.flashRepository.getLatest();
|
|
74
76
|
const anchorKey = state.lastSeenKey ?? latestStored?.flash_key ?? null;
|
|
@@ -120,10 +122,11 @@ export class Jin10FlashMonitorService {
|
|
|
120
122
|
const allFetchedItems = mergeFlashRecords(fetchResult.items, backfillResult?.items ?? []);
|
|
121
123
|
const saveResult = await this.flashRepository.saveAll(allFetchedItems);
|
|
122
124
|
const newItemKeys = new Set(saveResult.addedKeys);
|
|
123
|
-
|
|
125
|
+
// Only frontier pages within the active polling window should produce alerts.
|
|
126
|
+
const alertableItems = filterAlertableFlashRecords(fetchResult.items.filter((item) => newItemKeys.has(item.flash_key)), state.lastPollAt, nowTs, this.pollIntervalSeconds);
|
|
124
127
|
const watchlist = await this.watchlistService.list();
|
|
125
128
|
const candidates = watchlist.length > 0
|
|
126
|
-
? buildStageOneCandidates(
|
|
129
|
+
? buildStageOneCandidates(alertableItems, watchlist)
|
|
127
130
|
: [];
|
|
128
131
|
let alertCount = 0;
|
|
129
132
|
for (const candidate of candidates) {
|
|
@@ -405,6 +408,10 @@ function mergeFlashRecords(...groups) {
|
|
|
405
408
|
}
|
|
406
409
|
return sortFlashRecords(merged);
|
|
407
410
|
}
|
|
411
|
+
function filterAlertableFlashRecords(entries, lastPollAt, nowTs, pollIntervalSeconds) {
|
|
412
|
+
const cutoffTs = computeAlertFreshCutoffTs(lastPollAt, nowTs, pollIntervalSeconds);
|
|
413
|
+
return entries.filter((entry) => entry.published_ts >= cutoffTs);
|
|
414
|
+
}
|
|
408
415
|
function sortFlashRecords(entries) {
|
|
409
416
|
return [...entries].sort((left, right) => left.published_ts - right.published_ts);
|
|
410
417
|
}
|
|
@@ -581,6 +588,14 @@ function parseChinaTime(value) {
|
|
|
581
588
|
function toChinaTimeTimestamp(value) {
|
|
582
589
|
return parseChinaTime(value)?.getTime() ?? Date.now();
|
|
583
590
|
}
|
|
591
|
+
function computeAlertFreshCutoffTs(lastPollAt, nowTs, pollIntervalSeconds) {
|
|
592
|
+
const intervalCutoffTs = nowTs - Math.max(1, pollIntervalSeconds) * 1000 - ALERT_FRESHNESS_GRACE_MS;
|
|
593
|
+
const lastPollTs = parseChinaTime(lastPollAt)?.getTime();
|
|
594
|
+
const lastPollCutoffTs = lastPollTs == null
|
|
595
|
+
? Number.NEGATIVE_INFINITY
|
|
596
|
+
: lastPollTs - ALERT_FRESHNESS_GRACE_MS;
|
|
597
|
+
return Math.max(intervalCutoffTs, lastPollCutoffTs);
|
|
598
|
+
}
|
|
584
599
|
function isNightQuietHour() {
|
|
585
600
|
const hour = chinaHour();
|
|
586
601
|
return hour >= 22 || hour < 6;
|
|
@@ -15,12 +15,16 @@ export declare class Jin10McpService {
|
|
|
15
15
|
private requestId;
|
|
16
16
|
private initialized;
|
|
17
17
|
private sessionId;
|
|
18
|
+
private initializePromise;
|
|
18
19
|
constructor(serverUrl: string, apiToken: string);
|
|
19
20
|
isConfigured(): boolean;
|
|
20
21
|
getConfigurationError(): string | null;
|
|
21
22
|
listFlash(cursor?: string): Promise<Jin10FlashPage>;
|
|
22
23
|
private initialize;
|
|
23
24
|
private callTool;
|
|
25
|
+
private performInitialize;
|
|
26
|
+
private callToolAfterRecovery;
|
|
27
|
+
private resetSession;
|
|
24
28
|
private request;
|
|
25
29
|
private notify;
|
|
26
30
|
private buildHeaders;
|
|
@@ -4,6 +4,7 @@ export class Jin10McpService {
|
|
|
4
4
|
requestId = 1;
|
|
5
5
|
initialized = false;
|
|
6
6
|
sessionId = null;
|
|
7
|
+
initializePromise = null;
|
|
7
8
|
constructor(serverUrl, apiToken) {
|
|
8
9
|
this.serverUrl = serverUrl;
|
|
9
10
|
this.apiToken = apiToken;
|
|
@@ -28,6 +29,52 @@ export class Jin10McpService {
|
|
|
28
29
|
if (this.initialized) {
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
32
|
+
this.initializePromise ??= this.performInitialize().finally(() => {
|
|
33
|
+
this.initializePromise = null;
|
|
34
|
+
});
|
|
35
|
+
await this.initializePromise;
|
|
36
|
+
}
|
|
37
|
+
async callTool(name, args) {
|
|
38
|
+
try {
|
|
39
|
+
await this.initialize();
|
|
40
|
+
const result = await this.request("tools/call", {
|
|
41
|
+
name,
|
|
42
|
+
arguments: args,
|
|
43
|
+
});
|
|
44
|
+
if (!result) {
|
|
45
|
+
throw new Error(`jin10 tool ${name} returned empty result`);
|
|
46
|
+
}
|
|
47
|
+
if (result.isError) {
|
|
48
|
+
throw new Error(`jin10 tool ${name} returned MCP error`);
|
|
49
|
+
}
|
|
50
|
+
if (result.structuredContent !== undefined) {
|
|
51
|
+
return result.structuredContent;
|
|
52
|
+
}
|
|
53
|
+
const structured = result.content?.find((item) => item.structuredContent !== undefined)?.structuredContent;
|
|
54
|
+
if (structured !== undefined) {
|
|
55
|
+
return structured;
|
|
56
|
+
}
|
|
57
|
+
const text = result.content?.find((item) => typeof item.text === "string")?.text;
|
|
58
|
+
if (typeof text === "string" && text.trim()) {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(text);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return text;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (!isSessionExpiredError(error)) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
this.resetSession();
|
|
73
|
+
await this.initialize();
|
|
74
|
+
return await this.callToolAfterRecovery(name, args);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async performInitialize() {
|
|
31
78
|
await this.request("initialize", {
|
|
32
79
|
protocolVersion: "2025-11-25",
|
|
33
80
|
capabilities: {},
|
|
@@ -46,8 +93,7 @@ export class Jin10McpService {
|
|
|
46
93
|
}
|
|
47
94
|
this.initialized = true;
|
|
48
95
|
}
|
|
49
|
-
async
|
|
50
|
-
await this.initialize();
|
|
96
|
+
async callToolAfterRecovery(name, args) {
|
|
51
97
|
const result = await this.request("tools/call", {
|
|
52
98
|
name,
|
|
53
99
|
arguments: args,
|
|
@@ -76,6 +122,11 @@ export class Jin10McpService {
|
|
|
76
122
|
}
|
|
77
123
|
return result;
|
|
78
124
|
}
|
|
125
|
+
resetSession() {
|
|
126
|
+
this.initialized = false;
|
|
127
|
+
this.sessionId = null;
|
|
128
|
+
this.initializePromise = null;
|
|
129
|
+
}
|
|
79
130
|
async request(method, params) {
|
|
80
131
|
const configError = this.getConfigurationError();
|
|
81
132
|
if (configError) {
|
|
@@ -204,6 +255,10 @@ function truncate(value, maxLength) {
|
|
|
204
255
|
}
|
|
205
256
|
return `${value.slice(0, Math.max(0, maxLength - 3))}...`;
|
|
206
257
|
}
|
|
258
|
+
function isSessionExpiredError(error) {
|
|
259
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
260
|
+
return /session not found|unknown session|invalid session/i.test(message);
|
|
261
|
+
}
|
|
207
262
|
function normalizeFlashPage(value) {
|
|
208
263
|
const root = isRecord(value) ? value : {};
|
|
209
264
|
const data = isRecord(root.data) ? root.data : {};
|
|
@@ -45,8 +45,18 @@ export declare class MonitorService {
|
|
|
45
45
|
setExpectedStop(expectedStop: boolean): Promise<void>;
|
|
46
46
|
recordHeartbeat(runtimeHost?: "plugin_service" | "fallback_process"): Promise<void>;
|
|
47
47
|
recordLoopError(error: unknown): Promise<void>;
|
|
48
|
+
private tryAcquireRunLease;
|
|
49
|
+
private removeStaleRunLock;
|
|
50
|
+
private tryAcquireAlertClaim;
|
|
51
|
+
private removeStaleAlertClaim;
|
|
48
52
|
private trySendAlert;
|
|
53
|
+
private trySendCandidate;
|
|
49
54
|
private buildAlertDelivery;
|
|
50
55
|
private loadIntradayRows;
|
|
51
56
|
private buildVolumeAlert;
|
|
57
|
+
private hasSentAlert;
|
|
58
|
+
private sendAlertAndCleanupMedia;
|
|
59
|
+
private cleanupAlertMedia;
|
|
60
|
+
private getRunLockFilePath;
|
|
61
|
+
private getAlertClaimFilePath;
|
|
52
62
|
}
|