dsh-stock-analysis 0.2.11 → 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.
- package/README.md +31 -79
- package/dist/index.js +3782 -2693
- package/dist/web/app.js +38 -6
- package/dist/web/style.css +1 -0
- package/package.json +1 -1
- package/scripts/cli-json.mjs +23 -0
- package/scripts/exec-process.mjs +89 -0
- package/scripts/setup-python.mjs +37 -4
- package/scripts/tool-calls.mjs +489 -0
- package/skills/event-driven/SKILL.md +2 -2
- package/skills/growth-quality/SKILL.md +1 -1
- package/skills/stock-analysis/SKILL.md +8 -6
- package/skills/stock-analysis/references/stateless-analysis.md +9 -1
- package/tools/_cache.py +13 -0
- package/tools/_subproc.py +46 -0
- package/tools/alert_rules.py +2 -2
- package/tools/backtest.py +3 -3
- package/tools/capabilities.py +32 -9
- package/tools/cli_budgets.json +2 -0
- package/tools/diagnostics.py +3 -4
- package/tools/gather.py +2 -6
- package/tools/import_parser.py +3 -4
- package/tools/lixinger.py +119 -27
- package/tools/market_regime.py +5 -2
- package/tools/market_review.py +5 -6
- package/tools/name_resolver.py +66 -7
- package/tools/report_renderer.py +3 -3
- package/tools/requirements.txt +5 -4
- package/tools/risk_screening.py +3 -2
- package/tools/screener.py +6 -4
- package/tools/search_intel.py +79 -10
- package/tools/sec_edgar.py +266 -0
- package/tools/sec_holders.py +6 -0
- package/tools/signal_tracker.py +5 -5
- package/tools/stateless_analysis.py +115 -0
- package/tools/stock_data.py +455 -201
- package/tools/tiaa_disclosures.py +4 -0
- package/tools/tool_schemas.json +2704 -0
- package/tools/trading_calendar.py +65 -30
- package/tools/value_data.py +366 -134
- package/tools/watchlist.py +43 -5
package/dist/web/app.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(() => {
|
|
3
3
|
// dsh/web/app.ts
|
|
4
4
|
var POLL_IDLE = 15e3;
|
|
5
|
-
var POLL_BUSY =
|
|
5
|
+
var POLL_BUSY = 5e3;
|
|
6
6
|
var REQUEST_TIMEOUT = 15e3;
|
|
7
7
|
var CACHE_KEY = "stock-dashboard:v2:snapshot";
|
|
8
8
|
var PREF_KEY = "stock-dashboard:v2:prefs";
|
|
@@ -41,10 +41,13 @@
|
|
|
41
41
|
prices: /* @__PURE__ */ new Map(),
|
|
42
42
|
pollTimer: void 0,
|
|
43
43
|
inflight: false,
|
|
44
|
+
// A poll requested while one is in flight (e.g. right after a watchlist edit) runs once that one ends.
|
|
45
|
+
dirty: false,
|
|
44
46
|
saving: false,
|
|
45
47
|
error: null,
|
|
46
48
|
lastOk: 0,
|
|
47
|
-
fromCache: false
|
|
49
|
+
fromCache: false,
|
|
50
|
+
signature: ""
|
|
48
51
|
};
|
|
49
52
|
function $(id) {
|
|
50
53
|
const node = document.getElementById(id);
|
|
@@ -250,9 +253,18 @@
|
|
|
250
253
|
node.append(el("span", "live"), document.createTextNode(`${open.map((region) => REGION_NAMES[region]).join("\u3001")}\u4EA4\u6613\u4E2D \xB7 `));
|
|
251
254
|
}
|
|
252
255
|
node.append(document.createTextNode(state.fromCache ? "\u663E\u793A\u4E0A\u6B21\u6570\u636E\uFF0C\u6B63\u5728\u66F4\u65B0\u2026" : `${clock(state.lastOk, true)} \u5DF2\u540C\u6B65`));
|
|
256
|
+
if (!state.fromCache && [...snap.ribbon || [], ...snap.market.indices].some(isStale)) {
|
|
257
|
+
node.append(document.createTextNode(" \xB7 "), el("span", "warn", "\u90E8\u5206\u6307\u6570\u66F4\u65B0\u5931\u8D25"));
|
|
258
|
+
}
|
|
253
259
|
if (!state.fromCache && snap.pending > 0) node.append(document.createTextNode(` \xB7 \u540E\u53F0\u66F4\u65B0 ${snap.pending} \u9879`));
|
|
254
260
|
$("refresh").classList.toggle("busy", !state.fromCache && snap.pending > 0);
|
|
255
261
|
}
|
|
262
|
+
function isStale(row) {
|
|
263
|
+
return Boolean(row.error && row.quote);
|
|
264
|
+
}
|
|
265
|
+
function staleTitle(row) {
|
|
266
|
+
return `\u66F4\u65B0\u5931\u8D25\uFF0C\u663E\u793A\u4E0A\u6B21\u62A5\u4EF7${row.updatedAt ? `\uFF08${clock(row.updatedAt)}\uFF09` : ""}`;
|
|
267
|
+
}
|
|
256
268
|
function groupByRegion(list) {
|
|
257
269
|
const groups = /* @__PURE__ */ new Map();
|
|
258
270
|
for (const item of list) {
|
|
@@ -291,6 +303,10 @@
|
|
|
291
303
|
el("span", `tile-price ${dir(row.quote.change_pct)}`, fmtPrice(row.quote.price, 2)),
|
|
292
304
|
el("span", `tile-pct ${dir(row.quote.change_pct)}`, fmtPct(row.quote.change_pct))
|
|
293
305
|
);
|
|
306
|
+
if (isStale(row)) {
|
|
307
|
+
tile.classList.add("is-stale");
|
|
308
|
+
tile.title = staleTitle(row);
|
|
309
|
+
}
|
|
294
310
|
} else if (row.loading) {
|
|
295
311
|
tile.append(skeleton(64), skeleton(40));
|
|
296
312
|
} else {
|
|
@@ -558,6 +574,10 @@
|
|
|
558
574
|
if (row.quote && num(row.quote.price) !== null) {
|
|
559
575
|
price.textContent = fmtPrice(row.quote.price, 2);
|
|
560
576
|
pct.textContent = `${fmtSigned(row.quote.change, 2)} ${fmtPct(row.quote.change_pct)}`;
|
|
577
|
+
if (isStale(row)) {
|
|
578
|
+
tr.classList.add("is-stale");
|
|
579
|
+
tr.title = staleTitle(row);
|
|
580
|
+
}
|
|
561
581
|
} else if (row.loading) {
|
|
562
582
|
price.append(skeleton(64));
|
|
563
583
|
pct.append(skeleton(80));
|
|
@@ -671,6 +691,7 @@
|
|
|
671
691
|
body.append(side);
|
|
672
692
|
}
|
|
673
693
|
function render(flash = /* @__PURE__ */ new Map()) {
|
|
694
|
+
$("tip").hidden = true;
|
|
674
695
|
$("watch-count").textContent = state.snap ? `${state.snap.watchlist.length} / 30` : "";
|
|
675
696
|
renderStatus();
|
|
676
697
|
renderRibbon();
|
|
@@ -700,23 +721,34 @@
|
|
|
700
721
|
}
|
|
701
722
|
async function poll() {
|
|
702
723
|
clearTimeout(state.pollTimer);
|
|
703
|
-
if (state.inflight)
|
|
724
|
+
if (state.inflight) {
|
|
725
|
+
state.dirty = true;
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
704
728
|
state.inflight = true;
|
|
729
|
+
state.dirty = false;
|
|
705
730
|
const region = state.region;
|
|
706
731
|
try {
|
|
707
732
|
const snap = await api(`./api/snapshot?region=${encodeURIComponent(region)}`);
|
|
708
733
|
state.error = null;
|
|
709
734
|
state.lastOk = Date.now();
|
|
710
735
|
if (region === state.region) {
|
|
711
|
-
|
|
712
|
-
|
|
736
|
+
const signature = JSON.stringify({ ...snap, fetchedAt: null, pending: null });
|
|
737
|
+
if (signature === state.signature && !state.fromCache) {
|
|
738
|
+
state.snap = snap;
|
|
739
|
+
renderStatus();
|
|
740
|
+
} else {
|
|
741
|
+
state.signature = signature;
|
|
742
|
+
applySnapshot(snap);
|
|
743
|
+
writeJson(CACHE_KEY, { savedAt: Date.now(), snap });
|
|
744
|
+
}
|
|
713
745
|
}
|
|
714
746
|
} catch (error) {
|
|
715
747
|
state.error = error.message;
|
|
716
748
|
renderStatus();
|
|
717
749
|
} finally {
|
|
718
750
|
state.inflight = false;
|
|
719
|
-
if (region !== state.region) void poll();
|
|
751
|
+
if (region !== state.region || state.dirty) void poll();
|
|
720
752
|
else schedule();
|
|
721
753
|
}
|
|
722
754
|
}
|
package/dist/web/style.css
CHANGED
|
@@ -176,6 +176,7 @@ table { width: 100%; border-collapse: collapse; }
|
|
|
176
176
|
.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 11px; }
|
|
177
177
|
.tag { padding: 0 4px; border-radius: 3px; background: var(--surface-subtle); font-size: 10.5px; line-height: 16px; }
|
|
178
178
|
.stale { color: var(--warn); }
|
|
179
|
+
.is-stale .tile-price, .is-stale .tile-pct, .is-stale .iprice, .is-stale .ipct { opacity: .55; }
|
|
179
180
|
.price { font-size: 15px; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; border-radius: 5px; }
|
|
180
181
|
.price.flash-up { animation: flash-up 1.4s cubic-bezier(.16, 1, .3, 1); }
|
|
181
182
|
.price.flash-down { animation: flash-down 1.4s cubic-bezier(.16, 1, .3, 1); }
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|
package/scripts/setup-python.mjs
CHANGED
|
@@ -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
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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` +
|