@weaxs/openclaw-stock-analysis 0.2.10 → 0.2.12

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.
Files changed (41) hide show
  1. package/README.md +11 -51
  2. package/dist/index.js +3693 -1971
  3. package/index.ts +74 -1636
  4. package/openclaw.plugin.json +3 -0
  5. package/package.json +3 -3
  6. package/scripts/cli-json.mjs +23 -0
  7. package/scripts/exec-process.mjs +89 -0
  8. package/scripts/setup-python.mjs +37 -4
  9. package/scripts/tool-calls.mjs +489 -0
  10. package/skills/event-driven/SKILL.md +2 -2
  11. package/skills/growth-quality/SKILL.md +1 -1
  12. package/skills/stock-analysis/SKILL.md +12 -7
  13. package/skills/stock-analysis/references/stateless-analysis.md +9 -1
  14. package/tools/_cache.py +13 -0
  15. package/tools/_subproc.py +46 -0
  16. package/tools/alert_rules.py +65 -16
  17. package/tools/backtest.py +3 -3
  18. package/tools/capabilities.py +32 -9
  19. package/tools/cli_budgets.json +2 -0
  20. package/tools/diagnostics.py +3 -4
  21. package/tools/gather.py +2 -6
  22. package/tools/import_parser.py +3 -4
  23. package/tools/lixinger.py +119 -27
  24. package/tools/market_regime.py +5 -2
  25. package/tools/market_review.py +5 -6
  26. package/tools/name_resolver.py +82 -21
  27. package/tools/report_renderer.py +3 -3
  28. package/tools/requirements.txt +6 -5
  29. package/tools/risk_screening.py +3 -2
  30. package/tools/screener.py +6 -4
  31. package/tools/search_intel.py +81 -12
  32. package/tools/sec_edgar.py +266 -0
  33. package/tools/sec_holders.py +6 -0
  34. package/tools/signal_tracker.py +11 -10
  35. package/tools/stateless_analysis.py +115 -0
  36. package/tools/stock_data.py +707 -222
  37. package/tools/tiaa_disclosures.py +267 -0
  38. package/tools/tool_schemas.json +2704 -0
  39. package/tools/trading_calendar.py +65 -30
  40. package/tools/value_data.py +366 -134
  41. package/tools/watchlist.py +43 -5
@@ -6,6 +6,7 @@
6
6
  "tools": [
7
7
  "get_kline",
8
8
  "get_quote",
9
+ "get_fund_quote",
9
10
  "get_capital_flow",
10
11
  "get_news",
11
12
  "get_financials",
@@ -41,6 +42,7 @@
41
42
  "screen_risk",
42
43
  "detect_market_regime",
43
44
  "get_market_review",
45
+ "get_watchlist",
44
46
  "run_watchlist_analysis",
45
47
  "detect_anomaly",
46
48
  "diagnose_data_sources",
@@ -69,6 +71,7 @@
69
71
  "analyze_portfolio_risk",
70
72
  "plan_portfolio_rebalance",
71
73
  "calculate_position_size",
74
+ "calculate_dcf_valuation",
72
75
  "analyze_event_study",
73
76
  "validate_backtest",
74
77
  "compare_analysis_snapshots",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weaxs/openclaw-stock-analysis",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "OpenClaw plugin for stock analysis, screening, and strategy backtesting across A/HK/US/JP/KR/TW markets",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
@@ -13,8 +13,8 @@
13
13
  "minGatewayVersion": "2026.3.24-beta.2"
14
14
  },
15
15
  "build": {
16
- "openclawVersion": "2026.10.9",
17
- "pluginSdkVersion": "2026.10.9"
16
+ "openclawVersion": "2026.11.3",
17
+ "pluginSdkVersion": "2026.11.3"
18
18
  }
19
19
  },
