@dshtrading/hk 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,75 @@
1
+ Copyright (c) 2026 zhu1090093659 (dsh-trading)
2
+
3
+ # PolyForm Noncommercial License 1.0.0
4
+
5
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
6
+
7
+ ## Acceptance
8
+
9
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
14
+
15
+ ## Distribution License
16
+
17
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
18
+
19
+ ## Notices
20
+
21
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
22
+
23
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
24
+
25
+ ## Changes and New Works License
26
+
27
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
28
+
29
+ ## Patent License
30
+
31
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
32
+
33
+ ## Noncommercial Purposes
34
+
35
+ Any noncommercial purpose is a permitted purpose.
36
+
37
+ ## Personal Uses
38
+
39
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
40
+
41
+ ## Noncommercial Organizations
42
+
43
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
44
+
45
+ ## Fair Use
46
+
47
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
48
+
49
+ ## No Other Rights
50
+
51
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
52
+
53
+ ## Patent Defense
54
+
55
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
56
+
57
+ ## Violations
58
+
59
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
60
+
61
+ ## No Liability
62
+
63
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
64
+
65
+ ## Definitions
66
+
67
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
68
+
69
+ **You** refers to the individual or entity agreeing to these terms.
70
+
71
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
72
+
73
+ **Your licenses** are all the licenses granted to you for the software under these terms.
74
+
75
+ **Use** means anything you do with the software requiring one of your licenses.
@@ -0,0 +1,97 @@
1
+ # hk-trader agent preset —— dsh-trading hk 切片(实装形态抄 us-trader/cn-trader)。
2
+ #
3
+ # 本文件由 @dshtrading/hk 的 dsh-trading-hk-installer 插件(bundle host 面常驻行)在
4
+ # apply() 时幂等自安装到市场自有 preset root(默认 ~/.dsh-trading-presets/hk-trader;
5
+ # agent-presets 行需把该 root 配进 roots,统一配置归 @dshtrading/base)。插件卸载不
6
+ # 删除已安装目录;升级/重装后再次 apply 即恢复一致,行不可解析时只会得到带原因的
7
+ # broken 行,无进程崩溃(S3 REPORT broken 语义)。
8
+ #
9
+ # **单包双市场多实例模式(手册 §8,本仓新模式)**:connector 行 name 指向
10
+ # @dshtrading/connector-tencent(cn/hk 共用同一插件包),行 id 用市场命名空间的
11
+ # dsh-trading-hk-connector(cn preset 用 dsh-trading-cn-connector——不同 id 即不同
12
+ # 实例,行 id 即命名空间),config.market=hk 分流。provide 服务键 tradingHkMarketData,
13
+ # 组行 isolate 键 = 服务名(官方 standard preset 挂载硬规则;不包组则被
14
+ # dsh-agent-presets 以 published process-global service 拒绝,acceptance「修复 1」)。
15
+ #
16
+ # 组合形态对照官方 standard preset:本文件是 AGENT-PLANE 组合,不持有审批/沙箱/模型路由
17
+ # (host 面职责)。kit 行只向 scope 分层注册表(ctx.skills)注册、不 provide 服务,无需 realm。
18
+ - id: persona
19
+ name: '@deepseek-ai/dsh-persona'
20
+ config:
21
+ text: >-
22
+ 你是一名严谨的港股交易员,由 {{model}} 模型驱动,工作目录为 {{cwd}}。基于腾讯
23
+ 公开行情(实时快照与前权 OHLCV)做客观、量化的分析;下单类操作一律默认 dry-run
24
+ 模拟,liveTrading 关闭时直接拒绝实盘,未经用户明确确认绝不触碰真实资金;涉及
25
+ T+0 无涨跌幅、碎股手数、供股配股、窝轮牛熊证时逐项核对 hk-risk-checklist 风控
26
+ 清单,并明确提示跳空与流动性风险;你给出的任何内容都不构成投资建议。每次会话开始时,
27
+ 先检查工作目录下是否已有交易日志目录 .trading-journal/:没有则提醒用户本工作区尚未
28
+ 建立交易日志,并调用 trading-notes-setup 技能创建骨架;已有则把本会话的重要操作按
29
+ trading-notes-setup 的规范记入日志——agent 自己的操作入 agent 轨,用户的决定与手工
30
+ 操作代记入 human 轨,dry-run 一律标注。
31
+
32
+ # connector 行 provide 服务(tradingHkMarketData),必须包进 cordis:group + isolate,
33
+ # isolate 键 = 服务名(commit 8f75804 + acceptance「修复 1」)。
34
+ - id: dsh-trading-hk-connector-group
35
+ name: cordis:group
36
+ group: true
37
+ isolate:
38
+ tradingHkMarketData: true
39
+ config:
40
+ # 同包双实例:行 id 市场命名空间,name 指向共用插件包,market 分流。
41
+ - id: dsh-trading-hk-connector-tencent
42
+ name: '@dshtrading/connector-tencent'
43
+ config:
44
+ enabled: true
45
+ market: hk
46
+ dryRun: true
47
+ liveTrading: false
48
+
49
+ - id: dsh-trading-hk-connector-futu-group
50
+ name: cordis:group
51
+ group: true
52
+ isolate:
53
+ tradingHkMarketData: true
54
+ tradingHkTrade: true
55
+ config:
56
+ - id: dsh-trading-hk-connector-futu
57
+ name: '@dshtrading/connector-futu'
58
+ config:
59
+ enabled: true
60
+ dryRun: true
61
+ liveTrading: false
62
+
63
+ - id: dsh-trading-hk-connector-longbridge-group
64
+ name: cordis:group
65
+ group: true
66
+ isolate:
67
+ tradingHkMarketData: true
68
+ tradingHkTrade: true
69
+ config:
70
+ - id: dsh-trading-hk-connector-longbridge
71
+ name: '@dshtrading/connector-longbridge'
72
+ config:
73
+ enabled: true
74
+ dryRun: true
75
+ liveTrading: false
76
+
77
+ - id: dsh-trading-hk-connector-tiger-group
78
+ name: cordis:group
79
+ group: true
80
+ isolate:
81
+ tradingHkMarketData: true
82
+ tradingHkTrade: true
83
+ config:
84
+ - id: dsh-trading-hk-connector-tiger
85
+ name: '@dshtrading/connector-tiger'
86
+ config:
87
+ enabled: true
88
+ dryRun: true
89
+ liveTrading: false
90
+
91
+
92
+ - id: dsh-trading-hk-kit
93
+ name: '@dshtrading/kit-hk'
94
+ config:
95
+ dryRun: true
96
+ liveTrading: false
97
+
@@ -0,0 +1,3 @@
1
+ name: HK 交易员
2
+ description: 港股市场会话:腾讯行情工具与交易员人设(由 @dshtrading/hk 自安装,普通会话不可见 hk 工具)。
3
+ order: 22
@@ -0,0 +1,40 @@
1
+ # @dshtrading/hk —— hk 市场 bundle 的 patch 层(insert-only,README 设计铁律 #1)。
2
+ #
3
+ # 实装形态抄 @dshtrading/us(架构修订 2026-08-29 主 agent 决策):connector/kit 的
4
+ # 插件行在 preset 的 agent.cordis.yml(preset 级会话隔离)。本 bundle 的职责:
5
+ # 1. dsh-trading-hk-installer —— host 面常驻安装器插件(src/index.ts):boot 时幂等
6
+ # 自安装 hk-trader preset 到 ~/.dsh-trading-presets。自安装必须在 bundle 层而非
7
+ # kit 插件(kit 行在 preset 平面,preset 不存在则 kit.apply() 永不运行);
8
+ # 2. 依赖安装载体:preset 行按 bare 包名从 profile node_modules 解析(S3 坑 3),本包
9
+ # dependencies 实装 @dshtrading/connector-tencent 与 @dshtrading/kit-hk,保证
10
+ # preset 行可解析、不 broken。**connector-tencent 是 cn/hk 共用的单包双市场插件**:
11
+ # 本包与 @dshtrading/cn 依赖同一个包,preset 行以 config.market 分流(新模式,
12
+ # 手册 §8);
13
+ # 3. agent-presets root 行归 base 层所有(~/.dsh-trading-presets),本层不得重复配置。
14
+ #
15
+ # 注意:patch 文件必须保持「顶层 YAML 数组」形状(loadProfile → parsePatchList 对非数组
16
+ # 直接抛错);只允许 insert(按 id 打已存在行 = 整行替换,多市场并存会互相覆盖)。
17
+ - insert:
18
+ - id: dsh-trading-hk-installer
19
+ name: '@dshtrading/hk'
20
+
21
+ # host 面数据行(2026-08-30 GUI 行情桥配套):只 provide tradingHkMarketData。
22
+ - id: dsh-trading-hk-dataplane-tencent
23
+ name: '@dshtrading/connector-tencent/dataplane'
24
+ config:
25
+ enabled: true
26
+ market: hk
27
+ - id: dsh-trading-hk-dataplane-futu
28
+ name: '@dshtrading/connector-futu/dataplane'
29
+ config:
30
+ enabled: true
31
+ - id: dsh-trading-hk-dataplane-longbridge
32
+ name: '@dshtrading/connector-longbridge/dataplane'
33
+ config:
34
+ enabled: true
35
+ - id: dsh-trading-hk-dataplane-tiger
36
+ name: '@dshtrading/connector-tiger/dataplane'
37
+ config:
38
+ enabled: true
39
+
40
+
package/lib/index.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ import Schema from "@deepseek-ai/schemastery";
2
+ import { Context } from "@deepseek-ai/cordis";
3
+ //#region src/index.d.ts
4
+ /**
5
+ * Cordis 插件名 = patch 行 id(TEMPLATES §8):`dsh-trading-hk-*` 市场命名空间,
6
+ * 全仓唯一(insert-only 铁律 #1)。
7
+ */
8
+ declare const name = "dsh-trading-hk-installer";
9
+ interface Config {
10
+ /** preset 自安装 root 覆盖;默认 ~/.dsh-trading-presets(须与 base 层 agent-presets 行的 roots 一致)。 */
11
+ presetRoot?: string;
12
+ }
13
+ declare const Config: Schema<Config>;
14
+ declare const PRESET_ID = "hk-trader";
15
+ /** 默认安装 root:市场自有目录(S3 建议——绝不写进 ~/.dsh/.agent-presets 用户创作区)。 */
16
+ declare const DEFAULT_PRESET_ROOT: string;
17
+ interface SelfInstallResult {
18
+ /** 安装目录(preset 目录名即 roster id)。 */
19
+ dir: string;
20
+ /** 本次实际写入的文件名;空数组 = 内容已是当前代际。 */
21
+ wrote: string[];
22
+ /** 被跳过的文件与原因(用户改过/无管理戳)。 */
23
+ skipped: string[];
24
+ }
25
+ /**
26
+ * 幂等自安装 preset(S3 机制 + 2026-08-29 代际管理戳升级):mkdir -p + 逐文件按管理戳
27
+ * 三代裁决——
28
+ *
29
+ * 1. 目标不存在 → 写入(头行 = `# dsh-trading-managed: <内容sha前8>` + shipped 内容);
30
+ * 2. 目标存在且带本包可识别的管理戳(托管文件)→ 正文与 shipped 内容不同则整文件更新
31
+ * (以新代际覆盖——戳即「本文件归安装器托管」的约定);
32
+ * 3. 目标存在但无管理戳(用户改过/前代安装器所装)→ 跳过并记录提示(删除该文件即可
33
+ * 让安装器重新提供)。
34
+ *
35
+ * 迁移注意:代际升级前由旧安装器写入的已装文件没有管理戳,按第 3 条处理(跳过 + log
36
+ * 提示)——宁可不更新,绝不覆盖用户改动。
37
+ *
38
+ * 卸载本 bundle 不删除已安装目录(有意为之):升级/重装后再次 apply 即恢复一致;本包
39
+ * 被移除后 preset 行不可解析只会得到带原因的 broken 行,无进程崩溃(S3 REPORT broken 语义)。
40
+ * preset 引用的插件包必须进本 bundle 的 dependencies(S3 坑 3),见 package.json。
41
+ */
42
+ declare function installPreset(options?: {
43
+ presetRoot?: string;
44
+ }): Promise<SelfInstallResult>;
45
+ declare function apply(ctx: Context, config: Config): void;
46
+ //#endregion
47
+ export { Config, DEFAULT_PRESET_ROOT, PRESET_ID, SelfInstallResult, apply, installPreset, name };
package/lib/index.js ADDED
@@ -0,0 +1,108 @@
1
+ import { createHash } from "node:crypto";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { homedir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import Schema from "@deepseek-ai/schemastery";
7
+ //#region src/index.ts
8
+ /**
9
+ * @dshtrading/hk — hk 市场 bundle。包承载两块实质内容(实装形态抄 @dshtrading/us):
10
+ *
11
+ * 1. `cordis.patch.yml`(由 package.json 的 `dsh.bundle.patch` 声明):insert-only
12
+ * 聚合本 bundle 的 host 面常驻行(铁律 #1)。connector/kit 两行在 preset 的
13
+ * agent.cordis.yml(preset 级会话隔离,见 assets/preset/hk-trader/)。
14
+ * 2. `dsh-trading-hk-installer` 插件(本模块):hk-trader preset 幂等自安装(S3 机制)。
15
+ * 自安装职责必须在 bundle(host 面常驻)而非 kit 插件——kit 行在 preset 平面,
16
+ * preset 不存在时 kit.apply() 永不运行,鸡生蛋(2026-08-29 主 agent 结构性修复)。
17
+ *
18
+ * cn/hk 是**同一个 connector-tencent 插件包的两个实例**(单包双市场,手册 §8):
19
+ * 本 bundle 的 preset 行挂 market=hk 实例(提供 tradingHkMarketData + hk_* 工具)。
20
+ *
21
+ * @module @dshtrading/hk
22
+ */
23
+ /**
24
+ * Cordis 插件名 = patch 行 id(TEMPLATES §8):`dsh-trading-hk-*` 市场命名空间,
25
+ * 全仓唯一(insert-only 铁律 #1)。
26
+ */
27
+ const name = "dsh-trading-hk-installer";
28
+ const Config = Schema.object({ presetRoot: Schema.string() });
29
+ const PRESET_ID = "hk-trader";
30
+ /** 默认安装 root:市场自有目录(S3 建议——绝不写进 ~/.dsh/.agent-presets 用户创作区)。 */
31
+ const DEFAULT_PRESET_ROOT = join(homedir(), ".dsh-trading-presets");
32
+ /** 预置资产随本包分发(bundle 是市场组装点,preset 资产归 bundle 所有)。 */
33
+ const PRESET_ASSET_DIR = fileURLToPath(new URL("../assets/preset/", import.meta.url));
34
+ const PRESET_FILES = ["agent.cordis.yml", "preset.yml"];
35
+ /** 管理戳注释行前缀:托管安装文件的头行,值 = shipped 内容(不含戳行)的 SHA-256 前 8 位。 */
36
+ const MANAGED_STAMP_PREFIX = "# dsh-trading-managed: ";
37
+ function contentSha8(content) {
38
+ return createHash("sha256").update(content, "utf8").digest("hex").slice(0, 8);
39
+ }
40
+ /** 提取已安装文件头行的管理戳;null = 无戳(文件视为用户所有)。 */
41
+ function readManagedStamp(current) {
42
+ if (!current.startsWith(MANAGED_STAMP_PREFIX)) return null;
43
+ const stamp = (current.includes("\n") ? current.slice(0, current.indexOf("\n")) : current).slice(23).trim();
44
+ return /^[0-9a-f]{8}$/.test(stamp) ? stamp : null;
45
+ }
46
+ /** 已安装文件去掉管理戳头行后的正文。 */
47
+ function bodyAfterStamp(current) {
48
+ return current.includes("\n") ? current.slice(current.indexOf("\n") + 1) : "";
49
+ }
50
+ /**
51
+ * 幂等自安装 preset(S3 机制 + 2026-08-29 代际管理戳升级):mkdir -p + 逐文件按管理戳
52
+ * 三代裁决——
53
+ *
54
+ * 1. 目标不存在 → 写入(头行 = `# dsh-trading-managed: <内容sha前8>` + shipped 内容);
55
+ * 2. 目标存在且带本包可识别的管理戳(托管文件)→ 正文与 shipped 内容不同则整文件更新
56
+ * (以新代际覆盖——戳即「本文件归安装器托管」的约定);
57
+ * 3. 目标存在但无管理戳(用户改过/前代安装器所装)→ 跳过并记录提示(删除该文件即可
58
+ * 让安装器重新提供)。
59
+ *
60
+ * 迁移注意:代际升级前由旧安装器写入的已装文件没有管理戳,按第 3 条处理(跳过 + log
61
+ * 提示)——宁可不更新,绝不覆盖用户改动。
62
+ *
63
+ * 卸载本 bundle 不删除已安装目录(有意为之):升级/重装后再次 apply 即恢复一致;本包
64
+ * 被移除后 preset 行不可解析只会得到带原因的 broken 行,无进程崩溃(S3 REPORT broken 语义)。
65
+ * preset 引用的插件包必须进本 bundle 的 dependencies(S3 坑 3),见 package.json。
66
+ */
67
+ async function installPreset(options = {}) {
68
+ const dir = join(options.presetRoot ?? DEFAULT_PRESET_ROOT, PRESET_ID);
69
+ await mkdir(dir, { recursive: true });
70
+ const wrote = [];
71
+ const skipped = [];
72
+ for (const file of PRESET_FILES) {
73
+ const content = await readFile(join(PRESET_ASSET_DIR, PRESET_ID, file), "utf8");
74
+ const stamped = `${MANAGED_STAMP_PREFIX}${contentSha8(content)}\n${content}`;
75
+ const target = join(dir, file);
76
+ let current = null;
77
+ try {
78
+ current = await readFile(target, "utf8");
79
+ } catch {}
80
+ if (current === null) {
81
+ await writeFile(target, stamped);
82
+ wrote.push(file);
83
+ continue;
84
+ }
85
+ if (readManagedStamp(current) === null) {
86
+ skipped.push(`${file} (no management stamp — user-modified file left untouched; delete it to let the installer re-provision it)`);
87
+ continue;
88
+ }
89
+ if (bodyAfterStamp(current) !== content) {
90
+ await writeFile(target, stamped);
91
+ wrote.push(file);
92
+ }
93
+ }
94
+ return {
95
+ dir,
96
+ wrote,
97
+ skipped
98
+ };
99
+ }
100
+ function logger(ctx) {
101
+ const service = ctx.logger;
102
+ return typeof service === "function" ? service(name) : console;
103
+ }
104
+ function apply(ctx, config) {
105
+ installPreset({ presetRoot: config?.presetRoot }).then((result) => logger(ctx).info("[dsh-trading-hk-installer] self-install %s preset at %s wrote=[%s] skipped=[%s]", PRESET_ID, result.dir, result.wrote.join(",") || "nothing — already current", result.skipped.join("; ") || "none"), (error) => logger(ctx).warn("[dsh-trading-hk-installer] hk-trader preset self-install failed: %s", error));
106
+ }
107
+ //#endregion
108
+ export { Config, DEFAULT_PRESET_ROOT, PRESET_ID, apply, installPreset, name };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@dshtrading/hk",
3
+ "description": "HK (Hong Kong) market bundle for dsh-trading: host-plane hk-trader preset installer + insert-only aggregation of the Tencent connector (market=hk instance) and hk kit rows (design rule #1)",
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "./lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "default": "./lib/index.js"
12
+ },
13
+ "./cordis.patch.yml": "./cordis.patch.yml",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "lib",
18
+ "assets",
19
+ "cordis.patch.yml"
20
+ ],
21
+ "license": "PolyForm-Noncommercial-1.0.0",
22
+ "dsh": {
23
+ "bundle": {
24
+ "patch": "./cordis.patch.yml"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "@dshtrading/connector-futu": "0.1.0",
29
+ "@dshtrading/connector-tencent": "0.1.0",
30
+ "@dshtrading/connector-tiger": "0.1.0",
31
+ "@dshtrading/kit-hk": "0.1.0",
32
+ "@dshtrading/connector-longbridge": "0.1.0"
33
+ },
34
+ "peerDependencies": {
35
+ "@deepseek-ai/cordis": ">=4.0.0",
36
+ "@deepseek-ai/schemastery": ">=3.18.0"
37
+ },
38
+ "devDependencies": {
39
+ "tsdown": "^0.22.0"
40
+ },
41
+ "scripts": {
42
+ "build": "tsdown"
43
+ }
44
+ }