@zhangxij/dsh-yupan 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zhang-1239
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,164 @@
1
- # Temporary Holding Version
1
+ # 预判 · 个人判断记录
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > 先画下你认为的走势,到期再填实际值;偏差只跟自己比。
4
+
5
+ 预判是 [DeepSeek Harness](https://github.com/deepseek-ai) 的插件:一个挂在 Web 侧边栏里的个人面板,用来管理多条价格预测记录,用四种价格(开盘/最高/最低/收盘)画出你认为的未来走势;到期后手动填实际值,偏差按你自己的历史累计成画像。
6
+
7
+ **边界**:不接行情接口,不自动获取价格,不分析个股,不预测涨跌,不输出买卖建议。所有历史数据、预测值、实际值都来自你导入的文件、截图确认结果或手动输入。截图识别和列名辅助只用于录入,结果必须逐项确认后才写入。
8
+
9
+ ## 是什么
10
+
11
+ - **未来预测**:不导入数据也能直接开始。点「直接开始」进入画布,名称、起始日期都可以不填;按第 1 根、第 2 根记录,也可以随时手动填实际值。
12
+ - **回放挑战**:用已导入的历史 K 线,遮住末尾 N 根,画完立即揭晓;需要先「导入历史数据」。
13
+ - **画布**:每根预测 K 线有四个手柄;右侧表格可输入四个数字(回车下一根);模板可「沿用昨收画平」或「复制上一根」;Ctrl/⌘ + Z 撤销。周期 1–60 根可调。
14
+ - **状态**:待画 / 待揭晓 / 待填实际值 / 已完成。支持筛选、排序、编辑、删除。
15
+ - **我的画像**:方向偏差、幅度偏差、模式标签,只统计你自己的记录,不打分、不排名。
16
+ - **到期提醒**:未来预测填了起始日期后,按工作日排期,到期在对话底部提示。
17
+
18
+ ## 怎么装
19
+
20
+ 需要带插件系统的 DSH(`dsh web` 或 DSH Desktop)。
21
+
22
+ **从 npm 安装(发布后)**
23
+
24
+ ```sh
25
+ dsh plugin --profile desktop add @zhangxij/dsh-yupan
26
+ ```
27
+
28
+ **从本地目录安装(开发时)**
29
+
30
+ ```sh
31
+ dsh plugin --profile desktop add file:D:\yupan\plugin
32
+ ```
33
+
34
+ 把 `--profile desktop` 换成你自己的 profile 名(`dsh` 默认 profile 一般是 `web`)。
35
+
36
+ > 包名已设为 `@zhangxij/dsh-yupan`。如果 fork 到别的 scope,要同步改三处:`package.json` 的 `name`、`cordis.patch.yml` 的 `name`、`client.js` 里 `__ModuleLoader__.load({ id })` 的 id,否则宿主会找不到浏览器半侧。旧包名 `@local/yupan` 的记录会留在原数据目录里,见下面的「数据在哪」。
37
+
38
+ 安装后重启或刷新 DSH:左侧栏出现「预判」入口,点开就是面板。
39
+
40
+ ## 使用
41
+
42
+ 1. 左侧边栏点「预判」图标打开面板。首页直接给出两个入口:**未来预测** 和 **回放挑战**。
43
+ 2. 未来预测:
44
+ - 名称可选(不填为「未命名预测」);
45
+ - 起始日期可选(不填就不设到期提醒,随时可手动对比;填了按工作日排期);
46
+ - 周期 1–60 根可调,画布和表格即时同步。
47
+ 3. 回放挑战:选数据集、周期、可选起点;画完立即从本机数据库取实际值揭晓。
48
+ 4. 未来预测填实际值时也支持上传截图识别;识别结果先填入表格,逐项核对并勾选确认后才能保存。联网开关就在该窗口里,关闭则只能手动填。
49
+
50
+ ## 导入与确认
51
+
52
+ - CSV / XLSX 在 Host 本地解析(支持 UTF-8/GBK/UTF-16、Excel 日期序列、字段别名、无表头启发式)。确认页展示解析后的日期与四价、字段映射、重复策略,勾选确认后才写库。
53
+ - 同一标的同一日期默认跳过;可选覆盖。覆盖会更新原行的数值并把该行归到新数据集。
54
+ - 截图识别:设置里开启「联网辅助」并配置 OpenAI 兼容的 `chat/completions` 地址、模型、可选 Key。识别结果逐根展示,每根单独勾选「已核对」后才可写入;识别失败不猜值、不自动填充。关闭开关后只能手动录入。
55
+ - 列名辅助:映射不确定时可调用同一服务给出建议,仍由你确认。
56
+
57
+ ## 数据在哪
58
+
59
+ 数据目录按下面的顺序取,**取到第一个就用它**:
60
+
61
+ 1. 插件配置 `config.dataRoot`(`cordis.patch.yml` 里的 `config.dataRoot`);
62
+ 2. 环境变量 `DSH_YUPAN_DATA`;
63
+ 3. 仓库内 `data/`——**仅开发时**:插件目录不在 `node_modules` 里,且 `data/` 已经存在(跑过 `node seed.js` 才会有);
64
+ 4. 仓库父级的 `data/`——**仅开发时**,兼容旧版本默认的 `D:\yupan\data`;
65
+ 5. 用户目录 `~/.yupan`(Windows 上是 `C:\Users\<你的用户名>\.yupan`)。
66
+
67
+ 任何一步解析到 `node_modules` 里,都会退回 `~/.yupan`;安装后的包不会往自己的安装目录写数据。数据是一个 SQLite 文件 `yupan.db`(WAL 模式),表结构:
68
+
69
+ | 表 | 内容 |
70
+ | --- | --- |
71
+ | `datasets` | 每次导入的元数据 |
72
+ | `bars` | 原始 K 线,主键 `(symbol, date)`,按标的、日期建索引;查询永远带日期范围与 LIMIT |
73
+ | `predictions` | 预测记录;回放挑战用 `dataset_id` 关联数据集,未来预测可以为空;`predicted_json` / `actual_json` 保存四价 |
74
+ | `comparisons` | 预测与实际的分项对比、标签和摘要 |
75
+ | `settings` | 联网开关、识别服务地址/模型/Key、是否保留原文件 |
76
+ | `originals` | 仅在显式开启「保留原文件/原图」时保存 Blob |
77
+
78
+ - 备份:关掉 DSH,复制整个数据目录(含 `yupan.db`、`yupan.db-wal`、`yupan.db-shm`)。
79
+ - 清空:面板「数据」里可清空全部;或关掉 DSH 后删除数据目录。
80
+ - 卸载插件不会删除数据目录,需要手动清理。
81
+
82
+ ## 隐私与权限
83
+
84
+ - **不获取行情**:插件没有行情接口、没有行情轮询、没有遥测或第三方统计。
85
+ - **外部请求只有一个开关**:只有你在设置里主动开启「联网辅助」并填写地址后,截图识别和列名辅助才会把**你确认要识别的截图/表头**发给你配置的 OpenAI 兼容服务;地址由你填,插件不自带、不硬编码任何服务端。开关关闭时插件不发起外部请求。
86
+ - **DSH 访问检查**:HTTP 只注册同源路由 `GET /yupan/state`、`POST /yupan/predictions` 等(完整清单见 `index.js`),每个请求都在任何路由逻辑之前调用 `ctx.connection.requestRejection`:没有有效 DSH 凭据返回 401,跨站请求返回 403;同源校验只是最前面的廉价一层,不是唯一一层。
87
+ - **客户端走 DSH 连接**:浏览器端只请求同源的 `/yupan/*`,桌面壳暴露 `__DSH_TRANSPORT__.fetch` 时优先用它,否则用同源 `fetch` 自动携带 DSH 的 `dsh-auth-*` 会话 Cookie;不裸连第三方。
88
+ - **文件访问**:只读写上面解析出的数据目录;不扫描其它目录,不写 `node_modules`。
89
+ - **Key**:OCR 的 API Key 只存本机数据库;JSON 导出不含 Key,也不含保留的原文件 Blob。
90
+ - **导出**:面板「数据」里可导出全部 JSON(数据集、原始 K 线、预测、对比、设置),也可按标的/时间清除原始数据、删除单个数据集、清空全部。
91
+
92
+ ## 已知限制
93
+
94
+ - **中文优先**:界面文案是中文;`locale/zh.json`、`locale/en.json` 目前只有插件市场用的标题和描述,界面本身没有做多语言。
95
+ - **只做记录,不做判断**:偏差画像是「你自己的预测 − 你自己的实际值」的累计,不是准确率排名,也不能预测下一次。
96
+ - **识别依赖外部服务**:截图识别和列名辅助依赖你配置的 OpenAI 兼容服务;模型识别错、漏、串行时不会自动写入,必须逐项勾选「已核对」。
97
+ - **单机单用户**:没有账号、同步、协作;数据是本地 SQLite,落盘不加密。
98
+ - **需要 Node 内置 SQLite**:依赖 `node:sqlite`(DSH 自带的 Node 24 已包含);在更老的 Node 上无法加载。
99
+ - **原文件按需保留**:默认不保留上传的 CSV/XLSX/截图;开启后才会写进 `originals` 表。
100
+ - **开发时会切数据目录**:如果仓库内存在 `data/`,开发中的插件会优先用它而不是 `~/.yupan`。跑过 `seed.js` 后如果看不到原有记录,先检查这一点;删掉仓库内 `data/` 即可回到用户目录。
101
+
102
+ ## 开发
103
+
104
+ ```text
105
+ index.js 宿主端:数据目录、SQLite、/yupan 路由、导入解析、OCR 调用
106
+ client.js 浏览器端:侧边栏面板、画布、列表、画像、到期提示
107
+ lib/db.js SQLite 表结构与查询
108
+ lib/parse.js CSV/XLSX 解析、字段映射、日期归一化
109
+ lib/compare.js 偏差对比与个人画像聚合
110
+ lib/ocr.js 可选的截图识别 / 列名辅助
111
+ seed.js 本地演示数据(只写仓库内 data/ 或 --dir 指定的目录)
112
+ cordis.patch.yml 插件挂载
113
+ locale/*.json 市场用的中英文标题与描述
114
+ icon.svg 插件图标
115
+ icon-512.png 市场用 512×512 图标
116
+ screenshots.json 市场截图清单
117
+ market/ 市场条目模板(提交到 awesome-dsh-plugin 用)
118
+ docs/screenshots/ 截图目录与拍摄说明
119
+ ```
120
+
121
+ 常用命令:
122
+
123
+ ```sh
124
+ node --check index.js
125
+ node --check client.js
126
+ node --check seed.js
127
+ npm run check
128
+
129
+ # 往仓库内 data/ 写一份演示数据(已存在则拒绝,需 --force)
130
+ node seed.js
131
+
132
+ # 写到临时目录,不碰仓库和用户目录
133
+ node seed.js --dir D:\tmp\yupan-demo --force
134
+
135
+ # 检查 npm 包会带哪些文件
136
+ npm pack --dry-run
137
+ ```
138
+
139
+ 本地联调时可以用环境变量把数据指到临时目录:
140
+
141
+ ```powershell
142
+ $env:DSH_YUPAN_DATA = 'D:\tmp\yupan-dev'
143
+ ```
144
+
145
+ ## 发布(维护者)
146
+
147
+ 1. **包名**:已设为 `@zhangxij/dsh-yupan`。如果换 scope,同时同步 `cordis.patch.yml` 的 `name` 和 `client.js` 里 `__ModuleLoader__.load({ id })` 的 id,并更新 profile 的 `dependencies` 与 `dsh.profile.bundles`。
148
+ 2. **建仓库**:仓库地址按 `https://github.com/zhang-1239/dsh-yupan` 写在 `repository` / `homepage` / `bugs` 里;需要先在 GitHub 上创建这个仓库。若实际地址不同,改这三处和 `market/` 里的条目文件名、`url`、`icon`。
149
+ 3. **Repository About → Topics**:加上 `dsh-plugin`(市场收录的公开要求);`package.json` 的 `keywords` 也已带上 `dsh-plugin`。
150
+ 4. **发布**:`npm publish --access public`(`prepublishOnly` 会先跑语法检查)。
151
+ 5. **上架市场**:把 `market/zhang-1239__dsh-yupan.yml` 提交到 [awesome-dsh-plugin](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin);截图放到 `docs/screenshots/`(见该目录的 README)。
152
+
153
+ ## English
154
+
155
+ **Yupan** (預判, "forecast") is a personal forecast journal plugin for DeepSeek Harness. Draw the next N candles with four prices (open/high/low/close), fill in the actuals when the window closes, and see a bias profile built only from your own records.
156
+
157
+ - **Install:** `dsh plugin --profile desktop add @zhangxij/dsh-yupan` (local dev: `... add file:D:\yupan\plugin`). If you publish under a different scope, update the package name in `package.json`, `cordis.patch.yml`, and the `__ModuleLoader__` id in `client.js` together, plus the profile's `dependencies` and `dsh.profile.bundles`.
158
+ - **Data:** `config.dataRoot` → `DSH_YUPAN_DATA` → repo-local `data/` (development only, and only if it exists) → legacy sibling `data/` (development only) → `~/.yupan`. Never `node_modules`. One SQLite database (`yupan.db`, WAL) holds datasets, bars, predictions, comparisons, settings, and optional original blobs.
159
+ - **Privacy:** no market feed, no polling, no telemetry. The only outbound path is the optional screenshot OCR / column-name helper: it is off by default and, when you turn it on and configure a compatible endpoint, sends only the image or headers you chose to that endpoint. Every HTTP route calls `ctx.connection.requestRejection` before any route logic (401 without a valid DSH credential, 403 for an untrusted origin). The browser half calls only same-origin `/yupan/*`, preferring `__DSH_TRANSPORT__.fetch` when the desktop shell provides it.
160
+ - **Limitations:** Chinese-first UI; local single-user SQLite with no encryption or sync; OCR quality depends on your configured service and every value must be confirmed; requires Node's built-in `node:sqlite` (bundled with DSH's Node 24); original files are kept only when you opt in.
161
+
162
+ ## License
163
+
164
+ [MIT](LICENSE) © 2026 zhang-1239