tickflow-assist 0.2.13 → 0.2.14

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 CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  基于 [OpenClaw](https://openclaw.ai) 的 A 股监控与分析插件。它使用 [TickFlow](https://tickflow.org/auth/register?ref=BUJ54JEDGE) 获取行情与财务数据,结合 LLM 生成技术面、基本面、资讯面的综合判断,并把结果持久化到本地 LanceDB。
4
4
 
5
- 最近更新:`v0.2.13` `configure-openclaw` 与一键安装脚本中加入 Linux 中文字体自动安装,减少 VPS PNG 告警卡中文乱码;并补充 GitHub README 效果预览图。
5
+ 最近更新:`v0.2.14` 对齐 OpenClaw `v2026.3.31` 兼容声明与开发依赖,更新 QQ Bot 内置通道说明,并将 PNG 告警卡临时文件迁移到 OpenClaw 共享 temp root,修复新版本地媒体 allowlist 下的图片投递失败。
6
+
7
+ 当前主线按 OpenClaw `v2026.3.31+` 对齐。
6
8
 
7
9
  ## 安装
8
10
 
@@ -3,6 +3,7 @@ import { Database } from "./storage/db.js";
3
3
  import { WatchlistService } from "./services/watchlist-service.js";
4
4
  import { MonitorService } from "./services/monitor-service.js";
5
5
  import { AlertService } from "./services/alert-service.js";
6
+ import { AlertMediaService } from "./services/alert-media-service.js";
6
7
  import type { LocalTool, OpenClawPluginConfig, OpenClawPluginRuntime, RegisteredService } from "./runtime/plugin-api.js";
7
8
  import { RealtimeMonitorWorker } from "./background/realtime-monitor.worker.js";
8
9
  import { DailyUpdateWorker } from "./background/daily-update.worker.js";
@@ -19,6 +20,7 @@ export interface AppContext {
19
20
  };
20
21
  services: {
21
22
  alertService: AlertService;
23
+ alertMediaService: AlertMediaService;
22
24
  monitorService: MonitorService;
23
25
  realtimeMonitorWorker: RealtimeMonitorWorker;
24
26
  dailyUpdateWorker: DailyUpdateWorker;
package/dist/bootstrap.js CHANGED
@@ -1,3 +1,4 @@
1
+ import path from "node:path";
1
2
  import { TickFlowClient } from "./services/tickflow-client.js";
2
3
  import { InstrumentService } from "./services/instrument-service.js";
3
4
  import { KlineService } from "./services/kline-service.js";
@@ -63,6 +64,7 @@ import { testAlertTool } from "./tools/test-alert.tool.js";
63
64
  import { updateAllTool } from "./tools/update-all.tool.js";
64
65
  import { viewAnalysisTool } from "./tools/view-analysis.tool.js";
65
66
  import { backtestKeyLevelsTool } from "./tools/backtest-key-levels.tool.js";
67
+ import { resolvePreferredOpenClawTmpDir } from "./runtime/openclaw-temp-dir.js";
66
68
  import { RealtimeMonitorWorker } from "./background/realtime-monitor.worker.js";
67
69
  import { DailyUpdateWorker } from "./background/daily-update.worker.js";
68
70
  export function createAppContext(config, options = {}) {
@@ -107,7 +109,7 @@ export function createAppContext(config, options = {}) {
107
109
  }
108
110
  : undefined,
109
111
  });
110
- const alertMediaService = new AlertMediaService(config.databasePath);
112
+ const alertMediaService = new AlertMediaService(config.databasePath, undefined, undefined, resolveAlertMediaTempRootDir());
111
113
  const indicatorService = new IndicatorService(config.pythonBin, config.pythonArgs, config.pythonWorkdir);
112
114
  const watchlistService = new WatchlistService(watchlistRepository, instrumentService, watchlistProfileService);
113
115
  const keyLevelsBacktestService = new KeyLevelsBacktestService(keyLevelsHistoryRepository, klinesRepository, intradayKlinesRepository, watchlistService);
@@ -152,7 +154,7 @@ export function createAppContext(config, options = {}) {
152
154
  startMonitorTool(monitorService, runtime),
153
155
  stopDailyUpdateTool(dailyUpdateWorker, runtime),
154
156
  stopMonitorTool(monitorService, runtime),
155
- testAlertTool(alertService, alertMediaService),
157
+ testAlertTool(alertService, alertMediaService, runtime.configSource),
156
158
  updateAllTool(dailyUpdateWorker),
157
159
  viewAnalysisTool(analysisViewService),
158
160
  ],
@@ -192,6 +194,7 @@ export function createAppContext(config, options = {}) {
192
194
  runtime,
193
195
  services: {
194
196
  alertService,
197
+ alertMediaService,
195
198
  monitorService,
196
199
  realtimeMonitorWorker,
197
200
  dailyUpdateWorker,
@@ -200,6 +203,12 @@ export function createAppContext(config, options = {}) {
200
203
  },
201
204
  };
202
205
  }
206
+ function resolveAlertMediaTempRootDir() {
207
+ // OpenClaw 2026.3.31 no longer widens local media roots from tool-created files.
208
+ // Keep PNG alerts under the shared OpenClaw temp root so both runtime sends and
209
+ // `openclaw message send --media ...` can read them without extra allowlist config.
210
+ return path.join(resolvePreferredOpenClawTmpDir(), "tickflow-assist", "alert-media", "tmp");
211
+ }
203
212
  export async function buildWatchlistDebugSnapshot(app) {
204
213
  const watchlistTableExists = await app.services.database.hasTable("watchlist");
205
214
  const watchlistPreview = await app.services.watchlistService.list();
@@ -0,0 +1,21 @@
1
+ export declare const POSIX_OPENCLAW_TMP_DIR = "/tmp/openclaw";
2
+ interface TempDirStatLike {
3
+ isDirectory(): boolean;
4
+ isSymbolicLink(): boolean;
5
+ mode?: number;
6
+ uid?: number;
7
+ }
8
+ interface ResolvePreferredOpenClawTmpDirOptions {
9
+ accessSync?: (path: string, mode?: number) => void;
10
+ chmodSync?: (path: string, mode: number) => void;
11
+ lstatSync?: (path: string) => TempDirStatLike;
12
+ mkdirSync?: (path: string, opts: {
13
+ recursive: boolean;
14
+ mode?: number;
15
+ }) => void;
16
+ getuid?: () => number | undefined;
17
+ tmpdir?: () => string;
18
+ warn?: (message: string) => void;
19
+ }
20
+ export declare function resolvePreferredOpenClawTmpDir(options?: ResolvePreferredOpenClawTmpDirOptions): string;
21
+ export {};
@@ -0,0 +1,124 @@
1
+ import fsSync from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ export const POSIX_OPENCLAW_TMP_DIR = "/tmp/openclaw";
5
+ const TMP_DIR_ACCESS_MODE = fsSync.constants.W_OK | fsSync.constants.X_OK;
6
+ function isNodeErrorWithCode(error, code) {
7
+ return typeof error === "object" && error !== null && "code" in error && error.code === code;
8
+ }
9
+ export function resolvePreferredOpenClawTmpDir(options = {}) {
10
+ const accessSync = options.accessSync ?? fsSync.accessSync;
11
+ const chmodSync = options.chmodSync ?? fsSync.chmodSync;
12
+ const lstatSync = options.lstatSync ?? fsSync.lstatSync;
13
+ const mkdirSync = options.mkdirSync ?? fsSync.mkdirSync;
14
+ const warn = options.warn ?? ((message) => console.warn(message));
15
+ const getuid = options.getuid ?? (() => {
16
+ try {
17
+ return typeof process.getuid === "function" ? process.getuid() : undefined;
18
+ }
19
+ catch {
20
+ return undefined;
21
+ }
22
+ });
23
+ const resolveTmpdir = options.tmpdir ?? os.tmpdir;
24
+ const uid = getuid();
25
+ const isSecureDirForUser = (stats) => {
26
+ if (uid === undefined) {
27
+ return true;
28
+ }
29
+ if (typeof stats.uid === "number" && stats.uid !== uid) {
30
+ return false;
31
+ }
32
+ if (typeof stats.mode === "number" && (stats.mode & 0o022) !== 0) {
33
+ return false;
34
+ }
35
+ return true;
36
+ };
37
+ const fallback = () => {
38
+ const suffix = uid === undefined ? "openclaw" : `openclaw-${uid}`;
39
+ return path.join(resolveTmpdir(), suffix);
40
+ };
41
+ const isTrustedTmpDir = (stats) => stats.isDirectory() && !stats.isSymbolicLink() && isSecureDirForUser(stats);
42
+ const resolveDirState = (candidatePath) => {
43
+ try {
44
+ if (!isTrustedTmpDir(lstatSync(candidatePath))) {
45
+ return "invalid";
46
+ }
47
+ accessSync(candidatePath, TMP_DIR_ACCESS_MODE);
48
+ return "available";
49
+ }
50
+ catch (error) {
51
+ if (isNodeErrorWithCode(error, "ENOENT")) {
52
+ return "missing";
53
+ }
54
+ return "invalid";
55
+ }
56
+ };
57
+ const tryRepairWritableBits = (candidatePath) => {
58
+ try {
59
+ const stats = lstatSync(candidatePath);
60
+ if (!stats.isDirectory() || stats.isSymbolicLink()) {
61
+ return false;
62
+ }
63
+ if (uid !== undefined && typeof stats.uid === "number" && stats.uid !== uid) {
64
+ return false;
65
+ }
66
+ if (typeof stats.mode !== "number" || (stats.mode & 0o022) === 0) {
67
+ return false;
68
+ }
69
+ chmodSync(candidatePath, 0o700);
70
+ warn(`[tickflow-assist] tightened permissions on temp dir: ${candidatePath}`);
71
+ return resolveDirState(candidatePath) === "available";
72
+ }
73
+ catch {
74
+ return false;
75
+ }
76
+ };
77
+ const ensureTrustedFallbackDir = () => {
78
+ const fallbackPath = fallback();
79
+ const state = resolveDirState(fallbackPath);
80
+ if (state === "available") {
81
+ return fallbackPath;
82
+ }
83
+ if (state === "invalid") {
84
+ if (tryRepairWritableBits(fallbackPath)) {
85
+ return fallbackPath;
86
+ }
87
+ throw new Error(`Unsafe fallback OpenClaw temp dir: ${fallbackPath}`);
88
+ }
89
+ try {
90
+ mkdirSync(fallbackPath, { recursive: true, mode: 0o700 });
91
+ chmodSync(fallbackPath, 0o700);
92
+ }
93
+ catch {
94
+ throw new Error(`Unable to create fallback OpenClaw temp dir: ${fallbackPath}`);
95
+ }
96
+ if (resolveDirState(fallbackPath) !== "available" && !tryRepairWritableBits(fallbackPath)) {
97
+ throw new Error(`Unsafe fallback OpenClaw temp dir: ${fallbackPath}`);
98
+ }
99
+ return fallbackPath;
100
+ };
101
+ const existingPreferredState = resolveDirState(POSIX_OPENCLAW_TMP_DIR);
102
+ if (existingPreferredState === "available") {
103
+ return POSIX_OPENCLAW_TMP_DIR;
104
+ }
105
+ if (existingPreferredState === "invalid") {
106
+ if (tryRepairWritableBits(POSIX_OPENCLAW_TMP_DIR)) {
107
+ return POSIX_OPENCLAW_TMP_DIR;
108
+ }
109
+ return ensureTrustedFallbackDir();
110
+ }
111
+ try {
112
+ accessSync("/tmp", TMP_DIR_ACCESS_MODE);
113
+ mkdirSync(POSIX_OPENCLAW_TMP_DIR, { recursive: true, mode: 0o700 });
114
+ chmodSync(POSIX_OPENCLAW_TMP_DIR, 0o700);
115
+ if (resolveDirState(POSIX_OPENCLAW_TMP_DIR) !== "available"
116
+ && !tryRepairWritableBits(POSIX_OPENCLAW_TMP_DIR)) {
117
+ return ensureTrustedFallbackDir();
118
+ }
119
+ return POSIX_OPENCLAW_TMP_DIR;
120
+ }
121
+ catch {
122
+ return ensureTrustedFallbackDir();
123
+ }
124
+ }
@@ -12,7 +12,7 @@ export interface PluginEntryResult {
12
12
  id: string;
13
13
  name: string;
14
14
  description: string;
15
- kind?: string;
15
+ kind?: OpenClawPluginDefinition["kind"];
16
16
  register: (api: OpenClawPluginApi) => void;
17
17
  }
18
18
  export declare function definePluginEntry({ id, name, description, kind, register, }: DefinePluginEntryOptions): PluginEntryResult;
@@ -8,8 +8,9 @@ export declare class AlertMediaService {
8
8
  private readonly baseDir;
9
9
  private readonly retentionHours;
10
10
  private readonly cleanupIntervalMs;
11
+ private readonly tempRootDir?;
11
12
  private lastCleanupAt;
12
- constructor(baseDir: string, retentionHours?: number, cleanupIntervalMs?: number);
13
+ constructor(baseDir: string, retentionHours?: number, cleanupIntervalMs?: number, tempRootDir?: string | undefined);
13
14
  getTempRootDir(): string;
14
15
  writeAlertCard(params: {
15
16
  symbol: string;
@@ -8,14 +8,18 @@ export class AlertMediaService {
8
8
  baseDir;
9
9
  retentionHours;
10
10
  cleanupIntervalMs;
11
+ tempRootDir;
11
12
  lastCleanupAt = 0;
12
- constructor(baseDir, retentionHours = DEFAULT_RETENTION_HOURS, cleanupIntervalMs = DEFAULT_CLEANUP_INTERVAL_MS) {
13
+ constructor(baseDir, retentionHours = DEFAULT_RETENTION_HOURS, cleanupIntervalMs = DEFAULT_CLEANUP_INTERVAL_MS, tempRootDir) {
13
14
  this.baseDir = baseDir;
14
15
  this.retentionHours = retentionHours;
15
16
  this.cleanupIntervalMs = cleanupIntervalMs;
17
+ this.tempRootDir = tempRootDir;
16
18
  }
17
19
  getTempRootDir() {
18
- return path.resolve(this.baseDir, "..", "alert-media", "tmp");
20
+ return this.tempRootDir
21
+ ? path.resolve(this.tempRootDir)
22
+ : path.resolve(this.baseDir, "..", "alert-media", "tmp");
19
23
  }
20
24
  async writeAlertCard(params) {
21
25
  await this.maybeCleanupExpired();
@@ -25,6 +25,21 @@ export class AlertService {
25
25
  };
26
26
  }
27
27
  if (payload.mediaPath) {
28
+ if (payload.message.trim()) {
29
+ const mediaOnlyError = await this.trySendPayload({
30
+ ...payload,
31
+ message: "",
32
+ });
33
+ if (mediaOnlyError === null) {
34
+ const textFollowupError = await this.trySendPayload({ message: payload.message });
35
+ return {
36
+ ok: textFollowupError === null,
37
+ mediaAttempted: true,
38
+ mediaDelivered: true,
39
+ error: textFollowupError,
40
+ };
41
+ }
42
+ }
28
43
  const textFallback = normalizeSendInput(payload.message);
29
44
  const textFallbackError = await this.trySendPayload(textFallback);
30
45
  if (textFallbackError === null) {
@@ -32,7 +47,7 @@ export class AlertService {
32
47
  ok: true,
33
48
  mediaAttempted: true,
34
49
  mediaDelivered: false,
35
- error: null,
50
+ error: primaryError,
36
51
  };
37
52
  }
38
53
  return {
@@ -137,9 +152,6 @@ export class AlertService {
137
152
  };
138
153
  try {
139
154
  switch (this.channel) {
140
- case "telegram":
141
- await runtimeContext.runtime.channel.telegram.sendMessageTelegram(this.options.target, payload.message, baseOptions);
142
- return null;
143
155
  case "discord":
144
156
  await runtimeContext.runtime.channel.discord.sendMessageDiscord(this.options.target, payload.message, {
145
157
  ...baseOptions,
@@ -156,24 +168,9 @@ export class AlertService {
156
168
  case "signal":
157
169
  await runtimeContext.runtime.channel.signal.sendMessageSignal(this.options.target, payload.message, baseOptions);
158
170
  return null;
159
- case "imessage":
160
- await runtimeContext.runtime.channel.imessage.sendMessageIMessage(this.options.target, payload.message, {
161
- accountId: this.options.account || undefined,
162
- config: runtimeContext.config,
163
- mediaUrl: payload.mediaPath,
164
- mediaLocalRoots: payload.mediaLocalRoots,
165
- });
166
- return null;
167
- case "whatsapp":
168
- await runtimeContext.runtime.channel.whatsapp.sendMessageWhatsApp(this.options.target, payload.message, {
169
- verbose: false,
170
- cfg: runtimeContext.config,
171
- accountId: this.options.account || undefined,
172
- mediaUrl: payload.mediaPath,
173
- mediaLocalRoots: payload.mediaLocalRoots,
174
- });
175
- return null;
176
171
  default:
172
+ // OpenClaw 2026.3.31 narrows the typed runtime channel surface.
173
+ // Fall back to `openclaw message send` for channels not exposed here.
177
174
  return `runtime delivery not supported for channel: ${this.channel}`;
178
175
  }
179
176
  }
@@ -237,9 +234,10 @@ export class AlertService {
237
234
  "send",
238
235
  "--channel",
239
236
  this.channel,
240
- "--message",
241
- payload.message,
242
237
  ];
238
+ if (payload.message) {
239
+ args.push("--message", payload.message);
240
+ }
243
241
  if (payload.mediaPath) {
244
242
  args.push("--media", payload.mediaPath);
245
243
  }
@@ -1,6 +1,6 @@
1
1
  import { AlertService } from "../services/alert-service.js";
2
2
  import { AlertMediaService } from "../services/alert-media-service.js";
3
- export declare function testAlertTool(alertService: AlertService, alertMediaService: AlertMediaService): {
3
+ export declare function testAlertTool(alertService: AlertService, alertMediaService: AlertMediaService, configSource?: "openclaw_plugin" | "local_config"): {
4
4
  name: string;
5
5
  description: string;
6
6
  optional: boolean;
@@ -1,8 +1,8 @@
1
1
  import { formatChinaDateTime } from "../utils/china-time.js";
2
- export function testAlertTool(alertService, alertMediaService) {
2
+ export function testAlertTool(alertService, alertMediaService, configSource = "openclaw_plugin") {
3
3
  return {
4
4
  name: "test_alert",
5
- description: "Send a text plus PNG test alert through the configured OpenClaw alert delivery path.",
5
+ description: "Send a test alert through the configured OpenClaw alert delivery path. Plugin mode includes PNG; local mode sends text only.",
6
6
  optional: true,
7
7
  async run() {
8
8
  const now = formatChinaDateTime();
@@ -10,6 +10,19 @@ export function testAlertTool(alertService, alertMediaService) {
10
10
  `时间: ${now}`,
11
11
  "说明: 这是一条手动触发的测试消息,用于验证文本与 PNG 告警卡投递链路正常。",
12
12
  ]);
13
+ if (configSource === "local_config") {
14
+ const result = await alertService.sendWithResult({ message });
15
+ if (result.ok) {
16
+ return [
17
+ "✅ 测试告警文本已发送(本地命令模式)",
18
+ "说明: `npm run tool -- test_alert` 仅验证文本链路;请通过 `/ta_testalert` 验证 PNG 图片链路。",
19
+ ].join("\n");
20
+ }
21
+ const detail = result.error ?? alertService.getLastError();
22
+ return detail
23
+ ? `❌ 测试告警发送失败\n原因: ${detail}`
24
+ : "❌ 测试告警发送失败";
25
+ }
13
26
  let mediaFile = null;
14
27
  try {
15
28
  mediaFile = await alertMediaService.writeAlertCard({
@@ -41,10 +54,18 @@ export function testAlertTool(alertService, alertMediaService) {
41
54
  filename: mediaFile.filename,
42
55
  });
43
56
  if (result.ok && result.mediaDelivered) {
57
+ if (result.error) {
58
+ return [
59
+ "⚠️ PNG 告警卡已发送,但文本补发失败",
60
+ `原因: ${result.error}`,
61
+ ].join("\n");
62
+ }
44
63
  return "✅ 测试告警发送成功(文本 + PNG)";
45
64
  }
46
65
  if (result.ok) {
47
- return "⚠️ 测试告警文本已发送,但 PNG 未送达,已回退为纯文本";
66
+ return result.error
67
+ ? `⚠️ 测试告警文本已发送,但 PNG 未送达,已回退为纯文本\n原因: ${result.error}`
68
+ : "⚠️ 测试告警文本已发送,但 PNG 未送达,已回退为纯文本";
48
69
  }
49
70
  const detail = result.error ?? alertService.getLastError();
50
71
  return detail
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "tickflow-assist",
3
3
  "name": "TickFlow Assist",
4
- "version": "0.2.13",
4
+ "version": "0.2.14",
5
5
  "description": "A-share watchlist analysis, monitoring, and alert delivery powered by TickFlow and OpenClaw.",
6
6
  "skills": [
7
7
  "skills"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tickflow-assist",
3
- "version": "0.2.13",
4
- "description": "OpenClaw plugin for TickFlow-based A-share analysis, monitoring, and alerting.",
3
+ "version": "0.2.14",
4
+ "description": "OpenClaw smart stock plugin for A-share investing and watchlist workflows, powered by TickFlow API for realtime monitoring, post-close review, multi-dimensional analysis, key level tracking, and alerts. 面向 A 股投资与盯盘场景的 OpenClaw 智能股票插件,基于 TickFlow API 提供实时监控、收盘后复盘、多维综合分析、关键价位跟踪与告警能力。",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "dist/plugin.js",
@@ -38,12 +38,12 @@
38
38
  },
39
39
  "openclaw": {
40
40
  "build": {
41
- "openclawVersion": "2026.3.28"
41
+ "openclawVersion": "2026.3.31"
42
42
  },
43
43
  "compat": {
44
- "pluginApi": "2026.3.28",
45
- "minGatewayVersion": "2026.3.28",
46
- "builtWithOpenClawVersion": "2026.3.28"
44
+ "pluginApi": "2026.3.31",
45
+ "minGatewayVersion": "2026.3.31",
46
+ "builtWithOpenClawVersion": "2026.3.31"
47
47
  },
48
48
  "extensions": [
49
49
  "dist/plugin.js"
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "^22.13.11",
64
- "openclaw": "^2026.3.28",
64
+ "openclaw": "^2026.3.31",
65
65
  "typescript": "^5.8.2"
66
66
  }
67
67
  }