20
20
  "scripts": {
@@ -0,0 +1,23 @@
1
+ // Shared host-side CLI result rules; every adapter must surface failures the same way.
2
+ export const failureMessage = (error) =>
3
+ error.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER" ? "Python command output exceeded buffer limit"
4
+ : error.killed ? "Python command timed out"
5
+ : typeof error.code === "number" ? `Python command failed (exit ${error.code}); check interpreter/dependencies`
6
+ : "Python command failed; check interpreter/dependencies";
7
+
8
+ // Failed, empty, or non-JSON CLI output becomes a JSON error; a CLI-provided JSON error is kept.
9
+ export function cliJson(stdout, failure) {
10
+ try {
11
+ const data = JSON.parse(stdout);
12
+ if (!failure || (data && typeof data.error === "string")) return stdout;
13
+ } catch {
14
+ failure ??= stdout.trim() ? "Python command returned non-JSON output" : "Python command returned no JSON";
15
+ }
16
+ return JSON.stringify({ error: failure });
17
+ }
18
+
19
+ // Explicit null optional args would otherwise reach argv as "null"; dropping them applies defaults.
20
+ export const withoutNulls = (params) =>
21
+ params && typeof params === "object" && !Array.isArray(params)
22
+ ? Object.fromEntries(Object.entries(params).filter(([, value]) => value !== null))
23
+ : params;
@@ -0,0 +1,89 @@
1
+ import * as cp from "node:child_process";
2
+
3
+ function terminateTree(child) {
4
+ if (!child.pid) return;
5
+ if (process.platform === "win32") {
6
+ cp.execFile("taskkill", ["/F", "/T", "/PID", String(child.pid)], { timeout: 10_000 }, () => {});
7
+ return;
8
+ }
9
+ try {
10
+ process.kill(-child.pid, "SIGKILL");
11
+ } catch {
12
+ try { child.kill("SIGKILL"); } catch { /* already exited */ }
13
+ }
14
+ }
15
+
16
+ function failure(stdout, code, extra = {}) {
17
+ return Object.assign(new Error("Python command failed"), { stdout, code, ...extra });
18
+ }
19
+
20
+ // POSIX children run in their own session, so the host's terminal hangup no longer reaches them.
21
+ const live = new Set();
22
+ process.on("exit", () => { for (const child of live) terminateTree(child); });
23
+
24
+ /** execFile-compatible stdout collection that also terminates nested CLI children.
25
+ * @param {string} bin
26
+ * @param {string[]} argv
27
+ * @param {{timeoutMs?: number, maxBuffer?: number, signal?: AbortSignal}} [options]
28
+ */
29
+ export function execFileTree(bin, argv, { timeoutMs, maxBuffer = 32 * 1024 * 1024, signal } = {}) {
30
+ if (signal?.aborted) {
31
+ return Promise.reject(Object.assign(new Error("The operation was aborted"), { name: "AbortError", stdout: "" }));
32
+ }
33
+ return new Promise((resolve, reject) => {
34
+ const child = cp.spawn(bin, argv, {
35
+ detached: process.platform !== "win32",
36
+ stdio: ["ignore", "pipe", "ignore"],
37
+ windowsHide: true,
38
+ });
39
+ live.add(child);
40
+ const chunks = [];
41
+ const stdout = () => Buffer.concat(chunks).toString("utf8");
42
+ let bytes = 0;
43
+ let settled = false;
44
+ let timedOut = false;
45
+ let aborted = false;
46
+ let overflow = false;
47
+
48
+ const finish = (error) => {
49
+ if (settled) return;
50
+ settled = true;
51
+ if (timer) clearTimeout(timer);
52
+ signal?.removeEventListener("abort", onAbort);
53
+ if (error) reject(error);
54
+ else resolve(stdout());
55
+ };
56
+ const onAbort = () => {
57
+ aborted = true;
58
+ terminateTree(child);
59
+ };
60
+ signal?.addEventListener("abort", onAbort, { once: true });
61
+ const timer = timeoutMs > 0 ? setTimeout(() => {
62
+ timedOut = true;
63
+ terminateTree(child);
64
+ }, timeoutMs) : null;
65
+ timer?.unref();
66
+
67
+ child.stdout.on("data", chunk => {
68
+ if (bytes + chunk.length > maxBuffer) {
69
+ overflow = true;
70
+ terminateTree(child);
71
+ return;
72
+ }
73
+ bytes += chunk.length;
74
+ chunks.push(chunk);
75
+ });
76
+ child.on("error", error => {
77
+ error.stdout = stdout();
78
+ finish(error);
79
+ });
80
+ child.on("close", code => {
81
+ live.delete(child);
82
+ if (overflow) finish(failure(stdout(), "ERR_CHILD_PROCESS_STDIO_MAXBUFFER", { killed: true }));
83
+ else if (timedOut) finish(failure(stdout(), null, { killed: true }));
84
+ else if (aborted) finish(Object.assign(failure(stdout(), null), { name: "AbortError" }));
85
+ else if (code !== 0) finish(failure(stdout(), code));
86
+ else finish();
87
+ });
88
+ });
89
+ }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { execFileSync } from "node:child_process";
3
- import { existsSync, mkdirSync, renameSync } from "node:fs";
3
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync } from "node:fs";
4
4
  import { join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { pythonEnvironmentRoot, venvPythonPath } from "./venv-python.mjs";
@@ -19,6 +19,15 @@ function run(bin, args) {
19
19
  execFileSync(bin, args, { stdio: "inherit", timeout: 1_800_000 });
20
20
  }
21
21
 
22
+ function pipWorks() {
23
+ try {
24
+ execFileSync(venvPython, ["-m", "pip", "--version"], { stdio: "pipe" });
25
+ return true;
26
+ } catch {
27
+ return false;
28
+ }
29
+ }
30
+
22
31
  function findPython() {
23
32
  for (const name of ["python3", "python"]) {
24
33
  try {
@@ -48,11 +57,35 @@ try {
48
57
  mkdirSync(envRoot, { recursive: true });
49
58
  renameSync(join(pkgDir, ".venv"), venvDir);
50
59
  }
51
- if (!existsSync(venvDir)) {
52
- run(python, ["-m", "venv", venvDir]);
60
+ // A half-built venv (e.g. Debian without python3-venv) leaves python but no pip; rebuild it.
61
+ if (!existsSync(venvDir) || !pipWorks()) {
62
+ try {
63
+ run(python, ["-m", "venv", "--clear", venvDir]);
64
+ } catch (err) {
65
+ rmSync(venvDir, { recursive: true, force: true });
66
+ throw err;
67
+ }
53
68
  }
54
69
 
55
- run(venvPython, ["-m", "pip", "install", "-q", "-r", requirements]);
70
+ try {
71
+ run(venvPython, ["-m", "pip", "install", "-q", "-r", requirements]);
72
+ } catch {
73
+ // A failover provider without a wheel for this platform must not block the core tools.
74
+ const lines = readFileSync(requirements, "utf8").split(/\r?\n/).map(line => line.trim());
75
+ const marker = lines.findIndex(line => line.startsWith("# optional providers"));
76
+ const specs = list => list.filter(line => line && !line.startsWith("#"));
77
+ const core = specs(marker < 0 ? lines : lines.slice(0, marker));
78
+ if (core.length) run(venvPython, ["-m", "pip", "install", "-q", ...core]);
79
+ const skipped = specs(marker < 0 ? [] : lines.slice(marker + 1)).filter(spec => {
80
+ try {
81
+ run(venvPython, ["-m", "pip", "install", "-q", spec]);
82
+ return false;
83
+ } catch {
84
+ return true;
85
+ }
86
+ });
87
+ if (skipped.length) console.warn(`[stock-analysis-plugin] optional providers skipped: ${skipped.join(", ")}`);
88
+ }
56
89
  } catch (err) {
57
90
  console.warn(
58
91
  `\n[pi-stock-analysis] Python setup failed: ${err.message}\n` +